1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 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: |
… | |
… | |
49 | */ |
50 | */ |
50 | |
51 | |
51 | |
52 | |
52 | #include <global.h> |
53 | #include <global.h> |
53 | #include <random_map.h> |
54 | #include <random_map.h> |
|
|
55 | #include <rproto.h> |
54 | |
56 | |
55 | #ifndef MIN |
|
|
56 | # define MIN(x,y) (((x)<(y))? (x):(y)) |
|
|
57 | #endif |
|
|
58 | void centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
57 | 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); |
58 | 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); |
59 | static void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
61 | |
60 | |
62 | |
|
|
63 | void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
61 | static void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
64 | void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); |
62 | static void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); |
65 | |
63 | |
66 | char ** |
64 | void |
67 | map_gen_onion (int xsize, int ysize, int option, int layers) |
65 | map_gen_onion (Layout maze, int option, int layers) |
68 | { |
66 | { |
69 | int i, j; |
67 | int i, j; |
70 | |
68 | |
71 | /* allocate that array, set it up */ |
69 | int xsize = maze->w; |
72 | char **maze = (char **) calloc (sizeof (char *), xsize); |
70 | int ysize = maze->h; |
73 | |
71 | |
74 | for (i = 0; i < xsize; i++) |
72 | maze->clear (); |
75 | { |
|
|
76 | maze[i] = (char *) calloc (sizeof (char), ysize); |
|
|
77 | } |
|
|
78 | |
73 | |
79 | /* pick some random options if option = 0 */ |
74 | /* pick some random options if option = 0 */ |
80 | if (option == 0) |
75 | if (option == 0) |
81 | { |
76 | { |
82 | switch (rndm (3)) |
77 | switch (rmg_rndm (3)) |
83 | { |
78 | { |
84 | case 0: |
79 | case 0: |
85 | option |= RMOPT_CENTERED; |
80 | option |= RMOPT_CENTERED; |
86 | break; |
81 | break; |
87 | case 1: |
82 | case 1: |
… | |
… | |
89 | break; |
84 | break; |
90 | case 2: |
85 | case 2: |
91 | option |= RMOPT_BOTTOM_R; |
86 | option |= RMOPT_BOTTOM_R; |
92 | break; |
87 | break; |
93 | } |
88 | } |
94 | if (rndm (2)) |
89 | |
95 | option |= RMOPT_LINEAR; |
90 | if (rmg_rndm (2)) option |= RMOPT_LINEAR; |
96 | if (rndm (2)) |
|
|
97 | option |= RMOPT_IRR_SPACE; |
91 | if (rmg_rndm (2)) option |= RMOPT_IRR_SPACE; |
98 | } |
92 | } |
99 | |
93 | |
100 | /* write the outer walls, if appropriate. */ |
94 | /* write the outer walls, if appropriate. */ |
101 | if (!(option & RMOPT_WALL_OFF)) |
95 | if (!(option & RMOPT_WALL_OFF)) |
102 | { |
96 | maze->border (); |
103 | for (i = 0; i < xsize; i++) |
|
|
104 | maze[i][0] = maze[i][ysize - 1] = '#'; |
|
|
105 | for (j = 0; j < ysize; j++) |
|
|
106 | maze[0][j] = maze[xsize - 1][j] = '#'; |
|
|
107 | }; |
|
|
108 | |
97 | |
109 | if (option & RMOPT_WALLS_ONLY) |
98 | if (option & RMOPT_WALLS_ONLY) |
110 | return maze; |
99 | return; |
111 | |
100 | |
112 | /* pick off the mutually exclusive options */ |
101 | /* pick off the mutually exclusive options */ |
113 | if (option & RMOPT_BOTTOM_R) |
102 | if (option & RMOPT_BOTTOM_R) |
114 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
103 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
115 | else if (option & RMOPT_BOTTOM_C) |
104 | else if (option & RMOPT_BOTTOM_C) |
116 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
105 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
117 | else if (option & RMOPT_CENTERED) |
106 | else if (option & RMOPT_CENTERED) |
118 | centered_onion (maze, xsize, ysize, option, layers); |
107 | centered_onion (maze, xsize, ysize, option, layers); |
119 | |
|
|
120 | return maze; |
|
|
121 | } |
108 | } |
122 | |
109 | |
123 | void |
110 | static void |
124 | centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
111 | centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
125 | { |
112 | { |
126 | int i, maxlayers; |
113 | int i, maxlayers; |
127 | float *xlocations; |
|
|
128 | float *ylocations; |
|
|
129 | |
114 | |
130 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
115 | maxlayers = (min (xsize, ysize) - 2) / 5; |
|
|
116 | |
131 | if (!maxlayers) |
117 | if (!maxlayers) |
132 | return; /* map too small to onionize */ |
118 | return; /* map too small to onionize */ |
133 | |
119 | |
134 | if (layers > maxlayers) |
120 | if (layers > maxlayers) |
135 | layers = maxlayers; |
121 | layers = maxlayers; |
136 | |
122 | |
137 | if (layers == 0) |
123 | if (layers == 0) |
138 | layers = rndm (maxlayers) + 1; |
124 | layers = rmg_rndm (maxlayers) + 1; |
139 | |
125 | |
140 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
126 | float *xlocations = salloc0<float> (2 * layers); |
141 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
127 | float *ylocations = salloc0<float> (2 * layers); |
142 | |
128 | |
143 | /* place all the walls */ |
129 | /* place all the walls */ |
144 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
130 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
145 | { |
131 | { |
146 | int x_spaces_available, y_spaces_available; |
132 | int x_spaces_available, y_spaces_available; |
147 | |
133 | |
148 | /* the "extra" spaces available for spacing between layers */ |
134 | /* the "extra" spaces available for spacing between layers */ |
149 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
135 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
150 | y_spaces_available = (ysize - 2) - 6 * layers + 1; |
136 | y_spaces_available = (ysize - 2) - 6 * layers + 1; |
151 | |
137 | |
152 | |
|
|
153 | /* pick an initial random pitch */ |
138 | /* pick an initial random pitch */ |
154 | for (i = 0; i < 2 * layers; i++) |
139 | for (i = 0; i < 2 * layers; i++) |
155 | { |
140 | { |
156 | float xpitch = 2, ypitch = 2; |
141 | float xpitch = 2, ypitch = 2; |
157 | |
142 | |
158 | if (x_spaces_available > 0) |
143 | if (x_spaces_available > 0) |
159 | xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; |
144 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
160 | |
145 | |
161 | if (y_spaces_available > 0) |
146 | if (y_spaces_available > 0) |
162 | ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; |
147 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
163 | |
148 | |
164 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
149 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
165 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
150 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
166 | x_spaces_available -= (int) (xpitch - 2); |
151 | x_spaces_available -= (int) (xpitch - 2); |
167 | y_spaces_available -= (int) (ypitch - 2); |
152 | y_spaces_available -= (int) (ypitch - 2); |
168 | } |
153 | } |
169 | |
154 | |
170 | } |
155 | } |
|
|
156 | |
171 | if (!(option & RMOPT_IRR_SPACE)) |
157 | if (!(option & RMOPT_IRR_SPACE)) |
172 | { /* evenly spaced */ |
158 | { /* evenly spaced */ |
173 | float xpitch, ypitch; /* pitch of the onion layers */ |
159 | float xpitch, ypitch; /* pitch of the onion layers */ |
174 | |
160 | |
175 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
161 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
176 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
162 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
|
|
163 | |
177 | xlocations[0] = xpitch; |
164 | xlocations[0] = xpitch; |
178 | ylocations[0] = ypitch; |
165 | ylocations[0] = ypitch; |
|
|
166 | |
179 | for (i = 1; i < 2 * layers; i++) |
167 | for (i = 1; i < 2 * layers; i++) |
180 | { |
168 | { |
181 | xlocations[i] = xlocations[i - 1] + xpitch; |
169 | xlocations[i] = xlocations[i - 1] + xpitch; |
182 | ylocations[i] = ylocations[i - 1] + ypitch; |
170 | ylocations[i] = ylocations[i - 1] + ypitch; |
183 | } |
171 | } |
184 | } |
172 | } |
185 | |
173 | |
186 | /* draw all the onion boxes. */ |
174 | /* draw all the onion boxes. */ |
187 | |
|
|
188 | draw_onion (maze, xlocations, ylocations, layers); |
175 | draw_onion (maze, xlocations, ylocations, layers); |
189 | make_doors (maze, xlocations, ylocations, layers, option); |
176 | make_doors (maze, xlocations, ylocations, layers, option); |
190 | |
177 | |
|
|
178 | sfree (xlocations, 2 * layers); |
|
|
179 | sfree (ylocations, 2 * layers); |
191 | } |
180 | } |
192 | |
181 | |
193 | void |
182 | static void |
194 | bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
183 | bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
195 | { |
184 | { |
196 | int i, maxlayers; |
185 | int i, maxlayers; |
197 | float *xlocations; |
|
|
198 | float *ylocations; |
|
|
199 | |
186 | |
200 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
187 | maxlayers = (min (xsize, ysize) - 2) / 5; |
|
|
188 | |
201 | if (!maxlayers) |
189 | if (!maxlayers) |
202 | return; /* map too small to onionize */ |
190 | return; /* map too small to onionize */ |
|
|
191 | |
203 | if (layers > maxlayers) |
192 | if (layers > maxlayers) |
204 | layers = maxlayers; |
193 | layers = maxlayers; |
|
|
194 | |
205 | if (layers == 0) |
195 | if (layers == 0) |
206 | layers = rndm (maxlayers) + 1; |
196 | layers = rmg_rndm (maxlayers) + 1; |
207 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
208 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
209 | |
197 | |
|
|
198 | float *xlocations = salloc0<float> (2 * layers); |
|
|
199 | float *ylocations = salloc0<float> (2 * layers); |
210 | |
200 | |
211 | /* place all the walls */ |
201 | /* place all the walls */ |
212 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
202 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
213 | { |
203 | { |
214 | int x_spaces_available, y_spaces_available; |
204 | int x_spaces_available, y_spaces_available; |
215 | |
205 | |
216 | /* the "extra" spaces available for spacing between layers */ |
206 | /* the "extra" spaces available for spacing between layers */ |
217 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
207 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
218 | y_spaces_available = (ysize - 2) - 3 * layers + 1; |
208 | y_spaces_available = (ysize - 2) - 3 * layers + 1; |
219 | |
209 | |
220 | |
|
|
221 | /* pick an initial random pitch */ |
210 | /* pick an initial random pitch */ |
222 | for (i = 0; i < 2 * layers; i++) |
211 | for (i = 0; i < 2 * layers; i++) |
223 | { |
212 | { |
224 | float xpitch = 2, ypitch = 2; |
213 | float xpitch = 2, ypitch = 2; |
225 | |
214 | |
226 | if (x_spaces_available > 0) |
215 | if (x_spaces_available > 0) |
227 | xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; |
216 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
228 | |
217 | |
229 | if (y_spaces_available > 0) |
218 | if (y_spaces_available > 0) |
230 | ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; |
219 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
231 | |
220 | |
232 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
221 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
|
|
222 | |
233 | if (i < layers) |
223 | if (i < layers) |
234 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
224 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
235 | else |
225 | else |
236 | ylocations[i] = ysize - 1; |
226 | ylocations[i] = ysize - 1; |
237 | |
227 | |
238 | x_spaces_available -= (int) (xpitch - 2); |
228 | x_spaces_available -= (int) (xpitch - 2); |
239 | y_spaces_available -= (int) (ypitch - 2); |
229 | y_spaces_available -= (int) (ypitch - 2); |
240 | } |
230 | } |
241 | |
|
|
242 | } |
231 | } |
|
|
232 | |
243 | if (!(option & RMOPT_IRR_SPACE)) |
233 | if (!(option & RMOPT_IRR_SPACE)) |
244 | { /* evenly spaced */ |
234 | { /* evenly spaced */ |
245 | float xpitch, ypitch; /* pitch of the onion layers */ |
235 | float xpitch, ypitch; /* pitch of the onion layers */ |
246 | |
236 | |
247 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
237 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
248 | ypitch = (ysize - 2.0) / (layers + 1); |
238 | ypitch = (ysize - 2.0) / (layers + 1); |
|
|
239 | |
249 | xlocations[0] = xpitch; |
240 | xlocations[0] = xpitch; |
250 | ylocations[0] = ypitch; |
241 | ylocations[0] = ypitch; |
|
|
242 | |
251 | for (i = 1; i < 2 * layers; i++) |
243 | for (i = 1; i < 2 * layers; i++) |
252 | { |
244 | { |
253 | xlocations[i] = xlocations[i - 1] + xpitch; |
245 | xlocations[i] = xlocations[i - 1] + xpitch; |
|
|
246 | |
254 | if (i < layers) |
247 | if (i < layers) |
255 | ylocations[i] = ylocations[i - 1] + ypitch; |
248 | ylocations[i] = ylocations[i - 1] + ypitch; |
256 | else |
249 | else |
257 | ylocations[i] = ysize - 1; |
250 | ylocations[i] = ysize - 1; |
258 | } |
251 | } |
… | |
… | |
261 | /* draw all the onion boxes. */ |
254 | /* draw all the onion boxes. */ |
262 | |
255 | |
263 | draw_onion (maze, xlocations, ylocations, layers); |
256 | draw_onion (maze, xlocations, ylocations, layers); |
264 | make_doors (maze, xlocations, ylocations, layers, option); |
257 | make_doors (maze, xlocations, ylocations, layers, option); |
265 | |
258 | |
|
|
259 | sfree (xlocations, 2 * layers); |
|
|
260 | sfree (ylocations, 2 * layers); |
266 | } |
261 | } |
267 | |
262 | |
268 | |
|
|
269 | /* draw_boxes: draws the lines in the maze defining the onion layers */ |
263 | /* draw_boxes: draws the lines in the maze defining the onion layers */ |
270 | |
264 | static void |
271 | void |
|
|
272 | draw_onion (char **maze, float *xlocations, float *ylocations, int layers) |
265 | draw_onion (char **maze, float *xlocations, float *ylocations, int layers) |
273 | { |
266 | { |
274 | int i, j, l; |
267 | int i, j, l; |
275 | |
268 | |
276 | for (l = 0; l < layers; l++) |
269 | for (l = 0; l < layers; l++) |
… | |
… | |
296 | } |
289 | } |
297 | |
290 | |
298 | } |
291 | } |
299 | } |
292 | } |
300 | |
293 | |
301 | void |
294 | static void |
302 | make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options) |
295 | make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options) |
303 | { |
296 | { |
304 | int freedoms; /* number of different walls on which we could place a door */ |
297 | int freedoms; /* number of different walls on which we could place a door */ |
305 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
298 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
306 | int l, x1 = 0, x2, y1 = 0, y2; |
299 | int l, x1 = 0, x2, y1 = 0, y2; |
307 | |
300 | |
308 | freedoms = 4; /* centered */ |
301 | freedoms = 4; /* centered */ |
|
|
302 | |
309 | if (options & RMOPT_BOTTOM_C) |
303 | if (options & RMOPT_BOTTOM_C) |
310 | freedoms = 3; |
304 | freedoms = 3; |
|
|
305 | |
311 | if (options & RMOPT_BOTTOM_R) |
306 | if (options & RMOPT_BOTTOM_R) |
312 | freedoms = 2; |
307 | freedoms = 2; |
|
|
308 | |
313 | if (layers <= 0) |
309 | if (layers <= 0) |
314 | return; |
310 | return; |
315 | |
311 | |
316 | /* pick which wall will have a door. */ |
312 | /* pick which wall will have a door. */ |
317 | which_wall = rndm (freedoms) + 1; |
313 | which_wall = rmg_rndm (freedoms) + 1; |
318 | for (l = 0; l < layers; l++) |
314 | for (l = 0; l < layers; l++) |
319 | { |
315 | { |
320 | if (options & RMOPT_LINEAR) |
316 | if (options & RMOPT_LINEAR) |
321 | { /* linear door placement. */ |
317 | { /* linear door placement. */ |
322 | switch (which_wall) |
318 | switch (which_wall) |
… | |
… | |
347 | } |
343 | } |
348 | } |
344 | } |
349 | } |
345 | } |
350 | else |
346 | else |
351 | { /* random door placement. */ |
347 | { /* random door placement. */ |
352 | which_wall = rndm (freedoms) + 1; |
348 | which_wall = rmg_rndm (freedoms) + 1; |
353 | switch (which_wall) |
349 | switch (which_wall) |
354 | { |
350 | { |
355 | case 1: |
351 | case 1: |
356 | { /* left hand wall */ |
352 | { /* left hand wall */ |
357 | x1 = (int) xlocations[l]; |
353 | x1 = (int) xlocations[l]; |
358 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
354 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
359 | if (y2 > 0) |
355 | if (y2 > 0) |
360 | y1 = (int) (ylocations[l] + rndm (y2) + 1); |
356 | y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1); |
361 | else |
357 | else |
362 | y1 = (int) (ylocations[l] + 1); |
358 | y1 = (int) (ylocations[l] + 1); |
363 | break; |
359 | break; |
364 | } |
360 | } |
365 | case 2: |
361 | case 2: |
366 | { /* top wall placement */ |
362 | { /* top wall placement */ |
367 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
363 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
368 | if (x2 > 0) |
364 | if (x2 > 0) |
369 | x1 = (int) (xlocations[l] + rndm (x2) + 1); |
365 | x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1); |
370 | else |
366 | else |
371 | x1 = (int) (xlocations[l] + 1); |
367 | x1 = (int) (xlocations[l] + 1); |
372 | y1 = (int) ylocations[l]; |
368 | y1 = (int) ylocations[l]; |
373 | break; |
369 | break; |
374 | } |
370 | } |
375 | case 3: |
371 | case 3: |
376 | { /* right wall placement */ |
372 | { /* right wall placement */ |
377 | x1 = (int) xlocations[2 * layers - l - 1]; |
373 | x1 = (int) xlocations[2 * layers - l - 1]; |
378 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
374 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
379 | if (y2 > 0) |
375 | if (y2 > 0) |
380 | y1 = (int) (ylocations[l] + rndm (y2) + 1); |
376 | y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1); |
381 | else |
377 | else |
382 | y1 = (int) (ylocations[l] + 1); |
378 | y1 = (int) (ylocations[l] + 1); |
383 | |
379 | |
384 | break; |
380 | break; |
385 | } |
381 | } |
386 | case 4: |
382 | case 4: |
387 | { /* bottom wall placement */ |
383 | { /* bottom wall placement */ |
388 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
384 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
389 | if (x2 > 0) |
385 | if (x2 > 0) |
390 | x1 = (int) (xlocations[l] + rndm (x2) + 1); |
386 | x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1); |
391 | else |
387 | else |
392 | x1 = (int) (xlocations[l] + 1); |
388 | x1 = (int) (xlocations[l] + 1); |
393 | y1 = (int) ylocations[2 * layers - l - 1]; |
389 | y1 = (int) ylocations[2 * layers - l - 1]; |
394 | break; |
390 | break; |
395 | } |
391 | } |
396 | |
392 | |
397 | } |
393 | } |
398 | } |
394 | } |
|
|
395 | |
399 | if (options & RMOPT_NO_DOORS) |
396 | if (options & RMOPT_NO_DOORS) |
400 | maze[x1][y1] = '#'; /* no door. */ |
397 | maze[x1][y1] = '#'; /* no door. */ |
401 | else |
398 | else |
402 | maze[x1][y1] = 'D'; /* write the door */ |
399 | maze[x1][y1] = 'D'; /* write the door */ |
403 | |
400 | |
404 | } |
401 | } |
405 | /* mark the center of the maze with a C */ |
402 | /* mark the center of the maze with a C */ |
406 | l = layers - 1; |
403 | l = layers - 1; |
407 | x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2; |
404 | x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2; |
408 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
405 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
|
|
406 | |
409 | maze[x1][y1] = 'C'; |
407 | maze[x1][y1] = 'C'; |
410 | |
|
|
411 | /* not needed anymore */ |
|
|
412 | free (xlocations); |
|
|
413 | free (ylocations); |
|
|
414 | |
|
|
415 | } |
408 | } |
416 | |
409 | |
417 | void |
410 | static void |
418 | bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
411 | bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
419 | { |
412 | { |
420 | int i, maxlayers; |
413 | int i, maxlayers; |
421 | float *xlocations; |
|
|
422 | float *ylocations; |
|
|
423 | |
414 | |
424 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
415 | maxlayers = (min (xsize, ysize) - 2) / 5; |
|
|
416 | |
425 | if (!maxlayers) |
417 | if (!maxlayers) |
426 | return; /* map too small to onionize */ |
418 | return; /* map too small to onionize */ |
|
|
419 | |
427 | if (layers > maxlayers) |
420 | if (layers > maxlayers) |
428 | layers = maxlayers; |
421 | layers = maxlayers; |
|
|
422 | |
429 | if (layers == 0) |
423 | if (layers == 0) |
430 | layers = rndm (maxlayers) + 1; |
424 | layers = rmg_rndm (maxlayers) + 1; |
431 | |
425 | |
432 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
426 | float *xlocations = salloc0<float> (2 * layers); |
433 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
427 | float *ylocations = salloc0<float> (2 * layers); |
434 | |
428 | |
435 | /* place all the walls */ |
429 | /* place all the walls */ |
436 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
430 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
437 | { |
431 | { |
438 | int x_spaces_available, y_spaces_available; |
432 | int x_spaces_available, y_spaces_available; |
… | |
… | |
446 | for (i = 0; i < 2 * layers; i++) |
440 | for (i = 0; i < 2 * layers; i++) |
447 | { |
441 | { |
448 | float xpitch = 2, ypitch = 2; |
442 | float xpitch = 2, ypitch = 2; |
449 | |
443 | |
450 | if (x_spaces_available > 0) |
444 | if (x_spaces_available > 0) |
451 | xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; |
445 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
452 | |
446 | |
453 | if (y_spaces_available > 0) |
447 | if (y_spaces_available > 0) |
454 | ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; |
448 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
455 | |
449 | |
456 | if (i < layers) |
450 | if (i < layers) |
457 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
451 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
458 | else |
452 | else |
459 | xlocations[i] = xsize - 1; |
453 | xlocations[i] = xsize - 1; |
460 | |
454 | |
461 | if (i < layers) |
455 | if (i < layers) |
462 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
456 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
463 | else |
457 | else |
464 | ylocations[i] = ysize - 1; |
458 | ylocations[i] = ysize - 1; |
|
|
459 | |
465 | x_spaces_available -= (int) (xpitch - 2); |
460 | x_spaces_available -= (int) (xpitch - 2); |
466 | y_spaces_available -= (int) (ypitch - 2); |
461 | y_spaces_available -= (int) (ypitch - 2); |
467 | } |
462 | } |
468 | |
|
|
469 | } |
463 | } |
|
|
464 | |
470 | if (!(option & RMOPT_IRR_SPACE)) |
465 | if (!(option & RMOPT_IRR_SPACE)) |
471 | { /* evenly spaced */ |
466 | { /* evenly spaced */ |
472 | float xpitch, ypitch; /* pitch of the onion layers */ |
467 | float xpitch, ypitch; /* pitch of the onion layers */ |
473 | |
468 | |
474 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
469 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
475 | ypitch = (ysize - 2.0) / (layers + 1); |
470 | ypitch = (ysize - 2.0) / (layers + 1); |
|
|
471 | |
476 | xlocations[0] = xpitch; |
472 | xlocations[0] = xpitch; |
477 | ylocations[0] = ypitch; |
473 | ylocations[0] = ypitch; |
|
|
474 | |
478 | for (i = 1; i < 2 * layers; i++) |
475 | for (i = 1; i < 2 * layers; i++) |
479 | { |
476 | { |
480 | if (i < layers) |
477 | if (i < layers) |
481 | xlocations[i] = xlocations[i - 1] + xpitch; |
478 | xlocations[i] = xlocations[i - 1] + xpitch; |
482 | else |
479 | else |
483 | xlocations[i] = xsize - 1; |
480 | xlocations[i] = xsize - 1; |
|
|
481 | |
484 | if (i < layers) |
482 | if (i < layers) |
485 | ylocations[i] = ylocations[i - 1] + ypitch; |
483 | ylocations[i] = ylocations[i - 1] + ypitch; |
486 | else |
484 | else |
487 | ylocations[i] = ysize - 1; |
485 | ylocations[i] = ysize - 1; |
488 | } |
486 | } |
… | |
… | |
491 | /* draw all the onion boxes. */ |
489 | /* draw all the onion boxes. */ |
492 | |
490 | |
493 | draw_onion (maze, xlocations, ylocations, layers); |
491 | draw_onion (maze, xlocations, ylocations, layers); |
494 | make_doors (maze, xlocations, ylocations, layers, option); |
492 | make_doors (maze, xlocations, ylocations, layers, option); |
495 | |
493 | |
|
|
494 | sfree (xlocations, 2 * layers); |
|
|
495 | sfree (ylocations, 2 * layers); |
496 | } |
496 | } |
|
|
497 | |