From 914cae8212c0bf5e7dbacd261b41664a4095bf86 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 18 May 2022 11:26:47 +0100 Subject: [PATCH] Clarify when crOldPos is set --- src/Dodge/Creature/Action.hs | 3 +-- src/Dodge/Creature/State.hs | 13 +++---------- src/Dodge/Update.hs | 6 ++++++ src/Dodge/WallCreatureCollisions.hs | 13 ++++++------- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Dodge/Creature/Action.hs b/src/Dodge/Creature/Action.hs index e45b14e36..faf33c73e 100644 --- a/src/Dodge/Creature/Action.hs +++ b/src/Dodge/Creature/Action.hs @@ -251,8 +251,7 @@ sizeSelf x cr w ) | otherwise = Nothing where - cr1 = colCrWall' w (cr {_crRad = 10* x}) - --cr2 = colCrWall w cr1 + cr1 = colCrWall w (cr {_crRad = 10* x}) distR = 120 distortionBulge | _crRad cr < 10*x = raddist 1.9 diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 0e27f4bed..300e71535 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -57,9 +57,7 @@ stateUpdate f = foldCr , invSideEff , movementSideEff , f - , internalUpdate -- note that updateMovement needs to be evaluated at the correct moment - -- wrt any changes in position made by the creature: the - -- oldPos needs to be correctly set + , internalUpdate , checkDeath ] @@ -92,11 +90,6 @@ dropByState cr w = foldr (copyInvItemToFloor cr) w $ case cr ^. crState . crDrop DropSpecific xs -> xs DropAmount n -> take n $ evalState (shuffle $ IM.keys $ _crInv cr) (_randGen w) -setOldPos :: Creature -> Creature -setOldPos cr = cr - & crOldPos .~ _crPos cr - & crOldDir .~ _crDir cr - doDamage :: Creature -> World -> World doDamage cr w = w & creatures . ix (_crID cr) . crState . crDamage .~ [] @@ -185,8 +178,8 @@ weaponReloadSounds cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption o updateMovement :: Creature -> Creature updateMovement cr - | isFrictionless cr = over crPos (+.+ momentum) $ setOldPos cr - | otherwise = updateWalkCycle $ setOldPos cr + | isFrictionless cr = over crPos (+.+ momentum) cr + | otherwise = updateWalkCycle cr where momentum' = 0.98 *.* (_crPos cr -.- _crOldPos cr) momentum'' | magV momentum' > 1 = 1 *.* normalizeV momentum' diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 7efadc4da..495ac2346 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -72,6 +72,7 @@ functionalUpdate cfig w = checkEndGame . updateIMl _machines _mcUpdate . updateIMl _creatures _crUpdate -- creatures should be updated early so that crOldPos is set before any position change + . over creatures (fmap setOldPos) . updateCreatureGroups . updateBlocks . updateSeenWalls @@ -85,6 +86,11 @@ functionalUpdate cfig w = checkEndGame where (x,y) = cloudZoneOfPoint $ stripZ $ _clPos cl +setOldPos :: Creature -> Creature +setOldPos cr = cr + & crOldPos .~ _crPos cr + & crOldDir .~ _crDir cr + -- hack --updateRandGen :: World -> World --updateRandGen = randGen %~ (snd . (uniform :: StdGen -> (Int,StdGen))) diff --git a/src/Dodge/WallCreatureCollisions.hs b/src/Dodge/WallCreatureCollisions.hs index 081c4ec5b..b4744579a 100644 --- a/src/Dodge/WallCreatureCollisions.hs +++ b/src/Dodge/WallCreatureCollisions.hs @@ -2,7 +2,6 @@ module Dodge.WallCreatureCollisions ( colCrsWalls , colCrWall - , colCrWall' , pushCreatureOutFromWalls , crOnWall ) where @@ -20,16 +19,16 @@ import Control.Lens import qualified Data.IntMap.Strict as IM colCrsWalls :: Configuration -> World -> World -colCrsWalls cfig w = w & creatures %~ fmap (colCrWall cfig w) +colCrsWalls cfig w = w & creatures %~ fmap (noclipCheck cfig w) -colCrWall :: Configuration -> World -> Creature -> Creature -colCrWall cfig w c +noclipCheck :: Configuration -> World -> Creature -> Creature +noclipCheck cfig w c | _debug_noclip cfig && _crID c == 0 = c -- for noclip - | otherwise = colCrWall' w c + | otherwise = colCrWall w c -- no noclip check, so no need for a configuration file -colCrWall' :: World -> Creature -> Creature -colCrWall' w c +colCrWall :: World -> Creature -> Creature +colCrWall w c | p1 == p2 = pushOrCrush ls c -- | _crPos c' == _crPos c'' = c' -- | otherwise = c & crPos .~ _crOldPos c