Commit before trying to remove reified impulses

This commit is contained in:
2025-10-15 14:19:38 +01:00
parent a0c4d62018
commit f9bcac915f
7 changed files with 147 additions and 452 deletions
+37 -26
View File
@@ -13,25 +13,24 @@ module Dodge.Creature.ReaderUpdate (
setViewPos,
) where
import Linear
import Dodge.Creature.Vocalization
import Dodge.Creature.Radius
import RandomHelp
import Dodge.Creature.Perception
import qualified IntMapHelp as IM
import Data.List (sortOn)
import Control.Applicative
import LensHelp
import Control.Monad
import Data.Bifunctor
import Data.List (sortOn)
import Data.Maybe
import Dodge.Base
--import Dodge.Creature.Volition
import Dodge.Creature.Perception
import Dodge.Creature.Radius
import Dodge.Creature.Vocalization
import Dodge.Data.CreatureEffect
import Dodge.Data.World
import Dodge.Zoning.Creature
import FoldableHelp
import Geometry
import qualified IntMapHelp as IM
import LensHelp
import Linear
import RandomHelp
overrideMeleeCloseTarget :: Creature -> Creature
overrideMeleeCloseTarget cr = maybe cr (tryMeleeAttack cr) (_targetCr $ _crIntention cr)
@@ -43,12 +42,15 @@ tryMeleeAttack cr tcr
&& dist tpos cpos < crRad (cr ^. crType) + crRad (tcr ^. crType) + 5
&& abs (_crDir cr - argV (tpos -.- cpos)) < pi / 4 =
cr & crActionPlan . apImpulse .~ [Melee $ _crID tcr]
& crActionPlan . apAction .~ [DoReplicate 10 NoAction `DoActionThen` DoImpulses
[ChangeStrategy (CloseToMelee $ _crID tcr)] ]
& crActionPlan . apAction
.~ [ DoReplicate 10 NoAction
`DoActionThen` DoImpulses
[ChangeStrategy (CloseToMelee $ _crID tcr)]
]
& crActionPlan . apStrategy .~ MeleeStrike
| otherwise = cr
where
cpos = cr ^. crPos . _xy
cpos = cr ^. crPos . _xy
tpos = tcr ^. crPos . _xy
setMvPos :: World -> Creature -> Creature
@@ -92,7 +94,7 @@ flockACC w cr = case cr ^? crIntention . targetCr . _Just of
Nothing -> cr
Just tcr ->
let tpos = tcr ^. crPos . _xy
cpos = cr ^. crPos . _xy
cpos = cr ^. crPos . _xy
isFarACC cr' =
_crGroup cr' == _crGroup cr
&& _crID cr' /= _crID cr
@@ -117,19 +119,25 @@ chaseCritMv w cr = case _apStrategy (_crActionPlan cr) of
StrategyActions _ _ -> cr
WarningCry -> cr
MeleeStrike -> cr
CloseToMelee cid | Just 0 == (cr ^? crVocalization . vcCoolDown)
-> cr & crActionPlan . apAction
.:~ ImpulsesList ( [Bark soundid] : replicate numjits [RandomImpulse thejitter]
++ [[ChangeStrategy (CloseToMelee cid)]])
& crVocalization . vcCoolDown .~ 10
& crActionPlan . apStrategy .~ WarningCry
CloseToMelee cid
| Just 0 == (cr ^? crVocalization . vcCoolDown) ->
cr
& crActionPlan . apAction
.:~ ImpulsesList
( [Bark soundid] :
replicate numjits [RandomImpulse thejitter]
++ [[ChangeStrategy (CloseToMelee cid)]]
)
& crVocalization . vcCoolDown .~ 10
& crActionPlan . apStrategy .~ WarningCry
where
thejitter = RandImpulseCircMove 3
soundid = evalState (takeOne (crWarningSounds cr)) (_randGen w)
numjits = fst $ randomR (15, 25) (_randGen w)
_ -> case cr ^? crIntention . mvToPoint . _Just of
Just p
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) -> cr & crActionPlan . apAction .~ [PathTo p]
| dist (cr ^. crPos . _xy) p > crRad (cr ^. crType) ->
cr & crActionPlan . apAction .~ [PathTo p]
| otherwise ->
cr & crActionPlan . apAction .~ [bfsThenReturn 500 `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait]]
& crActionPlan . apStrategy .~ WatchAndWait
@@ -151,12 +159,13 @@ viewTarget w cr = case cr ^? crIntention . viewPoint . _Just of
cr
& crActionPlan . apAction
.~ [TurnToPoint p]
-- %~ replaceNullWith
-- ( TurnToPoint p
-- )
-- %~ replaceNullWith
-- ( TurnToPoint p
-- )
& crIntention . viewPoint .~ Nothing
& crActionPlan . apStrategy .~ Investigate
| otherwise -> cr & crActionPlan . apAction %~ replaceNullWith (PathTo p)
| otherwise ->
cr & crActionPlan . apAction %~ replaceNullWith (PathTo p)
& crActionPlan . apStrategy .~ Investigate
Nothing -> cr
@@ -198,8 +207,10 @@ 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