From 87395fd6c2ddfc85cd2f00d0ca53952d75999f33 Mon Sep 17 00:00:00 2001 From: Chinsky Date: Sun, 21 Feb 2016 15:24:36 +0300 Subject: [PATCH] Shortens some wordy procs that used a lot of duplicate code with power of OOP --- code/modules/mob/living/carbon/human/life.dm | 139 ++++++------------- 1 file changed, 40 insertions(+), 99 deletions(-) diff --git a/code/modules/mob/living/carbon/human/life.dm b/code/modules/mob/living/carbon/human/life.dm index 47cca0e5cf..8247a6636a 100644 --- a/code/modules/mob/living/carbon/human/life.dm +++ b/code/modules/mob/living/carbon/human/life.dm @@ -711,85 +711,25 @@ //This proc returns a number made up of the flags for body parts which you are protected on. (such as HEAD, UPPER_TORSO, LOWER_TORSO, etc. See setup.dm for the full list) /mob/living/carbon/human/proc/get_heat_protection_flags(temperature) //Temperature is the temperature you're being exposed to. - var/thermal_protection_flags = 0 + . = 0 //Handle normal clothing - if(head) - if(head.max_heat_protection_temperature && head.max_heat_protection_temperature >= temperature) - thermal_protection_flags |= head.heat_protection - if(wear_suit) - if(wear_suit.max_heat_protection_temperature && wear_suit.max_heat_protection_temperature >= temperature) - thermal_protection_flags |= wear_suit.heat_protection - if(w_uniform) - if(w_uniform.max_heat_protection_temperature && w_uniform.max_heat_protection_temperature >= temperature) - thermal_protection_flags |= w_uniform.heat_protection - if(shoes) - if(shoes.max_heat_protection_temperature && shoes.max_heat_protection_temperature >= temperature) - thermal_protection_flags |= shoes.heat_protection - if(gloves) - if(gloves.max_heat_protection_temperature && gloves.max_heat_protection_temperature >= temperature) - thermal_protection_flags |= gloves.heat_protection - if(wear_mask) - if(wear_mask.max_heat_protection_temperature && wear_mask.max_heat_protection_temperature >= temperature) - thermal_protection_flags |= wear_mask.heat_protection - - return thermal_protection_flags - -/mob/living/carbon/human/get_heat_protection(temperature) //Temperature is the temperature you're being exposed to. - var/thermal_protection_flags = get_heat_protection_flags(temperature) - - var/thermal_protection = 0.0 - if(thermal_protection_flags) - if(thermal_protection_flags & HEAD) - thermal_protection += THERMAL_PROTECTION_HEAD - if(thermal_protection_flags & UPPER_TORSO) - thermal_protection += THERMAL_PROTECTION_UPPER_TORSO - if(thermal_protection_flags & LOWER_TORSO) - thermal_protection += THERMAL_PROTECTION_LOWER_TORSO - if(thermal_protection_flags & LEG_LEFT) - thermal_protection += THERMAL_PROTECTION_LEG_LEFT - if(thermal_protection_flags & LEG_RIGHT) - thermal_protection += THERMAL_PROTECTION_LEG_RIGHT - if(thermal_protection_flags & FOOT_LEFT) - thermal_protection += THERMAL_PROTECTION_FOOT_LEFT - if(thermal_protection_flags & FOOT_RIGHT) - thermal_protection += THERMAL_PROTECTION_FOOT_RIGHT - if(thermal_protection_flags & ARM_LEFT) - thermal_protection += THERMAL_PROTECTION_ARM_LEFT - if(thermal_protection_flags & ARM_RIGHT) - thermal_protection += THERMAL_PROTECTION_ARM_RIGHT - if(thermal_protection_flags & HAND_LEFT) - thermal_protection += THERMAL_PROTECTION_HAND_LEFT - if(thermal_protection_flags & HAND_RIGHT) - thermal_protection += THERMAL_PROTECTION_HAND_RIGHT - - - return min(1,thermal_protection) + for(var/obj/item/clothing/C in list(head,wear_suit,w_uniform,shoes,gloves,wear_mask)) + if(C) + if(C.max_heat_protection_temperature && C.max_heat_protection_temperature >= temperature) + . |= C.heat_protection //See proc/get_heat_protection_flags(temperature) for the description of this proc. /mob/living/carbon/human/proc/get_cold_protection_flags(temperature) - var/thermal_protection_flags = 0 + . = 0 //Handle normal clothing + for(var/obj/item/clothing/C in list(head,wear_suit,w_uniform,shoes,gloves,wear_mask)) + if(C) + if(C.min_cold_protection_temperature && C.min_cold_protection_temperature <= temperature) + . |= C.cold_protection - if(head) - if(head.min_cold_protection_temperature && head.min_cold_protection_temperature <= temperature) - thermal_protection_flags |= head.cold_protection - if(wear_suit) - if(wear_suit.min_cold_protection_temperature && wear_suit.min_cold_protection_temperature <= temperature) - thermal_protection_flags |= wear_suit.cold_protection - if(w_uniform) - if(w_uniform.min_cold_protection_temperature && w_uniform.min_cold_protection_temperature <= temperature) - thermal_protection_flags |= w_uniform.cold_protection - if(shoes) - if(shoes.min_cold_protection_temperature && shoes.min_cold_protection_temperature <= temperature) - thermal_protection_flags |= shoes.cold_protection - if(gloves) - if(gloves.min_cold_protection_temperature && gloves.min_cold_protection_temperature <= temperature) - thermal_protection_flags |= gloves.cold_protection - if(wear_mask) - if(wear_mask.min_cold_protection_temperature && wear_mask.min_cold_protection_temperature <= temperature) - thermal_protection_flags |= wear_mask.cold_protection - - return thermal_protection_flags +/mob/living/carbon/human/get_heat_protection(temperature) //Temperature is the temperature you're being exposed to. + var/thermal_protection_flags = get_heat_protection_flags(temperature) + return get_thermal_protection(thermal_protection_flags) /mob/living/carbon/human/get_cold_protection(temperature) if(COLD_RESISTANCE in mutations) @@ -797,33 +737,34 @@ temperature = max(temperature, 2.7) //There is an occasional bug where the temperature is miscalculated in ares with a small amount of gas on them, so this is necessary to ensure that that bug does not affect this calculation. Space's temperature is 2.7K and most suits that are intended to protect against any cold, protect down to 2.0K. var/thermal_protection_flags = get_cold_protection_flags(temperature) + return get_thermal_protection(thermal_protection_flags) - var/thermal_protection = 0.0 - if(thermal_protection_flags) - if(thermal_protection_flags & HEAD) - thermal_protection += THERMAL_PROTECTION_HEAD - if(thermal_protection_flags & UPPER_TORSO) - thermal_protection += THERMAL_PROTECTION_UPPER_TORSO - if(thermal_protection_flags & LOWER_TORSO) - thermal_protection += THERMAL_PROTECTION_LOWER_TORSO - if(thermal_protection_flags & LEG_LEFT) - thermal_protection += THERMAL_PROTECTION_LEG_LEFT - if(thermal_protection_flags & LEG_RIGHT) - thermal_protection += THERMAL_PROTECTION_LEG_RIGHT - if(thermal_protection_flags & FOOT_LEFT) - thermal_protection += THERMAL_PROTECTION_FOOT_LEFT - if(thermal_protection_flags & FOOT_RIGHT) - thermal_protection += THERMAL_PROTECTION_FOOT_RIGHT - if(thermal_protection_flags & ARM_LEFT) - thermal_protection += THERMAL_PROTECTION_ARM_LEFT - if(thermal_protection_flags & ARM_RIGHT) - thermal_protection += THERMAL_PROTECTION_ARM_RIGHT - if(thermal_protection_flags & HAND_LEFT) - thermal_protection += THERMAL_PROTECTION_HAND_LEFT - if(thermal_protection_flags & HAND_RIGHT) - thermal_protection += THERMAL_PROTECTION_HAND_RIGHT - - return min(1,thermal_protection) +/mob/living/carbon/human/proc/get_thermal_protection(var/flags) + .=0 + if(flags) + if(flags & HEAD) + . += THERMAL_PROTECTION_HEAD + if(flags & UPPER_TORSO) + . += THERMAL_PROTECTION_UPPER_TORSO + if(flags & LOWER_TORSO) + . += THERMAL_PROTECTION_LOWER_TORSO + if(flags & LEG_LEFT) + . += THERMAL_PROTECTION_LEG_LEFT + if(flags & LEG_RIGHT) + . += THERMAL_PROTECTION_LEG_RIGHT + if(flags & FOOT_LEFT) + . += THERMAL_PROTECTION_FOOT_LEFT + if(flags & FOOT_RIGHT) + . += THERMAL_PROTECTION_FOOT_RIGHT + if(flags & ARM_LEFT) + . += THERMAL_PROTECTION_ARM_LEFT + if(flags & ARM_RIGHT) + . += THERMAL_PROTECTION_ARM_RIGHT + if(flags & HAND_LEFT) + . += THERMAL_PROTECTION_HAND_LEFT + if(flags & HAND_RIGHT) + . += THERMAL_PROTECTION_HAND_RIGHT + return min(1,.) /mob/living/carbon/human/handle_chemicals_in_body()