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