Skip to content

Commit

Permalink
[MIRROR] Improves how ai movement checks for if movement is allowed […
Browse files Browse the repository at this point in the history
…MDB IGNORE] (#554)

* Improves how ai movement checks for if movement is allowed (#79620)

---------

Co-authored-by: SkyratBot <[email protected]>
Co-authored-by: Emmett Gaines <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2023
1 parent 205c9bf commit 4575573
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
27 changes: 17 additions & 10 deletions code/datums/ai/movement/_ai_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
if(controller.pathing_attempts >= max_pathing_attempts)
controller.CancelActions()

///Should the movement be allowed to happen? As of writing this, MOVELOOP_SKIP_STEP is defined as (1<<0) so be careful on using (return TRUE) or (can_move = TRUE; return can_move)
///Should the movement be allowed to happen?
/datum/ai_movement/proc/allowed_to_move(datum/move_loop/source)
SHOULD_BE_PURE(TRUE)

var/atom/movable/pawn = source.moving
var/datum/ai_controller/controller = source.extra_info
source.delay = controller.movement_delay

var/can_move = TRUE
if(controller.ai_traits & STOP_MOVING_WHEN_PULLED && pawn.pulledby) //Need to store more state. Annoying.
Expand All @@ -37,24 +38,30 @@
if(!isturf(pawn.loc)) //No moving if not on a turf
can_move = FALSE

return can_move

///Anything to do before moving; any checks if the pawn should be able to move should be placed in allowed_to_move() and called by this proc
/datum/ai_movement/proc/pre_move(datum/move_loop/source)
SIGNAL_HANDLER
SHOULD_NOT_OVERRIDE(TRUE)

var/datum/ai_controller/controller = source.extra_info

// Check if this controller can actually run, so we don't chase people with corpses
if(!controller.able_to_run())
controller.CancelActions()
qdel(source) //stop moving
return MOVELOOP_SKIP_STEP

//Why doesn't this return TRUE or can_move?
//MOVELOOP_SKIP_STEP is defined as (1<<0) and TRUE are defined as the same "1", returning TRUE would be the equivalent of skipping the move
if(can_move)
source.delay = controller.movement_delay

// Why doesn't this return TRUE?
// MOVELOOP_SKIP_STEP is defined as (1<<0) and TRUE are defined as the same "1", returning TRUE would be the equivalent of skipping the move
if(allowed_to_move(source))
return
increment_pathing_failures(controller)
return MOVELOOP_SKIP_STEP

///Anything to do before moving; any checks if the pawn should be able to move should be placed in allowed_to_move() and called by this proc
/datum/ai_movement/proc/pre_move(datum/move_loop/source)
SIGNAL_HANDLER
return allowed_to_move(source)

//Anything to do post movement
/datum/ai_movement/proc/post_move(datum/move_loop/source, succeeded)
SIGNAL_HANDLER
Expand Down
4 changes: 1 addition & 3 deletions code/datums/ai/movement/ai_movement_basic_avoidance.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
/datum/ai_movement/basic_avoidance/allowed_to_move(datum/move_loop/has_target/dist_bound/source)
. = ..()
var/turf/target_turf = get_step_towards(source.moving, source.target)

if(!target_turf?.can_cross_safely(source.moving))
. = MOVELOOP_SKIP_STEP
return .
return FALSE

/// Move immediately and don't update our facing
/datum/ai_movement/basic_avoidance/backstep
Expand Down
2 changes: 1 addition & 1 deletion code/datums/ai/movement/ai_movement_complete_stop.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
RegisterSignal(loop, COMSIG_MOVELOOP_PREPROCESS_CHECK, PROC_REF(pre_move))

/datum/ai_movement/complete_stop/allowed_to_move(datum/move_loop/source)
return // no movement allowed
return FALSE
4 changes: 1 addition & 3 deletions code/datums/ai/movement/ai_movement_dumb.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@
/datum/ai_movement/dumb/allowed_to_move(datum/move_loop/has_target/source)
. = ..()
var/turf/target_turf = get_step_towards(source.moving, source.target)

if(!target_turf?.can_cross_safely(source.moving))
. = MOVELOOP_SKIP_STEP
return .
return FALSE

0 comments on commit 4575573

Please sign in to comment.