-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathcell.dm
421 lines (352 loc) · 11.7 KB
/
cell.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/obj/item/stock_parts/cell
name = "power cell"
desc = "A rechargeable electrochemical power cell."
icon = 'icons/obj/power.dmi'
icon_state = "cell"
item_state = "cell"
lefthand_file = 'icons/mob/inhands/misc/devices_lefthand.dmi'
righthand_file = 'icons/mob/inhands/misc/devices_righthand.dmi'
force = 5
throwforce = 5
throw_speed = 2
throw_range = 5
w_class = WEIGHT_CLASS_SMALL
var/charge = 0 // note %age conveted to actual charge in New
var/maxcharge = 1000
materials = list(/datum/material/iron=700, /datum/material/glass=50)
grind_results = list(/datum/reagent/lithium = 15, /datum/reagent/iron = 5, /datum/reagent/silicon = 5)
var/rigged = FALSE // true if rigged to explode
var/chargerate = 100 //how much power is given every tick in a recharger
var/self_recharge = 0 //does it self recharge, over time, or not?
var/ratingdesc = TRUE
var/grown_battery = FALSE // If it's a grown that acts as a battery, add a wire overlay to it.
/obj/item/stock_parts/cell/get_cell()
return src
/obj/item/stock_parts/cell/Initialize(mapload, override_maxcharge)
. = ..()
START_PROCESSING(SSobj, src)
create_reagents(5, INJECTABLE | DRAINABLE)
if (override_maxcharge)
maxcharge = override_maxcharge
charge = maxcharge
if(ratingdesc)
desc += " This one has a rating of [DisplayEnergy(maxcharge)], and you should not swallow it."
update_appearance(UPDATE_ICON)
RegisterSignal(src, COMSIG_ITEM_MAGICALLY_CHARGED, PROC_REF(on_magic_charge))
var/static/list/loc_connections = list(
COMSIG_ITEM_MAGICALLY_CHARGED = PROC_REF(on_magic_charge),
)
AddElement(/datum/element/connect_loc, loc_connections)
/obj/item/stock_parts/cell/Destroy()
STOP_PROCESSING(SSobj, src)
return ..()
/obj/item/stock_parts/cell/vv_edit_var(var_name, var_value)
switch(var_name)
if("self_recharge")
if(var_value)
START_PROCESSING(SSobj, src)
else
STOP_PROCESSING(SSobj, src)
. = ..()
/**
* Signal proc for [COMSIG_ITEM_MAGICALLY_CHARGED]
*
* If we, or the item we're located in, is subject to the charge spell, gain some charge back
*/
/obj/item/stock_parts/cell/proc/on_magic_charge(datum/source, datum/action/cooldown/spell/charge/spell, mob/living/caster)
SIGNAL_HANDLER
// This shouldn't be running if we're not being held by a mob,
// or if we're not within an object being held by a mob, but just in case...
if(!ismovable(loc))
return
. = COMPONENT_ITEM_CHARGED
if(prob(80))
maxcharge -= 200
if(maxcharge <= 1) // Div by 0 protection
maxcharge = 1
. |= COMPONENT_ITEM_BURNT_OUT
charge = maxcharge
update_appearance(UPDATE_ICON)
// Guns need to process their chamber when we've been charged
if(isgun(loc))
var/obj/item/gun/gun_loc = loc
gun_loc.process_chamber()
// The thing we're in might have overlays or icon states for whether the cell is charged
if(!ismob(loc))
loc.update_appearance(UPDATE_ICON)
return .
/obj/item/stock_parts/cell/process(delta_time)
if(self_recharge)
give(chargerate * 0.125 * delta_time)
else
return PROCESS_KILL
/obj/item/stock_parts/cell/update_overlays()
. = ..()
cut_overlays()
if(grown_battery)
. += image('icons/obj/power.dmi',"grown_wires")
if(charge < 0.01)
return
else if(charge/maxcharge >=0.995)
. += "cell-o2"
else
. += "cell-o1"
/obj/item/stock_parts/cell/proc/percent() // return % charge of cell
return 100*charge/maxcharge
// use power from a cell
/obj/item/stock_parts/cell/use(amount)
if(rigged && amount > 0)
explode()
return 0
if(charge < amount)
return 0
charge = (charge - amount)
if(!istype(loc, /obj/machinery/power/apc))
SSblackbox.record_feedback("tally", "cell_used", 1, type)
return 1
// recharge the cell
/obj/item/stock_parts/cell/proc/give(amount)
if(rigged && amount > 0)
explode()
return 0
if(maxcharge < amount)
amount = maxcharge
var/power_used = min(maxcharge-charge,amount)
charge += power_used
return power_used
/obj/item/stock_parts/cell/examine(mob/user)
. = ..()
if(rigged)
. += span_danger("This power cell seems to be faulty!")
else
. += "The charge meter reads [round(src.percent() )]%."
/obj/item/stock_parts/cell/suicide_act(mob/user)
if(!use(500))
user.visible_message(span_suicide("[user] is licking the electrodes of [src] but the cell doesnt have enough charge!"))
return SHAME
user.visible_message(span_suicide("[user] is licking the electrodes of [src]! It looks like [user.p_theyre()] trying to commit suicide!"))
return FIRELOSS
/obj/item/stock_parts/cell/on_reagent_change(changetype)
rigged = !isnull(reagents.has_reagent(/datum/reagent/toxin/plasma, 5)) //has_reagent returns the reagent datum
..()
/obj/item/stock_parts/cell/proc/explode()
var/turf/T = get_turf(src.loc)
if (charge==0)
return
var/devastation_range = -1 //round(charge/11000)
var/heavy_impact_range = round(sqrt(charge)/60)
var/light_impact_range = round(sqrt(charge)/30)
var/flash_range = light_impact_range
if (light_impact_range==0)
rigged = FALSE
corrupt()
return
//explosion(T, 0, 1, 2, 2)
explosion(T, devastation_range, heavy_impact_range, light_impact_range, flash_range)
qdel(src)
/obj/item/stock_parts/cell/proc/corrupt()
charge /= 2
maxcharge = max(maxcharge/2, chargerate)
if (prob(10))
rigged = TRUE //broken batterys are dangerous
/obj/item/stock_parts/cell/emp_act(severity)
. = ..()
if(. & EMP_PROTECT_SELF)
return
charge -= max((charge * severity / 100), 50 * severity)
if (charge < 0)
charge = 0
/obj/item/stock_parts/cell/ex_act(severity, target)
..()
if(!QDELETED(src))
switch(severity)
if(2)
if(prob(50))
corrupt()
if(3)
if(prob(25))
corrupt()
/obj/item/stock_parts/cell/blob_act(obj/structure/blob/B)
SSexplosions.high_mov_atom += src
/obj/item/stock_parts/cell/proc/get_electrocute_damage()
if(charge >= 1000)
return clamp(20 + round(charge/25000), 20, 195) + rand(-5,5)
else
return 0
/obj/item/stock_parts/cell/get_part_rating()
return rating * maxcharge
/* Cell variants*/
/obj/item/stock_parts/cell/empty/Initialize(mapload)
. = ..()
charge = 0
/obj/item/stock_parts/cell/crap
name = "\improper Nanotrasen brand rechargeable AA battery"
desc = "You can't top the plasma top." //TOTALLY TRADEMARK INFRINGEMENT
maxcharge = 500
materials = list(/datum/material/glass=40)
/obj/item/stock_parts/cell/crap/empty/Initialize(mapload)
. = ..()
charge = 0
update_appearance(UPDATE_ICON)
/obj/item/stock_parts/cell/upgraded
name = "upgraded power cell"
desc = "A power cell with a slightly higher capacity than normal!"
maxcharge = 2500
materials = list(/datum/material/glass=50)
chargerate = 1000
/obj/item/stock_parts/cell/upgraded/plus
name = "upgraded power cell+"
desc = "A power cell with an even higher capacity than the base model!"
maxcharge = 5000
/obj/item/stock_parts/cell/secborg
name = "security borg rechargeable D battery"
maxcharge = 600 //600 max charge / 100 charge per shot = six shots
materials = list(/datum/material/glass=40)
/obj/item/stock_parts/cell/secborg/empty/Initialize(mapload)
. = ..()
charge = 0
update_appearance(UPDATE_ICON)
/obj/item/stock_parts/cell/mini_egun
name = "miniature energy gun power cell"
maxcharge = 600
/obj/item/stock_parts/cell/pulse //200 pulse shots
name = "pulse rifle power cell"
maxcharge = 40000
chargerate = 1500
/obj/item/stock_parts/cell/pulse/carbine //25 pulse shots
name = "pulse carbine power cell"
maxcharge = 5000
/obj/item/stock_parts/cell/pulse/pistol //10 pulse shots
name = "pulse pistol power cell"
maxcharge = 2000
/obj/item/stock_parts/cell/high
name = "high-capacity power cell"
icon_state = "hcell"
maxcharge = 10000
materials = list(/datum/material/glass=60)
chargerate = 1500
/obj/item/stock_parts/cell/high/plus
name = "high-capacity power cell+"
desc = "Where did these come from?"
icon_state = "h+cell"
maxcharge = 15000
chargerate = 2250
/obj/item/stock_parts/cell/high/empty/Initialize(mapload)
. = ..()
charge = 0
update_appearance(UPDATE_ICON)
/obj/item/stock_parts/cell/super
name = "super-capacity power cell"
icon_state = "scell"
maxcharge = 20000
materials = list(/datum/material/glass=300)
chargerate = 2000
/obj/item/stock_parts/cell/super/empty/Initialize(mapload)
. = ..()
charge = 0
update_appearance(UPDATE_ICON)
/obj/item/stock_parts/cell/hyper
name = "hyper-capacity power cell"
icon_state = "hpcell"
maxcharge = 30000
materials = list(/datum/material/glass=400)
chargerate = 3000
/obj/item/stock_parts/cell/hyper/empty/Initialize(mapload)
. = ..()
charge = 0
update_appearance(UPDATE_ICON)
/obj/item/stock_parts/cell/bluespace
name = "bluespace power cell"
desc = "A rechargeable transdimensional power cell."
icon_state = "bscell"
maxcharge = 40000
materials = list(/datum/material/glass=600)
chargerate = 4000
/obj/item/stock_parts/cell/bluespace/empty/Initialize(mapload)
. = ..()
charge = 0
update_appearance(UPDATE_ICON)
/obj/item/stock_parts/cell/infinite
name = "infinite-capacity power cell!"
icon_state = "icell"
maxcharge = 30000
materials = list(/datum/material/glass=1000)
rating = 100
chargerate = 30000
/obj/item/stock_parts/cell/infinite/use()
return 1
/obj/item/stock_parts/cell/infinite/abductor
name = "void core"
desc = "An alien power cell that produces energy seemingly out of nowhere."
icon = 'icons/obj/abductor.dmi'
icon_state = "cell"
maxcharge = 50000
ratingdesc = FALSE
/obj/item/stock_parts/cell/infinite/abductor/Initialize(mapload, override_maxcharge)
AddElement(/datum/element/update_icon_blocker)
return ..()
/obj/item/stock_parts/cell/potato
name = "potato battery"
desc = "A rechargeable starch based power cell."
icon = 'icons/obj/hydroponics/harvest.dmi'
icon_state = "potato"
charge = 100
maxcharge = 300
materials = list()
grown_battery = TRUE //it has the overlays for wires
/obj/item/stock_parts/cell/high/slime
name = "charged slime core"
desc = "A yellow slime core infused with plasma, it crackles with power."
icon = 'icons/mob/slimes.dmi'
icon_state = "yellow slime extract"
materials = list()
rating = 5 //self-recharge makes these desirable
self_recharge = 1 // Infused slime cores self-recharge, over time
/obj/item/stock_parts/cell/emproof
name = "\improper EMP-proof cell"
desc = "An EMP-proof cell."
maxcharge = 500
rating = 3
/obj/item/stock_parts/cell/emproof/Initialize(mapload)
. = ..()
ADD_TRAIT(src, TRAIT_EMPPROOF_SELF, "innate_empproof")
/obj/item/stock_parts/cell/emproof/empty/Initialize(mapload)
. = ..()
charge = 0
update_appearance(UPDATE_ICON)
/obj/item/stock_parts/cell/emproof/corrupt()
return
/obj/item/stock_parts/cell/beam_rifle
name = "beam rifle capacitor"
desc = "A high powered capacitor that can provide huge amounts of energy in an instant."
maxcharge = 30000
chargerate = 5000 //Extremely energy intensive
/obj/item/stock_parts/cell/beam_rifle/corrupt()
return
/obj/item/stock_parts/cell/beam_rifle/emp_act(severity)
. = ..()
if(. & EMP_PROTECT_SELF)
return
charge = clamp((charge-(1000 * severity)),0,maxcharge)
/obj/item/stock_parts/cell/emergency_light
name = "miniature power cell"
desc = "A tiny power cell with a very low power capacity. Used in light fixtures to power them in the event of an outage."
maxcharge = 120 //Emergency lights use 0.2 W per tick, meaning ~10 minutes of emergency power from a cell
materials = list(/datum/material/glass = 20)
w_class = WEIGHT_CLASS_TINY
/obj/item/stock_parts/cell/emergency_light/Initialize(mapload)
. = ..()
var/area/A = get_area(src)
if(!A.lightswitch || !A.light_power)
charge = 0 //For naturally depowered areas, we start with no power
/obj/item/stock_parts/cell/crystal_cell
name = "crystal power cell"
desc = "A very high power cell made from crystallized plasma"
icon_state = "crystal_cell"
maxcharge = 50000
chargerate = 0
custom_materials = null
grind_results = null
rating = 5
/obj/item/stock_parts/cell/crystal_cell/give(amount)
return //no cheating