48 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
55 void draw_onion(
char **maze,
float *xlocations,
float *ylocations,
int layers);
56 void make_doors(
char **maze,
float *xlocations,
float *ylocations,
int layers,
int options);
75 char **maze = (
char **)calloc(xsize,
sizeof(
char *));
76 for (i = 0; i < xsize; i++) {
77 maze[i] = (
char *)calloc(ysize,
sizeof(
char));
105 for (i = 0; i < xsize; i++) {
106 maze[i][0] = maze[i][ysize-1] =
'#';
108 for (j = 0; j < ysize; j++) {
109 maze[0][j] = maze[xsize-1][j] =
'#';
147 maxlayers = (
MIN(xsize, ysize)-2)/5;
151 if (layers > maxlayers) {
155 layers = (
RANDOM()%maxlayers)+1;
157 xlocations = (
float *)calloc(2 * layers,
sizeof(
float));
158 ylocations = (
float *)calloc(2 * layers,
sizeof(
float));
162 int x_spaces_available, y_spaces_available;
164 x_spaces_available = (xsize-2)-6*layers+1;
165 y_spaces_available = (ysize-2)-6*layers+1;
168 for (i = 0; i < 2*layers; i++) {
169 float xpitch = 2, ypitch = 2;
171 if (x_spaces_available > 0)
173 +(
RANDOM()%x_spaces_available
174 +
RANDOM()%x_spaces_available
175 +
RANDOM()%x_spaces_available)/3;
177 if (y_spaces_available > 0)
179 +(
RANDOM()%y_spaces_available
180 +
RANDOM()%y_spaces_available
181 +
RANDOM()%y_spaces_available)/3;
182 xlocations[i] = ((i > 0) ? xlocations[i-1] : 0)+xpitch;
183 ylocations[i] = ((i > 0) ? ylocations[i-1] : 0)+ypitch;
184 x_spaces_available -= xpitch-2;
185 y_spaces_available -= ypitch-2;
190 float xpitch, ypitch;
192 xpitch = (xsize-2.0)/(2.0*layers+1);
193 ypitch = (ysize-2.0)/(2.0*layers+1);
194 xlocations[0] = xpitch;
195 ylocations[0] = ypitch;
196 for (i = 1; i < 2*layers; i++) {
197 xlocations[i] = xlocations[i-1]+xpitch;
198 ylocations[i] = ylocations[i-1]+ypitch;
203 draw_onion(maze, xlocations, ylocations, layers);
225 maxlayers = (
MIN(xsize, ysize)-2)/5;
229 if (layers > maxlayers) {
233 layers = (
RANDOM()%maxlayers)+1;
235 xlocations = (
float *)calloc(2 * layers,
sizeof(
float));
236 ylocations = (
float *)calloc(2 * layers,
sizeof(
float));
240 int x_spaces_available, y_spaces_available;
242 x_spaces_available = (xsize-2)-6*layers+1;
243 y_spaces_available = (ysize-2)-3*layers+1;
246 for (i = 0; i < 2*layers; i++) {
247 float xpitch = 2, ypitch = 2;
249 if (x_spaces_available > 0)
251 +(
RANDOM()%x_spaces_available
252 +
RANDOM()%x_spaces_available
253 +
RANDOM()%x_spaces_available)/3;
255 if (y_spaces_available > 0)
257 +(
RANDOM()%y_spaces_available
258 +
RANDOM()%y_spaces_available
259 +
RANDOM()%y_spaces_available)/3;
260 xlocations[i] = ((i > 0) ? xlocations[i-1] : 0)+xpitch;
262 ylocations[i] = ((i > 0) ? ylocations[i-1] : 0)+ypitch;
264 ylocations[i] = ysize-1;
266 x_spaces_available -= xpitch-2;
267 y_spaces_available -= ypitch-2;
273 float xpitch, ypitch;
275 xpitch = (xsize-2.0)/(2.0*layers+1);
276 ypitch = (ysize-2.0)/(layers+1);
277 xlocations[0] = xpitch;
278 ylocations[0] = ypitch;
279 for (i = 1; i < 2*layers; i++) {
280 xlocations[i] = xlocations[i-1]+xpitch;
282 ylocations[i] = ylocations[i-1]+ypitch;
284 ylocations[i] = ysize-1;
290 draw_onion(maze, xlocations, ylocations, layers);
306 void draw_onion(
char **maze,
float *xlocations,
float *ylocations,
int layers)
310 for (
l = 0;
l < layers;
l++) {
315 y2 = (
int)ylocations[2*layers-
l-1];
316 for (i = (
int)xlocations[
l]; i <= (
int)xlocations[2*layers-
l-1]; i++) {
323 x2 = (
int)xlocations[2*layers-
l-1];
324 for (j = (
int)ylocations[
l]; j <= (
int)ylocations[2*layers-
l-1]; j++) {
349 int l,
x1 = 0, x2,
y1 = 0, y2;
363 which_wall =
RANDOM()%freedoms+1;
364 for (
l = 0;
l < layers;
l++) {
366 switch (which_wall) {
369 y1 = (
int)((ylocations[
l]+ylocations[2*layers-
l-1])/2);
374 x1 = (
int)((xlocations[
l]+xlocations[2*layers-
l-1])/2);
380 x1 = (
int)xlocations[2*layers-
l-1];
381 y1 = (
int)((ylocations[
l]+ylocations[2*layers-
l-1])/2);
386 x1 = (
int)((xlocations[
l]+xlocations[2*layers-
l-1])/2);
387 y1 = (
int)ylocations[2*layers-
l-1];
392 which_wall =
RANDOM()%freedoms+1;
393 switch (which_wall) {
396 y2 = ylocations[2*layers-
l-1]-ylocations[
l]-1;
400 y1 = ylocations[
l]+1;
406 x2 = (
int)((-xlocations[
l]+xlocations[2*layers-
l-1]))-1;
410 x1 = xlocations[
l]+1;
417 x1 = (
int)xlocations[2*layers-
l-1];
418 y2 = (
int)((-ylocations[
l]+ylocations[2*layers-
l-1]))-1;
422 y1 = ylocations[
l]+1;
428 x2 = (
int)((-xlocations[
l]+xlocations[2*layers-
l-1]))-1;
432 x1 = xlocations[
l]+1;
434 y1 = (
int)ylocations[2*layers-
l-1];
449 x1 = (
int)(xlocations[
l]+xlocations[2*layers-
l-1])/2;
450 y1 = (
int)(ylocations[
l]+ylocations[2*layers-
l-1])/2;
477 maxlayers = (
MIN(xsize, ysize)-2)/5;
481 if (layers > maxlayers) {
485 layers = (
RANDOM()%maxlayers)+1;
487 xlocations = (
float *)calloc(2 * layers,
sizeof(
float));
488 ylocations = (
float *)calloc(2 * layers,
sizeof(
float));
492 int x_spaces_available, y_spaces_available;
494 x_spaces_available = (xsize-2)-3*layers+1;
495 y_spaces_available = (ysize-2)-3*layers+1;
498 for (i = 0; i < 2*layers; i++) {
499 float xpitch = 2, ypitch = 2;
501 if (x_spaces_available > 0)
503 +(
RANDOM()%x_spaces_available
504 +
RANDOM()%x_spaces_available
505 +
RANDOM()%x_spaces_available)/3;
507 if (y_spaces_available > 0)
509 +(
RANDOM()%y_spaces_available
510 +
RANDOM()%y_spaces_available
511 +
RANDOM()%y_spaces_available)/3;
513 xlocations[i] = ((i > 0) ? xlocations[i-1] : 0)+xpitch;
515 xlocations[i] = xsize-1;
519 ylocations[i] = ((i > 0) ? ylocations[i-1] : 0)+ypitch;
521 ylocations[i] = ysize-1;
523 x_spaces_available -= xpitch-2;
524 y_spaces_available -= ypitch-2;
529 float xpitch, ypitch;
531 xpitch = (xsize-2.0)/(2.0*layers+1);
532 ypitch = (ysize-2.0)/(layers+1);
533 xlocations[0] = xpitch;
534 ylocations[0] = ypitch;
535 for (i = 1; i < 2*layers; i++) {
537 xlocations[i] = xlocations[i-1]+xpitch;
539 xlocations[i] = xsize-1;
542 ylocations[i] = ylocations[i-1]+ypitch;
544 ylocations[i] = ysize-1;
550 draw_onion(maze, xlocations, ylocations, layers);