--- deliantra/server/random_maps/room_gen_onion.C 2006/08/13 17:16:03 1.1 +++ deliantra/server/random_maps/room_gen_onion.C 2006/08/29 08:01:36 1.2 @@ -1,6 +1,6 @@ /* * static char *room_gen_onion_c = - * "$Id: room_gen_onion.C,v 1.1 2006/08/13 17:16:03 elmex Exp $"; + * "$Id: room_gen_onion.C,v 1.2 2006/08/29 08:01:36 root Exp $"; */ /* @@ -80,27 +80,27 @@ /* pick some random options if option = 0 */ if(option == 0) { - switch(RANDOM()%3) { - case 0: - option |= OPT_CENTERED; - break; - case 1: - option |= OPT_BOTTOM_C; - break; - case 2: - option |= OPT_BOTTOM_R; - break; - } - if(RANDOM()%2) option |=OPT_LINEAR; - if(RANDOM()%2) option |=OPT_IRR_SPACE; + switch(RANDOM()%3) { + case 0: + option |= OPT_CENTERED; + break; + case 1: + option |= OPT_BOTTOM_C; + break; + case 2: + option |= OPT_BOTTOM_R; + break; + } + if(RANDOM()%2) option |=OPT_LINEAR; + if(RANDOM()%2) option |=OPT_IRR_SPACE; } /* write the outer walls, if appropriate. */ if(!(option & OPT_WALL_OFF )) { for(i=0;i0) - xpitch = 2 + (RANDOM()%x_spaces_available + - RANDOM()%x_spaces_available + - RANDOM()%x_spaces_available)/3; - - if(y_spaces_available>0) - ypitch = 2 + (RANDOM()%y_spaces_available + - RANDOM()%y_spaces_available + - RANDOM()%y_spaces_available)/3; - xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; - ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; - x_spaces_available-=(int) (xpitch -2); - y_spaces_available-=(int) (ypitch -2); - } - + int x_spaces_available, y_spaces_available; + /* the "extra" spaces available for spacing between layers */ + x_spaces_available = (xsize -2) - 6*layers +1; + y_spaces_available = (ysize -2) - 6*layers +1; + + + /* pick an initial random pitch */ + for(i=0;i<2*layers;i++) { + float xpitch=2,ypitch=2; + if(x_spaces_available>0) + xpitch = 2 + (RANDOM()%x_spaces_available + + RANDOM()%x_spaces_available + + RANDOM()%x_spaces_available)/3; + + if(y_spaces_available>0) + ypitch = 2 + (RANDOM()%y_spaces_available + + RANDOM()%y_spaces_available + + RANDOM()%y_spaces_available)/3; + xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; + ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; + x_spaces_available-=(int) (xpitch -2); + y_spaces_available-=(int) (ypitch -2); + } + } if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ float xpitch, ypitch; /* pitch of the onion layers */ @@ -163,8 +163,8 @@ xlocations[0] = xpitch; ylocations[0] = ypitch; for(i=1;i<2*layers;i++) { - xlocations[i] = xlocations[i-1] + xpitch; - ylocations[i] = ylocations[i-1] + ypitch; + xlocations[i] = xlocations[i-1] + xpitch; + ylocations[i] = ylocations[i-1] + ypitch; } } @@ -190,31 +190,31 @@ /* place all the walls */ if(option & OPT_IRR_SPACE) /* randomly spaced */ { - int x_spaces_available, y_spaces_available; - /* the "extra" spaces available for spacing between layers */ - x_spaces_available = (xsize -2) - 6*layers +1; - y_spaces_available = (ysize -2) - 3*layers +1; - - - /* pick an initial random pitch */ - for(i=0;i<2*layers;i++) { - float xpitch=2,ypitch=2; - if(x_spaces_available>0) - xpitch = 2 + (RANDOM()%x_spaces_available + - RANDOM()%x_spaces_available + - RANDOM()%x_spaces_available)/3; - - if(y_spaces_available>0) - ypitch = 2 + (RANDOM()%y_spaces_available + - RANDOM()%y_spaces_available + - RANDOM()%y_spaces_available)/3; - xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; - if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; - else ylocations[i] = ysize-1; - x_spaces_available-=(int)(xpitch -2); - y_spaces_available-=(int)(ypitch -2); - } - + int x_spaces_available, y_spaces_available; + /* the "extra" spaces available for spacing between layers */ + x_spaces_available = (xsize -2) - 6*layers +1; + y_spaces_available = (ysize -2) - 3*layers +1; + + + /* pick an initial random pitch */ + for(i=0;i<2*layers;i++) { + float xpitch=2,ypitch=2; + if(x_spaces_available>0) + xpitch = 2 + (RANDOM()%x_spaces_available + + RANDOM()%x_spaces_available + + RANDOM()%x_spaces_available)/3; + + if(y_spaces_available>0) + ypitch = 2 + (RANDOM()%y_spaces_available + + RANDOM()%y_spaces_available + + RANDOM()%y_spaces_available)/3; + xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; + if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; + else ylocations[i] = ysize-1; + x_spaces_available-=(int)(xpitch -2); + y_spaces_available-=(int)(ypitch -2); + } + } if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ float xpitch, ypitch; /* pitch of the onion layers */ @@ -223,9 +223,9 @@ xlocations[0] = xpitch; ylocations[0] = ypitch; for(i=1;i<2*layers;i++) { - xlocations[i] = xlocations[i-1] + xpitch; - if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; - else ylocations[i]=ysize-1; + xlocations[i] = xlocations[i-1] + xpitch; + if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; + else ylocations[i]=ysize-1; } } @@ -243,23 +243,23 @@ int i,j,l; for(l=0;l 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); - else y1 = (int) (ylocations[l]+1); - break; - } - case 2: { /* top wall placement */ - x2 = (int)( (-xlocations[l] + xlocations[2*layers-l-1]))-1; - if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); - else x1 = (int) (xlocations[l]+1); - y1 = (int)ylocations[l]; - break; - } - case 3: { /* right wall placement */ - x1 = (int)xlocations[2*layers-l-1]; - y2 = (int)( (-ylocations[l] + ylocations[2*layers-l-1]))-1; - if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); - else y1 = (int) (ylocations[l]+1); - - break; - } - case 4: { /* bottom wall placement */ - x2 = (int)( (-xlocations[l] + xlocations[2*layers-l-1]))-1; - if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); - else x1 = (int) (xlocations[l]+1); - y1 = (int)ylocations[2*layers-l-1]; - break; - } - - } - } - if(options & OPT_NO_DOORS) + if(options & OPT_LINEAR) { /* linear door placement. */ + switch(which_wall) { + case 1: { /* left hand wall */ + x1 = (int)xlocations[l]; + y1 = (int)( (ylocations[l] + ylocations[2*layers-l-1])/2); + break; + } + case 2: { /* top wall placement */ + x1 = (int)( (xlocations[l] + xlocations[2*layers-l-1])/2); + y1 = (int)ylocations[l]; + break; + } + case 3: { /* right wall placement */ + x1 = (int)xlocations[2*layers-l-1]; + y1 = (int)( (ylocations[l] + ylocations[2*layers-l-1])/2); + break; + } + case 4: { /* bottom wall placement */ + x1 = (int)( (xlocations[l] + xlocations[2*layers-l-1])/2); + y1 = (int)ylocations[2*layers -l -1]; + break; + } + } + } + else { /* random door placement. */ + which_wall=RANDOM()%freedoms + 1; + switch(which_wall) { + case 1: { /* left hand wall */ + x1 = (int)xlocations[l]; + y2 = (int) (ylocations[2*layers-l-1]-ylocations[l]-1); + if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); + else y1 = (int) (ylocations[l]+1); + break; + } + case 2: { /* top wall placement */ + x2 = (int)( (-xlocations[l] + xlocations[2*layers-l-1]))-1; + if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); + else x1 = (int) (xlocations[l]+1); + y1 = (int)ylocations[l]; + break; + } + case 3: { /* right wall placement */ + x1 = (int)xlocations[2*layers-l-1]; + y2 = (int)( (-ylocations[l] + ylocations[2*layers-l-1]))-1; + if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); + else y1 = (int) (ylocations[l]+1); + + break; + } + case 4: { /* bottom wall placement */ + x2 = (int)( (-xlocations[l] + xlocations[2*layers-l-1]))-1; + if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); + else x1 = (int) (xlocations[l]+1); + y1 = (int)ylocations[2*layers-l-1]; + break; + } + + } + } + if(options & OPT_NO_DOORS) maze[x1][y1] = '#'; /* no door. */ else maze[x1][y1] = 'D'; /* write the door */ @@ -366,33 +366,33 @@ /* place all the walls */ if(option & OPT_IRR_SPACE) /* randomly spaced */ { - int x_spaces_available, y_spaces_available; - /* the "extra" spaces available for spacing between layers */ - x_spaces_available = (xsize -2) - 3*layers +1; - y_spaces_available = (ysize -2) - 3*layers +1; - - - /* pick an initial random pitch */ - for(i=0;i<2*layers;i++) { - float xpitch=2,ypitch=2; - if(x_spaces_available>0) - xpitch = 2 + (RANDOM()%x_spaces_available + - RANDOM()%x_spaces_available + - RANDOM()%x_spaces_available)/3; - - if(y_spaces_available>0) - ypitch = 2 + (RANDOM()%y_spaces_available + - RANDOM()%y_spaces_available + - RANDOM()%y_spaces_available)/3; - if(i < layers) xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; - else xlocations[i] = xsize-1; - - if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; - else ylocations[i] = ysize-1; - x_spaces_available-=(int)(xpitch -2); - y_spaces_available-=(int)(ypitch -2); - } - + int x_spaces_available, y_spaces_available; + /* the "extra" spaces available for spacing between layers */ + x_spaces_available = (xsize -2) - 3*layers +1; + y_spaces_available = (ysize -2) - 3*layers +1; + + + /* pick an initial random pitch */ + for(i=0;i<2*layers;i++) { + float xpitch=2,ypitch=2; + if(x_spaces_available>0) + xpitch = 2 + (RANDOM()%x_spaces_available + + RANDOM()%x_spaces_available + + RANDOM()%x_spaces_available)/3; + + if(y_spaces_available>0) + ypitch = 2 + (RANDOM()%y_spaces_available + + RANDOM()%y_spaces_available + + RANDOM()%y_spaces_available)/3; + if(i < layers) xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; + else xlocations[i] = xsize-1; + + if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; + else ylocations[i] = ysize-1; + x_spaces_available-=(int)(xpitch -2); + y_spaces_available-=(int)(ypitch -2); + } + } if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ float xpitch, ypitch; /* pitch of the onion layers */ @@ -401,10 +401,10 @@ xlocations[0] = xpitch; ylocations[0] = ypitch; for(i=1;i<2*layers;i++) { - if(i < layers) xlocations[i] = xlocations[i-1] + xpitch; - else xlocations[i]=xsize-1; - if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; - else ylocations[i]=ysize-1; + if(i < layers) xlocations[i] = xlocations[i-1] + xpitch; + else xlocations[i]=xsize-1; + if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; + else ylocations[i]=ysize-1; } }