Now working

This commit is contained in:
Shifty/Anthomansland
2020-06-11 13:57:32 +02:00
parent df51495c04
commit 46a5ef5306
10 changed files with 39 additions and 28 deletions

View File

@@ -1285,10 +1285,10 @@ var/default_colour_matrix = list(1,0,0,0,\
// null << "[x][a]")
#endif
#define ASTAR_DEBUG 1
#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)
#else
#define astar_debug(text)
#endif

View File

@@ -140,13 +140,11 @@ var/global/list/pathmakers = list()
pathmakers.Remove(src)
//cleaning after us
for(var/PathNode/PN in open.L)
PN.source.PathNodes[PM_id] = null
PN.source.PathNodes.Remove("[PM_id]")
open.L -= PN
qdel(PN)
for(var/turf/T in closed)
var/PathNode/PN = T.FindPathNode(PM_id)
T.PathNodes[PM_id] = null
T.PathNodes.Remove("[PM_id]")
closed -= T
qdel(PN)
owner = null
start = null

View File

@@ -121,6 +121,7 @@ length to avoid portals or something i guess?? Not that they're counted right no
var/distance_from_end //A* movement cost variable, how far it is from the end
var/distance_from_start //A* heuristic variable, how far it is from the start
var/nodecount //count the number of Nodes traversed
var/id
/PathNode/New(s,p,ndistance_from_start,ndistance_from_end,pnt,id)
source = s
@@ -130,11 +131,14 @@ length to avoid portals or something i guess?? Not that they're counted right no
calc_f()
nodecount = pnt
source.AddPathNode(src, id)
src.id = id
/PathNode/proc/calc_f()
total_node_cost = distance_from_start + distance_from_end
/PathNode/Destroy()
source.PathNodes[id] = null
source.PathNodes.Remove(id)
source = null
prevNode = null
..()
@@ -144,11 +148,11 @@ length to avoid portals or something i guess?? Not that they're counted right no
//////////////////////
//the weighting function, used in the A* algorithm
proc/PathWeightCompare(PathNode/a, PathNode/b)
/proc/PathWeightCompare(PathNode/a, PathNode/b)
return a.total_node_cost - b.total_node_cost
//search if there's a PathNode that points to turf T in the Priority Queue
proc/SeekTurf(var/PriorityQueue/Queue, var/turf/T)
/proc/SeekTurf(var/PriorityQueue/Queue, var/turf/T)
var/i = 1
var/PathNode/PN
while(i < Queue.L.len + 1)
@@ -223,6 +227,12 @@ proc/quick_AStar(start,end,adjacent,dist,maxnodes,maxnodedepth = 30,mintargetdis
//if too many steps, abandon that path
if(maxnodedepth && (cur.nodecount > maxnodedepth))
//cleanup
for(var/PathNode/PN in open.L)
qdel(PN)
for(var/turf/T in closed)
var/PathNode/PN = T.FindPathNode("unique_[reference]")
qdel(PN)
return list()
//found the target turf (or close enough), let's create the path to it
@@ -256,19 +266,20 @@ proc/quick_AStar(start,end,adjacent,dist,maxnodes,maxnodedepth = 30,mintargetdis
PNode.distance_from_start = newenddist
PNode.calc_f()
open.ReSort(PNode)//reorder the changed element in the list
}
//cleanup
for(var/PathNode/PN in open.L)
PN.source.PathNodes["unique_[reference]"] = null
PN.source.PathNodes.Remove("unique_[reference]")
qdel(PN)
for(var/turf/T in closed)
var/PathNode/PN = T.FindPathNode("unique_[reference]")
T.PathNodes["unique_[reference]"] = null
T.PathNodes.Remove("unique_[reference]")
qdel(PN)
for(var/turf/T in path)
var/PathNode/PN = T.FindPathNode("unique_[reference]")
qdel(PN)
open.L = null
closed = null
//if the path is longer than maxnodes, then don't return it
if(path && maxnodes && path.len > (maxnodes + 1))

View File

@@ -16,8 +16,8 @@
#define BOT_OLDTARGET_FORGET_DEFAULT 100 //100*WaitMachinery
#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_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]")
#else
#define log_astar_bot(text)
@@ -104,7 +104,7 @@
if(botcard)
qdel(botcard)
botcard = null
if (waiting_for_patrol)
if (waiting_for_patrol || waiting_for_path)
for (var/datum/path_maker/PM in pathmakers)
if (PM.owner == src)
qdel(PM)
@@ -296,6 +296,8 @@
// After that, we signal the beacon where we are and they transmit a location.
// The closet location is picked, and a path is calculated.
/obj/machinery/bot/proc/find_patrol_path()
if (summoned)
return
if(waiting_for_patrol)
return
if(awaiting_beacon++)
@@ -465,8 +467,8 @@
target = null
else
summoned = TRUE
destination = signal.source.loc
target = signal.source.loc
destination = get_turf(signal.source)
target = get_turf(signal.source)
path = list()
patrol_path = list()
return 1
@@ -494,7 +496,9 @@
log_astar_bot("path is [path.len]")
return TRUE
waiting_for_path = 1
return AStar(src, proc_to_call, src.loc, target, /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance_cardinal, 0, max(10,get_dist(src,target)*3), id=botcard, exclude=avoid)
. = AStar(src, proc_to_call, src.loc, target, /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance_cardinal, 0, max(10,get_dist(src,target)*3), id=botcard, exclude=avoid)
if (!.)
waiting_for_path = 0
/obj/machinery/bot/proc/calc_patrol_path(var/target, var/proc_to_call, var/turf/avoid = null)
ASSERT(target && proc_to_call)

View File

@@ -202,7 +202,7 @@ text("<A href='?src=\ref[src];operation=oddbutton'>[src.oddbutton ? "Yes" : "No"
clean(target)
remove_oldtarget(target)
target = null
return TRUE
return ..()
/obj/machinery/bot/cleanbot/proc/get_targets() //This seems slightly wasteful, but it will only be called approximately once every six rounds so whatever
blacklisted_targets = list()

View File

@@ -210,7 +210,7 @@ Auto Patrol: []"},
/obj/machinery/bot/ed209/kick_act(mob/living/H)
..()
summoned = FALSE // Anger
threatlevel = H.assess_threat(src)
threatlevel += PERP_LEVEL_ARREST_MORE

View File

@@ -235,6 +235,7 @@ var/global/list/floorbot_targets=list()
path = list()
floorbot_targets -= target
target = null
return ..()
/obj/machinery/bot/floorbot/proc/checkforwork()
if(have_target())

View File

@@ -89,10 +89,6 @@ var/global/mulebot_count = 0
cell.maxcharge = 2000
spawn(5) // must wait for map loading to finish
if(radio_controller)
radio_controller.add_object(src, control_freq, filter = RADIO_MULEBOT)
radio_controller.add_object(src, beacon_freq, filter = RADIO_NAVBEACONS)
mulebot_count += 1
if(!suffix)
suffix = "#[mulebot_count]"
@@ -568,7 +564,7 @@ var/global/mulebot_count = 0
/obj/machinery/bot/mulebot/receive_signal(datum/signal/signal)
var/recv = signal.data["beacon"]
if(recv == new_destination) // if the recvd beacon location matches the set destination, then we will navigate there
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]")
destination = new_destination
new_destination = ""

View File

@@ -175,6 +175,7 @@ Auto Patrol: []"},
return !cuffing
/obj/machinery/bot/secbot/proc/set_target(var/mob/M)
summoned = FALSE
target = M
steps_per = 3
//process_path()
@@ -309,7 +310,7 @@ Auto Patrol: []"},
/obj/machinery/bot/secbot/return_status()
if (target)
return "Chasing prep"
return "On the move"
if (auto_patrol)
return "Patrolling"
return ..()

View File

@@ -1047,7 +1047,7 @@ var/global/list/obj/item/device/pda/PDAs = list()
<a href='?src=\ref[cartridge.radio];bot=\ref[mule];command=switch_power;user=\ref[usr]'>Turn [mule.on ? "off" : "on"] <br/>
<a href='?src=\ref[cartridge.radio];bot=\ref[mule];command=return_home;user=\ref[usr]'>Send home</a> <br/>
<a href='?src=\ref[cartridge.radio];bot=\ref[mule];command=[cartridge.saved_destination];user=\ref[usr]'>Send to:</a> <a href='?src=\ref[cartridge];change_destination=1'>[cartridge.saved_destination] - EDIT</a> <br/>
</li>>"}
</li>"}
dat += "</ul>"
if (PDA_MODE_BEEPSKY)
if (!istype(cartridge.radio, /obj/item/radio/integrated/signal/bot/beepsky))