Move machine destruction to external function

This commit is contained in:
2022-07-14 12:48:52 +01:00
parent 79791d0df2
commit f05d284312
7 changed files with 57 additions and 23 deletions
+4 -2
View File
@@ -15,6 +15,7 @@ module Dodge.Data
, module Dodge.Data.LoadAction , module Dodge.Data.LoadAction
, module Dodge.Data.ForegroundShape , module Dodge.Data.ForegroundShape
, module Dodge.Data.Wall , module Dodge.Data.Wall
, module Dodge.Data.Object
, module Dodge.Data.Zoning , module Dodge.Data.Zoning
, module Dodge.Data.Bounds , module Dodge.Data.Bounds
, module Dodge.Combine.Data , module Dodge.Combine.Data
@@ -40,6 +41,7 @@ import Dodge.Data.RadarBlip
import Dodge.Data.Room import Dodge.Data.Room
import Dodge.Data.Flare import Dodge.Data.Flare
import Dodge.Data.PathGraph import Dodge.Data.PathGraph
import Dodge.Data.Object
import Dodge.Data.Zoning import Dodge.Data.Zoning
import Dodge.Data.ForegroundShape import Dodge.Data.ForegroundShape
import Dodge.Data.LoadAction import Dodge.Data.LoadAction
@@ -1022,7 +1024,6 @@ data Machine = Machine
{ _mcID :: Int { _mcID :: Int
, _mcWallIDs :: IS.IntSet , _mcWallIDs :: IS.IntSet
, _mcUpdate :: Machine -> World -> World , _mcUpdate :: Machine -> World -> World
, _mcDeath :: Machine -> World -> World
, _mcApplyDamage :: [Damage] -> Machine -> World -> World , _mcApplyDamage :: [Damage] -> Machine -> World -> World
, _mcDraw :: Machine -> SPic , _mcDraw :: Machine -> SPic
, _mcPos :: Point2 , _mcPos :: Point2
@@ -1033,8 +1034,9 @@ data Machine = Machine
, _mcDamage :: [Damage] , _mcDamage :: [Damage]
, _mcLSs :: [Int] , _mcLSs :: [Int]
, _mcType :: MachineType , _mcType :: MachineType
, _mcMounts :: M.Map Object Int
, _mcName :: String , _mcName :: String
, _mcTermMID :: Maybe Int -- , _mcTermMID :: Maybe Int
} }
data Sensor = NoSensor data Sensor = NoSensor
| SensorToggleAmount | SensorToggleAmount
+13
View File
@@ -0,0 +1,13 @@
module Dodge.Data.Object where
data Object
= ObTerminal
| ObCreature
| ObMachine
| ObWall
| ObDoor
| ObButton
| ObForegroundShape
| ObLightSource
| ObProp
deriving (Eq,Show,Ord,Read,Enum,Bounded)
+1 -2
View File
@@ -181,7 +181,6 @@ defaultMachine = Machine
{ _mcID = 0 { _mcID = 0
, _mcWallIDs = mempty , _mcWallIDs = mempty
, _mcUpdate = defaultMachineUpdate , _mcUpdate = defaultMachineUpdate
, _mcDeath = const id
, _mcApplyDamage = \_ _ -> id , _mcApplyDamage = \_ _ -> id
, _mcDraw = const mempty , _mcDraw = const mempty
, _mcColor = white , _mcColor = white
@@ -193,7 +192,7 @@ defaultMachine = Machine
, _mcLSs = [] , _mcLSs = []
, _mcType = StaticMachine , _mcType = StaticMachine
, _mcName = "" , _mcName = ""
, _mcTermMID = Nothing , _mcMounts = mempty
} }
defaultMachineUpdate :: Machine -> World -> World defaultMachineUpdate :: Machine -> World -> World
defaultMachineUpdate mc defaultMachineUpdate mc
+4 -4
View File
@@ -41,10 +41,10 @@ initialAnoTree :: Annotation
initialAnoTree = OnwardList initialAnoTree = OnwardList
$ intersperse (AnTree corDoor) $ intersperse (AnTree corDoor)
[ IntAnno $ AnTree . startRoom [ IntAnno $ AnTree . startRoom
, AnRoom $ tanksRoom [] [] <&> rmPmnts .~ [] -- , AnRoom $ tanksRoom [] [] <&> rmPmnts .~ []
, AnRoom $ tanksRoom [] [] -- , AnRoom $ tanksRoom [] []
, AnRoom $ roomCCrits 0 -- , AnRoom $ roomCCrits 0
, AnRoom $ return airlock0 -- , AnRoom $ return airlock0
, AnRoom slowDoorRoom , AnRoom slowDoorRoom
-- , AnRoom $ roomCCrits 10 -- , AnRoom $ roomCCrits 10
-- , AnTree firstBreather -- , AnTree firstBreather
+27
View File
@@ -0,0 +1,27 @@
module Dodge.Machine.Destroy where
import Dodge.Wall.Delete
import Dodge.Data
import Dodge.WorldEvent.Explosion
import LensHelp
import Data.Maybe
import qualified Data.IntMap.Strict as IM
destroyMachine :: Machine -> World -> World
destroyMachine mc = (machines %~ IM.delete (_mcID mc))
. deleteWallIDs (_mcWallIDs mc)
. makeExplosionAt (_mcPos mc)
. mcKillTerm mc
. mcKillBut mc
mcKillTerm :: Machine -> World -> World
mcKillTerm mc w = fromMaybe w $ do
tmid <- mc ^? mcMounts . ix ObTerminal
tm <- w ^? terminals . ix tmid
return $ w
& _tmDeathEffect tm tm
mcKillBut :: Machine -> World -> World
mcKillBut mc w = fromMaybe w $ do
btid <- mc ^? mcMounts . ix ObButton
return $ w & buttons . at btid .~ Nothing
+2 -11
View File
@@ -13,7 +13,6 @@ import Dodge.Default
import Dodge.Machine import Dodge.Machine
import Dodge.SoundLogic import Dodge.SoundLogic
import Dodge.Terminal import Dodge.Terminal
import Dodge.WorldEvent.Explosion
import Color import Color
import Geometry import Geometry
import ShapePicture import ShapePicture
@@ -33,27 +32,20 @@ putTerminal'' mc tm mcf = ps0PushPS (PutTerminal tm)
$ \tmpl -> Just $ ps0PushPS (PutButton termButton) $ \tmpl -> Just $ ps0PushPS (PutButton termButton)
$ \btpl -> Just $ pt0 (PutMachine (reverse $ square 10) $ \btpl -> Just $ pt0 (PutMachine (reverse $ square 10)
(mc & mcUpdate %~ (\fmu mc' -> mcf (fromJust $ _plMID btpl) mc' . fmu mc') . machineAddSound fridgeHumS (mc & mcUpdate %~ (\fmu mc' -> mcf (fromJust $ _plMID btpl) mc' . fmu mc') . machineAddSound fridgeHumS
& mcDeath %~ (\fd mc' -> mcKillTerm mc' . (buttons . at (fromJust (_plMID btpl)) .~ Nothing) . fd mc') & mcMounts . at ObButton ?~ fromJust (_plMID btpl)
) ) ) )
$ \mcpl -> Just $ sps0 $ PutWorldUpdate $ const (setids tmpl btpl mcpl) $ \mcpl -> Just $ sps0 $ PutWorldUpdate $ const (setids tmpl btpl mcpl)
where where
setids tmpl btpl mcpl w = w setids tmpl btpl mcpl w = w
& terminals . ix tmid . tmButtonID .~ btid & terminals . ix tmid . tmButtonID .~ btid
& terminals . ix tmid . tmMachineID .~ mcid & terminals . ix tmid . tmMachineID .~ mcid
& machines . ix mcid . mcTermMID ?~ tmid & machines . ix mcid . mcMounts . at ObTerminal ?~ tmid
& buttons . ix btid . btTermMID ?~ tmid & buttons . ix btid . btTermMID ?~ tmid
where where
tmid = fromJust (_plMID tmpl) tmid = fromJust (_plMID tmpl)
btid = fromJust (_plMID btpl) btid = fromJust (_plMID btpl)
mcid = fromJust (_plMID mcpl) mcid = fromJust (_plMID mcpl)
mcKillTerm :: Machine -> World -> World
mcKillTerm mc w = fromMaybe w $ do
tmid <- _mcTermMID mc
tm <- w ^? terminals . ix tmid
return $ w
& _tmDeathEffect tm tm
putTerminal' putTerminal'
:: Color :: Color
-> Terminal -> Terminal
@@ -72,7 +64,6 @@ putTerminal col f = putTerminal'' (mc & mcColor .~ col) f (\_ -> basicMachineUpd
mc = defaultMachine mc = defaultMachine
{ _mcDraw = terminalSPic { _mcDraw = terminalSPic
, _mcHP = 100 , _mcHP = 100
, _mcDeath = makeExplosionAt . _mcPos
} }
termButton :: Button termButton :: Button
+6 -4
View File
@@ -12,8 +12,9 @@ import Dodge.CullBox
--import Dodge.Block --import Dodge.Block
import Dodge.Distortion import Dodge.Distortion
import Dodge.SoundLogic import Dodge.SoundLogic
import Dodge.Wall.Delete --import Dodge.Wall.Delete
import Dodge.Update.WallDamage import Dodge.Update.WallDamage
import Dodge.Machine.Destroy
--import Dodge.Menu --import Dodge.Menu
import Dodge.Base import Dodge.Base
import Dodge.Zone import Dodge.Zone
@@ -127,9 +128,10 @@ updateWorldSelect w = f . g $ case (w ^? mouseButtons . ix ButtonLeft, w ^? mous
mcChooseUpdate :: Machine -> Machine -> World -> World mcChooseUpdate :: Machine -> Machine -> World -> World
mcChooseUpdate mc mc' mcChooseUpdate mc mc'
| _mcHP mc > 0 = _mcUpdate mc mc' | _mcHP mc > 0 = _mcUpdate mc mc'
| otherwise = (machines %~ IM.delete (_mcID mc)) | otherwise = destroyMachine mc
. deleteWallIDs (_mcWallIDs mc) -- (machines %~ IM.delete (_mcID mc))
. _mcDeath mc mc' -- . deleteWallIDs (_mcWallIDs mc)
-- . _mcDeath mc mc'
tmUpdate :: Terminal -> World -> World tmUpdate :: Terminal -> World -> World
tmUpdate tm w = case w ^? terminals . ix (_tmID tm) . tmFutureLines . ix 0 of tmUpdate tm w = case w ^? terminals . ix (_tmID tm) . tmFutureLines . ix 0 of