{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE StrictData #-} {-# LANGUAGE TemplateHaskell #-} module Dodge.Data.ActionPlan where import Control.Lens import Data.Aeson import Data.Aeson.TH import Dodge.Data.Creature.Stance import Dodge.Data.CreatureEffect import Geometry.Data import Sound.Data data ActionPlan = Inanimate | ActionPlan { _apImpulse :: [Impulse] -- done per frame , _apAction :: [Action] -- updated per frame, likely persist across frames , _apStrategy :: Strategy -- current strategy , _apGoal :: [Goal] -- particular ordered goals } --deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show) --Generic, Flat) data Impulse = Move Point2 | MoveForward Float | Turn Float | RandomTurn Float | RandomImpulse RandImpulse -- (State StdGen Impulse) | TurnToward Point2 Float | MvTurnToward Point2 | MvForward | TurnTo Point2 | UseItem | SwitchToItem Int | DropItem | Bark SoundID -- placeholder for various communication types | Melee Int | ChangePosture Posture | MakeSound SoundID | ChangeStrategy Strategy | AddGoal Goal | ArbitraryImpulseFunction WdCrCr | ArbitraryImpulse CrWdImp | ArbitraryImpulseEffect CrWdWd | ImpulseUseTargetCID { _impulseUseTargetCID :: IntImp } | ImpulseUseTarget { _impulseUseTarget :: CrImp } | ImpulseUseAheadPos { _impulseUseAheadPos :: P2Imp } | ImpulseNothing --deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show) --Generic, Flat) data RandImpulse = RandImpulseList [Impulse] | RandImpulseCircMove Float deriving (Eq, Ord, Show) --Generic, Flat) infixr 9 `WaitThen` infixr 9 `DoActionThen` infixr 9 `DoActionWhile` infixr 9 `DoReplicate` infixr 9 `DoImpulsesAlongside` data Action = LabelAction { _actLabel :: String , _actAction :: Action } | ActionNothing | AimAt { _targetID :: Int , _targetSeenAt :: Point2 } | PathTo { _pathToPoint :: Point2 } | TurnToPoint { _turnToPoint :: Point2 } | -- | PickupItem -- {_pickupItemID :: Int -- } ImpulsesList { _impulsesListList :: [[Impulse]] } | DoImpulses { _doImpulsesList :: [Impulse] } | WaitThen { _waitThenTimer :: Int , _waitThenAction :: Action } | DoActionWhile { _doActionWhileCondition :: WdCrBl , _doActionWhileAction :: Action } | DoActionWhilePartial { _doActionWhilePartial :: Action , _doActionWhileCondition :: WdCrBl , _doActionWhileAction :: Action } | DoActionIf { _doActionIfCondition :: WdCrBl , _doActionIfAction :: Action } | DoActionIfElse { _doActionIfElseIfAction :: Action , _doActionIfElseCondition :: WdCrBl , _doActionIfElseElseAction :: Action } | DoActionWhileInterrupt { _doActionWhileThenDo :: Action , _doActionWhileThenCondition :: WdCrBl , _doActionWhileThenThen :: Action } | DoActions { _doActionsList :: [Action] } | DoActionThen { _doActionThenFirst :: Action , _doActionThenSecond :: Action } | -- | DoGuardActions -- {_doGuardActionsList :: [( (World, Creature) -> Bool, Action, Maybe Action)] -- } DoReplicate { _doReplicateTimes :: Int , _doReplicateAction :: Action } | DoReplicatePartial { _partialAction :: Action , _doReplicateTimes :: Int , _doReplicateAction :: Action } | LeadTarget { _leadTargetBy :: Point2 } | NoAction | StartSentinelPost | UseTarget { _useTarget :: MCrAc } | UseSelf { _useSelf :: CrAc } | UseAheadPos { _useAheadPos :: P2Ac } | UseMvTargetPos { _useMvTargetPos :: MP2Ac } | ArbitraryAction {_arbitraryAction :: CrWdAc} | -- | Repeatedly perform impulses alongside a main action until the main action terminates DoImpulsesAlongside { _sideImpulses :: [Impulse] , _mainAction :: Action } deriving (Eq, Ord, Show) --Generic, Flat) --deriving (Eq, Ord, Show, Read) --Generic, Flat) data Strategy = Flank {_flankTarget :: Int} | Ambush {_ambushTarget :: Int} | Lure Int Point2 | Patrol [Point2] | ShootAt Int | FollowImpulses | WatchAndWait | Investigate | WarningCry | LookAround | CloseToMelee {_meleeTarget :: Int} | StrategyActions Strategy [Action] | GetTo Point2 | Reload | Flee | MeleeStrike deriving (Eq, Ord, Show) --Generic, Flat) --deriving (Eq, Ord, Show, Read) --Generic, Flat) data Goal = LiveLongAndProsper | Kill {_killTarget :: Int} | SentinelAt {_sentinelPos :: Point2, _sentinelDir :: Float} deriving (Eq, Ord, Show) --Generic, Flat) --deriving (Eq, Ord, Show, Read) --Generic, Flat) concat <$> mapM (deriveJSON defaultOptions) [ ''Impulse , ''RandImpulse , ''Action , ''Strategy , ''ActionPlan , ''Goal ] --deriveJSON defaultOptions ''Impulse --deriveJSON defaultOptions ''RandImpulse --deriveJSON defaultOptions ''Action --deriveJSON defaultOptions ''Strategy --deriveJSON defaultOptions ''ActionPlan --deriveJSON defaultOptions ''Goal makeLenses ''ActionPlan makeLenses ''Impulse makeLenses ''Action makeLenses ''Strategy