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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines