Cleanup, split CWorld into separate file

This commit is contained in:
2022-07-26 21:19:12 +01:00
parent c2707719fb
commit 6554d219dc
27 changed files with 1049 additions and 911 deletions
+108 -84
View File
@@ -1,36 +1,43 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData #-}
--{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE DeriveGeneric #-}
module Dodge.Data.ActionPlan where
import GHC.Generics
import Data.Aeson
import Dodge.Creature.Stance.Data
import Dodge.Data.CreatureEffect
--import Dodge.ShortShow
import Control.Lens
import Data.Aeson
import Dodge.Data.Creature.Stance
import Dodge.Data.CreatureEffect
import GHC.Generics
import Geometry.Data
import Sound.Data
--import GHC.Generics
data ActionPlan
= Inanimate
| ActionPlan
{_apImpulse :: [Impulse]
,_apAction :: [Action]
,_apStrategy :: Strategy
,_apGoal :: [Goal]
{ _apImpulse :: [Impulse]
, _apAction :: [Action]
, _apStrategy :: Strategy
, _apGoal :: [Goal]
}
deriving (Eq,Ord,Show,Read,Generic)
deriving (Eq, Ord, Show, Read, Generic)
instance ToJSON ActionPlan where
toEncoding = genericToEncoding defaultOptions
instance FromJSON ActionPlan
data RandImpulse
data RandImpulse
= RandImpulseList [Impulse]
| RandImpulseCircMove Float
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON RandImpulse where
deriving (Eq, Ord, Show, Read, Generic)
instance ToJSON RandImpulse where
toEncoding = genericToEncoding defaultOptions
instance FromJSON RandImpulse
instance FromJSON RandImpulse
data Impulse
= Move Point2
| MoveForward Float
@@ -50,127 +57,138 @@ data Impulse
| MakeSound SoundID
| ChangeStrategy Strategy
| AddGoal Goal
| ArbitraryImpulseFunction WdCrCr
| ArbitraryImpulse CrWdImp
| ArbitraryImpulseEffect CrWdWd
| ArbitraryImpulseFunction WdCrCr
| ArbitraryImpulse CrWdImp
| ArbitraryImpulseEffect CrWdWd
| ImpulseUseTargetCID
{_impulseUseTargetCID :: IntImp
{ _impulseUseTargetCID :: IntImp
}
| ImpulseUseTarget
{_impulseUseTarget :: CrImp
{ _impulseUseTarget :: CrImp
}
| ImpulseUseAheadPos
{_impulseUseAheadPos :: P2Imp
{ _impulseUseAheadPos :: P2Imp
}
| ImpulseNothing
deriving (Eq,Ord,Show,Read,Generic)
deriving (Eq, Ord, Show, Read, Generic)
instance ToJSON Impulse where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Impulse
infixr 9 `WaitThen`
infixr 9 `DoActionThen`
infixr 9 `DoActionWhile`
infixr 9 `DoReplicate`
infixr 9 `DoImpulsesAlongside`
data Action
= LabelAction
{_actLabel :: String
,_actAction :: Action
{ _actLabel :: String
, _actAction :: Action
}
| ActionNothing
| AimAt
{_targetID :: Int
,_targetSeenAt :: Point2
{ _targetID :: Int
, _targetSeenAt :: Point2
}
| PathTo
{_pathToPoint :: Point2
| PathTo
{ _pathToPoint :: Point2
}
| TurnToPoint
{_turnToPoint :: Point2
{ _turnToPoint :: Point2
}
-- | PickupItem
-- {_pickupItemID :: Int
-- }
| ImpulsesList
{_impulsesListList :: [[Impulse]]
| -- | PickupItem
-- {_pickupItemID :: Int
-- }
ImpulsesList
{ _impulsesListList :: [[Impulse]]
}
| DoImpulses
{_doImpulsesList :: [Impulse]
| DoImpulses
{ _doImpulsesList :: [Impulse]
}
| WaitThen
{_waitThenTimer :: Int
,_waitThenAction :: Action
| WaitThen
{ _waitThenTimer :: Int
, _waitThenAction :: Action
}
| DoActionWhile
{_doActionWhileCondition :: WdCrBl
,_doActionWhileAction :: Action
| DoActionWhile
{ _doActionWhileCondition :: WdCrBl
, _doActionWhileAction :: Action
}
| DoActionWhilePartial
{_doActionWhilePartial :: Action
,_doActionWhileCondition :: WdCrBl
,_doActionWhileAction :: Action
{ _doActionWhilePartial :: Action
, _doActionWhileCondition :: WdCrBl
, _doActionWhileAction :: Action
}
| DoActionIf
{_doActionIfCondition :: WdCrBl
,_doActionIfAction :: Action
{ _doActionIfCondition :: WdCrBl
, _doActionIfAction :: Action
}
| DoActionIfElse
{_doActionIfElseIfAction :: Action
,_doActionIfElseCondition :: WdCrBl
,_doActionIfElseElseAction :: Action
| DoActionIfElse
{ _doActionIfElseIfAction :: Action
, _doActionIfElseCondition :: WdCrBl
, _doActionIfElseElseAction :: Action
}
| DoActionWhileInterrupt
{_doActionWhileThenDo :: Action
,_doActionWhileThenCondition :: WdCrBl
,_doActionWhileThenThen :: Action
| DoActionWhileInterrupt
{ _doActionWhileThenDo :: Action
, _doActionWhileThenCondition :: WdCrBl
, _doActionWhileThenThen :: Action
}
| DoActions
{_doActionsList :: [Action]
| DoActions
{ _doActionsList :: [Action]
}
| DoActionThen
{_doActionThenFirst :: Action
,_doActionThenSecond :: Action
| DoActionThen
{ _doActionThenFirst :: Action
, _doActionThenSecond :: Action
}
-- | DoGuardActions
-- {_doGuardActionsList :: [( (World, Creature) -> Bool, Action, Maybe Action)]
-- }
| DoReplicate
{_doReplicateTimes :: Int
,_doReplicateAction :: Action
| -- | DoGuardActions
-- {_doGuardActionsList :: [( (World, Creature) -> Bool, Action, Maybe Action)]
-- }
DoReplicate
{ _doReplicateTimes :: Int
, _doReplicateAction :: Action
}
| DoReplicatePartial
{_partialAction :: Action
,_doReplicateTimes :: Int
,_doReplicateAction :: Action
{ _partialAction :: Action
, _doReplicateTimes :: Int
, _doReplicateAction :: Action
}
| LeadTarget
{_leadTargetBy :: Point2
{ _leadTargetBy :: Point2
}
| NoAction
| StartSentinelPost
| UseTarget
{_useTarget :: MCrAc
{ _useTarget :: MCrAc
}
| UseSelf
{_useSelf :: CrAc
{ _useSelf :: CrAc
}
| UseAheadPos
{_useAheadPos :: P2Ac
{ _useAheadPos :: P2Ac
}
| UseMvTargetPos
{_useMvTargetPos :: MP2Ac
{ _useMvTargetPos :: MP2Ac
}
| ArbitraryAction
{ _arbitraryAction :: CrWdAc }
| DoImpulsesAlongside
-- ^ Repeatedly perform impulses alongside a main action until the main action terminates
{_sideImpulses :: [Impulse]
,_mainAction :: Action
{_arbitraryAction :: CrWdAc}
| -- | Repeatedly perform impulses alongside a main action until the main action terminates
DoImpulsesAlongside
{ _sideImpulses :: [Impulse]
, _mainAction :: Action
}
deriving (Eq,Ord,Show,Read,Generic)
deriving (Eq, Ord, Show, Read, Generic)
instance ToJSON Action where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Action
data Strategy
= Flank Int
| Ambush Int
@@ -187,18 +205,24 @@ data Strategy
| Reload
| Flee
| MeleeStrike
deriving (Eq,Ord,Show,Read,Generic)
deriving (Eq, Ord, Show, Read, Generic)
instance ToJSON Strategy where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Strategy
data Goal
= LiveLongAndProsper
| Kill Int
| SentinelAt Point2 Float
deriving (Eq,Ord,Show,Read,Generic)
deriving (Eq, Ord, Show, Read, Generic)
instance ToJSON Goal where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Goal
makeLenses ''ActionPlan
makeLenses ''Impulse
makeLenses ''Action