-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
pt_laser.dm
583 lines (500 loc) · 18.1 KB
/
pt_laser.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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
#define PTLEFFICIENCY 0.1
#define PTLMINOUTPUT 1 MEGA WATT
/obj/machinery/power/pt_laser
name = "power transmission laser"
icon = 'icons/obj/pt_laser.dmi'
desc = "Generates a laser beam used to transmit power vast distances across space."
icon_state = "ptl"
density = 1
anchored = 1
dir = 4
bound_height = 96
bound_width = 96
var/range = 100 //how far the beam goes, set to max(world.maxx,world.maxy) in New()
var/output = 0 //power output of the beam
var/capacity = 1e15
var/charge = 0
var/charging = 0
var/load_last_tick = 0 //how much load did we put on the network last tick?
var/chargelevel = 0 //Power input
var/online = FALSE
var/obj/machinery/power/terminal/terminal = null
var/firing = FALSE //laser is currently active
var/list/laser_parts = list() //all the individual laser objects
var/list/laser_turfs = list() //every turf with a laser on it
var/list/affecting_mobs = list()//mobs in the path of the beam
var/list/blocking_objects = list() //the objects blocking the laser, if any
var/selling = FALSE
var/laser_process_counter = 0
var/input_number = 0
var/output_number = 0
var/input_multi = 1 //for kW, MW, GW etc
var/output_multi = 1e6
var/emagged = FALSE
var/lifetime_earnings = 0
var/excess = null //for tgui readout
var/is_charging = FALSE //for tgui readout
/obj/machinery/power/pt_laser/New()
..()
range = max(world.maxx,world.maxy)
SPAWN_DBG(0.5 SECONDS)
var/turf/origin = get_rear_turf()
if(!origin) return //just in case
dir_loop:
for(var/d in cardinal)
var/turf/T = get_step(origin, d)
for(var/obj/machinery/power/terminal/term in T)
if(term?.dir == turn(d, 180))
terminal = term
break dir_loop
if(!terminal)
status |= BROKEN
return
terminal.master = src
updateicon()
/obj/machinery/power/pt_laser/disposing()
for(var/obj/O in laser_parts)
qdel(O)
for(var/x_off = 0 to 2)
for(var/y_off = 0 to 2)
var/turf/T = locate(src.x + x_off,src.y + y_off,src.z)
if(T && prob(50))
make_cleanable( /obj/decal/cleanable/machine_debris,T)
..()
/obj/machinery/power/pt_laser/emag_act(var/mob/user, var/obj/item/card/emag/E)
if (src.emagged)
return 0
src.emagged = TRUE
if (user)
src.add_fingerprint(user)
src.visible_message("<span class='alert'>[src.name] looks a little wonky, as [user] has messed with the polarity using an electromagnetic card!</span>")
return 1
/obj/machinery/power/pt_laser/proc/updateicon(var/started_firing = 0)
overlays = null
if(status & BROKEN || charge == 0)
overlays += image('icons/obj/pt_laser.dmi', "unpowered")
return
if(load_last_tick > 0)
overlays += image('icons/obj/pt_laser.dmi', "green_light")
if(online)
overlays += image('icons/obj/pt_laser.dmi', "red_light")
if(started_firing)
overlays += image('icons/obj/pt_laser.dmi', "started_firing")
else if(firing)
overlays += image('icons/obj/pt_laser.dmi', "firing")
var/clevel = chargedisplay()
if(clevel == 6)
overlays += image('icons/obj/pt_laser.dmi', "charge_full")
else if(clevel>0)
overlays += image('icons/obj/pt_laser.dmi', "charge_[clevel]")
/obj/machinery/power/pt_laser/proc/chargedisplay()
if(!output)
return 0
return min(round((charge/abs(output))*6),6) //how close it is to firing power, not to capacity.
/obj/machinery/power/pt_laser/process(mult)
if(status & BROKEN)
return
//store machine state to see if we need to update the icon overlays
var/last_disp = chargedisplay()
var/last_onln = online
var/last_llt = load_last_tick
var/last_firing = firing
var/dont_update = 0
var/adj_output = abs(output)
if(terminal)
src.excess = (terminal.surplus() + load_last_tick) //otherwise the charge used by this machine last tick is counted against the charge available to it this tick aaaaaaaaaaaaaa
if(charging && src.excess >= src.chargelevel) // if there's power available, try to charge
var/load = min(capacity-charge, chargelevel) // charge at set rate, limited to spare capacity
charge += load * mult // increase the charge
add_load(load) // add the load to the terminal side network
load_last_tick = load
if (!src.is_charging) src.is_charging = TRUE
else
load_last_tick = 0
if (src.is_charging) src.is_charging = FALSE
if( charge > adj_output*mult)
adj_output *= mult
if(online) // if it's switched on
if(!firing) //not firing
if(charge >= adj_output && (adj_output >= PTLMINOUTPUT)) //have power to fire
if(laser_parts.len == 0)
start_firing() //creates all the laser objects then activates the right ones
else
restart_firing() //if the laser was created already, just activate the existing objects
dont_update = 1 //so the firing animation runs
charge -= adj_output
if(selling)
power_sold()
else if(charge < adj_output && (adj_output >= PTLMINOUTPUT)) //firing but not enough charge to sustain
stop_firing()
else //firing and have enough power to carry on
for(var/mob/living/L in affecting_mobs) //has to happen every tick
if(burn_living(L,adj_output*PTLEFFICIENCY)) //returns 1 if they are gibbed, 0 otherwise
affecting_mobs -= L
if(laser_process_counter > 9)
process_laser() //fine if it happens less often, just tile burning and hotspot exposure
laser_process_counter = 0
else
laser_process_counter ++
charge -= adj_output
if(selling)
power_sold(adj_output)
else if(blocking_objects.len > 0)
melt_blocking_objects()
update_laser()
// only update icon if state changed
if(dont_update == 0 && (last_firing != firing || last_disp != chargedisplay() || last_onln != online || ((last_llt > 0 && load_last_tick == 0) || (last_llt == 0 && load_last_tick > 0))))
updateicon()
/obj/machinery/power/pt_laser/proc/power_sold(adjusted_output)
if (round(adjusted_output) == 0)
return FALSE
var/output_mw = adjusted_output / 1e6
#define BUX_PER_SEC_CAP 5000 //at inf power, generate 5000$/tick, also max amt to drain/tick
#define ACCEL_FACTOR 69 //our acceleration factor towards cap
#define STEAL_FACTOR 4 //Adjusts the curve of the stealing EQ (2nd deriv/concavity)
//For equation + explaination, https://www.desmos.com/calculator/62w5igbqwo
//Adjusted to give a decent amt. of cash/tick @ 50GW (said to be average hellburn)
var/generated_moolah = (2*output_mw*BUX_PER_SEC_CAP)/(2*output_mw + BUX_PER_SEC_CAP*ACCEL_FACTOR) //used if output_mw > 0
if (output_mw < 0) //steals money since you emagged it
generated_moolah = (-2*output_mw*BUX_PER_SEC_CAP)/(2*STEAL_FACTOR*output_mw - BUX_PER_SEC_CAP*STEAL_FACTOR*ACCEL_FACTOR)
lifetime_earnings += generated_moolah
var/list/accounts = list()
for(var/datum/data/record/t in data_core.bank)
if(t.fields["job"] == "Chief Engineer")
accounts += t
accounts += t //fuck it
else if(t.fields["job"] == "Engineer")
accounts += t
if(abs(generated_moolah) >= accounts.len*2) //otherwise not enough to split evenly so don't bother I guess
wagesystem.station_budget += round(generated_moolah/2)
generated_moolah -= round(generated_moolah/2) //no coming up with $$$ out of air!
for(var/datum/data/record/t in accounts)
t.fields["current_money"] += round(generated_moolah/accounts.len)
#undef STEAL_FACTOR
#undef ACCEL_FACTOR
#undef BUX_PER_SEC_CAP
/obj/machinery/power/pt_laser/proc/get_barrel_turf()
var/x_off = 0
var/y_off = 0
switch(dir)
if(1)
x_off = 1
y_off = 2
if(2)
x_off = 1
y_off = 0
if(4)
x_off = 2
y_off = 1
if(8)
x_off = 0
y_off = 1
var/turf/T = locate(src.x + x_off,src.y + y_off,src.z)
return T
/obj/machinery/power/pt_laser/proc/get_rear_turf()
var/x_off = 0
var/y_off = 0
switch(dir)
if(1)
x_off = 1
y_off = 0
if(2)
x_off = 1
y_off = 2
if(4)
x_off = 0
y_off = 1
if(8)
x_off = 2
y_off = 1
var/turf/T = locate(src.x + x_off,src.y + y_off,src.z)
return T
/obj/machinery/power/pt_laser/proc/start_firing()
var/turf/T = get_barrel_turf()
if(!T) return //just in case
firing = 1
updateicon(1)
for(var/dist = 0, dist < range, dist += 1) // creates each field tile
T = get_step(T, dir)
if(!T) break //edge of the map
var/obj/lpt_laser/laser = new/obj/lpt_laser(T)
laser.set_dir(dir)
laser.power = round(abs(output)*PTLEFFICIENCY)
laser.source = src
laser.active = 0
src.laser_parts += laser
src.laser_turfs += T
melt_blocking_objects()
update_laser()
/obj/machinery/power/pt_laser/proc/restart_firing()
firing = 1
updateicon(1)
melt_blocking_objects()
update_laser()
/obj/machinery/power/pt_laser/proc/check_laser_active() //returns number of laser_parts that should be active starting at top of list
blocking_objects = list()
var/turf/T = get_barrel_turf()
if(!T) return //just in case
for(var/dist = 0, dist < range, dist += 1)
T = get_step(T, dir)
if(!T || T.density)
if(!istype(T, /turf/unsimulated/wall/trench)) return dist
for(var/obj/O in T)
if(!istype(O,/obj/window) && !istype(O,/obj/grille) && !ismob(O) && O.density)
blocking_objects += O
if(blocking_objects.len > 0) return dist
/obj/machinery/power/pt_laser/proc/stop_firing()
for(var/obj/lpt_laser/L in laser_parts)
L.invisibility = 101 //make it invisible
L.active = 0
L.light.disable()
affecting_mobs = list()
selling = 0
firing = 0
blocking_objects = list()
/obj/machinery/power/pt_laser/proc/update_laser()
firing = 1
var/active_num = check_laser_active()
var/counter = 1
for(var/obj/lpt_laser/L in laser_parts)
if(counter <= active_num)
L.invisibility = 0 //make it visible
L.alpha = clamp(((log(10, L.power) - 5) * (255 / 5)), 50, 255) //50 at ~1e7 255 at 1e11 power, the point at which the laser's most deadly effect happens
L.active = 1
L.light.enable()
L.burn_all_living_contents()
counter++
else
L.invisibility = 101
L.active = 0
L.light.disable()
if(active_num == laser_parts.len)
selling = 1
/obj/machinery/power/pt_laser/proc/melt_blocking_objects()
for (var/obj/O in blocking_objects)
if (istype(O, /obj/machinery/door/poddoor))
continue
else if (prob((abs(output)*PTLEFFICIENCY)/5e5))
O.visible_message("<b>[O.name] is melted away by the [src]!</b>")
qdel(O)
/obj/machinery/power/pt_laser/add_load(var/amount)
if(terminal?.powernet)
terminal.powernet.newload += amount
/obj/machinery/power/pt_laser/proc/update_laser_power()
//only call stop_firing() if output setting is hire than charge, and if we are actually firing
if(src.firing && (abs(src.output) > src.charge))
stop_firing()
for(var/obj/lpt_laser/L in laser_parts)
L.power = round(abs(src.output)*PTLEFFICIENCY)
L.alpha = clamp(((log(10, L.power) - 5) * (255 / 5)), 50, 255) //50 at ~1e7 255 at 1e11 power, the point at which the laser's most deadly effect happens
/obj/machinery/power/pt_laser/ui_interact(mob/user, datum/tgui/ui)
ui = tgui_process.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "PowerTransmissionLaser")
ui.open()
/obj/machinery/power/pt_laser/ui_data(mob/user)
. = list(
"capacity" = src.capacity,
"charge" = src.charge,
"isEmagged" = src.emagged,
"isChargingEnabled" = src.charging,
"excessPower" = src.excess,
"gridLoad" = src.terminal?.powernet.load,
"inputLevel" = src.chargelevel,
"inputMultiplier" = src.input_multi,
"inputNumber" = src.input_number,
"isCharging" = src.is_charging,
"isFiring" = src.firing,
"isLaserEnabled" = src.online,
"lifetimeEarnings" = src.lifetime_earnings,
"name" = src.name,
"outputLevel" = src.output,
"outputMultiplier" = src.output_multi,
"outputNumber" = src.output_number,
"totalGridPower" = src.terminal?.powernet.avail,
)
/obj/machinery/power/pt_laser/ui_act(action, params)
. = ..()
if (.)
return
switch(action)
//Input controls
if("toggleInput")
src.charging = !src.charging
. = TRUE
if("setInput")
src.input_number = clamp(params["setInput"], 0, 999)
src.chargelevel = src.input_number * src.input_multi
. = TRUE
if("inputW")
src.input_multi = 1 WATT
src.chargelevel = src.input_number * src.input_multi
. = TRUE
if("inputkW")
src.input_multi = 1 KILO WATT
src.chargelevel = src.input_number * src.input_multi
. = TRUE
if("inputMW")
src.input_multi = 1 MEGA WATT
src.chargelevel = src.input_number * src.input_multi
. = TRUE
if("inputGW")
src.input_multi = 1 GIGA WATT
src.chargelevel = src.input_number * src.input_multi
. = TRUE
if("inputTW")
src.input_multi = 1 TERA WATT
src.chargelevel = src.input_number * src.input_multi
. = TRUE
//Output controls
if("toggleOutput")
src.online = !src.online
if(!online) src.stop_firing()
. = TRUE
if("setOutput")
if (src.emagged)
src.output_number = clamp(params["setOutput"], -999, 999)
else
src.output_number = clamp(params["setOutput"], 0, 999)
src.output = src.output_number * src.output_multi
if(!src.output)
src.stop_firing()
src.update_laser_power()
. = TRUE
if("outputMW")
src.output_multi = 1 MEGA WATT
src.output = src.output_number * src.output_multi
src.update_laser_power()
. = TRUE
if("outputGW")
src.output_multi = 1 GIGA WATT
src.output = src.output_number * src.output_multi
src.update_laser_power()
. = TRUE
if("outputTW")
src.output_multi = 1 TERA WATT
src.output = src.output_number * src.output_multi
src.update_laser_power()
. = TRUE
/obj/machinery/power/pt_laser/ex_act(severity)
switch(severity)
if(1.0)
qdel(src)
if(2.0)
if (prob(50))
status |= BROKEN
updateicon()
if(3.0)
if (prob(25))
status |= BROKEN
updateicon()
return
/obj/machinery/power/pt_laser/proc/process_laser()
if(output == 0) return
var/power = abs(output)*PTLEFFICIENCY
for(var/turf/T in laser_turfs)
if(power > 5e7)
T.hotspot_expose(power/1e5,5) //1000K at 100MW
if(istype(T, /turf/simulated/floor) && prob(power/1e5))
T:burn_tile()
/obj/lpt_laser
name = "laser"
desc = "A powerful laser beam."
icon = 'icons/obj/power.dmi'
icon_state = "ptl_beam"
anchored = 2
density = 0
luminosity = 1
invisibility = 101
event_handler_flags = USE_HASENTERED | USE_FLUID_ENTER
var/power = 0
var/active = 1
var/obj/machinery/power/pt_laser/source = null
var/datum/light/light
/obj/lpt_laser/New()
light = new /datum/light/point
light.attach(src)
light.set_color(0, 0.8, 0.1)
light.set_brightness(0.4)
light.set_height(0.5)
light.enable()
SPAWN_DBG(0)
alpha = clamp(((log(10, src.power) - 5) * (255 / 5)), 50, 255) //50 at ~1e7 255 at 1e11 power, the point at which the laser's most deadly effect happens
if(active)
if(istype(src.loc, /turf) && power > 5e7)
src.loc:hotspot_expose(power/1e5,5) //1000K at 100MW
if(istype(src.loc, /turf/simulated/floor) && prob(power/1e6))
src.loc:burn_tile()
for (var/mob/living/L in src.loc)
if (isintangible(L))
continue
if (!burn_living(L,power) && source) //burn_living() returns 1 if they are gibbed, 0 otherwise
if (!source.affecting_mobs.Find(L))
source.affecting_mobs.Add(L)
..()
/obj/lpt_laser/ex_act(severity)
return
/obj/lpt_laser/HasEntered(var/atom/movable/AM)
if (src.active && isliving(AM) && !isintangible(AM))
if (!burn_living(AM,power) && source) //burn_living() returns 1 if they are gibbed, 0 otherwise
if (!source.affecting_mobs.Find(AM))
source.affecting_mobs.Add(AM)
/obj/lpt_laser/Uncrossed(var/atom/movable/AM)
if(isliving(AM) && source)
source.affecting_mobs -= AM
/obj/lpt_laser/proc/burn_all_living_contents()
for(var/mob/living/L in src.loc)
if(burn_living(L,power) && source) //returns 1 if they were gibbed
source.affecting_mobs -= L
/obj/proc/burn_living(var/mob/living/L,var/power = 0)
if(power < 10) return
if(isintangible(L)) return // somehow flocktraces are still getting destroyed by the laser. maybe this will fix it
if(prob(min(power/1e5,50)))
INVOKE_ASYNC(L, /mob/living.proc/emote, "scream") //might be spammy if they stand in it for ages, idk
if(L.dir == turn(src.dir,180) && ishuman(L)) //they're looking into the beam!
var/safety = 1
/* L:head:up broke for no reason so I had to rewrite it.
if (istype(L:head, /obj/item/clothing/head/helmet/welding))
if(!L:head:up)
safety = 8*/
var/mob/living/carbon/human/newL = L
if (istype(newL.glasses, /obj/item/clothing/glasses/thermal) || newL.eye_istype(/obj/item/organ/eye/cyber/thermal))
safety = 0.5
else if (istype(newL.glasses, /obj/item/clothing/glasses/nightvision) || newL.eye_istype(/obj/item/organ/eye/cyber/nightvision))
safety = 0.25
else if (istype(newL.head, /obj/item/clothing/head/helmet/welding) && !newL.head:up)
safety = 8
else if (istype(newL.head, /obj/item/clothing/head/helmet/space))
safety = 8
else if (istype(newL.glasses, /obj/item/clothing/glasses/sunglasses) || newL.eye_istype(/obj/item/organ/eye/cyber/sunglass))
safety = 2
boutput(L, "<span class='alert'>Your eyes are burned by the laser!</span>")
L.take_eye_damage(power/(safety*1e5)) //this will damage them a shitload at the sorts of power the laser will reach, as it should.
L.change_eye_blurry(rand(power / (safety * 2e5)), 50) //don't stare into 100MW lasers, kids
//this will probably need fiddling with, hard to decide on reasonable values
switch(power)
if(10 to 1e7)
L.set_burning(power/1e5) //100 (max burning) at 10MW
L.bodytemperature = max(power/1e4, L.bodytemperature) //1000K at 10MW. More than hotspot because it's hitting them not just radiating heat (i guess? idk)
if(1e7+1 to 5e8)
L.set_burning(100)
L.bodytemperature = max(power/1e4, L.bodytemperature)
L.TakeDamage("chest", 0, power/1e7) //ow
if(ishuman(L) && prob(min(power/1e7,50)))
var/limb = pick("l_arm","r_arm","l_leg","r_leg")
L:sever_limb(limb)
L.visible_message("<b>The [src.name] slices off one of [L.name]'s limbs!</b>")
if(5e8+1 to 1e11) //you really fucked up this time buddy
make_cleanable( /obj/decal/cleanable/ash,src.loc)
L.unlock_medal("For Your Ohm Good", 1)
L.visible_message("<b>[L.name] is vaporised by the [src]!</b>")
L.elecgib()
return 1 //tells the caller to remove L from the laser's affecting_mobs
if(1e11+1 to INFINITY) //you really, REALLY fucked up this time buddy
L.unlock_medal("For Your Ohm Good", 1)
L.visible_message("<b>[L.name] is detonated by the [src]!</b>")
L.blowthefuckup(min(1+round(power/1e12),20),0)
return 1 //tells the caller to remove L from the laser's affecting_mobs
return 0
#undef PTLEFFICIENCY
#undef PTLMINOUTPUT