306 lines
9.1 KiB
Haskell
306 lines
9.1 KiB
Haskell
{-# LANGUAGE TemplateHaskell #-}
|
|
{-# LANGUAGE StrictData #-}
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
module Dodge.Data.ActionPlan where
|
|
import Dodge.Creature.Stance.Data
|
|
import Dodge.Data.CreatureEffect
|
|
import Dodge.ShortShow
|
|
import Control.Lens
|
|
import Geometry.Data
|
|
import Control.Monad.State
|
|
import System.Random
|
|
import Sound.Data
|
|
import GHC.Generics
|
|
data ActionPlan
|
|
= Inanimate
|
|
| ActionPlan
|
|
{_apImpulse :: [Impulse]
|
|
,_apAction :: [Action]
|
|
,_apStrategy :: Strategy
|
|
,_apGoal :: [Goal]
|
|
}
|
|
data RandImpulse = RandImpulseList [Impulse]
|
|
data Impulse
|
|
= Move Point2
|
|
| MoveForward Float
|
|
| Turn Float
|
|
| RandomTurn Float
|
|
| RandomImpulse (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
|
|
instance Show Impulse where
|
|
show imp = case imp of
|
|
Move p -> "Move "++shortPoint2 p
|
|
MoveForward f -> "MoveForward "++ show f
|
|
Turn f -> "Turn "++show f
|
|
RandomTurn f -> "RandomTurn "++show f
|
|
TurnToward p f -> "TurnToward "++shortPoint2 p++show f
|
|
MvTurnToward p -> "MvTurnToward "++shortPoint2 p
|
|
MvForward -> "MvForward"
|
|
TurnTo p -> "TurnTo "++shortPoint2 p
|
|
UseItem -> "UseItem"
|
|
SwitchToItem i -> "SwitchToItem "++show i
|
|
DropItem -> "DropItem"
|
|
Bark sid -> "Bark "++show sid
|
|
Melee i -> "Melee "++show i
|
|
ChangePosture post -> "ChangePosture " ++ show post
|
|
MakeSound sid -> "MakeSound " ++ show sid
|
|
ChangeStrategy s -> "ChangeStrategy " ++ show s
|
|
AddGoal g -> "AddGoal " ++ show g
|
|
ArbitraryImpulseFunction {} -> "ArbitraryImpulseFunction"
|
|
ArbitraryImpulse {} -> "ArbitraryImpulse"
|
|
ArbitraryImpulseEffect {} -> "ArbitraryImpulseEffect"
|
|
ImpulseUseTargetCID {} -> "ImpulseUseTargetCID"
|
|
ImpulseUseTarget {} -> "ImpulseUseTarget"
|
|
ImpulseUseAheadPos {} -> "ImpulseUseAheadPos"
|
|
RandomImpulse {} -> "RandomImpulse"
|
|
ImpulseNothing -> "ImpulseNothing"
|
|
-- deriving (Eq,Ord,Show)
|
|
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 }
|
|
| DoImpulsesAlongside
|
|
-- ^ Repeatedly perform impulses alongside a main action until the main action terminates
|
|
{_sideImpulses :: [Impulse]
|
|
,_mainAction :: Action
|
|
}
|
|
deriving (Generic)
|
|
instance Show Action where
|
|
show act = case act of
|
|
ActionNothing -> "ActionNothing"
|
|
LabelAction
|
|
{_actLabel = str
|
|
,_actAction = subAct
|
|
} -> str++":"++show subAct
|
|
AimAt
|
|
{_targetID = tid
|
|
,_targetSeenAt = p
|
|
} -> "AimAt tid:"++show tid++" seenAt:"++shortPoint2 p
|
|
PathTo
|
|
{_pathToPoint = p
|
|
} -> "PathTo:"++shortPoint2 p
|
|
TurnToPoint
|
|
{_turnToPoint = p
|
|
} -> "TurnToPoint:"++shortPoint2 p
|
|
---- | PickupItem
|
|
---- {_pickupItemID :: Int
|
|
---- }
|
|
ImpulsesList
|
|
{_impulsesListList = iss
|
|
} -> "ImpulsesList:"++show iss
|
|
DoImpulses
|
|
{_doImpulsesList = is
|
|
} -> "DoImpulses:"++show is
|
|
WaitThen
|
|
{_waitThenTimer = i
|
|
,_waitThenAction = a
|
|
} -> "WaitThen timer:"++show i++" act:"++show a
|
|
DoActionWhile
|
|
{_doActionWhileCondition = _
|
|
,_doActionWhileAction = a
|
|
} -> "DoActionWhile (function) act:"++show a
|
|
DoActionWhilePartial
|
|
{_doActionWhilePartial = partact
|
|
,_doActionWhileCondition = _
|
|
,_doActionWhileAction = a
|
|
} -> "DoActionWhilePartial partAct:"++show partact++" resetAct:"++show a
|
|
DoActionIf
|
|
{_doActionIfCondition = _
|
|
,_doActionIfAction = a
|
|
} -> "DoActionIf act:"++show a
|
|
DoActionIfElse
|
|
{_doActionIfElseIfAction = ifa
|
|
,_doActionIfElseCondition = _
|
|
,_doActionIfElseElseAction = elsea
|
|
} -> "DoActionIfElse ifa:"++show ifa++" elsea:"++show elsea
|
|
DoActionWhileInterrupt
|
|
{_doActionWhileThenDo = whilea
|
|
,_doActionWhileThenCondition = _
|
|
,_doActionWhileThenThen = thena
|
|
} -> "DoActionWhileInterrupt whilea:" ++show whilea++" interrupta:"++show thena
|
|
DoActions
|
|
{_doActionsList = as
|
|
} -> "DoActions " ++ foldMap show as
|
|
DoActionThen
|
|
{_doActionThenFirst = a1
|
|
,_doActionThenSecond = a2
|
|
} -> "DoActionThen " ++ show a1 ++ " then:" ++ show a2
|
|
---- | DoGuardActions
|
|
---- {_doGuardActionsList :: [( (World, Creature) -> Bool, Action, Maybe Action)]
|
|
---- }
|
|
DoReplicate
|
|
{_doReplicateTimes = i
|
|
,_doReplicateAction = a
|
|
} -> "DoReplicate times:" ++ show i ++ " act:"++ show a
|
|
DoReplicatePartial
|
|
{_partialAction = pa
|
|
,_doReplicateTimes = i
|
|
,_doReplicateAction = ra
|
|
} -> "DoReplicatePartial pa:" ++ show pa ++ " times:" ++ show i ++ " reset:"++ show ra
|
|
LeadTarget
|
|
{_leadTargetBy = p
|
|
} -> "LeadTarget by:"++ show p
|
|
NoAction -> "NoAction"
|
|
StartSentinelPost -> "StartSentinelPost"
|
|
UseTarget
|
|
{_useTarget = _
|
|
} -> "UseTarget func"
|
|
UseSelf
|
|
{_useSelf = _
|
|
} -> "UseSelf func"
|
|
UseAheadPos
|
|
{_useAheadPos = _
|
|
} -> "UseAheadPos func"
|
|
UseMvTargetPos
|
|
{_useMvTargetPos = _
|
|
} -> "UseMvTargetPos func"
|
|
ArbitraryAction {} -> "ArbitraryAction func"
|
|
DoImpulsesAlongside
|
|
{_sideImpulses = is
|
|
,_mainAction = a
|
|
} -> "DoImpulsesAlongside sideImpulses:"++show is ++ " mainA:"++show a
|
|
|
|
-- deriving (Eq,Ord,Show)
|
|
data Strategy
|
|
= Flank Int
|
|
| Ambush Int
|
|
| Lure Int Point2
|
|
| Patrol [Point2]
|
|
| ShootAt Int
|
|
| FollowImpulses
|
|
| WatchAndWait
|
|
| WarningCry
|
|
| LookAround
|
|
| CloseToMelee Int
|
|
| StrategyActions Strategy [Action]
|
|
| GetTo Point2
|
|
| Reload
|
|
| Flee
|
|
| MeleeStrike
|
|
deriving (Generic,Show)
|
|
-- deriving (Eq,Ord,Show)
|
|
data Goal
|
|
= LiveLongAndProsper
|
|
| Kill Int
|
|
| SentinelAt Point2 Float
|
|
deriving (Show)
|
|
makeLenses ''ActionPlan
|
|
makeLenses ''Impulse
|
|
makeLenses ''Action
|