Tweak chase crit perception

This commit is contained in:
2023-04-30 23:29:31 +01:00
parent 5180e9a995
commit ba12a73842
6 changed files with 25 additions and 11 deletions
+4 -1
View File
@@ -2,8 +2,10 @@
module Dodge.Creature.Perception ( module Dodge.Creature.Perception (
perceptionUpdate, perceptionUpdate,
chaseCritPerceptionUpdate, chaseCritPerceptionUpdate,
visionCheck,
) where ) where
import Linear
import Control.Lens import Control.Lens
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
import Data.Maybe import Data.Maybe
@@ -152,7 +154,8 @@ visionCheck cr tpos = doFloatFloat (_viFOV vi) ang * doFloatFloat (_viDist vi) d
where where
vi = _cpVision $ _crPerception cr vi = _cpVision $ _crPerception cr
cpos = _crPos cr cpos = _crPos cr
ang = angleVV (unitVectorAtAngle (_crDir cr)) (tpos - cpos) dirvec = unitVectorAtAngle (_crDir cr)
ang = angleVV dirvec (tpos - (cpos - _crRad cr *^ dirvec))
d = dist tpos cpos d = dist tpos cpos
+17 -5
View File
@@ -14,6 +14,9 @@ module Dodge.Creature.ReaderUpdate (
setViewPos, setViewPos,
) where ) where
import Dodge.Creature.Perception
import qualified IntMapHelp as IM
import Data.List (sortOn)
import Control.Applicative import Control.Applicative
import Control.Lens import Control.Lens
import Control.Monad import Control.Monad
@@ -51,11 +54,19 @@ setMvPos w cr = cr & crIntention . mvToPoint .~ mpos
return $ tpos return $ tpos
mpos = mtpos <|> _mvToPoint int mpos = mtpos <|> _mvToPoint int
setViewPos :: Creature -> Creature setViewPos :: World -> Creature -> Creature
setViewPos cr = cr & crIntention . viewPoint %~ (<|> mpos) setViewPos w cr = cr & crIntention . viewPoint %~ ((<|> mpos) . (attentionViewPoint w cr <|>))
where where
mpos = listToMaybe (_soundsToInvestigate $ _crMemory cr) mpos = listToMaybe (_soundsToInvestigate $ _crMemory cr)
attentionViewPoint :: World -> Creature -> Maybe Point2
attentionViewPoint w cr = do
attention <- cr ^? crPerception . cpAttention . getAttentiveTo
cid <- (sortOn snd $ IM.toList attention) ^? ix 0 . _1
tcr <- w ^? cWorld . lWorld . creatures . ix cid
guard $ visionCheck cr (_crPos tcr) > 0
return (_crPos tcr)
setTargetMv :: setTargetMv ::
-- | Function for determining target -- | Function for determining target
(World -> Creature -> Maybe Creature) -> (World -> Creature -> Maybe Creature) ->
@@ -120,9 +131,10 @@ viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of
| hasLOSIndirect p (_crPos cr) w -> | hasLOSIndirect p (_crPos cr) w ->
cr cr
& crActionPlan . apAction & crActionPlan . apAction
%~ replaceNullWith .~ [TurnToPoint p]
( TurnToPoint p -- %~ replaceNullWith
) -- ( TurnToPoint p
-- )
& crIntention . viewPoint .~ Nothing & crIntention . viewPoint .~ Nothing
| otherwise -> cr & crActionPlan . apAction %~ replaceNullWith (PathTo p) | otherwise -> cr & crActionPlan . apAction %~ replaceNullWith (PathTo p)
Nothing -> cr Nothing -> cr
+1 -1
View File
@@ -12,7 +12,7 @@ data FloatFloat
= FloatID = FloatID
| FloatFOV Float | FloatFOV Float
| FloatLessCheck Float | FloatLessCheck Float
| FloatDistLinearMaxMin Float Float Float | FloatDistLinearNearFar Float Float Float
| FloatAbsCheckGreaterLess Float Float Float | FloatAbsCheckGreaterLess Float Float Float
| FloatConst Float | FloatConst Float
deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show, Read) --Generic, Flat)
+1 -2
View File
@@ -92,8 +92,7 @@ defaultVision :: Vision
defaultVision = defaultVision =
Eyes Eyes
{ _viFOV = FloatFOV 0.8 { _viFOV = FloatFOV 0.8
--, _viDist = FloatLessCheck 500 , _viDist = FloatDistLinearNearFar 500 10 1
, _viDist = FloatDistLinearMaxMin 500 10 1
} }
defaultAudition :: Audition defaultAudition :: Audition
+1 -1
View File
@@ -12,7 +12,7 @@ doFloatFloat ff x = case ff of
FloatLessCheck y FloatLessCheck y
| x > y -> 0 | x > y -> 0
| otherwise -> 1 | otherwise -> 1
FloatDistLinearMaxMin maxd a b FloatDistLinearNearFar maxd a b
| x > maxd -> 0 | x > maxd -> 0
| otherwise -> (a * (maxd - x) + b * (x - maxd)) / maxd | otherwise -> (a * (maxd - x) + b * (x - maxd)) / maxd
FloatAbsCheckGreaterLess a y1 y2 FloatAbsCheckGreaterLess a y1 y2
+1 -1
View File
@@ -16,7 +16,7 @@ updateHumanoid cr = case cr ^?! crType . humanoidAI of
[ const doStrategyActions [ const doStrategyActions
, performActions , performActions
, const overrideMeleeCloseTarget , const overrideMeleeCloseTarget
, const setViewPos , setViewPos
, setMvPos , setMvPos
, chaseCritMv , chaseCritMv
, chaseCritPerceptionUpdate [0] , chaseCritPerceptionUpdate [0]