Add action to perform on pathing failure

This commit is contained in:
2026-04-03 15:45:16 +01:00
parent 2d1cf4b371
commit d15fbc902c
4 changed files with 16 additions and 15 deletions
+5 -5
View File
@@ -83,7 +83,7 @@ performAction cr w ac = case ac of
let (imps, newAcs) = foldMap (performAction cr w) acs
in (imps, newAcs)
StartSentinelPost -> ([AddGoal $ SentinelAt (cr ^. crPos . _xy) (_crDir cr)], mempty)
PathTo p -> performPathTo cr w p
PathTo p a -> performPathTo a cr w p
TurnToPoint p -> performTurnToA cr p
LeadTarget p -> fromMaybe ([], mempty) $ do
i <- cr ^? crIntention . targetCr . _Just
@@ -119,15 +119,15 @@ crPathing cr = case cr ^. crStance . carriage of
Flying {} -> (isFlyable, not . S.member (WallObstacle WallNotAutoOpen))
_ -> (isWalkable, not . pathEdgeObstructed)
performPathTo :: Creature -> World -> Point2 -> ActionUpdate
performPathTo cr w p
performPathTo :: Action -> Creature -> World -> Point2 -> ActionUpdate
performPathTo a cr w p
| dist cpos p <= crRad (cr ^. crType) = mempty
| fst (crPathing cr) cpos p w = gotowards p
| otherwise = case uncurry pointTowardsImpulse' (crPathing cr) cpos p w of
Just q -> gotowards q
_ -> ([ChangeStrategy Flee], [])
_ -> ([], [a])
where
gotowards q = ( [MvTurnToward q, MvForward, RandomTurn jit] , [PathTo p])
gotowards q = ( [MvTurnToward q, MvForward, RandomTurn jit] , [PathTo p a])
cpos = cr ^. crPos . _xy
jit = _mvTurnJit $ crMvType cr
+8 -8
View File
@@ -6,7 +6,7 @@ module Dodge.Creature.ReaderUpdate (
watchUpdateStrat,
overrideInternal,
searchIfDamaged,
goToTarget,
-- goToTarget,
flockACC,
chaseCritMv,
setMvPos,
@@ -142,7 +142,7 @@ chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
cr & crActionPlan . apAction .~ [PathTo p]
cr & crActionPlan . apAction .~ [PathTo p (DoImpulses [ChangeStrategy Wander])]
| otherwise ->
cr & crActionPlan . apAction .~ [bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]]
& crActionPlan . apStrategy .~ WatchAndWait
@@ -156,17 +156,17 @@ hoverCritMv w cr = case _apStrategy (_crActionPlan cr) of
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
cr & crActionPlan . apAction .~ [PathTo p]
cr & crActionPlan . apAction .~ [PathTo p (DoImpulses [ChangeStrategy Wander])]
| otherwise ->
cr & crActionPlan . apAction .~ [bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]]
& crActionPlan . apStrategy .~ WatchAndWait
& crIntention . mvToPoint .~ Nothing
_ -> viewTarget w cr
goToTarget :: World -> Creature -> Creature
goToTarget w cr = case cr ^? crIntention . mvToPoint . _Just of
Just p -> cr & crActionPlan . apAction .~ [PathTo p]
_ -> viewTarget w cr
--goToTarget :: World -> Creature -> Creature
--goToTarget w cr = case cr ^? crIntention . mvToPoint . _Just of
-- Just p -> cr & crActionPlan . apAction .~ [PathTo p]
-- _ -> viewTarget w cr
viewTarget :: World -> Creature -> Creature
viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of
@@ -177,7 +177,7 @@ viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of
& crIntention . viewPoint .~ Nothing
& crActionPlan . apStrategy .~ Investigate
| otherwise ->
cr & crActionPlan . apAction %~ replaceNullWith (PathTo p)
cr & crActionPlan . apAction %~ replaceNullWith (PathTo p (DoImpulses [ChangeStrategy Wander]))
& crActionPlan . apStrategy .~ Investigate
Nothing -> cr
+1 -1
View File
@@ -14,7 +14,7 @@ goToPostStrat cr = case find sentinelGoal $ _apGoal $ _crActionPlan cr of
(GetTo p)
[ DoActionThen (WaitThen 150 holsterIfAiming) $
DoActionThen
(PathTo p)
(PathTo p NoAction)
NoAction
-- $ DoImpulses [ChangeStrategy WatchAndWait]
]
+2 -1
View File
@@ -67,7 +67,7 @@ data Action
{ _targetID :: Int
, _targetSeenAt :: Point2
}
| PathTo { _pathToPoint :: Point2 }
| PathTo { _pathToPoint :: Point2, _pathFailAction :: Action }
| TurnToPoint { _turnToPoint :: Point2 }
| ImpulsesList { _impulsesListList :: [[Impulse]] }
| DoImpulses { _doImpulsesList :: [Impulse] }
@@ -136,6 +136,7 @@ data Strategy
| Investigate
| WarningCry
| LookAround
| Wander
| CloseToMelee {_meleeTarget :: Int}
| StrategyActions Strategy [Action]
| GetTo Point2