This commit is contained in:
2021-05-05 17:36:10 +02:00
parent f0e5095b5f
commit 05086d6f4a
29 changed files with 760 additions and 766 deletions
+11
View File
@@ -0,0 +1,11 @@
module Dodge.Creature.AI
where
import Dodge.Data
import Control.Lens
import System.Random
insectAI
:: ( World -> StdGen -> Creature -> (World -> World, StdGen, Creature) )
-> World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature)
insectAI = undefined
+12
View File
@@ -0,0 +1,12 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
module Dodge.Creature.AI.Data
where
import Dodge.Creature.State.Data
import Dodge.Creature.Impulse.Data
import Control.Lens
data Intelligence
= Zombie { _crImpulse :: Impulse }
| Inanimate
+13 -1
View File
@@ -9,8 +9,10 @@ module Dodge.Creature.Action
where
import Dodge.Creature.Action.UseItem
import Dodge.Creature.Action.Movement
import Dodge.Creature.Stance.Data
import Dodge.Creature.State.Data
import Dodge.WorldEvent.Shockwave
import Dodge.Data
import Dodge.Data hiding (carriage)
import Dodge.Base
import Dodge.SoundLogic
import Dodge.WorldEvent
@@ -176,6 +178,16 @@ crTurnTo
crTurnTo p cr = set crDir dirToTarget cr
where dirToTarget = argV (p -.- _crPos cr)
crRandomTurn
:: RandomGen g
=> Float -- ^ Max possible angle, supposed to be positive
-> Creature
-> g
-> (Creature, g)
crRandomTurn a cr g =
let (r, g') = randomR (negate a, a) g
in (cr & crDir +~ r, g')
crTurnTowardSpeed
:: Float -- ^ Turn speed
-> Point2 -- ^ Target position
+58
View File
@@ -0,0 +1,58 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
module Dodge.Creature.Impulse.Data
where
import Dodge.Creature.Stance.Data
import Geometry.Data
import Control.Lens
data Impulse
= MoveTo Point2
| MoveToFor Point2 Int
| MoveFire Point2 Point2
| PathTo Point2
| PathAlong [Point2]
| SubPathTo Point2 Int Point2
| Wait
| WaitFor Int
| WaitForID Int Int
| FireAt Point2
| FireAtID Int Point2
| Fire
| Reload
| IncreaseAlert Int
| Guard Point2 Point2
| Search Int
| SearchNear Point2
| AimAt Point2 Int
| InitGuard
| Init
| MeleeAttack Int
| InitTrackYou
| TrackYou
| Track Int
| TrackFor Int Int
| TurnByFor Float Int
| TurnTo Point2
| TurnToward Point2
| TurnTowardAngle Float
| StrafeLeftAround Int Point2
| StrafeRightAround Int Point2
| StrafeLeftFor Int
| StrafeRightFor Int
| StrafeLeftForSpeed Int Float
| StrafeRightForSpeed Int Float
| StrafeLeftFire
| StrafeRightFire
| MoveForwardFor Int
| MoveForwardFire
| MoveBackwardFor Int
| MoveByFor Point2 Int
| MoveBackwardFire
| ImpulseID Int Impulse
| AtRange Float
| AtRanges Float Float
| RepeatAction Int Impulse
| MakeJudgement
| SetPosture Posture
deriving (Eq,Show)
+3
View File
@@ -4,6 +4,9 @@ Inanimate objects such as lamps, barrels, etc
module Dodge.Creature.Inanimate
where
import Dodge.Data
import Dodge.Creature.Stance.Data
import Dodge.Creature.State.Data
import Dodge.Creature.Impulse.Data
import Dodge.Base
import Dodge.Picture.Layer
import Dodge.Default
+1
View File
@@ -6,6 +6,7 @@ module Dodge.Creature.Picture
, circLine
) where
import Dodge.Data
import Dodge.Creature.State.Data
import Dodge.Picture.Layer
import Picture
import Geometry
+25
View File
@@ -0,0 +1,25 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
module Dodge.Creature.Stance.Data
where
import Geometry.Data
import Control.Lens
data Stance = Stance
{_carriage :: Carriage
,_posture :: Posture
}
deriving (Eq,Show)
data Carriage
= Walking { _stepCycle :: Int, _stepToAdd :: Int }
| Standing
| Floating
| Flying
| Boosting Point2
deriving (Eq,Show)
data Posture = Aiming | AtEase
deriving (Eq,Show)
makeLenses ''Stance
makeLenses ''Carriage
makeLenses ''Posture
+3
View File
@@ -1,5 +1,8 @@
module Dodge.Creature.State where
import Dodge.Data
import Dodge.Creature.State.Data
import Dodge.Creature.Stance.Data
import Dodge.Data
import Dodge.Base
import Dodge.SoundLogic
import Dodge.RandomHelp
+5 -70
View File
@@ -4,11 +4,13 @@ module Dodge.Creature.State.Data
where
import Geometry
import Dodge.Data.DamageType
import Dodge.Creature.Impulse.Data
import Dodge.Creature.Stance.Data
import Control.Lens
data CreatureState = CrSt
{ _goals :: [[Goal]]
{ _goals :: [[Impulse]]
, _stance :: Stance
, _faction :: Faction
, _crDamage :: [DamageType]
@@ -27,72 +29,7 @@ data CrSpState
= Barrel { _piercedPoints :: [Point2]}
| GenCr
deriving (Eq,Show,Ord)
data Goal
= MoveTo Point2
| MoveToFor Point2 Int
| MoveFire Point2 Point2
| PathTo Point2
| PathAlong [Point2]
| SubPathTo Point2 Int Point2
| Wait
| WaitFor Int
| WaitForID Int Int
| FireAt Point2
| FireAtID Int Point2
| Fire
| Reload
| IncreaseAlert Int
| Guard Point2 Point2
| Search Int
| SearchNear Point2
| AimAt Point2 Int
| InitGuard
| Init
| MeleeAttack Int
| InitTrackYou
| TrackYou
| Track Int
| TrackFor Int Int
| TurnByFor Float Int
| TurnTo Point2
| TurnToward Point2
| TurnTowardAngle Float
| StrafeLeftAround Int Point2
| StrafeRightAround Int Point2
| StrafeLeftFor Int
| StrafeRightFor Int
| StrafeLeftForSpeed Int Float
| StrafeRightForSpeed Int Float
| StrafeLeftFire
| StrafeRightFire
| MoveForwardFor Int
| MoveForwardFire
| MoveBackwardFor Int
| MoveByFor Point2 Int
| MoveBackwardFire
| GoalID Int Goal
| AtRange Float
| AtRanges Float Float
| RepeatAction Int Goal
| MakeJudgement
| SetPosture Posture
deriving (Eq,Show)
data Stance = Stance
{_carriage :: Carriage
,_posture :: Posture
}
deriving (Eq,Show)
data Carriage
= Walking { _stepCycle :: Int, _stepToAdd :: Int }
| Standing
| Floating
| Flying
| Boosting Point2
deriving (Eq,Show)
data Posture = Aiming | AtEase
deriving (Eq,Show)
data Mind = ZombieMind | HumanMind
deriving (Eq,Show)
data Faction
= GenericFaction Int
| ZombieFaction
@@ -104,6 +41,4 @@ data Faction
makeLenses ''CreatureState
makeLenses ''CrSpState
makeLenses ''Goal
makeLenses ''Carriage
makeLenses ''Posture
makeLenses ''Impulse
+2
View File
@@ -4,6 +4,8 @@ import Dodge.Data
import Dodge.Base
import Dodge.Creature.Action
import Dodge.Creature.State
import Dodge.Creature.State.Data
import Dodge.Creature.Stance.Data
import Dodge.Update.UsingInput
import Dodge.Config.KeyConfig
import Dodge.Item.Attachment.Data