Skip to content

Commit

Permalink
Merge pull request #2626 from Fluffy-Frontier/upstream-mirror-1671
Browse files Browse the repository at this point in the history
[MIRROR] Add a unit test to check that maploaded simple/basic mobs are in an environment they can survive in.
  • Loading branch information
mogeoko authored Mar 28, 2024
2 parents 7cc9e28 + c4ec1a7 commit 2fa4912
Show file tree
Hide file tree
Showing 63 changed files with 326 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2601,9 +2601,7 @@
pixel_x = 15;
pixel_y = 14
},
/mob/living/basic/frog{
name = "Peter Jr."
},
/mob/living/basic/frog/icemoon_facility,
/turf/open/floor/plating/icemoon,
/area/ruin/plasma_facility/operations)
"TK" = (
Expand Down
6 changes: 3 additions & 3 deletions _maps/RandomRuins/IceRuins/icemoon_underground_library.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
},
/area/ruin/unpowered/buried_library)
"aO" = (
/mob/living/basic/pet/fox,
/mob/living/basic/pet/fox/icemoon,
/turf/open/floor/wood{
initial_gas_mix = "ICEMOON_ATMOS"
},
Expand Down Expand Up @@ -327,7 +327,7 @@
/area/ruin/unpowered/buried_library)
"cA" = (
/obj/effect/decal/cleanable/dirt,
/mob/living/basic/pet/fox,
/mob/living/basic/pet/fox/icemoon,
/turf/open/floor/wood{
initial_gas_mix = "ICEMOON_ATMOS"
},
Expand Down Expand Up @@ -394,7 +394,7 @@
/obj/structure/fluff/paper{
dir = 1
},
/mob/living/basic/pet/fox,
/mob/living/basic/pet/fox/icemoon,
/turf/open/floor/wood{
initial_gas_mix = "ICEMOON_ATMOS"
},
Expand Down
4 changes: 1 addition & 3 deletions _maps/RandomRuins/LavaRuins/lavaland_surface_pizzaparty.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@
"nq" = (
/obj/effect/decal/cleanable/cobweb,
/obj/machinery/light/small/directional/north,
/mob/living/basic/pet/dog/bullterrier{
name = "Saint Nick's Helpful Associate"
},
/mob/living/basic/pet/dog/bullterrier/lavaland_party,
/turf/open/floor/carpet/blue/lavaland,
/area/ruin/unpowered)
"nI" = (
Expand Down
4 changes: 2 additions & 2 deletions _maps/RandomZLevels/SnowCabin.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -3002,7 +3002,7 @@
set_luminosity = 6;
light_color = "#9bbbff"
},
/mob/living/basic/pet/penguin/baby/permanent,
/mob/living/basic/pet/penguin/baby/permanent/snowdin,
/turf/open/misc/ice/smooth,
/area/awaymission/cabin/snowforest)
"sK" = (
Expand Down Expand Up @@ -3725,7 +3725,7 @@
set_luminosity = 6;
light_color = "#9bbbff"
},
/mob/living/basic/pet/penguin/emperor,
/mob/living/basic/pet/penguin/emperor/snowdin,
/turf/open/misc/ice/smooth,
/area/awaymission/cabin/snowforest)
"Aa" = (
Expand Down
29 changes: 10 additions & 19 deletions _maps/RandomZLevels/caves.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@
},
/area/awaymission/caves/bmp_asteroid/level_two)
"kE" = (
/mob/living/basic/spider/giant/hunter,
/mob/living/basic/spider/giant/hunter/away_caves,
/turf/open/floor/iron,
/area/awaymission/caves/bmp_asteroid)
"kL" = (
Expand Down Expand Up @@ -1332,7 +1332,7 @@
/area/awaymission/caves/northblock)
"pC" = (
/obj/item/mjollnir,
/mob/living/basic/spider/giant/nurse,
/mob/living/basic/spider/giant/nurse/away_caves,
/turf/open/misc/asteroid/basalt{
initial_gas_mix = "n2=23;o2=14;TEMP=2.7"
},
Expand Down Expand Up @@ -1432,7 +1432,7 @@
/obj/machinery/sleeper{
dir = 8
},
/mob/living/basic/spider/giant/hunter,
/mob/living/basic/spider/giant/hunter/away_caves,
/turf/open/floor/iron,
/area/awaymission/caves/bmp_asteroid)
"uO" = (
Expand Down Expand Up @@ -1590,7 +1590,7 @@
},
/area/awaymission/caves/bmp_asteroid/level_two)
"Bz" = (
/mob/living/basic/spider/giant/nurse,
/mob/living/basic/spider/giant/nurse/away_caves,
/turf/open/misc/asteroid/basalt{
initial_gas_mix = "n2=23;o2=14;TEMP=2.7"
},
Expand Down Expand Up @@ -1672,7 +1672,7 @@
"FS" = (
/obj/machinery/light/small/built/directional/north,
/obj/structure/spider/stickyweb,
/mob/living/basic/spider/giant/hunter,
/mob/living/basic/spider/giant/hunter/away_caves,
/turf/open/floor/iron,
/area/awaymission/caves/bmp_asteroid)
"FV" = (
Expand Down Expand Up @@ -1856,10 +1856,7 @@
/turf/open/floor/iron,
/area/awaymission/caves/listeningpost)
"Qe" = (
/mob/living/basic/bat{
desc = "A rare breed of bat which roosts deep in caves.";
name = "Cave Bat"
},
/mob/living/basic/bat/away_caves,
/turf/open/misc/asteroid/basalt{
initial_gas_mix = "n2=23;o2=14;TEMP=2.7"
},
Expand All @@ -1871,10 +1868,7 @@
},
/area/awaymission/caves/bmp_asteroid/level_four)
"Rt" = (
/mob/living/basic/bat{
desc = "A rare breed of bat which roosts deep in caves.";
name = "Cave Bat"
},
/mob/living/basic/bat/away_caves,
/turf/open/misc/asteroid/basalt{
initial_gas_mix = "n2=23;o2=14;TEMP=2.7"
},
Expand Down Expand Up @@ -1951,14 +1945,11 @@
/turf/open/floor/iron/recharge_floor,
/area/awaymission/caves/bmp_asteroid)
"Xa" = (
/mob/living/basic/bat{
desc = "A rare breed of bat which roosts deep in caves.";
name = "Cave Bat"
},
/mob/living/basic/bat/away_caves,
/turf/open/floor/iron,
/area/awaymission/caves/northblock)
"Xs" = (
/mob/living/basic/spider/giant/hunter,
/mob/living/basic/spider/giant/hunter/away_caves,
/turf/open/misc/asteroid/basalt{
initial_gas_mix = "n2=23;o2=14;TEMP=2.7"
},
Expand All @@ -1980,7 +1971,7 @@
/area/awaymission/caves/bmp_asteroid/level_two)
"XR" = (
/obj/structure/spider/stickyweb,
/mob/living/basic/spider/giant/hunter,
/mob/living/basic/spider/giant/hunter/away_caves,
/turf/open/misc/asteroid/basalt{
initial_gas_mix = "n2=23;o2=14;TEMP=2.7"
},
Expand Down
12 changes: 3 additions & 9 deletions _maps/map_files/KiloStation2/KiloStation2.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -34106,10 +34106,7 @@
/obj/effect/decal/cleanable/blood/gibs/old,
/obj/effect/spawner/random/structure/crate,
/obj/effect/mapping_helpers/burnt_floor,
/mob/living/basic/chicken{
name = "Kentucky";
real_name = "Kentucky"
},
/mob/living/basic/chicken/teshari,
/turf/open/floor/plating,
/area/station/maintenance/starboard)
"kVv" = (
Expand Down Expand Up @@ -42491,10 +42488,7 @@
/area/station/cargo/storage)
"nFN" = (
/obj/machinery/igniter/incinerator_ordmix,
/mob/living/basic/chicken{
name = "Kentucky";
real_name = "Kentucky"
},
/mob/living/basic/chicken/teshari,
/turf/open/floor/engine/vacuum,
/area/station/science/ordnance/burnchamber)
"nFT" = (
Expand Down Expand Up @@ -75589,7 +75583,7 @@
/area/station/hallway/primary/central/fore)
"yfS" = (
/obj/machinery/light/small/directional/west,
/mob/living/basic/chicken,
/mob/living/basic/chicken/teshari,
/turf/open/misc/sandy_dirt,
/area/station/service/hydroponics/garden)
"ygj" = (
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/dcs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ PROCESSING_SUBSYSTEM_DEF(dcs)
var/datum/element/eletype = arguments[1]
var/list/fullid = list(eletype)
var/list/named_arguments
for(var/i in initial(eletype.argument_hash_start_idx) to length(arguments))
for(var/i in initial(eletype.argument_hash_start_idx) to (initial(eletype.argument_hash_end_idx) || length(arguments)))
var/key = arguments[i]

if(istext(key))
Expand Down
10 changes: 8 additions & 2 deletions code/datums/elements/_element.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@
/**
* The index of the first attach argument to consider for duplicate elements
*
* All arguments from this index onwards (1 based) are hashed into the key to determine
* if this is a new unique element or one already exists
* All arguments from this index onwards (1 based, until `argument_hash_end_idx` is reached, if set)
* are hashed into the key to determine if this is a new unique element or one already exists
*
* Is only used when flags contains [ELEMENT_BESPOKE]
*
* This is infinity so you must explicitly set this
*/
var/argument_hash_start_idx = INFINITY
/**
* The index of the last attach argument to consider for duplicate elements
* Only used when `element_flags` contains [ELEMENT_BESPOKE].
* If not set, it'll copy every argument from `argument_hash_start_idx` onwards as normal
*/
var/argument_hash_end_idx = 0

/// Activates the functionality defined by the element on the given target datum
/datum/element/proc/Attach(datum/target)
Expand Down
67 changes: 43 additions & 24 deletions code/datums/elements/atmos_requirements.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@
/datum/element/atmos_requirements
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
argument_hash_end_idx = 3
/// An assoc list of "what atmos does this mob require to survive in".
var/list/atmos_requirements
/// How much (brute) damage we take from being in unsuitable atmos.
var/unsuitable_atmos_damage

/datum/element/atmos_requirements/Attach(datum/target, list/atmos_requirements, unsuitable_atmos_damage = 5)
/datum/element/atmos_requirements/Attach(datum/target, list/atmos_requirements, unsuitable_atmos_damage = 5, mapload = FALSE)
. = ..()
if(!isliving(target))
return ELEMENT_INCOMPATIBLE
if(!atmos_requirements)
stack_trace("[type] added to [target] without any requirements specified.")
CRASH("[type] added to [target] without any requirements specified.")
var/list/short = atmos_requirements
if(!short["min_oxy"] && !short["max_oxy"] && !short["min_plas"] && !short["max_plas"] && !short["min_co2"] && !short["max_co2"] && !short["min_n2"] && !short["max_n2"])
CRASH("[type] added to [target] with all requirements set to 0.")
src.atmos_requirements = atmos_requirements
src.unsuitable_atmos_damage = unsuitable_atmos_damage
RegisterSignal(target, COMSIG_LIVING_HANDLE_BREATHING, PROC_REF(on_non_stasis_life))

if(!mapload || !PERFORM_ALL_TESTS(focus_only/atmos_and_temp_requirements))
return
check_safe_environment(target)

/datum/element/atmos_requirements/Detach(datum/target)
. = ..()
UnregisterSignal(target, COMSIG_LIVING_HANDLE_BREATHING)
Expand All @@ -42,34 +50,45 @@
return TRUE

var/turf/open/open_turf = target.loc
if(!open_turf.air && (atmos_requirements["min_oxy"] || atmos_requirements["min_tox"] || atmos_requirements["min_n2"] || atmos_requirements["min_co2"]))
if(isnull(open_turf.air))
if(atmos_requirements["min_oxy"] || atmos_requirements["min_plas"] || atmos_requirements["min_n2"] || atmos_requirements["min_co2"])
return FALSE
return TRUE

var/list/gases = get_atmos_req_list(open_turf)

if(!ISINRANGE(gases["oxy"], atmos_requirements["min_oxy"], (atmos_requirements["max_oxy"] || INFINITY)))
return FALSE
if(!ISINRANGE(gases["plas"], atmos_requirements["min_plas"], (atmos_requirements["max_plas"] || INFINITY)))
return FALSE
if(!ISINRANGE(gases["n2"], atmos_requirements["min_n2"], (atmos_requirements["max_n2"] || INFINITY)))
return FALSE
if(!ISINRANGE(gases["co2"], atmos_requirements["min_co2"], (atmos_requirements["max_co2"] || INFINITY)))
return FALSE
return TRUE

/datum/element/atmos_requirements/proc/get_atmos_req_list(turf/open/open_turf)
var/open_turf_gases = open_turf.air.gases
open_turf.air.assert_gases(/datum/gas/oxygen, /datum/gas/pluoxium, /datum/gas/nitrogen, /datum/gas/carbon_dioxide, /datum/gas/plasma)

var/plas = open_turf_gases[/datum/gas/plasma][MOLES]
var/oxy = open_turf_gases[/datum/gas/oxygen][MOLES] + (open_turf_gases[/datum/gas/pluoxium][MOLES] * PLUOXIUM_PROPORTION)
var/n2 = open_turf_gases[/datum/gas/nitrogen][MOLES]
var/co2 = open_turf_gases[/datum/gas/carbon_dioxide][MOLES]
var/list/return_gases = list()
return_gases["plas"] = open_turf_gases[/datum/gas/plasma][MOLES]
return_gases["oxy"] = open_turf_gases[/datum/gas/oxygen][MOLES] + (open_turf_gases[/datum/gas/pluoxium][MOLES] * PLUOXIUM_PROPORTION)
return_gases["n2"] = open_turf_gases[/datum/gas/nitrogen][MOLES]
return_gases["co2"] = open_turf_gases[/datum/gas/carbon_dioxide][MOLES]

open_turf.air.garbage_collect()

if(atmos_requirements["min_oxy"] && oxy < atmos_requirements["min_oxy"])
return FALSE
else if(atmos_requirements["max_oxy"] && oxy > atmos_requirements["max_oxy"])
return FALSE
else if(atmos_requirements["min_plas"] && plas < atmos_requirements["min_plas"])
return FALSE
else if(atmos_requirements["max_plas"] && plas > atmos_requirements["max_plas"])
return FALSE
else if(atmos_requirements["min_n2"] && n2 < atmos_requirements["min_n2"])
return FALSE
else if(atmos_requirements["max_n2"] && n2 > atmos_requirements["max_n2"])
return FALSE
else if(atmos_requirements["min_co2"] && co2 < atmos_requirements["min_co2"])
return FALSE
else if(atmos_requirements["max_co2"] && co2 > atmos_requirements["max_co2"])
return FALSE
return return_gases

return TRUE
///Ensures that maploaded mobs are in a safe environment. Unit test stuff.
/datum/element/atmos_requirements/proc/check_safe_environment(mob/living/living_mob)
if(living_mob.stat == DEAD || is_breathable_atmos(living_mob))
return
var/turf/open/open_turf = living_mob.loc
var/list/gases
var/string_text = "No Air"
if(open_turf.air)
gases = get_atmos_req_list(open_turf)
string_text = "O2: [gases["o2"]] - Plasma: [gases["plasma"]] - N2: [gases["n2"]] - CO2: [gases["co2"]]"
stack_trace("[living_mob] loaded on a turf with unsafe atmos at \[[open_turf.x], [open_turf.y], [open_turf.z]\] (area : [open_turf.loc]). Turf gases: [string_text]. Check the mob atmos requirements again.")
72 changes: 0 additions & 72 deletions code/datums/elements/basic_body_temp_sensitive.dm

This file was deleted.

Loading

0 comments on commit 2fa4912

Please sign in to comment.