1 |
/* |
2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
* |
4 |
* Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
* Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
6 |
* Copyright (©) 1992,2007 Frank Tore Johansen |
7 |
* |
8 |
* Deliantra is free software: you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
10 |
* the Free Software Foundation, either version 3 of the License, or |
11 |
* (at your option) any later version. |
12 |
* |
13 |
* This program is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
17 |
* |
18 |
* You should have received a copy of the GNU General Public License |
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 |
* |
21 |
* The authors can be reached via e-mail to <support@deliantra.net> |
22 |
*/ |
23 |
|
24 |
/* peterm@langmuir.eecs.berkeley.edu: this function generates a random |
25 |
snake-type layout. |
26 |
|
27 |
input: xsize, ysize; |
28 |
output: a char** array with # and . for closed and open respectively. |
29 |
|
30 |
a char value of 0 represents a blank space: a '#' is |
31 |
a wall. |
32 |
|
33 |
*/ |
34 |
|
35 |
#include <global.h> |
36 |
|
37 |
#include "random_map.h" |
38 |
#include "rproto.h" |
39 |
|
40 |
/* These are some helper functions which help with |
41 |
manipulating a centered onion and turning it into |
42 |
a square spiral */ |
43 |
void |
44 |
make_square_spiral_layout (Layout maze, int options) |
45 |
{ |
46 |
/* generate and allocate a doorless, centered onion */ |
47 |
map_gen_onion (maze, RMOPT_CENTERED | RMOPT_NO_DOORS, 0); |
48 |
|
49 |
int xsize = maze->w; |
50 |
int ysize = maze->h; |
51 |
|
52 |
/* find the layout center. */ |
53 |
int cx = 0; |
54 |
int cy = 0; |
55 |
for (int i = 0; i < xsize; i++) |
56 |
for (int j = 0; j < ysize; j++) |
57 |
if (maze[i][j] == 'C') |
58 |
{ |
59 |
cx = i; |
60 |
cy = j; |
61 |
break; |
62 |
} |
63 |
|
64 |
int tx = cx; |
65 |
int ty = cy; |
66 |
for (;;) |
67 |
{ |
68 |
/* this starts from within a centered onion layer (or between two layers), |
69 |
and looks up until it finds a wall, and then looks right until it |
70 |
finds a vertical wall, i.e., the corner. It sets tx and ty to that. |
71 |
it also starts from tx and ty. */ |
72 |
--ty; |
73 |
|
74 |
/* find the top wall. */ |
75 |
while (maze[tx][ty] != '#') |
76 |
--ty; |
77 |
|
78 |
/* proceed right until a corner is detected */ |
79 |
while (maze[tx][ty + 1] != '#') |
80 |
++tx; |
81 |
|
82 |
/* tx and ty should now be the top-right corner of the onion layer */ |
83 |
if (ty < 2 || tx < 2 || tx > xsize - 2 || ty > ysize - 2) |
84 |
break; |
85 |
|
86 |
make_wall (maze, tx, ty - 1, 1); /* make a vertical wall with a door */ |
87 |
|
88 |
maze[tx][ty - 1] = '#'; /* convert the door that make_wall puts here to a wall */ |
89 |
maze[tx - 1][ty] = 'D'; /* make a doorway out of this layer */ |
90 |
|
91 |
/* walk left until we find the top-left corner */ |
92 |
while (tx > 2 && maze[tx - 1][ty]) |
93 |
--tx; |
94 |
|
95 |
make_wall (maze, tx - 1, ty, 0); /* make a horizontal wall with a door */ |
96 |
|
97 |
/* walk down until we find the bottom-left corner */ |
98 |
while (ty + 1 < ysize && maze[tx][ty + 1]) |
99 |
++ty; |
100 |
|
101 |
make_wall (maze, tx, ty + 1, 1); /* make a vertical wall with a door */ |
102 |
|
103 |
/* walk rightuntil we find the bottom-right corner */ |
104 |
while (tx + 1 < xsize && maze[tx + 1][ty]) |
105 |
++tx; |
106 |
|
107 |
make_wall (maze, tx + 1, ty, 0); /* make a horizontal wall with a door */ |
108 |
++tx; /* set up for next layer. */ |
109 |
} |
110 |
|
111 |
/* place the exits. */ |
112 |
|
113 |
if (rmg_rndm (2)) |
114 |
{ |
115 |
maze[cx][cy] = '>'; |
116 |
maze[xsize - 2][1] = '<'; |
117 |
} |
118 |
else |
119 |
{ |
120 |
maze[cx][cy] = '<'; |
121 |
maze[xsize - 2][1] = '>'; |
122 |
} |
123 |
} |
124 |
|