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