Simplify creature action/impulse code
This commit is contained in:
@@ -11,6 +11,7 @@ module Dodge.Creature.Action (
|
|||||||
youDropItem,
|
youDropItem,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Data.Foldable
|
||||||
import Linear
|
import Linear
|
||||||
import NewInt
|
import NewInt
|
||||||
import Dodge.Creature.MoveType
|
import Dodge.Creature.MoveType
|
||||||
@@ -32,11 +33,20 @@ import Dodge.SoundLogic
|
|||||||
import Geometry
|
import Geometry
|
||||||
import qualified IntMapHelp as IM
|
import qualified IntMapHelp as IM
|
||||||
import LensHelp
|
import LensHelp
|
||||||
|
import Dodge.Creature.Impulse
|
||||||
|
|
||||||
performActions :: World -> Creature -> ([Impulse],Creature)
|
--performActions :: World -> Creature -> ([Impulse],Creature)
|
||||||
performActions w cr = (concat iss
|
--performActions w cr = (concat iss
|
||||||
, cr & crActionPlan . apAction .~ catMaybes mayas)
|
-- , cr & crActionPlan . apAction .~ catMaybes mayas)
|
||||||
|
-- where
|
||||||
|
-- (iss, mayas) = unzip $ map (performAction cr w) $ cr ^. crActionPlan . apAction
|
||||||
|
|
||||||
|
performActions :: Int -> World -> World
|
||||||
|
performActions cid w = foldl' (followImpulse cid)
|
||||||
|
(w & cWorld . lWorld . creatures . ix cid . crActionPlan . apAction .~ catMaybes mayas)
|
||||||
|
(concat iss)
|
||||||
where
|
where
|
||||||
|
cr = w ^?! cWorld . lWorld . creatures . ix cid
|
||||||
(iss, mayas) = unzip $ map (performAction cr w) $ cr ^. crActionPlan . apAction
|
(iss, mayas) = unzip $ map (performAction cr w) $ cr ^. crActionPlan . apAction
|
||||||
|
|
||||||
type OutAction = ([Impulse], Maybe Action)
|
type OutAction = ([Impulse], Maybe Action)
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
--{-# LANGUAGE TupleSections #-}
|
--{-# LANGUAGE TupleSections #-}
|
||||||
|
|
||||||
module Dodge.Creature.Impulse (followImpulses) where
|
module Dodge.Creature.Impulse (followImpulse) where
|
||||||
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Data.Foldable
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Dodge.Creature.Action
|
|
||||||
import Dodge.Creature.Impulse.Movement
|
import Dodge.Creature.Impulse.Movement
|
||||||
import Dodge.Creature.MoveType
|
import Dodge.Creature.MoveType
|
||||||
--import Dodge.Creature.Impulse.UseItem
|
--import Dodge.Creature.Impulse.UseItem
|
||||||
@@ -21,11 +19,6 @@ import Linear
|
|||||||
import NewInt
|
import NewInt
|
||||||
import System.Random
|
import System.Random
|
||||||
|
|
||||||
followImpulses :: Int -> World -> World
|
|
||||||
followImpulses cid w =
|
|
||||||
let (is, cr) = performActions w (w ^?! cWorld . lWorld . creatures . ix cid)
|
|
||||||
in foldl' (followImpulse cid) (w & cWorld . lWorld . creatures . ix cid .~ cr) is
|
|
||||||
|
|
||||||
-- note SwitchToItem doesn't necessarily update the root item correctly
|
-- note SwitchToItem doesn't necessarily update the root item correctly
|
||||||
followImpulse :: Int -> World -> Impulse -> World
|
followImpulse :: Int -> World -> Impulse -> World
|
||||||
followImpulse cid w imp = case imp of
|
followImpulse cid w imp = case imp of
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
module Dodge.Creature.Update (updateCreature) where
|
module Dodge.Creature.Update (updateCreature) where
|
||||||
|
|
||||||
import Dodge.Creature.Impulse
|
|
||||||
import Linear
|
import Linear
|
||||||
import NewInt
|
import NewInt
|
||||||
import Color
|
import Color
|
||||||
@@ -48,7 +47,7 @@ updateCreature' cr =
|
|||||||
LampCrit{} -> updateLampoid cr
|
LampCrit{} -> updateLampoid cr
|
||||||
BarrelCrit bt -> updateBarreloid bt cr
|
BarrelCrit bt -> updateBarreloid bt cr
|
||||||
AvatarDead -> id
|
AvatarDead -> id
|
||||||
ChaseCrit {} -> \w -> crUpdate cid . followImpulses cid
|
ChaseCrit {} -> \w -> crUpdate cid . performActions cid
|
||||||
$ over (cWorld . lWorld . creatures . ix cid) (chaseCritInternal w) w
|
$ over (cWorld . lWorld . creatures . ix cid) (chaseCritInternal w) w
|
||||||
_ -> crUpdate cid
|
_ -> crUpdate cid
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -3552,12 +3552,8 @@ flickerUpdate src/Dodge/Placement/Instance/LightSource/Flicker.hs 24;" f
|
|||||||
floatSize src/Shader/Parameters.hs 17;" f
|
floatSize src/Shader/Parameters.hs 17;" f
|
||||||
flockACC src/Dodge/Creature/ReaderUpdate.hs 95;" f
|
flockACC src/Dodge/Creature/ReaderUpdate.hs 95;" f
|
||||||
flockArmourChaseCrit src/Dodge/Creature/ArmourChase.hs 14;" f
|
flockArmourChaseCrit src/Dodge/Creature/ArmourChase.hs 14;" f
|
||||||
flockCenterFunc src/Dodge/Creature/Boid.hs 259;" f
|
|
||||||
flockChaseTarget src/Dodge/Creature/Boid.hs 188;" f
|
flockChaseTarget src/Dodge/Creature/Boid.hs 188;" f
|
||||||
flockFunc src/Dodge/Creature/Boid.hs 246;" f
|
|
||||||
flockPointTarget src/Dodge/Creature/Boid.hs 204;" f
|
flockPointTarget src/Dodge/Creature/Boid.hs 204;" f
|
||||||
flockPointTargetR src/Dodge/Creature/Boid.hs 272;" f
|
|
||||||
flockToPointUsing' src/Dodge/Creature/Boid.hs 232;" f
|
|
||||||
floorItemPickupInfo src/Dodge/Render/HUD.hs 231;" f
|
floorItemPickupInfo src/Dodge/Render/HUD.hs 231;" f
|
||||||
floorItemSPic src/Dodge/Render/ShapePicture.hs 120;" f
|
floorItemSPic src/Dodge/Render/ShapePicture.hs 120;" f
|
||||||
floorWire src/Dodge/Wire.hs 13;" f
|
floorWire src/Dodge/Wire.hs 13;" f
|
||||||
@@ -4183,7 +4179,7 @@ mcUseItem src/Dodge/Machine/Update.hs 89;" f
|
|||||||
megaBattery src/Dodge/Item/Ammo.hs 55;" f
|
megaBattery src/Dodge/Item/Ammo.hs 55;" f
|
||||||
megaShellMag src/Dodge/Item/Ammo.hs 44;" f
|
megaShellMag src/Dodge/Item/Ammo.hs 44;" f
|
||||||
megaTinMag src/Dodge/Item/Ammo.hs 23;" f
|
megaTinMag src/Dodge/Item/Ammo.hs 23;" f
|
||||||
meleeHeadingMove src/Dodge/Creature/Boid.hs 287;" f
|
meleeHeadingMove src/Dodge/Creature/Boid.hs 295;" f
|
||||||
memoBoxEdgeIndices src/Shader/Poke.hs 352;" f
|
memoBoxEdgeIndices src/Shader/Poke.hs 352;" f
|
||||||
memoBoxSurfaces src/Shader/Poke.hs 286;" f
|
memoBoxSurfaces src/Shader/Poke.hs 286;" f
|
||||||
memoCylinderIndices src/Shader/Poke.hs 323;" f
|
memoCylinderIndices src/Shader/Poke.hs 323;" f
|
||||||
@@ -4277,7 +4273,7 @@ mvGust src/Dodge/Update.hs 784;" f
|
|||||||
mvLS src/Dodge/Placement/PlaceSpot.hs 273;" f
|
mvLS src/Dodge/Placement/PlaceSpot.hs 273;" f
|
||||||
mvP src/Dodge/Wall/Move.hs 54;" f
|
mvP src/Dodge/Wall/Move.hs 54;" f
|
||||||
mvPointAlongAtSpeed src/Dodge/Base.hs 121;" f
|
mvPointAlongAtSpeed src/Dodge/Base.hs 121;" f
|
||||||
mvPointMeleeTarg src/Dodge/Creature/Boid.hs 319;" f
|
mvPointMeleeTarg src/Dodge/Creature/Boid.hs 327;" f
|
||||||
mvPointToward src/Dodge/Base.hs 136;" f
|
mvPointToward src/Dodge/Base.hs 136;" f
|
||||||
mvPointTowardAtSpeed src/Dodge/Base.hs 105;" f
|
mvPointTowardAtSpeed src/Dodge/Base.hs 105;" f
|
||||||
mvProp src/Dodge/Placement/PlaceSpot.hs 188;" f
|
mvProp src/Dodge/Placement/PlaceSpot.hs 188;" f
|
||||||
|
|||||||
Reference in New Issue
Block a user