Simplify creature update
This commit is contained in:
@@ -150,7 +150,7 @@ moduleCombinations =
|
||||
, [amod [INCENDIARYMODULE] "+INCENDIARY" (itParams . lasBeam .~ BeamCombine flameBeamCombine)
|
||||
,amod [STATICMODULE] "+STATIC"
|
||||
( (itParams . lasBeam .~ BeamCombine teslaBeamCombine)
|
||||
. (itParams . subParams .~ Just teslaParams)
|
||||
. (itParams . subParams ?~ teslaParams)
|
||||
)
|
||||
,amod [TRANSFORMER] "+SPLIT" (itParams . lasBeam .~ BeamCombine splitBeamCombine)
|
||||
]
|
||||
|
||||
@@ -11,6 +11,7 @@ module Dodge.Creature
|
||||
, smallChaseCrit
|
||||
) where
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Creature.Update
|
||||
--import Dodge.Item.Weapon.Grenade
|
||||
import Dodge.Item.Weapon.Booster
|
||||
import Dodge.Item.Weapon.Utility
|
||||
@@ -20,7 +21,7 @@ import Dodge.Item.Craftable
|
||||
--import Dodge.Creature.SetTarget
|
||||
import Dodge.Creature.Volition
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.Impulse
|
||||
--import Dodge.Creature.Impulse
|
||||
import Dodge.Creature.SentinelAI
|
||||
import Dodge.Creature.LauncherCrit
|
||||
import Dodge.Creature.PistolCrit
|
||||
@@ -66,8 +67,8 @@ spawnerCrit = defaultCreature
|
||||
miniGunCrit :: Creature
|
||||
miniGunCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $
|
||||
sentinelFireType (const shootTillEmpty)
|
||||
, _crUpdate = defaultImpulsive $
|
||||
[sentinelFireType (const shootTillEmpty)]
|
||||
, _crActionPlan = ActionPlan
|
||||
{ _crImpulse = []
|
||||
, _crAction = []
|
||||
@@ -87,7 +88,7 @@ longCrit :: Creature
|
||||
longCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
-- , _crUpdate = stateUpdate sniperAI
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $ sentinelFireType $ const shootTillEmpty
|
||||
, _crUpdate = defaultImpulsive $ [sentinelFireType $ const shootTillEmpty]
|
||||
, _crActionPlan = ActionPlan
|
||||
{ _crImpulse = []
|
||||
, _crAction = []
|
||||
@@ -107,7 +108,7 @@ multGunCrit = defaultCreature
|
||||
, _crInvSel = 0
|
||||
, _crRad = 10
|
||||
, _crHP = 300
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $ sentinelExtraWatchUpdate
|
||||
, _crUpdate = defaultImpulsive $ [sentinelExtraWatchUpdate
|
||||
[ ( const $ not . crHasAmmo
|
||||
, \_ _ -> StrategyActions Reload reloadActions
|
||||
)
|
||||
@@ -120,6 +121,7 @@ multGunCrit = defaultCreature
|
||||
[ drawwp `DoActionThen` shootFirstMiss `DoActionThen` DoImpulses [ChangeStrategy WatchAndWait] ]
|
||||
)
|
||||
]
|
||||
]
|
||||
, _crActionPlan = ActionPlan
|
||||
{ _crImpulse = []
|
||||
, _crAction = []
|
||||
@@ -148,7 +150,7 @@ startCr = defaultCreature
|
||||
, _crMvDir = pi/2
|
||||
, _crID = 0
|
||||
, _crPict = basicCrPict black
|
||||
, _crUpdate = stateUpdate yourControl
|
||||
, _crUpdate = stateUpdate' yourControl'
|
||||
, _crRad = 10
|
||||
, _crMass = 10
|
||||
, _crHP = 1000
|
||||
|
||||
@@ -3,12 +3,13 @@ module Dodge.Creature.ArmourChase
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Default
|
||||
import Dodge.Creature.State
|
||||
import Dodge.Creature.ChainUpdates
|
||||
--import Dodge.Creature.State
|
||||
import Dodge.Creature.Update
|
||||
--import Dodge.Creature.ChainUpdates
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.Impulse
|
||||
--import Dodge.Creature.Impulse
|
||||
import Dodge.Creature.Action
|
||||
import Dodge.Item.Equipment
|
||||
import Dodge.Item.Consumable
|
||||
@@ -19,7 +20,7 @@ import Control.Lens
|
||||
|
||||
armourChaseCrit :: Creature
|
||||
armourChaseCrit = defaultCreature
|
||||
{ _crUpdate = stateUpdate $ impulsiveAI $ chainCreatureUpdates
|
||||
{ _crUpdate = defaultImpulsive
|
||||
[ watchUpdateStrat []
|
||||
, const doStrategyActions
|
||||
, performActions
|
||||
|
||||
@@ -4,10 +4,11 @@ module Dodge.Creature.AutoCrit
|
||||
import Dodge.Data
|
||||
import Dodge.Default
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.Update
|
||||
import Dodge.Creature.SentinelAI
|
||||
--import Dodge.Creature.ChooseTarget
|
||||
import Dodge.Creature.Impulse
|
||||
import Dodge.Creature.State
|
||||
--import Dodge.Creature.Impulse
|
||||
--import Dodge.Creature.State
|
||||
--import Dodge.Creature.State.Data
|
||||
import Dodge.Item.Weapon.BulletGuns
|
||||
import Dodge.Item.Consumable
|
||||
@@ -21,7 +22,7 @@ import qualified Data.IntMap.Strict as IM
|
||||
autoCrit :: Creature
|
||||
autoCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
, _crUpdate = stateUpdate $ impulsiveAI sentinelAI
|
||||
, _crUpdate = defaultImpulsive [sentinelAI]
|
||||
, _crActionPlan = ActionPlan
|
||||
{ _crImpulse = []
|
||||
, _crAction = []
|
||||
|
||||
@@ -33,7 +33,7 @@ smallChaseCrit = chaseCrit
|
||||
}
|
||||
chaseCrit :: Creature
|
||||
chaseCrit = defaultCreature
|
||||
{ _crUpdate = stateUpdate $ impulsiveAI $ chainCreatureUpdates
|
||||
{ _crUpdate = stateUpdate' $ impulsiveAI' $ chainCreatureUpdates
|
||||
[ const doStrategyActions
|
||||
, performActions
|
||||
, const overrideMeleeCloseTarget
|
||||
|
||||
@@ -11,6 +11,9 @@ import Control.Monad.State
|
||||
--import System.Random
|
||||
import Data.List
|
||||
|
||||
applyNoDamage :: [Damage] -> Creature -> World -> World
|
||||
applyNoDamage _ _ = id
|
||||
|
||||
defaultApplyDamage :: [Damage] -> Creature -> World -> World
|
||||
defaultApplyDamage ds cr w = foldl' (applyIndividualDamage cr) w ds'
|
||||
& creatures . ix (_crID cr) %~ doPoisonDam
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
module Dodge.Creature.Impulse
|
||||
( impulsiveAI
|
||||
, impulsiveAI'
|
||||
, followImpulses
|
||||
, followThenClearImpulses
|
||||
, followThenClearImpulses'
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.Vocalization
|
||||
@@ -17,6 +19,12 @@ import System.Random
|
||||
import Data.Bifunctor
|
||||
--import Data.Maybe
|
||||
|
||||
impulsiveAI' :: (World -> Creature -> Creature)
|
||||
-> Creature -> World -> World
|
||||
impulsiveAI' f cr w = g w & creatures . ix (_crID cr) .~ cr'
|
||||
where
|
||||
(g,cr') = impulsiveAI f cr w
|
||||
|
||||
impulsiveAI
|
||||
:: (World -> Creature -> Creature) -- | internal creature update
|
||||
-> Creature
|
||||
@@ -24,6 +32,11 @@ impulsiveAI
|
||||
-> (World -> World , Creature)
|
||||
impulsiveAI f cr w = followImpulses w $ f w cr
|
||||
|
||||
followThenClearImpulses' :: Creature -> World -> World
|
||||
followThenClearImpulses' cr w = f w & creatures . ix (_crID cr) .~ cr'
|
||||
where
|
||||
(f,cr') = followThenClearImpulses w cr
|
||||
|
||||
followThenClearImpulses :: World -> Creature -> (World -> World, Creature)
|
||||
followThenClearImpulses w = second f . followImpulses w
|
||||
where
|
||||
|
||||
@@ -5,15 +5,16 @@ module Dodge.Creature.LauncherCrit
|
||||
import Dodge.Data
|
||||
import Dodge.Default
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.ChainUpdates
|
||||
--import Dodge.Creature.ChainUpdates
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Creature.Volition
|
||||
import Dodge.Creature.Strategy
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.State
|
||||
--import Dodge.Creature.State
|
||||
import Dodge.Creature.Update
|
||||
import Dodge.Item.Weapon.Launcher
|
||||
import Dodge.Creature.Impulse
|
||||
--import Dodge.Creature.Impulse
|
||||
import Dodge.Creature.Action
|
||||
import Geometry.Data
|
||||
import Picture
|
||||
@@ -24,7 +25,7 @@ import Control.Lens
|
||||
launcherCrit :: Creature
|
||||
launcherCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $ chainCreatureUpdates
|
||||
, _crUpdate = defaultImpulsive
|
||||
[ performActions
|
||||
, watchUpdateStrat
|
||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0) [retreatFire])
|
||||
|
||||
@@ -26,7 +26,7 @@ import Control.Lens
|
||||
ltAutoCrit :: Creature
|
||||
ltAutoCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $ chainCreatureUpdates
|
||||
, _crUpdate = stateUpdate' $ impulsiveAI' $ chainCreatureUpdates
|
||||
[ performActions
|
||||
, watchUpdateStrat
|
||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||
|
||||
@@ -29,7 +29,7 @@ import Control.Monad.State
|
||||
pistolCrit :: Creature
|
||||
pistolCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $ chainCreatureUpdates
|
||||
, _crUpdate = stateUpdate' $ impulsiveAI' $ chainCreatureUpdates
|
||||
[ performActions
|
||||
, watchUpdateStrat
|
||||
[ (crHasTargetLOS, \w cr -> StrategyActions (ShootAt 0)
|
||||
|
||||
@@ -27,7 +27,7 @@ import Control.Lens
|
||||
spreadGunCrit :: Creature
|
||||
spreadGunCrit = defaultCreature
|
||||
{ _crPict = basicCrPict red
|
||||
, _crUpdate = stateUpdate $ impulsiveAI $ chainCreatureUpdates
|
||||
, _crUpdate = stateUpdate' $ impulsiveAI' $ chainCreatureUpdates
|
||||
[performActions
|
||||
,watchUpdateStrat
|
||||
[ (crHasTargetLOS, \_ _ -> StrategyActions (ShootAt 0)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module Dodge.Creature.State
|
||||
( stateUpdate
|
||||
( stateUpdate'
|
||||
, stateUpdateDamage
|
||||
, doDamage
|
||||
, clearDamage
|
||||
@@ -8,6 +8,7 @@ module Dodge.Creature.State
|
||||
import Dodge.Data
|
||||
import Dodge.Hammer
|
||||
import Dodge.Reloading
|
||||
|
||||
import Dodge.Base
|
||||
import Dodge.Creature.State.WalkCycle
|
||||
--import Dodge.Creature.Test
|
||||
@@ -38,20 +39,47 @@ import System.Random
|
||||
--import qualified Data.Vector as V
|
||||
--import qualified Data.Vector.Mutable as MV
|
||||
|
||||
-- | The movement is updated before the ai in order to correctly set the oldpos.
|
||||
foldCr :: [Creature -> World -> World]
|
||||
-> Creature -> World -> World
|
||||
foldCr xs cr w = foldr ($ cr) w xs
|
||||
|
||||
-- | this seems to work, but I am not sure about the ordering:
|
||||
-- previously, the movement was updated before the ai in order to correctly set the oldpos.
|
||||
-- This should be made more sensible: should the movement side effects apply to
|
||||
-- the creature before or after it has moved?
|
||||
-- currently invSideEffects are applied after the creature moves, to correctly
|
||||
-- update shield positions
|
||||
stateUpdate :: (Creature -> World -> (World -> World, Creature))
|
||||
-> Creature -> World -> World
|
||||
stateUpdate = stateUpdateDamage doDamage
|
||||
-- at what point invSideEffects is applied wrt to when the creature moves
|
||||
-- may effect whether the shield moves correctly
|
||||
stateUpdate' :: (Creature -> World -> World) -> Creature -> World -> World
|
||||
stateUpdate' f = foldCr
|
||||
[ checkDeath
|
||||
, doDamage
|
||||
, invSideEff
|
||||
, movementSideEff
|
||||
, moveCrHammerUp
|
||||
, stepReloading'
|
||||
, updateMovement'
|
||||
, f
|
||||
]
|
||||
|
||||
checkDeath :: Creature -> World -> World
|
||||
checkDeath cr
|
||||
| _crHP cr < 1 = creatures . at (_crID cr) .~ Nothing -- TODO add corpse
|
||||
| otherwise = id
|
||||
moveCrHammerUp :: Creature -> World -> World
|
||||
moveCrHammerUp cr = creatures . ix (_crID cr) . crHammerPosition %~ moveHammerUp
|
||||
|
||||
stepReloading' :: Creature -> World -> World
|
||||
stepReloading' cr = creatures . ix (_crID cr) %~ stepReloading
|
||||
|
||||
updateMovement' :: Creature -> World -> World
|
||||
updateMovement' cr = creatures . ix (_crID cr) %~ updateMovement
|
||||
|
||||
stateUpdateDamage :: (Creature -> World -> World)
|
||||
-> (Creature -> World -> (World -> World, Creature))
|
||||
-> Creature -> World -> World
|
||||
stateUpdateDamage damageupdate u cr w = damageupdate cr $
|
||||
invSideEff upcr . movementSideEff cr . deathEff . f $ w
|
||||
stateUpdateDamage damageupdate u cr w = damageupdate cr
|
||||
$ invSideEff upcr . movementSideEff cr . deathEff . f
|
||||
$ w
|
||||
& creatures . at (_crID cr) .~ (mvcrhammerup . stepReloading <$> crOrCorpse upcr)
|
||||
where
|
||||
(f,upcr) = u (updateMovement cr) w
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
module Dodge.Creature.SwarmCrit
|
||||
( swarmCrit
|
||||
)
|
||||
where
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Default
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.Creature.ChainUpdates
|
||||
import Dodge.Creature.Update
|
||||
--import Dodge.Creature.ChainUpdates
|
||||
import Dodge.Creature.Boid
|
||||
import Dodge.Creature.ReaderUpdate
|
||||
import Dodge.Creature.Perception
|
||||
import Dodge.Creature.Impulse
|
||||
import Dodge.Creature.State
|
||||
--import Dodge.Creature.Impulse
|
||||
--import Dodge.Creature.State
|
||||
import Dodge.Picture.Layer
|
||||
import Picture
|
||||
|
||||
@@ -18,7 +18,7 @@ import Control.Lens
|
||||
|
||||
swarmCrit :: Creature
|
||||
swarmCrit = defaultCreature
|
||||
{ _crUpdate = stateUpdate $ impulsiveAI $ chainCreatureUpdates
|
||||
{ _crUpdate = defaultImpulsive
|
||||
[ flockToPointUsing' (encircleDistP 100) (meleeHeadingMove 0.1 0.1 (pi/4) 3.9)
|
||||
, const (crMeleeCooldown %~ max 0 . subtract 1)
|
||||
, perceptionUpdate [0]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module Dodge.Creature.YourControl
|
||||
( yourControl
|
||||
(-- yourControl
|
||||
yourControl'
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.Impulse.Movement
|
||||
@@ -23,6 +24,12 @@ yourControl cr w =
|
||||
)
|
||||
where
|
||||
speed = _mvSpeed $ _crMvType cr
|
||||
yourControl' :: Creature -> World -> World
|
||||
yourControl' cr w = w
|
||||
& updateUsingInput
|
||||
& creatures . ix (_crID cr) %~ (mouseActionsCr (_mouseButtons w) . wasdWithAiming w speed 0)
|
||||
where
|
||||
speed = _mvSpeed $ _crMvType cr
|
||||
|
||||
{- | Turn key presses into creature movement. -}
|
||||
wasdWithAiming
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
module Dodge.Debug.Terminal
|
||||
where
|
||||
import Dodge.Creature
|
||||
import Dodge.Creature.State
|
||||
import Dodge.Creature.YourControl
|
||||
import Dodge.Creature.Damage
|
||||
--import Dodge.Creature.State
|
||||
--import Dodge.Creature.YourControl
|
||||
import Dodge.Data
|
||||
import Dodge.Menu.PushPop
|
||||
import Control.Monad
|
||||
@@ -22,9 +23,8 @@ applyTerminalString "LOADME" = (uvWorld . creatures . ix 0 . crInv .~ stackedInv
|
||||
. (uvWorld . creatures . ix 0 . crInvCapacity .~ 50)
|
||||
applyTerminalString "LA" = (uvWorld . creatures . ix 0 . crInv .~ inventoryA)
|
||||
. (uvWorld . creatures . ix 0 . crInvCapacity .~ 50)
|
||||
applyTerminalString "GODON" =
|
||||
uvWorld . creatures . ix 0 . crUpdate .~ stateUpdateDamage clearDamage yourControl
|
||||
applyTerminalString "GODOFF" = uvWorld . creatures . ix 0 . crUpdate .~ stateUpdate yourControl
|
||||
applyTerminalString "GODON" = uvWorld . creatures . ix 0 . crApplyDamage .~ applyNoDamage
|
||||
applyTerminalString "GODOFF" = uvWorld . creatures . ix 0 . crApplyDamage .~ defaultApplyDamage
|
||||
applyTerminalString "LOADTEST" = (uvWorld . creatures . ix 0 . crInv .~ testInventory)
|
||||
. (uvWorld . creatures . ix 0 . crInvCapacity .~ 50)
|
||||
applyTerminalString "LM" = applyTerminalString "LOADME"
|
||||
|
||||
@@ -404,7 +404,7 @@ shootTeslaArc' :: ItemParams -> Point2 -> Float -> World -> (World,ItemParams)
|
||||
shootTeslaArc' ip pos dir w =
|
||||
(w & randGen .~ g
|
||||
& instantParticles .:~ aTeslaArcAt col newarc
|
||||
, ip & currentArc .~ Just newarc
|
||||
, ip & currentArc ?~ newarc
|
||||
)
|
||||
where
|
||||
(col,g) = takeOne [white,azure,blue,cyan] & runState $ _randGen w
|
||||
@@ -487,6 +487,7 @@ shootLaser it cr = instantParticles .:~ lasRayAt (_lasColor $ _itParams it) dam
|
||||
phasev = _phaseV . _itParams $ _crInv cr IM.! _crInvSel cr
|
||||
dam = _lasDamage $ _itParams it
|
||||
|
||||
|
||||
shootDualLaser :: Item -> Creature -> World -> World
|
||||
shootDualLaser it cr w = w'
|
||||
& newBeams . positronBeams .:~ dualRayAt (_lasBeam $ _itParams it) itid w (_lasColor $ _itParams it) dam phasev posl dirl
|
||||
|
||||
@@ -3,6 +3,7 @@ import Color
|
||||
import Dodge.Data
|
||||
--import Dodge.Reloading
|
||||
import Dodge.Creature.State
|
||||
import Dodge.Creature.Damage
|
||||
import Dodge.Creature.Impulse
|
||||
import Dodge.Creature.Picture
|
||||
import Dodge.LevelGen.Data
|
||||
@@ -76,8 +77,9 @@ updateTurret rotSpeed mc w
|
||||
& crRad .~ 1
|
||||
& crDir .~ mcdir
|
||||
& crPict .~ (\cr _ _ -> drawCrEquipment cr)
|
||||
& crUpdate .~ stateUpdateDamage clearDamage (flip followThenClearImpulses)
|
||||
& crUpdate .~ stateUpdate' followThenClearImpulses'
|
||||
& crStance . posture .~ Aiming
|
||||
& crApplyDamage .~ applyNoDamage
|
||||
Just cid -> w'
|
||||
& creatures . ix cid . crPos .~ mcpos
|
||||
& creatures . ix cid . crDir .~ mcdir
|
||||
|
||||
Reference in New Issue
Block a user