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