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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines