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