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