Handle machine damage/destruction during wall damage
This commit is contained in:
@@ -24,11 +24,13 @@ import Sound.Data
|
||||
|
||||
updateMachine :: Machine -> World -> World
|
||||
updateMachine mc
|
||||
| _mcHP mc < 1 = destroyMachine mc
|
||||
| otherwise =
|
||||
mcApplyDamage (_mcDamage mc) mc
|
||||
. mcPlaySound mc
|
||||
= mcPlaySound mc
|
||||
. mcTypeUpdate mc (_mcType mc)
|
||||
-- | _mcHP mc < 1 = destroyMachine mc
|
||||
-- | otherwise =
|
||||
-- mcApplyDamage (_mcDamage mc) mc
|
||||
-- . mcPlaySound mc
|
||||
-- . mcTypeUpdate mc (_mcType mc)
|
||||
|
||||
mcTypeUpdate :: Machine -> MachineType -> World -> World
|
||||
mcTypeUpdate mc = \case
|
||||
|
||||
@@ -25,14 +25,17 @@ import Dodge.Zoning.Pathing
|
||||
import Geometry.Data
|
||||
import LensHelp
|
||||
import Linear
|
||||
import qualified Data.IntSet as IS
|
||||
import Dodge.Machine.Destroy
|
||||
|
||||
damageWall :: Int -> Damage -> World -> (S.Set Int2, World)
|
||||
damageWall wlid dt w = fromMaybe (mempty,w) $ do
|
||||
wl <- w ^? cWorld . lWorld . walls . ix wlid
|
||||
let (dmam, w') = damMatSideEffect dt (_wlMaterial wl) (Right wl) w
|
||||
return $ case wl ^. wlStructure of
|
||||
MachinePart mcid -> (,) mempty
|
||||
$ w' & cWorld . lWorld . machines . ix mcid . mcDamage .:~ dt
|
||||
MachinePart mcid -> -- (,) mempty
|
||||
-- $ w' & cWorld . lWorld . machines . ix mcid . mcDamage .:~ dt
|
||||
w' & damageMachine dmam mcid
|
||||
BlockPart blid ->
|
||||
w' & damageBlock (wl ^. wlMaterial) dmam blid
|
||||
DoorPart drid _ ->
|
||||
@@ -40,6 +43,19 @@ damageWall wlid dt w = fromMaybe (mempty,w) $ do
|
||||
& maybeDestroyDoor drid
|
||||
_ -> (mempty, w')
|
||||
|
||||
damageMachine :: Int -> Int -> World -> (S.Set Int2, World)
|
||||
damageMachine x mcid w = case w ^? cWorld . lWorld . machines . ix mcid of
|
||||
Just mc | _mcHP mc < x -> destroyMachine' mc w
|
||||
_ -> (mempty, w & cWorld . lWorld . machines . ix mcid . mcHP -~ x)
|
||||
|
||||
destroyMachine' :: Machine -> World -> (S.Set Int2, World)
|
||||
destroyMachine' mc w = (js, destroyMachine mc w)
|
||||
where
|
||||
wlids = IS.toList $ mc ^. mcWallIDs
|
||||
f wlid = w ^?! cWorld . lWorld . walls . ix wlid . wlLine
|
||||
js = foldMap (S.fromList . uncurry (zoneOfSeg peZoneSize) . f) wlids
|
||||
|
||||
|
||||
-- block destruction is convoluted...
|
||||
damageBlock :: Material -> Int -> Int -> World -> (S.Set Int2, World)
|
||||
damageBlock = \case
|
||||
|
||||
Reference in New Issue
Block a user