Simplify creature action/impulse code

This commit is contained in:
2025-10-18 17:32:23 +01:00
parent 11c7b25fe9
commit 4542a6cea6
4 changed files with 17 additions and 19 deletions
+13 -3
View File
@@ -11,6 +11,7 @@ module Dodge.Creature.Action (
youDropItem,
) where
import Data.Foldable
import Linear
import NewInt
import Dodge.Creature.MoveType
@@ -32,11 +33,20 @@ import Dodge.SoundLogic
import Geometry
import qualified IntMapHelp as IM
import LensHelp
import Dodge.Creature.Impulse
performActions :: World -> Creature -> ([Impulse],Creature)
performActions w cr = (concat iss
, cr & crActionPlan . apAction .~ catMaybes mayas)
--performActions :: World -> Creature -> ([Impulse],Creature)
--performActions w cr = (concat iss
-- , 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
cr = w ^?! cWorld . lWorld . creatures . ix cid
(iss, mayas) = unzip $ map (performAction cr w) $ cr ^. crActionPlan . apAction
type OutAction = ([Impulse], Maybe Action)