-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathdismemberment.dm
458 lines (393 loc) · 14.7 KB
/
dismemberment.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
/obj/item/bodypart/proc/can_dismember(obj/item/I)
if(dismemberable)
return TRUE
//Dismember a limb
/obj/item/bodypart/proc/dismember(dam_type = BRUTE, silent = TRUE)
if(!owner || !dismemberable)
return FALSE
var/mob/living/carbon/C = owner
if(C.status_flags & GODMODE)
return FALSE
if(HAS_TRAIT(C, TRAIT_NODISMEMBER))
return FALSE
var/obj/item/bodypart/affecting = C.get_bodypart(BODY_ZONE_CHEST)
affecting.receive_damage(clamp(brute_dam/2 * affecting.body_damage_coeff, 15, 50), clamp(burn_dam/2 * affecting.body_damage_coeff, 0, 50), wound_bonus=CANT_WOUND) //Damage the chest based on limb's existing damage
if(!silent)
C.visible_message(span_danger("<B>[C]'s [name] is violently dismembered!</B>"))
INVOKE_ASYNC(C, TYPE_PROC_REF(/mob, emote), "scream")
playsound(get_turf(C), 'sound/effects/dismember.ogg', 80, TRUE)
SEND_SIGNAL(C, COMSIG_ADD_MOOD_EVENT, "dismembered", /datum/mood_event/dismembered)
var/should_disintegrate = !HAS_TRAIT(owner, TRAIT_EASYDISMEMBER) // if their limb falls off easily it should just fall off instead
drop_limb()
if(dam_type == BURN && should_disintegrate)
burn()
return 1
add_mob_blood(C)
C.bleed(rand(20, 40))
var/turf/location = C.loc
if(istype(location))
C.add_splatter_floor(location)
var/direction = pick(GLOB.cardinals)
var/t_range = rand(2,max(throw_range/2, 2))
var/turf/target_turf = get_turf(src)
for(var/i in 1 to t_range-1)
var/turf/new_turf = get_step(target_turf, direction)
if(!new_turf)
break
target_turf = new_turf
if(new_turf.density)
break
throw_at(target_turf, throw_range, throw_speed)
return 1
/obj/item/bodypart/chest/dismember()
if(!owner)
return FALSE
var/mob/living/carbon/C = owner
if(!dismemberable)
return FALSE
if(HAS_TRAIT(C, TRAIT_NODISMEMBER))
return FALSE
. = list()
var/turf/T = get_turf(C)
C.add_splatter_floor(T)
playsound(get_turf(C), 'sound/misc/splort.ogg', 80, 1)
for(var/X in C.internal_organs)
var/obj/item/organ/O = X
var/org_zone = check_zone(O.zone)
if(org_zone != BODY_ZONE_CHEST)
continue
O.Remove(C)
O.forceMove(T)
. += X
if(cavity_item)
cavity_item.forceMove(T)
. += cavity_item
cavity_item = null
///limb removal. The "special" argument is used for swapping a limb with a new one without the effects of losing a limb kicking in.
/obj/item/bodypart/proc/drop_limb(special, dismembered)
if(!owner)
return
var/atom/Tsec = owner.drop_location()
SEND_SIGNAL(owner, COMSIG_CARBON_REMOVE_LIMB, src, dismembered)
update_limb(1)
owner.bodyparts -= src
if(held_index)
var/obj/item/I = owner.get_item_for_held_index(held_index)
if(I)
owner.dropItemToGround(I, TRUE)
owner.hand_bodyparts[held_index] = null
for(var/thing in wounds)
var/datum/wound/W = thing
W.remove_wound(TRUE)
for(var/thing in scars)
var/datum/scar/S = thing
S.victim = null
LAZYREMOVE(owner.all_scars, S)
var/mob/living/carbon/phantom_owner = owner // so we can still refer to the guy who lost their limb after said limb forgets 'em
set_owner(null)
for(var/X in phantom_owner.surgeries) //if we had an ongoing surgery on that limb, we stop it.
var/datum/surgery/S = X
if(S.operated_bodypart == src)
phantom_owner.surgeries -= S
qdel(S)
break
for(var/obj/item/I in embedded_objects)
phantom_owner.remove_embedded_object(I, src, TRUE, TRUE)
if(!phantom_owner.has_embedded_objects())
phantom_owner.clear_alert("embeddedobject")
SEND_SIGNAL(phantom_owner, COMSIG_CLEAR_MOOD_EVENT, "embedded")
if(!special)
if(phantom_owner.dna)
for(var/X in phantom_owner.dna.mutations) //some mutations require having specific limbs to be kept.
var/datum/mutation/human/MT = X
if(MT.limb_req && MT.limb_req == body_zone)
phantom_owner.dna.force_lose(MT)
for(var/X in phantom_owner.internal_organs) //internal organs inside the dismembered limb are dropped.
var/obj/item/organ/O = X
var/org_zone = check_zone(O.zone)
if(org_zone != body_zone)
continue
O.transfer_to_limb(src, phantom_owner)
update_icon_dropped()
phantom_owner.update_health_hud() //update the healthdoll
phantom_owner.update_body()
phantom_owner.update_hair()
phantom_owner.update_mobility()
if(!Tsec) // Tsec = null happens when a "dummy human" used for rendering icons on prefs screen gets its limbs replaced.
qdel(src)
return
if(is_pseudopart)
drop_organs(phantom_owner) //Psuedoparts shouldn't have organs, but just in case
qdel(src)
return
forceMove(Tsec)
/**
* get_mangled_state() is relevant for flesh and bone bodyparts, and returns whether this bodypart has mangled skin, mangled bone, or both (or neither i guess)
*
* Dismemberment for flesh and bone requires the victim to have the skin on their bodypart destroyed (either a critical cut or piercing wound), and at least a hairline fracture
* (severe bone), at which point we can start rolling for dismembering. The attack must also deal at least 10 damage, and must be a brute attack of some kind (sorry for now, cakehat, maybe later)
*
* Returns: BODYPART_MANGLED_NONE if we're fine, BODYPART_MANGLED_FLESH if our skin is broken, BODYPART_MANGLED_BONE if our bone is broken, or BODYPART_MANGLED_BOTH if both are broken and we're up for dismembering
*/
/obj/item/bodypart/proc/get_mangled_state()
. = BODYPART_MANGLED_NONE
for(var/i in wounds)
var/datum/wound/iter_wound = i
if((iter_wound.wound_flags & MANGLES_BONE))
. |= BODYPART_MANGLED_BONE
if((iter_wound.wound_flags & MANGLES_FLESH))
. |= BODYPART_MANGLED_FLESH
/**
* try_dismember() is used, once we've confirmed that a flesh and bone bodypart has both the skin and bone mangled, to actually roll for it
*
* Mangling is described in the above proc, [/obj/item/bodypart/proc/get_mangled_state]. This simply makes the roll for whether we actually dismember or not
* using how damaged the limb already is, and how much damage this blow was for. If we have a critical bone wound instead of just a severe, we add +10% to the roll.
* Lastly, we choose which kind of dismember we want based on the wounding type we hit with. Note we don't care about all the normal mods or armor for this
*
* Arguments:
* * wounding_type: Either WOUND_BLUNT, WOUND_SLASH, or WOUND_PIERCE, basically only matters for the dismember message
* * wounding_dmg: The damage of the strike that prompted this roll, higher damage = higher chance
* * wound_bonus: Not actually used right now, but maybe someday
* * bare_wound_bonus: ditto above
*/
/obj/item/bodypart/proc/try_dismember(wounding_type, wounding_dmg, wound_bonus, bare_wound_bonus)
if(wounding_dmg < DISMEMBER_MINIMUM_DAMAGE)
return
var/base_chance = wounding_dmg
base_chance += (get_damage() / max_damage * 50) // how much damage we dealt with this blow, + 50% of the damage percentage we already had on this bodypart
if(locate(/datum/wound/blunt/critical) in wounds) // we only require a severe bone break, but if there's a critical bone break, we'll add 15% more
base_chance += 15
if(prob(base_chance))
var/datum/wound/loss/dismembering = new
return dismembering.apply_dismember(src, wounding_type)
//when a limb is dropped, the internal organs are removed from the mob and put into the limb
/obj/item/organ/proc/transfer_to_limb(obj/item/bodypart/LB, mob/living/carbon/C)
Remove(C)
forceMove(LB)
/obj/item/organ/brain/transfer_to_limb(obj/item/bodypart/head/LB, mob/living/carbon/human/C)
Remove(C) //Changeling brain concerns are now handled in Remove
forceMove(LB)
LB.brain = src
if(brainmob)
LB.brainmob = brainmob
brainmob = null
LB.brainmob.forceMove(LB)
LB.brainmob.set_stat(DEAD)
/obj/item/organ/eyes/transfer_to_limb(obj/item/bodypart/head/LB, mob/living/carbon/human/C)
LB.eyes = src
..()
/obj/item/organ/ears/transfer_to_limb(obj/item/bodypart/head/LB, mob/living/carbon/human/C)
LB.ears = src
..()
/obj/item/organ/tongue/transfer_to_limb(obj/item/bodypart/head/LB, mob/living/carbon/human/C)
LB.tongue = src
..()
/obj/item/bodypart/chest/drop_limb(special)
if(special)
..()
/obj/item/bodypart/r_arm/drop_limb(special)
var/mob/living/carbon/C = owner
..()
if(C && !special)
if(C.handcuffed)
C.handcuffed.forceMove(drop_location())
C.handcuffed.dropped(C)
C.set_handcuffed(null)
C.update_handcuffed()
if(C.hud_used)
var/atom/movable/screen/inventory/hand/R = C.hud_used.hand_slots["[held_index]"]
if(R)
R.update_appearance(UPDATE_ICON)
if(C.gloves)
C.dropItemToGround(C.gloves, TRUE)
C.update_inv_gloves() //to remove the bloody hands overlay
/obj/item/bodypart/l_arm/drop_limb(special)
var/mob/living/carbon/C = owner
..()
if(C && !special)
if(C.handcuffed)
C.handcuffed.forceMove(drop_location())
C.handcuffed.dropped(C)
C.set_handcuffed(null)
C.update_handcuffed()
if(C.hud_used)
var/atom/movable/screen/inventory/hand/L = C.hud_used.hand_slots["[held_index]"]
if(L)
L.update_appearance(UPDATE_ICON)
if(C.gloves)
C.dropItemToGround(C.gloves, TRUE)
C.update_inv_gloves() //to remove the bloody hands overlay
/obj/item/bodypart/leg/right/drop_limb(special)
if(owner && !special)
if(owner.legcuffed)
owner.legcuffed.forceMove(owner.drop_location()) //At this point bodypart is still in nullspace
owner.legcuffed.dropped(owner)
owner.legcuffed = null
owner.update_inv_legcuffed()
if(owner.shoes)
owner.dropItemToGround(owner.shoes, TRUE)
..()
/obj/item/bodypart/leg/left/drop_limb(special) //copypasta
if(owner && !special)
if(owner.legcuffed)
owner.legcuffed.forceMove(owner.drop_location())
owner.legcuffed.dropped(owner)
owner.legcuffed = null
owner.update_inv_legcuffed()
if(owner.shoes)
owner.dropItemToGround(owner.shoes, TRUE)
..()
/obj/item/bodypart/head/drop_limb(special)
if(!special)
//Drop all worn head items
for(var/X in list(owner.glasses, owner.ears, owner.wear_mask, owner.head))
var/obj/item/I = X
owner.dropItemToGround(I, TRUE)
owner.wash_cream() //clean creampie overlay
//Handle dental implants
for(var/datum/action/item_action/hands_free/activate_pill/AP in owner.actions)
AP.Remove(owner)
var/obj/pill = AP.target
if(pill)
pill.forceMove(src)
//Make sure de-zombification happens before organ removal instead of during it
var/obj/item/organ/zombie_infection/ooze = owner.getorganslot(ORGAN_SLOT_ZOMBIE)
if(istype(ooze))
ooze.transfer_to_limb(src, owner)
name = "[owner.real_name]'s head"
..()
//Attach a limb to a human and drop any existing limb of that type.
/obj/item/bodypart/proc/replace_limb(mob/living/carbon/C, special)
if(!istype(C))
return
var/obj/item/bodypart/O = C.get_bodypart(body_zone)
if(O)
O.drop_limb(1)
attach_limb(C, special)
/obj/item/bodypart/head/replace_limb(mob/living/carbon/C, special)
if(!istype(C))
return
var/obj/item/bodypart/head/O = C.get_bodypart(body_zone)
if(O)
if(!special)
return
else
O.drop_limb(1)
attach_limb(C, special)
/obj/item/bodypart/proc/attach_limb(mob/living/carbon/C, special)
moveToNullspace()
set_owner(C)
SEND_SIGNAL(C, COMSIG_CARBON_ATTACH_LIMB, src, special)
C.bodyparts += src
if(held_index)
if(held_index > C.hand_bodyparts.len)
C.hand_bodyparts.len = held_index
C.hand_bodyparts[held_index] = src
if(C.dna.species.mutanthands && !is_pseudopart)
C.put_in_hand(new C.dna.species.mutanthands(), held_index)
if(C.hud_used)
var/atom/movable/screen/inventory/hand/hand = C.hud_used.hand_slots["[held_index]"]
if(hand)
hand.update_appearance(UPDATE_ICON)
C.update_inv_gloves()
if(special) //non conventional limb attachment
for(var/X in C.surgeries) //if we had an ongoing surgery to attach a new limb, we stop it.
var/datum/surgery/S = X
var/surgery_zone = check_zone(S.location)
if(surgery_zone == body_zone)
C.surgeries -= S
qdel(S)
break
for(var/obj/item/organ/O in contents)
O.Insert(C)
for(var/i in wounds)
var/datum/wound/W = i
// we have to remove the wound from the limb wound list first, so that we can reapply it fresh with the new person
// otherwise the wound thinks it's trying to replace an existing wound of the same type (itself) and fails/deletes itself
LAZYREMOVE(wounds, W)
W.apply_wound(src, TRUE)
for(var/thing in scars)
var/datum/scar/S = thing
if(S in C.all_scars) // prevent double scars from happening for whatever reason
continue
S.victim = C
LAZYADD(C.all_scars, thing)
update_bodypart_damage_state()
if(C.dna && C.dna.species && (C.mob_biotypes & MOB_ROBOTIC) && src.status == BODYPART_ROBOTIC)
src.render_like_organic = TRUE
C.updatehealth()
C.update_body()
C.update_hair()
C.update_damage_overlays()
C.update_mobility()
/obj/item/bodypart/head/attach_limb(mob/living/carbon/C, special)
//Transfer some head appearance vars over
if(brain)
if(brainmob)
brainmob.container = null //Reset brainmob head var.
brainmob.forceMove(brain) //Throw mob into brain.
brain.brainmob = brainmob //Set the brain to use the brainmob
brainmob = null //Set head brainmob var to null
brain.Insert(C) //Now insert the brain proper
brain = null //No more brain in the head
if(tongue)
tongue = null
if(ears)
ears = null
if(eyes)
eyes = null
if(ishuman(C))
var/mob/living/carbon/human/H = C
H.hair_color = hair_color
H.hair_style = hair_style
H.facial_hair_color = facial_hair_color
H.facial_hair_style = facial_hair_style
H.lip_style = lip_style
H.lip_color = lip_color
if(real_name)
C.real_name = real_name
real_name = ""
name = initial(name)
//Handle dental implants
for(var/obj/item/reagent_containers/pill/P in src)
for(var/datum/action/item_action/hands_free/activate_pill/AP in P.actions)
P.forceMove(C)
AP.Grant(C)
break
..()
//Regenerates all limbs. Returns amount of limbs regenerated
/mob/living/proc/regenerate_limbs(noheal, excluded_limbs)
return 0
/mob/living/carbon/regenerate_limbs(noheal, list/excluded_limbs)
var/list/limb_list = list(BODY_ZONE_HEAD, BODY_ZONE_CHEST, BODY_ZONE_R_ARM, BODY_ZONE_L_ARM, BODY_ZONE_R_LEG, BODY_ZONE_L_LEG)
if(excluded_limbs)
limb_list -= excluded_limbs
for(var/Z in limb_list)
. += regenerate_limb(Z, noheal)
/mob/living/proc/regenerate_limb(limb_zone, noheal)
return
/mob/living/carbon/regenerate_limb(limb_zone, noheal)
var/obj/item/bodypart/L
if(get_bodypart(limb_zone))
return FALSE
L = newBodyPart(limb_zone, 0, 0)
if(L)
if(!noheal)
L.set_brute_dam(0)
L.set_burn_dam(0)
L.brutestate = 0
L.burnstate = 0
if(ishuman(src))
var/mob/living/carbon/human/H = src
if(H.dna && H.dna.species && (H.mob_biotypes & MOB_ROBOTIC))
L.change_bodypart_status(BODYPART_ROBOTIC)
L.render_like_organic = TRUE
if(limb_zone == "head" && H.dna && H.dna.species && (NOMOUTH in H.dna.species.species_traits))
var/obj/item/bodypart/head/head = L
if(head)
head.mouth = FALSE
L.attach_limb(src, 1)
var/datum/scar/scaries = new
var/datum/wound/loss/phantom_loss = new // stolen valor, really
scaries.generate(L, phantom_loss)
return TRUE