diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 91fdc108b..52ea63a72 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -31,7 +31,8 @@ import qualified Data.IntMap.Lazy as IM import qualified Data.Map as M import Control.Lens import Data.Monoid ---import System.Random +import System.Random +--import Data.Bifunctor update :: World -> World update = functionalUpdate . pushSideEffects @@ -136,10 +137,18 @@ updateParticles w = set particles (catMaybes ps) w' where (w',ps) = mapAccumR (\a b -> _ptUpdate' b a b) w $ _particles w +-- Note that this updates the randgen updateCreatures :: World -> World -updateCreatures w = appEndo f $ w & creatures .~ IM.mapMaybe id m +updateCreatures w = appEndo f $ w + & creatures .~ IM.mapMaybe id m + & randGen .~ newg where - (f,m) = traverse (\cr -> _crUpdate cr cr w) (_creatures w) + ((f,newg),m) = mapAccumR crUp (Endo id,_randGen w) (_creatures w) + crUp (f',g) cr = ((f' <> f'',g'), cr') + where + (f'',cr') = _crUpdate cr cr (w & randGen .~ g) + (_,g') = genWord8 g + {- | Apply door mechanisms. -}