1 | |
|
|
2 | /* |
1 | /* |
3 | * static char *room_gen_onion_c = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
4 | * "$Id: room_gen_onion.C,v 1.3 2006/09/10 16:06:37 root Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
|
|
9 | * the terms of the Affero GNU General Public License as published by the |
|
|
10 | * Free Software Foundation, either version 3 of the License, or (at your |
|
|
11 | * option) any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, |
|
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | * GNU General Public License for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the Affero GNU General Public License |
|
|
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
5 | */ |
23 | */ |
6 | |
|
|
7 | /* |
|
|
8 | CrossFire, A Multiplayer game for X-windows |
|
|
9 | |
|
|
10 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
|
|
11 | Copyright (C) 1992 Frank Tore Johansen |
|
|
12 | |
|
|
13 | This program is free software; you can redistribute it and/or modify |
|
|
14 | it under the terms of the GNU General Public License as published by |
|
|
15 | the Free Software Foundation; either version 2 of the License, or |
|
|
16 | (at your option) any later version. |
|
|
17 | |
|
|
18 | This program is distributed in the hope that it will be useful, |
|
|
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
21 | GNU General Public License for more details. |
|
|
22 | |
|
|
23 | You should have received a copy of the GNU General Public License |
|
|
24 | along with this program; if not, write to the Free Software |
|
|
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
26 | |
|
|
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
|
|
28 | */ |
|
|
29 | |
|
|
30 | |
24 | |
31 | /* The onion room generator: |
25 | /* The onion room generator: |
32 | Onion rooms are like this: |
26 | Onion rooms are like this: |
33 | |
27 | |
34 | char **map_gen_onion(int xsize, int ysize, int option, int layers); |
28 | char **map_gen_onion(int xsize, int ysize, int option, int layers); |
… | |
… | |
55 | |
49 | |
56 | */ |
50 | */ |
57 | |
51 | |
58 | |
52 | |
59 | #include <global.h> |
53 | #include <global.h> |
60 | #include <random_map.h> |
54 | #include <rmg.h> |
|
|
55 | #include <rproto.h> |
61 | |
56 | |
62 | #ifndef MIN |
|
|
63 | # define MIN(x,y) (((x)<(y))? (x):(y)) |
|
|
64 | #endif |
|
|
65 | 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); |
66 | 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); |
67 | 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); |
68 | |
60 | |
69 | |
|
|
70 | void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
61 | static void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
71 | 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); |
72 | |
63 | |
73 | char ** |
64 | void |
74 | map_gen_onion (int xsize, int ysize, int option, int layers) |
65 | map_gen_onion (layout &maze, int option, int layers) |
75 | { |
66 | { |
76 | int i, j; |
67 | int i, j; |
77 | |
68 | |
78 | /* allocate that array, set it up */ |
69 | int xsize = maze.w; |
79 | char **maze = (char **) calloc (sizeof (char *), xsize); |
70 | int ysize = maze.h; |
80 | |
71 | |
81 | for (i = 0; i < xsize; i++) |
72 | maze.clear (); |
82 | { |
|
|
83 | maze[i] = (char *) calloc (sizeof (char), ysize); |
|
|
84 | } |
|
|
85 | |
73 | |
86 | /* pick some random options if option = 0 */ |
74 | /* pick some random options if option = 0 */ |
87 | if (option == 0) |
75 | if (option == 0) |
88 | { |
76 | { |
89 | switch (RANDOM () % 3) |
77 | switch (rmg_rndm (3)) |
90 | { |
78 | { |
91 | case 0: |
79 | case 0: |
92 | option |= OPT_CENTERED; |
80 | option |= RMOPT_CENTERED; |
93 | break; |
81 | break; |
94 | case 1: |
82 | case 1: |
95 | option |= OPT_BOTTOM_C; |
83 | option |= RMOPT_BOTTOM_C; |
96 | break; |
84 | break; |
97 | case 2: |
85 | case 2: |
98 | option |= OPT_BOTTOM_R; |
86 | option |= RMOPT_BOTTOM_R; |
99 | break; |
87 | break; |
100 | } |
88 | } |
101 | if (RANDOM () % 2) |
89 | |
102 | option |= OPT_LINEAR; |
90 | if (rmg_rndm (2)) option |= RMOPT_LINEAR; |
103 | if (RANDOM () % 2) |
|
|
104 | option |= OPT_IRR_SPACE; |
91 | if (rmg_rndm (2)) option |= RMOPT_IRR_SPACE; |
105 | } |
92 | } |
106 | |
93 | |
107 | /* write the outer walls, if appropriate. */ |
94 | /* write the outer walls, if appropriate. */ |
108 | if (!(option & OPT_WALL_OFF)) |
95 | if (!(option & RMOPT_WALL_OFF)) |
109 | { |
96 | maze.border (); |
110 | for (i = 0; i < xsize; i++) |
|
|
111 | maze[i][0] = maze[i][ysize - 1] = '#'; |
|
|
112 | for (j = 0; j < ysize; j++) |
|
|
113 | maze[0][j] = maze[xsize - 1][j] = '#'; |
|
|
114 | }; |
|
|
115 | |
97 | |
116 | if (option & OPT_WALLS_ONLY) |
98 | if (option & RMOPT_WALLS_ONLY) |
117 | return maze; |
99 | return; |
118 | |
100 | |
119 | /* pick off the mutually exclusive options */ |
101 | /* pick off the mutually exclusive options */ |
120 | if (option & OPT_BOTTOM_R) |
102 | if (option & RMOPT_BOTTOM_R) |
121 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
103 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
122 | else if (option & OPT_BOTTOM_C) |
104 | else if (option & RMOPT_BOTTOM_C) |
123 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
105 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
124 | else if (option & OPT_CENTERED) |
106 | else if (option & RMOPT_CENTERED) |
125 | centered_onion (maze, xsize, ysize, option, layers); |
107 | centered_onion (maze, xsize, ysize, option, layers); |
126 | |
|
|
127 | return maze; |
|
|
128 | } |
108 | } |
129 | |
109 | |
130 | void |
110 | static void |
131 | 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) |
132 | { |
112 | { |
133 | int i, maxlayers; |
113 | int i, maxlayers; |
134 | float *xlocations; |
|
|
135 | float *ylocations; |
|
|
136 | |
114 | |
137 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
115 | maxlayers = (min (xsize, ysize) - 2) / 5; |
|
|
116 | |
138 | if (!maxlayers) |
117 | if (!maxlayers) |
139 | return; /* map too small to onionize */ |
118 | return; /* map too small to onionize */ |
|
|
119 | |
140 | if (layers > maxlayers) |
120 | if (layers > maxlayers) |
141 | layers = maxlayers; |
121 | layers = maxlayers; |
|
|
122 | |
142 | if (layers == 0) |
123 | if (layers == 0) |
143 | layers = (RANDOM () % maxlayers) + 1; |
124 | layers = rmg_rndm (maxlayers) + 1; |
144 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
145 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
146 | |
125 | |
|
|
126 | float *xlocations = salloc0<float> (2 * layers); |
|
|
127 | float *ylocations = salloc0<float> (2 * layers); |
147 | |
128 | |
148 | /* place all the walls */ |
129 | /* place all the walls */ |
149 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
130 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
150 | { |
131 | { |
151 | int x_spaces_available, y_spaces_available; |
132 | int x_spaces_available, y_spaces_available; |
152 | |
133 | |
153 | /* the "extra" spaces available for spacing between layers */ |
134 | /* the "extra" spaces available for spacing between layers */ |
154 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
135 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
155 | y_spaces_available = (ysize - 2) - 6 * layers + 1; |
136 | y_spaces_available = (ysize - 2) - 6 * layers + 1; |
156 | |
137 | |
157 | |
|
|
158 | /* pick an initial random pitch */ |
138 | /* pick an initial random pitch */ |
159 | for (i = 0; i < 2 * layers; i++) |
139 | for (i = 0; i < 2 * layers; i++) |
160 | { |
140 | { |
161 | float xpitch = 2, ypitch = 2; |
141 | float xpitch = 2, ypitch = 2; |
162 | |
142 | |
163 | if (x_spaces_available > 0) |
143 | if (x_spaces_available > 0) |
164 | xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; |
144 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
165 | |
145 | |
166 | if (y_spaces_available > 0) |
146 | if (y_spaces_available > 0) |
167 | ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; |
147 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
|
|
148 | |
168 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
149 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
169 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
150 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
170 | x_spaces_available -= (int) (xpitch - 2); |
151 | x_spaces_available -= (int) (xpitch - 2); |
171 | y_spaces_available -= (int) (ypitch - 2); |
152 | y_spaces_available -= (int) (ypitch - 2); |
172 | } |
153 | } |
173 | |
154 | |
174 | } |
155 | } |
|
|
156 | |
175 | if (!(option & OPT_IRR_SPACE)) |
157 | if (!(option & RMOPT_IRR_SPACE)) |
176 | { /* evenly spaced */ |
158 | { /* evenly spaced */ |
177 | float xpitch, ypitch; /* pitch of the onion layers */ |
159 | float xpitch, ypitch; /* pitch of the onion layers */ |
178 | |
160 | |
179 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
161 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
180 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
162 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
|
|
163 | |
181 | xlocations[0] = xpitch; |
164 | xlocations[0] = xpitch; |
182 | ylocations[0] = ypitch; |
165 | ylocations[0] = ypitch; |
|
|
166 | |
183 | for (i = 1; i < 2 * layers; i++) |
167 | for (i = 1; i < 2 * layers; i++) |
184 | { |
168 | { |
185 | xlocations[i] = xlocations[i - 1] + xpitch; |
169 | xlocations[i] = xlocations[i - 1] + xpitch; |
186 | ylocations[i] = ylocations[i - 1] + ypitch; |
170 | ylocations[i] = ylocations[i - 1] + ypitch; |
187 | } |
171 | } |
188 | } |
172 | } |
189 | |
173 | |
190 | /* draw all the onion boxes. */ |
174 | /* draw all the onion boxes. */ |
191 | |
|
|
192 | draw_onion (maze, xlocations, ylocations, layers); |
175 | draw_onion (maze, xlocations, ylocations, layers); |
193 | make_doors (maze, xlocations, ylocations, layers, option); |
176 | make_doors (maze, xlocations, ylocations, layers, option); |
194 | |
177 | |
|
|
178 | sfree (xlocations, 2 * layers); |
|
|
179 | sfree (ylocations, 2 * layers); |
195 | } |
180 | } |
196 | |
181 | |
197 | void |
182 | static void |
198 | 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) |
199 | { |
184 | { |
200 | int i, maxlayers; |
185 | int i, maxlayers; |
201 | float *xlocations; |
|
|
202 | float *ylocations; |
|
|
203 | |
186 | |
204 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
187 | maxlayers = (min (xsize, ysize) - 2) / 5; |
|
|
188 | |
205 | if (!maxlayers) |
189 | if (!maxlayers) |
206 | return; /* map too small to onionize */ |
190 | return; /* map too small to onionize */ |
|
|
191 | |
207 | if (layers > maxlayers) |
192 | if (layers > maxlayers) |
208 | layers = maxlayers; |
193 | layers = maxlayers; |
|
|
194 | |
209 | if (layers == 0) |
195 | if (layers == 0) |
210 | layers = (RANDOM () % maxlayers) + 1; |
196 | layers = rmg_rndm (maxlayers) + 1; |
211 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
212 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
213 | |
197 | |
|
|
198 | float *xlocations = salloc0<float> (2 * layers); |
|
|
199 | float *ylocations = salloc0<float> (2 * layers); |
214 | |
200 | |
215 | /* place all the walls */ |
201 | /* place all the walls */ |
216 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
202 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
217 | { |
203 | { |
218 | int x_spaces_available, y_spaces_available; |
204 | int x_spaces_available, y_spaces_available; |
219 | |
205 | |
220 | /* the "extra" spaces available for spacing between layers */ |
206 | /* the "extra" spaces available for spacing between layers */ |
221 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
207 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
222 | y_spaces_available = (ysize - 2) - 3 * layers + 1; |
208 | y_spaces_available = (ysize - 2) - 3 * layers + 1; |
223 | |
209 | |
224 | |
|
|
225 | /* pick an initial random pitch */ |
210 | /* pick an initial random pitch */ |
226 | for (i = 0; i < 2 * layers; i++) |
211 | for (i = 0; i < 2 * layers; i++) |
227 | { |
212 | { |
228 | float xpitch = 2, ypitch = 2; |
213 | float xpitch = 2, ypitch = 2; |
229 | |
214 | |
230 | if (x_spaces_available > 0) |
215 | if (x_spaces_available > 0) |
231 | xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; |
216 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
232 | |
217 | |
233 | if (y_spaces_available > 0) |
218 | if (y_spaces_available > 0) |
234 | ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; |
219 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
|
|
220 | |
235 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
221 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
|
|
222 | |
236 | if (i < layers) |
223 | if (i < layers) |
237 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
224 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
238 | else |
225 | else |
239 | ylocations[i] = ysize - 1; |
226 | ylocations[i] = ysize - 1; |
|
|
227 | |
240 | x_spaces_available -= (int) (xpitch - 2); |
228 | x_spaces_available -= (int) (xpitch - 2); |
241 | y_spaces_available -= (int) (ypitch - 2); |
229 | y_spaces_available -= (int) (ypitch - 2); |
242 | } |
230 | } |
243 | |
|
|
244 | } |
231 | } |
|
|
232 | |
245 | if (!(option & OPT_IRR_SPACE)) |
233 | if (!(option & RMOPT_IRR_SPACE)) |
246 | { /* evenly spaced */ |
234 | { /* evenly spaced */ |
247 | float xpitch, ypitch; /* pitch of the onion layers */ |
235 | float xpitch, ypitch; /* pitch of the onion layers */ |
248 | |
236 | |
249 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
237 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
250 | ypitch = (ysize - 2.0) / (layers + 1); |
238 | ypitch = (ysize - 2.0) / (layers + 1); |
|
|
239 | |
251 | xlocations[0] = xpitch; |
240 | xlocations[0] = xpitch; |
252 | ylocations[0] = ypitch; |
241 | ylocations[0] = ypitch; |
|
|
242 | |
253 | for (i = 1; i < 2 * layers; i++) |
243 | for (i = 1; i < 2 * layers; i++) |
254 | { |
244 | { |
255 | xlocations[i] = xlocations[i - 1] + xpitch; |
245 | xlocations[i] = xlocations[i - 1] + xpitch; |
|
|
246 | |
256 | if (i < layers) |
247 | if (i < layers) |
257 | ylocations[i] = ylocations[i - 1] + ypitch; |
248 | ylocations[i] = ylocations[i - 1] + ypitch; |
258 | else |
249 | else |
259 | ylocations[i] = ysize - 1; |
250 | ylocations[i] = ysize - 1; |
260 | } |
251 | } |
… | |
… | |
263 | /* draw all the onion boxes. */ |
254 | /* draw all the onion boxes. */ |
264 | |
255 | |
265 | draw_onion (maze, xlocations, ylocations, layers); |
256 | draw_onion (maze, xlocations, ylocations, layers); |
266 | make_doors (maze, xlocations, ylocations, layers, option); |
257 | make_doors (maze, xlocations, ylocations, layers, option); |
267 | |
258 | |
|
|
259 | sfree (xlocations, 2 * layers); |
|
|
260 | sfree (ylocations, 2 * layers); |
268 | } |
261 | } |
269 | |
262 | |
270 | |
|
|
271 | /* 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 */ |
272 | |
264 | static void |
273 | void |
|
|
274 | draw_onion (char **maze, float *xlocations, float *ylocations, int layers) |
265 | draw_onion (char **maze, float *xlocations, float *ylocations, int layers) |
275 | { |
266 | { |
276 | int i, j, l; |
267 | int i, j, l; |
277 | |
268 | |
278 | for (l = 0; l < layers; l++) |
269 | for (l = 0; l < layers; l++) |
… | |
… | |
298 | } |
289 | } |
299 | |
290 | |
300 | } |
291 | } |
301 | } |
292 | } |
302 | |
293 | |
303 | void |
294 | static void |
304 | 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) |
305 | { |
296 | { |
306 | 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 */ |
307 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
298 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
308 | int l, x1 = 0, x2, y1 = 0, y2; |
299 | int l, x1 = 0, x2, y1 = 0, y2; |
309 | |
300 | |
310 | freedoms = 4; /* centered */ |
301 | freedoms = 4; /* centered */ |
|
|
302 | |
311 | if (options & OPT_BOTTOM_C) |
303 | if (options & RMOPT_BOTTOM_C) |
312 | freedoms = 3; |
304 | freedoms = 3; |
|
|
305 | |
313 | if (options & OPT_BOTTOM_R) |
306 | if (options & RMOPT_BOTTOM_R) |
314 | freedoms = 2; |
307 | freedoms = 2; |
|
|
308 | |
315 | if (layers <= 0) |
309 | if (layers <= 0) |
316 | return; |
310 | return; |
|
|
311 | |
317 | /* pick which wall will have a door. */ |
312 | /* pick which wall will have a door. */ |
318 | which_wall = RANDOM () % freedoms + 1; |
313 | which_wall = rmg_rndm (freedoms) + 1; |
319 | for (l = 0; l < layers; l++) |
314 | for (l = 0; l < layers; l++) |
320 | { |
315 | { |
321 | if (options & OPT_LINEAR) |
316 | if (options & RMOPT_LINEAR) |
322 | { /* linear door placement. */ |
317 | { /* linear door placement. */ |
323 | switch (which_wall) |
318 | switch (which_wall) |
324 | { |
319 | { |
325 | case 1: |
320 | case 1: |
326 | { /* left hand wall */ |
321 | { /* left hand wall */ |
327 | x1 = (int) xlocations[l]; |
322 | x1 = (int) xlocations[l]; |
328 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
323 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
329 | break; |
324 | break; |
330 | } |
325 | } |
331 | case 2: |
326 | case 2: |
332 | { /* top wall placement */ |
327 | { /* top wall placement */ |
333 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
328 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
334 | y1 = (int) ylocations[l]; |
329 | y1 = (int) ylocations[l]; |
335 | break; |
330 | break; |
336 | } |
331 | } |
337 | case 3: |
332 | case 3: |
338 | { /* right wall placement */ |
333 | { /* right wall placement */ |
339 | x1 = (int) xlocations[2 * layers - l - 1]; |
334 | x1 = (int) xlocations[2 * layers - l - 1]; |
340 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
335 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
341 | break; |
336 | break; |
342 | } |
337 | } |
343 | case 4: |
338 | case 4: |
344 | { /* bottom wall placement */ |
339 | { /* bottom wall placement */ |
345 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
340 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
346 | y1 = (int) ylocations[2 * layers - l - 1]; |
341 | y1 = (int) ylocations[2 * layers - l - 1]; |
347 | break; |
342 | break; |
348 | } |
343 | } |
349 | } |
344 | } |
350 | } |
345 | } |
351 | else |
346 | else |
352 | { /* random door placement. */ |
347 | { /* random door placement. */ |
353 | which_wall = RANDOM () % freedoms + 1; |
348 | which_wall = rmg_rndm (freedoms) + 1; |
354 | switch (which_wall) |
349 | switch (which_wall) |
355 | { |
350 | { |
356 | case 1: |
351 | case 1: |
357 | { /* left hand wall */ |
352 | { /* left hand wall */ |
358 | x1 = (int) xlocations[l]; |
353 | x1 = (int) xlocations[l]; |
359 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
354 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
360 | if (y2 > 0) |
355 | if (y2 > 0) |
361 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
356 | y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1); |
362 | else |
357 | else |
363 | y1 = (int) (ylocations[l] + 1); |
358 | y1 = (int) (ylocations[l] + 1); |
364 | break; |
359 | break; |
365 | } |
360 | } |
366 | case 2: |
361 | case 2: |
367 | { /* top wall placement */ |
362 | { /* top wall placement */ |
368 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
363 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
369 | if (x2 > 0) |
364 | if (x2 > 0) |
370 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
365 | x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1); |
371 | else |
366 | else |
372 | x1 = (int) (xlocations[l] + 1); |
367 | x1 = (int) (xlocations[l] + 1); |
373 | y1 = (int) ylocations[l]; |
368 | y1 = (int) ylocations[l]; |
374 | break; |
369 | break; |
375 | } |
370 | } |
376 | case 3: |
371 | case 3: |
377 | { /* right wall placement */ |
372 | { /* right wall placement */ |
378 | x1 = (int) xlocations[2 * layers - l - 1]; |
373 | x1 = (int) xlocations[2 * layers - l - 1]; |
379 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
374 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
380 | if (y2 > 0) |
375 | if (y2 > 0) |
381 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
376 | y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1); |
382 | else |
377 | else |
383 | y1 = (int) (ylocations[l] + 1); |
378 | y1 = (int) (ylocations[l] + 1); |
384 | |
379 | |
385 | break; |
380 | break; |
386 | } |
381 | } |
387 | case 4: |
382 | case 4: |
388 | { /* bottom wall placement */ |
383 | { /* bottom wall placement */ |
389 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
384 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
390 | if (x2 > 0) |
385 | if (x2 > 0) |
391 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
386 | x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1); |
392 | else |
387 | else |
393 | x1 = (int) (xlocations[l] + 1); |
388 | x1 = (int) (xlocations[l] + 1); |
394 | y1 = (int) ylocations[2 * layers - l - 1]; |
389 | y1 = (int) ylocations[2 * layers - l - 1]; |
395 | break; |
390 | break; |
396 | } |
391 | } |
397 | |
392 | |
398 | } |
393 | } |
399 | } |
394 | } |
|
|
395 | |
400 | if (options & OPT_NO_DOORS) |
396 | if (options & RMOPT_NO_DOORS) |
401 | maze[x1][y1] = '#'; /* no door. */ |
397 | maze[x1][y1] = '#'; /* no door. */ |
402 | else |
398 | else |
403 | maze[x1][y1] = 'D'; /* write the door */ |
399 | maze[x1][y1] = 'D'; /* write the door */ |
404 | |
400 | |
405 | } |
401 | } |
406 | /* mark the center of the maze with a C */ |
402 | /* mark the center of the maze with a C */ |
407 | l = layers - 1; |
403 | l = layers - 1; |
408 | x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2; |
404 | x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2; |
409 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
405 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
|
|
406 | |
410 | maze[x1][y1] = 'C'; |
407 | maze[x1][y1] = 'C'; |
411 | |
|
|
412 | /* not needed anymore */ |
|
|
413 | free (xlocations); |
|
|
414 | free (ylocations); |
|
|
415 | |
|
|
416 | } |
408 | } |
417 | |
409 | |
418 | void |
410 | static void |
419 | 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) |
420 | { |
412 | { |
421 | int i, maxlayers; |
413 | int i, maxlayers; |
422 | float *xlocations; |
|
|
423 | float *ylocations; |
|
|
424 | |
414 | |
425 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
415 | maxlayers = (min (xsize, ysize) - 2) / 5; |
|
|
416 | |
426 | if (!maxlayers) |
417 | if (!maxlayers) |
427 | return; /* map too small to onionize */ |
418 | return; /* map too small to onionize */ |
|
|
419 | |
428 | if (layers > maxlayers) |
420 | if (layers > maxlayers) |
429 | layers = maxlayers; |
421 | layers = maxlayers; |
|
|
422 | |
430 | if (layers == 0) |
423 | if (layers == 0) |
431 | layers = (RANDOM () % maxlayers) + 1; |
424 | layers = rmg_rndm (maxlayers) + 1; |
432 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
433 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
|
|
434 | |
425 | |
|
|
426 | float *xlocations = salloc0<float> (2 * layers); |
|
|
427 | float *ylocations = salloc0<float> (2 * layers); |
435 | |
428 | |
436 | /* place all the walls */ |
429 | /* place all the walls */ |
437 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
430 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
438 | { |
431 | { |
439 | int x_spaces_available, y_spaces_available; |
432 | int x_spaces_available, y_spaces_available; |
440 | |
433 | |
441 | /* the "extra" spaces available for spacing between layers */ |
434 | /* the "extra" spaces available for spacing between layers */ |
442 | x_spaces_available = (xsize - 2) - 3 * layers + 1; |
435 | x_spaces_available = (xsize - 2) - 3 * layers + 1; |
… | |
… | |
447 | for (i = 0; i < 2 * layers; i++) |
440 | for (i = 0; i < 2 * layers; i++) |
448 | { |
441 | { |
449 | float xpitch = 2, ypitch = 2; |
442 | float xpitch = 2, ypitch = 2; |
450 | |
443 | |
451 | if (x_spaces_available > 0) |
444 | if (x_spaces_available > 0) |
452 | xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; |
445 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
453 | |
446 | |
454 | if (y_spaces_available > 0) |
447 | if (y_spaces_available > 0) |
455 | ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; |
448 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
|
|
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 & OPT_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 | |