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

Comparing deliantra/server/random_maps/room_gen_onion.C (file contents):
Revision 1.4 by root, Thu Sep 14 22:34:02 2006 UTC vs.
Revision 1.16 by root, Sun May 4 14:12:37 2008 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22 */
23
24 23
25/* The onion room generator: 24/* The onion room generator:
26Onion rooms are like this: 25Onion rooms are like this:
27 26
28char **map_gen_onion(int xsize, int ysize, int option, int layers); 27char **map_gen_onion(int xsize, int ysize, int option, int layers);
58#endif 57#endif
59void centered_onion (char **maze, int xsize, int ysize, int option, int layers); 58void centered_onion (char **maze, int xsize, int ysize, int option, int layers);
60void bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers); 59void bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers);
61void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers); 60void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers);
62 61
63
64void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); 62void draw_onion (char **maze, float *xlocations, float *ylocations, int layers);
65void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); 63void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options);
66 64
67char ** 65void
68map_gen_onion (int xsize, int ysize, int option, int layers) 66map_gen_onion (Layout maze, int option, int layers)
69{ 67{
70 int i, j; 68 int i, j;
71 69
72 /* allocate that array, set it up */ 70 int xsize = maze->w;
73 char **maze = (char **) calloc (sizeof (char *), xsize); 71 int ysize = maze->h;
74 72
75 for (i = 0; i < xsize; i++) 73 maze->clear ();
76 {
77 maze[i] = (char *) calloc (sizeof (char), ysize);
78 }
79 74
80 /* pick some random options if option = 0 */ 75 /* pick some random options if option = 0 */
81 if (option == 0) 76 if (option == 0)
82 { 77 {
83 switch (RANDOM () % 3) 78 switch (rmg_rndm (3))
84 { 79 {
85 case 0: 80 case 0:
86 option |= OPT_CENTERED; 81 option |= RMOPT_CENTERED;
87 break; 82 break;
88 case 1: 83 case 1:
89 option |= OPT_BOTTOM_C; 84 option |= RMOPT_BOTTOM_C;
90 break; 85 break;
91 case 2: 86 case 2:
92 option |= OPT_BOTTOM_R; 87 option |= RMOPT_BOTTOM_R;
93 break; 88 break;
94 } 89 }
95 if (RANDOM () % 2) 90
96 option |= OPT_LINEAR; 91 if (rmg_rndm (2)) option |= RMOPT_LINEAR;
97 if (RANDOM () % 2)
98 option |= OPT_IRR_SPACE; 92 if (rmg_rndm (2)) option |= RMOPT_IRR_SPACE;
99 } 93 }
100 94
101 /* write the outer walls, if appropriate. */ 95 /* write the outer walls, if appropriate. */
102 if (!(option & OPT_WALL_OFF)) 96 if (!(option & RMOPT_WALL_OFF))
103 { 97 maze->border ();
104 for (i = 0; i < xsize; i++)
105 maze[i][0] = maze[i][ysize - 1] = '#';
106 for (j = 0; j < ysize; j++)
107 maze[0][j] = maze[xsize - 1][j] = '#';
108 };
109 98
110 if (option & OPT_WALLS_ONLY) 99 if (option & RMOPT_WALLS_ONLY)
111 return maze; 100 return;
112 101
113 /* pick off the mutually exclusive options */ 102 /* pick off the mutually exclusive options */
114 if (option & OPT_BOTTOM_R) 103 if (option & RMOPT_BOTTOM_R)
115 bottom_right_centered_onion (maze, xsize, ysize, option, layers); 104 bottom_right_centered_onion (maze, xsize, ysize, option, layers);
116 else if (option & OPT_BOTTOM_C) 105 else if (option & RMOPT_BOTTOM_C)
117 bottom_centered_onion (maze, xsize, ysize, option, layers); 106 bottom_centered_onion (maze, xsize, ysize, option, layers);
118 else if (option & OPT_CENTERED) 107 else if (option & RMOPT_CENTERED)
119 centered_onion (maze, xsize, ysize, option, layers); 108 centered_onion (maze, xsize, ysize, option, layers);
120
121 return maze;
122} 109}
123 110
124void 111void
125centered_onion (char **maze, int xsize, int ysize, int option, int layers) 112centered_onion (char **maze, int xsize, int ysize, int option, int layers)
126{ 113{
127 int i, maxlayers; 114 int i, maxlayers;
128 float *xlocations;
129 float *ylocations;
130 115
131 maxlayers = (MIN (xsize, ysize) - 2) / 5; 116 maxlayers = (MIN (xsize, ysize) - 2) / 5;
117
132 if (!maxlayers) 118 if (!maxlayers)
133 return; /* map too small to onionize */ 119 return; /* map too small to onionize */
120
134 if (layers > maxlayers) 121 if (layers > maxlayers)
135 layers = maxlayers; 122 layers = maxlayers;
123
136 if (layers == 0) 124 if (layers == 0)
137 layers = (RANDOM () % maxlayers) + 1; 125 layers = rmg_rndm (maxlayers) + 1;
138 xlocations = (float *) calloc (sizeof (float), 2 * layers);
139 ylocations = (float *) calloc (sizeof (float), 2 * layers);
140 126
127 float *xlocations = salloc0<float> (2 * layers);
128 float *ylocations = salloc0<float> (2 * layers);
141 129
142 /* place all the walls */ 130 /* place all the walls */
143 if (option & OPT_IRR_SPACE) /* randomly spaced */ 131 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
144 { 132 {
145 int x_spaces_available, y_spaces_available; 133 int x_spaces_available, y_spaces_available;
146 134
147 /* the "extra" spaces available for spacing between layers */ 135 /* the "extra" spaces available for spacing between layers */
148 x_spaces_available = (xsize - 2) - 6 * layers + 1; 136 x_spaces_available = (xsize - 2) - 6 * layers + 1;
149 y_spaces_available = (ysize - 2) - 6 * layers + 1; 137 y_spaces_available = (ysize - 2) - 6 * layers + 1;
150 138
151
152 /* pick an initial random pitch */ 139 /* pick an initial random pitch */
153 for (i = 0; i < 2 * layers; i++) 140 for (i = 0; i < 2 * layers; i++)
154 { 141 {
155 float xpitch = 2, ypitch = 2; 142 float xpitch = 2, ypitch = 2;
156 143
157 if (x_spaces_available > 0) 144 if (x_spaces_available > 0)
158 xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; 145 xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3;
159 146
160 if (y_spaces_available > 0) 147 if (y_spaces_available > 0)
161 ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; 148 ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3;
149
162 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 150 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
163 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 151 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
164 x_spaces_available -= (int) (xpitch - 2); 152 x_spaces_available -= (int) (xpitch - 2);
165 y_spaces_available -= (int) (ypitch - 2); 153 y_spaces_available -= (int) (ypitch - 2);
166 } 154 }
167 155
168 } 156 }
157
169 if (!(option & OPT_IRR_SPACE)) 158 if (!(option & RMOPT_IRR_SPACE))
170 { /* evenly spaced */ 159 { /* evenly spaced */
171 float xpitch, ypitch; /* pitch of the onion layers */ 160 float xpitch, ypitch; /* pitch of the onion layers */
172 161
173 xpitch = (xsize - 2.0) / (2.0 * layers + 1); 162 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
174 ypitch = (ysize - 2.0) / (2.0 * layers + 1); 163 ypitch = (ysize - 2.0) / (2.0 * layers + 1);
164
175 xlocations[0] = xpitch; 165 xlocations[0] = xpitch;
176 ylocations[0] = ypitch; 166 ylocations[0] = ypitch;
167
177 for (i = 1; i < 2 * layers; i++) 168 for (i = 1; i < 2 * layers; i++)
178 { 169 {
179 xlocations[i] = xlocations[i - 1] + xpitch; 170 xlocations[i] = xlocations[i - 1] + xpitch;
180 ylocations[i] = ylocations[i - 1] + ypitch; 171 ylocations[i] = ylocations[i - 1] + ypitch;
181 } 172 }
182 } 173 }
183 174
184 /* draw all the onion boxes. */ 175 /* draw all the onion boxes. */
185
186 draw_onion (maze, xlocations, ylocations, layers); 176 draw_onion (maze, xlocations, ylocations, layers);
187 make_doors (maze, xlocations, ylocations, layers, option); 177 make_doors (maze, xlocations, ylocations, layers, option);
188 178
179 sfree (xlocations, 2 * layers);
180 sfree (ylocations, 2 * layers);
189} 181}
190 182
191void 183void
192bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers) 184bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers)
193{ 185{
194 int i, maxlayers; 186 int i, maxlayers;
195 float *xlocations;
196 float *ylocations;
197 187
198 maxlayers = (MIN (xsize, ysize) - 2) / 5; 188 maxlayers = (MIN (xsize, ysize) - 2) / 5;
189
199 if (!maxlayers) 190 if (!maxlayers)
200 return; /* map too small to onionize */ 191 return; /* map too small to onionize */
192
201 if (layers > maxlayers) 193 if (layers > maxlayers)
202 layers = maxlayers; 194 layers = maxlayers;
195
203 if (layers == 0) 196 if (layers == 0)
204 layers = (RANDOM () % maxlayers) + 1; 197 layers = rmg_rndm (maxlayers) + 1;
205 xlocations = (float *) calloc (sizeof (float), 2 * layers);
206 ylocations = (float *) calloc (sizeof (float), 2 * layers);
207 198
199 float *xlocations = salloc0<float> (2 * layers);
200 float *ylocations = salloc0<float> (2 * layers);
208 201
209 /* place all the walls */ 202 /* place all the walls */
210 if (option & OPT_IRR_SPACE) /* randomly spaced */ 203 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
211 { 204 {
212 int x_spaces_available, y_spaces_available; 205 int x_spaces_available, y_spaces_available;
213 206
214 /* the "extra" spaces available for spacing between layers */ 207 /* the "extra" spaces available for spacing between layers */
215 x_spaces_available = (xsize - 2) - 6 * layers + 1; 208 x_spaces_available = (xsize - 2) - 6 * layers + 1;
216 y_spaces_available = (ysize - 2) - 3 * layers + 1; 209 y_spaces_available = (ysize - 2) - 3 * layers + 1;
217 210
218
219 /* pick an initial random pitch */ 211 /* pick an initial random pitch */
220 for (i = 0; i < 2 * layers; i++) 212 for (i = 0; i < 2 * layers; i++)
221 { 213 {
222 float xpitch = 2, ypitch = 2; 214 float xpitch = 2, ypitch = 2;
223 215
224 if (x_spaces_available > 0) 216 if (x_spaces_available > 0)
225 xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; 217 xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3;
226 218
227 if (y_spaces_available > 0) 219 if (y_spaces_available > 0)
228 ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; 220 ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3;
221
229 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 222 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
223
230 if (i < layers) 224 if (i < layers)
231 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 225 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
232 else 226 else
233 ylocations[i] = ysize - 1; 227 ylocations[i] = ysize - 1;
228
234 x_spaces_available -= (int) (xpitch - 2); 229 x_spaces_available -= (int) (xpitch - 2);
235 y_spaces_available -= (int) (ypitch - 2); 230 y_spaces_available -= (int) (ypitch - 2);
236 } 231 }
237
238 } 232 }
233
239 if (!(option & OPT_IRR_SPACE)) 234 if (!(option & RMOPT_IRR_SPACE))
240 { /* evenly spaced */ 235 { /* evenly spaced */
241 float xpitch, ypitch; /* pitch of the onion layers */ 236 float xpitch, ypitch; /* pitch of the onion layers */
242 237
243 xpitch = (xsize - 2.0) / (2.0 * layers + 1); 238 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
244 ypitch = (ysize - 2.0) / (layers + 1); 239 ypitch = (ysize - 2.0) / (layers + 1);
240
245 xlocations[0] = xpitch; 241 xlocations[0] = xpitch;
246 ylocations[0] = ypitch; 242 ylocations[0] = ypitch;
243
247 for (i = 1; i < 2 * layers; i++) 244 for (i = 1; i < 2 * layers; i++)
248 { 245 {
249 xlocations[i] = xlocations[i - 1] + xpitch; 246 xlocations[i] = xlocations[i - 1] + xpitch;
247
250 if (i < layers) 248 if (i < layers)
251 ylocations[i] = ylocations[i - 1] + ypitch; 249 ylocations[i] = ylocations[i - 1] + ypitch;
252 else 250 else
253 ylocations[i] = ysize - 1; 251 ylocations[i] = ysize - 1;
254 } 252 }
257 /* draw all the onion boxes. */ 255 /* draw all the onion boxes. */
258 256
259 draw_onion (maze, xlocations, ylocations, layers); 257 draw_onion (maze, xlocations, ylocations, layers);
260 make_doors (maze, xlocations, ylocations, layers, option); 258 make_doors (maze, xlocations, ylocations, layers, option);
261 259
260 sfree (xlocations, 2 * layers);
261 sfree (ylocations, 2 * layers);
262} 262}
263
264 263
265/* draw_boxes: draws the lines in the maze defining the onion layers */ 264/* draw_boxes: draws the lines in the maze defining the onion layers */
266
267void 265void
268draw_onion (char **maze, float *xlocations, float *ylocations, int layers) 266draw_onion (char **maze, float *xlocations, float *ylocations, int layers)
269{ 267{
270 int i, j, l; 268 int i, j, l;
271 269
300 int freedoms; /* number of different walls on which we could place a door */ 298 int freedoms; /* number of different walls on which we could place a door */
301 int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ 299 int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */
302 int l, x1 = 0, x2, y1 = 0, y2; 300 int l, x1 = 0, x2, y1 = 0, y2;
303 301
304 freedoms = 4; /* centered */ 302 freedoms = 4; /* centered */
303
305 if (options & OPT_BOTTOM_C) 304 if (options & RMOPT_BOTTOM_C)
306 freedoms = 3; 305 freedoms = 3;
306
307 if (options & OPT_BOTTOM_R) 307 if (options & RMOPT_BOTTOM_R)
308 freedoms = 2; 308 freedoms = 2;
309
309 if (layers <= 0) 310 if (layers <= 0)
310 return; 311 return;
312
311 /* pick which wall will have a door. */ 313 /* pick which wall will have a door. */
312 which_wall = RANDOM () % freedoms + 1; 314 which_wall = rmg_rndm (freedoms) + 1;
313 for (l = 0; l < layers; l++) 315 for (l = 0; l < layers; l++)
314 { 316 {
315 if (options & OPT_LINEAR) 317 if (options & RMOPT_LINEAR)
316 { /* linear door placement. */ 318 { /* linear door placement. */
317 switch (which_wall) 319 switch (which_wall)
318 { 320 {
319 case 1: 321 case 1:
320 { /* left hand wall */ 322 { /* left hand wall */
321 x1 = (int) xlocations[l]; 323 x1 = (int) xlocations[l];
322 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); 324 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2);
323 break; 325 break;
324 } 326 }
325 case 2: 327 case 2:
326 { /* top wall placement */ 328 { /* top wall placement */
327 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); 329 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2);
328 y1 = (int) ylocations[l]; 330 y1 = (int) ylocations[l];
329 break; 331 break;
330 } 332 }
331 case 3: 333 case 3:
332 { /* right wall placement */ 334 { /* right wall placement */
333 x1 = (int) xlocations[2 * layers - l - 1]; 335 x1 = (int) xlocations[2 * layers - l - 1];
334 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); 336 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2);
335 break; 337 break;
336 } 338 }
337 case 4: 339 case 4:
338 { /* bottom wall placement */ 340 { /* bottom wall placement */
339 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); 341 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2);
340 y1 = (int) ylocations[2 * layers - l - 1]; 342 y1 = (int) ylocations[2 * layers - l - 1];
341 break; 343 break;
342 } 344 }
343 } 345 }
344 } 346 }
345 else 347 else
346 { /* random door placement. */ 348 { /* random door placement. */
347 which_wall = RANDOM () % freedoms + 1; 349 which_wall = rmg_rndm (freedoms) + 1;
348 switch (which_wall) 350 switch (which_wall)
349 { 351 {
350 case 1: 352 case 1:
351 { /* left hand wall */ 353 { /* left hand wall */
352 x1 = (int) xlocations[l]; 354 x1 = (int) xlocations[l];
353 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); 355 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1);
354 if (y2 > 0) 356 if (y2 > 0)
355 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); 357 y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1);
356 else 358 else
357 y1 = (int) (ylocations[l] + 1); 359 y1 = (int) (ylocations[l] + 1);
358 break; 360 break;
359 } 361 }
360 case 2: 362 case 2:
361 { /* top wall placement */ 363 { /* top wall placement */
362 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 364 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
363 if (x2 > 0) 365 if (x2 > 0)
364 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); 366 x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1);
365 else 367 else
366 x1 = (int) (xlocations[l] + 1); 368 x1 = (int) (xlocations[l] + 1);
367 y1 = (int) ylocations[l]; 369 y1 = (int) ylocations[l];
368 break; 370 break;
369 } 371 }
370 case 3: 372 case 3:
371 { /* right wall placement */ 373 { /* right wall placement */
372 x1 = (int) xlocations[2 * layers - l - 1]; 374 x1 = (int) xlocations[2 * layers - l - 1];
373 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; 375 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1;
374 if (y2 > 0) 376 if (y2 > 0)
375 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); 377 y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1);
376 else 378 else
377 y1 = (int) (ylocations[l] + 1); 379 y1 = (int) (ylocations[l] + 1);
378 380
379 break; 381 break;
380 } 382 }
381 case 4: 383 case 4:
382 { /* bottom wall placement */ 384 { /* bottom wall placement */
383 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 385 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
384 if (x2 > 0) 386 if (x2 > 0)
385 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); 387 x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1);
386 else 388 else
387 x1 = (int) (xlocations[l] + 1); 389 x1 = (int) (xlocations[l] + 1);
388 y1 = (int) ylocations[2 * layers - l - 1]; 390 y1 = (int) ylocations[2 * layers - l - 1];
389 break; 391 break;
390 } 392 }
391 393
392 } 394 }
393 } 395 }
396
394 if (options & OPT_NO_DOORS) 397 if (options & RMOPT_NO_DOORS)
395 maze[x1][y1] = '#'; /* no door. */ 398 maze[x1][y1] = '#'; /* no door. */
396 else 399 else
397 maze[x1][y1] = 'D'; /* write the door */ 400 maze[x1][y1] = 'D'; /* write the door */
398 401
399 } 402 }
400 /* mark the center of the maze with a C */ 403 /* mark the center of the maze with a C */
401 l = layers - 1; 404 l = layers - 1;
402 x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2; 405 x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2;
403 y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; 406 y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2;
407
404 maze[x1][y1] = 'C'; 408 maze[x1][y1] = 'C';
405
406 /* not needed anymore */
407 free (xlocations);
408 free (ylocations);
409
410} 409}
411 410
412void 411void
413bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers) 412bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers)
414{ 413{
415 int i, maxlayers; 414 int i, maxlayers;
416 float *xlocations;
417 float *ylocations;
418 415
419 maxlayers = (MIN (xsize, ysize) - 2) / 5; 416 maxlayers = (MIN (xsize, ysize) - 2) / 5;
417
420 if (!maxlayers) 418 if (!maxlayers)
421 return; /* map too small to onionize */ 419 return; /* map too small to onionize */
420
422 if (layers > maxlayers) 421 if (layers > maxlayers)
423 layers = maxlayers; 422 layers = maxlayers;
423
424 if (layers == 0) 424 if (layers == 0)
425 layers = (RANDOM () % maxlayers) + 1; 425 layers = rmg_rndm (maxlayers) + 1;
426 xlocations = (float *) calloc (sizeof (float), 2 * layers);
427 ylocations = (float *) calloc (sizeof (float), 2 * layers);
428 426
427 float *xlocations = salloc0<float> (2 * layers);
428 float *ylocations = salloc0<float> (2 * layers);
429 429
430 /* place all the walls */ 430 /* place all the walls */
431 if (option & OPT_IRR_SPACE) /* randomly spaced */ 431 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
432 { 432 {
433 int x_spaces_available, y_spaces_available; 433 int x_spaces_available, y_spaces_available;
434 434
435 /* the "extra" spaces available for spacing between layers */ 435 /* the "extra" spaces available for spacing between layers */
436 x_spaces_available = (xsize - 2) - 3 * layers + 1; 436 x_spaces_available = (xsize - 2) - 3 * layers + 1;
441 for (i = 0; i < 2 * layers; i++) 441 for (i = 0; i < 2 * layers; i++)
442 { 442 {
443 float xpitch = 2, ypitch = 2; 443 float xpitch = 2, ypitch = 2;
444 444
445 if (x_spaces_available > 0) 445 if (x_spaces_available > 0)
446 xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; 446 xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3;
447 447
448 if (y_spaces_available > 0) 448 if (y_spaces_available > 0)
449 ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; 449 ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3;
450
450 if (i < layers) 451 if (i < layers)
451 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 452 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
452 else 453 else
453 xlocations[i] = xsize - 1; 454 xlocations[i] = xsize - 1;
454 455
455 if (i < layers) 456 if (i < layers)
456 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 457 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
457 else 458 else
458 ylocations[i] = ysize - 1; 459 ylocations[i] = ysize - 1;
460
459 x_spaces_available -= (int) (xpitch - 2); 461 x_spaces_available -= (int) (xpitch - 2);
460 y_spaces_available -= (int) (ypitch - 2); 462 y_spaces_available -= (int) (ypitch - 2);
461 } 463 }
462
463 } 464 }
465
464 if (!(option & OPT_IRR_SPACE)) 466 if (!(option & RMOPT_IRR_SPACE))
465 { /* evenly spaced */ 467 { /* evenly spaced */
466 float xpitch, ypitch; /* pitch of the onion layers */ 468 float xpitch, ypitch; /* pitch of the onion layers */
467 469
468 xpitch = (xsize - 2.0) / (2.0 * layers + 1); 470 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
469 ypitch = (ysize - 2.0) / (layers + 1); 471 ypitch = (ysize - 2.0) / (layers + 1);
472
470 xlocations[0] = xpitch; 473 xlocations[0] = xpitch;
471 ylocations[0] = ypitch; 474 ylocations[0] = ypitch;
475
472 for (i = 1; i < 2 * layers; i++) 476 for (i = 1; i < 2 * layers; i++)
473 { 477 {
474 if (i < layers) 478 if (i < layers)
475 xlocations[i] = xlocations[i - 1] + xpitch; 479 xlocations[i] = xlocations[i - 1] + xpitch;
476 else 480 else
477 xlocations[i] = xsize - 1; 481 xlocations[i] = xsize - 1;
482
478 if (i < layers) 483 if (i < layers)
479 ylocations[i] = ylocations[i - 1] + ypitch; 484 ylocations[i] = ylocations[i - 1] + ypitch;
480 else 485 else
481 ylocations[i] = ysize - 1; 486 ylocations[i] = ysize - 1;
482 } 487 }
485 /* draw all the onion boxes. */ 490 /* draw all the onion boxes. */
486 491
487 draw_onion (maze, xlocations, ylocations, layers); 492 draw_onion (maze, xlocations, ylocations, layers);
488 make_doors (maze, xlocations, ylocations, layers, option); 493 make_doors (maze, xlocations, ylocations, layers, option);
489 494
495 sfree (xlocations, 2 * layers);
496 sfree (ylocations, 2 * layers);
490} 497}
498

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines