/
life.dm
792 lines (665 loc) · 26.5 KB
/
life.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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
/mob/living/carbon/Life()
set invisibility = 0
if(notransform)
return
if(damageoverlaytemp)
damageoverlaytemp = 0
update_damage_hud()
//Just don't run if we're qdeleted already
if(QDELETED(src))
return ..()
if(!IS_IN_STASIS(src))
//Reagent processing needs to come before breathing, to prevent edge cases.
handle_organs()
. = ..()
if(QDELETED(src))
return
if(.) //not dead
handle_blood()
if(isLivingSSD())//if you're disconnected, you're going to sleep
if(AmountSleeping() < 20)
AdjustSleeping(20)//adjust every 10 seconds
if(stat != DEAD)
var/bprv = handle_bodyparts()
if(bprv & BODYPART_LIFE_UPDATE_HEALTH)
update_stamina() //needs to go before updatehealth to remove stamcrit
updatehealth()
if(stat != DEAD)
handle_brain_damage()
mothdust = max(0, mothdust - 1); //WS edit - moth dust when hugging
else
. = ..()
if(stat == DEAD)
stop_sound_channel(CHANNEL_HEARTBEAT)
check_cremation()
//Updates the number of stored chemicals for powers
handle_changeling()
if(stat != DEAD)
return 1
///////////////
// BREATHING //
///////////////
//Start of a breath chain, calls breathe()
/mob/living/carbon/handle_breathing(times_fired)
var/next_breath = 4
var/obj/item/organ/lungs/L = getorganslot(ORGAN_SLOT_LUNGS)
var/obj/item/organ/heart/H = getorganslot(ORGAN_SLOT_HEART)
if(L)
if(L.damage > L.high_threshold)
next_breath--
if(H)
if(H.damage > H.high_threshold)
next_breath--
if((times_fired % next_breath) == 0 || failed_last_breath)
breathe() //Breathe per 4 ticks if healthy, down to 2 if our lungs or heart are damaged, unless suffocating
if(failed_last_breath)
SEND_SIGNAL(src, COMSIG_ADD_MOOD_EVENT, "suffocation", /datum/mood_event/suffocation)
else
SEND_SIGNAL(src, COMSIG_CLEAR_MOOD_EVENT, "suffocation")
else
if(istype(loc, /obj/))
var/obj/location_as_object = loc
location_as_object.handle_internal_lifeform(src,0)
//Second link in a breath chain, calls check_breath()
/mob/living/carbon/proc/breathe()
var/obj/item/organ/lungs = getorganslot(ORGAN_SLOT_LUNGS)
if(reagents.has_reagent(/datum/reagent/toxin/lexorin, needs_metabolizing = TRUE))
return
if(istype(loc, /obj/machinery/atmospherics/components/unary/cryo_cell))
return
var/datum/gas_mixture/environment
if(loc)
environment = loc.return_air()
var/datum/gas_mixture/breath
if(!getorganslot(ORGAN_SLOT_BREATHING_TUBE))
if(health <= HEALTH_THRESHOLD_FULLCRIT || (pulledby && pulledby.grab_state >= GRAB_KILL) || HAS_TRAIT(src, TRAIT_MAGIC_CHOKE) || (lungs && lungs.organ_flags & ORGAN_FAILING))
losebreath++ //You can't breath at all when in critical or when being choked, so you're going to miss a breath
else if(health <= crit_threshold)
losebreath += 0.25 //You're having trouble breathing in soft crit, so you'll miss a breath one in four times
//Suffocate
if(losebreath >= 1) //You've missed a breath, take oxy damage
losebreath--
if(prob(10))
emote("gasp")
if(istype(loc, /obj/))
var/obj/loc_as_obj = loc
loc_as_obj.handle_internal_lifeform(src,0)
else
//Breathe from internal
breath = get_breath_from_internal(BREATH_VOLUME)
if(isnull(breath)) //in case of 0 pressure internals
if(isobj(loc)) //Breathe from loc as object
var/obj/loc_as_obj = loc
breath = loc_as_obj.handle_internal_lifeform(src, BREATH_VOLUME)
else if(isturf(loc)) //Breathe from loc as turf
var/breath_ratio = 0
if(environment)
breath_ratio = BREATH_VOLUME/environment.return_volume()
breath = loc.remove_air_ratio(breath_ratio)
else //Breathe from loc as obj again
if(istype(loc, /obj/))
var/obj/loc_as_obj = loc
loc_as_obj.handle_internal_lifeform(src,0)
if(breath)
breath.set_volume(BREATH_VOLUME)
check_breath(breath)
if(breath)
loc.assume_air(breath)
air_update_turf()
/mob/living/carbon/proc/has_smoke_protection()
if(HAS_TRAIT(src, TRAIT_NOBREATH))
return TRUE
return FALSE
//Third link in a breath chain, calls handle_breath_temperature()
/mob/living/carbon/proc/check_breath(datum/gas_mixture/breath)
if(status_flags & GODMODE)
return
if(HAS_TRAIT(src, TRAIT_NOBREATH))
return
var/obj/item/organ/lungs = getorganslot(ORGAN_SLOT_LUNGS)
if(!lungs)
adjustOxyLoss(2)
//CRIT
if(!breath || (breath.total_moles() == 0) || !lungs)
if(reagents.has_reagent(/datum/reagent/medicine/epinephrine, needs_metabolizing = TRUE) && lungs)
return
adjustOxyLoss(1)
failed_last_breath = 1
throw_alert("not_enough_oxy", /atom/movable/screen/alert/not_enough_oxy)
return 0
var/safe_oxy_min = 16
var/safe_co2_max = 10
var/safe_tox_max = 0.05
var/SA_para_min = 1
var/SA_sleep_min = 5
var/oxygen_used = 0
var/moles = breath.total_moles()
var/breath_pressure = (moles*R_IDEAL_GAS_EQUATION*breath.return_temperature())/BREATH_VOLUME
var/O2_partialpressure = ((breath.get_moles(GAS_O2)/moles)*breath_pressure) + (((breath.get_moles(GAS_PLUOXIUM)*8)/moles)*breath_pressure)
var/Toxins_partialpressure = (breath.get_moles(GAS_PLASMA)/moles)*breath_pressure
var/CO2_partialpressure = (breath.get_moles(GAS_CO2)/moles)*breath_pressure
//OXYGEN
if(O2_partialpressure < safe_oxy_min) //Not enough oxygen
if(prob(20))
emote("gasp")
if(O2_partialpressure > 0)
var/ratio = 1 - O2_partialpressure/safe_oxy_min
adjustOxyLoss(min(5*ratio, 3))
failed_last_breath = 1
oxygen_used = breath.get_moles(GAS_O2)*ratio
else
adjustOxyLoss(3)
failed_last_breath = 1
throw_alert("not_enough_oxy", /atom/movable/screen/alert/not_enough_oxy)
else //Enough oxygen
failed_last_breath = 0
if(health >= crit_threshold)
adjustOxyLoss(-5)
oxygen_used = breath.get_moles(GAS_O2)
clear_alert("not_enough_oxy")
breath.adjust_moles(GAS_O2, -oxygen_used)
breath.adjust_moles(GAS_CO2, oxygen_used)
//CARBON DIOXIDE
if(CO2_partialpressure > safe_co2_max)
if(!co2overloadtime)
co2overloadtime = world.time
else if(world.time - co2overloadtime > 120)
Unconscious(60)
adjustOxyLoss(3)
if(world.time - co2overloadtime > 300)
adjustOxyLoss(8)
if(prob(20))
emote("cough")
else
co2overloadtime = 0
//TOXINS/PLASMA
if(Toxins_partialpressure > safe_tox_max)
var/ratio = (breath.get_moles(GAS_PLASMA)/safe_tox_max) * 10
adjustToxLoss(clamp(ratio, MIN_TOXIC_GAS_DAMAGE, MAX_TOXIC_GAS_DAMAGE))
throw_alert("too_much_tox", /atom/movable/screen/alert/too_much_tox)
else
clear_alert("too_much_tox")
//NITROUS OXIDE
if(breath.get_moles(GAS_NITROUS))
var/SA_partialpressure = (breath.get_moles(GAS_NITROUS)/breath.total_moles())*breath_pressure
if(SA_partialpressure > SA_para_min)
Unconscious(60)
if(SA_partialpressure > SA_sleep_min)
Sleeping(max(AmountSleeping() + 40, 200))
else if(SA_partialpressure > 0.01)
if(prob(20))
emote(pick("giggle","laugh"))
SEND_SIGNAL(src, COMSIG_ADD_MOOD_EVENT, "chemical_euphoria", /datum/mood_event/chemical_euphoria)
if(SA_partialpressure > safe_tox_max*3)
var/ratio = (breath.get_moles(GAS_NITROUS)/safe_tox_max)
adjustToxLoss(clamp(ratio, MIN_TOXIC_GAS_DAMAGE, MAX_TOXIC_GAS_DAMAGE))
throw_alert("too_much_tox", /atom/movable/screen/alert/too_much_tox)
else
clear_alert("too_much_tox")
else
SEND_SIGNAL(src, COMSIG_CLEAR_MOOD_EVENT, "chemical_euphoria")
//BZ (Facepunch port of their Agent B)
if(breath.get_moles(GAS_BZ))
var/bz_partialpressure = (breath.get_moles(GAS_BZ)/breath.total_moles())*breath_pressure
if(bz_partialpressure > 1)
hallucination += 10
else if(bz_partialpressure > 0.01)
hallucination += 5
//TRITIUM
if(breath.get_moles(GAS_TRITIUM))
var/tritium_partialpressure = (breath.get_moles(GAS_TRITIUM)/breath.total_moles())*breath_pressure
radiation += tritium_partialpressure/10
//NITRYL
if(breath.get_moles(GAS_NITRYL))
var/nitryl_partialpressure = (breath.get_moles(GAS_NITRYL)/breath.total_moles())*breath_pressure
adjustFireLoss(nitryl_partialpressure/4)
//FREON
if(breath.get_moles(GAS_FREON))
var/freon_partialpressure = (breath.get_moles(GAS_FREON)/breath.total_moles())*breath_pressure
adjustFireLoss(freon_partialpressure * 0.25)
//BREATH TEMPERATURE
handle_breath_temperature(breath)
return 1
//Fourth and final link in a breath chain
/mob/living/carbon/proc/handle_breath_temperature(datum/gas_mixture/breath)
// The air you breathe out should match your body temperature
breath.set_temperature(bodytemperature)
/mob/living/carbon/proc/get_breath_from_internal(volume_needed)
//WS Port Begin - Citadel Internals
var/obj/item/clothing/check
var/internals = FALSE
for(check in GET_INTERNAL_SLOTS(src))
if(check.clothing_flags & ALLOWINTERNALS)
internals = TRUE
//WS Port End - Citadel Internals
if(internal)
if(internal.loc != src)
internal = null
update_internals_hud_icon(0)
else if (!internals && !getorganslot(ORGAN_SLOT_BREATHING_TUBE)) //WS Port - Citadel Internals
internal = null
update_internals_hud_icon(0)
else
update_internals_hud_icon(1)
. = internal.remove_air_volume(volume_needed)
if(!.)
return FALSE //to differentiate between no internals and active, but empty internals
/mob/living/carbon/proc/handle_blood()
return
/mob/living/carbon/proc/handle_bodyparts()
if(stam_regen_start_time <= world.time)
if(HAS_TRAIT_FROM(src, TRAIT_INCAPACITATED, STAMINA))
. |= BODYPART_LIFE_UPDATE_HEALTH //make sure we remove the stamcrit
for(var/obj/item/bodypart/BP as anything in bodyparts)
. |= BP.on_life()
/mob/living/carbon/proc/handle_organs()
if(stat != DEAD)
for(var/V in internal_organs)
var/obj/item/organ/O = V
if(O.owner) // This exist mostly because reagent metabolization can cause organ reshuffling
O.on_life()
else
if(reagents.has_reagent(/datum/reagent/toxin/formaldehyde, 1)) // No organ decay if the body contains formaldehyde.
return
for(var/V in internal_organs)
var/obj/item/organ/O = V
O.on_death() //Needed so organs decay while inside the body.
/mob/living/carbon/handle_diseases()
for(var/thing in diseases)
var/datum/disease/D = thing
if(prob(D.infectivity))
D.spread()
if(stat != DEAD || D.process_dead)
D.stage_act()
//todo generalize this and move hud out
/mob/living/carbon/proc/handle_changeling()
if(mind && hud_used && hud_used.lingchemdisplay)
var/datum/antagonist/changeling/changeling = mind.has_antag_datum(/datum/antagonist/changeling)
if(changeling)
changeling.regenerate()
hud_used.lingchemdisplay.invisibility = 0
hud_used.lingchemdisplay.maptext = "<div align='center' valign='middle' style='position:relative; top:0px; left:6px'><font color='#dd66dd'>[round(changeling.chem_charges)]</font></div>"
else
hud_used.lingchemdisplay.invisibility = INVISIBILITY_ABSTRACT
/mob/living/carbon/handle_mutations_and_radiation()
if(dna && dna.temporary_mutations.len)
for(var/mut in dna.temporary_mutations)
if(dna.temporary_mutations[mut] < world.time)
if(mut == UI_CHANGED)
if(dna.previous["UI"])
dna.uni_identity = merge_text(dna.uni_identity,dna.previous["UI"])
updateappearance(mutations_overlay_update=1)
dna.previous.Remove("UI")
dna.temporary_mutations.Remove(mut)
continue
if(mut == UE_CHANGED)
if(dna.previous["name"])
real_name = dna.previous["name"]
name = real_name
dna.previous.Remove("name")
if(dna.previous["UE"])
dna.unique_enzymes = dna.previous["UE"]
dna.previous.Remove("UE")
if(dna.previous["blood_type"])
dna.blood_type = dna.previous["blood_type"]
dna.previous.Remove("blood_type")
dna.temporary_mutations.Remove(mut)
continue
for(var/datum/mutation/human/HM in dna.mutations)
if(HM && HM.timed)
dna.remove_mutation(HM.type)
radiation -= min(radiation, RAD_LOSS_PER_TICK)
if(radiation > RAD_MOB_SAFE)
adjustToxLoss(log(radiation-RAD_MOB_SAFE)*RAD_TOX_COEFFICIENT)
/*
Alcohol Poisoning Chart
Note that all higher effects of alcohol poisoning will inherit effects for smaller amounts (i.e. light poisoning inherts from slight poisoning)
In addition, severe effects won't always trigger unless the drink is poisonously strong
All effects don't start immediately, but rather get worse over time; the rate is affected by the imbiber's alcohol tolerance
0: Non-alcoholic
1-10: Barely classifiable as alcohol - occassional slurring
11-20: Slight alcohol content - slurring
21-30: Below average - imbiber begins to look slightly drunk
31-40: Just below average - no unique effects
41-50: Average - mild disorientation, imbiber begins to look drunk
51-60: Just above average - disorientation, vomiting, imbiber begins to look heavily drunk
61-70: Above average - small chance of blurry vision, imbiber begins to look smashed
71-80: High alcohol content - blurry vision, imbiber completely shitfaced
81-90: Extremely high alcohol content - light brain damage, passing out
91-100: Dangerously toxic - swift death
*/
#define BALLMER_POINTS 5
//this updates all special effects: stun, sleeping, knockdown, druggy, stuttering, etc..
/mob/living/carbon/handle_status_effects()
..()
var/restingpwr = 1 + 4 * resting
//Dizziness
if(dizziness)
var/client/C = client
var/pixel_x_diff = 0
var/pixel_y_diff = 0
var/temp
var/saved_dizz = dizziness
if(C)
var/oldsrc = src
var/amplitude = dizziness*(sin(dizziness * world.time) + 1) // This shit is annoying at high strength
src = null
spawn(0)
if(C)
temp = amplitude * sin(saved_dizz * world.time)
pixel_x_diff += temp
C.pixel_x += temp
temp = amplitude * cos(saved_dizz * world.time)
pixel_y_diff += temp
C.pixel_y += temp
sleep(3)
if(C)
temp = amplitude * sin(saved_dizz * world.time)
pixel_x_diff += temp
C.pixel_x += temp
temp = amplitude * cos(saved_dizz * world.time)
pixel_y_diff += temp
C.pixel_y += temp
sleep(3)
if(C)
C.pixel_x -= pixel_x_diff
C.pixel_y -= pixel_y_diff
src = oldsrc
dizziness = max(dizziness - restingpwr, 0)
if(drowsyness)
drowsyness = max(drowsyness - restingpwr, 0)
blur_eyes(2)
if(prob(5))
AdjustSleeping(100)
//Jitteriness
if(jitteriness)
do_jitter_animation(jitteriness)
jitteriness = max(jitteriness - restingpwr, 0)
SEND_SIGNAL(src, COMSIG_ADD_MOOD_EVENT, "jittery", /datum/mood_event/jittery)
else
SEND_SIGNAL(src, COMSIG_CLEAR_MOOD_EVENT, "jittery")
if(stuttering)
stuttering = max(stuttering-1, 0)
if(slurring)
slurring = max(slurring-1,0)
if(cultslurring)
cultslurring = max(cultslurring-1, 0)
if(clockcultslurring) //Shiptest edit
clockcultslurring = max(clockcultslurring-1, 0)
if(silent)
silent = max(silent-1, 0)
if(druggy)
adjust_drugginess(-1)
if(hallucination)
handle_hallucinations()
if(drunkenness)
drunkenness = max(drunkenness - (drunkenness * 0.04) - 0.01, 0)
if(drunkenness >= 6)
SEND_SIGNAL(src, COMSIG_ADD_MOOD_EVENT, "drunk", /datum/mood_event/drunk)
if(prob(25))
slurring += 2
jitteriness = max(jitteriness - 3, 0)
throw_alert("drunk", /atom/movable/screen/alert/drunk)
sound_environment_override = SOUND_ENVIRONMENT_PSYCHOTIC
else
SEND_SIGNAL(src, COMSIG_CLEAR_MOOD_EVENT, "drunk")
clear_alert("drunk")
sound_environment_override = SOUND_ENVIRONMENT_NONE
if(drunkenness >= 11 && slurring < 5)
slurring += 1.2
if(drunkenness >= 41)
if(prob(25))
confused += 2
Dizzy(10)
if(drunkenness >= 51)
if(prob(3) && !dna.check_mutation(DORFISM)) //WS Edit - they can handle their drink to keep it down
confused += 15
vomit() // vomiting clears toxloss, consider this a blessing
Dizzy(25)
if(drunkenness >= 61)
if(prob(50))
blur_eyes(5)
if(drunkenness >= 71)
blur_eyes(5)
if(drunkenness >= 81)
adjustToxLoss(1)
if(prob(5) && !stat)
to_chat(src, "<span class='warning'>Maybe you should lie down for a bit...</span>")
if(drunkenness >= 91)
adjustToxLoss(1)
adjustOrganLoss(ORGAN_SLOT_BRAIN, 0.4)
if(prob(20) && !stat)
to_chat(src, "<span class='warning'>Just a quick nap...</span>")
Sleeping(900)
if(drunkenness >= 101)
adjustToxLoss(2) //Let's be honest you shouldn't be alive by now
/// Base carbon environment handler, adds natural stabilization
/mob/living/carbon/handle_environment(datum/gas_mixture/environment)
var/areatemp = get_temperature(environment)
if(stat != DEAD) // If you are dead your body does not stabilize naturally
natural_bodytemperature_stabilization(environment)
if(!on_fire || areatemp > bodytemperature) // If we are not on fire or the area is hotter
adjust_bodytemperature((areatemp - bodytemperature), use_insulation=TRUE, use_steps=TRUE)
/**
* Used to stabilize the body temperature back to normal on living mobs
*
* vars:
* * environment The environment gas mix
*/
/mob/living/carbon/proc/natural_bodytemperature_stabilization(datum/gas_mixture/environment)
if(!dna)
return
var/areatemp = get_temperature(environment)
var/body_temperature_difference = get_body_temp_normal() - bodytemperature
var/natural_change = 0
// We are very cold, increate body temperature
if(bodytemperature <= dna.species.bodytemp_cold_damage_limit)
natural_change = max((body_temperature_difference * metabolism_efficiency / dna.species.bodytemp_autorecovery_divisor), \
dna.species.bodytemp_autorecovery_min)
// we are cold, reduce the minimum increment and do not jump over the difference
else if(bodytemperature > dna.species.bodytemp_cold_damage_limit && bodytemperature < get_body_temp_normal())
natural_change = max(body_temperature_difference * metabolism_efficiency / dna.species.bodytemp_autorecovery_divisor, \
min(body_temperature_difference, dna.species.bodytemp_autorecovery_min / 4))
// We are hot, reduce the minimum increment and do not jump below the difference
else if(bodytemperature > get_body_temp_normal() && bodytemperature <= dna.species.bodytemp_heat_damage_limit)
natural_change = min(body_temperature_difference * metabolism_efficiency / dna.species.bodytemp_autorecovery_divisor, \
max(body_temperature_difference, -(dna.species.bodytemp_autorecovery_min / 4)))
// We are very hot, reduce the body temperature
else if(bodytemperature >= dna.species.bodytemp_heat_damage_limit)
natural_change = min((body_temperature_difference / dna.species.bodytemp_autorecovery_divisor), -dna.species.bodytemp_autorecovery_min)
var/thermal_protection = 1 - get_insulation_protection(areatemp) // invert the protection
if(areatemp > bodytemperature) // It is hot here
if(bodytemperature < get_body_temp_normal())
// Our bodytemp is below normal we are cold, insulation helps us retain body heat
// and will reduce the heat we lose to the environment
natural_change = (thermal_protection + 1) * natural_change
else
// Our bodytemp is above normal and sweating, insulation hinders out ability to reduce heat
// but will reduce the amount of heat we get from the environment
natural_change = (1 / (thermal_protection + 1)) * natural_change
else // It is cold here
if(!on_fire) // If on fire ignore ignore local temperature in cold areas
if(bodytemperature < get_body_temp_normal())
// Our bodytemp is below normal, insulation helps us retain body heat
// and will reduce the heat we lose to the environment
natural_change = (thermal_protection + 1) * natural_change
else
// Our bodytemp is above normal and sweating, insulation hinders out ability to reduce heat
// but will reduce the amount of heat we get from the environment
natural_change = (1 / (thermal_protection + 1)) * natural_change
// Apply the natural stabilization changes
adjust_bodytemperature(natural_change)
/**
* Get the insulation that is appropriate to the temperature you're being exposed to.
* All clothing, natural insulation, and traits are combined returning a single value.
*
* required temperature The Temperature that you're being exposed to
*
* return the percentage of protection as a value from 0 - 1
**/
/mob/living/carbon/proc/get_insulation_protection(temperature)
return (temperature > bodytemperature) ? get_heat_protection(temperature) : get_cold_protection(temperature)
/// This returns the percentage of protection from heat as a value from 0 - 1
/// temperature is the temperature you're being exposed to
/mob/living/carbon/proc/get_heat_protection(temperature)
return heat_protection
/// This returns the percentage of protection from cold as a value from 0 - 1
/// temperature is the temperature you're being exposed to
/mob/living/carbon/proc/get_cold_protection(temperature)
return cold_protection
/**
* Have two mobs share body heat between each other.
* Account for the insulation and max temperature change range for the mob
*
* vars:
* * M The mob/living/carbon that is sharing body heat
*/
/mob/living/carbon/proc/share_bodytemperature(mob/living/carbon/M)
var/temp_diff = bodytemperature - M.bodytemperature
if(temp_diff > 0) // you are warm share the heat of life
M.adjust_bodytemperature((temp_diff * 0.5), use_insulation=TRUE, use_steps=TRUE) // warm up the giver
adjust_bodytemperature((temp_diff * -0.5), use_insulation=TRUE, use_steps=TRUE) // cool down the reciver
else // they are warmer leech from them
adjust_bodytemperature((temp_diff * -0.5) , use_insulation=TRUE, use_steps=TRUE) // warm up the reciver
M.adjust_bodytemperature((temp_diff * 0.5), use_insulation=TRUE, use_steps=TRUE) // cool down the giver
/**
* Adjust the body temperature of a mob
* expanded for carbon mobs allowing the use of insulation and change steps
*
* vars:
* * amount The amount of degrees to change body temperature by
* * min_temp (optional) The minimum body temperature after adjustment
* * max_temp (optional) The maximum body temperature after adjustment
* * use_insulation (optional) modifies the amount based on the amount of insulation the mob has
* * use_steps (optional) Use the body temp divisors and max change rates
* * hardsuit_fix (optional) num HUMAN_BODYTEMP_NORMAL - H.bodytemperature Use hardsuit override until hardsuits fix is done...
*/
/mob/living/carbon/adjust_bodytemperature(amount, min_temp=0, max_temp=INFINITY, use_insulation=FALSE, use_steps=FALSE, \
hardsuit_fix=FALSE)
// apply insulation to the amount of change
if(use_insulation)
amount *= (1 - get_insulation_protection(bodytemperature + amount))
// Extra calculation for hardsuits to bleed off heat
if(hardsuit_fix)
amount += hardsuit_fix
// Use the bodytemp divisors to get the change step, with max step size
if(use_steps && dna)
amount = (amount > 0) ? min(amount / dna.species.bodytemp_heat_divisor, dna.species.bodytemp_heating_rate_max) : max(amount / dna.species.bodytemp_cold_divisor, dna.species.bodytemp_cooling_rate_max)
if(bodytemperature >= min_temp && bodytemperature <= max_temp)
bodytemperature = clamp(bodytemperature + amount,min_temp,max_temp)
/////////
//LIVER//
/////////
///Decides if the liver is failing or not.
/mob/living/carbon/proc/handle_liver()
if(!dna)
return
var/obj/item/organ/liver/liver = getorganslot(ORGAN_SLOT_LIVER)
if(!liver)
liver_failure()
/mob/living/carbon/proc/undergoing_liver_failure()
var/obj/item/organ/liver/liver = getorganslot(ORGAN_SLOT_LIVER)
if(liver && (liver.organ_flags & ORGAN_FAILING))
return TRUE
/mob/living/carbon/proc/liver_failure()
reagents.end_metabolization(src, keep_liverless = TRUE) //Stops trait-based effects on reagents, to prevent permanent buffs
reagents.metabolize(src, can_overdose=FALSE, liverless = TRUE)
if(HAS_TRAIT(src, TRAIT_STABLELIVER) || HAS_TRAIT(src, TRAIT_NOMETABOLISM))
return
adjustToxLoss(4, TRUE, TRUE)
if(prob(30))
to_chat(src, "<span class='warning'>You feel a stabbing pain in your abdomen!</span>")
/////////////
//CREMATION//
/////////////
/mob/living/carbon/proc/check_cremation()
//Only cremate while actively on fire
if(!on_fire)
return
//Only starts when the chest has taken full damage
var/obj/item/bodypart/chest = get_bodypart(BODY_ZONE_CHEST)
if(!(chest.get_damage() >= chest.max_damage))
return
//Burn off limbs one by one
var/obj/item/bodypart/limb
var/list/limb_list = list(BODY_ZONE_L_ARM, BODY_ZONE_R_ARM, BODY_ZONE_L_LEG, BODY_ZONE_R_LEG)
var/still_has_limbs = FALSE
for(var/zone in limb_list)
limb = get_bodypart(zone)
if(limb)
still_has_limbs = TRUE
if(limb.get_damage() >= limb.max_damage)
limb.cremation_progress += rand(2,5)
if(limb.cremation_progress >= 100)
if(IS_ORGANIC_LIMB(limb)) //Non-organic limbs don't burn
limb.drop_limb()
limb.visible_message("<span class='warning'>[src]'s [limb.name] crumbles into ash!</span>")
qdel(limb)
else
limb.drop_limb()
limb.visible_message("<span class='warning'>[src]'s [limb.name] detaches from [p_their()] body!</span>")
if(still_has_limbs)
return
//Burn the head last
var/obj/item/bodypart/head = get_bodypart(BODY_ZONE_HEAD)
if(head)
if(head.get_damage() >= head.max_damage)
head.cremation_progress += rand(2,5)
if(head.cremation_progress >= 100)
if(!IS_ORGANIC_LIMB(head)) //Non-organic limbs don't burn
head.drop_limb()
head.visible_message("<span class='warning'>[src]'s head crumbles into ash!</span>")
qdel(head)
else
head.drop_limb()
head.visible_message("<span class='warning'>[src]'s head detaches from [p_their()] body!</span>")
return
//Nothing left: dust the body, drop the items (if they're flammable they'll burn on their own)
chest.cremation_progress += rand(2,5)
if(chest.cremation_progress >= 100)
visible_message("<span class='warning'>[src]'s body crumbles into a pile of ash!</span>")
dust(TRUE, TRUE)
////////////////
//BRAIN DAMAGE//
////////////////
/mob/living/carbon/proc/handle_brain_damage()
for(var/T in get_traumas())
var/datum/brain_trauma/BT = T
BT.on_life()
/////////////////////////////////////
//MONKEYS WITH TOO MUCH CHOLOESTROL//
/////////////////////////////////////
/mob/living/carbon/proc/can_heartattack()
if(!needs_heart())
return FALSE
var/obj/item/organ/heart/heart = getorganslot(ORGAN_SLOT_HEART)
if(!heart || (heart.organ_flags & ORGAN_SYNTHETIC))
return FALSE
return TRUE
/mob/living/carbon/proc/needs_heart()
if(HAS_TRAIT(src, TRAIT_STABLEHEART))
return FALSE
if(dna && dna.species && (NOBLOOD in dna.species.species_traits)) //not all carbons have species!
return FALSE
return TRUE
/*
* The mob is having a heart attack
*
* NOTE: this is true if the mob has no heart and needs one, which can be suprising,
* you are meant to use it in combination with can_heartattack for heart attack
* related situations (i.e not just cardiac arrest)
*/
/mob/living/carbon/proc/undergoing_cardiac_arrest()
var/obj/item/organ/heart/heart = getorganslot(ORGAN_SLOT_HEART)
if(istype(heart) && heart.beating)
return FALSE
else if(!needs_heart())
return FALSE
return TRUE
/mob/living/carbon/proc/set_heartattack(status)
if(!can_heartattack())
return FALSE
var/obj/item/organ/heart/heart = getorganslot(ORGAN_SLOT_HEART)
if(!istype(heart))
return
heart.beating = !status