Chase crit suspicion increases more when you are closer
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
-- | Functions updating a creature in a Reader World environment
|
||||
module Dodge.Creature.ReaderUpdate (
|
||||
doStrategyActions,
|
||||
setTargetMv,
|
||||
@@ -17,6 +16,7 @@ module Dodge.Creature.ReaderUpdate (
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import Data.Bifunctor
|
||||
import Data.Maybe
|
||||
import Dodge.Base
|
||||
@@ -26,7 +26,6 @@ import Dodge.Data.World
|
||||
import Dodge.Zoning.Creature
|
||||
import FoldableHelp
|
||||
import Geometry
|
||||
import Control.Monad
|
||||
|
||||
overrideMeleeCloseTarget :: Creature -> Creature
|
||||
overrideMeleeCloseTarget cr = maybe cr (tryMeleeAttack cr) (_targetCr $ _crIntention cr)
|
||||
@@ -34,12 +33,13 @@ overrideMeleeCloseTarget cr = maybe cr (tryMeleeAttack cr) (_targetCr $ _crInten
|
||||
tryMeleeAttack :: Creature -> Creature -> Creature
|
||||
tryMeleeAttack cr tcr
|
||||
| _crMeleeCooldown cr == 0
|
||||
&& dist (_crPos tcr) cpos < _crRad cr + _crRad tcr + 5
|
||||
&& abs (_crDir cr - argV (_crPos tcr -.- cpos)) < pi / 4 =
|
||||
&& dist tpos cpos < _crRad cr + _crRad tcr + 5
|
||||
&& abs (_crDir cr - argV (tpos -.- cpos)) < pi / 4 =
|
||||
cr & crActionPlan . apImpulse .~ [Melee $ _crID tcr]
|
||||
| otherwise = cr
|
||||
where
|
||||
cpos = _crPos cr
|
||||
tpos = _crPos tcr
|
||||
|
||||
setMvPos :: World -> Creature -> Creature
|
||||
setMvPos w cr = cr & crIntention . mvToPoint .~ mpos
|
||||
@@ -47,14 +47,9 @@ setMvPos w cr = cr & crIntention . mvToPoint .~ mpos
|
||||
int = _crIntention cr
|
||||
mtpos = do
|
||||
tpos <- _crPos <$> _targetCr int
|
||||
if hasLOSIndirect (_crPos cr) tpos w
|
||||
then Just tpos
|
||||
else Nothing
|
||||
mpos =
|
||||
mtpos
|
||||
<|> _mvToPoint int
|
||||
|
||||
-- <|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
|
||||
guard $ hasLOSIndirect (_crPos cr) tpos w
|
||||
return $ tpos
|
||||
mpos = mtpos <|> _mvToPoint int
|
||||
|
||||
setViewPos :: Creature -> Creature
|
||||
setViewPos cr = cr & crIntention . viewPoint %~ (<|> mpos)
|
||||
@@ -112,31 +107,25 @@ chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
|
||||
_ -> viewTarget w cr
|
||||
|
||||
goToTarget :: World -> Creature -> Creature
|
||||
goToTarget w cr =
|
||||
case cr ^? crIntention . mvToPoint . _Just of
|
||||
Just p -> cr & crActionPlan . apAction .~ [PathTo p]
|
||||
_ -> viewTarget w cr
|
||||
goToTarget w cr = case cr ^? crIntention . mvToPoint . _Just of
|
||||
Just p -> cr & crActionPlan . apAction .~ [PathTo p]
|
||||
_ -> viewTarget w cr
|
||||
|
||||
lookAroundSelf :: Action
|
||||
lookAroundSelf = UseSelf CrTurnAround
|
||||
--lookAroundSelf :: Action
|
||||
--lookAroundSelf = UseSelf CrTurnAround
|
||||
|
||||
viewTarget :: World -> Creature -> Creature
|
||||
viewTarget w cr = do
|
||||
case cr ^? crIntention . viewPoint . _Just of
|
||||
Just p
|
||||
| hasLOSIndirect p (_crPos cr) w ->
|
||||
cr'
|
||||
& crActionPlan . apAction
|
||||
%~ replaceNullWith
|
||||
( TurnToPoint p
|
||||
`DoActionThen` 40 `WaitThen` lookAroundSelf
|
||||
`DoActionThen` 20 `WaitThen` lookAroundSelf
|
||||
)
|
||||
& crIntention . viewPoint .~ Nothing
|
||||
| otherwise -> cr' & crActionPlan . apAction %~ replaceNullWith (PathTo p)
|
||||
Nothing -> cr -- & crPerception . crAwakeLevel .~ Lethargic
|
||||
where
|
||||
cr' = cr & crPerception . cpVigilance .~ Vigilant
|
||||
viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of
|
||||
Just p
|
||||
| hasLOSIndirect p (_crPos cr) w ->
|
||||
cr
|
||||
& crActionPlan . apAction
|
||||
%~ replaceNullWith
|
||||
( TurnToPoint p
|
||||
)
|
||||
& crIntention . viewPoint .~ Nothing
|
||||
| otherwise -> cr & crActionPlan . apAction %~ replaceNullWith (PathTo p)
|
||||
Nothing -> cr
|
||||
|
||||
replaceNullWith :: a -> [a] -> [a]
|
||||
replaceNullWith x [] = [x]
|
||||
@@ -155,7 +144,7 @@ reloadOverride cr = fromMaybe cr $ do
|
||||
guard $ cr ^. crStance . posture == Aiming
|
||||
itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
guard $ cr ^? crInv . ix itRef . itUse . heldConsumption . laLoaded == Just 0
|
||||
return $ cr & crActionPlan . apStrategy .~ StrategyActions Reload reloadActions
|
||||
return $ cr & crActionPlan . apStrategy .~ StrategyActions Reload reloadActions
|
||||
where
|
||||
reloadActions =
|
||||
[ holsterWeapon
|
||||
@@ -192,20 +181,22 @@ targetYouWhenCognizant :: World -> Creature -> Creature
|
||||
targetYouWhenCognizant w cr = case cr ^? crPerception . cpAwareness . ix 0 of
|
||||
-- so this caused a space leak: be careful with ?~
|
||||
-- consider changing targeted creature to be just an index
|
||||
Just (Cognizant _) -> (w ^?! cWorld . lWorld . creatures . ix 0) `seq` cr & crIntention . targetCr ?~ (w ^?! cWorld . lWorld . creatures . ix 0)
|
||||
Just (Cognizant _) -> (w ^?! cWorld . lWorld . creatures . ix 0) `seq`
|
||||
cr & crIntention . targetCr ?~ (w ^?! cWorld . lWorld . creatures . ix 0)
|
||||
& crPerception . cpVigilance .~ Vigilant
|
||||
_ -> cr & crIntention . targetCr .~ Nothing
|
||||
|
||||
searchIfDamaged :: Creature -> Creature
|
||||
searchIfDamaged cr
|
||||
| _crPastDamage cr > 0 &&
|
||||
_apStrategy (_crActionPlan cr) == WatchAndWait =
|
||||
cr & crPerception . cpVigilance .~ Vigilant
|
||||
& crActionPlan . apStrategy
|
||||
.~ StrategyActions
|
||||
LookAround
|
||||
[ TurnToPoint (_crPos cr -.- unitVectorAtAngle (_crDir cr))
|
||||
`DoActionThen` 40 `WaitThen` bfsThenReturn 500
|
||||
]
|
||||
| _crPastDamage cr > 0
|
||||
&& _apStrategy (_crActionPlan cr) == WatchAndWait =
|
||||
cr & crPerception . cpVigilance .~ Vigilant
|
||||
& crActionPlan . apStrategy
|
||||
.~ StrategyActions
|
||||
LookAround
|
||||
[ TurnToPoint (_crPos cr -.- unitVectorAtAngle (_crDir cr))
|
||||
`DoActionThen` 40 `WaitThen` bfsThenReturn 500
|
||||
]
|
||||
| otherwise = cr
|
||||
|
||||
bfsThenReturn :: Int -> Action
|
||||
|
||||
Reference in New Issue
Block a user