Skip to content

Commit

Permalink
[MIRROR] Fix modsuit pathfinder module / JPS changes (#1461) (#2431)
Browse files Browse the repository at this point in the history
* Fix modsuit pathfinder module / JPS changes (#81983)

## About The Pull Request
The Pathfinder module sucks cock because it doesn't work. And the
reasons it doesn't work are as follows:
1. It uses the default JPS pathfinding datum, which has a hard distance
limit of 30, instead of the intended 200.
2. JPS pathfinding as a whole will fail if you encounter more than 3
doors. This is because every door wastes about 5 movement opportunities,
and the default pathfinder only has a limit of 20 before it considers
the entire pathfinding attempt moot and bails out.

Here's how I fixed it:
1. Created a new jps child that has a range of MOD_AI_RANGE
2. Instead of counting all failures during the entire pathfinding
attempt, it will only consider consecutive failures. Every successful
move will reset the pathfinding failure count. This should make JPS
pathfinding more reliable overall?


## Changelog
:cl:
fix: Modsuit Pathfinder module is significantly better at finding it's
destination.
/:cl:

* Fix modsuit pathfinder module / JPS changes

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: Kapu1178 <[email protected]>
  • Loading branch information
3 people authored Mar 17, 2024
1 parent 1874c43 commit e14a4f5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion code/datums/ai/_ai_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ multiple modular subtrees with behaviors
///Stored arguments for behaviors given during their initial creation
var/list/behavior_args = list()
///Tracks recent pathing attempts, if we fail too many in a row we fail our current plans.
var/pathing_attempts
var/consecutive_pathing_attempts
///Can the AI remain in control if there is a client?
var/continue_processing_when_client = FALSE
///distance to give up on target
Expand Down
16 changes: 10 additions & 6 deletions code/datums/ai/movement/_ai_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@
//Override this to setup the moveloop you want to use
/datum/ai_movement/proc/start_moving_towards(datum/ai_controller/controller, atom/current_movement_target, min_distance)
SHOULD_CALL_PARENT(TRUE)
controller.pathing_attempts = 0
controller.consecutive_pathing_attempts = 0
controller.set_blackboard_key(BB_CURRENT_MIN_MOVE_DISTANCE, min_distance)
moving_controllers[controller] = current_movement_target

/datum/ai_movement/proc/stop_moving_towards(datum/ai_controller/controller)
controller.pathing_attempts = 0
controller.consecutive_pathing_attempts = 0
moving_controllers -= controller
// We got deleted as we finished an action
if(!QDELETED(controller.pawn))
SSmove_manager.stop_looping(controller.pawn, SSai_movement)

/datum/ai_movement/proc/increment_pathing_failures(datum/ai_controller/controller)
controller.pathing_attempts++
if(controller.pathing_attempts >= max_pathing_attempts)
controller.consecutive_pathing_attempts++
if(controller.consecutive_pathing_attempts >= max_pathing_attempts)
controller.CancelActions()

/datum/ai_movement/proc/reset_pathing_failures(datum/ai_controller/controller)
controller.consecutive_pathing_attempts = 0

///Should the movement be allowed to happen? return TRUE if it can, FALSE otherwise
/datum/ai_movement/proc/allowed_to_move(datum/move_loop/source)
SHOULD_BE_PURE(TRUE)
Expand Down Expand Up @@ -68,7 +71,8 @@
//Anything to do post movement
/datum/ai_movement/proc/post_move(datum/move_loop/source, succeeded)
SIGNAL_HANDLER
if(succeeded != FALSE)
return
var/datum/ai_controller/controller = source.extra_info
if(succeeded != MOVELOOP_FAILURE)
reset_pathing_failures(controller)
return
increment_pathing_failures(controller)
3 changes: 3 additions & 0 deletions code/datums/ai/movement/ai_movement_jps.dm
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@

/datum/ai_movement/jps/bot/travel_to_beacon
maximum_length = AI_BOT_PATH_LENGTH

/datum/ai_movement/jps/modsuit
maximum_length = MOD_AI_RANGE
2 changes: 1 addition & 1 deletion code/datums/ai/objects/mod.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
BB_MOD_IMPLANT,
)
max_target_distance = MOD_AI_RANGE //a little spicy but its one specific item that summons it, and it doesn't run otherwise
ai_movement = /datum/ai_movement/jps
ai_movement = /datum/ai_movement/jps/modsuit
///ID card generated from the suit's required access. Used for pathing.
var/obj/item/card/id/advanced/id_card

Expand Down

0 comments on commit e14a4f5

Please sign in to comment.