Improve cleanbot ai slightly

*Multiple cleanbots will no longer attempt to clean the same tile at the same time.
*Cleanbots will now clean tiles closer to them first.
This commit is contained in:
Meghan-Rossi
2020-08-18 13:50:25 +01:00
parent f621edf039
commit 925b8350f5
4 changed files with 31 additions and 7 deletions

View File

@@ -19,6 +19,11 @@
..()
get_targets()
/mob/living/bot/cleanbot/Destroy()
if(target)
cleanbot_reserved_turfs -= target
return ..()
/mob/living/bot/cleanbot/handleIdle()
if(!screwloose && !oddbutton && prob(2))
custom_emote(2, "makes an excited booping sound!")
@@ -65,18 +70,29 @@
return .
/mob/living/bot/cleanbot/lookForTargets()
for(var/obj/effect/decal/cleanable/D in view(world.view, src)) // There was some odd code to make it start with nearest decals, it's unnecessary, this works
if(confirmTarget(D))
target = D
return
for(var/i = 0, i <= world.view, i++)
for(var/obj/effect/decal/cleanable/D in view(i, src))
if (i > 0 && get_dist(src, D) < i)
continue // already checked this one
else if(confirmTarget(D))
target = D
cleanbot_reserved_turfs += D
return
/mob/living/bot/resetTarget()
cleanbot_reserved_turfs -= target
..()
/mob/living/bot/cleanbot/confirmTarget(var/obj/effect/decal/cleanable/D)
if(!..())
return 0
return FALSE
if(D.loc in cleanbot_reserved_turfs)
return FALSE
for(var/T in target_types)
if(istype(D, T))
return 1
return 0
return TRUE
return FALSE
/mob/living/bot/cleanbot/handleAdjacentTarget()
if(get_turf(target) == src.loc)
@@ -105,6 +121,7 @@
return
qdel(D)
if(D == target)
cleanbot_reserved_turfs -= target
target = null
busy = 0
update_icons()