1 | /* |
|
|
2 | * static char *room_gen_onion_c = |
|
|
3 | * "$Id: room_gen_onion.C,v 1.2 2006/08/29 08:01:36 root Exp $"; |
|
|
4 | */ |
|
|
5 | |
|
|
6 | /* |
1 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
8 | |
3 | |
9 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
10 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
21 | |
16 | |
22 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
23 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
25 | |
20 | |
26 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
27 | */ |
22 | */ |
28 | |
23 | |
29 | |
24 | |
30 | /* The onion room generator: |
25 | /* The onion room generator: |
31 | Onion rooms are like this: |
26 | Onion rooms are like this: |
… | |
… | |
57 | |
52 | |
58 | #include <global.h> |
53 | #include <global.h> |
59 | #include <random_map.h> |
54 | #include <random_map.h> |
60 | |
55 | |
61 | #ifndef MIN |
56 | #ifndef MIN |
62 | #define MIN(x,y) (((x)<(y))? (x):(y)) |
57 | # define MIN(x,y) (((x)<(y))? (x):(y)) |
63 | #endif |
58 | #endif |
64 | void centered_onion(char **maze, int xsize, int ysize, int option, int layers); |
59 | void centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
65 | void bottom_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); |
66 | void bottom_right_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); |
67 | |
62 | |
68 | |
63 | |
69 | void draw_onion(char **maze,float *xlocations,float *ylocations,int layers); |
64 | void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
70 | void make_doors(char **maze,float *xlocations,float *ylocations,int layers,int options); |
65 | void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); |
71 | |
66 | |
|
|
67 | char ** |
72 | char **map_gen_onion(int xsize, int ysize, int option, int layers) { |
68 | map_gen_onion (int xsize, int ysize, int option, int layers) |
|
|
69 | { |
73 | int i,j; |
70 | int i, j; |
74 | |
71 | |
75 | /* allocate that array, set it up */ |
72 | /* allocate that array, set it up */ |
76 | char **maze = (char **)calloc(sizeof(char*),xsize); |
73 | char **maze = (char **) calloc (sizeof (char *), xsize); |
|
|
74 | |
77 | for(i=0;i<xsize;i++) { |
75 | for (i = 0; i < xsize; i++) |
|
|
76 | { |
78 | maze[i] = (char *) calloc(sizeof(char),ysize); |
77 | maze[i] = (char *) calloc (sizeof (char), ysize); |
79 | } |
78 | } |
80 | |
79 | |
81 | /* pick some random options if option = 0 */ |
80 | /* pick some random options if option = 0 */ |
82 | if(option == 0) { |
81 | if (option == 0) |
|
|
82 | { |
83 | switch(RANDOM()%3) { |
83 | switch (RANDOM () % 3) |
|
|
84 | { |
84 | case 0: |
85 | case 0: |
85 | option |= OPT_CENTERED; |
86 | option |= OPT_CENTERED; |
86 | break; |
87 | break; |
87 | case 1: |
88 | case 1: |
88 | option |= OPT_BOTTOM_C; |
89 | option |= OPT_BOTTOM_C; |
89 | break; |
90 | break; |
90 | case 2: |
91 | case 2: |
91 | option |= OPT_BOTTOM_R; |
92 | option |= OPT_BOTTOM_R; |
92 | break; |
93 | break; |
93 | } |
94 | } |
|
|
95 | if (RANDOM () % 2) |
94 | if(RANDOM()%2) option |=OPT_LINEAR; |
96 | option |= OPT_LINEAR; |
|
|
97 | if (RANDOM () % 2) |
95 | if(RANDOM()%2) option |=OPT_IRR_SPACE; |
98 | option |= OPT_IRR_SPACE; |
96 | } |
99 | } |
97 | |
100 | |
98 | /* write the outer walls, if appropriate. */ |
101 | /* write the outer walls, if appropriate. */ |
99 | if(!(option & OPT_WALL_OFF )) { |
102 | if (!(option & OPT_WALL_OFF)) |
|
|
103 | { |
100 | for(i=0;i<xsize;i++) |
104 | for (i = 0; i < xsize; i++) |
101 | maze[i][0] = maze[i][ysize-1] = '#'; |
105 | maze[i][0] = maze[i][ysize - 1] = '#'; |
102 | for(j=0;j<ysize;j++) |
106 | for (j = 0; j < ysize; j++) |
103 | maze[0][j] = maze[xsize-1][j] = '#'; |
107 | maze[0][j] = maze[xsize - 1][j] = '#'; |
104 | }; |
108 | }; |
105 | |
109 | |
106 | if(option & OPT_WALLS_ONLY) return maze; |
110 | if (option & OPT_WALLS_ONLY) |
|
|
111 | return maze; |
107 | |
112 | |
108 | /* pick off the mutually exclusive options */ |
113 | /* pick off the mutually exclusive options */ |
109 | if(option & OPT_BOTTOM_R) |
114 | if (option & OPT_BOTTOM_R) |
110 | bottom_right_centered_onion(maze,xsize,ysize,option,layers); |
115 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
111 | else if(option & OPT_BOTTOM_C) |
116 | else if (option & OPT_BOTTOM_C) |
112 | bottom_centered_onion(maze,xsize,ysize,option,layers); |
117 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
113 | else if(option & OPT_CENTERED) |
118 | else if (option & OPT_CENTERED) |
114 | centered_onion(maze,xsize,ysize,option,layers); |
119 | centered_onion (maze, xsize, ysize, option, layers); |
115 | |
120 | |
116 | return maze; |
121 | return maze; |
117 | } |
122 | } |
118 | |
123 | |
|
|
124 | void |
119 | void centered_onion(char **maze, int xsize, int ysize, int option, int layers) { |
125 | centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
|
|
126 | { |
120 | int i,maxlayers; |
127 | int i, maxlayers; |
121 | float *xlocations; |
128 | float *xlocations; |
122 | float *ylocations; |
129 | float *ylocations; |
123 | |
130 | |
124 | maxlayers = (MIN(xsize,ysize)-2)/5; |
131 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
125 | if(!maxlayers) return; /* map too small to onionize */ |
132 | if (!maxlayers) |
126 | if(layers > maxlayers) layers = maxlayers; |
133 | return; /* map too small to onionize */ |
|
|
134 | if (layers > maxlayers) |
|
|
135 | layers = maxlayers; |
|
|
136 | if (layers == 0) |
127 | if(layers == 0) layers = (RANDOM() % maxlayers)+1; |
137 | layers = (RANDOM () % maxlayers) + 1; |
128 | xlocations = (float *) calloc(sizeof(float),2 * layers); |
138 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
129 | ylocations = (float *) calloc(sizeof(float),2 * layers); |
139 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
130 | |
140 | |
131 | |
141 | |
132 | /* place all the walls */ |
142 | /* place all the walls */ |
133 | if(option & OPT_IRR_SPACE) /* randomly spaced */ { |
143 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
|
|
144 | { |
134 | int x_spaces_available, y_spaces_available; |
145 | int x_spaces_available, y_spaces_available; |
|
|
146 | |
135 | /* the "extra" spaces available for spacing between layers */ |
147 | /* the "extra" spaces available for spacing between layers */ |
136 | x_spaces_available = (xsize -2) - 6*layers +1; |
148 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
137 | y_spaces_available = (ysize -2) - 6*layers +1; |
149 | y_spaces_available = (ysize - 2) - 6 * layers + 1; |
138 | |
150 | |
139 | |
151 | |
140 | /* pick an initial random pitch */ |
152 | /* pick an initial random pitch */ |
141 | for(i=0;i<2*layers;i++) { |
153 | for (i = 0; i < 2 * layers; i++) |
|
|
154 | { |
142 | float xpitch=2,ypitch=2; |
155 | float xpitch = 2, ypitch = 2; |
|
|
156 | |
143 | if(x_spaces_available>0) |
157 | if (x_spaces_available > 0) |
144 | xpitch = 2 + (RANDOM()%x_spaces_available + |
158 | xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; |
145 | RANDOM()%x_spaces_available + |
|
|
146 | RANDOM()%x_spaces_available)/3; |
|
|
147 | |
159 | |
148 | if(y_spaces_available>0) |
160 | if (y_spaces_available > 0) |
149 | ypitch = 2 + (RANDOM()%y_spaces_available + |
161 | ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; |
150 | RANDOM()%y_spaces_available + |
|
|
151 | RANDOM()%y_spaces_available)/3; |
|
|
152 | xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; |
162 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
153 | ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; |
163 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
154 | x_spaces_available-=(int) (xpitch -2); |
164 | x_spaces_available -= (int) (xpitch - 2); |
155 | y_spaces_available-=(int) (ypitch -2); |
165 | y_spaces_available -= (int) (ypitch - 2); |
156 | } |
166 | } |
157 | |
167 | |
158 | } |
168 | } |
159 | if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ |
169 | if (!(option & OPT_IRR_SPACE)) |
|
|
170 | { /* evenly spaced */ |
160 | float xpitch, ypitch; /* pitch of the onion layers */ |
171 | float xpitch, ypitch; /* pitch of the onion layers */ |
|
|
172 | |
161 | xpitch = (xsize-2.0)/(2.0*layers+1); |
173 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
162 | ypitch = (ysize-2.0)/(2.0*layers+1); |
174 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
163 | xlocations[0] = xpitch; |
175 | xlocations[0] = xpitch; |
164 | ylocations[0] = ypitch; |
176 | ylocations[0] = ypitch; |
165 | for(i=1;i<2*layers;i++) { |
177 | for (i = 1; i < 2 * layers; i++) |
|
|
178 | { |
166 | xlocations[i] = xlocations[i-1] + xpitch; |
179 | xlocations[i] = xlocations[i - 1] + xpitch; |
167 | ylocations[i] = ylocations[i-1] + ypitch; |
180 | ylocations[i] = ylocations[i - 1] + ypitch; |
168 | } |
181 | } |
169 | } |
|
|
170 | |
182 | } |
|
|
183 | |
171 | /* draw all the onion boxes. */ |
184 | /* draw all the onion boxes. */ |
172 | |
185 | |
173 | draw_onion(maze,xlocations,ylocations,layers); |
186 | draw_onion (maze, xlocations, ylocations, layers); |
174 | make_doors(maze,xlocations,ylocations,layers,option); |
187 | make_doors (maze, xlocations, ylocations, layers, option); |
175 | |
|
|
176 | } |
|
|
177 | |
188 | |
|
|
189 | } |
|
|
190 | |
|
|
191 | void |
178 | void bottom_centered_onion(char **maze, int xsize, int ysize, int option, int layers) { |
192 | bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
|
|
193 | { |
179 | int i,maxlayers; |
194 | int i, maxlayers; |
180 | float *xlocations; |
195 | float *xlocations; |
181 | float *ylocations; |
196 | float *ylocations; |
182 | |
197 | |
183 | maxlayers = (MIN(xsize,ysize)-2)/5; |
198 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
184 | if(!maxlayers) return; /* map too small to onionize */ |
199 | if (!maxlayers) |
185 | if(layers > maxlayers) layers = maxlayers; |
200 | return; /* map too small to onionize */ |
|
|
201 | if (layers > maxlayers) |
|
|
202 | layers = maxlayers; |
|
|
203 | if (layers == 0) |
186 | if(layers == 0) layers = (RANDOM() % maxlayers)+1; |
204 | layers = (RANDOM () % maxlayers) + 1; |
187 | xlocations = (float *) calloc(sizeof(float),2 * layers); |
205 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
188 | ylocations = (float *) calloc(sizeof(float),2 * layers); |
206 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
189 | |
207 | |
190 | |
208 | |
191 | /* place all the walls */ |
209 | /* place all the walls */ |
192 | if(option & OPT_IRR_SPACE) /* randomly spaced */ { |
210 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
|
|
211 | { |
193 | int x_spaces_available, y_spaces_available; |
212 | int x_spaces_available, y_spaces_available; |
|
|
213 | |
194 | /* the "extra" spaces available for spacing between layers */ |
214 | /* the "extra" spaces available for spacing between layers */ |
195 | x_spaces_available = (xsize -2) - 6*layers +1; |
215 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
196 | y_spaces_available = (ysize -2) - 3*layers +1; |
216 | y_spaces_available = (ysize - 2) - 3 * layers + 1; |
197 | |
217 | |
198 | |
218 | |
199 | /* pick an initial random pitch */ |
219 | /* pick an initial random pitch */ |
200 | for(i=0;i<2*layers;i++) { |
220 | for (i = 0; i < 2 * layers; i++) |
|
|
221 | { |
201 | float xpitch=2,ypitch=2; |
222 | float xpitch = 2, ypitch = 2; |
|
|
223 | |
202 | if(x_spaces_available>0) |
224 | if (x_spaces_available > 0) |
203 | xpitch = 2 + (RANDOM()%x_spaces_available + |
225 | xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; |
204 | RANDOM()%x_spaces_available + |
|
|
205 | RANDOM()%x_spaces_available)/3; |
|
|
206 | |
226 | |
207 | if(y_spaces_available>0) |
227 | if (y_spaces_available > 0) |
208 | ypitch = 2 + (RANDOM()%y_spaces_available + |
228 | ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; |
209 | RANDOM()%y_spaces_available + |
|
|
210 | RANDOM()%y_spaces_available)/3; |
|
|
211 | xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; |
229 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
|
|
230 | if (i < layers) |
212 | if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; |
231 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
|
|
232 | else |
213 | else ylocations[i] = ysize-1; |
233 | ylocations[i] = ysize - 1; |
214 | x_spaces_available-=(int)(xpitch -2); |
234 | x_spaces_available -= (int) (xpitch - 2); |
215 | y_spaces_available-=(int)(ypitch -2); |
235 | y_spaces_available -= (int) (ypitch - 2); |
216 | } |
236 | } |
217 | |
237 | |
218 | } |
238 | } |
219 | if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ |
239 | if (!(option & OPT_IRR_SPACE)) |
|
|
240 | { /* evenly spaced */ |
220 | float xpitch, ypitch; /* pitch of the onion layers */ |
241 | float xpitch, ypitch; /* pitch of the onion layers */ |
|
|
242 | |
221 | xpitch = (xsize-2.0)/(2.0*layers+1); |
243 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
222 | ypitch = (ysize-2.0)/(layers+1); |
244 | ypitch = (ysize - 2.0) / (layers + 1); |
223 | xlocations[0] = xpitch; |
245 | xlocations[0] = xpitch; |
224 | ylocations[0] = ypitch; |
246 | ylocations[0] = ypitch; |
225 | for(i=1;i<2*layers;i++) { |
247 | for (i = 1; i < 2 * layers; i++) |
|
|
248 | { |
226 | xlocations[i] = xlocations[i-1] + xpitch; |
249 | xlocations[i] = xlocations[i - 1] + xpitch; |
|
|
250 | if (i < layers) |
227 | if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; |
251 | ylocations[i] = ylocations[i - 1] + ypitch; |
|
|
252 | else |
228 | else ylocations[i]=ysize-1; |
253 | ylocations[i] = ysize - 1; |
229 | } |
254 | } |
230 | } |
|
|
231 | |
255 | } |
|
|
256 | |
232 | /* draw all the onion boxes. */ |
257 | /* draw all the onion boxes. */ |
233 | |
258 | |
234 | draw_onion(maze,xlocations,ylocations,layers); |
259 | draw_onion (maze, xlocations, ylocations, layers); |
235 | make_doors(maze,xlocations,ylocations,layers,option); |
260 | make_doors (maze, xlocations, ylocations, layers, option); |
236 | |
261 | |
237 | } |
262 | } |
238 | |
263 | |
239 | |
264 | |
240 | /* draw_boxes: draws the lines in the maze defining the onion layers */ |
265 | /* draw_boxes: draws the lines in the maze defining the onion layers */ |
241 | |
266 | |
|
|
267 | void |
242 | void draw_onion(char **maze,float *xlocations,float *ylocations, int layers) { |
268 | draw_onion (char **maze, float *xlocations, float *ylocations, int layers) |
|
|
269 | { |
243 | int i,j,l; |
270 | int i, j, l; |
244 | |
271 | |
245 | for(l=0;l<layers;l++) { |
272 | for (l = 0; l < layers; l++) |
|
|
273 | { |
246 | int x1,x2,y1,y2; |
274 | int x1, x2, y1, y2; |
|
|
275 | |
247 | /* horizontal segments */ |
276 | /* horizontal segments */ |
248 | y1 = (int)ylocations[l]; |
277 | y1 = (int) ylocations[l]; |
249 | y2 = (int)ylocations[2*layers -l-1]; |
278 | y2 = (int) ylocations[2 * layers - l - 1]; |
250 | for(i=(int)xlocations[l];i<=(int)xlocations[2*layers -l -1];i++) { |
279 | for (i = (int) xlocations[l]; i <= (int) xlocations[2 * layers - l - 1]; i++) |
|
|
280 | { |
251 | maze[i][y1] = '#'; |
281 | maze[i][y1] = '#'; |
252 | maze[i][y2] = '#'; |
282 | maze[i][y2] = '#'; |
253 | } |
283 | } |
254 | |
284 | |
255 | /* vertical segments */ |
285 | /* vertical segments */ |
256 | x1 = (int)xlocations[l]; |
286 | x1 = (int) xlocations[l]; |
257 | x2 = (int)xlocations[2*layers-l-1]; |
287 | x2 = (int) xlocations[2 * layers - l - 1]; |
258 | for(j=(int)ylocations[l];j<=(int)ylocations[2*layers -l -1];j++) { |
288 | for (j = (int) ylocations[l]; j <= (int) ylocations[2 * layers - l - 1]; j++) |
|
|
289 | { |
259 | maze[x1][j] = '#'; |
290 | maze[x1][j] = '#'; |
260 | maze[x2][j] = '#'; |
291 | maze[x2][j] = '#'; |
261 | } |
292 | } |
262 | |
293 | |
263 | } |
294 | } |
264 | } |
295 | } |
265 | |
296 | |
|
|
297 | void |
266 | void make_doors(char **maze, float *xlocations,float *ylocations,int layers,int options) { |
298 | make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options) |
|
|
299 | { |
267 | 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 */ |
268 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
301 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
269 | int l,x1=0,x2,y1=0,y2; |
302 | int l, x1 = 0, x2, y1 = 0, y2; |
|
|
303 | |
270 | freedoms = 4; /* centered */ |
304 | freedoms = 4; /* centered */ |
271 | if(options & OPT_BOTTOM_C) freedoms=3; |
305 | if (options & OPT_BOTTOM_C) |
|
|
306 | freedoms = 3; |
272 | if(options & OPT_BOTTOM_R) freedoms=2; |
307 | if (options & OPT_BOTTOM_R) |
|
|
308 | freedoms = 2; |
273 | if(layers<= 0) return; |
309 | if (layers <= 0) |
|
|
310 | return; |
274 | /* pick which wall will have a door. */ |
311 | /* pick which wall will have a door. */ |
275 | which_wall = RANDOM() %freedoms + 1; |
312 | which_wall = RANDOM () % freedoms + 1; |
276 | for(l=0;l<layers;l++) { |
313 | for (l = 0; l < layers; l++) |
277 | if(options & OPT_LINEAR) { /* linear door placement. */ |
314 | { |
|
|
315 | if (options & OPT_LINEAR) |
|
|
316 | { /* linear door placement. */ |
278 | switch(which_wall) { |
317 | switch (which_wall) |
|
|
318 | { |
|
|
319 | case 1: |
279 | case 1: { /* left hand wall */ |
320 | { /* left hand wall */ |
280 | x1 = (int)xlocations[l]; |
321 | x1 = (int) xlocations[l]; |
281 | y1 = (int)( (ylocations[l] + ylocations[2*layers-l-1])/2); |
322 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
282 | break; |
323 | break; |
283 | } |
|
|
284 | case 2: { /* top wall placement */ |
|
|
285 | x1 = (int)( (xlocations[l] + xlocations[2*layers-l-1])/2); |
|
|
286 | y1 = (int)ylocations[l]; |
|
|
287 | break; |
|
|
288 | } |
|
|
289 | case 3: { /* right wall placement */ |
|
|
290 | x1 = (int)xlocations[2*layers-l-1]; |
|
|
291 | y1 = (int)( (ylocations[l] + ylocations[2*layers-l-1])/2); |
|
|
292 | break; |
|
|
293 | } |
|
|
294 | case 4: { /* bottom wall placement */ |
|
|
295 | x1 = (int)( (xlocations[l] + xlocations[2*layers-l-1])/2); |
|
|
296 | y1 = (int)ylocations[2*layers -l -1]; |
|
|
297 | break; |
|
|
298 | } |
|
|
299 | } |
|
|
300 | } |
|
|
301 | else { /* random door placement. */ |
|
|
302 | which_wall=RANDOM()%freedoms + 1; |
|
|
303 | switch(which_wall) { |
|
|
304 | case 1: { /* left hand wall */ |
|
|
305 | x1 = (int)xlocations[l]; |
|
|
306 | y2 = (int) (ylocations[2*layers-l-1]-ylocations[l]-1); |
|
|
307 | if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); |
|
|
308 | else y1 = (int) (ylocations[l]+1); |
|
|
309 | break; |
|
|
310 | } |
|
|
311 | case 2: { /* top wall placement */ |
|
|
312 | x2 = (int)( (-xlocations[l] + xlocations[2*layers-l-1]))-1; |
|
|
313 | if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); |
|
|
314 | else x1 = (int) (xlocations[l]+1); |
|
|
315 | y1 = (int)ylocations[l]; |
|
|
316 | break; |
|
|
317 | } |
|
|
318 | case 3: { /* right wall placement */ |
|
|
319 | x1 = (int)xlocations[2*layers-l-1]; |
|
|
320 | y2 = (int)( (-ylocations[l] + ylocations[2*layers-l-1]))-1; |
|
|
321 | if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); |
|
|
322 | else y1 = (int) (ylocations[l]+1); |
|
|
323 | |
|
|
324 | break; |
|
|
325 | } |
|
|
326 | case 4: { /* bottom wall placement */ |
|
|
327 | x2 = (int)( (-xlocations[l] + xlocations[2*layers-l-1]))-1; |
|
|
328 | if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); |
|
|
329 | else x1 = (int) (xlocations[l]+1); |
|
|
330 | y1 = (int)ylocations[2*layers-l-1]; |
|
|
331 | break; |
|
|
332 | } |
|
|
333 | |
324 | } |
|
|
325 | case 2: |
|
|
326 | { /* top wall placement */ |
|
|
327 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
|
|
328 | y1 = (int) ylocations[l]; |
|
|
329 | break; |
334 | } |
330 | } |
|
|
331 | case 3: |
|
|
332 | { /* right wall placement */ |
|
|
333 | x1 = (int) xlocations[2 * layers - l - 1]; |
|
|
334 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
|
|
335 | break; |
|
|
336 | } |
|
|
337 | case 4: |
|
|
338 | { /* bottom wall placement */ |
|
|
339 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
|
|
340 | y1 = (int) ylocations[2 * layers - l - 1]; |
|
|
341 | break; |
|
|
342 | } |
|
|
343 | } |
335 | } |
344 | } |
|
|
345 | else |
|
|
346 | { /* random door placement. */ |
|
|
347 | which_wall = RANDOM () % freedoms + 1; |
|
|
348 | switch (which_wall) |
|
|
349 | { |
|
|
350 | case 1: |
|
|
351 | { /* left hand wall */ |
|
|
352 | x1 = (int) xlocations[l]; |
|
|
353 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
|
|
354 | if (y2 > 0) |
|
|
355 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
|
|
356 | else |
|
|
357 | y1 = (int) (ylocations[l] + 1); |
|
|
358 | break; |
|
|
359 | } |
|
|
360 | case 2: |
|
|
361 | { /* top wall placement */ |
|
|
362 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
|
|
363 | if (x2 > 0) |
|
|
364 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
|
|
365 | else |
|
|
366 | x1 = (int) (xlocations[l] + 1); |
|
|
367 | y1 = (int) ylocations[l]; |
|
|
368 | break; |
|
|
369 | } |
|
|
370 | case 3: |
|
|
371 | { /* right wall placement */ |
|
|
372 | x1 = (int) xlocations[2 * layers - l - 1]; |
|
|
373 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
|
|
374 | if (y2 > 0) |
|
|
375 | y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); |
|
|
376 | else |
|
|
377 | y1 = (int) (ylocations[l] + 1); |
|
|
378 | |
|
|
379 | break; |
|
|
380 | } |
|
|
381 | case 4: |
|
|
382 | { /* bottom wall placement */ |
|
|
383 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
|
|
384 | if (x2 > 0) |
|
|
385 | x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); |
|
|
386 | else |
|
|
387 | x1 = (int) (xlocations[l] + 1); |
|
|
388 | y1 = (int) ylocations[2 * layers - l - 1]; |
|
|
389 | break; |
|
|
390 | } |
|
|
391 | |
|
|
392 | } |
|
|
393 | } |
336 | if(options & OPT_NO_DOORS) |
394 | if (options & OPT_NO_DOORS) |
337 | maze[x1][y1] = '#'; /* no door. */ |
395 | maze[x1][y1] = '#'; /* no door. */ |
338 | else |
396 | else |
339 | maze[x1][y1] = 'D'; /* write the door */ |
397 | maze[x1][y1] = 'D'; /* write the door */ |
340 | |
398 | |
341 | } |
399 | } |
342 | /* mark the center of the maze with a C */ |
400 | /* mark the center of the maze with a C */ |
343 | l = layers -1; |
401 | l = layers - 1; |
344 | x1 = (int) (xlocations[l] + xlocations[2*layers -l -1])/2; |
402 | x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2; |
345 | y1 = (int) (ylocations[l] + ylocations[2*layers -l -1])/2; |
403 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
346 | maze[x1][y1] = 'C'; |
404 | maze[x1][y1] = 'C'; |
347 | |
405 | |
348 | /* not needed anymore */ |
406 | /* not needed anymore */ |
349 | free(xlocations); |
407 | free (xlocations); |
350 | free(ylocations); |
408 | free (ylocations); |
351 | |
|
|
352 | } |
|
|
353 | |
409 | |
|
|
410 | } |
|
|
411 | |
|
|
412 | void |
354 | void bottom_right_centered_onion(char **maze, int xsize, int ysize, int option, int layers){ |
413 | bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
|
|
414 | { |
355 | int i,maxlayers; |
415 | int i, maxlayers; |
356 | float *xlocations; |
416 | float *xlocations; |
357 | float *ylocations; |
417 | float *ylocations; |
358 | |
418 | |
359 | maxlayers = (MIN(xsize,ysize)-2)/5; |
419 | maxlayers = (MIN (xsize, ysize) - 2) / 5; |
360 | if(!maxlayers) return; /* map too small to onionize */ |
420 | if (!maxlayers) |
361 | if(layers > maxlayers) layers = maxlayers; |
421 | return; /* map too small to onionize */ |
|
|
422 | if (layers > maxlayers) |
|
|
423 | layers = maxlayers; |
|
|
424 | if (layers == 0) |
362 | if(layers == 0) layers = (RANDOM() % maxlayers)+1; |
425 | layers = (RANDOM () % maxlayers) + 1; |
363 | xlocations = (float *) calloc(sizeof(float),2 * layers); |
426 | xlocations = (float *) calloc (sizeof (float), 2 * layers); |
364 | ylocations = (float *) calloc(sizeof(float),2 * layers); |
427 | ylocations = (float *) calloc (sizeof (float), 2 * layers); |
365 | |
428 | |
366 | |
429 | |
367 | /* place all the walls */ |
430 | /* place all the walls */ |
368 | if(option & OPT_IRR_SPACE) /* randomly spaced */ { |
431 | if (option & OPT_IRR_SPACE) /* randomly spaced */ |
|
|
432 | { |
369 | int x_spaces_available, y_spaces_available; |
433 | int x_spaces_available, y_spaces_available; |
|
|
434 | |
370 | /* the "extra" spaces available for spacing between layers */ |
435 | /* the "extra" spaces available for spacing between layers */ |
371 | x_spaces_available = (xsize -2) - 3*layers +1; |
436 | x_spaces_available = (xsize - 2) - 3 * layers + 1; |
372 | y_spaces_available = (ysize -2) - 3*layers +1; |
437 | y_spaces_available = (ysize - 2) - 3 * layers + 1; |
373 | |
438 | |
374 | |
439 | |
375 | /* pick an initial random pitch */ |
440 | /* pick an initial random pitch */ |
376 | for(i=0;i<2*layers;i++) { |
441 | for (i = 0; i < 2 * layers; i++) |
|
|
442 | { |
377 | float xpitch=2,ypitch=2; |
443 | float xpitch = 2, ypitch = 2; |
|
|
444 | |
378 | if(x_spaces_available>0) |
445 | if (x_spaces_available > 0) |
379 | xpitch = 2 + (RANDOM()%x_spaces_available + |
446 | xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; |
380 | RANDOM()%x_spaces_available + |
|
|
381 | RANDOM()%x_spaces_available)/3; |
|
|
382 | |
447 | |
383 | if(y_spaces_available>0) |
448 | if (y_spaces_available > 0) |
384 | ypitch = 2 + (RANDOM()%y_spaces_available + |
449 | ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; |
385 | RANDOM()%y_spaces_available + |
450 | if (i < layers) |
386 | RANDOM()%y_spaces_available)/3; |
|
|
387 | if(i < layers) xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; |
451 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
|
|
452 | else |
388 | else xlocations[i] = xsize-1; |
453 | xlocations[i] = xsize - 1; |
389 | |
454 | |
|
|
455 | if (i < layers) |
390 | if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; |
456 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
|
|
457 | else |
391 | else ylocations[i] = ysize-1; |
458 | ylocations[i] = ysize - 1; |
392 | x_spaces_available-=(int)(xpitch -2); |
459 | x_spaces_available -= (int) (xpitch - 2); |
393 | y_spaces_available-=(int)(ypitch -2); |
460 | y_spaces_available -= (int) (ypitch - 2); |
394 | } |
461 | } |
395 | |
462 | |
396 | } |
463 | } |
397 | if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ |
464 | if (!(option & OPT_IRR_SPACE)) |
|
|
465 | { /* evenly spaced */ |
398 | float xpitch, ypitch; /* pitch of the onion layers */ |
466 | float xpitch, ypitch; /* pitch of the onion layers */ |
|
|
467 | |
399 | xpitch = (xsize-2.0)/(2.0*layers+1); |
468 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
400 | ypitch = (ysize-2.0)/(layers+1); |
469 | ypitch = (ysize - 2.0) / (layers + 1); |
401 | xlocations[0] = xpitch; |
470 | xlocations[0] = xpitch; |
402 | ylocations[0] = ypitch; |
471 | ylocations[0] = ypitch; |
403 | for(i=1;i<2*layers;i++) { |
472 | for (i = 1; i < 2 * layers; i++) |
|
|
473 | { |
|
|
474 | if (i < layers) |
404 | if(i < layers) xlocations[i] = xlocations[i-1] + xpitch; |
475 | xlocations[i] = xlocations[i - 1] + xpitch; |
|
|
476 | else |
405 | else xlocations[i]=xsize-1; |
477 | xlocations[i] = xsize - 1; |
|
|
478 | if (i < layers) |
406 | if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; |
479 | ylocations[i] = ylocations[i - 1] + ypitch; |
|
|
480 | else |
407 | else ylocations[i]=ysize-1; |
481 | ylocations[i] = ysize - 1; |
408 | } |
482 | } |
409 | } |
|
|
410 | |
483 | } |
|
|
484 | |
411 | /* draw all the onion boxes. */ |
485 | /* draw all the onion boxes. */ |
412 | |
486 | |
413 | draw_onion(maze,xlocations,ylocations,layers); |
487 | draw_onion (maze, xlocations, ylocations, layers); |
414 | make_doors(maze,xlocations,ylocations,layers,option); |
488 | make_doors (maze, xlocations, ylocations, layers, option); |
415 | |
489 | |
416 | } |
490 | } |