Crossfire Server, Branch 1.12  R12190
Data Structures | Typedefs | Functions
maze_gen.c File Reference

General maze generator. More...

#include <stdlib.h>
#include <stdio.h>
#include <global.h>
#include <maze_gen.h>
#include <time.h>
Include dependency graph for maze_gen.c:

Go to the source code of this file.

Data Structures

struct  free_walls_struct
 Contains free walls in the map. More...

Typedefs

typedef struct free_walls_struct free_walls_struct
 Contains free walls in the map.

Functions

static void fill_maze_full (char **maze, int x, int y, int xsize, int ysize, free_walls_struct *free_walls)
 Recursive routine which will fill every available space in the maze with walls.
static void fill_maze_sparse (char **maze, int x, int y, int xsize, int ysize, free_walls_struct *free_walls)
 Recursive routine which will fill much of the maze, but will leave some free spots (possibly large) toward the center.
static int find_free_point (char **maze, int *x, int *y, int xc, int yc, int xsize, int ysize)
 Randomly look for a square adjacent to this one where we can place a new block without closing a path.
static void make_wall_free_list (int xsize, int ysize, free_walls_struct *free_walls)
 Inits the list of points where we can put walls on.
char ** maze_gen (int xsize, int ysize, int option)
 This function generates a random blocked maze with the property that there is only one path from one spot to any other, and there is always a path from one spot to any other.
static void pop_wall_point (int *x, int *y, free_walls_struct *free_walls)
 Randomly returns one of the elements from the wall point list.

Detailed Description

General maze generator.

Author:
peterm@langmuir.eecs.berkeley.edu

Definition in file maze_gen.c.


Typedef Documentation

Contains free walls in the map.


Function Documentation

static void fill_maze_full ( char **  maze,
int  x,
int  y,
int  xsize,
int  ysize,
free_walls_struct free_walls 
) [static]

Recursive routine which will fill every available space in the maze with walls.

Parameters:
mazemaze.
x
ywhere to put a wall.
xsize
ysizemaze size.
free_wallsfree walls list.

Definition at line 297 of file maze_gen.c.

References find_free_point(), pop_wall_point(), and free_walls_struct::wall_free_size.

Referenced by maze_gen().

Here is the call graph for this function:

Here is the caller graph for this function:

static void fill_maze_sparse ( char **  maze,
int  x,
int  y,
int  xsize,
int  ysize,
free_walls_struct free_walls 
) [static]

Recursive routine which will fill much of the maze, but will leave some free spots (possibly large) toward the center.

Parameters:
mazemaze.
x
ywhere to put a wall.
xsize
ysizemaze size.
free_wallsfree walls list.

Definition at line 329 of file maze_gen.c.

References find_free_point(), pop_wall_point(), and free_walls_struct::wall_free_size.

Referenced by maze_gen().

Here is the call graph for this function:

Here is the caller graph for this function:

static int find_free_point ( char **  maze,
int *  x,
int *  y,
int  xc,
int  yc,
int  xsize,
int  ysize 
) [static]

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.

Parameters:
mazecurrent maze.
[out]x
[out]ycoordinates of the found point.
xc
yccoordinates from where to look.
xsize
ysizemaze size.
Returns:
-1 if no free spot, 0 else.

Definition at line 191 of file maze_gen.c.

Referenced by fill_maze_full(), and fill_maze_sparse().

Here is the caller graph for this function:

static void make_wall_free_list ( int  xsize,
int  ysize,
free_walls_struct free_walls 
) [static]

Inits the list of points where we can put walls on.

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.

Parameters:
xsize
ysizesize of the map.
free_wallsstructure to initialise. free_walls_struct::wall_free_size must be initialised.

Definition at line 123 of file maze_gen.c.

References free_walls_struct::wall_free_size, free_walls_struct::wall_x_list, and free_walls_struct::wall_y_list.

Referenced by maze_gen().

Here is the caller graph for this function:

char** maze_gen ( int  xsize,
int  ysize,
int  option 
)

This function generates a random blocked maze with the property that there is only one path from one spot to any other, and there is always a path from one spot to any other.

Parameters:
xsize
ysizewanted map size.
optionif 0, maze will be sparse (sizeable rooms), else totally filled.
Returns:
a char** array with # and . for closed and open respectively. a char value of 0 represents a blank space: a '#' is a wall.

Definition at line 68 of file maze_gen.c.

References fill_maze_full(), fill_maze_sparse(), make_wall_free_list(), pop_wall_point(), free_walls_struct::wall_free_size, free_walls_struct::wall_x_list, and free_walls_struct::wall_y_list.

Referenced by layoutgen().

Here is the call graph for this function:

Here is the caller graph for this function:

static void pop_wall_point ( int *  x,
int *  y,
free_walls_struct free_walls 
) [static]

Randomly returns one of the elements from the wall point list.

Parameters:
[out]x
[out]ycoordinates of the point.
free_wallsfree walls list.

Definition at line 163 of file maze_gen.c.

References free_walls_struct::wall_free_size, free_walls_struct::wall_x_list, and free_walls_struct::wall_y_list.

Referenced by fill_maze_full(), fill_maze_sparse(), and maze_gen().

Here is the caller graph for this function: