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)
StartSentinelPost -> ([AddGoal $ SentinelAt (cr ^. crPos . _xy) (_crDir cr)], NoAction)
PathTo p a -> performPathTo a cr w p
EvadeAim _ _ 0 -> (mempty,NoAction)
EvadeAim p a i -> tryEvadeSideways cr w p a i
EvadeAim -> tryEvadeSideways cr w
TurnToPoint p -> performTurnToA cr p
LeadTarget p -> fromMaybe ([], NoAction) $ do
i <- cr ^? crIntention . targetCr . _Just
@@ -103,8 +102,8 @@ performAction cr w ac = case ac of
(imps, nextac) -> (imps, DoReplicatePartial startac t nextac)
NoAction -> ([], NoAction)
tryEvadeSideways :: Creature -> World -> Point2 -> Float -> Int -> ActionUpdate
tryEvadeSideways _ w p a i = jumpleft -- (mv,mempty)
tryEvadeSideways :: Creature -> World -> ActionUpdate
tryEvadeSideways _ w = jumpleft -- (mv,mempty)
where
jumpleft = (mv,DoReplicate 5 (DoImpulses mv))
mv = [Walk (V2 0 d)]
+7 -1
View File
@@ -38,7 +38,13 @@ crabCrit :: Creature
crabCrit = defaultCreature
& crName .~ "chaseCrit"
& crHP .~ HP 350
& crType .~ CrabCrit 0 LeftForward 0 0
& crType .~ CrabCrit
{ _meleeCooldownL = 0
, _meleeCooldownR = 0
, _footForward = LeftForward
, _strideAmount = 0
, _dodgeCooldown = 0
}
& crFaction .~ ColorFaction red
& crPerception . cpVision . viFOV .~ FloatFOV pi
+17 -4
View File
@@ -123,8 +123,12 @@ flockACC w cr = fromMaybe cr $ do
crabCritMv :: World -> Creature -> Creature
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
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
CloseToMelee _ | ma <- cr ^? crActionPlan . apAction , notpath ma -> cr
Wander | Just tid <- cr ^? crIntention . targetCr . _Just
@@ -139,23 +143,32 @@ crabCritMv w cr = case _apStrategy (_crActionPlan cr) of
& crIntention . mvToPoint .~ Nothing
_ -> viewTarget w cr
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)
notpath = \case
Just NoAction -> False
Just PathTo {} -> False
Just AimAt {} -> False
_ -> True
aimi tid = do
aimi tid = fromMaybe False $ do
tcr <- w ^? cWorld . lWorld . creatures . ix tid
Aiming <- tcr ^? crStance . posture
let txy = tcr ^. crPos . _xy
cxy = cr ^. crPos . _xy
0 <- cr ^? crType . dodgeCooldown
guard $ hasLOS cxy txy w
return $ hasLOS cxy txy w
&& abs (nearZeroAngle (tcr^.crDir - argV (cxy - txy))) < 0.3
&& isWalkable txy cxy w
&& diffAngles (cr ^. crDir) (argV (txy - cxy)) < 0.1
return (txy, tcr ^. crDir)
chaseCritMv :: World -> Creature -> Creature
chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
+1 -1
View File
@@ -69,7 +69,7 @@ data Action
, _targetSeenAt :: Point2
}
| PathTo { _pathToPoint :: Point2, _pathFailAction :: Action }
| EvadeAim {_enemyPos :: Point2, _enemyDir :: Float, _acTimer :: Int}
| EvadeAim
| TurnToPoint { _turnToPoint :: Point2 }
| ImpulsesList { _impulsesListList :: [[Impulse]], _acAction :: Action }
| DoImpulses { _doImpulsesList :: [Impulse] }
+3 -1
View File
@@ -58,7 +58,9 @@ data CreatureType
, _footForward :: FootForward
, _strideAmount :: Float
}
| CrabCrit {_meleeCooldown :: Int
| CrabCrit
{ _meleeCooldownL :: Int
, _meleeCooldownR :: Int
, _footForward :: FootForward
, _strideAmount :: Float
, _dodgeCooldown :: Int
+3 -2
View File
@@ -29,7 +29,8 @@ chaseCritInternal w cr =
crabCritInternal :: World -> Creature -> Creature
crabCritInternal w =
(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)
. searchIfDamaged
. targetYouWhenCognizant w
@@ -37,7 +38,7 @@ crabCritInternal w =
. crabCritMv w
. setMvPosToTargetCr w
. setViewPos w
. overrideMeleeCloseTarget w
-- . overrideMeleeCloseTarget w
. doStrategyActions
hoverCritInternal :: World -> Creature -> Creature