Work on crab

This commit is contained in:
2026-04-07 23:22:56 +01:00
parent 333f2875cb
commit 707ccae971
6 changed files with 34 additions and 13 deletions
+3 -4
View File
@@ -86,8 +86,7 @@ performAction cr w ac = case ac of
-- in (imps, newAcs) -- in (imps, newAcs)
StartSentinelPost -> ([AddGoal $ SentinelAt (cr ^. crPos . _xy) (_crDir cr)], NoAction) StartSentinelPost -> ([AddGoal $ SentinelAt (cr ^. crPos . _xy) (_crDir cr)], NoAction)
PathTo p a -> performPathTo a cr w p PathTo p a -> performPathTo a cr w p
EvadeAim _ _ 0 -> (mempty,NoAction) EvadeAim -> tryEvadeSideways cr w
EvadeAim p a i -> tryEvadeSideways cr w p a i
TurnToPoint p -> performTurnToA cr p TurnToPoint p -> performTurnToA cr p
LeadTarget p -> fromMaybe ([], NoAction) $ do LeadTarget p -> fromMaybe ([], NoAction) $ do
i <- cr ^? crIntention . targetCr . _Just i <- cr ^? crIntention . targetCr . _Just
@@ -103,8 +102,8 @@ performAction cr w ac = case ac of
(imps, nextac) -> (imps, DoReplicatePartial startac t nextac) (imps, nextac) -> (imps, DoReplicatePartial startac t nextac)
NoAction -> ([], NoAction) NoAction -> ([], NoAction)
tryEvadeSideways :: Creature -> World -> Point2 -> Float -> Int -> ActionUpdate tryEvadeSideways :: Creature -> World -> ActionUpdate
tryEvadeSideways _ w p a i = jumpleft -- (mv,mempty) tryEvadeSideways _ w = jumpleft -- (mv,mempty)
where where
jumpleft = (mv,DoReplicate 5 (DoImpulses mv)) jumpleft = (mv,DoReplicate 5 (DoImpulses mv))
mv = [Walk (V2 0 d)] mv = [Walk (V2 0 d)]
+7 -1
View File
@@ -38,7 +38,13 @@ crabCrit :: Creature
crabCrit = defaultCreature crabCrit = defaultCreature
& crName .~ "chaseCrit" & crName .~ "chaseCrit"
& crHP .~ HP 350 & crHP .~ HP 350
& crType .~ CrabCrit 0 LeftForward 0 0 & crType .~ CrabCrit
{ _meleeCooldownL = 0
, _meleeCooldownR = 0
, _footForward = LeftForward
, _strideAmount = 0
, _dodgeCooldown = 0
}
& crFaction .~ ColorFaction red & crFaction .~ ColorFaction red
& crPerception . cpVision . viFOV .~ FloatFOV pi & crPerception . cpVision . viFOV .~ FloatFOV pi
+17 -4
View File
@@ -123,8 +123,12 @@ flockACC w cr = fromMaybe cr $ do
crabCritMv :: World -> Creature -> Creature crabCritMv :: World -> Creature -> Creature
crabCritMv w cr = case _apStrategy (_crActionPlan cr) of crabCritMv w cr = case _apStrategy (_crActionPlan cr) of
_ | Just tid <- melee -> cr & crActionPlan . apAction
.~ DoImpulses [Melee tid] `DoActionThen`
DoReplicate 10 NoAction
& crType . meleeCooldownL .~ 20
WarningCry -> cr WarningCry -> cr
CloseToMelee tid | Just (p,a) <- aimi tid -> cr & crActionPlan . apAction .~ EvadeAim p a 10 CloseToMelee tid | aimi tid -> cr & crActionPlan . apAction .~ EvadeAim
& crType . dodgeCooldown .~ dc & crType . dodgeCooldown .~ dc
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
Wander | Just tid <- cr ^? crIntention . targetCr . _Just Wander | Just tid <- cr ^? crIntention . targetCr . _Just
@@ -139,23 +143,32 @@ crabCritMv w cr = case _apStrategy (_crActionPlan cr) of
& crIntention . mvToPoint .~ Nothing & crIntention . mvToPoint .~ Nothing
_ -> viewTarget w cr _ -> viewTarget w cr
where where
melee = do
tid <- cr ^? crIntention . targetCr . _Just
tcr <- w ^? cWorld . lWorld . creatures . ix tid
let cpos = cr ^. crPos . _xy
tpos = tcr ^. crPos . _xy
guard $ _meleeCooldownL (_crType cr) == 0
&& Just (_crID tcr) == cr ^? crActionPlan . apStrategy . meleeTarget
&& dist tpos cpos < crRad (cr ^. crType) + crRad (tcr ^. crType) + 5
&& abs (_crDir cr - argV (tpos -.- cpos)) < pi / 4
return tid
dc = fst $ randomR (15,25) (w ^. randGen) dc = fst $ randomR (15,25) (w ^. randGen)
notpath = \case notpath = \case
Just NoAction -> False Just NoAction -> False
Just PathTo {} -> False Just PathTo {} -> False
Just AimAt {} -> False Just AimAt {} -> False
_ -> True _ -> True
aimi tid = do aimi tid = fromMaybe False $ do
tcr <- w ^? cWorld . lWorld . creatures . ix tid tcr <- w ^? cWorld . lWorld . creatures . ix tid
Aiming <- tcr ^? crStance . posture Aiming <- tcr ^? crStance . posture
let txy = tcr ^. crPos . _xy let txy = tcr ^. crPos . _xy
cxy = cr ^. crPos . _xy cxy = cr ^. crPos . _xy
0 <- cr ^? crType . dodgeCooldown 0 <- cr ^? crType . dodgeCooldown
guard $ hasLOS cxy txy w return $ hasLOS cxy txy w
&& abs (nearZeroAngle (tcr^.crDir - argV (cxy - txy))) < 0.3 && abs (nearZeroAngle (tcr^.crDir - argV (cxy - txy))) < 0.3
&& isWalkable txy cxy w && isWalkable txy cxy w
&& diffAngles (cr ^. crDir) (argV (txy - cxy)) < 0.1 && diffAngles (cr ^. crDir) (argV (txy - cxy)) < 0.1
return (txy, tcr ^. crDir)
chaseCritMv :: World -> Creature -> Creature chaseCritMv :: World -> Creature -> Creature
chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
+1 -1
View File
@@ -69,7 +69,7 @@ data Action
, _targetSeenAt :: Point2 , _targetSeenAt :: Point2
} }
| PathTo { _pathToPoint :: Point2, _pathFailAction :: Action } | PathTo { _pathToPoint :: Point2, _pathFailAction :: Action }
| EvadeAim {_enemyPos :: Point2, _enemyDir :: Float, _acTimer :: Int} | EvadeAim
| TurnToPoint { _turnToPoint :: Point2 } | TurnToPoint { _turnToPoint :: Point2 }
| ImpulsesList { _impulsesListList :: [[Impulse]], _acAction :: Action } | ImpulsesList { _impulsesListList :: [[Impulse]], _acAction :: Action }
| DoImpulses { _doImpulsesList :: [Impulse] } | DoImpulses { _doImpulsesList :: [Impulse] }
+3 -1
View File
@@ -58,7 +58,9 @@ data CreatureType
, _footForward :: FootForward , _footForward :: FootForward
, _strideAmount :: Float , _strideAmount :: Float
} }
| CrabCrit {_meleeCooldown :: Int | CrabCrit
{ _meleeCooldownL :: Int
, _meleeCooldownR :: Int
, _footForward :: FootForward , _footForward :: FootForward
, _strideAmount :: Float , _strideAmount :: Float
, _dodgeCooldown :: Int , _dodgeCooldown :: Int
+3 -2
View File
@@ -29,7 +29,8 @@ chaseCritInternal w cr =
crabCritInternal :: World -> Creature -> Creature crabCritInternal :: World -> Creature -> Creature
crabCritInternal w = crabCritInternal w =
(crVocalization %~ updateVocTimer) (crVocalization %~ updateVocTimer)
. (crType . meleeCooldown %~ max 0 . subtract 1) . (crType . meleeCooldownL %~ max 0 . subtract 1)
. (crType . meleeCooldownR %~ max 0 . subtract 1)
. (crType . dodgeCooldown %~ max 0 . subtract 1) . (crType . dodgeCooldown %~ max 0 . subtract 1)
. searchIfDamaged . searchIfDamaged
. targetYouWhenCognizant w . targetYouWhenCognizant w
@@ -37,7 +38,7 @@ crabCritInternal w =
. crabCritMv w . crabCritMv w
. setMvPosToTargetCr w . setMvPosToTargetCr w
. setViewPos w . setViewPos w
. overrideMeleeCloseTarget w -- . overrideMeleeCloseTarget w
. doStrategyActions . doStrategyActions
hoverCritInternal :: World -> Creature -> Creature hoverCritInternal :: World -> Creature -> Creature