From e756d2f5bc8a0419bcbba5a52a19d53caea4795b Mon Sep 17 00:00:00 2001 From: FabianK3 <21039694+FabianK3@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:19:37 +0200 Subject: [PATCH] Fixed Farmbot water auto refill (#20073) ### Bug Fixes #19753 ### Changes The auto refill logic was basically completely missing. I have added the sink selection to `think()`, the refill action to `UnarmedAttack()` and some light refactoring. --- code/modules/mob/living/bot/farmbot.dm | 44 ++++++++++++++----- .../fabiank3-bugfix-farmbot-water-refill.yml | 6 +++ 2 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 html/changelogs/fabiank3-bugfix-farmbot-water-refill.yml diff --git a/code/modules/mob/living/bot/farmbot.dm b/code/modules/mob/living/bot/farmbot.dm index 72945b166e6..22cfb3d339e 100644 --- a/code/modules/mob/living/bot/farmbot.dm +++ b/code/modules/mob/living/bot/farmbot.dm @@ -169,19 +169,25 @@ target = H break else - for(var/obj/machinery/portable_atmospherics/hydroponics/tray in view(7, src)) - if(!tray.seed) //No seed? We don't care. - continue - if(!process_tray(tray)) //If there's nothing for us to do with the plant, ignore this tray. - continue - if(pathfind(tray)) //If we can get there, we can accept it as a target. - target = tray - frustration = 0 - break + if(check_tank()) + for(var/obj/structure/sink/S in view(7, src)) + if(pathfind(get_turf(S))) + target = S + frustration = 0 + break + else + for(var/obj/machinery/portable_atmospherics/hydroponics/tray in view(7, src)) + if(!tray.seed) //No seed? We don't care. + continue + if(!process_tray(tray)) //If there's nothing for us to do with the plant, ignore this tray. + continue + if(pathfind(get_turf(tray))) //If we can get there, we can accept it as a target. + target = tray + frustration = 0 + break -/mob/living/bot/farmbot/proc/pathfind(var/atom/A) - var/turf/targetloc = get_turf(A) +/mob/living/bot/farmbot/proc/pathfind(var/turf/targetloc) if(!targetloc) return FALSE @@ -246,6 +252,13 @@ attacking = TRUE addtimer(CALLBACK(src, PROC_REF(do_action_on_tray), FARMBOT_NUTRIMENT, T), 3 SECONDS) + else if(istype(A, /obj/structure/sink)) + action = "water" + update_icon() + visible_message(SPAN_NOTICE("[src] starts refilling its tank from \the [A].")) + attacking = TRUE + addtimer(CALLBACK(src, PROC_REF(refill_water)), 3 SECONDS) + else if(emagged && ishuman(A)) var/action = pick("weed", "water") attacking = TRUE @@ -301,6 +314,13 @@ /mob/living/bot/farmbot/proc/rearm_attacking() attacking = FALSE +/mob/living/bot/farmbot/proc/refill_water() + tank.reagents.add_reagent(/singleton/reagent/water, (tank.reagents.maximum_volume - tank.reagents.total_volume)) + playsound(get_turf(src), 'sound/effects/slosh.ogg', 25, TRUE) + action = "" + update_icon() + attacking = FALSE + /mob/living/bot/farmbot/explode() visible_message(SPAN_DANGER("[src] blows apart!")) var/turf/T = get_turf(src) @@ -340,7 +360,7 @@ /mob/living/bot/farmbot/proc/check_tank() if(!tank) return FALSE - return ((!target && refills_water && tank.reagents.total_volume < tank.reagents.maximum_volume) || ((tank.reagents.total_volume ) / tank.reagents.maximum_volume) <= 0.3) + return (refills_water && (tank.reagents.total_volume / tank.reagents.maximum_volume) <= 0.3) /obj/item/farmbot_arm_assembly name = "water tank/robot arm assembly" diff --git a/html/changelogs/fabiank3-bugfix-farmbot-water-refill.yml b/html/changelogs/fabiank3-bugfix-farmbot-water-refill.yml new file mode 100644 index 00000000000..29cdc9540f6 --- /dev/null +++ b/html/changelogs/fabiank3-bugfix-farmbot-water-refill.yml @@ -0,0 +1,6 @@ +author: FabianK3 + +delete-after: True + +changes: + - bugfix: "Fixed the water tank refill of Farmbots. Farmbots will now refill their tank if the option is enabled and a sink is nearby."