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

@@ -11,6 +11,7 @@ var/global/list/ai_list = list() //List of all AIs, including clientless
var/global/list/living_mob_list = list() //List of all alive mobs, including clientless. Excludes /mob/new_player var/global/list/living_mob_list = list() //List of all alive mobs, including clientless. Excludes /mob/new_player
var/global/list/dead_mob_list = list() //List of all dead mobs, including clientless. Excludes /mob/new_player var/global/list/dead_mob_list = list() //List of all dead mobs, including clientless. Excludes /mob/new_player
var/global/list/listening_objects = list() //List of all objects which care about receiving messages (communicators, radios, etc) var/global/list/listening_objects = list() //List of all objects which care about receiving messages (communicators, radios, etc)
var/global/list/cleanbot_reserved_turfs = list() //List of all turfs currently targeted by some cleanbot
var/global/list/cable_list = list() //Index for all cables, so that powernets don't have to look through the entire world all the time var/global/list/cable_list = list() //Index for all cables, so that powernets don't have to look through the entire world all the time
var/global/list/landmarks_list = list() //list of all landmarks created var/global/list/landmarks_list = list() //list of all landmarks created

View File

@@ -49,6 +49,7 @@
/turf/Destroy() /turf/Destroy()
. = QDEL_HINT_IWILLGC . = QDEL_HINT_IWILLGC
cleanbot_reserved_turfs -= src
..() ..()
/turf/ex_act(severity) /turf/ex_act(severity)

View File

@@ -19,6 +19,11 @@
..() ..()
get_targets() get_targets()
/mob/living/bot/cleanbot/Destroy()
if(target)
cleanbot_reserved_turfs -= target
return ..()
/mob/living/bot/cleanbot/handleIdle() /mob/living/bot/cleanbot/handleIdle()
if(!screwloose && !oddbutton && prob(2)) if(!screwloose && !oddbutton && prob(2))
custom_emote(2, "makes an excited booping sound!") custom_emote(2, "makes an excited booping sound!")
@@ -65,18 +70,29 @@
return . return .
/mob/living/bot/cleanbot/lookForTargets() /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 for(var/i = 0, i <= world.view, i++)
if(confirmTarget(D)) 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 target = D
cleanbot_reserved_turfs += D
return return
/mob/living/bot/resetTarget()
cleanbot_reserved_turfs -= target
..()
/mob/living/bot/cleanbot/confirmTarget(var/obj/effect/decal/cleanable/D) /mob/living/bot/cleanbot/confirmTarget(var/obj/effect/decal/cleanable/D)
if(!..()) if(!..())
return 0 return FALSE
if(D.loc in cleanbot_reserved_turfs)
return FALSE
for(var/T in target_types) for(var/T in target_types)
if(istype(D, T)) if(istype(D, T))
return 1 return TRUE
return 0 return FALSE
/mob/living/bot/cleanbot/handleAdjacentTarget() /mob/living/bot/cleanbot/handleAdjacentTarget()
if(get_turf(target) == src.loc) if(get_turf(target) == src.loc)
@@ -105,6 +121,7 @@
return return
qdel(D) qdel(D)
if(D == target) if(D == target)
cleanbot_reserved_turfs -= target
target = null target = null
busy = 0 busy = 0
update_icons() update_icons()

View File

@@ -0,0 +1,5 @@
author: Meghan Rossi
delete-after: True
changes:
- rscadd: "Multiple cleanbots will no longer attempt to clean the same tile at the same time."
- rscadd: "Cleanbots will now clean tiles closer to them first."