41 lines
1.3 KiB
Haskell
41 lines
1.3 KiB
Haskell
{- | Controls a walls response to external damage.
|
|
- Indestructible walls may still produce sparks, dust etc
|
|
-}
|
|
module Dodge.Wall.Damage (
|
|
-- damageBlocksBy,
|
|
damageWall,
|
|
) where
|
|
|
|
import Dodge.Material.Damage
|
|
import Dodge.Block
|
|
import Dodge.Data.World
|
|
import LensHelp
|
|
|
|
-- 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
|
|
BlockPart blid ->
|
|
w' & cWorld . lWorld . blocks . ix blid . blHP -~ x
|
|
& maybeDestroyBlock blid
|
|
DoorPart drid ->
|
|
w' & cWorld . lWorld . doors . ix drid . drHP -~ x
|
|
& maybeDestroyDoor drid
|
|
_ -> w'
|
|
where
|
|
x = case dt of
|
|
Explosive y _ -> y * 100
|
|
_ -> dt ^. dmAmount
|
|
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
|
|
|
|
maybeDestroyDoor :: Int -> World -> World
|
|
maybeDestroyDoor drid w = case w ^? cWorld . lWorld . doors . ix drid of
|
|
Just dr | _drHP dr < 1 -> destroyDoor dr w
|
|
_ -> w
|