--- deliantra/server/random_maps/room_gen_spiral.C 2006/08/13 17:16:03 1.1 +++ deliantra/server/random_maps/room_gen_spiral.C 2006/12/31 19:02:24 1.5 @@ -1,3 +1,4 @@ + /* CrossFire, A Multiplayer game for X-windows @@ -32,99 +33,113 @@ #include #include -#define RANDOM_OPTIONS 0 /* Pick random options below */ -#define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly*/ -#define FINE_SPIRAL 2 /* uses the min. separation: most coiling */ -#define FIT_SPIRAL 4 /* scale to a rectangular region, not square */ -#define MAX_SPIRAL_OPT 8 /* this should be 2x the last real option */ +#define RANDOM_OPTIONS 0 /* Pick random options below */ +#define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */ +#define FINE_SPIRAL 2 /* uses the min. separation: most coiling */ +#define FIT_SPIRAL 4 /* scale to a rectangular region, not square */ +#define MAX_SPIRAL_OPT 8 /* this should be 2x the last real option */ #include #ifndef MIN -#define MIN(x,y) (((x)<(y))? (x):(y)) +# define MIN(x,y) (((x)<(y))? (x):(y)) #endif #ifndef MAX -#define MAX(x,y) (((x)<(y))? (y):(x)) +# define MAX(x,y) (((x)<(y))? (y):(x)) #endif #define MINDIST 3 #define MAX_FINE .454545 -extern int surround_check(char **maze,int i, int j, int xsize, int ysize); +extern int surround_check (char **maze, int i, int j, int xsize, int ysize); + +char ** +map_gen_spiral (int xsize, int ysize, int option) +{ + int i, j; + float parm = 0; + float x = 0, y = 0; + int ic, jc; + float SizeX, SizeY; + float xscale, yscale; -char **map_gen_spiral(int xsize, int ysize, int option) { - int i,j; - float parm=0; - float x=0,y=0; - int ic,jc; - float SizeX,SizeY; - float xscale,yscale; - /* allocate that array, set it up */ - char **maze = (char **)calloc(sizeof(char*),xsize); - for(i=0;i ysize) xscale *= (float)xsize/(float)ysize; - else yscale *= (float)ysize/(float)xsize; - } - - if(option & REGULAR_SPIRAL) { - float scale = MIN(xscale,yscale); - xscale=yscale=scale; - } + if (!(option & FINE_SPIRAL)) + { + float pitch = (RANDOM () % 5) / 10. + 10. / 22.; + + xscale = yscale = pitch; + } + + if ((option & FIT_SPIRAL) && (xsize != ysize)) + { + if (xsize > ysize) + xscale *= (float) xsize / (float) ysize; + else + yscale *= (float) ysize / (float) xsize; + } + + if (option & REGULAR_SPIRAL) + { + float scale = MIN (xscale, yscale); + + xscale = yscale = scale; + } /* cut out the spiral */ - while( (fabs(x) < SizeX) && (fabs(y) < SizeY) ) + while ((fabs (x) < SizeX) && (fabs (y) < SizeY)) { - x = parm * cos(parm)*xscale; - y = parm * sin(parm)*yscale; - maze[(int)(ic + x )][(int)(jc + y )]='\0'; - parm+=0.01; + x = parm * cos (parm) * xscale; + y = parm * sin (parm) * yscale; + maze[(int) (ic + x)][(int) (jc + y)] = '\0'; + parm += 0.01; }; - -maze[(int)(ic + x+0.5)][(int)(jc + y+0.5)]='<'; + + maze[(int) (ic + x + 0.5)][(int) (jc + y + 0.5)] = '<'; /* cut out the center in a 2x2 and place the center and downexit */ - maze[ic][jc+1]='>'; - maze[ic][jc]='C'; + maze[ic][jc + 1] = '>'; + maze[ic][jc] = 'C'; return maze; @@ -132,73 +147,86 @@ /* the following function connects disjoint spirals which may result from the symmetrization process. */ -void connect_spirals(int xsize,int ysize,int sym, char **layout) { +void +connect_spirals (int xsize, int ysize, int sym, char **layout) +{ - int i,j,ic=xsize/2,jc=ysize/2; + int i, j, ic = xsize / 2, jc = ysize / 2; - if(sym==X_SYM) { - layout[ic][jc] = 0; - /* go left from map center */ - for(i=ic-1,j=jc; i>0 && layout[i][j]=='#' ;i--) - layout[i][j]=0; - /* go right */ - for(i=ic+1,j=jc; i0 && layout[i][j]=='#' ;j--) - layout[i][j]=0; - /* go down */ - for(i=ic,j=jc+1; j0 && layout[i][j]=='#' ;i--) { - layout[i][j + jc]=0; - layout[i][j]=0; - } - /* go right */ - for(i=ic+1,j=jc/2; i0 && layout[i][j]=='#' ;j--) { - layout[i][j]=0; - layout[i+ic][j]=0; - } - /* go down */ - for(i=ic/2,j=jc+1; j 0 && layout[i][j] == '#'; i--) + layout[i][j] = 0; + /* go right */ + for (i = ic + 1, j = jc; i < xsize - 1 && layout[i][j] == '#'; i++) + layout[i][j] = 0; } - } + if (sym == SYMMETRY_Y) + { - /* get rid of bad doors. */ - for(i=0;i 0 && layout[i][j] == '#'; j--) + layout[i][j] = 0; + /* go down */ + for (i = ic, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) + layout[i][j] = 0; + } + + if (sym == SYMMETRY_XY) + { + /* go left from map center */ + layout[ic][jc / 2] = 0; + layout[ic / 2][jc] = 0; + layout[ic][jc / 2 + jc] = 0; + layout[ic / 2 + ic][jc] = 0; + for (i = ic - 1, j = jc / 2; i > 0 && layout[i][j] == '#'; i--) + { + layout[i][j + jc] = 0; + layout[i][j] = 0; } - } + /* go right */ + for (i = ic + 1, j = jc / 2; i < xsize - 1 && layout[i][j] == '#'; i++) + { + layout[i][j + jc] = 0; + layout[i][j] = 0; + } + /* go up */ + for (i = ic / 2, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) + { + layout[i][j] = 0; + layout[i + ic][j] = 0; + } + /* go down */ + for (i = ic / 2, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) + { + layout[i][j] = 0; + layout[i + ic][j] = 0; + } + } - + /* get rid of bad doors. */ + for (i = 0; i < xsize; i++) + for (j = 0; j < ysize; j++) + { + if (layout[i][j] == 'D') + { /* remove bad door. */ + int si = surround_check (layout, i, j, xsize, ysize); + + if (si != 3 && si != 12) + { + layout[i][j] = 0; + /* back up and recheck any nearby doors */ + i = 0; + j = 0; + } + } + } -} + +}