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
+5 -4
View File
@@ -21,6 +21,7 @@ module Dodge.Creature.Action
)
where
import Dodge.Inventory.Add
import Dodge.CreatureEffect
--import Dodge.ShortShow
import Dodge.Path
import Dodge.Default
@@ -111,18 +112,18 @@ performAction cr w ac = case ac of
(imps , Nothing ) -> (imps, Just afta)
DoActionWhile f act -> performAction cr w $ DoActionWhilePartial act f act
DoActionWhilePartial partAc f resetAc
| f w cr -> case performAction cr w partAc of
| doWdCrBl f w cr -> case performAction cr w partAc of
(imps, Just nxta) -> (imps, Just $ DoActionWhilePartial nxta f resetAc)
(imps, Nothing) -> (imps, Just $ DoActionWhilePartial resetAc f resetAc)
| otherwise -> performAction cr w partAc
DoActionIf f ifa
| f w cr -> performAction cr w ifa
| doWdCrBl f w cr -> performAction cr w ifa
| otherwise -> ([],Nothing)
DoActionIfElse ifa f elsea
| f w cr -> performAction cr w ifa
| doWdCrBl f w cr -> performAction cr w ifa
| otherwise -> performAction cr w elsea
DoActionWhileInterrupt repa f afta
| f w cr -> (fst $ performAction cr w repa, Just $ DoActionWhileInterrupt repa f afta)
| doWdCrBl f w cr -> (fst $ performAction cr w repa, Just $ DoActionWhileInterrupt repa f afta)
| otherwise -> performAction cr w afta
DoActions [] -> ([], Nothing)
DoActions acs ->
+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
+1 -1
View File
@@ -144,7 +144,7 @@ reloadOverride cr
reloadActions =
[ holsterWeapon
, 1 `WaitThen`
DoActionWhileInterrupt NoAction (const crIsReloading)
DoActionWhileInterrupt NoAction (WdCrBlfromCrBl CrIsReloading)
(DoImpulses [ChangeStrategy WatchAndWait])
]
+3 -3
View File
@@ -23,7 +23,7 @@ sentinelAI w = reloadOverride .
[ (crHasTargetLOS
, \ _ cr -> StrategyActions (ShootAt (fromJust $ tcid cr))
[ DoActionIf
(const $ not . crIsAiming)
(WdCrNegate $ WdCrBlfromCrBl CrIsAiming)
(drawWeapon `DoActionThen` (50 `WaitThen` NoAction))
`DoActionThen` lostest
`DoActionWhile` advanceShoot
@@ -38,7 +38,7 @@ sentinelAI w = reloadOverride .
where
advanceShoot = DoImpulses [UseItem, MoveForward 3]
tcid cr = _crID <$> _targetCr (_crIntention cr)
lostest w' cr = maybe False (\cid -> canSee (_crID cr) cid w') (tcid cr)
lostest = WdCrLOSTarget -- w' cr = maybe False (\cid -> canSee (_crID cr) cid w') (tcid cr)
--chainCreatureUpdates :: [World -> Creature -> Creature] -> World -> Creature -> Creature
--chainCreatureUpdates ls w cr = foldr (\f -> f w) cr ls
@@ -65,7 +65,7 @@ sentinelFireType f = chainCreatureUpdates
(crActionPlan . apStrategy .~ WatchAndWait)
]
where
drawwp = DoActionIfElse NoAction (const crIsAiming) (DoActionThen drawWeapon (WaitThen 50 NoAction))
drawwp = DoActionIfElse NoAction (WdCrBlfromCrBl CrIsAiming) (DoActionThen drawWeapon (WaitThen 50 NoAction))
aiming = AimAt
{ _targetID = 0
, _targetSeenAt = V2 0 0 -- hack
+2 -2
View File
@@ -23,7 +23,7 @@ fleeFrom cr mtcr = case mtcr of
shootTillEmpty :: Action
--shootTillEmpty = (crCanShoot `DoActionWhile` DoImpulses [UseItem])
shootTillEmpty = (const crCanShoot `DoActionWhile` DoImpulses [UseItem])
shootTillEmpty = (WdCrBlfromCrBl CrCanShoot `DoActionWhile` DoImpulses [UseItem])
`DoActionThen` 20 `WaitThen` holsterWeapon
--advanceShoot :: Int -> Action
@@ -39,5 +39,5 @@ shootFirstMiss :: Action
shootFirstMiss =
LeadTarget (V2 30 50) `DoActionThen`
DoImpulses [UseItem] `DoActionThen`
(const crCanShoot `DoActionWhile` DoActions [LeadTarget (V2 0 0),DoImpulses [UseItem]])
(WdCrBlfromCrBl CrCanShoot `DoActionWhile` DoActions [LeadTarget (V2 0 0),DoImpulses [UseItem]])
`DoActionThen` 20 `WaitThen` holsterWeapon
+16 -11
View File
@@ -10,6 +10,7 @@ circular imports are probably not a good idea.
{-# LANGUAGE DerivingStrategies #-}
module Dodge.Data
( module Dodge.Data
, module Dodge.Data.CreatureEffect
, module Dodge.Data.WorldEffect
, module Dodge.Data.Button
, module Dodge.Data.Item.Params
@@ -70,6 +71,7 @@ module Dodge.Data
, module Dodge.Data.RadarBlip
, module Dodge.Data.PathGraph
) where
import Dodge.Data.CreatureEffect
import Dodge.Data.WorldEffect
import Dodge.Data.Button
import Dodge.Data.Item.Params
@@ -668,6 +670,7 @@ data ActionPlan
,_apStrategy :: Strategy
,_apGoal :: [Goal]
}
data RandImpulse = RandImpulseList [Impulse]
data Impulse
= Move Point2
| MoveForward Float
@@ -687,18 +690,19 @@ data Impulse
| MakeSound SoundID
| ChangeStrategy Strategy
| AddGoal Goal
| ArbitraryImpulseFunction (World -> Creature -> Creature)
| ArbitraryImpulse (Creature -> World -> Impulse)
| ArbitraryImpulseEffect (Creature -> World -> World)
| ArbitraryImpulseFunction WdCrCr
| ArbitraryImpulse CrWdImp
| ArbitraryImpulseEffect CrWdWd
| ImpulseUseTargetCID
{_impulseUseTargetCID :: Int -> Impulse
{_impulseUseTargetCID :: IntImp
}
| ImpulseUseTarget
{_impulseUseTarget :: Creature -> Impulse
{_impulseUseTarget :: CrImp
}
| ImpulseUseAheadPos
{_impulseUseAheadPos :: Point2 -> Impulse
{_impulseUseAheadPos :: P2Imp
}
| ImpulseNothing
instance Show Impulse where
show imp = case imp of
Move p -> "Move "++shortPoint2 p
@@ -725,6 +729,7 @@ instance Show Impulse where
ImpulseUseTarget {} -> "ImpulseUseTarget"
ImpulseUseAheadPos {} -> "ImpulseUseAheadPos"
RandomImpulse {} -> "RandomImpulse"
ImpulseNothing -> "ImpulseNothing"
-- deriving (Eq,Ord,Show)
infixr 9 `WaitThen`
infixr 9 `DoActionThen`
@@ -760,26 +765,26 @@ data Action
,_waitThenAction :: Action
}
| DoActionWhile
{_doActionWhileCondition :: World -> Creature -> Bool
{_doActionWhileCondition :: WdCrBl
,_doActionWhileAction :: Action
}
| DoActionWhilePartial
{_doActionWhilePartial :: Action
,_doActionWhileCondition :: World -> Creature -> Bool
,_doActionWhileCondition :: WdCrBl
,_doActionWhileAction :: Action
}
| DoActionIf
{_doActionIfCondition :: World -> Creature -> Bool
{_doActionIfCondition :: WdCrBl
,_doActionIfAction :: Action
}
| DoActionIfElse
{_doActionIfElseIfAction :: Action
,_doActionIfElseCondition :: World -> Creature -> Bool
,_doActionIfElseCondition :: WdCrBl
,_doActionIfElseElseAction :: Action
}
| DoActionWhileInterrupt
{_doActionWhileThenDo :: Action
,_doActionWhileThenCondition :: World -> Creature -> Bool
,_doActionWhileThenCondition :: WdCrBl
,_doActionWhileThenThen :: Action
}
| DoActions
+10 -9
View File
@@ -37,9 +37,9 @@ updateHumanoid cr = case cr ^?! crType . humanoidAI of
[performActions
,watchUpdateStrat
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
[DoActionIf (const $ not . crIsAiming) drawWeapon
[DoActionIf (WdCrNegate $ WdCrBlfromCrBl CrIsAiming) drawWeapon
,DoActionThen
(DoActionWhile crHasTargetLOS $ ArbitraryAction chooseMovementSpreadGun)
(DoActionWhile WdCrLOSTarget $ ArbitraryAction chooseMovementSpreadGun)
(DoImpulses [ChangeStrategy WatchAndWait])
]
)
@@ -57,7 +57,7 @@ updateHumanoid cr = case cr ^?! crType . humanoidAI of
[ performActions
, watchUpdateStrat
[ (crHasTargetLOS, \w cr' -> StrategyActions (ShootAt 0)
[DoActionIf (const $ not . crIsAiming) drawWeapon,chooseMovementPistol cr' w])
[DoActionIf (WdCrNegate $ WdCrBlfromCrBl CrIsAiming) drawWeapon,chooseMovementPistol cr' w])
, (const crAwayFromPost, const goToPostStrat)
]
, perceptionUpdate [0]
@@ -72,9 +72,9 @@ updateHumanoid cr = case cr ^?! crType . humanoidAI of
[ performActions
, watchUpdateStrat
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
[DoActionIf (const $ not . crIsAiming) drawWeapon
[DoActionIf (WdCrNegate $ WdCrBlfromCrBl CrIsAiming) drawWeapon
,DoActionThen
(DoActionWhile crHasTargetLOS $ ArbitraryAction chooseMovementLtAuto)
(DoActionWhile WdCrLOSTarget $ ArbitraryAction chooseMovementLtAuto)
(DoImpulses [ChangeStrategy WatchAndWait])
]
)
@@ -130,7 +130,7 @@ updateHumanoid cr = case cr ^?! crType . humanoidAI of
)
, (const $ not . crSafeDistFromTarg 150
, \_ cr' -> StrategyActions Flee
[const (not . crSafeDistFromTarg 150) `DoActionWhile` UseTarget (fleeFrom cr')
[WdCrNegate (WdCrSafeDistFromTarget 150) `DoActionWhile` UseTarget (fleeFrom cr')
`DoActionThen` DoImpulses [ChangeStrategy WatchAndWait] ]
)
, (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
@@ -141,10 +141,10 @@ updateHumanoid cr = case cr ^?! crType . humanoidAI of
YourAI -> stateUpdate yourControl cr
InanimateAI -> id
where
drawwp = DoActionIfElse NoAction (const crIsAiming) (DoActionThen drawWeapon (WaitThen 50 NoAction))
drawwp = DoActionIfElse NoAction (WdCrBlfromCrBl CrIsAiming) (DoActionThen drawWeapon (WaitThen 50 NoAction))
reloadActions =
[ holsterWeapon
, WaitThen 1 $ DoActionWhileInterrupt NoAction (const crIsReloading) (DoImpulses [ChangeStrategy WatchAndWait])
, WaitThen 1 $ DoActionWhileInterrupt NoAction (WdCrBlfromCrBl CrIsReloading) (DoImpulses [ChangeStrategy WatchAndWait])
]
-- bit of a hack to get new random generators after each creature's update
defaultImpulsive :: [World -> Creature -> Creature]
@@ -268,7 +268,8 @@ retreatFireLauncher = ImpulsesList ( [ UseItem ] : replicate 20 [ Turn 0.16 ])
drawWeapon
`DoActionThen`
ImpulsesList (
replicate 100 [UseItem, ImpulseUseTarget $ \tcr -> TurnToward (_crPos tcr) (pi/16) ] )
replicate 100 [UseItem, ImpulseUseTarget (TurnTowardCr (pi/16)) -- $ \tcr -> TurnToward (_crPos tcr) (pi/16) ] )
])
`DoActionThen`
20
`WaitThen`