Improve awareness

This commit is contained in:
2021-09-05 23:58:35 +01:00
parent e366698064
commit 86311c5d41
24 changed files with 121 additions and 397 deletions
+1
View File
@@ -82,6 +82,7 @@ miniGunCrit = defaultCreature
, _crRad = 10
, _crState = defaultState
, _crHP = 500
, _crMvType = defaultAimMvType
}
longCrit :: Creature
longCrit = defaultCreature
+33 -22
View File
@@ -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
-22
View File
@@ -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
-114
View File
@@ -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
-48
View File
@@ -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
-33
View File
@@ -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
+27 -35
View File
@@ -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)
+2 -1
View File
@@ -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
+1 -1
View File
@@ -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 >=>
+43 -1
View File
@@ -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
+2 -3
View File
@@ -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)
-51
View File
@@ -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
+1 -4
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
-41
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
-11
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+4
View File
@@ -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
-3
View File
@@ -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.
+1 -1
View File
@@ -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