Add frame clock

This commit is contained in:
2021-09-09 13:29:09 +01:00
parent a2288110ae
commit be7b2d2cd7
27 changed files with 176 additions and 87 deletions
+36 -12
View File
@@ -10,6 +10,7 @@ module Dodge.Creature.ReaderUpdate
, goToTarget
, flockACCR
, setMvPos
, setViewPos
)
where
import Dodge.Data
@@ -19,6 +20,7 @@ import Dodge.Creature.Test
import Dodge.Creature.Volition
import Dodge.Creature.Perception.Data
import Dodge.Base
import Dodge.Base.Collide
import Geometry
import FoldableHelp
@@ -31,7 +33,7 @@ import Data.Maybe
overrideMeleeCloseTargetR
:: Creature
-> Reader World Creature
overrideMeleeCloseTargetR cr = return $ maybe cr (tryMeleeAttack cr) (_crTarget cr)
overrideMeleeCloseTargetR cr = return $ maybe cr (tryMeleeAttack cr) (_targetCr $ _crIntention cr)
tryMeleeAttack :: Creature -> Creature -> Creature
tryMeleeAttack cr tcr
@@ -45,11 +47,17 @@ tryMeleeAttack cr tcr
cpos = _crPos cr
setMvPos :: Creature -> Reader World Creature
setMvPos cr = pure $ cr & crMvTarget .~ mpos
setMvPos cr = pure $ cr & crIntention . mvToPoint .~ mpos
where
mpos = (_crPos <$> _crTarget cr)
<|> _crMvTarget cr
<|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
int = _crIntention cr
mpos = (_crPos <$> _targetCr int)
<|> _mvToPoint int
-- <|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
setViewPos :: Creature -> Reader World Creature
setViewPos cr = pure $ cr & crIntention . viewPoint %~ (<|> mpos)
where
mpos = listToMaybe (_soundsToInvestigate $ _crMemory cr)
setTargetMv
:: (Creature -> Reader World (Maybe Creature)) -- ^ Function for determining target
@@ -59,10 +67,10 @@ setTargetMv targFunc cr = do
targ <- targFunc cr
case targ of
Nothing -> pure cr
Just crTarg -> pure $ cr & crMvTarget .~ Just (_crPos crTarg)
Just crTarg -> pure $ cr & crIntention . mvToPoint ?~ _crPos crTarg
flockACCR :: Creature -> Reader World Creature
flockACCR cr = do
case cr ^? crTarget . _Just of
case cr ^? crIntention . targetCr . _Just of
Nothing -> pure cr
Just tcr -> do
w <- ask
@@ -81,13 +89,29 @@ flockACCR cr = do
horShift = if isLHS tpos cpos (_crPos acr)
then r *.* horDir
else negate r *.* horDir
pure $ cr & crMvTarget .~ Just (tpos +.+ horShift)
pure $ cr & crIntention . mvToPoint ?~ tpos +.+ horShift
goToTarget :: Creature -> Reader World Creature
goToTarget cr = do
case cr ^? crMvTarget . _Just of
case cr ^? crIntention . mvToPoint . _Just of
Just p -> pure $ cr & crActionPlan . crAction .~ [PathTo p]
_ -> pure cr
_ -> viewTarget cr
viewTarget :: Creature -> Reader World Creature
viewTarget cr = do
w <- ask
case cr ^? crIntention . viewPoint . _Just of
Just p | hasLOSIndirect p (_crPos cr) w -> pure $ cr'
& crActionPlan . crAction %~ replaceNullWith (TurnToA p)
& crIntention . viewPoint .~ Nothing
| otherwise -> pure $ cr' & crActionPlan . crAction %~ replaceNullWith (PathTo p)
Nothing -> pure $ cr & crPerception . crAwakeLevel .~ Lethargic
where
cr' = cr & crPerception . crAwakeLevel .~ Vigilant
replaceNullWith :: a -> [a] -> [a]
replaceNullWith x [] = [x]
replaceNullWith _ xs = xs
doStrategyActionsR
:: Creature
@@ -138,5 +162,5 @@ listGuard (_,z) _ = z
targetYouWhenCognizantR :: Creature -> Reader World Creature
targetYouWhenCognizantR cr = reader $ \w -> case cr ^? crPerception . crAwarenessLevel . ix 0 of
Just (Cognizant _) -> cr {_crTarget = Just $! _creatures w IM.! 0}
_ -> cr & crTarget .~ Nothing
Just (Cognizant _) -> cr & crIntention . targetCr ?~ _creatures w IM.! 0
_ -> cr & crIntention . targetCr .~ Nothing