Skip to content

Commit

Permalink
Should fix most issues with bots. (#33647)
Browse files Browse the repository at this point in the history
* Hurray!

* oops

* debug shit
  • Loading branch information
ShiftyRail authored Nov 12, 2022
1 parent 02c4ae5 commit ddbb390
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 33 deletions.
6 changes: 4 additions & 2 deletions __DEFINES/setup.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
#define COOKTEMP_DEFAULT T0C + 316 //Around 600 F
23 changes: 12 additions & 11 deletions code/game/machinery/bots/bots.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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]")
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/bots/cleanbot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
..()
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/bots/ed209bot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/bots/floorbot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
. = ..()
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/bots/medbot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 29 additions & 13 deletions code/game/machinery/bots/mulebot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Remote Controlled from QM's PDA
*
* Hello, the path algorithm now uses
*
* NOW USES WHAT??? UH???? UH????
*
*
*
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -589,14 +597,15 @@ 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
mode = MODE_MOVING
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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/bots/secbot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions code/game/machinery/navbeacon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit ddbb390

Please sign in to comment.