{- | Controls a walls response to external damage. - Indestructible walls may still produce sparks, dust etc -} 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 -> (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 is blid DoorPart drid _ -> f $ w' & cWorld . lWorld . doors . ix drid . drHP -~ dmam -- & maybeDestroyDoor drid _ -> 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 :: 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 -- Just dr | _drHP dr < 1 -> destroyDoor dr w -- _ -> w