Simplify creature update

This commit is contained in:
2022-04-07 19:40:12 +01:00
parent 7ca9afeb5f
commit ac74ae0ed1
17 changed files with 104 additions and 45 deletions
+13
View File
@@ -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