From 06c9bdafeedcc8546eb20ce56365172e7beb4c6b Mon Sep 17 00:00:00 2001 From: Mark Suckerberg Date: Tue, 19 Sep 2023 16:44:50 -0500 Subject: [PATCH] Firebot GC --- .../mob/living/simple_animal/bot/firebot.dm | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/code/modules/mob/living/simple_animal/bot/firebot.dm b/code/modules/mob/living/simple_animal/bot/firebot.dm index 4bfa9dd98a6c..ba8eafba9010 100644 --- a/code/modules/mob/living/simple_animal/bot/firebot.dm +++ b/code/modules/mob/living/simple_animal/bot/firebot.dm @@ -23,8 +23,8 @@ window_name = "Mobile Fire Extinguisher v1.0" path_image_color = "#FFA500" - var/atom/target_fire - var/atom/old_target_fire + var/datum/weakref/target_fire_ref + var/datum/weakref/old_target_fire_ref var/obj/item/extinguisher/internal_ext @@ -106,15 +106,15 @@ /mob/living/simple_animal/bot/firebot/bot_reset() ..() - target_fire = null - old_target_fire = null + target_fire_ref = null + old_target_fire_ref = null ignore_list = list() anchored = FALSE update_appearance() /mob/living/simple_animal/bot/firebot/proc/soft_reset() path = list() - target_fire = null + target_fire_ref = null mode = BOT_IDLE last_found = world.time update_appearance() @@ -149,7 +149,7 @@ audible_message("[src] buzzes oddly!") playsound(src, "sparks", 75, TRUE, SHORT_RANGE_SOUND_EXTRARANGE) if(user) - old_target_fire = user + old_target_fire_ref = WEAKREF(user) extinguish_fires = FALSE extinguish_people = TRUE @@ -184,7 +184,7 @@ else if(isturf(target)) var/turf/open/T = target - if(T.active_hotspot) + if(T.active_hotspot || T.turf_fire) return TRUE return FALSE @@ -194,12 +194,12 @@ return if(IsStun() || IsParalyzed()) - old_target_fire = target_fire - target_fire = null + old_target_fire_ref = target_fire_ref + target_fire_ref = null mode = BOT_IDLE return - if(prob(1) && target_fire == null) + if(prob(1) && !target_fire_ref) var/list/messagevoice = list("No fires detected." = 'sound/voice/firebot/nofires.ogg', "Only you can prevent station fires." = 'sound/voice/firebot/onlyyou.ogg', "Temperature nominal." = 'sound/voice/firebot/tempnominal.ogg', @@ -210,24 +210,39 @@ // Couldn't reach the target, reset and try again ignoring the old one if(frustration > 8) - old_target_fire = target_fire + old_target_fire_ref = target_fire_ref soft_reset() + var/atom/target_fire = target_fire_ref?.resolve() + // We extinguished our target or it was deleted if(QDELETED(target_fire) || !is_burning(target_fire) || isdead(target_fire)) target_fire = null + target_fire_ref = null var/scan_range = (stationary_mode ? 1 : DEFAULT_SCAN_RANGE) + var/old_target_fire = old_target_fire_ref?.resolve() if(extinguish_people) target_fire = scan(/mob/living, old_target_fire, scan_range) // Scan for burning humans first + target_fire_ref = WEAKREF(target_fire) - if(target_fire == null && extinguish_fires) + if(!target_fire && extinguish_fires) target_fire = scan(/turf/open, old_target_fire, scan_range) // Scan for burning turfs second + target_fire_ref = WEAKREF(target_fire) - old_target_fire = target_fire + old_target_fire_ref = target_fire_ref + + if(!target_fire) + if(auto_patrol) + if(mode == BOT_IDLE || mode == BOT_START_PATROL) + start_patrol() + + if(mode == BOT_PATROL) + bot_patrol() + return // Target reached ENGAGE WATER CANNON - if(target_fire && (get_dist(src, target_fire) <= (emagged == 2 ? 1 : 2))) // Make the bot spray water from afar when not emagged + if(get_dist(src, target_fire) <= (emagged == 2 ? 1 : 2)) // Make the bot spray water from afar when not emagged if((speech_cooldown + SPEECH_INTERVAL) < world.time) if(ishuman(target_fire)) speak("Stop, drop and roll!") @@ -243,39 +258,32 @@ soft_reset() // Target ran away - else if(target_fire && path.len && (get_dist(target_fire,path[path.len]) > 2)) + else if(length(path) && (get_dist(target_fire, path[length(path)]) > 2)) path = list() mode = BOT_IDLE last_found = world.time - else if(target_fire && stationary_mode) + else if(stationary_mode) soft_reset() return - if(target_fire && (get_dist(src, target_fire) > 2)) + if(get_dist(src, target_fire) > 2) path = get_path_to(src, get_turf(target_fire), /turf/proc/Distance_cardinal, 0, 30, 1, id=access_card) mode = BOT_MOVING - if(!path.len) + if(!length(path)) soft_reset() - if(path.len > 0 && target_fire) + if(length(path)) if(!bot_move(path[path.len])) - old_target_fire = target_fire + old_target_fire_ref = target_fire_ref soft_reset() return // We got a target but it's too far away from us - if(path.len > 8 && target_fire) + if(length(path) > 8) frustration++ - if(auto_patrol && !target_fire) - if(mode == BOT_IDLE || mode == BOT_START_PATROL) - start_patrol() - - if(mode == BOT_PATROL) - bot_patrol() - //Look for burning people or turfs around the bot /mob/living/simple_animal/bot/firebot/process_scan(atom/scan_target)