From 58e8aef49db46eb9d7c26e6e11fd4f3470952283 Mon Sep 17 00:00:00 2001 From: Archie <53913550+ArchieBeepBoop@users.noreply.github.com> Date: Tue, 13 Sep 2022 15:30:13 -0300 Subject: [PATCH] General fixes and adding a general helper --- code/__HELPERS/unsorted_hyper.dm | 74 +++++++++++++++++++ code/modules/jobs/job_types/job.dm | 2 +- .../code/game/machinery/safety_tether.dm | 10 +-- hyperstation/code/mobs/mimic.dm | 69 +---------------- tgstation.dme | 1 + 5 files changed, 84 insertions(+), 72 deletions(-) create mode 100644 code/__HELPERS/unsorted_hyper.dm diff --git a/code/__HELPERS/unsorted_hyper.dm b/code/__HELPERS/unsorted_hyper.dm new file mode 100644 index 000000000..b6f26f243 --- /dev/null +++ b/code/__HELPERS/unsorted_hyper.dm @@ -0,0 +1,74 @@ +// This list was originally created to narrow the list of safe areas for mobs to spawn in the station. If an area is considered too dangerous for something to spawn in, kindly add it to this list. +GLOBAL_LIST_INIT(basic_safe_area_list, typecacheof(list( + /area/space, + /area/shuttle, + /area/mine, + /area/holodeck, + /area/ruin, + /area/hallway, + /area/hallway/primary, + /area/hallway/secondary, + /area/hallway/secondary/entry, + /area/engine/supermatter, + /area/engine/atmospherics_engine, + /area/engine/engineering/reactor_core, + /area/engine/engineering/reactor_control, + /area/ai_monitored/turret_protected, + /area/layenia/cloudlayer, + /area/asteroid/nearstation, + /area/science/server, + /area/science/explab, + /area/science/xenobiology, + /area/security/processing))) + +// Performance intensive check for picking an area with turfs that are considered the safest possible to spawn something in. +//Only use this for creatures, as it considers people around, temperature, area size and more. +/proc/get_safest_possible_turfs(list/blacklisted_areas, spawncount) + var/list/area/stationAreas = list() + var/list/area/eligible_areas = list() + var/validFound = FALSE + var/list/turf/validTurfs = list() + var/area/pickedArea + if(!blacklisted_areas.len) + blacklisted_areas = GLOB.basic_safe_area_list + for(var/area/A in world) // Get the areas in the Z level + if(A.z == SSmapping.station_start) + stationAreas += A + for(var/area/place in stationAreas) // first we check if it's a valid area + if(place.outdoors) + continue + if(place.areasize < 16) + continue + if(is_type_in_typecache(place, blacklisted_areas)) + continue + eligible_areas += place + for(var/area/place in eligible_areas) // now we check if there are people in that area + var/numOfPeople + for(var/mob/living/carbon/H in place) + numOfPeople++ + break + if(numOfPeople > 0) + eligible_areas -= place // removes this area from the list of eligible areas, it has people in it + while(!validFound || !eligible_areas.len) + pickedArea = pick_n_take(eligible_areas) + var/list/turf/t = get_area_turfs(pickedArea, SSmapping.station_start) + for(var/turf/thisTurf in t) // now we check if it's a closed turf, cold turf or occupied turf and yeet it + if(isopenturf(thisTurf)) + var/turf/open/tempGet = thisTurf + if(tempGet.air.temperature <= T0C) + t -= thisTurf + continue + if(isclosedturf(thisTurf)) + t -= thisTurf + else + for(var/obj/O in thisTurf) + if(O.density && !(istype(O, /obj/structure/table))) + t -= thisTurf + break + if(t.len >= spawncount) //Is the number of available turfs equal or bigger than spawncount? + validFound = TRUE + validTurfs = t + return validTurfs + if(!validFound) + message_admins("A function attempted to get safe turfs, but we found none.") + return null diff --git a/code/modules/jobs/job_types/job.dm b/code/modules/jobs/job_types/job.dm index 024fb1cc7..e3e2ca4f1 100644 --- a/code/modules/jobs/job_types/job.dm +++ b/code/modules/jobs/job_types/job.dm @@ -67,7 +67,7 @@ var/whitelist_type = "" //load characters loadout on spawn - var loadout = TRUE + var/loadout = TRUE //Only override this proc //H is usually a human unless an /equip override transformed it diff --git a/hyperstation/code/game/machinery/safety_tether.dm b/hyperstation/code/game/machinery/safety_tether.dm index 1955d7599..0f636f900 100644 --- a/hyperstation/code/game/machinery/safety_tether.dm +++ b/hyperstation/code/game/machinery/safety_tether.dm @@ -83,6 +83,8 @@ var/radio_key = /obj/item/encryptionkey/headset_medsci /obj/machinery/safety_tether/Initialize() + //ensures light is properly centered around the tether. Removes lighting system's pixel approximation that breaks it. + light_source = get_turf(src) . = ..() //Adds this to the global list of safety tethers in the world to pull from when chasms attempt to drop mobs @@ -95,10 +97,7 @@ radio.canhear_range = 0 radio.recalculateChannels() - //ensures light is properly centered around the tether. Removes lighting system's pixel approximation that breaks it. - light_source = get_turf(src) update_icon() - power_change() //Here to start lights on ititialization. /obj/machinery/safety_tether/Destroy() QDEL_NULL(radio) @@ -228,7 +227,8 @@ SPEAKCOMMON("The Safety Tether's shut down from a lack of power.") light_source.set_light(0) else - SPEAKCOMMON("The Safety Tether is back online.") + if(SSticker.HasRoundStarted()) + SPEAKCOMMON("The Safety Tether is back online.") light_source.set_light(brightness_on, light_power, light_color) update_icon() @@ -251,4 +251,4 @@ //#undef SPEAK #undef SPEAKCOMMON #undef SPEAKMEDICAL -#undef SPEAKSCIENCE \ No newline at end of file +#undef SPEAKSCIENCE diff --git a/hyperstation/code/mobs/mimic.dm b/hyperstation/code/mobs/mimic.dm index c89e973c4..e6e3dc7f1 100644 --- a/hyperstation/code/mobs/mimic.dm +++ b/hyperstation/code/mobs/mimic.dm @@ -322,26 +322,6 @@ /datum/round_event/mimic_infestation announceWhen = 200 - var/static/list/mimic_station_areas_blacklist = typecacheof(/area/space, - /area/shuttle, - /area/mine, - /area/holodeck, - /area/ruin, - /area/hallway, - /area/hallway/primary, - /area/hallway/secondary, - /area/hallway/secondary/entry, - /area/engine/supermatter, - /area/engine/atmospherics_engine, - /area/engine/engineering/reactor_core, - /area/engine/engineering/reactor_control, - /area/ai_monitored/turret_protected, - /area/layenia/cloudlayer, - /area/asteroid/nearstation, - /area/science/server, - /area/science/explab, - /area/science/xenobiology, - /area/security/processing) var/spawncount = 1 fakeable = FALSE @@ -353,54 +333,11 @@ priority_announce("Unidentified lifesigns detected aboard [station_name()]. Secure any exterior access, including ducting and ventilation.", "Lifesign Alert", 'sound/ai/aliens.ogg') /datum/round_event/mimic_infestation/start() - var/list/area/stationAreas = list() - var/list/area/eligible_areas = list() - for(var/area/A in world) // Get the areas in the Z level - if(A.z == SSmapping.station_start) - stationAreas += A - for(var/area/place in stationAreas) // first we check if it's a valid area - if(place.outdoors) - continue - if(place.areasize < 16) - continue - if(is_type_in_typecache(place, mimic_station_areas_blacklist)) - continue - eligible_areas += place - for(var/area/place in eligible_areas) // now we check if there are people in that area - var/numOfPeople - for(var/mob/living/carbon/H in place) - numOfPeople++ - break - if(numOfPeople > 0) - eligible_areas -= place - - var/validFound = FALSE - var/list/turf/validTurfs = list() - var/area/pickedArea - while(!validFound || !eligible_areas.len) - pickedArea = pick_n_take(eligible_areas) - var/list/turf/t = get_area_turfs(pickedArea, SSmapping.station_start) - for(var/turf/thisTurf in t) // now we check if it's a closed turf, cold turf or occupied turf and yeet it - if(isopenturf(thisTurf)) - var/turf/open/tempGet = thisTurf - if(tempGet.air.temperature <= T0C) - t -= thisTurf - continue - if(isclosedturf(thisTurf)) - t -= thisTurf - else - for(var/obj/O in thisTurf) - if(O.density && !(istype(O, /obj/structure/table))) - t -= thisTurf - break - if(t.len >= spawncount) //Is the number of available turfs equal or bigger than spawncount? - validFound = TRUE - validTurfs = t - - if(!eligible_areas.len) + var/list/turf/validTurfs = get_safest_possible_turfs(GLOB.basic_safe_area_list, spawncount) + if(!validTurfs.len) message_admins("No eligible areas for spawning mimics.") return WAITING_FOR_SOMETHING - + var/area/pickedArea = get_area(pick(validTurfs)) notify_ghosts("A group of mimics has spawned in [pickedArea]!", source=pickedArea, action=NOTIFY_ATTACK, flashwindow = FALSE) while(spawncount > 0 && validTurfs.len) spawncount-- diff --git a/tgstation.dme b/tgstation.dme index 6236e1025..9affb3561 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -159,6 +159,7 @@ #include "code\__HELPERS\typelists.dm" #include "code\__HELPERS\unique_ids.dm" #include "code\__HELPERS\unsorted.dm" +#include "code\__HELPERS\unsorted_hyper.dm" #include "code\__HELPERS\verbs.dm" #include "code\__HELPERS\view.dm" #include "code\__HELPERS\sorts\__main.dm"