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.9 by root, Thu Jan 18 19:42:10 2007 UTC vs.
Revision 1.11 by root, Sun Jul 1 05:00:19 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines