Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Fixed pathfinding component and added to tech node #263

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions code/__HELPERS/path.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* * exclude: If we want to avoid a specific turf, like if we're a mulebot who already got blocked by some turf
* * skip_first: Whether or not to delete the first item in the path. This would be done because the first item is the starting tile, which can break movement for some creatures.
*/
/proc/get_path_to(caller, end, max_distance = 30, mintargetdist, id=null, simulated_only = TRUE, turf/exclude, skip_first=TRUE)
/proc/get_path_to(caller, end, max_distance = 30, mintargetdist, id=null, simulated_only = TRUE, turf/exclude, skip_first=TRUE, use_diags=TRUE)
if(!caller || !get_turf(end))
return

Expand All @@ -28,7 +28,7 @@
l = SSpathfinder.mobs.getfree(caller)

var/list/path
var/datum/pathfind/pathfind_datum = new(caller, end, id, max_distance, mintargetdist, simulated_only, exclude)
var/datum/pathfind/pathfind_datum = new(caller, end, id, max_distance, mintargetdist, simulated_only, exclude, use_diags)
path = pathfind_datum.search()
qdel(pathfind_datum)

Expand Down Expand Up @@ -120,8 +120,10 @@
var/simulated_only
/// A specific turf we're avoiding, like if a mulebot is being blocked by someone t-posing in a doorway we're trying to get through
var/turf/avoid
// Should we use diagonals in pathfinding? Set to FALSE if we are pathfinding for a mob or object that can only go on the four cardinals (like mechs)
var/use_diags = TRUE

/datum/pathfind/New(atom/movable/caller, atom/goal, id, max_distance, mintargetdist, simulated_only, avoid)
/datum/pathfind/New(atom/movable/caller, atom/goal, id, max_distance, mintargetdist, simulated_only, avoid, use_diags)
src.caller = caller
end = get_turf(goal)
open = new /datum/heap(/proc/HeapPathWeightCompare)
Expand All @@ -131,6 +133,7 @@
src.mintargetdist = mintargetdist
src.simulated_only = simulated_only
src.avoid = avoid
src.use_diags = use_diags

/**
* search() is the proc you call to kick off and handle the actual pathfinding, and kills the pathfind datum instance when it's done.
Expand Down Expand Up @@ -165,8 +168,9 @@
for(var/scan_direction in list(EAST, WEST, NORTH, SOUTH))
lateral_scan_spec(current_turf, scan_direction, current_processed_node)

for(var/scan_direction in list(NORTHEAST, SOUTHEAST, NORTHWEST, SOUTHWEST))
diag_scan_spec(current_turf, scan_direction, current_processed_node)
if(use_diags)
for(var/scan_direction in list(NORTHEAST, SOUTHEAST, NORTHWEST, SOUTHWEST))
diag_scan_spec(current_turf, scan_direction, current_processed_node)

CHECK_TICK

Expand Down Expand Up @@ -234,7 +238,8 @@
if(parent_node && parent_node.number_tiles + steps_taken > max_distance)
return

var/interesting = FALSE // have we found a forced neighbor that would make us add this turf to the open list?
// if we aren't using diagonals in general, then we need to be able to find all direct paths as interesting
var/interesting = !use_diags // have we found a forced neighbor that would make us add this turf to the open list?

switch(heading)
if(NORTH)
Expand Down
1 change: 1 addition & 0 deletions code/modules/research/techweb/all_nodes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
"comp_toentity",
"comp_tonumber",
"comp_tostring",
"comp_pathfind",
"comp_typecheck",
"compact_remote_shell",
"component_printer",
Expand Down
18 changes: 17 additions & 1 deletion code/modules/wiremod/components/action/pathfind.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
var/datum/port/input/input_X
var/datum/port/input/input_Y
var/datum/port/input/id_card
var/datum/port/input/use_diagonals
var/datum/port/input/input_entity

var/datum/port/output/output
var/datum/port/output/finished
Expand Down Expand Up @@ -38,6 +40,8 @@
input_X = add_input_port("Target X", PORT_TYPE_NUMBER, FALSE)
input_Y = add_input_port("Target Y", PORT_TYPE_NUMBER, FALSE)
id_card = add_input_port("ID Card", PORT_TYPE_ATOM, FALSE)
input_entity = add_input_port("Pathfinding Entity", PORT_TYPE_ATOM, FALSE)
use_diagonals = add_input_port("Use Diagonals", PORT_TYPE_NUMBER, FALSE, 1)

output = add_output_port("Next step", PORT_TYPE_ATOM)
finished = add_output_port("Arrived to destination", PORT_TYPE_SIGNAL)
Expand All @@ -53,6 +57,8 @@
finished = null
failed = null
reason_failed = null
use_diagonals = null
input_entity = null

path = null
old_dest = null
Expand All @@ -71,6 +77,13 @@
var/target_Y = input_Y.input_value
if(isnull(target_Y))
return

var/use_diag_val = use_diagonals.input_value

if(isnull(use_diag_val))
return

var/entity = input_entity.input_value

var/atom/path_id = id_card.input_value
if(path_id && !istype(path_id, /obj/item/card/id))
Expand Down Expand Up @@ -114,7 +127,10 @@
TIMER_COOLDOWN_END(parent, COOLDOWN_CIRCUIT_PATHFIND_SAME)

old_dest = destination
path = get_path_to(src, destination, max_range, id=path_id)
var/udv = TRUE
if(use_diag_val == 0) // I wish it didn't have to be this way
udv = FALSE
path = get_path_to(entity ||= src, destination, max_range, id=path_id, use_diags = udv)
Copy link
Contributor

@EtraIV EtraIV Jun 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I commented on this before but path = get_path_to(entity || src, destination, max_range, id=path_id, use_diags = udv) would be more correct (didn't properly know what || did, but now I saw "The entire expression takes the value of the last argument to be evaluated.", My bad).

if(length(path) == 0 || !path)// Check if we can even path there
next_turf = null
failed.set_output(COMPONENT_SIGNAL)
Expand Down