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.12 by root, Thu Nov 8 19:43:25 2007 UTC vs.
Revision 1.16 by root, Sun May 4 14:12:37 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines