63 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
66 void centered_onion(
char **maze,
int xsize,
int ysize,
int option,
int layers);
70 void draw_onion(
char **maze,
float *xlocations,
float *ylocations,
int layers);
71 void make_doors(
char **maze,
float *xlocations,
float *ylocations,
int layers,
int options);
89 char **maze = (
char **)calloc(
sizeof(
char *), xsize);
90 for (i = 0; i < xsize; i++) {
91 maze[i] = (
char *)calloc(
sizeof(
char), ysize);
117 for (i = 0; i < xsize; i++)
118 maze[i][0] = maze[i][ysize-1] =
'#';
119 for (j = 0; j < ysize; j++)
120 maze[0][j] = maze[xsize-1][j] =
'#';
154 maxlayers = (
MIN(xsize, ysize)-2)/5;
157 if (layers > maxlayers)
160 layers = (RANDOM()%maxlayers)+1;
161 xlocations = (
float *)calloc(
sizeof(
float), 2*layers);
162 ylocations = (
float *)calloc(
sizeof(
float), 2*layers);
166 int x_spaces_available, y_spaces_available;
168 x_spaces_available = (xsize-2)-6*layers+1;
169 y_spaces_available = (ysize-2)-6*layers+1;
172 for (i = 0; i < 2*layers; i++) {
173 float xpitch = 2, ypitch = 2;
175 if (x_spaces_available > 0)
177 +(RANDOM()%x_spaces_available
178 +RANDOM()%x_spaces_available
179 +RANDOM()%x_spaces_available)/3;
181 if (y_spaces_available > 0)
183 +(RANDOM()%y_spaces_available
184 +RANDOM()%y_spaces_available
185 +RANDOM()%y_spaces_available)/3;
186 xlocations[i] = ((i > 0) ? xlocations[i-1] : 0)+xpitch;
187 ylocations[i] = ((i > 0) ? ylocations[i-1] : 0)+ypitch;
188 x_spaces_available -= xpitch-2;
189 y_spaces_available -= ypitch-2;
193 if (!(option&OPT_IRR_SPACE)) {
195 float xpitch, ypitch;
197 xpitch = (xsize-2.0)/(2.0*layers+1);
198 ypitch = (ysize-2.0)/(2.0*layers+1);
199 xlocations[0] = xpitch;
200 ylocations[0] = ypitch;
201 for (i = 1; i < 2*layers; i++) {
202 xlocations[i] = xlocations[i-1]+xpitch;
203 ylocations[i] = ylocations[i-1]+ypitch;
208 draw_onion(maze, xlocations, ylocations, layers);
209 make_doors(maze, xlocations, ylocations, layers, option);
229 maxlayers = (
MIN(xsize, ysize)-2)/5;
232 if (layers > maxlayers)
235 layers = (RANDOM()%maxlayers)+1;
236 xlocations = (
float *)calloc(
sizeof(
float), 2*layers);
237 ylocations = (
float *)calloc(
sizeof(
float), 2*layers);
241 int x_spaces_available, y_spaces_available;
243 x_spaces_available = (xsize-2)-6*layers+1;
244 y_spaces_available = (ysize-2)-3*layers+1;
247 for (i = 0; i < 2*layers; i++) {
248 float xpitch = 2, ypitch = 2;
250 if (x_spaces_available > 0)
252 +(RANDOM()%x_spaces_available
253 +RANDOM()%x_spaces_available
254 +RANDOM()%x_spaces_available)/3;
256 if (y_spaces_available > 0)
258 +(RANDOM()%y_spaces_available
259 +RANDOM()%y_spaces_available
260 +RANDOM()%y_spaces_available)/3;
261 xlocations[i] = ((i > 0) ? xlocations[i-1] : 0)+xpitch;
263 ylocations[i] = ((i > 0) ? ylocations[i-1] : 0)+ypitch;
265 ylocations[i] = ysize-1;
266 x_spaces_available -= xpitch-2;
267 y_spaces_available -= ypitch-2;
272 if (!(option&OPT_IRR_SPACE)) {
274 float xpitch, ypitch;
276 xpitch = (xsize-2.0)/(2.0*layers+1);
277 ypitch = (ysize-2.0)/(layers+1);
278 xlocations[0] = xpitch;
279 ylocations[0] = ypitch;
280 for (i = 1; i < 2*layers; i++) {
281 xlocations[i] = xlocations[i-1]+xpitch;
283 ylocations[i] = ylocations[i-1]+ypitch;
285 ylocations[i] = ysize-1;
290 draw_onion(maze, xlocations, ylocations, layers);
291 make_doors(maze, xlocations, ylocations, layers, option);
306 void draw_onion(
char **maze,
float *xlocations,
float *ylocations,
int layers) {
309 for (l = 0; l < layers; l++) {
313 y1 = (int)ylocations[l];
314 y2 = (int)ylocations[2*layers-l-1];
315 for (i = (
int)xlocations[l]; i <= (int)xlocations[2*layers-l-1]; i++) {
321 x1 = (int)xlocations[l];
322 x2 = (int)xlocations[2*layers-l-1];
323 for (j = (
int)ylocations[l]; j <= (int)ylocations[2*layers-l-1]; j++) {
347 int l, x1 = 0, x2, y1 = 0, y2;
358 which_wall = RANDOM()%freedoms+1;
359 for (l = 0; l < layers; l++) {
361 switch (which_wall) {
363 x1 = (int)xlocations[l];
364 y1 = (int)((ylocations[l]+ylocations[2*layers-l-1])/2);
369 x1 = (int)((xlocations[l]+xlocations[2*layers-l-1])/2);
370 y1 = (int)ylocations[l];
375 x1 = (int)xlocations[2*layers-l-1];
376 y1 = (int)((ylocations[l]+ylocations[2*layers-l-1])/2);
381 x1 = (int)((xlocations[l]+xlocations[2*layers-l-1])/2);
382 y1 = (int)ylocations[2*layers-l-1];
387 which_wall = RANDOM()%freedoms+1;
388 switch (which_wall) {
390 x1 = (int)xlocations[l];
391 y2 = ylocations[2*layers-l-1]-ylocations[l]-1;
393 y1 = ylocations[l]+RANDOM()%y2+1;
395 y1 = ylocations[l]+1;
400 x2 = (int)((-xlocations[l]+xlocations[2*layers-l-1]))-1;
402 x1 = xlocations[l]+RANDOM()%x2+1;
404 x1 = xlocations[l]+1;
405 y1 = (int)ylocations[l];
410 x1 = (int)xlocations[2*layers-l-1];
411 y2 = (int)((-ylocations[l]+ylocations[2*layers-l-1]))-1;
413 y1 = ylocations[l]+RANDOM()%y2+1;
415 y1 = ylocations[l]+1;
420 x2 = (int)((-xlocations[l]+xlocations[2*layers-l-1]))-1;
422 x1 = xlocations[l]+RANDOM()%x2+1;
424 x1 = xlocations[l]+1;
425 y1 = (int)ylocations[2*layers-l-1];
439 x1 = (int)(xlocations[l]+xlocations[2*layers-l-1])/2;
440 y1 = (int)(ylocations[l]+ylocations[2*layers-l-1])/2;
465 maxlayers = (
MIN(xsize, ysize)-2)/5;
468 if (layers > maxlayers)
471 layers = (RANDOM()%maxlayers)+1;
472 xlocations = (
float *)calloc(
sizeof(
float), 2*layers);
473 ylocations = (
float *)calloc(
sizeof(
float), 2*layers);
477 int x_spaces_available, y_spaces_available;
479 x_spaces_available = (xsize-2)-3*layers+1;
480 y_spaces_available = (ysize-2)-3*layers+1;
483 for (i = 0; i < 2*layers; i++) {
484 float xpitch = 2, ypitch = 2;
486 if (x_spaces_available > 0)
488 +(RANDOM()%x_spaces_available
489 +RANDOM()%x_spaces_available
490 +RANDOM()%x_spaces_available)/3;
492 if (y_spaces_available > 0)
494 +(RANDOM()%y_spaces_available
495 +RANDOM()%y_spaces_available
496 +RANDOM()%y_spaces_available)/3;
498 xlocations[i] = ((i > 0) ? xlocations[i-1] : 0)+xpitch;
500 xlocations[i] = xsize-1;
503 ylocations[i] = ((i > 0) ? ylocations[i-1] : 0)+ypitch;
505 ylocations[i] = ysize-1;
506 x_spaces_available -= xpitch-2;
507 y_spaces_available -= ypitch-2;
512 if (!(option&OPT_IRR_SPACE)) {
513 float xpitch, ypitch;
515 xpitch = (xsize-2.0)/(2.0*layers+1);
516 ypitch = (ysize-2.0)/(layers+1);
517 xlocations[0] = xpitch;
518 ylocations[0] = ypitch;
519 for (i = 1; i < 2*layers; i++) {
521 xlocations[i] = xlocations[i-1]+xpitch;
523 xlocations[i] = xsize-1;
525 ylocations[i] = ylocations[i-1]+ypitch;
527 ylocations[i] = ysize-1;
532 draw_onion(maze, xlocations, ylocations, layers);
533 make_doors(maze, xlocations, ylocations, layers, option);
static struct Command_Line_Options options[]
void make_doors(char **maze, float *xlocations, float *ylocations, int layers, int options)
void centered_onion(char **maze, int xsize, int ysize, int option, int layers)
void draw_onion(char **maze, float *xlocations, float *ylocations, int layers)
void bottom_centered_onion(char **maze, int xsize, int ysize, int option, int layers)
void bottom_right_centered_onion(char **maze, int xsize, int ysize, int option, int layers)
char ** map_gen_onion(int xsize, int ysize, int option, int layers)