ActionPlan refactor
This commit is contained in:
@@ -100,6 +100,7 @@ performTurnToA cr p
|
||||
-- doAction -}
|
||||
performAction :: Creature -> World -> Action -> OutAction
|
||||
performAction cr w ac = case ac of
|
||||
ActionNothing -> ([],Nothing)
|
||||
LabelAction str subAc -> second (fmap (LabelAction str)) $ performAction cr w subAc
|
||||
AimAt tcid p -> performAimAt cr w tcid p
|
||||
WaitThen 0 newAc -> ([] , Just newAc)
|
||||
@@ -135,11 +136,11 @@ performAction cr w ac = case ac of
|
||||
LeadTarget p -> case cr ^? crIntention . targetCr . _Just of
|
||||
Just tcr -> ([TurnTo (_crPos tcr +.+ rotateV (_crDir tcr) p)], Nothing)
|
||||
_ -> ([], Nothing)
|
||||
UseTarget f -> performAction cr w $ f $ cr ^? crIntention . targetCr . _Just
|
||||
UseSelf f -> performAction cr w $ f cr
|
||||
UseAheadPos f -> performAction cr w (f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
|
||||
UseMvTargetPos f -> performAction cr w $ f $ _mvToPoint $ _crIntention cr
|
||||
ArbitraryAction f -> performAction cr w (f cr w)
|
||||
UseTarget f -> performAction cr w $ doMCrAc f $ cr ^? crIntention . targetCr . _Just
|
||||
UseSelf f -> performAction cr w $ doCrAc f cr
|
||||
UseAheadPos f -> performAction cr w (doP2Ac f (_crPos cr +.+ 20 *.* unitVectorAtAngle (_crDir cr)))
|
||||
UseMvTargetPos f -> performAction cr w $ doMP2Ac f $ _mvToPoint $ _crIntention cr
|
||||
ArbitraryAction f -> performAction cr w (doCrWdAc f cr w)
|
||||
DoImpulsesAlongside sideImp mainAc -> case performAction cr w mainAc of
|
||||
(imp, Just nxtac) -> (sideImp ++ imp, Just $ DoImpulsesAlongside sideImp nxtac)
|
||||
(imp, _) -> (sideImp ++ imp, Nothing)
|
||||
|
||||
@@ -15,11 +15,9 @@ module Dodge.Creature.ReaderUpdate
|
||||
, setViewPos
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.Volition
|
||||
import Dodge.Base
|
||||
import Dodge.Zone
|
||||
import Dodge.Path
|
||||
import Geometry
|
||||
|
||||
import qualified IntMapHelp as IM
|
||||
@@ -106,7 +104,7 @@ goToTarget w cr =
|
||||
_ -> viewTarget w cr
|
||||
|
||||
lookAroundSelf :: Action
|
||||
lookAroundSelf = UseSelf $ \cr -> TurnToPoint (_crPos cr -.- 10 *.* unitVectorAtAngle (_crDir cr))
|
||||
lookAroundSelf = UseSelf CrTurnAround -- $ \cr -> TurnToPoint (_crPos cr -.- 10 *.* unitVectorAtAngle (_crDir cr))
|
||||
|
||||
viewTarget :: World -> Creature -> Creature
|
||||
viewTarget w cr = do
|
||||
@@ -188,12 +186,13 @@ searchIfDamaged cr
|
||||
| otherwise = cr
|
||||
|
||||
bfsThenReturn :: Int -> Action
|
||||
bfsThenReturn t = ArbitraryAction theaction
|
||||
where
|
||||
theaction cr w = fromMaybe NoAction $ do
|
||||
n <- walkableNodeNear w (_crPos cr)
|
||||
let as = take 20 $ map PathTo $ bfsNodePoints n w
|
||||
return $ DoReplicate t $
|
||||
foldr DoActionThen NoAction as
|
||||
bfsThenReturn t = ArbitraryAction (CrWdBFSThenReturn t)
|
||||
-- theaction
|
||||
-- where
|
||||
-- theaction cr w = fromMaybe NoAction $ do
|
||||
-- n <- walkableNodeNear w (_crPos cr)
|
||||
-- let as = take 20 $ map PathTo $ bfsNodePoints n w
|
||||
-- return $ DoReplicate t $
|
||||
-- foldr DoActionThen NoAction as
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ module Dodge.Creature.SentinelAI
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.ChainUpdates
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.Volition
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
|
||||
@@ -3,12 +3,10 @@ module Dodge.Creature.Volition
|
||||
( holsterWeapon
|
||||
, drawWeapon
|
||||
, shootTillEmpty
|
||||
, fleeFrom
|
||||
-- , fleeFrom
|
||||
, shootFirstMiss
|
||||
) where
|
||||
import Dodge.Data
|
||||
--import Dodge.Base.Collide
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.SoundLogic.LoadSound
|
||||
import Geometry
|
||||
|
||||
@@ -16,10 +14,6 @@ holsterWeapon, drawWeapon :: Action
|
||||
holsterWeapon = DoImpulses [ChangePosture AtEase, MakeSound whiteNoiseFadeOutS]
|
||||
drawWeapon = DoImpulses [ChangePosture Aiming, MakeSound whiteNoiseFadeInS]
|
||||
|
||||
fleeFrom :: Creature -> Maybe Creature -> Action
|
||||
fleeFrom cr mtcr = case mtcr of
|
||||
Just tcr -> DoImpulses [MoveForward 3, TurnToward ((2 *.* _crPos cr) -.- _crPos tcr) (pi/4)]
|
||||
Nothing -> NoAction
|
||||
|
||||
shootTillEmpty :: Action
|
||||
--shootTillEmpty = (crCanShoot `DoActionWhile` DoImpulses [UseItem])
|
||||
|
||||
Reference in New Issue
Block a user