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.3 by root, Sun Sep 10 16:06:37 2006 UTC vs.
Revision 1.13 by root, Fri Apr 11 21:09:53 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines