Skip to content
Newer
Older
100644 213 lines (191 sloc) 8.33 KB
2d7f85b @clanehin implemented the SegHopList and optimized Grids with caching
authored
1
eb4b7b8 @clanehin Package move to Roguestar.Lib.
authored
2 module Roguestar.Lib.TerrainData
2689d3a @clanehin working on terrain generator
authored
3 (Biome(..),
4 TerrainPatch(..),
0162fe1 @clanehin Add biome perception and biome protocol query. This will support rend…
authored
5 TerrainGrid,
583286a @clanehin creatures can be in planes, with line of sight rules
authored
6 TerrainGenerationData(..),
a32c608 @clanehin Randomly place recreant factories on the terrain.
authored
7 TerrainPlacement,
8 recreantFactories,
a8e6f0d @clanehin Generate downstairs tiles.
authored
9 stairsUp,
10 stairsDown,
0b12e6a @clanehin work on terrain and HopList
authored
11 generateTerrain,
b80b348 @clanehin Randomize teleport jump landing location when the exact landing locat…
authored
12 difficult_terrains,
13 impassable_terrains)
8bd6b3c @clanehin started psudo-random grid system
authored
14 where
15
eb4b7b8 @clanehin Package move to Roguestar.Lib.
authored
16 import Roguestar.Lib.Grids
0b12e6a @clanehin work on terrain and HopList
authored
17 import Data.List as List
18 import Data.Map as Map
aa32f67 @clanehin Implement terrain affinity.
authored
19 --import Substances hiding (Water)
eb4b7b8 @clanehin Package move to Roguestar.Lib.
authored
20 import Roguestar.Lib.RNG
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
21
8bd6b3c @clanehin started psudo-random grid system
authored
22
24db9a1 @clanehin working on terrain generator
authored
23 -- |
24 -- Most automatically generated surface maps belong to a Biome, representing the kind of terrain
25 -- and plant life that dwells in terrain generated for the map.
26 --
a8e6f0d @clanehin Generate downstairs tiles.
authored
27 data Biome = ShallowDungeon
28 | DeepDungeon
29 | FrozenDungeon
30 | AbyssalDungeon
31 | InfernalDungeon
32 | RockBiome
8bd6b3c @clanehin started psudo-random grid system
authored
33 | IcyRockBiome
34 | GrasslandBiome
a732bed @clanehin Don't allow the sky to render while underground.
authored
35 | ForestBiome
8bd6b3c @clanehin started psudo-random grid system
authored
36 | TundraBiome
bf590d1 @clanehin optimized sight-range engine
authored
37 | DesertBiome
8bd6b3c @clanehin started psudo-random grid system
authored
38 | OceanBiome
0b12e6a @clanehin work on terrain and HopList
authored
39 | MountainBiome
a732bed @clanehin Don't allow the sky to render while underground.
authored
40 | SwampBiome
2d235a1 @clanehin Adds improved "AbstractLocation" model for locations, network of cybo…
authored
41 | PolarBiome
a732bed @clanehin Don't allow the sky to render while underground.
authored
42 deriving (Read,Show,Eq,Ord,Enum,Bounded)
8bd6b3c @clanehin started psudo-random grid system
authored
43
24db9a1 @clanehin working on terrain generator
authored
44 -- |
0162fe1 @clanehin Add biome perception and biome protocol query. This will support rend…
authored
45 -- All static terrain elements are members of TerrainGrid
24db9a1 @clanehin working on terrain generator
authored
46 --
47 -- The only difference between "Deasert" and "Sand" is that where
48 -- "Deasert" and "Water" touch, the map generator will produce
49 -- patches of plantlife (for oasis and shoreline effect).
50 --
8bd6b3c @clanehin started psudo-random grid system
authored
51 data TerrainPatch = RockFace
52 | Rubble
aa32f67 @clanehin Implement terrain affinity.
authored
53 | Ore
8bd6b3c @clanehin started psudo-random grid system
authored
54 | RockyGround
55 | Dirt
56 | Grass
57 | Sand
bf590d1 @clanehin optimized sight-range engine
authored
58 | Desert -- exactly like sand, except from the terrain generator's point of view: oasis can appear
8bd6b3c @clanehin started psudo-random grid system
authored
59 | Forest
60 | DeepForest
61 | Water
62 | DeepWater
63 | Ice
a732bed @clanehin Don't allow the sky to render while underground.
authored
64 | Lava
65 | Glass -- what sand becomes when struck by intense heat
66 | RecreantFactory
a8e6f0d @clanehin Generate downstairs tiles.
authored
67 | Upstairs
68 | Downstairs
24db9a1 @clanehin working on terrain generator
authored
69 deriving (Read,Show,Eq,Ord)
8bd6b3c @clanehin started psudo-random grid system
authored
70
1869b6e @clanehin Database is now ready to store Plane and Creature data, soon play a s…
authored
71 data TerrainGenerationData = TerrainGenerationData
a732bed @clanehin Don't allow the sky to render while underground.
authored
72 { tg_smootheness :: Integer,
73 tg_biome :: Biome,
74 tg_placements :: [TerrainPlacement] }
75 deriving (Read,Show)
1869b6e @clanehin Database is now ready to store Plane and Creature data, soon play a s…
authored
76
a32c608 @clanehin Randomly place recreant factories on the terrain.
authored
77 data TerrainPlacement = TerrainPlacement {
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
78 placement_sources :: [(Double,TerrainPatch)],
a32c608 @clanehin Randomly place recreant factories on the terrain.
authored
79 placement_replacements :: [(Integer,TerrainPatch)],
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
80 placement_seed :: Integer,
81 placement_blob :: Blob }
a32c608 @clanehin Randomly place recreant factories on the terrain.
authored
82 deriving (Read,Show)
83
0162fe1 @clanehin Add biome perception and biome protocol query. This will support rend…
authored
84 placeTerrain :: TerrainPlacement -> TerrainGrid -> TerrainGrid
a32c608 @clanehin Randomly place recreant factories on the terrain.
authored
85 placeTerrain terrain_placement =
86 arbitraryReplaceGrid (placement_sources terrain_placement)
87 (placement_replacements terrain_placement)
a732bed @clanehin Don't allow the sky to render while underground.
authored
88 (placement_seed terrain_placement)
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
89 (placement_blob terrain_placement)
a32c608 @clanehin Randomly place recreant factories on the terrain.
authored
90
91 recreantFactories :: Integer -> TerrainPlacement
92 recreantFactories seed = TerrainPlacement {
a732bed @clanehin Don't allow the sky to render while underground.
authored
93 placement_sources =
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
94 [(1/2,Ice),
95 (1/10,Sand),
96 (1/2,Desert),
97 (1/5,Dirt),
98 (1/1,Glass),
99 (1/20,Grass),
100 (1/100,Forest),
101 (1/2,RockyGround)],
a732bed @clanehin Don't allow the sky to render while underground.
authored
102 placement_replacements =
a32c608 @clanehin Randomly place recreant factories on the terrain.
authored
103 [(1,RecreantFactory)],
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
104 placement_seed = seed,
105 placement_blob = ConeBlob (0,0) 100 }
a32c608 @clanehin Randomly place recreant factories on the terrain.
authored
106
a8e6f0d @clanehin Generate downstairs tiles.
authored
107 stairsUp :: Integer -> Integer -> TerrainPlacement
108 stairsUp seed depth = TerrainPlacement {
109 placement_sources =
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
110 [(1/(15+3*realToFrac depth),RockyGround),
111 (1/(25+5*realToFrac depth),Ice),
112 (1/(50+10*realToFrac depth),Water),
113 (1/(75+15*realToFrac depth),RockFace)],
a8e6f0d @clanehin Generate downstairs tiles.
authored
114 placement_replacements =
115 [(1,Upstairs)],
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
116 placement_seed = seed,
117 placement_blob = UnitBlob }
a8e6f0d @clanehin Generate downstairs tiles.
authored
118
119 stairsDown :: Integer -> Integer -> TerrainPlacement
120 stairsDown seed depth = TerrainPlacement {
121 placement_sources =
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
122 [(1/(15+4*realToFrac depth),RockyGround),
123 (1/(25+5*realToFrac depth),Ice),
124 (1/(75+3*realToFrac depth),RockFace),
125 (1/(40+10*realToFrac depth),Dirt),
126 (1/60,Grass)],
a8e6f0d @clanehin Generate downstairs tiles.
authored
127 placement_replacements =
128 [(1,Downstairs)],
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
129 placement_seed = seed,
130 placement_blob = UnitBlob }
a8e6f0d @clanehin Generate downstairs tiles.
authored
131
583286a @clanehin creatures can be in planes, with line of sight rules
authored
132 -- |
133 -- A list of TerrainPatches that are considered "difficult", either for traveling
134 -- or for constructing buildings.
135 --
136 difficult_terrains :: [TerrainPatch]
b80b348 @clanehin Randomize teleport jump landing location when the exact landing locat…
authored
137 difficult_terrains = impassable_terrains ++
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
138 [Water,DeepWater,Ice,Lava]
b80b348 @clanehin Randomize teleport jump landing location when the exact landing locat…
authored
139
140 -- |
141 -- A list of TerrainPatches that are considered "impassable" for traveling.
142 --
143 impassable_terrains :: [TerrainPatch]
144 impassable_terrains = [RockFace,Forest,DeepForest]
583286a @clanehin creatures can be in planes, with line of sight rules
authored
145
0b12e6a @clanehin work on terrain and HopList
authored
146 terrainFrequencies :: Biome -> [(Integer,TerrainPatch)]
a8e6f0d @clanehin Generate downstairs tiles.
authored
147 terrainFrequencies ShallowDungeon = [(40,RockFace),(50,RockyGround),(5,Sand),(5,Dirt)]
148 terrainFrequencies DeepDungeon = [(50,RockFace),(25,Rubble),(25,RockyGround)]
149 terrainFrequencies FrozenDungeon = [(75,RockFace),(5,Rubble),(10,RockyGround),(10,Ice)]
150 terrainFrequencies AbyssalDungeon = [(60,RockFace),(10,Rubble),(10,RockyGround),(20,Water)]
151 terrainFrequencies InfernalDungeon = [(70,RockFace),(15,Rubble),(15,Lava)]
a32c608 @clanehin Randomly place recreant factories on the terrain.
authored
152 terrainFrequencies RockBiome = [(15,RockFace),(15,Rubble),(55,RockyGround),(15,Sand)]
153 terrainFrequencies IcyRockBiome = [(10,RockFace),(10,Rubble),(20,RockyGround),(60,Ice)]
154 terrainFrequencies GrasslandBiome = [(5,RockFace),(5,RockyGround),(10,Dirt),(10,Sand),(10,Forest),(10,Water),(50,Grass)]
155 terrainFrequencies ForestBiome = [(10,RockFace),(10,RockyGround),(10,Dirt),(10,Water),(10,Grass),(25,Forest),(25,DeepForest)]
156 terrainFrequencies TundraBiome = [(10,RockFace),(10,RockyGround),(10,Sand),(10,Water),(60,Ice)]
157 terrainFrequencies DesertBiome = [(10,RockFace),(10,RockyGround),(9,Grass),(1,Water),(70,Desert)]
158 terrainFrequencies OceanBiome = [(5,RockyGround),(10,Sand),(5,Grass),(5,Forest),(25,Water),(50,DeepWater)]
159 terrainFrequencies MountainBiome = [(50,RockFace),(25,RockyGround),(5,Rubble),(5,Sand),(5,Grass),(5,Forest),(5,Water)]
160 terrainFrequencies SwampBiome = [(40,Forest),(50,Water),(5,Sand),(5,Grass)]
2d235a1 @clanehin Adds improved "AbstractLocation" model for locations, network of cybo…
authored
161 terrainFrequencies PolarBiome = [(40,Ice),(30,Water),(5,DeepWater),(4,RockyGround),(1,RockFace)]
24db9a1 @clanehin working on terrain generator
authored
162
163 terrainInterpFn :: (TerrainPatch,TerrainPatch) -> [(Integer,TerrainPatch)]
0b12e6a @clanehin work on terrain and HopList
authored
164 terrainInterpFn (a,b) = [(1,a),(1,b)] ++ (terrainInterpRule (a,b)) ++ (terrainInterpRule (b,a))
24db9a1 @clanehin working on terrain generator
authored
165
5057424 @clanehin Terrain tweaks. Forests are sparser, and downstairs available on gras…
authored
166 -- Notice, in terrainInterpFn, we always throw in both terrain patches with a weight of 1.
24db9a1 @clanehin working on terrain generator
authored
167 terrainInterpRule :: (TerrainPatch,TerrainPatch) -> [(Integer,TerrainPatch)]
168 terrainInterpRule (RockFace,RockFace) = []
169 terrainInterpRule (RockFace,RockyGround) = [(3,RockFace),(1,Rubble),(3,RockyGround)]
170 terrainInterpRule (RockFace,x) = [(3,RockFace),(2,Rubble),(1,RockyGround),(1,Sand),(7,x)]
171 terrainInterpRule (Rubble,x) = [(1,Rubble),(2,Sand),(2,Dirt),(5,x)]
172 terrainInterpRule (DeepWater,DeepWater) = []
0b12e6a @clanehin work on terrain and HopList
authored
173 terrainInterpRule (DeepWater,Water) = [(3,DeepWater)]
24db9a1 @clanehin working on terrain generator
authored
174 terrainInterpRule (DeepWater,_) = [(3,Water)]
5057424 @clanehin Terrain tweaks. Forests are sparser, and downstairs available on gras…
authored
175 terrainInterpRule (DeepForest,DeepForest) = [(1,Grass)]
176 terrainInterpRule (DeepForest,Forest) = [(2,Grass)]
177 terrainInterpRule (DeepForest,_) = [(1,Forest)]
1869b6e @clanehin Database is now ready to store Plane and Creature data, soon play a s…
authored
178 terrainInterpRule (Forest,DeepForest) = []
5057424 @clanehin Terrain tweaks. Forests are sparser, and downstairs available on gras…
authored
179 terrainInterpRule (Forest,Forest) = [(3,Grass)]
180 terrainInterpRule (Forest,_) = [(3,Grass)]
0b12e6a @clanehin work on terrain and HopList
authored
181 terrainInterpRule (Water,Water) = [(20,Water),(1,Sand)]
24db9a1 @clanehin working on terrain generator
authored
182 terrainInterpRule (Water,DeepWater) = []
183 terrainInterpRule (Water,_) = [(1,Sand)]
bf590d1 @clanehin optimized sight-range engine
authored
184 terrainInterpRule (Sand,Desert) = [(1,Grass),(1,Forest)]
2689d3a @clanehin working on terrain generator
authored
185 terrainInterpRule _ = []
24db9a1 @clanehin working on terrain generator
authored
186
187 -- |
188 -- A list of every TerrainPatch that might be created from the terrainFrequencies function.
189 --
190 baseTerrainPatches :: [TerrainPatch]
583286a @clanehin creatures can be in planes, with line of sight rules
authored
191 baseTerrainPatches = nub $ List.map snd $ concatMap terrainFrequencies [minBound..maxBound]
24db9a1 @clanehin working on terrain generator
authored
192
193 terrainInterpMap :: Map (TerrainPatch,TerrainPatch) [(Integer,TerrainPatch)]
194 terrainInterpMap = let terrain_patch_pairs = [(a,b) | a <- baseTerrainPatches, b <- baseTerrainPatches]
aef9297 @clanehin Fix issue with terrain generator / random number generation, make up …
authored
195 interps = List.map terrainInterpFn terrain_patch_pairs
196 in fromList (zip terrain_patch_pairs interps)
2689d3a @clanehin working on terrain generator
authored
197
0162fe1 @clanehin Add biome perception and biome protocol query. This will support rend…
authored
198 type TerrainGrid = Grid TerrainPatch
2689d3a @clanehin working on terrain generator
authored
199
200 -- |
0b12e6a @clanehin work on terrain and HopList
authored
201 -- Generates a random terrain map. The Biome indicates determines what TerrainPatches
202 -- are generated. The second parameter is an Integer that indicates the smootheness of the
203 -- generated terrain. Finally, a random Integer stream is needed to provide the random data
204 -- to generate the terrain.
e7f7d9a @clanehin began implementation of InsidenessMap
authored
205 --
0162fe1 @clanehin Add biome perception and biome protocol query. This will support rend…
authored
206 generateTerrain :: TerrainGenerationData -> [Integer] -> TerrainGrid
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
207 generateTerrain tg rands = flip (List.foldr placeTerrain) (tg_placements tg) $
1869b6e @clanehin Database is now ready to store Plane and Creature data, soon play a s…
authored
208 generateGrid (terrainFrequencies (tg_biome tg))
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
209 terrainInterpMap
210 (tg_smootheness tg)
211 rands
212
Something went wrong with that request. Please try again.