1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra 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 3 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, see <http://www.gnu.org/licenses/>. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * |
20 | |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
|
|
22 | */ |
22 | */ |
23 | |
|
|
24 | |
23 | |
25 | /* The onion room generator: |
24 | /* The onion room generator: |
26 | Onion rooms are like this: |
25 | Onion rooms are like this: |
27 | |
26 | |
28 | char **map_gen_onion(int xsize, int ysize, int option, int layers); |
27 | char **map_gen_onion(int xsize, int ysize, int option, int layers); |
… | |
… | |
58 | #endif |
57 | #endif |
59 | void centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
58 | void centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
60 | void bottom_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 | void bottom_right_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 | |
61 | |
63 | |
|
|
64 | void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
62 | void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
65 | void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); |
63 | void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); |
66 | |
64 | |
67 | char ** |
65 | Maze |
68 | map_gen_onion (int xsize, int ysize, int option, int layers) |
66 | map_gen_onion (int xsize, int ysize, int option, int layers) |
69 | { |
67 | { |
70 | int i, j; |
68 | int i, j; |
71 | |
69 | |
72 | /* allocate that array, set it up */ |
70 | Maze maze (xsize, ysize); |
73 | char **maze = (char **) calloc (sizeof (char *), xsize); |
|
|
74 | |
|
|
75 | for (i = 0; i < xsize; i++) |
|
|
76 | { |
|
|
77 | maze[i] = (char *) calloc (sizeof (char), ysize); |
|
|
78 | } |
|
|
79 | |
71 | |
80 | /* pick some random options if option = 0 */ |
72 | /* pick some random options if option = 0 */ |
81 | if (option == 0) |
73 | if (option == 0) |
82 | { |
74 | { |
83 | switch (RANDOM () % 3) |
75 | switch (rndm (3)) |
84 | { |
76 | { |
85 | case 0: |
77 | case 0: |
86 | option |= RMOPT_CENTERED; |
78 | option |= RMOPT_CENTERED; |
87 | break; |
79 | break; |
88 | case 1: |
80 | case 1: |
89 | option |= RMOPT_BOTTOM_C; |
81 | option |= RMOPT_BOTTOM_C; |
90 | break; |
82 | break; |
91 | case 2: |
83 | case 2: |
92 | option |= RMOPT_BOTTOM_R; |
84 | option |= RMOPT_BOTTOM_R; |
93 | break; |
85 | break; |
94 | } |
86 | } |
95 | if (RANDOM () % 2) |
87 | |
96 | option |= RMOPT_LINEAR; |
88 | if (rndm (2)) option |= RMOPT_LINEAR; |
97 | if (RANDOM () % 2) |
|
|
98 | option |= RMOPT_IRR_SPACE; |
89 | if (rndm (2)) option |= RMOPT_IRR_SPACE; |
99 | } |
90 | } |
100 | |
91 | |
101 | /* write the outer walls, if appropriate. */ |
92 | /* write the outer walls, if appropriate. */ |
102 | if (!(option & RMOPT_WALL_OFF)) |
93 | if (!(option & RMOPT_WALL_OFF)) |
103 | { |
94 | { |
104 | for (i = 0; i < xsize; i++) |
|
|
105 | maze[i][0] = maze[i][ysize - 1] = '#'; |
95 | for (i = 0; i < xsize; i++) maze[i][0] = maze[i][ysize - 1] = '#'; |
106 | for (j = 0; j < ysize; j++) |
|
|
107 | maze[0][j] = maze[xsize - 1][j] = '#'; |
96 | for (j = 0; j < ysize; j++) maze[0][j] = maze[xsize - 1][j] = '#'; |
108 | }; |
97 | }; |
109 | |
98 | |
110 | if (option & RMOPT_WALLS_ONLY) |
99 | if (option & RMOPT_WALLS_ONLY) |
111 | return maze; |
100 | return maze; |
112 | |
101 | |
… | |
… | |
123 | |
112 | |
124 | void |
113 | void |
125 | 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) |
126 | { |
115 | { |
127 | int i, maxlayers; |
116 | int i, maxlayers; |
128 | float *xlocations; |
|
|
129 | float *ylocations; |
|
|
130 | |
117 | |
131 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
118 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
|
|
119 | |
132 | if (!maxlayers) |
120 | if (!maxlayers) |
133 | return; /* map too small to onionize */ |
121 | return; /* map too small to onionize */ |
|
|
122 | |
134 | if (layers > maxlayers) |
123 | if (layers > maxlayers) |
135 | layers = maxlayers; |
124 | layers = maxlayers; |
|
|
125 | |
136 | if (layers == 0) |
126 | if (layers == 0) |
137 | layers = (RANDOM () % maxlayers) + 1; |
127 | layers = rndm (maxlayers) + 1; |
138 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
139 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
140 | |
128 | |
|
|
129 | float *xlocations = salloc0<float> (2 * layers); |
|
|
130 | float *ylocations = salloc0<float> (2 * layers); |
141 | |
131 | |
142 | /* place all the walls */ |
132 | /* place all the walls */ |
143 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
133 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
144 | { |
134 | { |
145 | int x_spaces_available, y_spaces_available; |
135 | int x_spaces_available, y_spaces_available; |
146 | |
136 | |
147 | /* the "extra" spaces available for spacing between layers */ |
137 | /* the "extra" spaces available for spacing between layers */ |
148 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
138 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
149 | y_spaces_available = (ysize - 2) - 6 * layers + 1; |
139 | y_spaces_available = (ysize - 2) - 6 * layers + 1; |
150 | |
140 | |
151 | |
|
|
152 | /* pick an initial random pitch */ |
141 | /* pick an initial random pitch */ |
153 | for (i = 0; i < 2 * layers; i++) |
142 | for (i = 0; i < 2 * layers; i++) |
154 | { |
143 | { |
155 | float xpitch = 2, ypitch = 2; |
144 | float xpitch = 2, ypitch = 2; |
156 | |
145 | |
157 | if (x_spaces_available > 0) |
146 | if (x_spaces_available > 0) |
158 | xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; |
147 | xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; |
159 | |
148 | |
160 | if (y_spaces_available > 0) |
149 | if (y_spaces_available > 0) |
161 | ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; |
150 | ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; |
|
|
151 | |
162 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
152 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
163 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
153 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
164 | x_spaces_available -= (int) (xpitch - 2); |
154 | x_spaces_available -= (int) (xpitch - 2); |
165 | y_spaces_available -= (int) (ypitch - 2); |
155 | y_spaces_available -= (int) (ypitch - 2); |
166 | } |
156 | } |
167 | |
157 | |
168 | } |
158 | } |
|
|
159 | |
169 | if (!(option & RMOPT_IRR_SPACE)) |
160 | if (!(option & RMOPT_IRR_SPACE)) |
170 | { /* evenly spaced */ |
161 | { /* evenly spaced */ |
171 | float xpitch, ypitch; /* pitch of the onion layers */ |
162 | float xpitch, ypitch; /* pitch of the onion layers */ |
172 | |
163 | |
173 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
164 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
174 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
165 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
|
|
166 | |
175 | xlocations[0] = xpitch; |
167 | xlocations[0] = xpitch; |
176 | ylocations[0] = ypitch; |
168 | ylocations[0] = ypitch; |
|
|
169 | |
177 | for (i = 1; i < 2 * layers; i++) |
170 | for (i = 1; i < 2 * layers; i++) |
178 | { |
171 | { |
179 | xlocations[i] = xlocations[i - 1] + xpitch; |
172 | xlocations[i] = xlocations[i - 1] + xpitch; |
180 | ylocations[i] = ylocations[i - 1] + ypitch; |
173 | ylocations[i] = ylocations[i - 1] + ypitch; |
181 | } |
174 | } |
182 | } |
175 | } |
183 | |
176 | |
184 | /* draw all the onion boxes. */ |
177 | /* draw all the onion boxes. */ |
185 | |
|
|
186 | draw_onion (maze, xlocations, ylocations, layers); |
178 | draw_onion (maze, xlocations, ylocations, layers); |
187 | make_doors (maze, xlocations, ylocations, layers, option); |
179 | make_doors (maze, xlocations, ylocations, layers, option); |
188 | |
180 | |
|
|
181 | sfree (xlocations, 2 * layers); |
|
|
182 | sfree (ylocations, 2 * layers); |
189 | } |
183 | } |
190 | |
184 | |
191 | void |
185 | void |
192 | 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) |
193 | { |
187 | { |
194 | int i, maxlayers; |
188 | int i, maxlayers; |
195 | float *xlocations; |
|
|
196 | float *ylocations; |
|
|
197 | |
189 | |
198 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
190 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
|
|
191 | |
199 | if (!maxlayers) |
192 | if (!maxlayers) |
200 | return; /* map too small to onionize */ |
193 | return; /* map too small to onionize */ |
|
|
194 | |
201 | if (layers > maxlayers) |
195 | if (layers > maxlayers) |
202 | layers = maxlayers; |
196 | layers = maxlayers; |
|
|
197 | |
203 | if (layers == 0) |
198 | if (layers == 0) |
204 | layers = (RANDOM () % maxlayers) + 1; |
199 | layers = rndm (maxlayers) + 1; |
205 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
206 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
207 | |
200 | |
|
|
201 | float *xlocations = salloc0<float> (2 * layers); |
|
|
202 | float *ylocations = salloc0<float> (2 * layers); |
208 | |
203 | |
209 | /* place all the walls */ |
204 | /* place all the walls */ |
210 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
205 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
211 | { |
206 | { |
212 | int x_spaces_available, y_spaces_available; |
207 | int x_spaces_available, y_spaces_available; |
213 | |
208 | |
214 | /* the "extra" spaces available for spacing between layers */ |
209 | /* the "extra" spaces available for spacing between layers */ |
215 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
210 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
216 | y_spaces_available = (ysize - 2) - 3 * layers + 1; |
211 | y_spaces_available = (ysize - 2) - 3 * layers + 1; |
217 | |
212 | |
218 | |
|
|
219 | /* pick an initial random pitch */ |
213 | /* pick an initial random pitch */ |
220 | for (i = 0; i < 2 * layers; i++) |
214 | for (i = 0; i < 2 * layers; i++) |
221 | { |
215 | { |
222 | float xpitch = 2, ypitch = 2; |
216 | float xpitch = 2, ypitch = 2; |
223 | |
217 | |
224 | if (x_spaces_available > 0) |
218 | if (x_spaces_available > 0) |
225 | xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; |
219 | xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; |
226 | |
220 | |
227 | if (y_spaces_available > 0) |
221 | if (y_spaces_available > 0) |
228 | ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; |
222 | ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; |
|
|
223 | |
229 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
224 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
|
|
225 | |
230 | if (i < layers) |
226 | if (i < layers) |
231 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
227 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
232 | else |
228 | else |
233 | ylocations[i] = ysize - 1; |
229 | ylocations[i] = ysize - 1; |
|
|
230 | |
234 | x_spaces_available -= (int) (xpitch - 2); |
231 | x_spaces_available -= (int) (xpitch - 2); |
235 | y_spaces_available -= (int) (ypitch - 2); |
232 | y_spaces_available -= (int) (ypitch - 2); |
236 | } |
233 | } |
237 | |
|
|
238 | } |
234 | } |
|
|
235 | |
239 | if (!(option & RMOPT_IRR_SPACE)) |
236 | if (!(option & RMOPT_IRR_SPACE)) |
240 | { /* evenly spaced */ |
237 | { /* evenly spaced */ |
241 | float xpitch, ypitch; /* pitch of the onion layers */ |
238 | float xpitch, ypitch; /* pitch of the onion layers */ |
242 | |
239 | |
243 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
240 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
244 | ypitch = (ysize - 2.0) / (layers + 1); |
241 | ypitch = (ysize - 2.0) / (layers + 1); |
|
|
242 | |
245 | xlocations[0] = xpitch; |
243 | xlocations[0] = xpitch; |
246 | ylocations[0] = ypitch; |
244 | ylocations[0] = ypitch; |
|
|
245 | |
247 | for (i = 1; i < 2 * layers; i++) |
246 | for (i = 1; i < 2 * layers; i++) |
248 | { |
247 | { |
249 | xlocations[i] = xlocations[i - 1] + xpitch; |
248 | xlocations[i] = xlocations[i - 1] + xpitch; |
|
|
249 | |
250 | if (i < layers) |
250 | if (i < layers) |
251 | ylocations[i] = ylocations[i - 1] + ypitch; |
251 | ylocations[i] = ylocations[i - 1] + ypitch; |
252 | else |
252 | else |
253 | ylocations[i] = ysize - 1; |
253 | ylocations[i] = ysize - 1; |
254 | } |
254 | } |
… | |
… | |
257 | /* draw all the onion boxes. */ |
257 | /* draw all the onion boxes. */ |
258 | |
258 | |
259 | draw_onion (maze, xlocations, ylocations, layers); |
259 | draw_onion (maze, xlocations, ylocations, layers); |
260 | make_doors (maze, xlocations, ylocations, layers, option); |
260 | make_doors (maze, xlocations, ylocations, layers, option); |
261 | |
261 | |
|
|
262 | sfree (xlocations, 2 * layers); |
|
|
263 | sfree (ylocations, 2 * layers); |
262 | } |
264 | } |
263 | |
265 | |
264 | |
|
|
265 | /* 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 */ |
266 | |
|
|
267 | void |
267 | 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 | |
… | |
… | |
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; |
303 | |
303 | |
304 | freedoms = 4; /* centered */ |
304 | freedoms = 4; /* centered */ |
|
|
305 | |
305 | if (options & RMOPT_BOTTOM_C) |
306 | if (options & RMOPT_BOTTOM_C) |
306 | freedoms = 3; |
307 | freedoms = 3; |
|
|
308 | |
307 | if (options & RMOPT_BOTTOM_R) |
309 | if (options & RMOPT_BOTTOM_R) |
308 | freedoms = 2; |
310 | freedoms = 2; |
|
|
311 | |
309 | if (layers <= 0) |
312 | if (layers <= 0) |
310 | return; |
313 | return; |
|
|
314 | |
311 | /* pick which wall will have a door. */ |
315 | /* pick which wall will have a door. */ |
312 | which_wall = RANDOM () % freedoms + 1; |
316 | which_wall = rndm (freedoms) + 1; |
313 | for (l = 0; l < layers; l++) |
317 | for (l = 0; l < layers; l++) |
314 | { |
318 | { |
315 | if (options & RMOPT_LINEAR) |
319 | if (options & RMOPT_LINEAR) |
316 | { /* linear door placement. */ |
320 | { /* linear door placement. */ |
317 | switch (which_wall) |
321 | switch (which_wall) |
318 | { |
322 | { |
319 | case 1: |
323 | case 1: |
320 | { /* left hand wall */ |
324 | { /* left hand wall */ |
321 | x1 = (int) xlocations[l]; |
325 | x1 = (int) xlocations[l]; |
322 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
326 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
323 | break; |
327 | break; |
324 | } |
328 | } |
325 | case 2: |
329 | case 2: |
326 | { /* top wall placement */ |
330 | { /* top wall placement */ |
327 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
331 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
328 | y1 = (int) ylocations[l]; |
332 | y1 = (int) ylocations[l]; |
329 | break; |
333 | break; |
330 | } |
334 | } |
331 | case 3: |
335 | case 3: |
332 | { /* right wall placement */ |
336 | { /* right wall placement */ |
333 | x1 = (int) xlocations[2 * layers - l - 1]; |
337 | x1 = (int) xlocations[2 * layers - l - 1]; |
334 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
338 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
335 | break; |
339 | break; |
336 | } |
340 | } |
337 | case 4: |
341 | case 4: |
338 | { /* bottom wall placement */ |
342 | { /* bottom wall placement */ |
339 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
343 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
340 | y1 = (int) ylocations[2 * layers - l - 1]; |
344 | y1 = (int) ylocations[2 * layers - l - 1]; |
341 | break; |
345 | break; |
342 | } |
346 | } |
343 | } |
347 | } |
344 | } |
348 | } |
345 | else |
349 | else |
346 | { /* random door placement. */ |
350 | { /* random door placement. */ |
347 | which_wall = RANDOM () % freedoms + 1; |
351 | which_wall = rndm (freedoms) + 1; |
348 | switch (which_wall) |
352 | switch (which_wall) |
349 | { |
353 | { |
350 | case 1: |
354 | case 1: |
351 | { /* left hand wall */ |
355 | { /* left hand wall */ |
352 | x1 = (int) xlocations[l]; |
356 | x1 = (int) xlocations[l]; |
353 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
357 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
354 | if (y2 > 0) |
358 | if (y2 > 0) |
355 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
359 | y1 = (int) (ylocations[l] + rndm (y2) + 1); |
356 | else |
360 | else |
357 | y1 = (int) (ylocations[l] + 1); |
361 | y1 = (int) (ylocations[l] + 1); |
358 | break; |
362 | break; |
359 | } |
363 | } |
360 | case 2: |
364 | case 2: |
361 | { /* top wall placement */ |
365 | { /* top wall placement */ |
362 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
366 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
363 | if (x2 > 0) |
367 | if (x2 > 0) |
364 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
368 | x1 = (int) (xlocations[l] + rndm (x2) + 1); |
365 | else |
369 | else |
366 | x1 = (int) (xlocations[l] + 1); |
370 | x1 = (int) (xlocations[l] + 1); |
367 | y1 = (int) ylocations[l]; |
371 | y1 = (int) ylocations[l]; |
368 | break; |
372 | break; |
369 | } |
373 | } |
370 | case 3: |
374 | case 3: |
371 | { /* right wall placement */ |
375 | { /* right wall placement */ |
372 | x1 = (int) xlocations[2 * layers - l - 1]; |
376 | x1 = (int) xlocations[2 * layers - l - 1]; |
373 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
377 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
374 | if (y2 > 0) |
378 | if (y2 > 0) |
375 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
379 | y1 = (int) (ylocations[l] + rndm (y2) + 1); |
376 | else |
380 | else |
377 | y1 = (int) (ylocations[l] + 1); |
381 | y1 = (int) (ylocations[l] + 1); |
378 | |
382 | |
379 | break; |
383 | break; |
380 | } |
384 | } |
381 | case 4: |
385 | case 4: |
382 | { /* bottom wall placement */ |
386 | { /* bottom wall placement */ |
383 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
387 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
384 | if (x2 > 0) |
388 | if (x2 > 0) |
385 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
389 | x1 = (int) (xlocations[l] + rndm (x2) + 1); |
386 | else |
390 | else |
387 | x1 = (int) (xlocations[l] + 1); |
391 | x1 = (int) (xlocations[l] + 1); |
388 | y1 = (int) ylocations[2 * layers - l - 1]; |
392 | y1 = (int) ylocations[2 * layers - l - 1]; |
389 | break; |
393 | break; |
390 | } |
394 | } |
391 | |
395 | |
392 | } |
396 | } |
393 | } |
397 | } |
|
|
398 | |
394 | if (options & RMOPT_NO_DOORS) |
399 | if (options & RMOPT_NO_DOORS) |
395 | maze[x1][y1] = '#'; /* no door. */ |
400 | maze[x1][y1] = '#'; /* no door. */ |
396 | else |
401 | else |
397 | maze[x1][y1] = 'D'; /* write the door */ |
402 | maze[x1][y1] = 'D'; /* write the door */ |
398 | |
403 | |
399 | } |
404 | } |
400 | /* mark the center of the maze with a C */ |
405 | /* mark the center of the maze with a C */ |
401 | l = layers - 1; |
406 | l = layers - 1; |
402 | x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2; |
407 | x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2; |
403 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
408 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
|
|
409 | |
404 | maze[x1][y1] = 'C'; |
410 | maze[x1][y1] = 'C'; |
405 | |
|
|
406 | /* not needed anymore */ |
|
|
407 | free (xlocations); |
|
|
408 | free (ylocations); |
|
|
409 | |
|
|
410 | } |
411 | } |
411 | |
412 | |
412 | void |
413 | void |
413 | 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) |
414 | { |
415 | { |
415 | int i, maxlayers; |
416 | int i, maxlayers; |
416 | float *xlocations; |
|
|
417 | float *ylocations; |
|
|
418 | |
417 | |
419 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
418 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
|
|
419 | |
420 | if (!maxlayers) |
420 | if (!maxlayers) |
421 | return; /* map too small to onionize */ |
421 | return; /* map too small to onionize */ |
|
|
422 | |
422 | if (layers > maxlayers) |
423 | if (layers > maxlayers) |
423 | layers = maxlayers; |
424 | layers = maxlayers; |
|
|
425 | |
424 | if (layers == 0) |
426 | if (layers == 0) |
425 | layers = (RANDOM () % maxlayers) + 1; |
427 | layers = rndm (maxlayers) + 1; |
426 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
427 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
428 | |
428 | |
|
|
429 | float *xlocations = salloc0<float> (2 * layers); |
|
|
430 | float *ylocations = salloc0<float> (2 * layers); |
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; |
… | |
… | |
441 | for (i = 0; i < 2 * layers; i++) |
443 | for (i = 0; i < 2 * layers; i++) |
442 | { |
444 | { |
443 | float xpitch = 2, ypitch = 2; |
445 | float xpitch = 2, ypitch = 2; |
444 | |
446 | |
445 | if (x_spaces_available > 0) |
447 | if (x_spaces_available > 0) |
446 | xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; |
448 | xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; |
447 | |
449 | |
448 | if (y_spaces_available > 0) |
450 | if (y_spaces_available > 0) |
449 | ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; |
451 | ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; |
|
|
452 | |
450 | if (i < layers) |
453 | if (i < layers) |
451 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
454 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
452 | else |
455 | else |
453 | xlocations[i] = xsize - 1; |
456 | xlocations[i] = xsize - 1; |
454 | |
457 | |
455 | if (i < layers) |
458 | if (i < layers) |
456 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
459 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
457 | else |
460 | else |
458 | ylocations[i] = ysize - 1; |
461 | ylocations[i] = ysize - 1; |
|
|
462 | |
459 | x_spaces_available -= (int) (xpitch - 2); |
463 | x_spaces_available -= (int) (xpitch - 2); |
460 | y_spaces_available -= (int) (ypitch - 2); |
464 | y_spaces_available -= (int) (ypitch - 2); |
461 | } |
465 | } |
462 | |
|
|
463 | } |
466 | } |
|
|
467 | |
464 | if (!(option & RMOPT_IRR_SPACE)) |
468 | if (!(option & RMOPT_IRR_SPACE)) |
465 | { /* evenly spaced */ |
469 | { /* evenly spaced */ |
466 | float xpitch, ypitch; /* pitch of the onion layers */ |
470 | float xpitch, ypitch; /* pitch of the onion layers */ |
467 | |
471 | |
468 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
472 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
469 | ypitch = (ysize - 2.0) / (layers + 1); |
473 | ypitch = (ysize - 2.0) / (layers + 1); |
|
|
474 | |
470 | xlocations[0] = xpitch; |
475 | xlocations[0] = xpitch; |
471 | ylocations[0] = ypitch; |
476 | ylocations[0] = ypitch; |
|
|
477 | |
472 | for (i = 1; i < 2 * layers; i++) |
478 | for (i = 1; i < 2 * layers; i++) |
473 | { |
479 | { |
474 | if (i < layers) |
480 | if (i < layers) |
475 | xlocations[i] = xlocations[i - 1] + xpitch; |
481 | xlocations[i] = xlocations[i - 1] + xpitch; |
476 | else |
482 | else |
477 | xlocations[i] = xsize - 1; |
483 | xlocations[i] = xsize - 1; |
|
|
484 | |
478 | if (i < layers) |
485 | if (i < layers) |
479 | ylocations[i] = ylocations[i - 1] + ypitch; |
486 | ylocations[i] = ylocations[i - 1] + ypitch; |
480 | else |
487 | else |
481 | ylocations[i] = ysize - 1; |
488 | ylocations[i] = ysize - 1; |
482 | } |
489 | } |
… | |
… | |
485 | /* draw all the onion boxes. */ |
492 | /* draw all the onion boxes. */ |
486 | |
493 | |
487 | draw_onion (maze, xlocations, ylocations, layers); |
494 | draw_onion (maze, xlocations, ylocations, layers); |
488 | make_doors (maze, xlocations, ylocations, layers, option); |
495 | make_doors (maze, xlocations, ylocations, layers, option); |
489 | |
496 | |
|
|
497 | sfree (xlocations, 2 * layers); |
|
|
498 | sfree (ylocations, 2 * layers); |
490 | } |
499 | } |
|
|
500 | |