This commit is contained in:
2021-10-19 15:13:41 +01:00
parent 1f8b4b8565
commit 982c8d81e1
12 changed files with 22 additions and 62 deletions
+11 -7
View File
@@ -15,7 +15,6 @@ import Dodge.Creature.Perception.Data
import Dodge.Creature.Memory.Data import Dodge.Creature.Memory.Data
import Dodge.Data.SoundOrigin import Dodge.Data.SoundOrigin
import Dodge.Data.DamageType import Dodge.Data.DamageType
import Dodge.Zone.Data
import Dodge.Config.Data import Dodge.Config.Data
import Dodge.Config.KeyConfig import Dodge.Config.KeyConfig
import Dodge.Item.Attachment.Data import Dodge.Item.Attachment.Data
@@ -57,7 +56,7 @@ data World = World
, _props :: IM.IntMap Prop , _props :: IM.IntMap Prop
, _particles :: ![Particle] , _particles :: ![Particle]
, _walls :: !(IM.IntMap Wall) , _walls :: !(IM.IntMap Wall)
, _doors :: IM.IntMap Door' , _doors :: IM.IntMap Door
, _wallsZone :: Zone (IM.IntMap Wall) , _wallsZone :: Zone (IM.IntMap Wall)
, _forceFields :: IM.IntMap ForceField , _forceFields :: IM.IntMap ForceField
, _floorItems :: IM.IntMap FloorItem , _floorItems :: IM.IntMap FloorItem
@@ -80,7 +79,7 @@ data World = World
, _pathPoints :: ~(IM.IntMap (IM.IntMap [(Int,Point2)])) , _pathPoints :: ~(IM.IntMap (IM.IntMap [(Int,Point2)]))
, _savedWorlds :: M.Map SaveSlot World , _savedWorlds :: M.Map SaveSlot World
, _menuLayers :: [ScreenLayer] , _menuLayers :: [ScreenLayer]
, _worldTriggers :: S.Set WorldTrigger , _worldFlags :: S.Set WorldFlag
, _carteDisplay :: !Bool , _carteDisplay :: !Bool
, _carteCenter :: !Point2 , _carteCenter :: !Point2
, _carteZoom :: !Float , _carteZoom :: !Float
@@ -236,7 +235,7 @@ data CrMvType
, _mvTurnJit :: Float , _mvTurnJit :: Float
, _mvAimSpeed :: Float -> Float , _mvAimSpeed :: Float -> Float
} }
data WorldTrigger data WorldFlag
= ResetLevel Int = ResetLevel Int
| GameOver | GameOver
deriving (Eq,Ord) deriving (Eq,Ord)
@@ -536,12 +535,12 @@ data Prop
, _pjTimer :: Int , _pjTimer :: Int
} }
data Either3 a b c = E3x1 a | E3x2 b | E3x3 c data Either3 a b c = E3x1 a | E3x2 b | E3x3 c
data Door' = Door' data Door = Door
{ _drID :: Int { _drID :: Int
, _drWallIDs :: [Int] , _drWallIDs :: [Int]
, _drStatus :: DoorStatus , _drStatus :: DoorStatus
, _drTrigger :: World -> Bool , _drTrigger :: World -> Bool
, _drMech :: Door' -> World -> World , _drMech :: Door -> World -> World
} }
data DoorStatus = DoorOpen | DoorClosed | DoorHalfway | DoorInt Int data DoorStatus = DoorOpen | DoorClosed | DoorHalfway | DoorInt Int
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)
@@ -736,6 +735,10 @@ data Goal
| Kill Int | Kill Int
| SentinelAt Point2 Float | SentinelAt Point2 Float
newtype Zone a = Zone
{ _znObjects :: IM.IntMap (IM.IntMap a)
}
makeLenses ''World makeLenses ''World
makeLenses ''Cloud makeLenses ''Cloud
makeLenses ''Creature makeLenses ''Creature
@@ -761,7 +764,8 @@ makeLenses ''Action
makeLenses ''CrGroupParams makeLenses ''CrGroupParams
makeLenses ''CrMvType makeLenses ''CrMvType
makeLenses ''Intention makeLenses ''Intention
makeLenses ''Door' makeLenses ''Door
makeLenses ''Zone
numColor :: Int -> Color numColor :: Int -> Color
numColor 0 = toV4 (1,0,0,1) numColor 0 = toV4 (1,0,0,1)
numColor 1 = toV4 (0,1,0,1) numColor 1 = toV4 (0,1,0,1)
+1 -2
View File
@@ -2,7 +2,6 @@ module Dodge.Default.World
where where
import Dodge.Data import Dodge.Data
import Dodge.Base import Dodge.Base
import Dodge.Zone.Data
import Dodge.Config.Data import Dodge.Config.Data
import Dodge.Config.KeyConfig import Dodge.Config.KeyConfig
import Dodge.Item.Data import Dodge.Item.Data
@@ -54,7 +53,7 @@ defaultWorld = World
, _decorations = IM.empty , _decorations = IM.empty
, _savedWorlds = M.empty , _savedWorlds = M.empty
, _menuLayers = [] , _menuLayers = []
, _worldTriggers = S.empty , _worldFlags = S.empty
, _clickMousePos = V2 0 0 , _clickMousePos = V2 0 0
, _pathGraph = Data.Graph.Inductive.Graph.empty , _pathGraph = Data.Graph.Inductive.Graph.empty
, _pathGraphP = [] , _pathGraphP = []
-5
View File
@@ -1,5 +0,0 @@
module Dodge.DepthFirst
where
--dfs :: (a -> Bool) -> (a -> [a]) -> a -> Maybe a
--dfs cond f x
+2 -2
View File
@@ -85,5 +85,5 @@ initialRoomTree = do
t' t'
shiftExpandTree . expandTreeBy id <$> mapM annoToRoomTree t shiftExpandTree . expandTreeBy id <$> mapM annoToRoomTree t
levx :: RandomGen g => State g [Room] levx :: RandomGen g => Int -> State g [Room]
levx = untilJust initialRoomTree levx _ = untilJust initialRoomTree
+1 -1
View File
@@ -33,7 +33,7 @@ firstWorld = do
-- i <- randomRIO (0,5000) -- i <- randomRIO (0,5000)
let i = 2 let i = 2
putStrLn $ "Seed for level generation: " ++ show ( i :: Int) putStrLn $ "Seed for level generation: " ++ show ( i :: Int)
return $ generateLevelFromRoomList levx $ initialWorld {_randGen = mkStdGen i} return $ generateLevelFromRoomList (levx 1) $ initialWorld {_randGen = mkStdGen i}
initialWorld :: World initialWorld :: World
initialWorld = defaultWorld initialWorld = defaultWorld
+4 -6
View File
@@ -56,7 +56,7 @@ putDoor
putDoor col cond pss w = (drid, addWalls w & doors %~ addDoor) putDoor col cond pss w = (drid, addWalls w & doors %~ addDoor)
where where
drid = IM.newKey $ _doors w drid = IM.newKey $ _doors w
addDoor = IM.insert drid $ Door' addDoor = IM.insert drid $ Door
{ _drID = drid { _drID = drid
, _drWallIDs = wlids , _drWallIDs = wlids
, _drStatus = DoorInt 0 , _drStatus = DoorInt 0
@@ -77,7 +77,7 @@ putDoor col cond pss w = (drid, addWalls w & doors %~ addDoor)
} }
-- TODO use vector instead of list, perhaps also memoisation of rectanglePairs -- TODO use vector instead of list, perhaps also memoisation of rectanglePairs
-- perhaps also remove use of DoorInt in favour of DoorOpen/DoorClosed -- perhaps also remove use of DoorInt in favour of DoorOpen/DoorClosed
doorMechanismStepwise :: Int -> Int -> [Int] -> [(Point2,Point2)] -> Door' -> World -> World doorMechanismStepwise :: Int -> Int -> [Int] -> [(Point2,Point2)] -> Door -> World -> World
doorMechanismStepwise nsteps drid wlids pss dr w doorMechanismStepwise nsteps drid wlids pss dr w
| toOpen = case _drStatus dr of | toOpen = case _drStatus dr of
DoorInt x | x == nsteps -> w DoorInt x | x == nsteps -> w
@@ -99,9 +99,8 @@ doorMechanismStepwise nsteps drid wlids pss dr w
& (\w'' -> foldr (changeZonedWall (wlLine .~ ps) wlid) w'' (zoneps cps)) & (\w'' -> foldr (changeZonedWall (wlLine .~ ps) wlid) w'' (zoneps cps))
-- it is not at all clear that the zoning selects the correct walls -- it is not at all clear that the zoning selects the correct walls
-- TODO think about wall zoning, simplify! -- TODO think about wall zoning, simplify!
doorMechanism :: Int -> Float -> [(Int,(Point2,Point2),(Point2,Point2))] -> Door' -> World -> World doorMechanism :: Int -> Float -> [(Int,(Point2,Point2),(Point2,Point2))] -> Door -> World -> World
doorMechanism drid speed wlidOpCps dr w doorMechanism drid speed wlidOpCps dr w
| toOpen && dstatus /= DoorOpen = moveUpdate $ foldl' doOpen w wlidOpCps | toOpen && dstatus /= DoorOpen = moveUpdate $ foldl' doOpen w wlidOpCps
| not toOpen && dstatus /= DoorClosed = moveUpdate $ foldl' doClose w wlidOpCps | not toOpen && dstatus /= DoorClosed = moveUpdate $ foldl' doClose w wlidOpCps
@@ -135,7 +134,7 @@ putSingleDoor isPathable col cond a b speed w = (drid, addWalls w
& doors %~ addDoor) & doors %~ addDoor)
where where
drid = IM.newKey $ _doors w drid = IM.newKey $ _doors w
addDoor = IM.insert drid $ Door' addDoor = IM.insert drid $ Door
{ _drID = drid { _drID = drid
, _drWallIDs = wlids , _drWallIDs = wlids
, _drStatus = DoorClosed , _drStatus = DoorClosed
@@ -155,4 +154,3 @@ putSingleDoor isPathable col cond a b speed w = (drid, addWalls w
shiftedPairs = map (bimap shiftLeft shiftLeft) pairs shiftedPairs = map (bimap shiftLeft shiftLeft) pairs
shiftLeft = (+.+ (a -.- b)) shiftLeft = (+.+ (a -.- b))
wlids = take 4 [IM.newKey $ _walls w ..] wlids = take 4 [IM.newKey $ _walls w ..]
+1 -1
View File
@@ -162,7 +162,7 @@ startNewGame w = Just $ w
& worldEvents .~ const aNewGame & worldEvents .~ const aNewGame
where where
aNewGame :: World aNewGame :: World
aNewGame = updateFramebufferSize $ generateLevelFromRoomList levx $ initialWorld aNewGame = updateFramebufferSize $ generateLevelFromRoomList (levx 1) $ initialWorld
& randGen .~ _randGen w & randGen .~ _randGen w
& config .~ _config w & config .~ _config w
& preloadData .~ _preloadData w & preloadData .~ _preloadData w
+2 -4
View File
@@ -14,13 +14,12 @@ import Dodge.WorldEvent.Explosion
import Control.Lens import Control.Lens
import Control.Monad.State import Control.Monad.State
import System.Random import System.Random
import qualified Data.Set as S
telRoomLev telRoomLev
:: RandomGen g :: RandomGen g
=> Int -- ^ Level number to teleport to => Int -- ^ Level number to teleport to
-> State g Room -> State g Room
telRoomLev i = do telRoomLev _ = do
w <- state $ randomR (200,300) w <- state $ randomR (200,300)
h <- state $ randomR (200,300) h <- state $ randomR (200,300)
return $ roomRectAutoLinks w h & rmPS .~ return $ roomRectAutoLinks w h & rmPS .~
@@ -38,6 +37,5 @@ telRoomLev i = do
} }
ppFootprint = rectNSEW 20 (-20) 20 (-20) ppFootprint = rectNSEW 20 (-20) 20 (-20)
levelReset pp w levelReset pp w
| dist (_crPos $ you w) (_ppPos pp) < 20 = makeExplosionAt (_ppPos pp) $ | dist (_crPos $ you w) (_ppPos pp) < 20 = makeExplosionAt (_ppPos pp) w
w & worldTriggers %~ S.insert (ResetLevel i)
| otherwise = w | otherwise = w
-4
View File
@@ -1,4 +0,0 @@
module Dodge.TransparencyEffects
where
-16
View File
@@ -7,7 +7,6 @@ module Dodge.Update
) where ) where
import Dodge.Data import Dodge.Data
import Dodge.Menu import Dodge.Menu
import Dodge.Zone.Data
import Dodge.Config.Data import Dodge.Config.Data
import Dodge.Base import Dodge.Base
import Dodge.Zone import Dodge.Zone
@@ -16,9 +15,6 @@ import Dodge.LevelGen.Block
import Dodge.Update.Camera import Dodge.Update.Camera
import Dodge.SoundLogic import Dodge.SoundLogic
import Dodge.Inventory import Dodge.Inventory
import Dodge.Initialisation
import Dodge.Layout
import Dodge.Floor
import Geometry import Geometry
import Geometry.Vector3D import Geometry.Vector3D
@@ -52,7 +48,6 @@ functionalUpdate w = case _menuLayers w of
(_ : _) -> w (_ : _) -> w
[] -> checkEndGame [] -> checkEndGame
. updateRadialDistortions . updateRadialDistortions
. updateTriggers
. ppEvents . ppEvents
. updateCamera . updateCamera
. colCrsWalls . colCrsWalls
@@ -104,17 +99,6 @@ decreaseBulge (a,b,c,v)
| v < 1 = Just (a,b,c,min 1 (v + 0.05) ) | v < 1 = Just (a,b,c,min 1 (v + 0.05) )
| otherwise = Nothing | otherwise = Nothing
updateTriggers :: World -> World
updateTriggers w
| ResetLevel 1 `S.member` _worldTriggers w = generateLevelFromRoomList levx $ initialWorld
& randGen .~ _randGen w
& config .~ _config w
& menuLayers .~ []
& creatures . ix 0 .~ cr
| otherwise = w
where
cr = _creatures w IM.! 0 & crPos .~ V2 0 0
updateLightSources :: World -> World updateLightSources :: World -> World
updateLightSources w = over tempLightSources f w updateLightSources w = over tempLightSources f w
where where
-2
View File
@@ -17,11 +17,9 @@ module Dodge.Zone
, wallsNearZones , wallsNearZones
, zoneOfSight , zoneOfSight
, flattenIMIMIM , flattenIMIMIM
, module Dodge.Zone.Data
) )
where where
import Dodge.Data import Dodge.Data
import Dodge.Zone.Data
import Dodge.Base.Window import Dodge.Base.Window
import Geometry import Geometry
import Geometry.Zone import Geometry.Zone
-12
View File
@@ -1,12 +0,0 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
module Dodge.Zone.Data
where
import Control.Lens
import qualified Data.IntMap.Strict as IM
newtype Zone a = Zone
{ _znObjects :: IM.IntMap (IM.IntMap a)
}
makeLenses ''Zone