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