ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/server/random_maps/room_gen_onion.C
(Generate patch)

Comparing cf.schmorp.de/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.7 by pippijn, Sat Jan 6 14:42:30 2007 UTC

1
1/* 2/*
2 CrossFire, A Multiplayer game for X-windows 3 CrossFire, A Multiplayer game for X-windows
3 4
5 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 6 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 7 Copyright (C) 1992 Frank Tore Johansen
6 8
7 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
8 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
80 /* pick some random options if option = 0 */ 82 /* pick some random options if option = 0 */
81 if (option == 0) 83 if (option == 0)
82 { 84 {
83 switch (RANDOM () % 3) 85 switch (RANDOM () % 3)
84 { 86 {
85 case 0: 87 case 0:
86 option |= OPT_CENTERED; 88 option |= RMOPT_CENTERED;
87 break; 89 break;
88 case 1: 90 case 1:
89 option |= OPT_BOTTOM_C; 91 option |= RMOPT_BOTTOM_C;
90 break; 92 break;
91 case 2: 93 case 2:
92 option |= OPT_BOTTOM_R; 94 option |= RMOPT_BOTTOM_R;
93 break; 95 break;
94 } 96 }
95 if (RANDOM () % 2) 97 if (RANDOM () % 2)
96 option |= OPT_LINEAR; 98 option |= RMOPT_LINEAR;
97 if (RANDOM () % 2) 99 if (RANDOM () % 2)
98 option |= OPT_IRR_SPACE; 100 option |= RMOPT_IRR_SPACE;
99 } 101 }
100 102
101 /* write the outer walls, if appropriate. */ 103 /* write the outer walls, if appropriate. */
102 if (!(option & OPT_WALL_OFF)) 104 if (!(option & RMOPT_WALL_OFF))
103 { 105 {
104 for (i = 0; i < xsize; i++) 106 for (i = 0; i < xsize; i++)
105 maze[i][0] = maze[i][ysize - 1] = '#'; 107 maze[i][0] = maze[i][ysize - 1] = '#';
106 for (j = 0; j < ysize; j++) 108 for (j = 0; j < ysize; j++)
107 maze[0][j] = maze[xsize - 1][j] = '#'; 109 maze[0][j] = maze[xsize - 1][j] = '#';
108 }; 110 };
109 111
110 if (option & OPT_WALLS_ONLY) 112 if (option & RMOPT_WALLS_ONLY)
111 return maze; 113 return maze;
112 114
113 /* pick off the mutually exclusive options */ 115 /* pick off the mutually exclusive options */
114 if (option & OPT_BOTTOM_R) 116 if (option & RMOPT_BOTTOM_R)
115 bottom_right_centered_onion (maze, xsize, ysize, option, layers); 117 bottom_right_centered_onion (maze, xsize, ysize, option, layers);
116 else if (option & OPT_BOTTOM_C) 118 else if (option & RMOPT_BOTTOM_C)
117 bottom_centered_onion (maze, xsize, ysize, option, layers); 119 bottom_centered_onion (maze, xsize, ysize, option, layers);
118 else if (option & OPT_CENTERED) 120 else if (option & RMOPT_CENTERED)
119 centered_onion (maze, xsize, ysize, option, layers); 121 centered_onion (maze, xsize, ysize, option, layers);
120 122
121 return maze; 123 return maze;
122} 124}
123 125
138 xlocations = (float *) calloc (sizeof (float), 2 * layers); 140 xlocations = (float *) calloc (sizeof (float), 2 * layers);
139 ylocations = (float *) calloc (sizeof (float), 2 * layers); 141 ylocations = (float *) calloc (sizeof (float), 2 * layers);
140 142
141 143
142 /* place all the walls */ 144 /* place all the walls */
143 if (option & OPT_IRR_SPACE) /* randomly spaced */ 145 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
144 { 146 {
145 int x_spaces_available, y_spaces_available; 147 int x_spaces_available, y_spaces_available;
146 148
147 /* the "extra" spaces available for spacing between layers */ 149 /* the "extra" spaces available for spacing between layers */
148 x_spaces_available = (xsize - 2) - 6 * layers + 1; 150 x_spaces_available = (xsize - 2) - 6 * layers + 1;
164 x_spaces_available -= (int) (xpitch - 2); 166 x_spaces_available -= (int) (xpitch - 2);
165 y_spaces_available -= (int) (ypitch - 2); 167 y_spaces_available -= (int) (ypitch - 2);
166 } 168 }
167 169
168 } 170 }
169 if (!(option & OPT_IRR_SPACE)) 171 if (!(option & RMOPT_IRR_SPACE))
170 { /* evenly spaced */ 172 { /* evenly spaced */
171 float xpitch, ypitch; /* pitch of the onion layers */ 173 float xpitch, ypitch; /* pitch of the onion layers */
172 174
173 xpitch = (xsize - 2.0) / (2.0 * layers + 1); 175 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
174 ypitch = (ysize - 2.0) / (2.0 * layers + 1); 176 ypitch = (ysize - 2.0) / (2.0 * layers + 1);
205 xlocations = (float *) calloc (sizeof (float), 2 * layers); 207 xlocations = (float *) calloc (sizeof (float), 2 * layers);
206 ylocations = (float *) calloc (sizeof (float), 2 * layers); 208 ylocations = (float *) calloc (sizeof (float), 2 * layers);
207 209
208 210
209 /* place all the walls */ 211 /* place all the walls */
210 if (option & OPT_IRR_SPACE) /* randomly spaced */ 212 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
211 { 213 {
212 int x_spaces_available, y_spaces_available; 214 int x_spaces_available, y_spaces_available;
213 215
214 /* the "extra" spaces available for spacing between layers */ 216 /* the "extra" spaces available for spacing between layers */
215 x_spaces_available = (xsize - 2) - 6 * layers + 1; 217 x_spaces_available = (xsize - 2) - 6 * layers + 1;
234 x_spaces_available -= (int) (xpitch - 2); 236 x_spaces_available -= (int) (xpitch - 2);
235 y_spaces_available -= (int) (ypitch - 2); 237 y_spaces_available -= (int) (ypitch - 2);
236 } 238 }
237 239
238 } 240 }
239 if (!(option & OPT_IRR_SPACE)) 241 if (!(option & RMOPT_IRR_SPACE))
240 { /* evenly spaced */ 242 { /* evenly spaced */
241 float xpitch, ypitch; /* pitch of the onion layers */ 243 float xpitch, ypitch; /* pitch of the onion layers */
242 244
243 xpitch = (xsize - 2.0) / (2.0 * layers + 1); 245 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
244 ypitch = (ysize - 2.0) / (layers + 1); 246 ypitch = (ysize - 2.0) / (layers + 1);
300 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 */
301 int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ 303 int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */
302 int l, x1 = 0, x2, y1 = 0, y2; 304 int l, x1 = 0, x2, y1 = 0, y2;
303 305
304 freedoms = 4; /* centered */ 306 freedoms = 4; /* centered */
305 if (options & OPT_BOTTOM_C) 307 if (options & RMOPT_BOTTOM_C)
306 freedoms = 3; 308 freedoms = 3;
307 if (options & OPT_BOTTOM_R) 309 if (options & RMOPT_BOTTOM_R)
308 freedoms = 2; 310 freedoms = 2;
309 if (layers <= 0) 311 if (layers <= 0)
310 return; 312 return;
311 /* pick which wall will have a door. */ 313 /* pick which wall will have a door. */
312 which_wall = RANDOM () % freedoms + 1; 314 which_wall = RANDOM () % freedoms + 1;
313 for (l = 0; l < layers; l++) 315 for (l = 0; l < layers; l++)
314 { 316 {
315 if (options & OPT_LINEAR) 317 if (options & RMOPT_LINEAR)
316 { /* linear door placement. */ 318 { /* linear door placement. */
317 switch (which_wall) 319 switch (which_wall)
318 { 320 {
319 case 1: 321 case 1:
320 { /* left hand wall */ 322 { /* left hand wall */
321 x1 = (int) xlocations[l]; 323 x1 = (int) xlocations[l];
322 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); 324 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2);
323 break; 325 break;
324 } 326 }
325 case 2: 327 case 2:
326 { /* top wall placement */ 328 { /* top wall placement */
327 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); 329 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2);
328 y1 = (int) ylocations[l]; 330 y1 = (int) ylocations[l];
329 break; 331 break;
330 } 332 }
331 case 3: 333 case 3:
332 { /* right wall placement */ 334 { /* right wall placement */
333 x1 = (int) xlocations[2 * layers - l - 1]; 335 x1 = (int) xlocations[2 * layers - l - 1];
334 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); 336 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2);
335 break; 337 break;
336 } 338 }
337 case 4: 339 case 4:
338 { /* bottom wall placement */ 340 { /* bottom wall placement */
339 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); 341 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2);
340 y1 = (int) ylocations[2 * layers - l - 1]; 342 y1 = (int) ylocations[2 * layers - l - 1];
341 break; 343 break;
342 } 344 }
343 } 345 }
344 } 346 }
345 else 347 else
346 { /* random door placement. */ 348 { /* random door placement. */
347 which_wall = RANDOM () % freedoms + 1; 349 which_wall = RANDOM () % freedoms + 1;
348 switch (which_wall) 350 switch (which_wall)
349 { 351 {
350 case 1: 352 case 1:
351 { /* left hand wall */ 353 { /* left hand wall */
352 x1 = (int) xlocations[l]; 354 x1 = (int) xlocations[l];
353 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); 355 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1);
354 if (y2 > 0) 356 if (y2 > 0)
355 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); 357 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1);
356 else 358 else
357 y1 = (int) (ylocations[l] + 1); 359 y1 = (int) (ylocations[l] + 1);
358 break; 360 break;
359 } 361 }
360 case 2: 362 case 2:
361 { /* top wall placement */ 363 { /* top wall placement */
362 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 364 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
363 if (x2 > 0) 365 if (x2 > 0)
364 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); 366 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1);
365 else 367 else
366 x1 = (int) (xlocations[l] + 1); 368 x1 = (int) (xlocations[l] + 1);
367 y1 = (int) ylocations[l]; 369 y1 = (int) ylocations[l];
368 break; 370 break;
369 } 371 }
370 case 3: 372 case 3:
371 { /* right wall placement */ 373 { /* right wall placement */
372 x1 = (int) xlocations[2 * layers - l - 1]; 374 x1 = (int) xlocations[2 * layers - l - 1];
373 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; 375 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1;
374 if (y2 > 0) 376 if (y2 > 0)
375 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); 377 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1);
376 else 378 else
377 y1 = (int) (ylocations[l] + 1); 379 y1 = (int) (ylocations[l] + 1);
378 380
379 break; 381 break;
380 } 382 }
381 case 4: 383 case 4:
382 { /* bottom wall placement */ 384 { /* bottom wall placement */
383 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 385 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
384 if (x2 > 0) 386 if (x2 > 0)
385 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); 387 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1);
386 else 388 else
387 x1 = (int) (xlocations[l] + 1); 389 x1 = (int) (xlocations[l] + 1);
388 y1 = (int) ylocations[2 * layers - l - 1]; 390 y1 = (int) ylocations[2 * layers - l - 1];
389 break; 391 break;
390 } 392 }
391 393
392 } 394 }
393 } 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 }
426 xlocations = (float *) calloc (sizeof (float), 2 * layers); 428 xlocations = (float *) calloc (sizeof (float), 2 * layers);
427 ylocations = (float *) calloc (sizeof (float), 2 * layers); 429 ylocations = (float *) calloc (sizeof (float), 2 * layers);
428 430
429 431
430 /* place all the walls */ 432 /* place all the walls */
431 if (option & OPT_IRR_SPACE) /* randomly spaced */ 433 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
432 { 434 {
433 int x_spaces_available, y_spaces_available; 435 int x_spaces_available, y_spaces_available;
434 436
435 /* the "extra" spaces available for spacing between layers */ 437 /* the "extra" spaces available for spacing between layers */
436 x_spaces_available = (xsize - 2) - 3 * layers + 1; 438 x_spaces_available = (xsize - 2) - 3 * layers + 1;
459 x_spaces_available -= (int) (xpitch - 2); 461 x_spaces_available -= (int) (xpitch - 2);
460 y_spaces_available -= (int) (ypitch - 2); 462 y_spaces_available -= (int) (ypitch - 2);
461 } 463 }
462 464
463 } 465 }
464 if (!(option & OPT_IRR_SPACE)) 466 if (!(option & RMOPT_IRR_SPACE))
465 { /* evenly spaced */ 467 { /* evenly spaced */
466 float xpitch, ypitch; /* pitch of the onion layers */ 468 float xpitch, ypitch; /* pitch of the onion layers */
467 469
468 xpitch = (xsize - 2.0) / (2.0 * layers + 1); 470 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
469 ypitch = (ysize - 2.0) / (layers + 1); 471 ypitch = (ysize - 2.0) / (layers + 1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines