… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * 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, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* The onion room generator: |
25 | /* The onion room generator: |
… | |
… | |
53 | #include <random_map.h> |
54 | #include <random_map.h> |
54 | |
55 | |
55 | #ifndef MIN |
56 | #ifndef MIN |
56 | # define MIN(x,y) (((x)<(y))? (x):(y)) |
57 | # define MIN(x,y) (((x)<(y))? (x):(y)) |
57 | #endif |
58 | #endif |
|
|
59 | |
58 | void centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
60 | static void centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
59 | void bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
61 | static void bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
60 | void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
62 | static void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
61 | |
63 | |
62 | void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
64 | static void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
63 | void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); |
65 | static void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); |
64 | |
66 | |
65 | Maze |
67 | void |
66 | map_gen_onion (int xsize, int ysize, int option, int layers) |
68 | map_gen_onion (Layout maze, int option, int layers) |
67 | { |
69 | { |
68 | int i, j; |
70 | int i, j; |
69 | |
71 | |
70 | Maze maze (xsize, ysize); |
72 | int xsize = maze->w; |
|
|
73 | int ysize = maze->h; |
|
|
74 | |
|
|
75 | maze->clear (); |
71 | |
76 | |
72 | /* pick some random options if option = 0 */ |
77 | /* pick some random options if option = 0 */ |
73 | if (option == 0) |
78 | if (option == 0) |
74 | { |
79 | { |
75 | switch (rndm (3)) |
80 | switch (rmg_rndm (3)) |
76 | { |
81 | { |
77 | case 0: |
82 | case 0: |
78 | option |= RMOPT_CENTERED; |
83 | option |= RMOPT_CENTERED; |
79 | break; |
84 | break; |
80 | case 1: |
85 | case 1: |
… | |
… | |
83 | case 2: |
88 | case 2: |
84 | option |= RMOPT_BOTTOM_R; |
89 | option |= RMOPT_BOTTOM_R; |
85 | break; |
90 | break; |
86 | } |
91 | } |
87 | |
92 | |
88 | if (rndm (2)) option |= RMOPT_LINEAR; |
93 | if (rmg_rndm (2)) option |= RMOPT_LINEAR; |
89 | if (rndm (2)) option |= RMOPT_IRR_SPACE; |
94 | if (rmg_rndm (2)) option |= RMOPT_IRR_SPACE; |
90 | } |
95 | } |
91 | |
96 | |
92 | /* write the outer walls, if appropriate. */ |
97 | /* write the outer walls, if appropriate. */ |
93 | if (!(option & RMOPT_WALL_OFF)) |
98 | if (!(option & RMOPT_WALL_OFF)) |
94 | { |
99 | maze->border (); |
95 | for (i = 0; i < xsize; i++) maze[i][0] = maze[i][ysize - 1] = '#'; |
|
|
96 | for (j = 0; j < ysize; j++) maze[0][j] = maze[xsize - 1][j] = '#'; |
|
|
97 | }; |
|
|
98 | |
100 | |
99 | if (option & RMOPT_WALLS_ONLY) |
101 | if (option & RMOPT_WALLS_ONLY) |
100 | return maze; |
102 | return; |
101 | |
103 | |
102 | /* pick off the mutually exclusive options */ |
104 | /* pick off the mutually exclusive options */ |
103 | if (option & RMOPT_BOTTOM_R) |
105 | if (option & RMOPT_BOTTOM_R) |
104 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
106 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
105 | else if (option & RMOPT_BOTTOM_C) |
107 | else if (option & RMOPT_BOTTOM_C) |
106 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
108 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
107 | else if (option & RMOPT_CENTERED) |
109 | else if (option & RMOPT_CENTERED) |
108 | centered_onion (maze, xsize, ysize, option, layers); |
110 | centered_onion (maze, xsize, ysize, option, layers); |
109 | |
|
|
110 | return maze; |
|
|
111 | } |
111 | } |
112 | |
112 | |
113 | void |
113 | static void |
114 | centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
114 | centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
115 | { |
115 | { |
116 | int i, maxlayers; |
116 | int i, maxlayers; |
117 | |
117 | |
118 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
118 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
… | |
… | |
122 | |
122 | |
123 | if (layers > maxlayers) |
123 | if (layers > maxlayers) |
124 | layers = maxlayers; |
124 | layers = maxlayers; |
125 | |
125 | |
126 | if (layers == 0) |
126 | if (layers == 0) |
127 | layers = rndm (maxlayers) + 1; |
127 | layers = rmg_rndm (maxlayers) + 1; |
128 | |
128 | |
129 | float *xlocations = salloc0<float> (2 * layers); |
129 | float *xlocations = salloc0<float> (2 * layers); |
130 | float *ylocations = salloc0<float> (2 * layers); |
130 | float *ylocations = salloc0<float> (2 * layers); |
131 | |
131 | |
132 | /* place all the walls */ |
132 | /* place all the walls */ |
… | |
… | |
142 | for (i = 0; i < 2 * layers; i++) |
142 | for (i = 0; i < 2 * layers; i++) |
143 | { |
143 | { |
144 | float xpitch = 2, ypitch = 2; |
144 | float xpitch = 2, ypitch = 2; |
145 | |
145 | |
146 | if (x_spaces_available > 0) |
146 | if (x_spaces_available > 0) |
147 | xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; |
147 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
148 | |
148 | |
149 | if (y_spaces_available > 0) |
149 | if (y_spaces_available > 0) |
150 | ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; |
150 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
151 | |
151 | |
152 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
152 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
153 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
153 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
154 | x_spaces_available -= (int) (xpitch - 2); |
154 | x_spaces_available -= (int) (xpitch - 2); |
155 | y_spaces_available -= (int) (ypitch - 2); |
155 | y_spaces_available -= (int) (ypitch - 2); |
… | |
… | |
180 | |
180 | |
181 | sfree (xlocations, 2 * layers); |
181 | sfree (xlocations, 2 * layers); |
182 | sfree (ylocations, 2 * layers); |
182 | sfree (ylocations, 2 * layers); |
183 | } |
183 | } |
184 | |
184 | |
185 | void |
185 | static void |
186 | bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
186 | bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
187 | { |
187 | { |
188 | int i, maxlayers; |
188 | int i, maxlayers; |
189 | |
189 | |
190 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
190 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
… | |
… | |
194 | |
194 | |
195 | if (layers > maxlayers) |
195 | if (layers > maxlayers) |
196 | layers = maxlayers; |
196 | layers = maxlayers; |
197 | |
197 | |
198 | if (layers == 0) |
198 | if (layers == 0) |
199 | layers = rndm (maxlayers) + 1; |
199 | layers = rmg_rndm (maxlayers) + 1; |
200 | |
200 | |
201 | float *xlocations = salloc0<float> (2 * layers); |
201 | float *xlocations = salloc0<float> (2 * layers); |
202 | float *ylocations = salloc0<float> (2 * layers); |
202 | float *ylocations = salloc0<float> (2 * layers); |
203 | |
203 | |
204 | /* place all the walls */ |
204 | /* place all the walls */ |
… | |
… | |
214 | for (i = 0; i < 2 * layers; i++) |
214 | for (i = 0; i < 2 * layers; i++) |
215 | { |
215 | { |
216 | float xpitch = 2, ypitch = 2; |
216 | float xpitch = 2, ypitch = 2; |
217 | |
217 | |
218 | if (x_spaces_available > 0) |
218 | if (x_spaces_available > 0) |
219 | xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; |
219 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
220 | |
220 | |
221 | if (y_spaces_available > 0) |
221 | if (y_spaces_available > 0) |
222 | ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; |
222 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
223 | |
223 | |
224 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
224 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
225 | |
225 | |
226 | if (i < layers) |
226 | if (i < layers) |
227 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
227 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
… | |
… | |
261 | |
261 | |
262 | sfree (xlocations, 2 * layers); |
262 | sfree (xlocations, 2 * layers); |
263 | sfree (ylocations, 2 * layers); |
263 | sfree (ylocations, 2 * layers); |
264 | } |
264 | } |
265 | |
265 | |
266 | /* draw_boxes: draws the lines in the maze defining the onion layers */ |
266 | /* draw_boxes: draws the lines in the maze defining the onion layers */ |
267 | void |
267 | static void |
268 | draw_onion (char **maze, float *xlocations, float *ylocations, int layers) |
268 | draw_onion (char **maze, float *xlocations, float *ylocations, int layers) |
269 | { |
269 | { |
270 | int i, j, l; |
270 | int i, j, l; |
271 | |
271 | |
272 | for (l = 0; l < layers; l++) |
272 | for (l = 0; l < layers; l++) |
… | |
… | |
292 | } |
292 | } |
293 | |
293 | |
294 | } |
294 | } |
295 | } |
295 | } |
296 | |
296 | |
297 | void |
297 | static void |
298 | make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options) |
298 | make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options) |
299 | { |
299 | { |
300 | 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 */ |
301 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
301 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
302 | int l, x1 = 0, x2, y1 = 0, y2; |
302 | int l, x1 = 0, x2, y1 = 0, y2; |
… | |
… | |
311 | |
311 | |
312 | if (layers <= 0) |
312 | if (layers <= 0) |
313 | return; |
313 | return; |
314 | |
314 | |
315 | /* pick which wall will have a door. */ |
315 | /* pick which wall will have a door. */ |
316 | which_wall = rndm (freedoms) + 1; |
316 | which_wall = rmg_rndm (freedoms) + 1; |
317 | for (l = 0; l < layers; l++) |
317 | for (l = 0; l < layers; l++) |
318 | { |
318 | { |
319 | if (options & RMOPT_LINEAR) |
319 | if (options & RMOPT_LINEAR) |
320 | { /* linear door placement. */ |
320 | { /* linear door placement. */ |
321 | switch (which_wall) |
321 | switch (which_wall) |
… | |
… | |
346 | } |
346 | } |
347 | } |
347 | } |
348 | } |
348 | } |
349 | else |
349 | else |
350 | { /* random door placement. */ |
350 | { /* random door placement. */ |
351 | which_wall = rndm (freedoms) + 1; |
351 | which_wall = rmg_rndm (freedoms) + 1; |
352 | switch (which_wall) |
352 | switch (which_wall) |
353 | { |
353 | { |
354 | case 1: |
354 | case 1: |
355 | { /* left hand wall */ |
355 | { /* left hand wall */ |
356 | x1 = (int) xlocations[l]; |
356 | x1 = (int) xlocations[l]; |
357 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
357 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
358 | if (y2 > 0) |
358 | if (y2 > 0) |
359 | y1 = (int) (ylocations[l] + rndm (y2) + 1); |
359 | y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1); |
360 | else |
360 | else |
361 | y1 = (int) (ylocations[l] + 1); |
361 | y1 = (int) (ylocations[l] + 1); |
362 | break; |
362 | break; |
363 | } |
363 | } |
364 | case 2: |
364 | case 2: |
365 | { /* top wall placement */ |
365 | { /* top wall placement */ |
366 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
366 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
367 | if (x2 > 0) |
367 | if (x2 > 0) |
368 | x1 = (int) (xlocations[l] + rndm (x2) + 1); |
368 | x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1); |
369 | else |
369 | else |
370 | x1 = (int) (xlocations[l] + 1); |
370 | x1 = (int) (xlocations[l] + 1); |
371 | y1 = (int) ylocations[l]; |
371 | y1 = (int) ylocations[l]; |
372 | break; |
372 | break; |
373 | } |
373 | } |
374 | case 3: |
374 | case 3: |
375 | { /* right wall placement */ |
375 | { /* right wall placement */ |
376 | x1 = (int) xlocations[2 * layers - l - 1]; |
376 | x1 = (int) xlocations[2 * layers - l - 1]; |
377 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
377 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
378 | if (y2 > 0) |
378 | if (y2 > 0) |
379 | y1 = (int) (ylocations[l] + rndm (y2) + 1); |
379 | y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1); |
380 | else |
380 | else |
381 | y1 = (int) (ylocations[l] + 1); |
381 | y1 = (int) (ylocations[l] + 1); |
382 | |
382 | |
383 | break; |
383 | break; |
384 | } |
384 | } |
385 | case 4: |
385 | case 4: |
386 | { /* bottom wall placement */ |
386 | { /* bottom wall placement */ |
387 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
387 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
388 | if (x2 > 0) |
388 | if (x2 > 0) |
389 | x1 = (int) (xlocations[l] + rndm (x2) + 1); |
389 | x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1); |
390 | else |
390 | else |
391 | x1 = (int) (xlocations[l] + 1); |
391 | x1 = (int) (xlocations[l] + 1); |
392 | y1 = (int) ylocations[2 * layers - l - 1]; |
392 | y1 = (int) ylocations[2 * layers - l - 1]; |
393 | break; |
393 | break; |
394 | } |
394 | } |
… | |
… | |
408 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
408 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
409 | |
409 | |
410 | maze[x1][y1] = 'C'; |
410 | maze[x1][y1] = 'C'; |
411 | } |
411 | } |
412 | |
412 | |
413 | void |
413 | static void |
414 | bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
414 | bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
415 | { |
415 | { |
416 | int i, maxlayers; |
416 | int i, maxlayers; |
417 | |
417 | |
418 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
418 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
… | |
… | |
422 | |
422 | |
423 | if (layers > maxlayers) |
423 | if (layers > maxlayers) |
424 | layers = maxlayers; |
424 | layers = maxlayers; |
425 | |
425 | |
426 | if (layers == 0) |
426 | if (layers == 0) |
427 | layers = rndm (maxlayers) + 1; |
427 | layers = rmg_rndm (maxlayers) + 1; |
428 | |
428 | |
429 | float *xlocations = salloc0<float> (2 * layers); |
429 | float *xlocations = salloc0<float> (2 * layers); |
430 | float *ylocations = salloc0<float> (2 * layers); |
430 | float *ylocations = salloc0<float> (2 * layers); |
431 | |
431 | |
432 | /* place all the walls */ |
432 | /* place all the walls */ |
… | |
… | |
443 | for (i = 0; i < 2 * layers; i++) |
443 | for (i = 0; i < 2 * layers; i++) |
444 | { |
444 | { |
445 | float xpitch = 2, ypitch = 2; |
445 | float xpitch = 2, ypitch = 2; |
446 | |
446 | |
447 | if (x_spaces_available > 0) |
447 | if (x_spaces_available > 0) |
448 | xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; |
448 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
449 | |
449 | |
450 | if (y_spaces_available > 0) |
450 | if (y_spaces_available > 0) |
451 | ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; |
451 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
452 | |
452 | |
453 | if (i < layers) |
453 | if (i < layers) |
454 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
454 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
455 | else |
455 | else |
456 | xlocations[i] = xsize - 1; |
456 | xlocations[i] = xsize - 1; |