Update pathing on block destruction without relying on _blObstructs

This commit is contained in:
2025-10-24 10:34:27 +01:00
parent 9a3c642684
commit c39f99e146
6 changed files with 181 additions and 158 deletions
+13 -10
View File
@@ -3,33 +3,36 @@
-}
module Dodge.Wall.Damage (damageWall) where
import Geometry.Data
import Dodge.Material.Damage
import Dodge.Block
import Dodge.Data.World
import LensHelp
import qualified Data.Set as S
-- maybeDestroyDoor should rather happen during the door mechanism update
damageWall :: Damage -> Wall -> World -> World
damageWall dt wl w = case _wlStructure wl of
MachinePart mcid -> w' & cWorld . lWorld . machines . ix mcid . mcDamage .:~ dt
damageWall :: Damage -> Wall -> (S.Set Int2,World) -> (S.Set Int2,World)
damageWall dt wl (is,w) = case _wlStructure wl of
MachinePart mcid -> f $ w' & cWorld . lWorld . machines . ix mcid . mcDamage .:~ dt
BlockPart blid ->
w' & cWorld . lWorld . blocks . ix blid . blHP -~ dmam
& maybeDestroyBlock blid
& maybeDestroyBlock is blid
DoorPart drid ->
w' & cWorld . lWorld . doors . ix drid . drHP -~ dmam
f $ w' & cWorld . lWorld . doors . ix drid . drHP -~ dmam
-- & maybeDestroyDoor drid
_ -> w'
_ -> f $ w'
where
f = (,) is
-- x = case dt of
-- Explosive y _ -> y * 100
-- _ -> dt ^. dmAmount
(dmam,w') = damMatSideEffect dt (_wlMaterial wl) (Right wl) w
-- block destruction is convoluted...
maybeDestroyBlock :: Int -> World -> World
maybeDestroyBlock blid w = case w ^? cWorld . lWorld . blocks . ix blid of
Just bl | _blHP bl < 1 -> destroyBlock bl w
_ -> w
maybeDestroyBlock :: S.Set Int2 -> Int -> World -> (S.Set Int2,World)
maybeDestroyBlock is blid w = case w ^? cWorld . lWorld . blocks . ix blid of
Just bl | _blHP bl < 1 -> destroyBlock is bl w
_ -> (is,w)
--maybeDestroyDoor :: Int -> World -> World
--maybeDestroyDoor drid w = case w ^? cWorld . lWorld . doors . ix drid of