From cf8df529e51f4eea76e6bcb930b3e034992e5731 Mon Sep 17 00:00:00 2001 From: alex-gh Date: Sun, 25 Sep 2022 18:27:27 +0200 Subject: [PATCH] Fixes anomalies spawning in walls (#19064) * Fixes anomalies spawning in walls * break * Update code/modules/events/anomaly.dm Co-authored-by: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com> * better log message Co-authored-by: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com> --- code/modules/events/anomaly.dm | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/code/modules/events/anomaly.dm b/code/modules/events/anomaly.dm index 3e9230742fa..7835475faef 100644 --- a/code/modules/events/anomaly.dm +++ b/code/modules/events/anomaly.dm @@ -1,23 +1,32 @@ +#define TURF_FIND_TRIES 10 + /datum/event/anomaly name = "Anomaly: Energetic Flux" var/obj/effect/anomaly/anomaly_path = /obj/effect/anomaly/flux + var/turf/target_turf announceWhen = 1 /datum/event/anomaly/setup() - impact_area = findEventArea() - if(!impact_area) - CRASH("No valid areas for anomaly found.") - var/list/turf_test = get_area_turfs(impact_area) - if(!length(turf_test)) - CRASH("Anomaly: No valid turfs found for [impact_area] - [impact_area.type]") + for(var/tries in 0 to TURF_FIND_TRIES) + impact_area = findEventArea() + if(!impact_area) + CRASH("No valid areas for anomaly found.") + var/list/candidate_turfs = get_area_turfs(impact_area) + while(length(candidate_turfs)) + var/turf/candidate = pick_n_take(candidate_turfs) + if(!is_blocked_turf(candidate,TRUE)) + target_turf = candidate + break + if(target_turf) + break + if(!target_turf) + CRASH("Anomaly: Unable to find a valid turf to spawn the anomaly. Last area tried: [impact_area] - [impact_area.type]") /datum/event/anomaly/announce() GLOB.event_announcement.Announce("Localized hyper-energetic flux wave detected on long range scanners. Expected location of impact: [impact_area.name].", "Anomaly Alert", 'sound/AI/anomaly_flux.ogg') /datum/event/anomaly/start() - var/turf/T = pick(get_area_turfs(impact_area)) - var/newAnomaly - if(T) - newAnomaly = new anomaly_path(T) - if(newAnomaly) - announce_to_ghosts(newAnomaly) + var/newAnomaly = new anomaly_path(target_turf) + announce_to_ghosts(newAnomaly) + +#undef TURF_FIND_TRIES