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 |= OPT_CENTERED; |
87 | option |= RMOPT_CENTERED; |
87 | break; |
88 | break; |
88 | case 1: |
89 | case 1: |
89 | option |= OPT_BOTTOM_C; |
90 | option |= RMOPT_BOTTOM_C; |
90 | break; |
91 | break; |
91 | case 2: |
92 | case 2: |
92 | option |= OPT_BOTTOM_R; |
93 | option |= RMOPT_BOTTOM_R; |
93 | break; |
94 | break; |
94 | } |
95 | } |
95 | if (RANDOM () % 2) |
96 | if (rndm (2)) |
96 | option |= OPT_LINEAR; |
97 | option |= RMOPT_LINEAR; |
97 | if (RANDOM () % 2) |
98 | if (rndm (2)) |
98 | option |= OPT_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 & OPT_WALL_OFF)) |
103 | if (!(option & RMOPT_WALL_OFF)) |
103 | { |
104 | { |
104 | for (i = 0; i < xsize; i++) |
105 | for (i = 0; i < xsize; i++) |
105 | maze[i][0] = maze[i][ysize - 1] = '#'; |
106 | maze[i][0] = maze[i][ysize - 1] = '#'; |
106 | for (j = 0; j < ysize; j++) |
107 | for (j = 0; j < ysize; j++) |
107 | maze[0][j] = maze[xsize - 1][j] = '#'; |
108 | maze[0][j] = maze[xsize - 1][j] = '#'; |
108 | }; |
109 | }; |
109 | |
110 | |
110 | if (option & OPT_WALLS_ONLY) |
111 | if (option & RMOPT_WALLS_ONLY) |
111 | return maze; |
112 | return maze; |
112 | |
113 | |
113 | /* pick off the mutually exclusive options */ |
114 | /* pick off the mutually exclusive options */ |
114 | if (option & OPT_BOTTOM_R) |
115 | if (option & RMOPT_BOTTOM_R) |
115 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
116 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
116 | else if (option & OPT_BOTTOM_C) |
117 | else if (option & RMOPT_BOTTOM_C) |
117 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
118 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
118 | else if (option & OPT_CENTERED) |
119 | else if (option & RMOPT_CENTERED) |
119 | centered_onion (maze, xsize, ysize, option, layers); |
120 | centered_onion (maze, xsize, ysize, option, layers); |
120 | |
121 | |
121 | return maze; |
122 | return maze; |
122 | } |
123 | } |
123 | |
124 | |
… | |
… | |
138 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
139 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
139 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
140 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
140 | |
141 | |
141 | |
142 | |
142 | /* place all the walls */ |
143 | /* place all the walls */ |
143 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
144 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
144 | { |
145 | { |
145 | int x_spaces_available, y_spaces_available; |
146 | int x_spaces_available, y_spaces_available; |
146 | |
147 | |
147 | /* the "extra" spaces available for spacing between layers */ |
148 | /* the "extra" spaces available for spacing between layers */ |
148 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
149 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
… | |
… | |
164 | x_spaces_available -= (int) (xpitch - 2); |
165 | x_spaces_available -= (int) (xpitch - 2); |
165 | y_spaces_available -= (int) (ypitch - 2); |
166 | y_spaces_available -= (int) (ypitch - 2); |
166 | } |
167 | } |
167 | |
168 | |
168 | } |
169 | } |
169 | if (!(option & OPT_IRR_SPACE)) |
170 | if (!(option & RMOPT_IRR_SPACE)) |
170 | { /* evenly spaced */ |
171 | { /* evenly spaced */ |
171 | float xpitch, ypitch; /* pitch of the onion layers */ |
172 | float xpitch, ypitch; /* pitch of the onion layers */ |
172 | |
173 | |
173 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
174 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
174 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
175 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
… | |
… | |
205 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
206 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
206 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
207 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
207 | |
208 | |
208 | |
209 | |
209 | /* place all the walls */ |
210 | /* place all the walls */ |
210 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
211 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
211 | { |
212 | { |
212 | int x_spaces_available, y_spaces_available; |
213 | int x_spaces_available, y_spaces_available; |
213 | |
214 | |
214 | /* the "extra" spaces available for spacing between layers */ |
215 | /* the "extra" spaces available for spacing between layers */ |
215 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
216 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
… | |
… | |
234 | x_spaces_available -= (int) (xpitch - 2); |
235 | x_spaces_available -= (int) (xpitch - 2); |
235 | y_spaces_available -= (int) (ypitch - 2); |
236 | y_spaces_available -= (int) (ypitch - 2); |
236 | } |
237 | } |
237 | |
238 | |
238 | } |
239 | } |
239 | if (!(option & OPT_IRR_SPACE)) |
240 | if (!(option & RMOPT_IRR_SPACE)) |
240 | { /* evenly spaced */ |
241 | { /* evenly spaced */ |
241 | float xpitch, ypitch; /* pitch of the onion layers */ |
242 | float xpitch, ypitch; /* pitch of the onion layers */ |
242 | |
243 | |
243 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
244 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
244 | ypitch = (ysize - 2.0) / (layers + 1); |
245 | ypitch = (ysize - 2.0) / (layers + 1); |
… | |
… | |
300 | int freedoms; /* number of different walls on which we could place a door */ |
301 | int freedoms; /* number of different walls on which we could place a door */ |
301 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
302 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
302 | int l, x1 = 0, x2, y1 = 0, y2; |
303 | int l, x1 = 0, x2, y1 = 0, y2; |
303 | |
304 | |
304 | freedoms = 4; /* centered */ |
305 | freedoms = 4; /* centered */ |
305 | if (options & OPT_BOTTOM_C) |
306 | if (options & RMOPT_BOTTOM_C) |
306 | freedoms = 3; |
307 | freedoms = 3; |
307 | if (options & OPT_BOTTOM_R) |
308 | if (options & RMOPT_BOTTOM_R) |
308 | freedoms = 2; |
309 | freedoms = 2; |
309 | if (layers <= 0) |
310 | if (layers <= 0) |
310 | return; |
311 | return; |
311 | /* pick which wall will have a door. */ |
312 | /* pick which wall will have a door. */ |
312 | which_wall = RANDOM () % freedoms + 1; |
313 | which_wall = RANDOM () % freedoms + 1; |
313 | for (l = 0; l < layers; l++) |
314 | for (l = 0; l < layers; l++) |
314 | { |
315 | { |
315 | if (options & OPT_LINEAR) |
316 | if (options & RMOPT_LINEAR) |
316 | { /* linear door placement. */ |
317 | { /* linear door placement. */ |
317 | switch (which_wall) |
318 | switch (which_wall) |
318 | { |
319 | { |
319 | case 1: |
320 | case 1: |
320 | { /* left hand wall */ |
321 | { /* left hand wall */ |
321 | x1 = (int) xlocations[l]; |
322 | x1 = (int) xlocations[l]; |
322 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
323 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
323 | break; |
324 | break; |
324 | } |
325 | } |
325 | case 2: |
326 | case 2: |
326 | { /* top wall placement */ |
327 | { /* top wall placement */ |
327 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
328 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
328 | y1 = (int) ylocations[l]; |
329 | y1 = (int) ylocations[l]; |
329 | break; |
330 | break; |
330 | } |
331 | } |
331 | case 3: |
332 | case 3: |
332 | { /* right wall placement */ |
333 | { /* right wall placement */ |
333 | x1 = (int) xlocations[2 * layers - l - 1]; |
334 | x1 = (int) xlocations[2 * layers - l - 1]; |
334 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
335 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
335 | break; |
336 | break; |
336 | } |
337 | } |
337 | case 4: |
338 | case 4: |
338 | { /* bottom wall placement */ |
339 | { /* bottom wall placement */ |
339 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
340 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
340 | y1 = (int) ylocations[2 * layers - l - 1]; |
341 | y1 = (int) ylocations[2 * layers - l - 1]; |
341 | break; |
342 | break; |
342 | } |
343 | } |
343 | } |
344 | } |
344 | } |
345 | } |
345 | else |
346 | else |
346 | { /* random door placement. */ |
347 | { /* random door placement. */ |
347 | which_wall = RANDOM () % freedoms + 1; |
348 | which_wall = RANDOM () % freedoms + 1; |
348 | switch (which_wall) |
349 | switch (which_wall) |
349 | { |
350 | { |
350 | case 1: |
351 | case 1: |
351 | { /* left hand wall */ |
352 | { /* left hand wall */ |
352 | x1 = (int) xlocations[l]; |
353 | x1 = (int) xlocations[l]; |
353 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
354 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
354 | if (y2 > 0) |
355 | if (y2 > 0) |
355 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
356 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
356 | else |
357 | else |
357 | y1 = (int) (ylocations[l] + 1); |
358 | y1 = (int) (ylocations[l] + 1); |
358 | break; |
359 | break; |
359 | } |
360 | } |
360 | case 2: |
361 | case 2: |
361 | { /* top wall placement */ |
362 | { /* top wall placement */ |
362 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
363 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
363 | if (x2 > 0) |
364 | if (x2 > 0) |
364 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
365 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
365 | else |
366 | else |
366 | x1 = (int) (xlocations[l] + 1); |
367 | x1 = (int) (xlocations[l] + 1); |
367 | y1 = (int) ylocations[l]; |
368 | y1 = (int) ylocations[l]; |
368 | break; |
369 | break; |
369 | } |
370 | } |
370 | case 3: |
371 | case 3: |
371 | { /* right wall placement */ |
372 | { /* right wall placement */ |
372 | x1 = (int) xlocations[2 * layers - l - 1]; |
373 | x1 = (int) xlocations[2 * layers - l - 1]; |
373 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
374 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
374 | if (y2 > 0) |
375 | if (y2 > 0) |
375 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
376 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
376 | else |
377 | else |
377 | y1 = (int) (ylocations[l] + 1); |
378 | y1 = (int) (ylocations[l] + 1); |
378 | |
379 | |
379 | break; |
380 | break; |
380 | } |
381 | } |
381 | case 4: |
382 | case 4: |
382 | { /* bottom wall placement */ |
383 | { /* bottom wall placement */ |
383 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
384 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
384 | if (x2 > 0) |
385 | if (x2 > 0) |
385 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
386 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
386 | else |
387 | else |
387 | x1 = (int) (xlocations[l] + 1); |
388 | x1 = (int) (xlocations[l] + 1); |
388 | y1 = (int) ylocations[2 * layers - l - 1]; |
389 | y1 = (int) ylocations[2 * layers - l - 1]; |
389 | break; |
390 | break; |
390 | } |
391 | } |
391 | |
392 | |
392 | } |
393 | } |
393 | } |
394 | } |
394 | if (options & OPT_NO_DOORS) |
395 | if (options & RMOPT_NO_DOORS) |
395 | maze[x1][y1] = '#'; /* no door. */ |
396 | maze[x1][y1] = '#'; /* no door. */ |
396 | else |
397 | else |
397 | maze[x1][y1] = 'D'; /* write the door */ |
398 | maze[x1][y1] = 'D'; /* write the door */ |
398 | |
399 | |
399 | } |
400 | } |
… | |
… | |
426 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
427 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
427 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
428 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
428 | |
429 | |
429 | |
430 | |
430 | /* place all the walls */ |
431 | /* place all the walls */ |
431 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
432 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
432 | { |
433 | { |
433 | int x_spaces_available, y_spaces_available; |
434 | int x_spaces_available, y_spaces_available; |
434 | |
435 | |
435 | /* the "extra" spaces available for spacing between layers */ |
436 | /* the "extra" spaces available for spacing between layers */ |
436 | x_spaces_available = (xsize - 2) - 3 * layers + 1; |
437 | x_spaces_available = (xsize - 2) - 3 * layers + 1; |
… | |
… | |
459 | x_spaces_available -= (int) (xpitch - 2); |
460 | x_spaces_available -= (int) (xpitch - 2); |
460 | y_spaces_available -= (int) (ypitch - 2); |
461 | y_spaces_available -= (int) (ypitch - 2); |
461 | } |
462 | } |
462 | |
463 | |
463 | } |
464 | } |
464 | if (!(option & OPT_IRR_SPACE)) |
465 | if (!(option & RMOPT_IRR_SPACE)) |
465 | { /* evenly spaced */ |
466 | { /* evenly spaced */ |
466 | float xpitch, ypitch; /* pitch of the onion layers */ |
467 | float xpitch, ypitch; /* pitch of the onion layers */ |
467 | |
468 | |
468 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
469 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
469 | ypitch = (ysize - 2.0) / (layers + 1); |
470 | ypitch = (ysize - 2.0) / (layers + 1); |