Skip to content
Merged
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
25 changes: 25 additions & 0 deletions code/__DEFINES/~~oculis_defines/astar.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Note: higher A* weight = less preferred, lower weight = more preferred.

/// Default A* weight given to areas.
#define ASTAR_WEIGHT_AREA_DEFAULT 0
/// A* weight given to hallway areas.
#define ASTAR_WEIGHT_AREA_HALLS -20
/// A* weight given to maintenance areas.
#define ASTAR_WEIGHT_AREA_MAINTS -(ASTAR_WEIGHT_AREA_HALLS / 2)
/// A* weight given to commons areas, i.e dorms, bar, cafeteria, etc.
#define ASTAR_WEIGHT_AREA_COMMONS (ASTAR_WEIGHT_AREA_HALLS / 4)


/// Default A* weight given to turfs.
#define ASTAR_WEIGHT_TURF_DEFAULT 50
/// A* weight for turfs we'd prefer to not go over if possible, but it's fine if needed.
#define ASTAR_WEIGHT_TURF_DISCOURAGED (ASTAR_WEIGHT_TURF_DEFAULT * 1.5)
/// A* weight for turfs we should prolly never path over but it might be in the realm of possibility anyways?
#define ASTAR_WEIGHT_TURF_ALMOST_NEVER (ASTAR_WEIGHT_TURF_DEFAULT * 10)
/// A* weight for turfs we should never even CONSIDER pathing over.
#define ASTAR_WEIGHT_TURF_NEVER 9999

/// A* weight for objects that are better to walk around, but it's not a big deal at all.
#define ASTAR_WEIGHT_OBJ_MEH 2
/// A* weight for objects to avoid going thru, but not too strongly.
#define ASTAR_WEIGHT_OBJ_DISCOURAGED (ASTAR_WEIGHT_OBJ_MEH * 10)
9 changes: 8 additions & 1 deletion code/__HELPERS/paths/path.dm
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,12 @@
/// Require a movable
var/datum/weakref/requester_ref = null

/datum/can_pass_info/New(atom/movable/construct_from, list/access, no_id = FALSE, call_depth = 0)
// OCULIS EDIT ADDITION START - ASTAR - (multi-z pathfinding)
/// Whether to do extra checks for multi-Z pathing or not.
var/multiz_checks = FALSE
// OCULIS EDIT ADDITION END

/datum/can_pass_info/New(atom/movable/construct_from, list/access, no_id = FALSE, call_depth = 0, multiz_checks = FALSE) // OCULIS EDIT ADDITION - ASTAR - (multi-z pathfinding)
// No infiniloops
if(call_depth > 10)
return
Expand Down Expand Up @@ -353,6 +358,8 @@
if(construct_from.pulling)
src.pulling_info = new(construct_from.pulling, access, no_id, call_depth + 1)

src.multiz_checks = multiz_checks // OCULIS EDIT ADDITION - ASTAR - (multi-z pathfinding)

/// List of vars on /datum/can_pass_info to use when checking two instances for equality
GLOBAL_LIST_INIT(can_pass_info_vars, GLOBAL_PROC_REF(can_pass_check_vars))

Expand Down
34 changes: 34 additions & 0 deletions code/__HELPERS/~~oculis_helpers/_lists.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/****
* Even more custom binary search sorted insert (in reverse order), using defines instead of vars.
* INPUT: Item to be inserted
* LIST: List to insert INPUT into
* TYPECONT: A define setting the var to the typepath of the contents of the list
* COMPARE: The item to compare against, usualy the same as INPUT
* COMPARISON: A define that takes an item to compare as input, and returns their comparable value
* COMPTYPE: How should the list be compared? Either COMPARE_KEY or COMPARE_VALUE.
*/
#define BINARY_INSERT_DEFINE_REVERSE(INPUT, LIST, TYPECONT, COMPARE, COMPARISON, COMPTYPE) \
do {\
var/list/__BIN_LIST = LIST;\
var/__BIN_CTTL = length(__BIN_LIST);\
if(!__BIN_CTTL) {\
__BIN_LIST += INPUT;\
} else {\
var/__BIN_LEFT = 1;\
var/__BIN_RIGHT = __BIN_CTTL;\
var/__BIN_MID = (__BIN_LEFT + __BIN_RIGHT) >> 1;\
##TYPECONT(__BIN_ITEM);\
while(__BIN_LEFT < __BIN_RIGHT) {\
__BIN_ITEM = COMPTYPE;\
if(##COMPARISON(__BIN_ITEM) >= ##COMPARISON(COMPARE)) {\
__BIN_LEFT = __BIN_MID + 1;\
} else {\
__BIN_RIGHT = __BIN_MID;\
};\
__BIN_MID = (__BIN_LEFT + __BIN_RIGHT) >> 1;\
};\
__BIN_ITEM = COMPTYPE;\
__BIN_MID = ##COMPARISON(__BIN_ITEM) < ##COMPARISON(COMPARE) ? __BIN_MID : __BIN_MID + 1;\
__BIN_LIST.Insert(__BIN_MID, INPUT);\
};\
} while(FALSE)
10 changes: 10 additions & 0 deletions code/__HELPERS/~~oculis_helpers/mapping.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// Checks to see if two atoms are on connected Z-levels,
/// i.e on different floors of the station.
/proc/are_zs_connected(atom/a, atom/b)
a = get_turf(a)
b = get_turf(b)
if(isnull(a) || isnull(b))
return FALSE
if(a.z == b.z)
return TRUE
return (b.z in SSmapping.get_connected_levels(a))
19 changes: 19 additions & 0 deletions modular_oculis/master_files/code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/atom/movable
/// The weight for A* pathfinding added to turfs this atom is on.
var/astar_weight

/atom/movable/Initialize(mapload, ...)
. = ..()
if(astar_weight && isturf(loc))
var/turf/turf_loc = loc
turf_loc.astar_weight += astar_weight

/atom/movable/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change)
. = ..()
if(astar_weight)
var/turf/old_turf = get_turf(old_loc)
var/turf/new_turf = get_turf(src)
if(old_turf)
old_turf.astar_weight -= astar_weight
if(new_turf)
new_turf.astar_weight += astar_weight
19 changes: 19 additions & 0 deletions modular_oculis/master_files/code/game/turfs/open/openspace.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/turf/open/openspace/can_cross_safely(atom/movable/crossing)
. = ..()
if(.)
return
var/turf/below = GET_TURF_BELOW(src)
if(below)
var/obj/structure/stairs/stairs_below = locate() in below
if(stairs_below?.isTerminator())
return TRUE

/turf/open/openspace/CanAStarPass(to_dir, datum/can_pass_info/pass_info)
. = ..()
if(. || !pass_info.multiz_checks)
return
var/turf/turf_below = GET_TURF_BELOW(src)
if(turf_below)
var/obj/structure/stairs/stairs_below = locate() in turf_below
if(stairs_below?.isTerminator())
return TRUE
11 changes: 11 additions & 0 deletions modular_oculis/master_files/code/game/turfs/turf.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/turf
/// The weight of the turf for A* pathfinding.
var/astar_weight = ASTAR_WEIGHT_TURF_DEFAULT

/turf/ChangeTurf(path, list/new_baseturfs, flags)
var/old_astar_weight = (astar_weight - src::astar_weight) // just get the weight that isn't the turf
. = ..()
if(old_astar_weight)
var/turf/new_turf = .
if(new_turf && !(flags & CHANGETURF_SKIP))
new_turf.astar_weight += old_astar_weight
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Run our modular `create_astar_navigation` proc instead.
/mob/living/create_navigation()
create_astar_navigation()
Loading
Loading