Files
Jerry 2c95d1d28c Fix rare runtime if there are no available organs to take (#87671)
## About The Pull Request

This PR fixes a rare runtime error, regarding lost crew members, that
occurs when there are no organs in the `organs_we_can_take` list, which
causes an exception due to an attempt to `pick()` from an empty list.
## Why It's Good For The Game

The less exceptions exists, the better.
## Changelog
🆑
fix: fixed a rare runtime with lost crew having no organs
/🆑

---------

Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com>
2024-11-04 15:55:17 +01:00

50 lines
1.9 KiB
Plaintext

/// Damn space vultures man! At least they dont go for the brain
/datum/corpse_damage/post_mortem/organ_loss
damage_type = CORPSE_DAMAGE_ORGAN_LOSS
/// Chance that the organ is stored and delivered with the body
var/organ_save_chance = 20
/// Minimum organs we can lose
var/min_organs = 2
/// Maximum organs we can lose
var/max_organs = 8
/datum/corpse_damage/post_mortem/organ_loss/apply_to_body(mob/living/carbon/human/body, severity, list/saved_movables, list/datum/callback/on_revive_and_player_occupancy)
var/organs_to_take = round(min_organs + (max_organs - min_organs) * severity)
var/list/organs_we_can_take = body.organs - body.get_organ_slot(ORGAN_SLOT_BRAIN)
if (!length(organs_we_can_take))
return
for(var/i in 1 to organs_to_take)
var/obj/organ = pick(organs_we_can_take)
if(prob(organ_save_chance) && saved_movables) //if lucky, we can save the organ and have it be delivered with the body
organ.moveToNullspace()
saved_movables += organ
else
qdel(organ)
/// Damn space vultures man! At least they dont go for the chest or head, or they do but we don't get to see those bodies :O
/datum/corpse_damage/post_mortem/limb_loss
damage_type = CORPSE_DAMAGE_LIMB_LOSS
/// Chance that the limb is stored and delivered with the body
var/limb_save_chance = 20
/// Min limbs we can lose
var/min_limbs = 1
/// Max limbs we can lose
var/max_limbs = 4
/datum/corpse_damage/post_mortem/limb_loss/apply_to_body(mob/living/carbon/human/body, severity, list/saved_movables, list/datum/callback/on_revive_and_player_occupancy)
var/limbs_to_take = round(min_limbs + (max_limbs - min_limbs) * severity)
var/list/limbs_we_can_take = body.bodyparts - body.get_bodypart(BODY_ZONE_HEAD) - body.get_bodypart(BODY_ZONE_CHEST)
if(!limbs_we_can_take.len)
return
for(var/i in 1 to limbs_to_take)
var/obj/limb = pick(limbs_we_can_take)
if(prob(limb_save_chance) && saved_movables)
limb.moveToNullspace()
saved_movables += limb
else
qdel(limb)