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.6 by root, Sun Dec 31 19:02:24 2006 UTC

1
2/*
3 * static char *room_gen_onion_c =
4 * "$Id: room_gen_onion.C,v 1.3 2006/09/10 16:06:37 root Exp $";
5 */
6 1
7/* 2/*
8 CrossFire, A Multiplayer game for X-windows 3 CrossFire, A Multiplayer game for X-windows
9 4
10 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
22 17
23 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 21
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 22 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 23*/
29 24
30 25
31/* The onion room generator: 26/* The onion room generator:
32Onion rooms are like this: 27Onion rooms are like this:
86 /* pick some random options if option = 0 */ 81 /* pick some random options if option = 0 */
87 if (option == 0) 82 if (option == 0)
88 { 83 {
89 switch (RANDOM () % 3) 84 switch (RANDOM () % 3)
90 { 85 {
91 case 0: 86 case 0:
92 option |= OPT_CENTERED; 87 option |= RMOPT_CENTERED;
93 break; 88 break;
94 case 1: 89 case 1:
95 option |= OPT_BOTTOM_C; 90 option |= RMOPT_BOTTOM_C;
96 break; 91 break;
97 case 2: 92 case 2:
98 option |= OPT_BOTTOM_R; 93 option |= RMOPT_BOTTOM_R;
99 break; 94 break;
100 } 95 }
101 if (RANDOM () % 2) 96 if (RANDOM () % 2)
102 option |= OPT_LINEAR; 97 option |= RMOPT_LINEAR;
103 if (RANDOM () % 2) 98 if (RANDOM () % 2)
104 option |= OPT_IRR_SPACE; 99 option |= RMOPT_IRR_SPACE;
105 } 100 }
106 101
107 /* write the outer walls, if appropriate. */ 102 /* write the outer walls, if appropriate. */
108 if (!(option & OPT_WALL_OFF)) 103 if (!(option & RMOPT_WALL_OFF))
109 { 104 {
110 for (i = 0; i < xsize; i++) 105 for (i = 0; i < xsize; i++)
111 maze[i][0] = maze[i][ysize - 1] = '#'; 106 maze[i][0] = maze[i][ysize - 1] = '#';
112 for (j = 0; j < ysize; j++) 107 for (j = 0; j < ysize; j++)
113 maze[0][j] = maze[xsize - 1][j] = '#'; 108 maze[0][j] = maze[xsize - 1][j] = '#';
114 }; 109 };
115 110
116 if (option & OPT_WALLS_ONLY) 111 if (option & RMOPT_WALLS_ONLY)
117 return maze; 112 return maze;
118 113
119 /* pick off the mutually exclusive options */ 114 /* pick off the mutually exclusive options */
120 if (option & OPT_BOTTOM_R) 115 if (option & RMOPT_BOTTOM_R)
121 bottom_right_centered_onion (maze, xsize, ysize, option, layers); 116 bottom_right_centered_onion (maze, xsize, ysize, option, layers);
122 else if (option & OPT_BOTTOM_C) 117 else if (option & RMOPT_BOTTOM_C)
123 bottom_centered_onion (maze, xsize, ysize, option, layers); 118 bottom_centered_onion (maze, xsize, ysize, option, layers);
124 else if (option & OPT_CENTERED) 119 else if (option & RMOPT_CENTERED)
125 centered_onion (maze, xsize, ysize, option, layers); 120 centered_onion (maze, xsize, ysize, option, layers);
126 121
127 return maze; 122 return maze;
128} 123}
129 124
144 xlocations = (float *) calloc (sizeof (float), 2 * layers); 139 xlocations = (float *) calloc (sizeof (float), 2 * layers);
145 ylocations = (float *) calloc (sizeof (float), 2 * layers); 140 ylocations = (float *) calloc (sizeof (float), 2 * layers);
146 141
147 142
148 /* place all the walls */ 143 /* place all the walls */
149 if (option & OPT_IRR_SPACE) /* randomly spaced */ 144 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
150 { 145 {
151 int x_spaces_available, y_spaces_available; 146 int x_spaces_available, y_spaces_available;
152 147
153 /* the "extra" spaces available for spacing between layers */ 148 /* the "extra" spaces available for spacing between layers */
154 x_spaces_available = (xsize - 2) - 6 * layers + 1; 149 x_spaces_available = (xsize - 2) - 6 * layers + 1;
170 x_spaces_available -= (int) (xpitch - 2); 165 x_spaces_available -= (int) (xpitch - 2);
171 y_spaces_available -= (int) (ypitch - 2); 166 y_spaces_available -= (int) (ypitch - 2);
172 } 167 }
173 168
174 } 169 }
175 if (!(option & OPT_IRR_SPACE)) 170 if (!(option & RMOPT_IRR_SPACE))
176 { /* evenly spaced */ 171 { /* evenly spaced */
177 float xpitch, ypitch; /* pitch of the onion layers */ 172 float xpitch, ypitch; /* pitch of the onion layers */
178 173
179 xpitch = (xsize - 2.0) / (2.0 * layers + 1); 174 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
180 ypitch = (ysize - 2.0) / (2.0 * layers + 1); 175 ypitch = (ysize - 2.0) / (2.0 * layers + 1);
211 xlocations = (float *) calloc (sizeof (float), 2 * layers); 206 xlocations = (float *) calloc (sizeof (float), 2 * layers);
212 ylocations = (float *) calloc (sizeof (float), 2 * layers); 207 ylocations = (float *) calloc (sizeof (float), 2 * layers);
213 208
214 209
215 /* place all the walls */ 210 /* place all the walls */
216 if (option & OPT_IRR_SPACE) /* randomly spaced */ 211 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
217 { 212 {
218 int x_spaces_available, y_spaces_available; 213 int x_spaces_available, y_spaces_available;
219 214
220 /* the "extra" spaces available for spacing between layers */ 215 /* the "extra" spaces available for spacing between layers */
221 x_spaces_available = (xsize - 2) - 6 * layers + 1; 216 x_spaces_available = (xsize - 2) - 6 * layers + 1;
240 x_spaces_available -= (int) (xpitch - 2); 235 x_spaces_available -= (int) (xpitch - 2);
241 y_spaces_available -= (int) (ypitch - 2); 236 y_spaces_available -= (int) (ypitch - 2);
242 } 237 }
243 238
244 } 239 }
245 if (!(option & OPT_IRR_SPACE)) 240 if (!(option & RMOPT_IRR_SPACE))
246 { /* evenly spaced */ 241 { /* evenly spaced */
247 float xpitch, ypitch; /* pitch of the onion layers */ 242 float xpitch, ypitch; /* pitch of the onion layers */
248 243
249 xpitch = (xsize - 2.0) / (2.0 * layers + 1); 244 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
250 ypitch = (ysize - 2.0) / (layers + 1); 245 ypitch = (ysize - 2.0) / (layers + 1);
306 int freedoms; /* number of different walls on which we could place a door */ 301 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 */ 302 int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */
308 int l, x1 = 0, x2, y1 = 0, y2; 303 int l, x1 = 0, x2, y1 = 0, y2;
309 304
310 freedoms = 4; /* centered */ 305 freedoms = 4; /* centered */
311 if (options & OPT_BOTTOM_C) 306 if (options & RMOPT_BOTTOM_C)
312 freedoms = 3; 307 freedoms = 3;
313 if (options & OPT_BOTTOM_R) 308 if (options & RMOPT_BOTTOM_R)
314 freedoms = 2; 309 freedoms = 2;
315 if (layers <= 0) 310 if (layers <= 0)
316 return; 311 return;
317 /* pick which wall will have a door. */ 312 /* pick which wall will have a door. */
318 which_wall = RANDOM () % freedoms + 1; 313 which_wall = RANDOM () % freedoms + 1;
319 for (l = 0; l < layers; l++) 314 for (l = 0; l < layers; l++)
320 { 315 {
321 if (options & OPT_LINEAR) 316 if (options & RMOPT_LINEAR)
322 { /* linear door placement. */ 317 { /* linear door placement. */
323 switch (which_wall) 318 switch (which_wall)
324 { 319 {
325 case 1: 320 case 1:
326 { /* left hand wall */ 321 { /* left hand wall */
327 x1 = (int) xlocations[l]; 322 x1 = (int) xlocations[l];
328 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); 323 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2);
329 break; 324 break;
330 } 325 }
331 case 2: 326 case 2:
332 { /* top wall placement */ 327 { /* top wall placement */
333 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); 328 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2);
334 y1 = (int) ylocations[l]; 329 y1 = (int) ylocations[l];
335 break; 330 break;
336 } 331 }
337 case 3: 332 case 3:
338 { /* right wall placement */ 333 { /* right wall placement */
339 x1 = (int) xlocations[2 * layers - l - 1]; 334 x1 = (int) xlocations[2 * layers - l - 1];
340 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); 335 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2);
341 break; 336 break;
342 } 337 }
343 case 4: 338 case 4:
344 { /* bottom wall placement */ 339 { /* bottom wall placement */
345 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); 340 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2);
346 y1 = (int) ylocations[2 * layers - l - 1]; 341 y1 = (int) ylocations[2 * layers - l - 1];
347 break; 342 break;
348 } 343 }
349 } 344 }
350 } 345 }
351 else 346 else
352 { /* random door placement. */ 347 { /* random door placement. */
353 which_wall = RANDOM () % freedoms + 1; 348 which_wall = RANDOM () % freedoms + 1;
354 switch (which_wall) 349 switch (which_wall)
355 { 350 {
356 case 1: 351 case 1:
357 { /* left hand wall */ 352 { /* left hand wall */
358 x1 = (int) xlocations[l]; 353 x1 = (int) xlocations[l];
359 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); 354 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1);
360 if (y2 > 0) 355 if (y2 > 0)
361 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); 356 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1);
362 else 357 else
363 y1 = (int) (ylocations[l] + 1); 358 y1 = (int) (ylocations[l] + 1);
364 break; 359 break;
365 } 360 }
366 case 2: 361 case 2:
367 { /* top wall placement */ 362 { /* top wall placement */
368 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 363 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
369 if (x2 > 0) 364 if (x2 > 0)
370 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); 365 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1);
371 else 366 else
372 x1 = (int) (xlocations[l] + 1); 367 x1 = (int) (xlocations[l] + 1);
373 y1 = (int) ylocations[l]; 368 y1 = (int) ylocations[l];
374 break; 369 break;
375 } 370 }
376 case 3: 371 case 3:
377 { /* right wall placement */ 372 { /* right wall placement */
378 x1 = (int) xlocations[2 * layers - l - 1]; 373 x1 = (int) xlocations[2 * layers - l - 1];
379 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; 374 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1;
380 if (y2 > 0) 375 if (y2 > 0)
381 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); 376 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1);
382 else 377 else
383 y1 = (int) (ylocations[l] + 1); 378 y1 = (int) (ylocations[l] + 1);
384 379
385 break; 380 break;
386 } 381 }
387 case 4: 382 case 4:
388 { /* bottom wall placement */ 383 { /* bottom wall placement */
389 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 384 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
390 if (x2 > 0) 385 if (x2 > 0)
391 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); 386 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1);
392 else 387 else
393 x1 = (int) (xlocations[l] + 1); 388 x1 = (int) (xlocations[l] + 1);
394 y1 = (int) ylocations[2 * layers - l - 1]; 389 y1 = (int) ylocations[2 * layers - l - 1];
395 break; 390 break;
396 } 391 }
397 392
398 } 393 }
399 } 394 }
400 if (options & OPT_NO_DOORS) 395 if (options & RMOPT_NO_DOORS)
401 maze[x1][y1] = '#'; /* no door. */ 396 maze[x1][y1] = '#'; /* no door. */
402 else 397 else
403 maze[x1][y1] = 'D'; /* write the door */ 398 maze[x1][y1] = 'D'; /* write the door */
404 399
405 } 400 }
432 xlocations = (float *) calloc (sizeof (float), 2 * layers); 427 xlocations = (float *) calloc (sizeof (float), 2 * layers);
433 ylocations = (float *) calloc (sizeof (float), 2 * layers); 428 ylocations = (float *) calloc (sizeof (float), 2 * layers);
434 429
435 430
436 /* place all the walls */ 431 /* place all the walls */
437 if (option & OPT_IRR_SPACE) /* randomly spaced */ 432 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
438 { 433 {
439 int x_spaces_available, y_spaces_available; 434 int x_spaces_available, y_spaces_available;
440 435
441 /* the "extra" spaces available for spacing between layers */ 436 /* the "extra" spaces available for spacing between layers */
442 x_spaces_available = (xsize - 2) - 3 * layers + 1; 437 x_spaces_available = (xsize - 2) - 3 * layers + 1;
465 x_spaces_available -= (int) (xpitch - 2); 460 x_spaces_available -= (int) (xpitch - 2);
466 y_spaces_available -= (int) (ypitch - 2); 461 y_spaces_available -= (int) (ypitch - 2);
467 } 462 }
468 463
469 } 464 }
470 if (!(option & OPT_IRR_SPACE)) 465 if (!(option & RMOPT_IRR_SPACE))
471 { /* evenly spaced */ 466 { /* evenly spaced */
472 float xpitch, ypitch; /* pitch of the onion layers */ 467 float xpitch, ypitch; /* pitch of the onion layers */
473 468
474 xpitch = (xsize - 2.0) / (2.0 * layers + 1); 469 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
475 ypitch = (ysize - 2.0) / (layers + 1); 470 ypitch = (ysize - 2.0) / (layers + 1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines