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