From 925b8350f569ec87d50a75eefd70a8fbfa5a4bc3 Mon Sep 17 00:00:00 2001 From: Meghan-Rossi <56671765+Meghan-Rossi@users.noreply.github.com> Date: Tue, 18 Aug 2020 13:50:25 +0100 Subject: [PATCH] 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. --- code/_helpers/global_lists.dm | 1 + code/game/turfs/turf.dm | 1 + code/modules/mob/living/bot/cleanbot.dm | 31 ++++++++++++++----- .../meghan rossi - cleanbot tweaks.yml | 5 +++ 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 html/changelogs/meghan rossi - cleanbot tweaks.yml diff --git a/code/_helpers/global_lists.dm b/code/_helpers/global_lists.dm index 2735d124fe..7f170fbe8e 100644 --- a/code/_helpers/global_lists.dm +++ b/code/_helpers/global_lists.dm @@ -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/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/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/landmarks_list = list() //list of all landmarks created diff --git a/code/game/turfs/turf.dm b/code/game/turfs/turf.dm index 626ee68c71..4bc205c933 100644 --- a/code/game/turfs/turf.dm +++ b/code/game/turfs/turf.dm @@ -49,6 +49,7 @@ /turf/Destroy() . = QDEL_HINT_IWILLGC + cleanbot_reserved_turfs -= src ..() /turf/ex_act(severity) diff --git a/code/modules/mob/living/bot/cleanbot.dm b/code/modules/mob/living/bot/cleanbot.dm index 6a4c45f123..7512480374 100644 --- a/code/modules/mob/living/bot/cleanbot.dm +++ b/code/modules/mob/living/bot/cleanbot.dm @@ -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() diff --git a/html/changelogs/meghan rossi - cleanbot tweaks.yml b/html/changelogs/meghan rossi - cleanbot tweaks.yml new file mode 100644 index 0000000000..7074273745 --- /dev/null +++ b/html/changelogs/meghan rossi - cleanbot tweaks.yml @@ -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."