From 39bc480c03b5da866a6dc281dbc23f954376d112 Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 28 Apr 2026 22:37:33 +0100 Subject: [PATCH] Cleanup --- src/Dodge/Creature/Damage.hs | 15 ------------- src/Dodge/Creature/ReaderUpdate.hs | 11 +++++----- src/Dodge/Creature/Strategy.hs | 6 +++--- src/Dodge/Creature/Update.hs | 10 ++++----- src/Dodge/Data/ActionPlan.hs | 2 +- src/Dodge/Default/Creature.hs | 2 +- src/Dodge/Humanoid.hs | 34 +++++++++++++++--------------- src/Dodge/Room/Tutorial.hs | 5 +++-- 8 files changed, 34 insertions(+), 51 deletions(-) diff --git a/src/Dodge/Creature/Damage.hs b/src/Dodge/Creature/Damage.hs index 51d714579..43713c6c7 100644 --- a/src/Dodge/Creature/Damage.hs +++ b/src/Dodge/Creature/Damage.hs @@ -21,21 +21,6 @@ applyIndividualDamage cr w (Inertial _ _ v _) = w applyIndividualDamage cr w dm = let (i,w') = damMatSideEffect dm (crMaterial (_crType cr)) (Left cr) w in w' & damageHP cr i --- case dm of --- Piercing{} -> applyPiercingDamage cr dm w --- _ -> w & damageHP cr (_dmAmount dm) - ---applyPiercingDamage :: Creature -> Damage -> World -> World ---applyPiercingDamage cr dm w --- | crIsArmouredFrom (w ^. cWorld . lWorld . items) p cr --- = f . makeSpark NormalSpark p1 (argV (p1 - p)) $ w --- | otherwise = f . damageHP cr (_dmAmount dm) $ w --- where --- f = cWorld . lWorld . creatures . ix (_crID cr) . crPos . _xy +~ _dmVector dm --- / V2 x x --- x = crMass (_crType cr) --- p = _dmPos dm --- p1 = p + 2 *.* squashNormalizeV (p - cr ^. crPos . _xy) damageHP :: Creature -> Int -> World -> World damageHP cr x = diff --git a/src/Dodge/Creature/ReaderUpdate.hs b/src/Dodge/Creature/ReaderUpdate.hs index f62a43ca6..0db77f559 100644 --- a/src/Dodge/Creature/ReaderUpdate.hs +++ b/src/Dodge/Creature/ReaderUpdate.hs @@ -271,10 +271,9 @@ viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of doStrategyActions :: Creature -> Creature doStrategyActions cr = case cr ^? crActionPlan . apStrategy of - Just (StrategyActions strat acs) -> + Just (SetStrategyAction strat acs) -> cr --- & crActionPlan . apAction .~ acs - & crActionPlan . apAction .~ head acs + & crActionPlan . apAction .~ acs & crActionPlan . apStrategy .~ strat _ -> cr @@ -317,11 +316,11 @@ searchIfDamaged cr && _apStrategy (_crActionPlan cr) == WatchAndWait = cr & crPerception . cpVigilance .~ Vigilant & crActionPlan . apStrategy - .~ StrategyActions + .~ SetStrategyAction LookAround - [ TurnToPoint (cr ^. crPos . _xy -.- unitVectorAtAngle (_crDir cr)) + ( TurnToPoint (cr ^. crPos . _xy -.- unitVectorAtAngle (_crDir cr)) `DoActionThen` 40 `WaitThen` bfsThenReturn 500 - ] + ) | otherwise = cr bfsThenReturn :: Int -> Action diff --git a/src/Dodge/Creature/Strategy.hs b/src/Dodge/Creature/Strategy.hs index 26a0f8d6e..f2cc3c961 100644 --- a/src/Dodge/Creature/Strategy.hs +++ b/src/Dodge/Creature/Strategy.hs @@ -10,14 +10,14 @@ import Dodge.Data.Creature goToPostStrat :: Creature -> Strategy goToPostStrat cr = case find sentinelGoal $ _apGoal $ _crActionPlan cr of Just (SentinelAt p _) -> - StrategyActions + SetStrategyAction (GetTo p) - [ DoActionThen (WaitThen 150 holsterIfAiming) $ + ( DoActionThen (WaitThen 150 holsterIfAiming) $ DoActionThen (PathTo p NoAction) NoAction -- $ DoImpulses [ChangeStrategy WatchAndWait] - ] + ) _ -> WatchAndWait where sentinelGoal (SentinelAt _ _) = True diff --git a/src/Dodge/Creature/Update.hs b/src/Dodge/Creature/Update.hs index ea1d26d14..c9f502baf 100644 --- a/src/Dodge/Creature/Update.hs +++ b/src/Dodge/Creature/Update.hs @@ -66,11 +66,8 @@ updateLivingCreature cr = case cr ^. crType of . yourControl LampCrit{} -> updateLampoid cr BarrelCrit bt -> updateBarreloid bt cr - ChaseCrit{} -> \w -> - crUpdate cid . performActions cid $ - over (cWorld . lWorld . creatures . ix cid) (chaseCritInternal w) w - CrabCrit{} -> - crUpdate cid . performActions cid . crabCritInternal cid + ChaseCrit{} -> crUpdate cid . performActions cid . updateChaseCrit cid + CrabCrit{} -> crUpdate cid . performActions cid . crabCritInternal cid AutoCrit{} -> crUpdate cid SwarmCrit{} -> crUpdate cid HoverCrit{} -> \w -> @@ -97,7 +94,7 @@ updateHiveCrit cr cid w & tocr . crType . hiveGestation %~ (max 0 . subtract 1) | otherwise = w where - nbees = 50 + nbees = 25 tocr = cWorld . lWorld . creatures . ix cid nid = IM.newKey $ w ^. cWorld . lWorld . creatures ncr = beeCrit & crPos .~ (cr ^. crPos + (0 & _xy +~ 25)) @@ -144,6 +141,7 @@ updateAggroBee cr cid w t = \case Avatar{} -> True ChaseCrit{} -> True + CrabCrit{} -> True _ -> False -- do bees need to be able to see slime targets? diff --git a/src/Dodge/Data/ActionPlan.hs b/src/Dodge/Data/ActionPlan.hs index 90cc16d76..e57c00c32 100644 --- a/src/Dodge/Data/ActionPlan.hs +++ b/src/Dodge/Data/ActionPlan.hs @@ -144,7 +144,7 @@ data Strategy | LookAround | Wander | CloseToMelee {_meleeTarget :: Int} - | StrategyActions Strategy [Action] + | SetStrategyAction Strategy Action | GetTo Point2 -- | Reload | Flee diff --git a/src/Dodge/Default/Creature.hs b/src/Dodge/Default/Creature.hs index 63e5935c7..346f4232e 100644 --- a/src/Dodge/Default/Creature.hs +++ b/src/Dodge/Default/Creature.hs @@ -43,7 +43,7 @@ defaultCreature = , _posture = AtEase } , _crVocalization = VocReady - , _crActionPlan = ActionPlan NoAction (StrategyActions WatchAndWait [StartSentinelPost]) [LiveLongAndProsper] + , _crActionPlan = ActionPlan NoAction (SetStrategyAction WatchAndWait StartSentinelPost) [LiveLongAndProsper] , _crPerception = defaultPerceptionState , _crMemory = defaultCreatureMemory , _crFaction = NoFaction diff --git a/src/Dodge/Humanoid.hs b/src/Dodge/Humanoid.hs index 585bb74d6..563fa2fda 100644 --- a/src/Dodge/Humanoid.hs +++ b/src/Dodge/Humanoid.hs @@ -1,5 +1,5 @@ module Dodge.Humanoid ( - chaseCritInternal, + updateChaseCrit, crabCritInternal, hoverCritInternal, ) where @@ -9,22 +9,22 @@ import Dodge.Creature import Dodge.Data.World import LensHelp -chaseCritInternal :: World -> Creature -> Creature -chaseCritInternal w cr = - foldl' - (\c f -> f w c) - cr - [ const doStrategyActions - , overrideMeleeCloseTarget - , setViewPos - , setMvPosToTargetCr - , chaseCritMv - , perceptionUpdate [0] - , targetYouWhenCognizant - , const searchIfDamaged - , const (crType . meleeCooldown %~ max 0 . subtract 1) - , const (crVocalization %~ updateVocTimer) - ] +updateChaseCrit :: Int -> World -> World +updateChaseCrit cid w = + (tocr . crVocalization %~ updateVocTimer) + . (tocr . crType . meleeCooldown %~ max 0 . subtract 1) + . (tocr %~ searchIfDamaged) + . (tocr %~ targetYouWhenCognizant w) + . (tocr %~ perceptionUpdate [0] w) + . (tocr %~ chaseCritMv w) + . (tocr %~ setMvPosToTargetCr w) + . (tocr %~ setViewPos w) + . (tocr %~ overrideMeleeCloseTarget w) + . (tocr %~ doStrategyActions) + $ w + where + tocr = cWorld . lWorld . creatures . ix cid + crabCritInternal :: Int -> World -> World crabCritInternal cid w = diff --git a/src/Dodge/Room/Tutorial.hs b/src/Dodge/Room/Tutorial.hs index 93da4770f..413a57572 100644 --- a/src/Dodge/Room/Tutorial.hs +++ b/src/Dodge/Room/Tutorial.hs @@ -56,7 +56,8 @@ tutAnoTree :: State LayoutVars MTRS tutAnoTree = do foldMTRS [ tToBTree "TutStartRez" . return . cleatOnward <$> tutRezBox --- , corDoor + , corDoor + , chasmSpitTerminal -- , tToBTree "" . return . cleatOnward <$> slowDoorRoom , corDoor --, tToBTree "" . return . cleatOnward <$> (xChasm 200 200 @@ -372,7 +373,7 @@ chasmSpitTerminal = do , [sps0 $ putShape $ gird (V2 0 20) (V2 300 20), sps0 $ putShape $ gird (V2 0 280) (V2 300 280)] ] let y' = y & rmPmnts <>~ ls <> dec - cr = PutCrit chaseCrit + cr = PutCrit hoverCrit return $ tToBTree "chasmTerm" $ Node