|
|
1 | |
1 | /* |
2 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
3 | CrossFire, A Multiplayer game for X-windows |
3 | |
4 | |
|
|
5 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
7 | Copyright (C) 1992 Frank Tore Johansen |
6 | |
8 | |
7 | This program is free software; you can redistribute it and/or modify |
9 | 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 |
10 | it under the terms of the GNU General Public License as published by |
… | |
… | |
80 | /* pick some random options if option = 0 */ |
82 | /* pick some random options if option = 0 */ |
81 | if (option == 0) |
83 | if (option == 0) |
82 | { |
84 | { |
83 | switch (RANDOM () % 3) |
85 | switch (RANDOM () % 3) |
84 | { |
86 | { |
85 | case 0: |
87 | case 0: |
86 | option |= RMOPT_CENTERED; |
88 | option |= RMOPT_CENTERED; |
87 | break; |
89 | break; |
88 | case 1: |
90 | case 1: |
89 | option |= RMOPT_BOTTOM_C; |
91 | option |= RMOPT_BOTTOM_C; |
90 | break; |
92 | break; |
91 | case 2: |
93 | case 2: |
92 | option |= RMOPT_BOTTOM_R; |
94 | option |= RMOPT_BOTTOM_R; |
93 | break; |
95 | break; |
94 | } |
96 | } |
95 | if (RANDOM () % 2) |
97 | if (RANDOM () % 2) |
96 | option |= RMOPT_LINEAR; |
98 | option |= RMOPT_LINEAR; |
97 | if (RANDOM () % 2) |
99 | if (RANDOM () % 2) |
98 | option |= RMOPT_IRR_SPACE; |
100 | option |= RMOPT_IRR_SPACE; |
… | |
… | |
138 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
140 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
139 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
141 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
140 | |
142 | |
141 | |
143 | |
142 | /* place all the walls */ |
144 | /* place all the walls */ |
143 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
145 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
144 | { |
146 | { |
145 | int x_spaces_available, y_spaces_available; |
147 | int x_spaces_available, y_spaces_available; |
146 | |
148 | |
147 | /* the "extra" spaces available for spacing between layers */ |
149 | /* the "extra" spaces available for spacing between layers */ |
148 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
150 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
… | |
… | |
205 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
207 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
206 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
208 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
207 | |
209 | |
208 | |
210 | |
209 | /* place all the walls */ |
211 | /* place all the walls */ |
210 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
212 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
211 | { |
213 | { |
212 | int x_spaces_available, y_spaces_available; |
214 | int x_spaces_available, y_spaces_available; |
213 | |
215 | |
214 | /* the "extra" spaces available for spacing between layers */ |
216 | /* the "extra" spaces available for spacing between layers */ |
215 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
217 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
… | |
… | |
314 | { |
316 | { |
315 | if (options & RMOPT_LINEAR) |
317 | if (options & RMOPT_LINEAR) |
316 | { /* linear door placement. */ |
318 | { /* linear door placement. */ |
317 | switch (which_wall) |
319 | switch (which_wall) |
318 | { |
320 | { |
319 | case 1: |
321 | case 1: |
320 | { /* left hand wall */ |
322 | { /* left hand wall */ |
321 | x1 = (int) xlocations[l]; |
323 | x1 = (int) xlocations[l]; |
322 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
324 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
323 | break; |
325 | break; |
324 | } |
326 | } |
325 | case 2: |
327 | case 2: |
326 | { /* top wall placement */ |
328 | { /* top wall placement */ |
327 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
329 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
328 | y1 = (int) ylocations[l]; |
330 | y1 = (int) ylocations[l]; |
329 | break; |
331 | break; |
330 | } |
332 | } |
331 | case 3: |
333 | case 3: |
332 | { /* right wall placement */ |
334 | { /* right wall placement */ |
333 | x1 = (int) xlocations[2 * layers - l - 1]; |
335 | x1 = (int) xlocations[2 * layers - l - 1]; |
334 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
336 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
335 | break; |
337 | break; |
336 | } |
338 | } |
337 | case 4: |
339 | case 4: |
338 | { /* bottom wall placement */ |
340 | { /* bottom wall placement */ |
339 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
341 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
340 | y1 = (int) ylocations[2 * layers - l - 1]; |
342 | y1 = (int) ylocations[2 * layers - l - 1]; |
341 | break; |
343 | break; |
342 | } |
344 | } |
343 | } |
345 | } |
344 | } |
346 | } |
345 | else |
347 | else |
346 | { /* random door placement. */ |
348 | { /* random door placement. */ |
347 | which_wall = RANDOM () % freedoms + 1; |
349 | which_wall = RANDOM () % freedoms + 1; |
348 | switch (which_wall) |
350 | switch (which_wall) |
349 | { |
351 | { |
350 | case 1: |
352 | case 1: |
351 | { /* left hand wall */ |
353 | { /* left hand wall */ |
352 | x1 = (int) xlocations[l]; |
354 | x1 = (int) xlocations[l]; |
353 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
355 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
354 | if (y2 > 0) |
356 | if (y2 > 0) |
355 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
357 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
356 | else |
358 | else |
357 | y1 = (int) (ylocations[l] + 1); |
359 | y1 = (int) (ylocations[l] + 1); |
358 | break; |
360 | break; |
359 | } |
361 | } |
360 | case 2: |
362 | case 2: |
361 | { /* top wall placement */ |
363 | { /* top wall placement */ |
362 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
364 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
363 | if (x2 > 0) |
365 | if (x2 > 0) |
364 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
366 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
365 | else |
367 | else |
366 | x1 = (int) (xlocations[l] + 1); |
368 | x1 = (int) (xlocations[l] + 1); |
367 | y1 = (int) ylocations[l]; |
369 | y1 = (int) ylocations[l]; |
368 | break; |
370 | break; |
369 | } |
371 | } |
370 | case 3: |
372 | case 3: |
371 | { /* right wall placement */ |
373 | { /* right wall placement */ |
372 | x1 = (int) xlocations[2 * layers - l - 1]; |
374 | x1 = (int) xlocations[2 * layers - l - 1]; |
373 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
375 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
374 | if (y2 > 0) |
376 | if (y2 > 0) |
375 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
377 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
376 | else |
378 | else |
377 | y1 = (int) (ylocations[l] + 1); |
379 | y1 = (int) (ylocations[l] + 1); |
378 | |
380 | |
379 | break; |
381 | break; |
380 | } |
382 | } |
381 | case 4: |
383 | case 4: |
382 | { /* bottom wall placement */ |
384 | { /* bottom wall placement */ |
383 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
385 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
384 | if (x2 > 0) |
386 | if (x2 > 0) |
385 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
387 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
386 | else |
388 | else |
387 | x1 = (int) (xlocations[l] + 1); |
389 | x1 = (int) (xlocations[l] + 1); |
388 | y1 = (int) ylocations[2 * layers - l - 1]; |
390 | y1 = (int) ylocations[2 * layers - l - 1]; |
389 | break; |
391 | break; |
390 | } |
392 | } |
391 | |
393 | |
392 | } |
394 | } |
393 | } |
395 | } |
394 | if (options & RMOPT_NO_DOORS) |
396 | if (options & RMOPT_NO_DOORS) |
395 | maze[x1][y1] = '#'; /* no door. */ |
397 | maze[x1][y1] = '#'; /* no door. */ |
… | |
… | |
426 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
428 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
427 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
429 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
428 | |
430 | |
429 | |
431 | |
430 | /* place all the walls */ |
432 | /* place all the walls */ |
431 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
433 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
432 | { |
434 | { |
433 | int x_spaces_available, y_spaces_available; |
435 | int x_spaces_available, y_spaces_available; |
434 | |
436 | |
435 | /* the "extra" spaces available for spacing between layers */ |
437 | /* the "extra" spaces available for spacing between layers */ |
436 | x_spaces_available = (xsize - 2) - 3 * layers + 1; |
438 | x_spaces_available = (xsize - 2) - 3 * layers + 1; |