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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines