Simplify block/wall destruction

This uses a right fold, so might be slower than a strict left fold
This commit is contained in:
2025-11-09 16:00:46 +00:00
parent 6f3632d495
commit cd7a5dcbb5
3 changed files with 48 additions and 25 deletions
+22 -8
View File
@@ -2,7 +2,8 @@
{- | Controls a walls response to external damage.
- Indestructible walls may still produce sparks, dust etc
-}
module Dodge.Wall.Damage (damageWall) where
module Dodge.Wall.Damage (damageWall
) where
import Linear
import Data.Maybe
@@ -22,19 +23,32 @@ import Dodge.Data.World
import LensHelp
import qualified Data.Set as S
-- maybeDestroyDoor should rather happen during the door mechanism update
damageWall :: Damage -> Wall -> (S.Set Int2,World) -> (S.Set Int2,World)
damageWall dt wl (is,w) = case _wlStructure wl of
MachinePart mcid -> (,) is $ w' & cWorld . lWorld . machines . ix mcid . mcDamage .:~ dt
---- maybeDestroyDoor should rather happen during the door mechanism update
--damageWall :: Damage -> Wall -> (S.Set Int2,World) -> (S.Set Int2,World)
--damageWall dt wl (is,w) = case _wlStructure wl of
-- MachinePart mcid -> (,) is $ w' & cWorld . lWorld . machines . ix mcid . mcDamage .:~ dt
-- BlockPart blid ->
-- w' & cWorld . lWorld . blocks . ix blid . blHP -~ dmam
-- & maybeDestroyBlock blid
-- & _1 <>~ is
-- DoorPart drid _ ->
-- w' & cWorld . lWorld . doors . ix drid . drHP -~ dmam
-- & maybeDestroyDoor drid
-- & _1 <>~ is
-- _ -> (is, w')
-- where
-- (dmam,w') = damMatSideEffect dt (_wlMaterial wl) (Right wl) w
damageWall :: Wall -> Damage ->World -> (S.Set Int2,World)
damageWall wl dt w = case _wlStructure wl of
MachinePart mcid -> (,) mempty $ w' & cWorld . lWorld . machines . ix mcid . mcDamage .:~ dt
BlockPart blid ->
w' & cWorld . lWorld . blocks . ix blid . blHP -~ dmam
& maybeDestroyBlock blid
& _1 <>~ is
DoorPart drid _ ->
w' & cWorld . lWorld . doors . ix drid . drHP -~ dmam
& maybeDestroyDoor drid
& _1 <>~ is
_ -> (is, w')
_ -> (mempty, w')
where
(dmam,w') = damMatSideEffect dt (_wlMaterial wl) (Right wl) w