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