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.8 by root, Fri Apr 11 21:09:53 2008 UTC vs.
Revision 1.9 by root, Mon Apr 14 22:41:17 2008 UTC

32int wall_chance; 32int wall_chance;
33 33
34/* the outsize interface routine: accepts sizes, returns a char 34/* the outsize interface routine: accepts sizes, returns a char
35** maze. option is a flag for either a sparse or a full maze. Sparse 35** maze. option is a flag for either a sparse or a full maze. Sparse
36mazes have sizable rooms. option = 1, full, 0, sparse.*/ 36mazes have sizable rooms. option = 1, full, 0, sparse.*/
37 37void
38Maze 38maze_gen (Maze maze, int option)
39maze_gen (int xsize, int ysize, int option)
40{ 39{
41 int i, j; 40 maze->clear ();
42 41 maze->border ();
43 Maze maze (xsize, ysize);
44
45 /* write the outer walls */
46 for (i = 0; i < xsize; i++) maze[i][0] = maze[i][ysize - 1] = '#';
47 for (j = 0; j < ysize; j++) maze[0][j] = maze[xsize - 1][j] = '#';
48 42
49 /* find how many free wall spots there are */ 43 /* find how many free wall spots there are */
50 wall_free_size = 2 * (xsize - 4) + 2 * (ysize - 4); 44 wall_free_size = 2 * (maze->w - 4) + 2 * (maze->h - 4);
51 45
52 make_wall_free_list (xsize, ysize); 46 make_wall_free_list (maze->w, maze->h);
53 47
54 /* return the empty maze */ 48 /* return the empty maze */
55 if (wall_free_size <= 0) 49 if (wall_free_size <= 0)
56 return maze; 50 return;
57 51
58 /* recursively generate the walls of the maze */ 52 /* recursively generate the walls of the maze */
59 /* first pop a random starting point */ 53 /* first pop a random starting point */
60 while (wall_free_size > 0) 54 while (wall_free_size > 0)
61 { 55 {
56 int i, j;
57
62 pop_wall_point (&i, &j); 58 pop_wall_point (&i, &j);
63 59
64 if (option) 60 if (option)
65 fill_maze_full (maze, i, j, xsize, ysize); 61 fill_maze_full (maze, i, j, maze->w, maze->h);
66 else 62 else
67 fill_maze_sparse (maze, i, j, xsize, ysize); 63 fill_maze_sparse (maze, i, j, maze->w, maze->h);
68 } 64 }
69 65
70 /* clean up our intermediate data structures. */ 66 /* clean up our intermediate data structures. */
71 67
72 free (wall_x_list); 68 free (wall_x_list);
73 free (wall_y_list); 69 free (wall_y_list);
74
75 return maze;
76} 70}
77 71
78/* the free wall points are those outer points which aren't corners or 72/* the free wall points are those outer points which aren't corners or
79 near corners, and don't have a maze wall growing out of them already. */ 73 near corners, and don't have a maze wall growing out of them already. */
80void 74void
150 dirlist[count] = 1; 144 dirlist[count] = 1;
151 count++; 145 count++;
152 } 146 }
153 } 147 }
154 148
155
156 /* look down */ 149 /* look down */
157 if (yc > 2 && xc > 2 && xc < xsize - 2) /* it is valid to look down */ 150 if (yc > 2 && xc > 2 && xc < xsize - 2) /* it is valid to look down */
158 { 151 {
159 int cleartest = (int) maze[xc][yc - 1] + (int) maze[xc - 1][yc - 1] + (int) maze[xc + 1][yc - 1]; 152 int cleartest = (int) maze[xc][yc - 1] + (int) maze[xc - 1][yc - 1] + (int) maze[xc + 1][yc - 1];
160 153
165 dirlist[count] = 2; 158 dirlist[count] = 2;
166 count++; 159 count++;
167 } 160 }
168 } 161 }
169 162
170
171 /* look right */ 163 /* look right */
172 if (xc < xsize - 2 && yc > 2 && yc < ysize - 2) /* it is valid to look left */ 164 if (xc < xsize - 2 && yc > 2 && yc < ysize - 2) /* it is valid to look left */
173 { 165 {
174 int cleartest = (int) maze[xc + 1][yc] + (int) maze[xc + 1][yc - 1] + (int) maze[xc + 1][yc + 1]; 166 int cleartest = (int) maze[xc + 1][yc] + (int) maze[xc + 1][yc - 1] + (int) maze[xc + 1][yc + 1];
175 167
179 { 171 {
180 dirlist[count] = 3; 172 dirlist[count] = 3;
181 count++; 173 count++;
182 } 174 }
183 } 175 }
184
185 176
186 /* look left */ 177 /* look left */
187 if (xc > 2 && yc > 2 && yc < ysize - 2) /* it is valid to look down */ 178 if (xc > 2 && yc > 2 && yc < ysize - 2) /* it is valid to look down */
188 { 179 {
189 int cleartest = (int) maze[xc - 1][yc] + (int) maze[xc - 1][yc - 1] + (int) maze[xc - 1][yc + 1]; 180 int cleartest = (int) maze[xc - 1][yc] + (int) maze[xc - 1][yc - 1] + (int) maze[xc - 1][yc + 1];
239 return 1; 230 return 1;
240} 231}
241 232
242/* recursive routine which will fill every available space in the maze 233/* recursive routine which will fill every available space in the maze
243 with walls*/ 234 with walls*/
244
245void 235void
246fill_maze_full (char **maze, int x, int y, int xsize, int ysize) 236fill_maze_full (char **maze, int x, int y, int xsize, int ysize)
247{ 237{
248 int xc, yc; 238 int xc, yc;
249 239

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines