Add in "linear" lWorld to separate time reversable worlds

This commit is contained in:
2022-10-28 12:24:51 +01:00
parent 5f6bd43599
commit 7e790b7153
130 changed files with 827 additions and 980 deletions
+2 -2
View File
@@ -8,9 +8,9 @@ import qualified IntMapHelp as IM
createWall :: Wall -> World -> (Int, World)
createWall wl w =
( wlid
, w & cWorld . walls %~ IM.insert wlid newwl
, w & cWorld . lWorld . walls %~ IM.insert wlid newwl
& insertWallInZones newwl
)
where
newwl = wl{_wlID = wlid}
wlid = IM.newKey $ _walls (_cWorld w)
wlid = IM.newKey $ w ^. cWorld . lWorld . walls --_walls (_cWorld w)
+6 -6
View File
@@ -14,9 +14,9 @@ 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 . machines . ix mcid . mcDamage .:~ dt
BlockPart blid -> w' & cWorld . blocks . ix blid . blHP -~ x & maybeDestroyBlock blid
DoorPart drid -> w' & cWorld . doors . ix drid . drHP -~ x & maybeDestroyDoor drid
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 = dt' ^. dmAmount
@@ -24,16 +24,16 @@ damageWall dt wl w = case _wlStructure wl of
-- block destruction is convoluted...
maybeDestroyBlock :: Int -> World -> World
maybeDestroyBlock blid w = case w ^? cWorld . blocks . ix blid of
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 . doors . ix drid of
maybeDestroyDoor drid w = case w ^? cWorld . lWorld . doors . ix drid of
Just dr | _drHP dr < 1 -> destroyDoor dr w
_ -> w
damageBlocksBy :: Int -> Wall -> World -> World
damageBlocksBy x wl = case wl ^? wlStructure . wsBlock of
Just blid -> cWorld . blocks . ix blid . blHP -~ x
Just blid -> cWorld . lWorld . blocks . ix blid . blHP -~ x
Nothing -> id
+1 -1
View File
@@ -68,7 +68,7 @@ glassWallDamage dm wl w =
where
mbl = do
blid <- wl ^? wlStructure . wsBlock
w ^? cWorld . blocks . ix blid
w ^? cWorld . lWorld . blocks . ix blid
d :: Int
d = max 1 $ maybe 1 (subtract 1 . _blHP) mbl
a :: Int -> (World -> World) -> World -> (World, Damage)
+5 -4
View File
@@ -12,17 +12,18 @@ import qualified IntMapHelp as IM
deleteWallID :: Int -> World -> World
deleteWallID i w =
w & cWorld . walls %~ IM.delete i
w & cWorld . lWorld . walls %~ IM.delete i
& deleteWallFromZones wl
where
wl = _walls (_cWorld w) IM.! i
--wl = _walls (_cWorld w) IM.! i
wl = w ^?! cWorld . lWorld . walls . ix i
deleteWall :: Wall -> World -> World
deleteWall wl =
(cWorld . walls %~ IM.delete i)
(cWorld . lWorld . walls %~ IM.delete i)
. deleteWallFromZones wl
where
i = _wlID wl
deleteWallIDs :: IS.IntSet -> World -> World
deleteWallIDs is w = foldl' (flip deleteWall) w $ IM.restrictKeys (_walls (_cWorld w)) is
deleteWallIDs is w = foldl' (flip deleteWall) w $ IM.restrictKeys (w ^. cWorld . lWorld . walls) is
+7 -7
View File
@@ -15,21 +15,20 @@ import Dodge.Base
import Dodge.Data.World
import Dodge.Wall.Zone
import Geometry
import qualified IntMapHelp as IM
moveWallIDUnsafe :: Int -> (Point2, Point2) -> World -> World
moveWallIDUnsafe wlid wlline w = case w ^? cWorld . walls . ix wlid of
moveWallIDUnsafe wlid wlline w = case w ^? cWorld . lWorld . walls . ix wlid of
Nothing -> error "tried moving nonexistant wall"
Just wl -> moveWall wlid wl wlline w
moveWallID :: Int -> (Point2, Point2) -> World -> World
moveWallID wlid wlline w = case w ^? cWorld . walls . ix wlid of
moveWallID wlid wlline w = case w ^? cWorld . lWorld . walls . ix wlid of
Nothing -> w
Just wl -> moveWall wlid wl wlline w
moveWall :: Int -> Wall -> (Point2, Point2) -> World -> World
moveWall wlid wl wlline w =
w & cWorld . walls . ix wlid .~ newwl
w & cWorld . lWorld . walls . ix wlid .~ newwl
& deleteWallFromZones wl
& insertWallInZones newwl
where
@@ -37,18 +36,19 @@ moveWall wlid wl wlline w =
translateWallID :: Int -> Point2 -> World -> World
translateWallID wlid p w = fromMaybe w $ do
oldwl <- w ^? cWorld . walls . ix wlid
oldwl <- w ^? cWorld . lWorld . walls . ix wlid
let newwl = oldwl & wlLine . each +~ p
return $
w
& cWorld . walls . ix wlid .~ newwl
& cWorld . lWorld . walls . ix wlid .~ newwl
& deleteWallFromZones oldwl
& insertWallInZones newwl
moveWallIDToward :: Int -> Float -> (Point2, Point2) -> World -> World
moveWallIDToward wlid speed ep w = moveWall wlid wl newwlline w
where
wl = _walls (_cWorld w) IM.! wlid
--wl = _walls (_cWorld w) IM.! wlid
wl = w ^?! cWorld . lWorld . walls . ix wlid
newwlline = mvPs speed ep (_wlLine wl)
mvP :: Float -> Point2 -> Point2 -> Point2
+2 -2
View File
@@ -7,7 +7,7 @@ import Dodge.Zoning.Wall
-- need to verify that this not only inserts but also overwrites (updates) any
-- already existing walls
insertWallInZones :: Wall -> World -> World
insertWallInZones wl = cWorld . wlZoning %~ zoneWall wl
insertWallInZones wl = cWorld . lWorld . wlZoning %~ zoneWall wl
--insertWallInZones wl = wlZoning %~ updateZoning (IM.insert (_wlID wl)) wl
--insertWallInZones wl = wlZoning .updatets
@@ -16,6 +16,6 @@ insertWallInZones wl = cWorld . wlZoning %~ zoneWall wl
-- doinsert wlzns (V2 x y) = insertIMInZone x y (_wlID wl) wl wlzns
deleteWallFromZones :: Wall -> World -> World
deleteWallFromZones wl = cWorld . wlZoning %~ deZoneWall wl
deleteWallFromZones wl = cWorld . lWorld . wlZoning %~ deZoneWall wl
-- %~ flip (foldl' (flip $ \(a,b) updateeIMInZone a b (_wlID wl))) (zoneOfWall wl)