Simplify block/wall destruction
This uses a right fold, so might be slower than a strict left fold
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user