/
hfr_procs.dm
638 lines (566 loc) · 22.2 KB
/
hfr_procs.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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
/**
* This section contain all procs that helps building, destroy and control the hfr
*/
/**
* Called by multitool_act() in hfr_parts.dm, by atmos_process() in hfr_main_processes.dm and by fusion_process() in the same file
* This proc checks the surrounding of the core to ensure that the machine has been build correctly, returns false if there is a missing piece/wrong placed one
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/check_part_connectivity()
. = TRUE
if(!anchored || panel_open)
return FALSE
for(var/obj/machinery/hypertorus/object in orange(1,src))
if(. == FALSE)
break
if(object.panel_open)
. = FALSE
if(istype(object,/obj/machinery/hypertorus/corner))
var/dir = get_dir(src,object)
if(dir in GLOB.cardinals)
. = FALSE
switch(dir)
if(SOUTHEAST)
if(object.dir != SOUTH)
. = FALSE
if(SOUTHWEST)
if(object.dir != WEST)
. = FALSE
if(NORTHEAST)
if(object.dir != EAST)
. = FALSE
if(NORTHWEST)
if(object.dir != NORTH)
. = FALSE
corners |= object
continue
if(get_step(object,REVERSE_DIR(object.dir)) != loc)
. = FALSE
if(istype(object,/obj/machinery/hypertorus/interface))
if(linked_interface && linked_interface != object)
. = FALSE
linked_interface = object
for(var/obj/machinery/atmospherics/components/unary/hypertorus/object in orange(1,src))
if(. == FALSE)
break
if(object.panel_open)
. = FALSE
if(get_step(object,REVERSE_DIR(object.dir)) != loc)
. = FALSE
if(istype(object,/obj/machinery/atmospherics/components/unary/hypertorus/fuel_input))
if(linked_input && linked_input != object)
. = FALSE
linked_input = object
machine_parts |= object
if(istype(object,/obj/machinery/atmospherics/components/unary/hypertorus/waste_output))
if(linked_output && linked_output != object)
. = FALSE
linked_output = object
machine_parts |= object
if(istype(object,/obj/machinery/atmospherics/components/unary/hypertorus/moderator_input))
if(linked_moderator && linked_moderator != object)
. = FALSE
linked_moderator = object
machine_parts |= object
if(!linked_interface || !linked_input || !linked_moderator || !linked_output || corners.len != 4)
. = FALSE
/**
* Called by multitool_act() in hfr_parts.dm
* It sets the pieces to active, allowing the player to start the main reaction
* Arguments:
* * -user: the player doing the action
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/activate(mob/living/user)
if(active)
to_chat(user, span_notice("You already activated the machine."))
return
to_chat(user, span_notice("You link all parts toghether."))
active = TRUE
update_appearance()
linked_interface.active = TRUE
linked_interface.update_appearance()
RegisterSignal(linked_interface, COMSIG_QDELETING, PROC_REF(unregister_signals))
linked_input.active = TRUE
linked_input.update_appearance()
RegisterSignal(linked_input, COMSIG_QDELETING, PROC_REF(unregister_signals))
linked_output.active = TRUE
linked_output.update_appearance()
RegisterSignal(linked_output, COMSIG_QDELETING, PROC_REF(unregister_signals))
linked_moderator.active = TRUE
linked_moderator.update_appearance()
RegisterSignal(linked_moderator, COMSIG_QDELETING, PROC_REF(unregister_signals))
for(var/obj/machinery/hypertorus/corner/corner in corners)
corner.active = TRUE
corner.update_appearance()
RegisterSignal(corner, COMSIG_QDELETING, PROC_REF(unregister_signals))
soundloop = new(src, TRUE)
soundloop.volume = 5
/**
* Called when a part gets deleted around the hfr, called on Destroy() of the hfr core in hfr_core.dm
* Unregister the signals attached to the core from the various machines, if only_signals is false it will also call deactivate()
* Arguments:
* * only_signals: default FALSE, if true the proc will not call the deactivate() proc
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/unregister_signals(only_signals = FALSE)
SIGNAL_HANDLER
if(linked_interface)
UnregisterSignal(linked_interface, COMSIG_QDELETING)
if(linked_input)
UnregisterSignal(linked_input, COMSIG_QDELETING)
if(linked_output)
UnregisterSignal(linked_output, COMSIG_QDELETING)
if(linked_moderator)
UnregisterSignal(linked_moderator, COMSIG_QDELETING)
for(var/obj/machinery/hypertorus/corner/corner in corners)
UnregisterSignal(corner, COMSIG_QDELETING)
if(!only_signals)
deactivate()
/**
* Called by unregister_signals() in this file, called when the main fusion processes check_part_connectivity() returns false
* Deactivate the various machines by setting the active var to false, updates the machines icon and set the linked machine vars to null
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/deactivate()
if(!active)
return
active = FALSE
update_appearance()
if(linked_interface)
linked_interface.active = FALSE
linked_interface.update_appearance()
linked_interface = null
if(linked_input)
linked_input.active = FALSE
linked_input.update_appearance()
linked_input = null
if(linked_output)
linked_output.active = FALSE
linked_output.update_appearance()
linked_output = null
if(linked_moderator)
linked_moderator.active = FALSE
linked_moderator.update_appearance()
linked_moderator = null
if(corners.len)
for(var/obj/machinery/hypertorus/corner/corner in corners)
corner.active = FALSE
corner.update_appearance()
corners = list()
QDEL_NULL(soundloop)
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/assert_gases()
//Assert the gases that will be used/created during the process
internal_fusion.assert_gas(/datum/gas/antinoblium)
moderator_internal.assert_gases(arglist(GLOB.meta_gas_info))
if (!selected_fuel)
return
internal_fusion.assert_gases(arglist(selected_fuel.requirements | selected_fuel.primary_products))
/**
* Updates all related pipenets from all connected components
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/update_pipenets()
update_parents()
linked_input.update_parents()
linked_output.update_parents()
linked_moderator.update_parents()
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/update_temperature_status(seconds_per_tick)
fusion_temperature_archived = fusion_temperature
fusion_temperature = internal_fusion.temperature
moderator_temperature_archived = moderator_temperature
moderator_temperature = moderator_internal.temperature
coolant_temperature_archived = coolant_temperature
coolant_temperature = airs[1].temperature
output_temperature_archived = output_temperature
output_temperature = linked_output.airs[1].temperature
temperature_period = seconds_per_tick
//Set the power level of the fusion process
switch(fusion_temperature)
if(-INFINITY to 500)
power_level = 0
if(500 to 1e3)
power_level = 1
if(1e3 to 1e4)
power_level = 2
if(1e4 to 1e5)
power_level = 3
if(1e5 to 1e6)
power_level = 4
if(1e6 to 1e7)
power_level = 5
else
power_level = 6
/**
* Infrequently plays accent sounds, and adjusts main loop parameters
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/play_ambience()
// We play delam/neutral sounds at a rate determined by power and critical_threshold_proximity
if(last_accent_sound < world.time && prob(20))
var/aggression = min(((critical_threshold_proximity / 800) * ((power_level) / 5)), 1.0) * 100
if(critical_threshold_proximity >= 300)
playsound(src, SFX_HYPERTORUS_MELTING, max(50, aggression), FALSE, 40, 30, falloff_distance = 10)
else
playsound(src, SFX_HYPERTORUS_CALM, max(50, aggression), FALSE, 25, 25, falloff_distance = 10)
var/next_sound = round((100 - aggression) * 5) + 5
last_accent_sound = world.time + max(HYPERTORUS_ACCENT_SOUND_MIN_COOLDOWN, next_sound)
var/ambient_hum = 1
if (check_fuel())
ambient_hum = power_level + 1
soundloop.volume = clamp(ambient_hum * 8, 0, 50)
/**
* Called by the main fusion processes in hfr_main_processes.dm
* Getter for fusion fuel moles
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/check_fuel()
if(!selected_fuel)
return FALSE
if(!internal_fusion.total_moles())
return FALSE
for(var/gas_type in selected_fuel.requirements)
internal_fusion.assert_gas(gas_type)
if(internal_fusion.gases[gas_type][MOLES] < FUSION_MOLE_THRESHOLD)
return FALSE
return TRUE
/**
* Called by the main fusion processes in hfr_main_processes.dm
* Check the power use of the machine, return TRUE if there is enough power in the powernet
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/check_power_use()
if(machine_stat & (NOPOWER|BROKEN))
return FALSE
if(use_power == ACTIVE_POWER_USE)
update_mode_power_usage(ACTIVE_POWER_USE, (power_level + 1) * MIN_POWER_USAGE) //Max around 350 KW
return TRUE
///Checks if the gases in the input are the ones needed by the recipe
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/check_gas_requirements()
var/datum/gas_mixture/contents = linked_input.airs[1]
for(var/gas_type in selected_fuel.requirements)
if(!contents.gases[gas_type] || !contents.gases[gas_type][MOLES])
return FALSE
return TRUE
///Removes the gases from the internal gasmix when the recipe is changed
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/dump_gases()
var/datum/gas_mixture/remove = internal_fusion.remove(internal_fusion.total_moles())
linked_output.airs[1].merge(remove)
internal_fusion.garbage_collect()
linked_input.airs[1].garbage_collect()
/**
* Called by alarm() in this file
* Check the integrity level and returns the status of the machine
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/get_status()
var/integrity = get_integrity_percent()
if(integrity < HYPERTORUS_MELTING_PERCENT)
return HYPERTORUS_MELTING
if(integrity < HYPERTORUS_EMERGENCY_PERCENT)
return HYPERTORUS_EMERGENCY
if(integrity < HYPERTORUS_DANGER_PERCENT)
return HYPERTORUS_DANGER
if(integrity < HYPERTORUS_WARNING_PERCENT)
return HYPERTORUS_WARNING
if(power_level > 0)
return HYPERTORUS_NOMINAL
return HYPERTORUS_INACTIVE
/**
* Called by check_alert() in this file
* Play a sound from the machine, the type depends on the status of the hfr
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/alarm()
switch(get_status())
if(HYPERTORUS_MELTING)
playsound(src, 'sound/misc/bloblarm.ogg', 100, FALSE, 40, 30, falloff_distance = 10)
if(HYPERTORUS_EMERGENCY)
playsound(src, 'sound/machines/engine_alert1.ogg', 100, FALSE, 30, 30, falloff_distance = 10)
if(HYPERTORUS_DANGER)
playsound(src, 'sound/machines/engine_alert2.ogg', 100, FALSE, 30, 30, falloff_distance = 10)
if(HYPERTORUS_WARNING)
playsound(src, 'sound/machines/terminal_alert.ogg', 75)
/**
* Getter for the machine integrity
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/get_integrity_percent()
var/integrity = critical_threshold_proximity / melting_point
integrity = round(100 - integrity * 100, 0.01)
integrity = integrity < 0 ? 0 : integrity
return integrity
/**
* Get how charged the area's APC is
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/get_area_cell_percent()
// Make sure to get APC levels from the same area the core draws from
// Just in case people build an HFR across boundaries
var/area/area = get_area(src)
if (!area)
return 0
var/obj/machinery/power/apc/apc = area.apc
if (!apc)
return 0
var/obj/item/stock_parts/cell/cell = apc.cell
if (!cell)
return 0
return cell.percent()
/**
* Called by process_atmos() in hfr_main_processes.dm
* Called after checking the damage of the machine, calls alarm() and countdown()
* Broadcast messages into engi and common radio
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/check_alert()
if(critical_threshold_proximity < warning_point)
return
if((REALTIMEOFDAY - lastwarning) / 10 >= WARNING_TIME_DELAY)
alarm()
if(critical_threshold_proximity > emergency_point)
radio.talk_into(src, "[emergency_alert] Integrity: [get_integrity_percent()]%", common_channel)
lastwarning = REALTIMEOFDAY
if(!has_reached_emergency)
investigate_log("has reached the emergency point for the first time.", INVESTIGATE_HYPERTORUS)
message_admins("[src] has reached the emergency point [ADMIN_JMP(src)].")
has_reached_emergency = TRUE
send_radio_explanation()
else if(critical_threshold_proximity >= critical_threshold_proximity_archived) // The damage is still going up
radio.talk_into(src, "[warning_alert] Integrity: [get_integrity_percent()]%", engineering_channel)
lastwarning = REALTIMEOFDAY - (WARNING_TIME_DELAY * 5)
send_radio_explanation()
else // Phew, we're safe
radio.talk_into(src, "[safe_alert] Integrity: [get_integrity_percent()]%", engineering_channel)
lastwarning = REALTIMEOFDAY
//Melt
if(critical_threshold_proximity > melting_point)
countdown()
/obj/machinery/atmospherics/components/unary/hypertorus/core/emp_act(severity)
. = ..()
if (. & EMP_PROTECT_SELF)
return
warning_damage_flags |= HYPERTORUS_FLAG_EMPED
/**
* Called by check_alert() in this file
* Called to explain in radio what the issues are with the HFR
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/send_radio_explanation()
if(warning_damage_flags & HYPERTORUS_FLAG_EMPED)
var/list/characters = list()
characters += GLOB.alphabet
characters += GLOB.alphabet_upper
characters += GLOB.numerals
characters += GLOB.space
characters += GLOB.space //double the amount of them
var/message = random_string(rand(50,70), characters)
radio.talk_into(src, "[message]", engineering_channel)
return
if(warning_damage_flags & HYPERTORUS_FLAG_HIGH_POWER_DAMAGE)
radio.talk_into(src, "Warning! Shield destabilizing due to excessive power!", engineering_channel)
if(warning_damage_flags & HYPERTORUS_FLAG_IRON_CONTENT_DAMAGE)
radio.talk_into(src, "Warning! Iron shards are damaging the internal core shielding!", engineering_channel)
if(warning_damage_flags & HYPERTORUS_FLAG_HIGH_FUEL_MIX_MOLE)
radio.talk_into(src, "Warning! Fuel mix moles reaching critical levels!", engineering_channel)
if(warning_damage_flags & HYPERTORUS_FLAG_IRON_CONTENT_INCREASE)
radio.talk_into(src, "Warning! Iron amount inside the core is increasing!", engineering_channel)
/**
* Called by check_alert() in this file
* Called when the damage has reached critical levels, start the countdown before the destruction, calls meltdown()
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/countdown()
set waitfor = FALSE
if(final_countdown) // We're already doing it go away
return
final_countdown = TRUE
var/critical = selected_fuel.meltdown_flags & HYPERTORUS_FLAG_CRITICAL_MELTDOWN
if(critical)
priority_announce("WARNING - The explosion will likely cover a big part of the station and the coming EMP will wipe out most of the electronics. \
Get as far away as possible from the reactor or find a way to shut it down.", "Alert", 'sound/misc/notice3.ogg')
var/speaking = "[emergency_alert] The Hypertorus fusion reactor has reached critical integrity failure. Emergency magnetic dampeners online."
radio.talk_into(src, speaking, common_channel, language = get_selected_language())
notify_ghosts(
"The [src] has begun melting down!",
source = src,
header = "Meltdown Incoming",
ghost_sound = 'sound/machines/warning-buzzer.ogg',
notify_volume = 75,
)
for(var/i in HYPERTORUS_COUNTDOWN_TIME to 0 step -10)
if(critical_threshold_proximity < melting_point) // Cutting it a bit close there engineers
radio.talk_into(src, "[safe_alert] Failsafe has been disengaged.", common_channel)
final_countdown = FALSE
return
else if((i % 50) != 0 && i > 50) // A message once every 5 seconds until the final 5 seconds which count down individualy
sleep(1 SECONDS)
continue
else if(i > 50)
if(i == 10 SECONDS && critical)
sound_to_playing_players('sound/machines/hypertorus/HFR_critical_explosion.ogg')
speaking = "[DisplayTimeText(i, TRUE)] remain before total integrity failure."
else
speaking = "[i*0.1]..."
radio.talk_into(src, speaking, common_channel)
sleep(1 SECONDS)
meltdown()
/**
* Called by countdown() in this file
* Create the explosion + the gas emission before deleting the machine core.
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/meltdown()
var/flash_explosion = 0
var/light_impact_explosion = 0
var/heavy_impact_explosion = 0
var/devastating_explosion = 0
var/em_pulse = selected_fuel.meltdown_flags & HYPERTORUS_FLAG_EMP
var/rad_pulse = selected_fuel.meltdown_flags & HYPERTORUS_FLAG_RADIATION_PULSE
var/emp_light_size = 0
var/emp_heavy_size = 0
var/rad_pulse_size = 0
var/gas_spread = 0
var/gas_pockets = 0
var/critical = selected_fuel.meltdown_flags & HYPERTORUS_FLAG_CRITICAL_MELTDOWN
if(selected_fuel.meltdown_flags & HYPERTORUS_FLAG_BASE_EXPLOSION)
flash_explosion = power_level * 3
light_impact_explosion = power_level * 2
if(selected_fuel.meltdown_flags & HYPERTORUS_FLAG_MEDIUM_EXPLOSION)
flash_explosion = power_level * 6
light_impact_explosion = power_level * 5
heavy_impact_explosion = power_level * 0.5
if(selected_fuel.meltdown_flags & HYPERTORUS_FLAG_DEVASTATING_EXPLOSION)
flash_explosion = power_level * 8
light_impact_explosion = power_level * 7
heavy_impact_explosion = power_level * 2
devastating_explosion = power_level
if(selected_fuel.meltdown_flags & HYPERTORUS_FLAG_MINIMUM_SPREAD)
if(em_pulse)
emp_light_size = power_level * 3
emp_heavy_size = power_level * 1
if(rad_pulse)
rad_pulse_size = 2 * power_level + 8
gas_pockets = 5
gas_spread = power_level * 2
if(selected_fuel.meltdown_flags & HYPERTORUS_FLAG_MEDIUM_SPREAD)
if(em_pulse)
emp_light_size = power_level * 5
emp_heavy_size = power_level * 3
if(rad_pulse)
rad_pulse_size = power_level + 24
gas_pockets = 7
gas_spread = power_level * 4
if(selected_fuel.meltdown_flags & HYPERTORUS_FLAG_BIG_SPREAD)
if(em_pulse)
emp_light_size = power_level * 7
emp_heavy_size = power_level * 5
if(rad_pulse)
rad_pulse_size = power_level + 34
gas_pockets = 10
gas_spread = power_level * 6
if(selected_fuel.meltdown_flags & HYPERTORUS_FLAG_MASSIVE_SPREAD)
if(em_pulse)
emp_light_size = power_level * 9
emp_heavy_size = power_level * 7
if(rad_pulse)
rad_pulse_size = power_level + 44
gas_pockets = 15
gas_spread = power_level * 8
var/list/around_turfs = circle_range_turfs(src, gas_spread)
for(var/turf/turf as anything in around_turfs)
if(isclosedturf(turf) || isspaceturf(turf))
around_turfs -= turf
continue
var/datum/gas_mixture/remove_fusion
if(internal_fusion.total_moles() > 0)
remove_fusion = internal_fusion.remove_ratio(0.2)
var/datum/gas_mixture/remove
for(var/i in 1 to gas_pockets)
remove = remove_fusion.remove_ratio(1/gas_pockets)
var/turf/local = pick(around_turfs)
local.assume_air(remove)
loc.assume_air(internal_fusion)
var/datum/gas_mixture/remove_moderator
if(moderator_internal.total_moles() > 0)
remove_moderator = moderator_internal.remove_ratio(0.2)
var/datum/gas_mixture/remove
for(var/i in 1 to gas_pockets)
remove = remove_moderator.remove_ratio(1/gas_pockets)
var/turf/local = pick(around_turfs)
local.assume_air(remove)
loc.assume_air(moderator_internal)
//Max explosion ranges: devastation = 12, heavy = 24, light = 42
explosion(
origin = src,
devastation_range = critical ? devastating_explosion * 2 : devastating_explosion,
heavy_impact_range = critical ? heavy_impact_explosion * 2 : heavy_impact_explosion,
light_impact_range = light_impact_explosion,
flash_range = flash_explosion,
adminlog = TRUE,
ignorecap = TRUE
)
if(rad_pulse)
radiation_pulse(
source = loc,
max_range = rad_pulse_size,
threshold = 0.05,
)
if(em_pulse)
empulse(
epicenter = loc,
heavy_range = critical ? emp_heavy_size * 2 : emp_heavy_size,
light_range = critical ? emp_light_size * 2 : emp_heavy_size,
log = TRUE
)
qdel(src)
/*
* HFR cracking related procs
*/
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/check_cracked_parts()
for(var/obj/machinery/atmospherics/components/unary/hypertorus/part in machine_parts)
if(part.cracked)
return TRUE
return FALSE
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/create_crack()
var/obj/machinery/atmospherics/components/unary/hypertorus/part = pick(machine_parts)
part.cracked = TRUE
part.update_appearance()
return part
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/spill_gases(obj/origin, datum/gas_mixture/target_mix, ratio)
var/datum/gas_mixture/remove_mixture = target_mix.remove_ratio(ratio)
var/turf/origin_turf = origin.loc
if(!origin_turf)
return
origin_turf.assume_air(remove_mixture)
/obj/machinery/atmospherics/components/unary/hypertorus/core/proc/check_spill(seconds_per_tick)
var/obj/machinery/atmospherics/components/unary/hypertorus/cracked_part = check_cracked_parts()
if (cracked_part)
// We have an existing crack
var/leak_rate
if (moderator_internal.return_pressure() < HYPERTORUS_MEDIUM_SPILL_PRESSURE)
// Not high pressure, but can still leak
if (!prob(HYPERTORUS_WEAK_SPILL_CHANCE))
return
leak_rate = HYPERTORUS_WEAK_SPILL_RATE
else if (moderator_internal.return_pressure() < HYPERTORUS_STRONG_SPILL_PRESSURE)
// Lots of gas in here, out we go
leak_rate = HYPERTORUS_MEDIUM_SPILL_RATE
else
// Gotta go fast
leak_rate = HYPERTORUS_STRONG_SPILL_RATE
spill_gases(cracked_part, moderator_internal, ratio = 1 - (1 - leak_rate) ** seconds_per_tick)
return
if (moderator_internal.total_moles() < HYPERTORUS_HYPERCRITICAL_MOLES)
return
cracked_part = create_crack()
// See if we do anything in the initial rupture
if (moderator_internal.return_pressure() < HYPERTORUS_MEDIUM_SPILL_PRESSURE)
return
if (moderator_internal.return_pressure() < HYPERTORUS_STRONG_SPILL_PRESSURE)
// Medium explosion on initial rupture
explosion(
origin = cracked_part,
devastation_range = 0,
heavy_impact_range = 0,
light_impact_range = 1,
flame_range = 3,
flash_range = 3
)
spill_gases(cracked_part, moderator_internal, ratio = HYPERTORUS_MEDIUM_SPILL_INITIAL)
return
// Enough pressure for a strong explosion. Oh dear, oh dear.
explosion(
origin = cracked_part,
devastation_range = 0,
heavy_impact_range = 1,
light_impact_range = 3,
flame_range = 5,
flash_range = 5
)
spill_gases(cracked_part, moderator_internal, ratio = HYPERTORUS_STRONG_SPILL_INITIAL)
return