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.7 by pippijn, Sat Jan 6 14:42:30 2007 UTC vs.
Revision 1.10 by root, Sat Jan 27 02:19:37 2007 UTC

1
2/* 1/*
3 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
4 3 *
5 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
6 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team
7 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
8 7 *
9 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version. 11 * (at your option) any later version.
13 12 *
14 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,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 16 * GNU General Public License for more details.
18 17 *
19 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
20 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 21 *
23 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
24*/ 23 */
25 24
26 25
27/* The onion room generator: 26/* The onion room generator:
28Onion rooms are like this: 27Onion rooms are like this:
29 28
80 } 79 }
81 80
82 /* pick some random options if option = 0 */ 81 /* pick some random options if option = 0 */
83 if (option == 0) 82 if (option == 0)
84 { 83 {
85 switch (RANDOM () % 3) 84 switch (rndm (3))
86 { 85 {
87 case 0: 86 case 0:
88 option |= RMOPT_CENTERED; 87 option |= RMOPT_CENTERED;
89 break; 88 break;
90 case 1: 89 case 1:
92 break; 91 break;
93 case 2: 92 case 2:
94 option |= RMOPT_BOTTOM_R; 93 option |= RMOPT_BOTTOM_R;
95 break; 94 break;
96 } 95 }
97 if (RANDOM () % 2) 96 if (rndm (2))
98 option |= RMOPT_LINEAR; 97 option |= RMOPT_LINEAR;
99 if (RANDOM () % 2) 98 if (rndm (2))
100 option |= RMOPT_IRR_SPACE; 99 option |= RMOPT_IRR_SPACE;
101 } 100 }
102 101
103 /* write the outer walls, if appropriate. */ 102 /* write the outer walls, if appropriate. */
104 if (!(option & RMOPT_WALL_OFF)) 103 if (!(option & RMOPT_WALL_OFF))
131 float *ylocations; 130 float *ylocations;
132 131
133 maxlayers = (MIN (xsize, ysize) - 2) / 5; 132 maxlayers = (MIN (xsize, ysize) - 2) / 5;
134 if (!maxlayers) 133 if (!maxlayers)
135 return; /* map too small to onionize */ 134 return; /* map too small to onionize */
135
136 if (layers > maxlayers) 136 if (layers > maxlayers)
137 layers = maxlayers; 137 layers = maxlayers;
138
138 if (layers == 0) 139 if (layers == 0)
139 layers = (RANDOM () % maxlayers) + 1; 140 layers = rndm (maxlayers) + 1;
141
140 xlocations = (float *) calloc (sizeof (float), 2 * layers); 142 xlocations = (float *) calloc (sizeof (float), 2 * layers);
141 ylocations = (float *) calloc (sizeof (float), 2 * layers); 143 ylocations = (float *) calloc (sizeof (float), 2 * layers);
142
143 144
144 /* place all the walls */ 145 /* place all the walls */
145 if (option & RMOPT_IRR_SPACE) /* randomly spaced */ 146 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
146 { 147 {
147 int x_spaces_available, y_spaces_available; 148 int x_spaces_available, y_spaces_available;
155 for (i = 0; i < 2 * layers; i++) 156 for (i = 0; i < 2 * layers; i++)
156 { 157 {
157 float xpitch = 2, ypitch = 2; 158 float xpitch = 2, ypitch = 2;
158 159
159 if (x_spaces_available > 0) 160 if (x_spaces_available > 0)
160 xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; 161 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3;
161 162
162 if (y_spaces_available > 0) 163 if (y_spaces_available > 0)
163 ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; 164 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3;
165
164 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 166 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
165 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 167 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
166 x_spaces_available -= (int) (xpitch - 2); 168 x_spaces_available -= (int) (xpitch - 2);
167 y_spaces_available -= (int) (ypitch - 2); 169 y_spaces_available -= (int) (ypitch - 2);
168 } 170 }
201 if (!maxlayers) 203 if (!maxlayers)
202 return; /* map too small to onionize */ 204 return; /* map too small to onionize */
203 if (layers > maxlayers) 205 if (layers > maxlayers)
204 layers = maxlayers; 206 layers = maxlayers;
205 if (layers == 0) 207 if (layers == 0)
206 layers = (RANDOM () % maxlayers) + 1; 208 layers = rndm (maxlayers) + 1;
207 xlocations = (float *) calloc (sizeof (float), 2 * layers); 209 xlocations = (float *) calloc (sizeof (float), 2 * layers);
208 ylocations = (float *) calloc (sizeof (float), 2 * layers); 210 ylocations = (float *) calloc (sizeof (float), 2 * layers);
209 211
210 212
211 /* place all the walls */ 213 /* place all the walls */
222 for (i = 0; i < 2 * layers; i++) 224 for (i = 0; i < 2 * layers; i++)
223 { 225 {
224 float xpitch = 2, ypitch = 2; 226 float xpitch = 2, ypitch = 2;
225 227
226 if (x_spaces_available > 0) 228 if (x_spaces_available > 0)
227 xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; 229 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3;
228 230
229 if (y_spaces_available > 0) 231 if (y_spaces_available > 0)
230 ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; 232 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3;
233
231 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 234 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
232 if (i < layers) 235 if (i < layers)
233 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 236 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
234 else 237 else
235 ylocations[i] = ysize - 1; 238 ylocations[i] = ysize - 1;
239
236 x_spaces_available -= (int) (xpitch - 2); 240 x_spaces_available -= (int) (xpitch - 2);
237 y_spaces_available -= (int) (ypitch - 2); 241 y_spaces_available -= (int) (ypitch - 2);
238 } 242 }
239 243
240 } 244 }
308 freedoms = 3; 312 freedoms = 3;
309 if (options & RMOPT_BOTTOM_R) 313 if (options & RMOPT_BOTTOM_R)
310 freedoms = 2; 314 freedoms = 2;
311 if (layers <= 0) 315 if (layers <= 0)
312 return; 316 return;
317
313 /* pick which wall will have a door. */ 318 /* pick which wall will have a door. */
314 which_wall = RANDOM () % freedoms + 1; 319 which_wall = rndm (freedoms) + 1;
315 for (l = 0; l < layers; l++) 320 for (l = 0; l < layers; l++)
316 { 321 {
317 if (options & RMOPT_LINEAR) 322 if (options & RMOPT_LINEAR)
318 { /* linear door placement. */ 323 { /* linear door placement. */
319 switch (which_wall) 324 switch (which_wall)
344 } 349 }
345 } 350 }
346 } 351 }
347 else 352 else
348 { /* random door placement. */ 353 { /* random door placement. */
349 which_wall = RANDOM () % freedoms + 1; 354 which_wall = rndm (freedoms) + 1;
350 switch (which_wall) 355 switch (which_wall)
351 { 356 {
352 case 1: 357 case 1:
353 { /* left hand wall */ 358 { /* left hand wall */
354 x1 = (int) xlocations[l]; 359 x1 = (int) xlocations[l];
355 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); 360 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1);
356 if (y2 > 0) 361 if (y2 > 0)
357 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); 362 y1 = (int) (ylocations[l] + rndm (y2) + 1);
358 else 363 else
359 y1 = (int) (ylocations[l] + 1); 364 y1 = (int) (ylocations[l] + 1);
360 break; 365 break;
361 } 366 }
362 case 2: 367 case 2:
363 { /* top wall placement */ 368 { /* top wall placement */
364 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 369 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
365 if (x2 > 0) 370 if (x2 > 0)
366 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); 371 x1 = (int) (xlocations[l] + rndm (x2) + 1);
367 else 372 else
368 x1 = (int) (xlocations[l] + 1); 373 x1 = (int) (xlocations[l] + 1);
369 y1 = (int) ylocations[l]; 374 y1 = (int) ylocations[l];
370 break; 375 break;
371 } 376 }
372 case 3: 377 case 3:
373 { /* right wall placement */ 378 { /* right wall placement */
374 x1 = (int) xlocations[2 * layers - l - 1]; 379 x1 = (int) xlocations[2 * layers - l - 1];
375 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; 380 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1;
376 if (y2 > 0) 381 if (y2 > 0)
377 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); 382 y1 = (int) (ylocations[l] + rndm (y2) + 1);
378 else 383 else
379 y1 = (int) (ylocations[l] + 1); 384 y1 = (int) (ylocations[l] + 1);
380 385
381 break; 386 break;
382 } 387 }
383 case 4: 388 case 4:
384 { /* bottom wall placement */ 389 { /* bottom wall placement */
385 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 390 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
386 if (x2 > 0) 391 if (x2 > 0)
387 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); 392 x1 = (int) (xlocations[l] + rndm (x2) + 1);
388 else 393 else
389 x1 = (int) (xlocations[l] + 1); 394 x1 = (int) (xlocations[l] + 1);
390 y1 = (int) ylocations[2 * layers - l - 1]; 395 y1 = (int) ylocations[2 * layers - l - 1];
391 break; 396 break;
392 } 397 }
422 if (!maxlayers) 427 if (!maxlayers)
423 return; /* map too small to onionize */ 428 return; /* map too small to onionize */
424 if (layers > maxlayers) 429 if (layers > maxlayers)
425 layers = maxlayers; 430 layers = maxlayers;
426 if (layers == 0) 431 if (layers == 0)
427 layers = (RANDOM () % maxlayers) + 1; 432 layers = rndm (maxlayers) + 1;
433
428 xlocations = (float *) calloc (sizeof (float), 2 * layers); 434 xlocations = (float *) calloc (sizeof (float), 2 * layers);
429 ylocations = (float *) calloc (sizeof (float), 2 * layers); 435 ylocations = (float *) calloc (sizeof (float), 2 * layers);
430
431 436
432 /* place all the walls */ 437 /* place all the walls */
433 if (option & RMOPT_IRR_SPACE) /* randomly spaced */ 438 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
434 { 439 {
435 int x_spaces_available, y_spaces_available; 440 int x_spaces_available, y_spaces_available;
443 for (i = 0; i < 2 * layers; i++) 448 for (i = 0; i < 2 * layers; i++)
444 { 449 {
445 float xpitch = 2, ypitch = 2; 450 float xpitch = 2, ypitch = 2;
446 451
447 if (x_spaces_available > 0) 452 if (x_spaces_available > 0)
448 xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; 453 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3;
449 454
450 if (y_spaces_available > 0) 455 if (y_spaces_available > 0)
451 ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; 456 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3;
457
452 if (i < layers) 458 if (i < layers)
453 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 459 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
454 else 460 else
455 xlocations[i] = xsize - 1; 461 xlocations[i] = xsize - 1;
456 462

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines