about summary refs log tree commit diff stats
path: root/Fallen/Map
diff options
context:
space:
mode:
Diffstat (limited to 'Fallen/Map')
-rw-r--r--Fallen/Map/Dungeon.hs0
-rw-r--r--Fallen/Map/Overworld.hs59
2 files changed, 59 insertions, 0 deletions
diff --git a/Fallen/Map/Dungeon.hs b/Fallen/Map/Dungeon.hs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Fallen/Map/Dungeon.hs
diff --git a/Fallen/Map/Overworld.hs b/Fallen/Map/Overworld.hs new file mode 100644 index 0000000..308aad0 --- /dev/null +++ b/Fallen/Map/Overworld.hs
@@ -0,0 +1,59 @@
1module Fallen.Map.Overworld
2( initOverworld
3) where
4 import Fallen.Map
5 import Fallen.Tiles
6 import System.Random
7 import Fallen.Util
8 import Fallen.Point
9
10 -- initOverworld : generate the overworld
11 initOverworld rg = do
12 let m = emptyMap 150 150 Forest -- create map
13 let m' = fillMapRect 0 0 150 150 Grass m -- fill with grass
14 let (tr,rg1) = randomR (1,50) rg :: (Int,StdGen)
15 let (lr,rg2) = randomR (1,50) rg1 :: (Int,StdGen)
16 let (rr,rg3) = randomR (1,50) rg2 :: (Int,StdGen)
17 let (br,rg4) = randomR (1,50) rg3 :: (Int,StdGen)
18 let (m'',rg5) = roughen 150 tr lr rr br rg4 m' -- add surrounding forest
19 let (clumps,rg6) = randomR (30,60) rg5 :: (Int,StdGen)
20 let (m2,rg7) = drawClumps clumps rg6 m''
21 (m2,rg7)
22
23 -- roughen : create the rough forest edges of the overworld
24 roughen 0 _ _ _ _ rg m = (m,rg)
25 roughen w tr lr rr br rg m = do
26 let m' = fillMapRect (w-1) 0 1 tr Forest m
27 let m'' = fillMapRect 0 (w-1) lr 1 Forest m'
28 let m2 = fillMapRect (150-rr-1) (w-1) rr 1 Forest m''
29 let m2' = fillMapRect (w-1) (150-br-1) 1 br Forest m2
30 let (str,rg1) = randomR (-2,2) rg :: (Int,StdGen)
31 let (slr,rg2) = randomR (-2,2) rg1 :: (Int,StdGen)
32 let (srr,rg3) = randomR (-2,2) rg2 :: (Int,StdGen)
33 let (sbr,rg4) = randomR (-2,2) rg3 :: (Int,StdGen)
34 roughen (w-1) (bound tr str) (bound lr slr) (bound rr srr) (bound br sbr) rg4 m2' where
35 bound r s
36 | r + s < 1 = 1
37 | r + s > 50 = 50
38 | otherwise = r + s
39
40 -- drawClumps : add in clumps of rocks, water, and trees
41 clumpTypes = [Rock, Water, Forest]
42 clumpOver = [Rock, Water, Forest, Grass]
43 drawClumps 0 rg m = (m,rg)
44 drawClumps num rg m = do
45 let (area,rg1) = randomR (1,300) rg :: (Int,StdGen)
46 let (clumpType,rg2) = randomSetElement rg1 clumpTypes
47 let (startPoint,rg3) = randomPoint 0 0 149 149 rg2
48 let (m',rg4) = drawClump area clumpType startPoint m rg3
49 drawClumps (num-1) rg4 m'
50 drawClump 0 clumpType p m rg = (updateMap p clumpType m,rg)
51 drawClump area clumpType p m rg = do
52 let m' = updateMap p clumpType m
53 let legalDirs = legalMoves m' p clumpOver
54 if null legalDirs
55 then (m',rg)
56 else do
57 let (nextDir,rg1) = randomSetElement rg legalDirs
58 let nextPoint = stepInDirection p nextDir
59 drawClump (area-1) clumpType nextPoint m' rg1 \ No newline at end of file