1 | |
|
|
2 | /* |
|
|
3 | * static char *room_gen_onion_c = |
|
|
4 | * "$Id: room_gen_onion.C,v 1.3 2006/09/10 16:06:37 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | |
24 | |
31 | /* The onion room generator: |
25 | /* The onion room generator: |
32 | Onion rooms are like this: |
26 | Onion rooms are like this: |
… | |
… | |
87 | if (option == 0) |
81 | if (option == 0) |
88 | { |
82 | { |
89 | switch (RANDOM () % 3) |
83 | switch (RANDOM () % 3) |
90 | { |
84 | { |
91 | case 0: |
85 | case 0: |
92 | option |= OPT_CENTERED; |
86 | option |= RMOPT_CENTERED; |
93 | break; |
87 | break; |
94 | case 1: |
88 | case 1: |
95 | option |= OPT_BOTTOM_C; |
89 | option |= RMOPT_BOTTOM_C; |
96 | break; |
90 | break; |
97 | case 2: |
91 | case 2: |
98 | option |= OPT_BOTTOM_R; |
92 | option |= RMOPT_BOTTOM_R; |
99 | break; |
93 | break; |
100 | } |
94 | } |
101 | if (RANDOM () % 2) |
95 | if (RANDOM () % 2) |
102 | option |= OPT_LINEAR; |
96 | option |= RMOPT_LINEAR; |
103 | if (RANDOM () % 2) |
97 | if (RANDOM () % 2) |
104 | option |= OPT_IRR_SPACE; |
98 | option |= RMOPT_IRR_SPACE; |
105 | } |
99 | } |
106 | |
100 | |
107 | /* write the outer walls, if appropriate. */ |
101 | /* write the outer walls, if appropriate. */ |
108 | if (!(option & OPT_WALL_OFF)) |
102 | if (!(option & RMOPT_WALL_OFF)) |
109 | { |
103 | { |
110 | for (i = 0; i < xsize; i++) |
104 | for (i = 0; i < xsize; i++) |
111 | maze[i][0] = maze[i][ysize - 1] = '#'; |
105 | maze[i][0] = maze[i][ysize - 1] = '#'; |
112 | for (j = 0; j < ysize; j++) |
106 | for (j = 0; j < ysize; j++) |
113 | maze[0][j] = maze[xsize - 1][j] = '#'; |
107 | maze[0][j] = maze[xsize - 1][j] = '#'; |
114 | }; |
108 | }; |
115 | |
109 | |
116 | if (option & OPT_WALLS_ONLY) |
110 | if (option & RMOPT_WALLS_ONLY) |
117 | return maze; |
111 | return maze; |
118 | |
112 | |
119 | /* pick off the mutually exclusive options */ |
113 | /* pick off the mutually exclusive options */ |
120 | if (option & OPT_BOTTOM_R) |
114 | if (option & RMOPT_BOTTOM_R) |
121 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
115 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
122 | else if (option & OPT_BOTTOM_C) |
116 | else if (option & RMOPT_BOTTOM_C) |
123 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
117 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
124 | else if (option & OPT_CENTERED) |
118 | else if (option & RMOPT_CENTERED) |
125 | centered_onion (maze, xsize, ysize, option, layers); |
119 | centered_onion (maze, xsize, ysize, option, layers); |
126 | |
120 | |
127 | return maze; |
121 | return maze; |
128 | } |
122 | } |
129 | |
123 | |
… | |
… | |
144 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
138 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
145 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
139 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
146 | |
140 | |
147 | |
141 | |
148 | /* place all the walls */ |
142 | /* place all the walls */ |
149 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
143 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
150 | { |
144 | { |
151 | int x_spaces_available, y_spaces_available; |
145 | int x_spaces_available, y_spaces_available; |
152 | |
146 | |
153 | /* the "extra" spaces available for spacing between layers */ |
147 | /* the "extra" spaces available for spacing between layers */ |
154 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
148 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
… | |
… | |
170 | x_spaces_available -= (int) (xpitch - 2); |
164 | x_spaces_available -= (int) (xpitch - 2); |
171 | y_spaces_available -= (int) (ypitch - 2); |
165 | y_spaces_available -= (int) (ypitch - 2); |
172 | } |
166 | } |
173 | |
167 | |
174 | } |
168 | } |
175 | if (!(option & OPT_IRR_SPACE)) |
169 | if (!(option & RMOPT_IRR_SPACE)) |
176 | { /* evenly spaced */ |
170 | { /* evenly spaced */ |
177 | float xpitch, ypitch; /* pitch of the onion layers */ |
171 | float xpitch, ypitch; /* pitch of the onion layers */ |
178 | |
172 | |
179 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
173 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
180 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
174 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
… | |
… | |
211 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
205 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
212 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
206 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
213 | |
207 | |
214 | |
208 | |
215 | /* place all the walls */ |
209 | /* place all the walls */ |
216 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
210 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
217 | { |
211 | { |
218 | int x_spaces_available, y_spaces_available; |
212 | int x_spaces_available, y_spaces_available; |
219 | |
213 | |
220 | /* the "extra" spaces available for spacing between layers */ |
214 | /* the "extra" spaces available for spacing between layers */ |
221 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
215 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
… | |
… | |
240 | x_spaces_available -= (int) (xpitch - 2); |
234 | x_spaces_available -= (int) (xpitch - 2); |
241 | y_spaces_available -= (int) (ypitch - 2); |
235 | y_spaces_available -= (int) (ypitch - 2); |
242 | } |
236 | } |
243 | |
237 | |
244 | } |
238 | } |
245 | if (!(option & OPT_IRR_SPACE)) |
239 | if (!(option & RMOPT_IRR_SPACE)) |
246 | { /* evenly spaced */ |
240 | { /* evenly spaced */ |
247 | float xpitch, ypitch; /* pitch of the onion layers */ |
241 | float xpitch, ypitch; /* pitch of the onion layers */ |
248 | |
242 | |
249 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
243 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
250 | ypitch = (ysize - 2.0) / (layers + 1); |
244 | ypitch = (ysize - 2.0) / (layers + 1); |
… | |
… | |
306 | int freedoms; /* number of different walls on which we could place a door */ |
300 | int freedoms; /* number of different walls on which we could place a door */ |
307 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
301 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
308 | int l, x1 = 0, x2, y1 = 0, y2; |
302 | int l, x1 = 0, x2, y1 = 0, y2; |
309 | |
303 | |
310 | freedoms = 4; /* centered */ |
304 | freedoms = 4; /* centered */ |
311 | if (options & OPT_BOTTOM_C) |
305 | if (options & RMOPT_BOTTOM_C) |
312 | freedoms = 3; |
306 | freedoms = 3; |
313 | if (options & OPT_BOTTOM_R) |
307 | if (options & RMOPT_BOTTOM_R) |
314 | freedoms = 2; |
308 | freedoms = 2; |
315 | if (layers <= 0) |
309 | if (layers <= 0) |
316 | return; |
310 | return; |
317 | /* pick which wall will have a door. */ |
311 | /* pick which wall will have a door. */ |
318 | which_wall = RANDOM () % freedoms + 1; |
312 | which_wall = RANDOM () % freedoms + 1; |
319 | for (l = 0; l < layers; l++) |
313 | for (l = 0; l < layers; l++) |
320 | { |
314 | { |
321 | if (options & OPT_LINEAR) |
315 | if (options & RMOPT_LINEAR) |
322 | { /* linear door placement. */ |
316 | { /* linear door placement. */ |
323 | switch (which_wall) |
317 | switch (which_wall) |
324 | { |
318 | { |
325 | case 1: |
319 | case 1: |
326 | { /* left hand wall */ |
320 | { /* left hand wall */ |
… | |
… | |
395 | break; |
389 | break; |
396 | } |
390 | } |
397 | |
391 | |
398 | } |
392 | } |
399 | } |
393 | } |
400 | if (options & OPT_NO_DOORS) |
394 | if (options & RMOPT_NO_DOORS) |
401 | maze[x1][y1] = '#'; /* no door. */ |
395 | maze[x1][y1] = '#'; /* no door. */ |
402 | else |
396 | else |
403 | maze[x1][y1] = 'D'; /* write the door */ |
397 | maze[x1][y1] = 'D'; /* write the door */ |
404 | |
398 | |
405 | } |
399 | } |
… | |
… | |
432 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
426 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
433 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
427 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
434 | |
428 | |
435 | |
429 | |
436 | /* place all the walls */ |
430 | /* place all the walls */ |
437 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
431 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
438 | { |
432 | { |
439 | int x_spaces_available, y_spaces_available; |
433 | int x_spaces_available, y_spaces_available; |
440 | |
434 | |
441 | /* the "extra" spaces available for spacing between layers */ |
435 | /* the "extra" spaces available for spacing between layers */ |
442 | x_spaces_available = (xsize - 2) - 3 * layers + 1; |
436 | x_spaces_available = (xsize - 2) - 3 * layers + 1; |
… | |
… | |
465 | x_spaces_available -= (int) (xpitch - 2); |
459 | x_spaces_available -= (int) (xpitch - 2); |
466 | y_spaces_available -= (int) (ypitch - 2); |
460 | y_spaces_available -= (int) (ypitch - 2); |
467 | } |
461 | } |
468 | |
462 | |
469 | } |
463 | } |
470 | if (!(option & OPT_IRR_SPACE)) |
464 | if (!(option & RMOPT_IRR_SPACE)) |
471 | { /* evenly spaced */ |
465 | { /* evenly spaced */ |
472 | float xpitch, ypitch; /* pitch of the onion layers */ |
466 | float xpitch, ypitch; /* pitch of the onion layers */ |
473 | |
467 | |
474 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
468 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
475 | ypitch = (ysize - 2.0) / (layers + 1); |
469 | ypitch = (ysize - 2.0) / (layers + 1); |