Dataify impulse/action/strategy function fields

This commit is contained in:
2022-07-21 21:45:31 +01:00
parent 14f3c8bc52
commit 583027112d
7 changed files with 45 additions and 36 deletions
+8 -6
View File
@@ -4,6 +4,7 @@ module Dodge.Creature.Impulse
, followThenClearImpulses
) where
import Dodge.Data
import Dodge.CreatureEffect
import Dodge.Creature.Vocalization
import Dodge.Creature.Impulse.Movement
import Dodge.Creature.Impulse.UseItem
@@ -50,6 +51,7 @@ followImpulses w cr = foldr f (id, cr) (_apImpulse $ _crActionPlan cr)
followImpulse :: Creature -> World -> Impulse -> (World -> World , Creature)
followImpulse cr w imp = case imp of
ImpulseNothing -> (id,cr)
RandomImpulse rimp ->
let (newimp,newgen) = runState rimp (_randGen w)
in first ((randGen .~ newgen) .) $ followImpulse cr w newimp
@@ -69,16 +71,16 @@ followImpulse cr w imp = case imp of
DropItem -> undefined
ChangeStrategy strat -> crup $ cr & crActionPlan . apStrategy .~ strat
AddGoal gl -> crup $ cr & crActionPlan . apGoal .:~ gl
ArbitraryImpulseFunction f -> crup $ f w cr
ArbitraryImpulse f -> followImpulse cr w (f cr w)
ArbitraryImpulseEffect f -> (f cr, cr)
ArbitraryImpulseFunction f -> crup $ doWdCrCr f w cr
ArbitraryImpulse f -> followImpulse cr w (doCrWdImp f cr w)
ArbitraryImpulseEffect f -> (doCrWdWd f cr, cr)
ImpulseUseTargetCID f -> case cr ^? crIntention . targetCr . _Just of
Just tcr -> followImpulse cr w (f $ _crID tcr)
Just tcr -> followImpulse cr w (doIntImp f $ _crID tcr)
_ -> crup cr
ImpulseUseTarget f -> case cr ^? crIntention . targetCr . _Just of
Just tcr -> followImpulse cr w (f tcr)
Just tcr -> followImpulse cr w (doCrImp f tcr)
_ -> crup cr
ImpulseUseAheadPos f -> followImpulse cr w (f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
ImpulseUseAheadPos f -> followImpulse cr w (doP2Imp f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
MvForward -> crup $ crMvForward speed cr
MvTurnToward p -> crup
$ creatureTurnToward p (turnRad $ safeAngleVV (p -.- cpos) (unitVectorAtAngle cdir)) cr