Files
loop/src/Dodge/Data/ActionPlan.hs
T

170 lines
4.4 KiB
Haskell

{-# 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
| MoveNoStride Point2
| 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
| ImpulseUseTarget { _impulseUseTarget :: CrImp }
| ImpulseNothing
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
= AimAt
{ _targetID :: Int
, _targetSeenAt :: Point2
}
| PathTo { _pathToPoint :: Point2, _pathFailAction :: Action }
| TurnToPoint { _turnToPoint :: Point2 }
| 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
}
| DoReplicate
{ _doReplicateTimes :: Int
, _doReplicateAction :: Action
}
| DoReplicatePartial
{ _partialAction :: Action
, _doReplicateTimes :: Int
, _doReplicateAction :: Action
}
| LeadTarget { _leadTargetBy :: Point2 }
| NoAction
| StartSentinelPost
| UseSelf { _useSelf :: CrAc }
| 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
| Wander
| CloseToMelee {_meleeTarget :: Int}
| StrategyActions Strategy [Action]
| GetTo Point2
| Reload
| Flee
| MeleeStrike
| Search
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
]
makeLenses ''ActionPlan
makeLenses ''Impulse
makeLenses ''Action
makeLenses ''Strategy