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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines