From bb4e21baf63746dab21272cee843d1bae4a113e1 Mon Sep 17 00:00:00 2001 From: warriorstar-orion Date: Sat, 1 Feb 2025 21:54:43 -0500 Subject: [PATCH] fix two vermin infestation issues (#28181) * fix two vermin infestation issues * Update code/modules/events/infestation.dm Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> Signed-off-by: Burzah <116982774+Burzah@users.noreply.github.com> --------- Signed-off-by: Burzah <116982774+Burzah@users.noreply.github.com> Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> --- code/__HELPERS/unsorted.dm | 6 ------ code/modules/events/infestation.dm | 30 ++++++++++++++++++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 2813c64425f..6e5ca9e91ba 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -1562,12 +1562,6 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new) if(areas) . |= T.loc -/proc/turf_clear(turf/T) - for(var/atom/A in T) - if(A.simulated) - return FALSE - return TRUE - /proc/screen_loc2turf(scr_loc, turf/origin) var/tX = splittext(scr_loc, ",") var/tY = splittext(tX[2], ":") diff --git a/code/modules/events/infestation.dm b/code/modules/events/infestation.dm index d3a9ff95745..ca3c31111b8 100644 --- a/code/modules/events/infestation.dm +++ b/code/modules/events/infestation.dm @@ -27,17 +27,27 @@ /datum/event/infestation/start() var/list/turf/simulated/floor/turfs = list() - spawn_area_type = pick(spawn_areas) - for(var/areapath in typesof(spawn_area_type)) - var/area/A = locate(areapath) - if(!A) - log_debug("Failed to locate area for infestation event!") - kill() - return - for(var/turf/simulated/floor/F in A.contents) - if(turf_clear(F)) - turfs += F + // shuffle in place so we don't have do that dance where we make a copy of + // the list, then pick and take, then do some conditional logic to make sure + // there's still areas to choose from, etc etc, it's a small list, it's cheap + shuffle_inplace(spawn_areas) + for(var/spawn_area in spawn_areas) + for(var/area_type in typesof(spawn_area)) + var/area/destination = locate(area_type) + if(!destination) + continue + for(var/turf/simulated/floor/F in destination.contents) + if(!is_blocked_turf(F)) + turfs += F + if(length(turfs)) + spawn_area_type = area_type + spawn_on_turfs(turfs) + return + log_debug("Failed to locate area for infestation event!") + kill() + +/datum/event/infestation/proc/spawn_on_turfs(list/turfs) var/list/spawn_types = list() var/max_number vermin = rand(0, 2)