ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/server/random_maps/room_gen_onion.C
(Generate patch)

Comparing cf.schmorp.de/server/random_maps/room_gen_onion.C (file contents):
Revision 1.1 by elmex, Sun Aug 13 17:16:03 2006 UTC vs.
Revision 1.10 by root, Sat Jan 27 02:19:37 2007 UTC

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.1 2006/08/13 17:16:03 elmex 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:
31Onion rooms are like this: 27Onion 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
64void centered_onion(char **maze, int xsize, int ysize, int option, int layers); 60void centered_onion (char **maze, int xsize, int ysize, int option, int layers);
65void bottom_centered_onion(char **maze, int xsize, int ysize, int option, int layers); 61void bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers);
66void bottom_right_centered_onion(char **maze, int xsize, int ysize, int option, int layers); 62void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers);
67 63
68 64
69void draw_onion(char **maze,float *xlocations,float *ylocations,int layers); 65void draw_onion (char **maze, float *xlocations, float *ylocations, int layers);
70void make_doors(char **maze,float *xlocations,float *ylocations,int layers,int options); 66void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options);
71 67
68char **
72char **map_gen_onion(int xsize, int ysize, int option, int layers) { 69map_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 switch(RANDOM()%3) { 83 {
84 case 0: 84 switch (rndm (3))
85 option |= OPT_CENTERED; 85 {
86 break; 86 case 0:
87 case 1: 87 option |= RMOPT_CENTERED;
88 option |= OPT_BOTTOM_C; 88 break;
89 break; 89 case 1:
90 case 2: 90 option |= RMOPT_BOTTOM_C;
91 option |= OPT_BOTTOM_R; 91 break;
92 break; 92 case 2:
93 } 93 option |= RMOPT_BOTTOM_R;
94 if(RANDOM()%2) option |=OPT_LINEAR; 94 break;
95 if(RANDOM()%2) option |=OPT_IRR_SPACE; 95 }
96 if (rndm (2))
97 option |= RMOPT_LINEAR;
98 if (rndm (2))
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
125void
119void centered_onion(char **maze, int xsize, int ysize, int option, int layers) { 126centered_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 */
127 if(layers == 0) layers = (RANDOM() % maxlayers)+1; 135
136 if (layers > maxlayers)
137 layers = maxlayers;
138
139 if (layers == 0)
140 layers = rndm (maxlayers) + 1;
141
128 xlocations = (float *) calloc(sizeof(float),2 * layers); 142 xlocations = (float *) calloc (sizeof (float), 2 * layers);
129 ylocations = (float *) calloc(sizeof(float),2 * layers); 143 ylocations = (float *) calloc (sizeof (float), 2 * layers);
130 144
131
132 /* place all the walls */ 145 /* place all the walls */
133 if(option & OPT_IRR_SPACE) /* randomly spaced */ { 146 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
147 {
134 int x_spaces_available, y_spaces_available; 148 int x_spaces_available, y_spaces_available;
149
135 /* the "extra" spaces available for spacing between layers */ 150 /* the "extra" spaces available for spacing between layers */
136 x_spaces_available = (xsize -2) - 6*layers +1; 151 x_spaces_available = (xsize - 2) - 6 * layers + 1;
137 y_spaces_available = (ysize -2) - 6*layers +1; 152 y_spaces_available = (ysize - 2) - 6 * layers + 1;
138 153
139 154
140 /* pick an initial random pitch */ 155 /* pick an initial random pitch */
141 for(i=0;i<2*layers;i++) { 156 for (i = 0; i < 2 * layers; i++)
142 float xpitch=2,ypitch=2; 157 {
158 float xpitch = 2, ypitch = 2;
159
143 if(x_spaces_available>0) 160 if (x_spaces_available > 0)
144 xpitch = 2 + (RANDOM()%x_spaces_available + 161 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3;
145 RANDOM()%x_spaces_available +
146 RANDOM()%x_spaces_available)/3;
147 162
148 if(y_spaces_available>0) 163 if (y_spaces_available > 0)
149 ypitch = 2 + (RANDOM()%y_spaces_available + 164 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3;
150 RANDOM()%y_spaces_available + 165
151 RANDOM()%y_spaces_available)/3;
152 xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; 166 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
153 ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; 167 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
154 x_spaces_available-=(int) (xpitch -2); 168 x_spaces_available -= (int) (xpitch - 2);
155 y_spaces_available-=(int) (ypitch -2); 169 y_spaces_available -= (int) (ypitch - 2);
156 } 170 }
157 171
158 } 172 }
159 if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ 173 if (!(option & RMOPT_IRR_SPACE))
174 { /* evenly spaced */
160 float xpitch, ypitch; /* pitch of the onion layers */ 175 float xpitch, ypitch; /* pitch of the onion layers */
176
161 xpitch = (xsize-2.0)/(2.0*layers+1); 177 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
162 ypitch = (ysize-2.0)/(2.0*layers+1); 178 ypitch = (ysize - 2.0) / (2.0 * layers + 1);
163 xlocations[0] = xpitch; 179 xlocations[0] = xpitch;
164 ylocations[0] = ypitch; 180 ylocations[0] = ypitch;
165 for(i=1;i<2*layers;i++) { 181 for (i = 1; i < 2 * layers; i++)
182 {
166 xlocations[i] = xlocations[i-1] + xpitch; 183 xlocations[i] = xlocations[i - 1] + xpitch;
167 ylocations[i] = ylocations[i-1] + ypitch; 184 ylocations[i] = ylocations[i - 1] + ypitch;
168 } 185 }
169 }
170 186 }
187
171 /* draw all the onion boxes. */ 188 /* draw all the onion boxes. */
172 189
173 draw_onion(maze,xlocations,ylocations,layers); 190 draw_onion (maze, xlocations, ylocations, layers);
174 make_doors(maze,xlocations,ylocations,layers,option); 191 make_doors (maze, xlocations, ylocations, layers, option);
175
176}
177 192
193}
194
195void
178void bottom_centered_onion(char **maze, int xsize, int ysize, int option, int layers) { 196bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers)
197{
179 int i,maxlayers; 198 int i, maxlayers;
180 float *xlocations; 199 float *xlocations;
181 float *ylocations; 200 float *ylocations;
182 201
183 maxlayers = (MIN(xsize,ysize)-2)/5; 202 maxlayers = (MIN (xsize, ysize) - 2) / 5;
184 if(!maxlayers) return; /* map too small to onionize */ 203 if (!maxlayers)
185 if(layers > maxlayers) layers = maxlayers; 204 return; /* map too small to onionize */
186 if(layers == 0) layers = (RANDOM() % maxlayers)+1; 205 if (layers > maxlayers)
206 layers = maxlayers;
207 if (layers == 0)
208 layers = rndm (maxlayers) + 1;
187 xlocations = (float *) calloc(sizeof(float),2 * layers); 209 xlocations = (float *) calloc (sizeof (float), 2 * layers);
188 ylocations = (float *) calloc(sizeof(float),2 * layers); 210 ylocations = (float *) calloc (sizeof (float), 2 * layers);
189 211
190 212
191 /* place all the walls */ 213 /* place all the walls */
192 if(option & OPT_IRR_SPACE) /* randomly spaced */ { 214 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
215 {
193 int x_spaces_available, y_spaces_available; 216 int x_spaces_available, y_spaces_available;
217
194 /* the "extra" spaces available for spacing between layers */ 218 /* the "extra" spaces available for spacing between layers */
195 x_spaces_available = (xsize -2) - 6*layers +1; 219 x_spaces_available = (xsize - 2) - 6 * layers + 1;
196 y_spaces_available = (ysize -2) - 3*layers +1; 220 y_spaces_available = (ysize - 2) - 3 * layers + 1;
197 221
198 222
199 /* pick an initial random pitch */ 223 /* pick an initial random pitch */
200 for(i=0;i<2*layers;i++) { 224 for (i = 0; i < 2 * layers; i++)
201 float xpitch=2,ypitch=2; 225 {
226 float xpitch = 2, ypitch = 2;
227
202 if(x_spaces_available>0) 228 if (x_spaces_available > 0)
203 xpitch = 2 + (RANDOM()%x_spaces_available + 229 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3;
204 RANDOM()%x_spaces_available +
205 RANDOM()%x_spaces_available)/3;
206 230
207 if(y_spaces_available>0) 231 if (y_spaces_available > 0)
208 ypitch = 2 + (RANDOM()%y_spaces_available + 232 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3;
209 RANDOM()%y_spaces_available + 233
210 RANDOM()%y_spaces_available)/3;
211 xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; 234 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
212 if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; 235 if (i < layers)
213 else ylocations[i] = ysize-1; 236 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
237 else
238 ylocations[i] = ysize - 1;
239
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 & RMOPT_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
273void
242void draw_onion(char **maze,float *xlocations,float *ylocations, int layers) { 274draw_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
303void
266void make_doors(char **maze, float *xlocations,float *ylocations,int layers,int options) { 304make_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 & RMOPT_BOTTOM_C)
312 freedoms = 3;
272 if(options & OPT_BOTTOM_R) freedoms=2; 313 if (options & RMOPT_BOTTOM_R)
314 freedoms = 2;
273 if(layers<= 0) return; 315 if (layers <= 0)
316 return;
317
274 /* pick which wall will have a door. */ 318 /* pick which wall will have a door. */
275 which_wall = RANDOM() %freedoms + 1; 319 which_wall = rndm (freedoms) + 1;
276 for(l=0;l<layers;l++) { 320 for (l = 0; l < layers; l++)
277 if(options & OPT_LINEAR) { /* linear door placement. */ 321 {
278 switch(which_wall) { 322 if (options & RMOPT_LINEAR)
279 case 1: { /* left hand wall */ 323 { /* linear door placement. */
280 x1 = (int)xlocations[l]; 324 switch (which_wall)
325 {
326 case 1:
327 { /* left hand wall */
328 x1 = (int) xlocations[l];
281 y1 = (int)( (ylocations[l] + ylocations[2*layers-l-1])/2); 329 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2);
282 break; 330 break;
283 } 331 }
284 case 2: { /* top wall placement */ 332 case 2:
333 { /* top wall placement */
285 x1 = (int)( (xlocations[l] + xlocations[2*layers-l-1])/2); 334 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2);
286 y1 = (int)ylocations[l]; 335 y1 = (int) ylocations[l];
287 break; 336 break;
288 } 337 }
289 case 3: { /* right wall placement */ 338 case 3:
290 x1 = (int)xlocations[2*layers-l-1]; 339 { /* right wall placement */
340 x1 = (int) xlocations[2 * layers - l - 1];
291 y1 = (int)( (ylocations[l] + ylocations[2*layers-l-1])/2); 341 y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2);
292 break; 342 break;
293 } 343 }
294 case 4: { /* bottom wall placement */ 344 case 4:
345 { /* bottom wall placement */
295 x1 = (int)( (xlocations[l] + xlocations[2*layers-l-1])/2); 346 x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2);
296 y1 = (int)ylocations[2*layers -l -1]; 347 y1 = (int) ylocations[2 * layers - l - 1];
297 break; 348 break;
298 } 349 }
299 } 350 }
300 } 351 }
301 else { /* random door placement. */ 352 else
302 which_wall=RANDOM()%freedoms + 1; 353 { /* random door placement. */
303 switch(which_wall) { 354 which_wall = rndm (freedoms) + 1;
304 case 1: { /* left hand wall */ 355 switch (which_wall)
305 x1 = (int)xlocations[l]; 356 {
357 case 1:
358 { /* left hand wall */
359 x1 = (int) xlocations[l];
306 y2 = (int) (ylocations[2*layers-l-1]-ylocations[l]-1); 360 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1);
307 if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); 361 if (y2 > 0)
308 else y1 = (int) (ylocations[l]+1); 362 y1 = (int) (ylocations[l] + rndm (y2) + 1);
309 break; 363 else
310 } 364 y1 = (int) (ylocations[l] + 1);
311 case 2: { /* top wall placement */ 365 break;
366 }
367 case 2:
368 { /* top wall placement */
312 x2 = (int)( (-xlocations[l] + xlocations[2*layers-l-1]))-1; 369 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
313 if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); 370 if (x2 > 0)
314 else x1 = (int) (xlocations[l]+1); 371 x1 = (int) (xlocations[l] + rndm (x2) + 1);
315 y1 = (int)ylocations[l]; 372 else
316 break; 373 x1 = (int) (xlocations[l] + 1);
317 } 374 y1 = (int) ylocations[l];
318 case 3: { /* right wall placement */ 375 break;
319 x1 = (int)xlocations[2*layers-l-1]; 376 }
377 case 3:
378 { /* right wall placement */
379 x1 = (int) xlocations[2 * layers - l - 1];
320 y2 = (int)( (-ylocations[l] + ylocations[2*layers-l-1]))-1; 380 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1;
321 if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); 381 if (y2 > 0)
322 else y1 = (int) (ylocations[l]+1); 382 y1 = (int) (ylocations[l] + rndm (y2) + 1);
383 else
384 y1 = (int) (ylocations[l] + 1);
323 385
324 break; 386 break;
325 } 387 }
326 case 4: { /* bottom wall placement */ 388 case 4:
389 { /* bottom wall placement */
327 x2 = (int)( (-xlocations[l] + xlocations[2*layers-l-1]))-1; 390 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
328 if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); 391 if (x2 > 0)
329 else x1 = (int) (xlocations[l]+1); 392 x1 = (int) (xlocations[l] + rndm (x2) + 1);
330 y1 = (int)ylocations[2*layers-l-1]; 393 else
331 break; 394 x1 = (int) (xlocations[l] + 1);
332 } 395 y1 = (int) ylocations[2 * layers - l - 1];
333 396 break;
334 } 397 }
335 } 398
399 }
400 }
336 if(options & OPT_NO_DOORS) 401 if (options & RMOPT_NO_DOORS)
337 maze[x1][y1] = '#'; /* no door. */ 402 maze[x1][y1] = '#'; /* no door. */
338 else 403 else
339 maze[x1][y1] = 'D'; /* write the door */ 404 maze[x1][y1] = 'D'; /* write the door */
340 405
341 } 406 }
342 /* mark the center of the maze with a C */ 407 /* mark the center of the maze with a C */
343 l = layers -1; 408 l = layers - 1;
344 x1 = (int) (xlocations[l] + xlocations[2*layers -l -1])/2; 409 x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2;
345 y1 = (int) (ylocations[l] + ylocations[2*layers -l -1])/2; 410 y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2;
346 maze[x1][y1] = 'C'; 411 maze[x1][y1] = 'C';
347 412
348 /* not needed anymore */ 413 /* not needed anymore */
349 free(xlocations); 414 free (xlocations);
350 free(ylocations); 415 free (ylocations);
351
352}
353 416
417}
418
419void
354void bottom_right_centered_onion(char **maze, int xsize, int ysize, int option, int layers){ 420bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers)
421{
355 int i,maxlayers; 422 int i, maxlayers;
356 float *xlocations; 423 float *xlocations;
357 float *ylocations; 424 float *ylocations;
358 425
359 maxlayers = (MIN(xsize,ysize)-2)/5; 426 maxlayers = (MIN (xsize, ysize) - 2) / 5;
360 if(!maxlayers) return; /* map too small to onionize */ 427 if (!maxlayers)
361 if(layers > maxlayers) layers = maxlayers; 428 return; /* map too small to onionize */
362 if(layers == 0) layers = (RANDOM() % maxlayers)+1; 429 if (layers > maxlayers)
430 layers = maxlayers;
431 if (layers == 0)
432 layers = rndm (maxlayers) + 1;
433
363 xlocations = (float *) calloc(sizeof(float),2 * layers); 434 xlocations = (float *) calloc (sizeof (float), 2 * layers);
364 ylocations = (float *) calloc(sizeof(float),2 * layers); 435 ylocations = (float *) calloc (sizeof (float), 2 * layers);
365 436
366
367 /* place all the walls */ 437 /* place all the walls */
368 if(option & OPT_IRR_SPACE) /* randomly spaced */ { 438 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
439 {
369 int x_spaces_available, y_spaces_available; 440 int x_spaces_available, y_spaces_available;
441
370 /* the "extra" spaces available for spacing between layers */ 442 /* the "extra" spaces available for spacing between layers */
371 x_spaces_available = (xsize -2) - 3*layers +1; 443 x_spaces_available = (xsize - 2) - 3 * layers + 1;
372 y_spaces_available = (ysize -2) - 3*layers +1; 444 y_spaces_available = (ysize - 2) - 3 * layers + 1;
373 445
374 446
375 /* pick an initial random pitch */ 447 /* pick an initial random pitch */
376 for(i=0;i<2*layers;i++) { 448 for (i = 0; i < 2 * layers; i++)
377 float xpitch=2,ypitch=2; 449 {
450 float xpitch = 2, ypitch = 2;
451
378 if(x_spaces_available>0) 452 if (x_spaces_available > 0)
379 xpitch = 2 + (RANDOM()%x_spaces_available + 453 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3;
380 RANDOM()%x_spaces_available +
381 RANDOM()%x_spaces_available)/3;
382 454
383 if(y_spaces_available>0) 455 if (y_spaces_available > 0)
384 ypitch = 2 + (RANDOM()%y_spaces_available + 456 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3;
385 RANDOM()%y_spaces_available + 457
386 RANDOM()%y_spaces_available)/3; 458 if (i < layers)
387 if(i < layers) xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; 459 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
388 else xlocations[i] = xsize-1; 460 else
389 461 xlocations[i] = xsize - 1;
390 if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; 462
391 else ylocations[i] = ysize-1; 463 if (i < layers)
464 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
465 else
466 ylocations[i] = ysize - 1;
392 x_spaces_available-=(int)(xpitch -2); 467 x_spaces_available -= (int) (xpitch - 2);
393 y_spaces_available-=(int)(ypitch -2); 468 y_spaces_available -= (int) (ypitch - 2);
394 } 469 }
395 470
396 } 471 }
397 if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ 472 if (!(option & RMOPT_IRR_SPACE))
473 { /* evenly spaced */
398 float xpitch, ypitch; /* pitch of the onion layers */ 474 float xpitch, ypitch; /* pitch of the onion layers */
475
399 xpitch = (xsize-2.0)/(2.0*layers+1); 476 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
400 ypitch = (ysize-2.0)/(layers+1); 477 ypitch = (ysize - 2.0) / (layers + 1);
401 xlocations[0] = xpitch; 478 xlocations[0] = xpitch;
402 ylocations[0] = ypitch; 479 ylocations[0] = ypitch;
403 for(i=1;i<2*layers;i++) { 480 for (i = 1; i < 2 * layers; i++)
404 if(i < layers) xlocations[i] = xlocations[i-1] + xpitch; 481 {
405 else xlocations[i]=xsize-1; 482 if (i < layers)
406 if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; 483 xlocations[i] = xlocations[i - 1] + xpitch;
407 else ylocations[i]=ysize-1; 484 else
408 } 485 xlocations[i] = xsize - 1;
409 } 486 if (i < layers)
487 ylocations[i] = ylocations[i - 1] + ypitch;
488 else
489 ylocations[i] = ysize - 1;
490 }
410 491 }
492
411 /* draw all the onion boxes. */ 493 /* draw all the onion boxes. */
412 494
413 draw_onion(maze,xlocations,ylocations,layers); 495 draw_onion (maze, xlocations, ylocations, layers);
414 make_doors(maze,xlocations,ylocations,layers,option); 496 make_doors (maze, xlocations, ylocations, layers, option);
415 497
416} 498}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines