--- deliantra/server/random_maps/maze_gen.C 2008/05/08 14:20:19 1.12 +++ deliantra/server/random_maps/maze_gen.C 2009/11/06 13:31:47 1.15 @@ -22,56 +22,13 @@ /* global variables that everyone needs: don't want to pass them in as parameters every time. */ -int *wall_x_list = 0; -int *wall_y_list = 0; -int wall_free_size = 0; - -/* heuristically, we need to change wall_chance based on the size of - the maze. */ - -int wall_chance; - -/* the outsize interface routine: accepts sizes, returns a char -** maze. option is a flag for either a sparse or a full maze. Sparse -mazes have sizable rooms. option = 1, full, 0, sparse.*/ -void -maze_gen (Layout maze, int option) -{ - maze->clear (); - maze->border (); - - /* find how many free wall spots there are */ - wall_free_size = 2 * (maze->w - 4) + 2 * (maze->h - 4); - - make_wall_free_list (maze->w, maze->h); - - /* return the empty maze */ - if (wall_free_size <= 0) - return; - - /* recursively generate the walls of the maze */ - /* first pop a random starting point */ - while (wall_free_size > 0) - { - int i, j; - - pop_wall_point (&i, &j); - - if (option) - fill_maze_full (maze, i, j, maze->w, maze->h); - else - fill_maze_sparse (maze, i, j, maze->w, maze->h); - } - - /* clean up our intermediate data structures. */ - - free (wall_x_list); - free (wall_y_list); -} +static int *wall_x_list = 0; +static int *wall_y_list = 0; +static int wall_free_size = 0; /* the free wall points are those outer points which aren't corners or near corners, and don't have a maze wall growing out of them already. */ -void +static void make_wall_free_list (int xsize, int ysize) { int i, j, count; @@ -108,7 +65,7 @@ } /* randomly returns one of the elements from the wall point list */ -void +static void pop_wall_point (int *x, int *y) { int index = rmg_rndm (wall_free_size); @@ -124,7 +81,7 @@ /* find free point: randomly look for a square adjacent to this one where we can place a new block without closing a path. We may only look up, down, right, or left. */ -int +static int find_free_point (char **maze, int *x, int *y, int xc, int yc, int xsize, int ysize) { /* we will randomly pick from this list, 1=up,2=down,3=right,4=left */ @@ -211,7 +168,7 @@ /* recursive routine which will fill every available space in the maze with walls*/ -void +static void fill_maze_full (char **maze, int x, int y, int xsize, int ysize) { int xc, yc; @@ -233,7 +190,7 @@ /* recursive routine which will fill much of the maze, but will leave some free spots (possibly large) toward the center.*/ -void +static void fill_maze_sparse (char **maze, int x, int y, int xsize, int ysize) { int xc, yc; @@ -253,3 +210,41 @@ fill_maze_sparse (maze, xc, yc, xsize, ysize); } +/* the outsize interface routine: accepts sizes, returns a char +** maze. option is a flag for either a sparse or a full maze. Sparse +mazes have sizable rooms. option = 1, full, 0, sparse.*/ +void +maze_gen (Layout maze, int option) +{ + maze->clear (); + maze->border (); + + /* find how many free wall spots there are */ + wall_free_size = 2 * (maze->w - 4) + 2 * (maze->h - 4); + + make_wall_free_list (maze->w, maze->h); + + /* return the empty maze */ + if (wall_free_size <= 0) + return; + + /* recursively generate the walls of the maze */ + /* first pop a random starting point */ + while (wall_free_size > 0) + { + int i, j; + + pop_wall_point (&i, &j); + + if (option) + fill_maze_full (maze, i, j, maze->w, maze->h); + else + fill_maze_sparse (maze, i, j, maze->w, maze->h); + } + + /* clean up our intermediate data structures. */ + + free (wall_x_list); + free (wall_y_list); +} +