From ddbb390c64518ab835d94a89d9d73accf0f46235 Mon Sep 17 00:00:00 2001 From: ShiftyRail <31417754+ShiftyRail@users.noreply.github.com> Date: Sat, 12 Nov 2022 18:00:54 +0000 Subject: [PATCH] Should fix most issues with bots. (#33647) * Hurray! * oops * debug shit --- __DEFINES/setup.dm | 6 ++-- code/game/machinery/bots/bots.dm | 23 +++++++-------- code/game/machinery/bots/cleanbot.dm | 2 +- code/game/machinery/bots/ed209bot.dm | 2 +- code/game/machinery/bots/floorbot.dm | 2 +- code/game/machinery/bots/medbot.dm | 2 +- code/game/machinery/bots/mulebot.dm | 42 +++++++++++++++++++--------- code/game/machinery/bots/secbot.dm | 2 +- code/game/machinery/navbeacon.dm | 6 ++-- 9 files changed, 54 insertions(+), 33 deletions(-) diff --git a/__DEFINES/setup.dm b/__DEFINES/setup.dm index 8bec59fd3228..319bd924f9d4 100644 --- a/__DEFINES/setup.dm +++ b/__DEFINES/setup.dm @@ -1321,9 +1321,11 @@ var/default_colour_matrix = list(1,0,0,0,\ #define ASTAR_DEBUG 0 #if ASTAR_DEBUG == 1 #warn "Astar debug is on. Don't forget to turn it off after you've done :)" -#define astar_debug(text) to_chat(world, text) +#define astar_debug(text) //to_chat(world, text) +#define astar_debug_mulebots(text) to_chat(world, text) #else #define astar_debug(text) +#define astar_debug_mulebots(text) #endif #define BSQL_DEBUG_CONNECTION 0 @@ -1842,4 +1844,4 @@ var/list/weekend_days = list("Friday", "Saturday", "Sunday") #define COOKVESSEL_CONTAINS_CONTENTS (1<<1) //The cooking vessel contains non-reagent contents (eg. items) //Default cooking temperature -#define COOKTEMP_DEFAULT T0C + 316 //Around 600 F \ No newline at end of file +#define COOKTEMP_DEFAULT T0C + 316 //Around 600 F diff --git a/code/game/machinery/bots/bots.dm b/code/game/machinery/bots/bots.dm index 39b23cb87bae..d758fb1f3eb3 100644 --- a/code/game/machinery/bots/bots.dm +++ b/code/game/machinery/bots/bots.dm @@ -11,8 +11,8 @@ #if ASTAR_DEBUG == 1 #define log_astar_bot(text) visible_message("[src] : [text]") -#define log_astar_beacon(text) to_chat(world, "[src] : [text]") -#define log_astar_command(text) to_chat(world, "[src] : [text]") +#define log_astar_beacon(text) //to_chat(world, "[src] : [text]") +#define log_astar_command(text) //to_chat(world, "[src] : [text]") #else #define log_astar_bot(text) #define log_astar_beacon(text) @@ -74,7 +74,7 @@ var/summoned = FALSE // Were they summoned? - var/commanding_radio = /obj/item/radio/integrated/signal/bot + var/commanding_radios = list(/obj/item/radio/integrated/signal/bot) // Queue of directions. Just like shift-clicking on age of empires 2. It'll go to the next direction after it's finished with this one // It's a list of lists. These lists are coordinates @@ -364,10 +364,11 @@ // However, it just says, "i'm a bot looking for a beacon named [new_dest]" // Only [new_dest], if it exist, replies with its location. /obj/machinery/bot/proc/set_destination(var/new_dest) - log_astar_beacon("new_destination [new_dest]") - new_destination = new_dest - post_signal(beacon_freq, "findbeacon", "patrol") - awaiting_beacon = 1 + if (new_dest) + log_astar_beacon("new_destination [new_dest]") + new_destination = new_dest + post_signal(beacon_freq, "findbeacon", "patrol") + awaiting_beacon = 1 // Proc called when we reached our patrol destination. // Normal behaviour is to null the current target and find a new one. @@ -477,9 +478,9 @@ // -- Received an order via signal. This proc assumes the bot is the correct one to get the command. /obj/machinery/bot/proc/execute_signal_command(var/datum/signal/signal, var/command) - log_astar_command("received command [command]") - if (!istype(signal.source, commanding_radio)) - log_astar_command("refused command [command], wrong radio type") + log_astar_command("recieved command [command]") + if (!is_type_in_list(signal.source, commanding_radios)) + log_astar_command("refused command [command], wrong radio type. Expected [english_list(commanding_radios, and_text = " or ")] got [signal.source.type]") return TRUE switch (command) if ("auto_patrol") @@ -548,7 +549,7 @@ /obj/machinery/bot/proc/calc_path(var/target, var/callback, var/turf/avoid = null) ASSERT(target && callback) var/cardinal_proc = bot_flags & BOT_SPACEWORTHY ? /turf/proc/AdjacentTurfsSpace : /turf/proc/CardinalTurfsWithAccess - if ((get_dist(src, target) < 13) && !(bot_flags & BOT_NOT_CHASING)) // For beepers and ED209 + if (((get_dist(src, target) < 13) && !(bot_flags & BOT_NOT_CHASING)) || (get_dist(src, target) < 6)) // For beepers and ED209 // IMPORTANT: Quick AStar only takes TURFS as arguments. log_astar_bot("quick astar path calculation...") path = quick_AStar(src.loc, get_turf(target), cardinal_proc, /turf/proc/Distance_cardinal, 0, max(10,get_dist(src,target)*3), id=botcard, exclude=avoid, reference="\ref[src]") diff --git a/code/game/machinery/bots/cleanbot.dm b/code/game/machinery/bots/cleanbot.dm index 772016b04d4a..00bfec6cec27 100644 --- a/code/game/machinery/bots/cleanbot.dm +++ b/code/game/machinery/bots/cleanbot.dm @@ -41,7 +41,7 @@ var/attackcooldown = 5 SECONDS // for admin cancer locked = FALSE can_take_pai = TRUE - commanding_radio = /obj/item/radio/integrated/signal/bot/janitor + commanding_radios = list(/obj/item/radio/integrated/signal/bot/janitor) /obj/machinery/bot/cleanbot/New() ..() diff --git a/code/game/machinery/bots/ed209bot.dm b/code/game/machinery/bots/ed209bot.dm index 0da2bdd03c21..eab0895f488b 100644 --- a/code/game/machinery/bots/ed209bot.dm +++ b/code/game/machinery/bots/ed209bot.dm @@ -45,7 +45,7 @@ ) target_chasing_distance = 12 - commanding_radio = /obj/item/radio/integrated/signal/bot/beepsky + commanding_radios = list(/obj/item/radio/integrated/signal/bot/beepsky) /obj/item/weapon/ed209_assembly name = "ED-209 assembly" diff --git a/code/game/machinery/bots/floorbot.dm b/code/game/machinery/bots/floorbot.dm index b95f0fc2e0d4..4aab3eb79332 100644 --- a/code/game/machinery/bots/floorbot.dm +++ b/code/game/machinery/bots/floorbot.dm @@ -53,7 +53,7 @@ var/global/list/floorbot_targets=list() var/targetdirection beacon_freq = 1445 // navigation beacon frequency var/skin = null - commanding_radio = /obj/item/radio/integrated/signal/bot/floorbot + commanding_radios = list(/obj/item/radio/integrated/signal/bot/floorbot) /obj/machinery/bot/floorbot/New() . = ..() diff --git a/code/game/machinery/bots/medbot.dm b/code/game/machinery/bots/medbot.dm index e5466a84f526..0efff7ba929c 100644 --- a/code/game/machinery/bots/medbot.dm +++ b/code/game/machinery/bots/medbot.dm @@ -62,7 +62,7 @@ var/list/firstaid_exceptions = list( var/last_spoke = 0 bot_type = MED_BOT - commanding_radio = /obj/item/radio/integrated/signal/bot/medbot + commanding_radios = list(/obj/item/radio/integrated/signal/bot/medbot) /obj/machinery/bot/medbot/splashable() return FALSE diff --git a/code/game/machinery/bots/mulebot.dm b/code/game/machinery/bots/mulebot.dm index 9ecef2c57108..4656f6ffe9d8 100644 --- a/code/game/machinery/bots/mulebot.dm +++ b/code/game/machinery/bots/mulebot.dm @@ -5,7 +5,7 @@ * Remote Controlled from QM's PDA * * Hello, the path algorithm now uses - * + * NOW USES WHAT??? UH???? UH???? * * * @@ -78,7 +78,11 @@ var/global/mulebot_count = 0 var/run_over_cooldown = 3 SECONDS //how often a pAI-controlled MULEbot can damage a mob by running over them var/coolingdown = FALSE - commanding_radio = /obj/item/radio/integrated/signal/bot/mule + // Technically if we were true to form, the navbeacon should've an insider radio which would be sending the signal rather than sending the signal itself + // The gain in functionality if it were to be implented is negligeble for a lot of confusing code + // Maybe I will implement it in a saner one day. + // https://www.youtube.com/watch?v=w_yPZfHJSaY + commanding_radios = list(/obj/item/radio/integrated/signal/bot/mule, /obj/machinery/navbeacon, /obj/machinery/bot/mulebot) var/datum/bot/order/mule/current_order // where we're going and what we have to do once we arrive to destination @@ -303,8 +307,12 @@ var/global/mulebot_count = 0 switch (command) if ("return_home") start_home() + if ("") // empty + astar_debug_mulebots("Empty command") + return else // It's a new destination ! - set_destination(command) + astar_debug_mulebots("New destination started: [command]") + start() // returns the wire panel text /obj/machinery/bot/mulebot/proc/wires() @@ -589,6 +597,7 @@ var/global/mulebot_count = 0 // starts bot moving to current destination /obj/machinery/bot/mulebot/proc/start() + astar_debug_mulebots("Moving out toward [destination]") if(destination == home_destination) mode = MODE_RETURNING else @@ -596,7 +605,7 @@ var/global/mulebot_count = 0 icon_state = "[icon_initial][(wires.MobAvoid() != 0)]" /obj/machinery/bot/mulebot/set_destination(var/new_dest) - log_astar_beacon("new_destination [new_dest]") + astar_debug_mulebots("new_destination is now [new_dest]") new_destination = new_dest request_path(new_dest) @@ -606,15 +615,16 @@ var/global/mulebot_count = 0 signal.source = src signal.transmission_method = 1 var/list/keyval = list( - "findbeacon" = new_dest + "findbeacon" = new_dest, ) signal.data = keyval frequency.post_signal(src, signal, filter = RADIO_NAVBEACONS) + astar_debug_mulebots("requesting path on freq [frequency.frequency]") /obj/machinery/bot/mulebot/receive_signal(datum/signal/signal) var/recv = signal.data["beacon"] if(recv && recv == new_destination) // if the recvd beacon location matches the set destination, then we will navigate there - log_astar_beacon("new destination chosen, [recv]") + astar_debug_mulebots("new destination recieved and acknoweldged from navbeacons, [recv]") destination = new_destination new_destination = "" target = signal.source.loc @@ -827,6 +837,7 @@ var/global/mulebot_count = 0 qdel(src) /obj/machinery/bot/mulebot/process_pathing() + astar_debug_mulebots("process_pathing mulebot") if(path.len) set_glide_size(DELAY2GLIDESIZE(SS_WAIT_BOTS/steps_per)) if(!process_astar_path()) // either end of path or couldn't move @@ -845,13 +856,18 @@ var/global/mulebot_count = 0 return spawn(SS_WAIT_BOTS/steps_per) process_pathing() - else if(destinations_queue.len) - current_order = shift(destinations_queue) - var/stop_a_tile_before = current_order.thing_to_load != null - path = get_path_to(src, current_order.destination, 30, stop_a_tile_before, botcard) - if(path.len) - bots_list.Remove(src) - process_pathing() + else + if (destination && !(destinations_queue.len)) + var/datum/bot/order/mule/new_order = new(get_turf(target), null, FALSE) + destinations_queue.Add(new_order) + if(destinations_queue.len) + astar_debug_mulebots("destination_queue non empty") + current_order = shift(destinations_queue) + var/stop_a_tile_before = current_order.thing_to_load != null + path = get_path_to(src, current_order.destination, 30, stop_a_tile_before, botcard) + if(path.len) + bots_list.Remove(src) + process_pathing() /obj/machinery/bot/mulebot/process_astar_path() if(gcDestroyed) diff --git a/code/game/machinery/bots/secbot.dm b/code/game/machinery/bots/secbot.dm index fa251c2a1dbf..c95e8340c581 100644 --- a/code/game/machinery/bots/secbot.dm +++ b/code/game/machinery/bots/secbot.dm @@ -48,7 +48,7 @@ var/baton_type = /obj/item/weapon/melee/baton/ var/secbot_assembly_type = /obj/item/weapon/secbot_assembly/ - commanding_radio = /obj/item/radio/integrated/signal/bot/beepsky + commanding_radios = list(/obj/item/radio/integrated/signal/bot/beepsky, /obj/machinery/navbeacon) hack_abilities = list( /datum/malfhack_ability/oneuse/emag, diff --git a/code/game/machinery/navbeacon.dm b/code/game/machinery/navbeacon.dm index 8c45694fb5de..413a49ccfca6 100644 --- a/code/game/machinery/navbeacon.dm +++ b/code/game/machinery/navbeacon.dm @@ -90,11 +90,12 @@ var/list/navbeacons = list() var/request = signal.data["findbeacon"] if(request && ((request in codes) || request == "any" || request == location)) spawn(1) + astar_debug_mulebots("navbeacons accepted request [request] and posted its own location") post_signal(request) // return a signal giving location and transponder codes -/obj/machinery/navbeacon/proc/post_signal(request) +/obj/machinery/navbeacon/proc/post_signal(request, var/mulebot_signal = FALSE) var/datum/radio_frequency/frequency = radio_controller.return_frequency(freq) if(!frequency) return @@ -110,7 +111,8 @@ var/list/navbeacons = list() for(var/key in codes) signal.data[key] = codes[key] - astar_debug("navbeacon [location] posted signal with request [request] on freq [freq].") + astar_debug_mulebots("navbeacon [location] posted signal with request [request] on freq [freq].") + frequency.post_signal(src, signal, filter = RADIO_NAVBEACONS) /obj/machinery/navbeacon/attackby(var/obj/item/I, var/mob/user)