From 707ccae9715fce4d75fce78398e7f8e23142e629 Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 7 Apr 2026 23:22:56 +0100 Subject: [PATCH] Work on crab --- src/Dodge/Creature/Action.hs | 7 +++---- src/Dodge/Creature/ChaseCrit.hs | 8 +++++++- src/Dodge/Creature/ReaderUpdate.hs | 21 +++++++++++++++++---- src/Dodge/Data/ActionPlan.hs | 2 +- src/Dodge/Data/Creature/Misc.hs | 4 +++- src/Dodge/Humanoid.hs | 5 +++-- 6 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/Dodge/Creature/Action.hs b/src/Dodge/Creature/Action.hs index 76dd44961..e7654b1dc 100644 --- a/src/Dodge/Creature/Action.hs +++ b/src/Dodge/Creature/Action.hs @@ -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)] diff --git a/src/Dodge/Creature/ChaseCrit.hs b/src/Dodge/Creature/ChaseCrit.hs index f47d8fe69..4b6db8117 100644 --- a/src/Dodge/Creature/ChaseCrit.hs +++ b/src/Dodge/Creature/ChaseCrit.hs @@ -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 diff --git a/src/Dodge/Creature/ReaderUpdate.hs b/src/Dodge/Creature/ReaderUpdate.hs index d58317d4c..7744fc16c 100644 --- a/src/Dodge/Creature/ReaderUpdate.hs +++ b/src/Dodge/Creature/ReaderUpdate.hs @@ -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 diff --git a/src/Dodge/Data/ActionPlan.hs b/src/Dodge/Data/ActionPlan.hs index 65ef8e3b5..5b8de6b9a 100644 --- a/src/Dodge/Data/ActionPlan.hs +++ b/src/Dodge/Data/ActionPlan.hs @@ -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] } diff --git a/src/Dodge/Data/Creature/Misc.hs b/src/Dodge/Data/Creature/Misc.hs index 6456f115a..2dd6c5e2a 100644 --- a/src/Dodge/Data/Creature/Misc.hs +++ b/src/Dodge/Data/Creature/Misc.hs @@ -58,7 +58,9 @@ data CreatureType , _footForward :: FootForward , _strideAmount :: Float } - | CrabCrit {_meleeCooldown :: Int + | CrabCrit + { _meleeCooldownL :: Int + , _meleeCooldownR :: Int , _footForward :: FootForward , _strideAmount :: Float , _dodgeCooldown :: Int diff --git a/src/Dodge/Humanoid.hs b/src/Dodge/Humanoid.hs index 4785812a0..8c32b7277 100644 --- a/src/Dodge/Humanoid.hs +++ b/src/Dodge/Humanoid.hs @@ -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