mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-11 16:14:08 +01:00
Add a unit test to check that maploaded simple/basic mobs are in an environment they can survive in. (#82180)
## About The Pull Request I've recently noticed that the maploaded penguins from the snowdin away mission were dying from unsafe atmos/temperature. This sparked the idea of making a (focus only) unit test that would prevent this sort of issues from happening. This PR also implements the usage of the `atmos_requirements` and `body_temp_sensitive` elements for simple animals too, cutting down the copypaste. ## Why It's Good For The Game More unit tests to make sure things are done correctly. ## Changelog 🆑 fix: Made sure that mapped critters (i.e. penguins on the snow cabin away mission) can survive in the environment they're spawned in. /🆑
This commit is contained in:
@@ -93,9 +93,9 @@
|
||||
var/minimum_survivable_temperature = NPC_DEFAULT_MIN_TEMP
|
||||
///Maximal body temperature without receiving damage
|
||||
var/maximum_survivable_temperature = NPC_DEFAULT_MAX_TEMP
|
||||
///This damage is taken when the body temp is too cold. Set both this and unsuitable_heat_damage to 0 to avoid adding the basic_body_temp_sensitive element.
|
||||
///This damage is taken when the body temp is too cold. Set both this and unsuitable_heat_damage to 0 to avoid adding the body_temp_sensitive element.
|
||||
var/unsuitable_cold_damage = 1
|
||||
///This damage is taken when the body temp is too hot. Set both this and unsuitable_cold_damage to 0 to avoid adding the basic_body_temp_sensitive element.
|
||||
///This damage is taken when the body temp is too hot. Set both this and unsuitable_cold_damage to 0 to avoid adding the body_temp_sensitive element.
|
||||
var/unsuitable_heat_damage = 1
|
||||
|
||||
/mob/living/basic/Initialize(mapload)
|
||||
@@ -115,23 +115,32 @@
|
||||
if(speak_emote)
|
||||
speak_emote = string_list(speak_emote)
|
||||
|
||||
apply_atmos_requirements()
|
||||
apply_temperature_requirements()
|
||||
///We need to wait for SSair to be initialized before we can check atmos/temp requirements.
|
||||
if(PERFORM_ALL_TESTS(focus_only/atmos_and_temp_requirements) && mapload && !SSair.initialized)
|
||||
RegisterSignal(SSair, COMSIG_SUBSYSTEM_POST_INITIALIZE, PROC_REF(on_ssair_init))
|
||||
return
|
||||
apply_atmos_requirements(mapload)
|
||||
apply_temperature_requirements(mapload)
|
||||
|
||||
/mob/living/basic/proc/on_ssair_init(datum/source)
|
||||
SIGNAL_HANDLER
|
||||
UnregisterSignal(SSair, COMSIG_SUBSYSTEM_POST_INITIALIZE)
|
||||
apply_atmos_requirements(TRUE)
|
||||
apply_temperature_requirements(TRUE)
|
||||
|
||||
/// Ensures this mob can take atmospheric damage if it's supposed to
|
||||
/mob/living/basic/proc/apply_atmos_requirements()
|
||||
if(unsuitable_atmos_damage == 0)
|
||||
/mob/living/basic/proc/apply_atmos_requirements(mapload)
|
||||
if(unsuitable_atmos_damage == 0 || isnull(habitable_atmos))
|
||||
return
|
||||
//String assoc list returns a cached list, so this is like a static list to pass into the element below.
|
||||
habitable_atmos = string_assoc_list(habitable_atmos)
|
||||
AddElement(/datum/element/atmos_requirements, habitable_atmos, unsuitable_atmos_damage)
|
||||
AddElement(/datum/element/atmos_requirements, habitable_atmos, unsuitable_atmos_damage, mapload)
|
||||
|
||||
/// Ensures this mob can take temperature damage if it's supposed to
|
||||
/mob/living/basic/proc/apply_temperature_requirements()
|
||||
if(unsuitable_cold_damage == 0 && unsuitable_heat_damage == 0)
|
||||
/mob/living/basic/proc/apply_temperature_requirements(mapload)
|
||||
if((unsuitable_cold_damage == 0 && unsuitable_heat_damage == 0) || (minimum_survivable_temperature <= 0 && maximum_survivable_temperature >= INFINITY))
|
||||
return
|
||||
AddElement(/datum/element/basic_body_temp_sensitive, minimum_survivable_temperature, maximum_survivable_temperature, unsuitable_cold_damage, unsuitable_heat_damage)
|
||||
|
||||
AddElement(/datum/element/body_temp_sensitive, minimum_survivable_temperature, maximum_survivable_temperature, unsuitable_cold_damage, unsuitable_heat_damage, mapload)
|
||||
|
||||
/mob/living/basic/Life(seconds_per_tick = SSMOBS_DT, times_fired)
|
||||
. = ..()
|
||||
@@ -219,7 +228,7 @@
|
||||
RemoveElement(/datum/element/atmos_requirements, habitable_atmos, unsuitable_atmos_damage)
|
||||
. = TRUE
|
||||
if(NAMEOF(src, minimum_survivable_temperature), NAMEOF(src, maximum_survivable_temperature), NAMEOF(src, unsuitable_cold_damage), NAMEOF(src, unsuitable_heat_damage))
|
||||
RemoveElement(/datum/element/basic_body_temp_sensitive, minimum_survivable_temperature, maximum_survivable_temperature, unsuitable_cold_damage, unsuitable_heat_damage)
|
||||
RemoveElement(/datum/element/body_temp_sensitive, minimum_survivable_temperature, maximum_survivable_temperature, unsuitable_cold_damage, unsuitable_heat_damage)
|
||||
. = TRUE
|
||||
|
||||
. = ..()
|
||||
|
||||
Reference in New Issue
Block a user