Skip to content

Commit

Permalink
Firebot GC
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSuckerberg committed Sep 19, 2023
1 parent 4380a1e commit 06c9bda
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions code/modules/mob/living/simple_animal/bot/firebot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -149,7 +149,7 @@
audible_message("<span class='danger'>[src] buzzes oddly!</span>")
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

Expand Down Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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!")
Expand All @@ -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)
Expand Down

0 comments on commit 06c9bda

Please sign in to comment.