From 86311c5d4137ac12872f0f58f6b8c02f5ad63bee Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 5 Sep 2021 23:58:35 +0100 Subject: [PATCH] Improve awareness --- src/Dodge/Creature.hs | 1 + src/Dodge/Creature/Action.hs | 55 ++++++++----- src/Dodge/Creature/Action/Flee.hs | 22 ----- src/Dodge/Creature/Action/Movement.hs | 114 -------------------------- src/Dodge/Creature/Action/UseItem.hs | 48 ----------- src/Dodge/Creature/ActionRat.hs | 33 -------- src/Dodge/Creature/AlertLevel.hs | 62 ++++++-------- src/Dodge/Creature/AlertLevel/Data.hs | 3 +- src/Dodge/Creature/ArmourChase.hs | 2 +- src/Dodge/Creature/Boid.hs | 44 +++++++++- src/Dodge/Creature/ChaseCrit.hs | 5 +- src/Dodge/Creature/ImpulseRat.hs | 51 ------------ src/Dodge/Creature/LauncherCrit.hs | 5 +- src/Dodge/Creature/LtAutoCrit.hs | 2 +- src/Dodge/Creature/PistolCrit.hs | 2 +- src/Dodge/Creature/ReaderUpdate.hs | 41 --------- src/Dodge/Creature/SentinelAI.hs | 2 +- src/Dodge/Creature/SpreadGunCrit.hs | 2 +- src/Dodge/Creature/SwarmCrit.hs | 11 --- src/Dodge/Creature/YourControl.hs | 2 +- src/Dodge/Default.hs | 2 +- src/Dodge/Floor.hs | 4 + src/Dodge/Item/Weapon/TriggerType.hs | 3 - src/Dodge/Update/UsingInput.hs | 2 +- 24 files changed, 121 insertions(+), 397 deletions(-) delete mode 100644 src/Dodge/Creature/Action/Flee.hs delete mode 100644 src/Dodge/Creature/Action/Movement.hs delete mode 100644 src/Dodge/Creature/Action/UseItem.hs delete mode 100644 src/Dodge/Creature/ActionRat.hs delete mode 100644 src/Dodge/Creature/ImpulseRat.hs diff --git a/src/Dodge/Creature.hs b/src/Dodge/Creature.hs index b44457196..06a4a406d 100644 --- a/src/Dodge/Creature.hs +++ b/src/Dodge/Creature.hs @@ -82,6 +82,7 @@ miniGunCrit = defaultCreature , _crRad = 10 , _crState = defaultState , _crHP = 500 + , _crMvType = defaultAimMvType } longCrit :: Creature longCrit = defaultCreature diff --git a/src/Dodge/Creature/Action.hs b/src/Dodge/Creature/Action.hs index b5cca57b6..3ade8f554 100644 --- a/src/Dodge/Creature/Action.hs +++ b/src/Dodge/Creature/Action.hs @@ -1,10 +1,14 @@ {- | Actions performed by creatures within the world -} module Dodge.Creature.Action --- ( module Dodge.Creature.Action --- , module Dodge.Creature.Action.UseItem --- , module Dodge.Creature.Action.Movement --- ) + ( performActionsR + , startReloadingWeapon + , blinkAction + , crAutoReload + , copyItemToFloor + , youDropItem + , pickUpItem + ) where import Dodge.Creature.Stance.Data import Dodge.WorldEvent.Shockwave @@ -39,6 +43,28 @@ performActions w cr = cr performActionsR :: Creature -> Reader World Creature performActionsR cr = reader $ \w -> performActions w cr +type OutAction = ( [Impulse] , Maybe Action ) + +performAimAt :: Creature -> World -> Int -> Point2 -> OutAction +performAimAt cr w tcid p = ([TurnToward tpos aimSp], Just $ AimAt tcid tpos) + where + cdir = _crDir cr + cpos = _crPos cr + canSee' = canSee (_crID cr) tcid w + aimSp = case cr ^? crMvType . mvAimSpeed of + Just f -> f $ safeAngleVV (unitVectorAtAngle cdir) (tpos - cpos) + Nothing -> error "creature without aiming type" + tpos | canSee' = _crPos (_creatures w IM.! tcid) + | otherwise = p + +performPathTo :: Creature -> World -> Point2 -> OutAction +performPathTo cr w p + | dist cpos p < 5 = ([], Nothing) + | hasLOS cpos p w = ([MvTurnToward p,MvForward] , Just (PathTo p)) + | otherwise = ([], Nothing) + where + cpos = _crPos cr + {- | Performing an action means that a creature has some impulses for a frame, and updates or deletes the action itself. -- doAction -} @@ -46,17 +72,9 @@ performAction :: Creature -> World -> Action - -> ( [Impulse] , Maybe Action ) + -> OutAction performAction cr w ac = case ac of - AimAt tcid p - -> ([TurnToward tpos aimSp], Just $ AimAt tcid tpos) - where - canSee' = canSee (_crID cr) tcid w - aimSp = case cr ^? crMvType . mvAimSpeed of - Just f -> f $ safeAngleVV (unitVectorAtAngle cdir) (tpos - cpos) - Nothing -> error "creature without aiming type" - tpos | canSee' = _crPos (_creatures w IM.! tcid) - | otherwise = p + AimAt tcid p -> performAimAt cr w tcid p WaitThen 0 newAc -> ([] , Just newAc) WaitThen t newAc -> ([] , Just (WaitThen (t-1) newAc)) ImpulsesList (xs:xss) -> (xs, Just $ ImpulsesList xss) @@ -85,10 +103,7 @@ performAction cr w ac = case ac of let (imps, newAcs) = unzip $ map (performAction cr w) acs in (concat imps, Just . DoActions $ catMaybes newAcs) StartSentinelPost -> ([AddGoal $ SentinelAt (_crPos cr) (_crDir cr)], Nothing) - PathTo p - | dist cpos p < 5 -> ([], Nothing) - | hasLOS cpos p w -> ([MvTurnToward p,MvForward] , Just (PathTo p)) - | otherwise -> ([], Nothing) + PathTo p -> performPathTo cr w p LeadTarget p -> case cr ^? crTarget . _Just of Just tcr -> ([TurnTo (_crPos tcr +.+ rotateV (_crDir tcr) p)], Nothing) _ -> ([], Nothing) @@ -106,10 +121,6 @@ performAction cr w ac = case ac of (imps , Just nac) -> (imps, Just $ DoReplicatePartial sac t nac) (imps , _) -> (imps, Just $ DoReplicatePartial sac (t-1) sac) NoAction -> ([],Nothing) --- _ -> ([], Nothing) - where - cpos = _crPos cr - cdir = _crDir cr startReloadingWeapon :: Creature diff --git a/src/Dodge/Creature/Action/Flee.hs b/src/Dodge/Creature/Action/Flee.hs deleted file mode 100644 index 058a33b72..000000000 --- a/src/Dodge/Creature/Action/Flee.hs +++ /dev/null @@ -1,22 +0,0 @@ -module Dodge.Creature.Action.Flee - where -import Dodge.Data -import Geometry -import FoldableHelp - -retreatPointForFrom - :: Float -> World -> Creature -> Point2 -> Maybe Point2 -retreatPointForFrom d _ cr p - = safeMinimumOn (dist cpos) - $ divideCircle 10 p d - where - cpos = _crPos cr --- = head $ sortBy (compare `on` (\p -> dist p ypos < 300)) $ retreatP'' : retreatPs --- where --- retreatPs = sortBy (compare `on` dist cpos) $ map f $ nRaysRad 8 400 --- where f p = fromMaybe (ypos +.+ p) $ fmap fst --- $ reflectPointWalls ypos (ypos +.+ p) (wallsAlongLine ypos (ypos +.+ p) w) --- retreatP' = cpos +.+ 300 *.* (cpos -.- ypos) --- retreatP'' = fromMaybe retreatP' $ fmap fst --- $ reflectPointWalls ypos retreatP' --- $ wallsAlongLine ypos retreatP' w diff --git a/src/Dodge/Creature/Action/Movement.hs b/src/Dodge/Creature/Action/Movement.hs deleted file mode 100644 index 84201e17d..000000000 --- a/src/Dodge/Creature/Action/Movement.hs +++ /dev/null @@ -1,114 +0,0 @@ -module Dodge.Creature.Action.Movement - where -import Dodge.Data -import Dodge.Creature.Stance.Data -import Dodge.Item.Data -import Geometry - -import Data.Maybe -import qualified Data.IntMap.Strict as IM -import Control.Lens -{- | Creature attempts to moves under its own steam. -The idea is that this may or may not work, depending on the status of the creature. -For now, though, this cannot fail. -} -crMvBy - :: Point2 -- ^ Movement translation vector, will be made relative to creature direction - -> Creature - -> Creature -crMvBy p' cr = advanceStepCounter (magV p) cr - & crPos %~ (+.+ p) - & crMvDir .~ argV p - where - p = (*.*) (equipFactor * aimingFactor) $ rotateV (_crDir cr) p' - equipFactor - | _posture (_crStance cr) == Aiming - = product $ map equipAimSpeed $ IM.elems $ _crInv cr - | otherwise = product $ map equipSpeed $ IM.elems $ _crInv cr - aimingFactor - | _posture (_crStance cr) == Aiming = fromMaybe 1 $ it ^? itAimingSpeed - | otherwise = 1 - it = _crInv cr IM.! _crInvSel cr - -crMvAbsolute - :: Point2 -- ^ Movement translation vector - -> Creature - -> Creature -crMvAbsolute p' cr = advanceStepCounter (magV p) cr - & crPos %~ (+.+ p) - & crMvDir .~ argV p - where - p = (*.*) (equipFactor * aimingFactor) p' - equipFactor - | _posture (_crStance cr) == Aiming - = product $ map equipAimSpeed $ IM.elems $ _crInv cr - | otherwise = product $ map equipSpeed $ IM.elems $ _crInv cr - aimingFactor - | _posture (_crStance cr) == Aiming = fromMaybe 1 $ it ^? itAimingSpeed - | otherwise = 1 - it = _crInv cr IM.! _crInvSel cr - -crMvForward - :: Float -- ^ Speed - -> Creature - -> Creature -crMvForward speed = crMvBy (V2 speed 0) - -advanceStepCounter - :: Float -- ^ Speed - -> Creature - -> Creature -advanceStepCounter speed cr = cr & crStance . carriage %~ f - where - --stnce = _crStance cr - f car = case car of - Standing -> f (Walking 0 RightForward) - Walking i ff -> Walking (i + ceiling speed) ff - _ -> car - -creatureTurn :: Float -> Creature -> Creature -creatureTurn a = crDir +~ a - -creatureTurnTo :: Point2 -> Creature -> Creature -creatureTurnTo p cr - | vToTarg == V2 0 0 = cr -- this should deal with the angleVV error - | otherwise = cr & crDir .~ dirToTarget - where - vToTarg = p -.- _crPos cr - dirToTarget = argV vToTarg - -creatureTurnTowardDir - :: Float -- ^ Angle - -> Float -- ^ Turn speed - -> Creature - -> Creature -creatureTurnTowardDir a turnSpeed cr - | vToTarg == V2 0 0 = cr -- this should deal with the angleVV error - | errorAngleVV 3 vToTarg (unitVectorAtAngle (_crDir cr)) <= turnSpeed - = cr & crDir .~ dirToTarget - | isLeftOfA (normalizeAngle dirToTarget) (normalizeAngle $ _crDir cr) = cr & crDir +~ turnSpeed - | otherwise = cr & crDir -~ turnSpeed - where - vToTarg = rotateV a (V2 1 0) - dirToTarget = argV vToTarg - -creatureTurnToward :: Point2 -> Float -> Creature -> Creature -creatureTurnToward p turnSpeed cr - | vToTarg == V2 0 0 = cr -- this should deal with the angleVV error - | errorAngleVV 3 vToTarg (unitVectorAtAngle (_crDir cr)) <= turnSpeed - = cr & crDir .~ dirToTarget - | isLeftOfA (normalizeAngle dirToTarget) (normalizeAngle $ _crDir cr) = cr & crDir +~ turnSpeed - | otherwise = cr & crDir -~ turnSpeed - where - vToTarg = p -.- _crPos cr - dirToTarget = argV vToTarg - -{- | Speed modifier of an item when not aiming. -} -equipSpeed :: Item -> Float -equipSpeed _ = 1 -{- | Speed modifier of an item when aiming. -} -equipAimSpeed :: Item -> Float -equipAimSpeed NoItem = 1 -equipAimSpeed it - | _itIdentity it == FrontArmour = 0.5 - | _itIdentity it == FlameShield = 0.5 - | otherwise = 1 diff --git a/src/Dodge/Creature/Action/UseItem.hs b/src/Dodge/Creature/Action/UseItem.hs deleted file mode 100644 index e2af96496..000000000 --- a/src/Dodge/Creature/Action/UseItem.hs +++ /dev/null @@ -1,48 +0,0 @@ -module Dodge.Creature.Action.UseItem - ( useItem - , tryUseItem - , useLeftItem - ) - where -import Dodge.Data -import Dodge.Inventory - -import qualified Data.IntMap.Strict as IM -import Control.Lens -import Data.Maybe - -useItem :: Int -> World -> World -useItem n w = itemEffect c it w - where - c = _creatures w IM.! n - it = _crInv c IM.! _crInvSel c - -tryUseItem - :: Creature - -> World - -> World -tryUseItem cr' w = case w ^? creatures . ix (_crID cr') of - Just cr -> itemEffect cr (_crInv cr IM.! _crInvSel cr) w - Nothing -> w - -itemEffect - :: Creature - -> Item - -> World - -> World -itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w) -itemEffect cr it@Weapon{_itUse=eff} w = foldr ($) eff (_itUseModifiers it) it cr w -itemEffect cr it@Throwable{_itUse = eff} w = foldr ($) eff (_itUseModifiers it) it cr w -itemEffect _ _ w = w - -useLeftItem - :: Int - -> World - -> World -useLeftItem cid w = case luse of - Nothing -> w - Just (invid, f) -> f cr invid w - where - cr = _creatures w IM.! cid - luses = IM.mapMaybe (^? itLeftClickUse . _Just) (_crInv cr) - luse = listToMaybe $ IM.toList luses diff --git a/src/Dodge/Creature/ActionRat.hs b/src/Dodge/Creature/ActionRat.hs deleted file mode 100644 index a3b326bd9..000000000 --- a/src/Dodge/Creature/ActionRat.hs +++ /dev/null @@ -1,33 +0,0 @@ -module Dodge.Creature.ActionRat - ( goToPostStrat - ) - where -import Dodge.Data ---import Dodge.Base ---import Dodge.Base.Collide ---import Dodge.Creature.ChooseTarget ---import Dodge.Creature.Stance.Data -import Dodge.Creature.Test -import Dodge.Creature.Volition ---import Geometry - -import Data.List ---import qualified Data.IntMap.Strict as IM ---import Control.Lens - -goToPostStrat :: World -> Creature -> Strategy -goToPostStrat w cr = case find sentinelGoal $ _crGoal $ _crActionPlan cr of - Just (SentinelAt p _) -> StrategyActions (GetTo p) - [DoActionThen (WaitThen 150 holsterIfAiming) - $ DoActionThen (PathTo p) - NoAction - -- $ DoImpulses [ChangeStrategy WatchAndWait] - ] - _ -> WatchAndWait - where - sentinelGoal (SentinelAt _ _) = True - sentinelGoal _ = False - holsterIfAiming - | crIsAiming (w,cr) = holsterWeapon - | otherwise = NoAction - diff --git a/src/Dodge/Creature/AlertLevel.hs b/src/Dodge/Creature/AlertLevel.hs index dd5cf3169..46c697dba 100644 --- a/src/Dodge/Creature/AlertLevel.hs +++ b/src/Dodge/Creature/AlertLevel.hs @@ -1,52 +1,43 @@ +{-# LANGUAGE TupleSections #-} {- | Deals with changes in a creature's awareness of other creatures. -} module Dodge.Creature.AlertLevel + ( basicPerceptionUpdateR + ) where import Dodge.Data import Dodge.Creature.AlertLevel.Data import Dodge.Base.Collide -import StrictHelp +--import StrictHelp import Control.Lens import Control.Monad.Reader import qualified Data.IntMap.Strict as IM -{- | Ties together (currently) an awareness and attention update -} -basicPerceptionUpdate - :: [Int] -- ^ List of creature ids that may direct attention and awareness - -> World - -> Creature - -> Creature -basicPerceptionUpdate is w cr - = basicAwarenessUpdate w $ basicAttentionUpdate is w cr +{- | Ties together (currently) an awareness and attention update -} basicPerceptionUpdateR :: [Int] -- ^ List of creature ids that may direct attention and awareness -> Creature -> Reader World Creature -basicPerceptionUpdateR is cr = reader $ \w -> - basicAwarenessUpdate w $ basicAttentionUpdate is w cr +basicPerceptionUpdateR is cr = basicAttentionUpdate is cr >>= basicAwarenessUpdate -{- | Update a creatures awareness based upon the creatures current direction +{- | Update a creatures awareness based upon the creatures' current direction of attention -} basicAwarenessUpdate - :: World -> Creature -> Creature -basicAwarenessUpdate _ cr = case _crAttentionDir cr of - AttentiveTo is -> cr & crAwarenessLevel %~ updateAwareness is - Fixated i -> cr & crAwarenessLevel - %~ ( IM.insert i (Cognizant 100) . IM.mapMaybe decreaseAwareness) -{- | Increase awareness of a given list of ids -} -updateAwareness :: [Int] -> IM.IntMap AwarenessLevel -> IM.IntMap AwarenessLevel -updateAwareness is imawareness - = foldr (\k -> IM.insertWith (\_ x -> increaseAwareness x) k (AwarenessInt 1)) - (IM.mapMaybe decreaseAwareness imawareness) is - -- (IM.mapMaybe decreaseAwareness imawareness) is -{- | Increase awareness level -} -increaseAwareness :: AwarenessLevel -> AwarenessLevel -increaseAwareness (AwarenessInt x) - | x < 100 = AwarenessInt $ x + 2 - | otherwise = Cognizant 1 -increaseAwareness (Cognizant x) - | x < 100 = Cognizant (x + 2) - | otherwise = Cognizant 100 + :: Creature -> Reader World Creature +basicAwarenessUpdate cr = case _crAttentionDir cr of + AttentiveTo is -> pure $ cr & crAwarenessLevel + %~ (IM.unionWith combineAwareness is . IM.mapMaybe decreaseAwareness) + Fixated i -> pure $ cr & crAwarenessLevel + %~ ( IM.insert i (Cognizant 100) . IM.mapMaybe decreaseAwareness) + +combineAwareness :: AwarenessLevel -> AwarenessLevel -> AwarenessLevel +combineAwareness (AwarenessInt x) (AwarenessInt y) + | x + y < 100 = AwarenessInt $ x + y + | otherwise = Cognizant 50 +combineAwareness (AwarenessInt x) (Cognizant y) = Cognizant $ min 100 $ x + y +combineAwareness (Cognizant x) (AwarenessInt y) = Cognizant $ min 100 $ x + y +combineAwareness (Cognizant x) (Cognizant y) = Cognizant $ min 100 $ x + y + {- | Decrease awareness level. Returns 'Maybe' value for use with 'IM.mapMaybe' -} decreaseAwareness :: AwarenessLevel -> Maybe AwarenessLevel @@ -58,8 +49,9 @@ decreaseAwareness (Cognizant x) = Just $ Cognizant $ x - 1 - are in view. -} basicAttentionUpdate :: [Int] -- ^ Creatures that may attract this creature's attention - -> World -> Creature - -> Creature -basicAttentionUpdate cids w cr = cr & crAttentionDir .~ - AttentiveTo (forceFoldable $ filter (\cid -> canSee (_crID cr) cid w) cids) + -> Reader World Creature +basicAttentionUpdate cids cr = do + w <- ask + pure $ cr & crAttentionDir .~ + AttentiveTo (IM.fromList $ map (, AwarenessInt 2) $ filter (\cid -> canSeeIndirect (_crID cr) cid w) cids) diff --git a/src/Dodge/Creature/AlertLevel/Data.hs b/src/Dodge/Creature/AlertLevel/Data.hs index 92dea986b..2c62b0cde 100644 --- a/src/Dodge/Creature/AlertLevel/Data.hs +++ b/src/Dodge/Creature/AlertLevel/Data.hs @@ -9,6 +9,7 @@ module Dodge.Creature.AlertLevel.Data , getFixated ) where import Control.Lens +import qualified Data.IntMap as IM data AwakeLevel = Comatose @@ -18,7 +19,7 @@ data AwakeLevel | Overstrung data AttentionDir - = AttentiveTo {_getAttentiveTo :: [Int]} + = AttentiveTo {_getAttentiveTo :: IM.IntMap AwarenessLevel } | Fixated {_getFixated :: Int } data AwarenessLevel diff --git a/src/Dodge/Creature/ArmourChase.hs b/src/Dodge/Creature/ArmourChase.hs index d454e986c..60667d9db 100644 --- a/src/Dodge/Creature/ArmourChase.hs +++ b/src/Dodge/Creature/ArmourChase.hs @@ -26,7 +26,7 @@ armourChaseCrit = defaultCreature doStrategyActionsR >=> performActionsR >=> targetYouWhenCognizantR >=> - setTargetMv (pure . _crTarget) >=> + setTargetMv (pure . _crTarget) >=> -- should be able to remove this? flockACCR >=> basicPerceptionUpdateR [0] >=> goToTarget >=> diff --git a/src/Dodge/Creature/Boid.hs b/src/Dodge/Creature/Boid.hs index 319c23050..77a901550 100644 --- a/src/Dodge/Creature/Boid.hs +++ b/src/Dodge/Creature/Boid.hs @@ -3,7 +3,6 @@ module Dodge.Creature.Boid import Dodge.Data import Dodge.Base import Dodge.Creature.State.Data -import Dodge.Creature.ImpulseRat import Geometry import Geometry.ConvexPoly @@ -254,3 +253,46 @@ flockPointTargetR f targFunc cr = reader $ \w -> case targFunc cr w of is = _swarm $ _crGroup cr crs = IM.restrictKeys (_creatures w) is p = f crTarg crs cr + +meleeHeadingMove + :: Float -- ^ max turn speed + -> Float -- ^ min turn speed + -> Float -- ^ turn speed cutoff angle + -> Float -- ^ move speed + -> Point2 -- ^ target point + -> Creature -- ^ start creature + -> Creature -- ^ target creature + -> [Impulse] +meleeHeadingMove maxta minta tacutoff speed tp cr tcr + | dist tpos cpos < combinedRad + 5 + && abs (_crDir cr - argV (tpos -.- cpos)) < tacutoff + && _crMeleeCooldown cr == 0 + = [Melee (_crID tcr), Turn pi] + | dist tpos cpos < combinedRad + 5 + && abs (_crDir cr - argV (tpos -.- cpos)) < tacutoff + = [ TurnToward tpos minta ] + | abs (_crDir cr - argV (tp -.- cpos)) < tacutoff + = [MoveForward speed , TurnToward tp maxta , RandomTurn maxta ] + | otherwise = [MoveForward speed , TurnToward tp minta, RandomTurn maxta ] + where + cpos = _crPos cr + tpos = _crPos tcr + combinedRad = _crRad cr + _crRad tcr + + +mvPointMeleeTarg :: Point2 -> Creature -> Creature -> [Impulse] +mvPointMeleeTarg p cr crT + | dist tpos cpos < combinedRad + 5 + && abs (_crDir cr - argV (tpos -.- cpos)) < pi/4 + && _crMeleeCooldown cr == 0 + = [Melee (_crID crT)] + | dist tpos cpos < combinedRad + 5 + && abs (_crDir cr - argV (tpos -.- cpos)) < pi/4 + = [ TurnToward tpos 0.05 ] + | abs (_crDir cr - argV (p -.- cpos)) < pi/4 + = [MoveForward 3 , TurnToward p 0.2 , RandomTurn 0.2 ] + | otherwise = [MoveForward 3 , TurnToward p 0.05, RandomTurn 0.2 ] + where + cpos = _crPos cr + tpos = _crPos crT + combinedRad = _crRad cr + _crRad crT diff --git a/src/Dodge/Creature/ChaseCrit.hs b/src/Dodge/Creature/ChaseCrit.hs index a27a488ed..f5605b48b 100644 --- a/src/Dodge/Creature/ChaseCrit.hs +++ b/src/Dodge/Creature/ChaseCrit.hs @@ -5,9 +5,7 @@ module Dodge.Creature.ChaseCrit import Dodge.Data import Dodge.Default import Dodge.Creature.Picture ---import Dodge.Creature.Test import Dodge.Creature.ReaderUpdate -import Dodge.Creature.ChooseTarget import Dodge.Creature.Impulse import Dodge.Creature.Action import Dodge.Creature.AlertLevel @@ -40,7 +38,8 @@ chaseCrit = defaultCreature doStrategyActionsR >=> performActionsR >=> overrideMeleeCloseTargetR >=> - chaseTargetR targetYouLOS >=> + setTargetMv (pure . _crTarget) >=> + goToTarget >=> basicPerceptionUpdateR [0] >=> targetYouWhenCognizantR >=> return . (crMeleeCooldown %~ max 0 . subtract 1) diff --git a/src/Dodge/Creature/ImpulseRat.hs b/src/Dodge/Creature/ImpulseRat.hs deleted file mode 100644 index f193c6368..000000000 --- a/src/Dodge/Creature/ImpulseRat.hs +++ /dev/null @@ -1,51 +0,0 @@ -module Dodge.Creature.ImpulseRat - ( mvPointMeleeTarg - , meleeHeadingMove - ) - where -import Dodge.Data - -import Geometry - -meleeHeadingMove - :: Float -- ^ max turn speed - -> Float -- ^ min turn speed - -> Float -- ^ turn speed cutoff angle - -> Float -- ^ move speed - -> Point2 -- ^ target point - -> Creature -- ^ start creature - -> Creature -- ^ target creature - -> [Impulse] -meleeHeadingMove maxta minta tacutoff speed tp cr tcr - | dist tpos cpos < combinedRad + 5 - && abs (_crDir cr - argV (tpos -.- cpos)) < tacutoff - && _crMeleeCooldown cr == 0 - = [Melee (_crID tcr), Turn pi] - | dist tpos cpos < combinedRad + 5 - && abs (_crDir cr - argV (tpos -.- cpos)) < tacutoff - = [ TurnToward tpos minta ] - | abs (_crDir cr - argV (tp -.- cpos)) < tacutoff - = [MoveForward speed , TurnToward tp maxta , RandomTurn maxta ] - | otherwise = [MoveForward speed , TurnToward tp minta, RandomTurn maxta ] - where - cpos = _crPos cr - tpos = _crPos tcr - combinedRad = _crRad cr + _crRad tcr - - -mvPointMeleeTarg :: Point2 -> Creature -> Creature -> [Impulse] -mvPointMeleeTarg p cr crT - | dist tpos cpos < combinedRad + 5 - && abs (_crDir cr - argV (tpos -.- cpos)) < pi/4 - && _crMeleeCooldown cr == 0 - = [Melee (_crID crT)] - | dist tpos cpos < combinedRad + 5 - && abs (_crDir cr - argV (tpos -.- cpos)) < pi/4 - = [ TurnToward tpos 0.05 ] - | abs (_crDir cr - argV (p -.- cpos)) < pi/4 - = [MoveForward 3 , TurnToward p 0.2 , RandomTurn 0.2 ] - | otherwise = [MoveForward 3 , TurnToward p 0.05, RandomTurn 0.2 ] - where - cpos = _crPos cr - tpos = _crPos crT - combinedRad = _crRad cr + _crRad crT diff --git a/src/Dodge/Creature/LauncherCrit.hs b/src/Dodge/Creature/LauncherCrit.hs index f662415a7..41be6b88e 100644 --- a/src/Dodge/Creature/LauncherCrit.hs +++ b/src/Dodge/Creature/LauncherCrit.hs @@ -7,14 +7,11 @@ import Dodge.Default import Dodge.Creature.Picture import Dodge.Creature.Test import Dodge.Creature.Volition -import Dodge.Creature.ActionRat ---import Dodge.Creature.ChooseTarget +import Dodge.Creature.Strategy import Dodge.Creature.ReaderUpdate import Dodge.Creature.AlertLevel import Dodge.Creature.State ---import Dodge.Creature.State.Data import Dodge.Item.Weapon.Launcher ---import Dodge.Item.Consumable import Dodge.Creature.Impulse import Dodge.Creature.Action import Geometry.Data diff --git a/src/Dodge/Creature/LtAutoCrit.hs b/src/Dodge/Creature/LtAutoCrit.hs index aa7c28581..c2ad64294 100644 --- a/src/Dodge/Creature/LtAutoCrit.hs +++ b/src/Dodge/Creature/LtAutoCrit.hs @@ -8,7 +8,7 @@ import Dodge.Creature.Impulse import Dodge.Creature.Action import Dodge.Creature.Test import Dodge.Creature.Volition -import Dodge.Creature.ActionRat +import Dodge.Creature.Strategy --import Dodge.Creature.ChooseTarget import Dodge.Creature.ReaderUpdate import Dodge.Creature.AlertLevel diff --git a/src/Dodge/Creature/PistolCrit.hs b/src/Dodge/Creature/PistolCrit.hs index 81aa969e9..977a0e71d 100644 --- a/src/Dodge/Creature/PistolCrit.hs +++ b/src/Dodge/Creature/PistolCrit.hs @@ -8,7 +8,7 @@ import Dodge.Creature.Test import Dodge.Creature.Impulse import Dodge.Creature.Action import Dodge.Creature.Volition -import Dodge.Creature.ActionRat +import Dodge.Creature.Strategy import Dodge.Creature.ReaderUpdate --import Dodge.Creature.ChooseTarget import Dodge.Creature.AlertLevel diff --git a/src/Dodge/Creature/ReaderUpdate.hs b/src/Dodge/Creature/ReaderUpdate.hs index 1e0cf3e2e..3e0d170c6 100644 --- a/src/Dodge/Creature/ReaderUpdate.hs +++ b/src/Dodge/Creature/ReaderUpdate.hs @@ -1,8 +1,6 @@ {- | Functions updating a creature in a Reader World environment -} module Dodge.Creature.ReaderUpdate ( doStrategyActionsR - , chaseTargetR - , chaseTargetRR , setTargetMv , targetYouWhenCognizantR , overrideMeleeCloseTargetR @@ -43,15 +41,6 @@ tryMeleeAttack cr tcr where cpos = _crPos cr -chaseTargetRR - :: (Creature -> Reader World (Maybe Creature)) -- ^ Function for determining target - -> Creature - -> Reader World Creature -chaseTargetRR targFunc cr = do - targ <- targFunc cr - case targ of - Nothing -> pure cr - Just crTarg -> pure $ cr & crActionPlan . crImpulse .~ chaseTarg cr crTarg setTargetMv :: (Creature -> Reader World (Maybe Creature)) -- ^ Function for determining target -> Creature @@ -107,26 +96,6 @@ goToTarget cr = do trad = _mvTurnRad mvType jit = _mvTurnJit mvType - -chaseTargetR - :: (Creature -> World -> Maybe Creature) -- ^ Function for determining target - -> Creature - -> Reader World Creature -chaseTargetR targFunc cr = reader $ \w -> case targFunc cr w of - Nothing -> cr - Just crTarg -> cr & crActionPlan . crImpulse .~ chaseTarg cr crTarg - -chaseTarg :: Creature -> Creature -> [Impulse] -chaseTarg cr crT = [MoveForward speed, TurnToward tpos (trad dirOffset), RandomTurn jit] - where - cpos = _crPos cr - tpos = _crPos crT - mvType = _crMvType cr - speed = _mvSpeed mvType - trad = _mvTurnRad mvType - jit = _mvTurnJit mvType - dirOffset = abs (_crDir cr - argV (tpos -.- cpos)) - doStrategyActionsR :: Creature -> Reader World Creature @@ -178,13 +147,3 @@ targetYouWhenCognizantR :: Creature -> Reader World Creature targetYouWhenCognizantR cr = reader $ \w -> case cr ^? crAwarenessLevel . ix 0 of Just (Cognizant _) -> cr {_crTarget = Just $! _creatures w IM.! 0} _ -> cr & crTarget .~ Nothing - ---shootTargetWithStratR --- :: (Creature -> World -> Maybe Creature) -- ^ Function for determining target --- -> (World -> Creature -> Creature -> [Action] -> [Action]) --- -- ^ Function for determining shooting strategy given target --- -> Creature --- -> Reader World Creature ---shootTargetWithStratR targFunc strat cr = reader $ \w -> case targFunc cr w of --- Nothing -> cr --- Just crTarg -> cr & crActionPlan . crAction %~ strat w cr crTarg diff --git a/src/Dodge/Creature/SentinelAI.hs b/src/Dodge/Creature/SentinelAI.hs index 598706248..7a5440593 100644 --- a/src/Dodge/Creature/SentinelAI.hs +++ b/src/Dodge/Creature/SentinelAI.hs @@ -5,7 +5,7 @@ import Dodge.Base.Collide import Dodge.Creature.Test import Dodge.Creature.Volition import Dodge.Creature.ReaderUpdate -import Dodge.Creature.ActionRat +import Dodge.Creature.Strategy import Dodge.Creature.Action --import Dodge.Creature.ChooseTarget import Dodge.Creature.AlertLevel diff --git a/src/Dodge/Creature/SpreadGunCrit.hs b/src/Dodge/Creature/SpreadGunCrit.hs index adcc2f5f2..b9402b4d6 100644 --- a/src/Dodge/Creature/SpreadGunCrit.hs +++ b/src/Dodge/Creature/SpreadGunCrit.hs @@ -8,7 +8,7 @@ import Dodge.Creature.Test import Dodge.Creature.Impulse import Dodge.Creature.Action import Dodge.Creature.Volition -import Dodge.Creature.ActionRat +import Dodge.Creature.Strategy import Dodge.Creature.ReaderUpdate --import Dodge.Creature.ChooseTarget import Dodge.Creature.AlertLevel diff --git a/src/Dodge/Creature/SwarmCrit.hs b/src/Dodge/Creature/SwarmCrit.hs index c3c052801..429ab3ebb 100644 --- a/src/Dodge/Creature/SwarmCrit.hs +++ b/src/Dodge/Creature/SwarmCrit.hs @@ -6,27 +6,16 @@ import Dodge.Data import Dodge.Default import Dodge.Creature.Picture import Dodge.Creature.Boid ---import Dodge.Creature.Test ---import Dodge.Creature.ActionRat -import Dodge.Creature.ImpulseRat ---import Dodge.Creature.ChooseTarget ---import Dodge.Creature.SetTarget import Dodge.Creature.ReaderUpdate import Dodge.Creature.AlertLevel import Dodge.Creature.Impulse import Dodge.Creature.State import Dodge.Creature.State.Data import Dodge.Picture.Layer ---import Geometry import Picture ---import Dodge.RandomHelp ---import Data.Maybe ---import qualified Data.IntMap.Strict as IM import Control.Lens import Control.Monad.Reader ---import Control.Monad.State ---import System.Random swarmCrit :: Creature swarmCrit = defaultCreature diff --git a/src/Dodge/Creature/YourControl.hs b/src/Dodge/Creature/YourControl.hs index 2fff6224f..b1b597a9d 100644 --- a/src/Dodge/Creature/YourControl.hs +++ b/src/Dodge/Creature/YourControl.hs @@ -2,7 +2,7 @@ module Dodge.Creature.YourControl where import Dodge.Data --import Dodge.Base -import Dodge.Creature.Action.Movement +import Dodge.Creature.Impulse.Movement --import Dodge.Creature.State --import Dodge.Creature.State.Data import Dodge.Creature.Stance.Data diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index 026f7121e..7dd5d19d8 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -51,7 +51,7 @@ defaultCreature = Creature , _crActionPlan = ActionPlan [] [] WatchAndWait [LiveLongAndProsper] , _crMeleeCooldown = 0 , _crAwakeLevel = Vigilant - , _crAttentionDir = AttentiveTo [] + , _crAttentionDir = AttentiveTo IM.empty , _crAwarenessLevel = IM.empty , _crFaction = NoFaction , _crTarget = Nothing diff --git a/src/Dodge/Floor.hs b/src/Dodge/Floor.hs index 3b6ff5e82..0af0eaa96 100644 --- a/src/Dodge/Floor.hs +++ b/src/Dodge/Floor.hs @@ -12,6 +12,7 @@ import Dodge.Creature.State.Data import Dodge.Room.Procedural import Dodge.Room.RoadBlock import Dodge.Room.Data +import Dodge.Room --import Dodge.Room.Link --import Dodge.Room.Door import Dodge.Room.Branch @@ -50,6 +51,9 @@ roomTreex = do [[StartRoom] ,[Corridor] ,[Corridor] + ,[SpecificRoom roomCCrits] + ,[Corridor] + ,[Corridor] ,[SpecificRoom . pure . pure . Right $ roomGlassOctogon 400 & rmPS %~ ([sPS (V2 0 50) 0 $ PutCrit armourChaseCrit ,sPS (V2 50 25) 0 $ PutCrit armourChaseCrit diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 2b2f234e3..c877d9af0 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -80,15 +80,12 @@ withThickSmokeI eff item cr w = eff item cr $ foldl' (flip $ makeThickSmokeAt . ps = replicateM 20 randOnUnitSphere & evalState $ _randGen w -- TODO create a trigger that does different things on first and continued -- fire. - - ammoCheckI :: ChainEffect ammoCheckI eff item cr w | _wpLoadedAmmo item <= 0 = fromMaybe w (startReloadingWeapon cr w) | _wpReloadState item > 0 = w | otherwise = eff item cr w - {- | Fires at an increasing rate. Has different effect after first fire. diff --git a/src/Dodge/Update/UsingInput.hs b/src/Dodge/Update/UsingInput.hs index 39ba5e2da..8e0e0577a 100644 --- a/src/Dodge/Update/UsingInput.hs +++ b/src/Dodge/Update/UsingInput.hs @@ -5,7 +5,7 @@ module Dodge.Update.UsingInput where import Dodge.Data import Dodge.Item.Data -import Dodge.Creature.Action.UseItem +import Dodge.Creature.Impulse.UseItem import Geometry import SDL