ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/maze_gen.C
(Generate patch)

Comparing deliantra/server/random_maps/maze_gen.C (file contents):
Revision 1.16 by root, Sat Nov 7 18:32:45 2009 UTC vs.
Revision 1.18 by root, Sun Jun 27 09:54:36 2010 UTC

92{ 92{
93 int index = rmg_rndm (wall_free_size); 93 int index = rmg_rndm (wall_free_size);
94 94
95 *x = wall_x_list[index]; 95 *x = wall_x_list[index];
96 *y = wall_y_list[index]; 96 *y = wall_y_list[index];
97
97 /* write the last array point here */ 98 /* write the last array point here */
98 wall_x_list[index] = wall_x_list[wall_free_size - 1]; 99 wall_x_list[index] = wall_x_list[wall_free_size - 1];
99 wall_y_list[index] = wall_y_list[wall_free_size - 1]; 100 wall_y_list[index] = wall_y_list[wall_free_size - 1];
100 wall_free_size--; 101 wall_free_size--;
101} 102}
111 int count = 0; /* # elements in dirlist */ 112 int count = 0; /* # elements in dirlist */
112 113
113 /* look up */ 114 /* look up */
114 if (yc < ysize - 2 && xc > 2 && xc < xsize - 2) /* it is valid to look up */ 115 if (yc < ysize - 2 && xc > 2 && xc < xsize - 2) /* it is valid to look up */
115 { 116 {
116 int cleartest = (int) maze[xc][yc + 1] + (int) maze[xc - 1][yc + 1] + (int) maze[xc + 1][yc + 1]; 117 int cleartest = maze[xc][yc + 1] + maze[xc - 1][yc + 1] + maze[xc + 1][yc + 1]
117
118 cleartest += (int) maze[xc][yc + 2] + (int) maze[xc - 1][yc + 2] + (int) maze[xc + 1][yc + 2]; 118 + maze[xc][yc + 2] + maze[xc - 1][yc + 2] + maze[xc + 1][yc + 2];
119 119
120 if (cleartest == 0) 120 if (cleartest == 0)
121 dirlist[count++] = 1; 121 dirlist[count++] = 1;
122 } 122 }
123 123
124 /* look down */ 124 /* look down */
125 if (yc > 2 && xc > 2 && xc < xsize - 2) /* it is valid to look down */ 125 if (yc > 2 && xc > 2 && xc < xsize - 2) /* it is valid to look down */
126 { 126 {
127 int cleartest = (int) maze[xc][yc - 1] + (int) maze[xc - 1][yc - 1] + (int) maze[xc + 1][yc - 1]; 127 int cleartest = maze[xc][yc - 1] + maze[xc - 1][yc - 1] + maze[xc + 1][yc - 1]
128
129 cleartest += (int) maze[xc][yc - 2] + (int) maze[xc - 1][yc - 2] + (int) maze[xc + 1][yc - 2]; 128 + maze[xc][yc - 2] + maze[xc - 1][yc - 2] + maze[xc + 1][yc - 2];
130 129
131 if (cleartest == 0) 130 if (cleartest == 0)
132 dirlist[count++] = 2; 131 dirlist[count++] = 2;
133 } 132 }
134 133
135 /* look right */ 134 /* look right */
136 if (xc < xsize - 2 && yc > 2 && yc < ysize - 2) /* it is valid to look left */ 135 if (xc < xsize - 2 && yc > 2 && yc < ysize - 2) /* it is valid to look left */
137 { 136 {
138 int cleartest = (int) maze[xc + 1][yc] + (int) maze[xc + 1][yc - 1] + (int) maze[xc + 1][yc + 1]; 137 int cleartest = maze[xc + 1][yc] + maze[xc + 1][yc - 1] + maze[xc + 1][yc + 1]
139
140 cleartest += (int) maze[xc + 2][yc] + (int) maze[xc + 2][yc - 1] + (int) maze[xc + 2][yc + 1]; 138 + maze[xc + 2][yc] + maze[xc + 2][yc - 1] + maze[xc + 2][yc + 1];
141 139
142 if (cleartest == 0) 140 if (cleartest == 0)
143 dirlist[count++] = 3; 141 dirlist[count++] = 3;
144 } 142 }
145 143
146 /* look left */ 144 /* look left */
147 if (xc > 2 && yc > 2 && yc < ysize - 2) /* it is valid to look down */ 145 if (xc > 2 && yc > 2 && yc < ysize - 2) /* it is valid to look down */
148 { 146 {
149 int cleartest = (int) maze[xc - 1][yc] + (int) maze[xc - 1][yc - 1] + (int) maze[xc - 1][yc + 1]; 147 int cleartest = maze[xc - 1][yc] + maze[xc - 1][yc - 1] + maze[xc - 1][yc + 1]
150
151 cleartest += (int) maze[xc - 2][yc] + (int) maze[xc - 2][yc - 1] + (int) maze[xc - 2][yc + 1]; 148 + maze[xc - 2][yc] + maze[xc - 2][yc - 1] + maze[xc - 2][yc + 1];
152 149
153 if (cleartest == 0) 150 if (cleartest == 0)
154 dirlist[count++] = 4; 151 dirlist[count++] = 4;
155 } 152 }
156 153
177 174
178 case 4: /* left */ 175 case 4: /* left */
179 *x = xc - 1; 176 *x = xc - 1;
180 *y = yc; 177 *y = yc;
181 break; 178 break;
182
183 default: /* ??? */
184 return -1;
185
186 } 179 }
187 180
188 return 1; 181 return 1;
189} 182}
190 183
197 190
198 /* write a wall here */ 191 /* write a wall here */
199 maze[x][y] = '#'; 192 maze[x][y] = '#';
200 193
201 /* decide if we're going to pick from the wall_free_list */ 194 /* decide if we're going to pick from the wall_free_list */
202 if (rmg_rndm (4) && wall_free_size > 0) 195 if (rmg_rndm (2) && wall_free_size > 0)
203 { 196 {
204 pop_wall_point (&xc, &yc); 197 pop_wall_point (&xc, &yc);
205 fill_maze_full (maze, xc, yc, xsize, ysize); 198 fill_maze_full (maze, xc, yc, xsize, ysize);
206 } 199 }
207 200
208 /* change the if to a while for a complete maze. */ 201 /* change the while to an if for a sparse maze. */
209 while (find_free_point (maze, &xc, &yc, x, y, xsize, ysize) != -1) 202 while (find_free_point (maze, &xc, &yc, x, y, xsize, ysize) != -1)
210 fill_maze_full (maze, xc, yc, xsize, ysize); 203 fill_maze_full (maze, xc, yc, xsize, ysize);
211} 204}
212 205
213/* recursive routine which will fill much of the maze, but will leave 206/* recursive routine which will fill much of the maze, but will leave
219 212
220 /* write a wall here */ 213 /* write a wall here */
221 maze[x][y] = '#'; 214 maze[x][y] = '#';
222 215
223 /* decide if we're going to pick from the wall_free_list */ 216 /* decide if we're going to pick from the wall_free_list */
224 if (rmg_rndm (4) && wall_free_size > 0) 217 if (rmg_rndm (2) && wall_free_size > 0)
225 { 218 {
226 pop_wall_point (&xc, &yc); 219 pop_wall_point (&xc, &yc);
227 fill_maze_sparse (maze, xc, yc, xsize, ysize); 220 fill_maze_sparse (maze, xc, yc, xsize, ysize);
228 } 221 }
229 222
230 /* change the if to a while for a complete maze. */ 223 /* change the if to a while for a complete maze. */
231 if (find_free_point (maze, &xc, &yc, x, y, xsize, ysize) != -1) 224 if (find_free_point (maze, &xc, &yc, x, y, xsize, ysize) != -1)
232 fill_maze_sparse (maze, xc, yc, xsize, ysize); 225 fill_maze_sparse (maze, xc, yc, xsize, ysize);
233} 226}
234 227
235/* the outsize interface routine: accepts sizes, returns a char 228/* the outsize interface routine: accepts sizes, returns a char
236** maze. option is a flag for either a sparse or a full maze. Sparse 229** maze. option is a flag for either a sparse or a full maze. Sparse
237mazes have sizable rooms. option = 1, full, 0, sparse.*/ 230mazes have sizable rooms. option = 1, full, 0, sparse.*/
238void 231void
239maze_gen (Layout maze, int option) 232maze_gen (Layout maze, int full)
240{ 233{
241 maze->clear (); 234 maze->clear ();
242 maze->border (); 235 maze->border ();
243 236
244 /* find how many free wall spots there are */ 237 /* find how many free wall spots there are */
256 { 249 {
257 int i, j; 250 int i, j;
258 251
259 pop_wall_point (&i, &j); 252 pop_wall_point (&i, &j);
260 253
261 if (option) 254 if (full)
262 fill_maze_full (maze, i, j, maze->w, maze->h); 255 fill_maze_full (maze, i, j, maze->w, maze->h);
263 else 256 else
264 fill_maze_sparse (maze, i, j, maze->w, maze->h); 257 fill_maze_sparse (maze, i, j, maze->w, maze->h);
265 } 258 }
266 259
268 261
269 free (wall_x_list); 262 free (wall_x_list);
270 free (wall_y_list); 263 free (wall_y_list);
271} 264}
272 265
266#if 0
267static struct demo
268{
269 demo ()
270 {
271 Layout layout (30, 30);
272 rmg_rndm.seed (time (0));
273
274 for(int i=1;i<10;++i)
275 {
276 maze_gen (layout, 1);
277 layout.print ();
278 }
279 exit (1);
280 }
281} demo;
282#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines