Crossfire Server, Trunk
maze_gen.c File Reference
#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
 

Typedefs

typedef struct free_walls_struct free_walls_struct
 

Functions

static void fill_maze_full (char **maze, int x, int y, int xsize, int ysize, free_walls_struct *)
 
static void fill_maze_sparse (char **maze, int x, int y, int xsize, int ysize, free_walls_struct *)
 
static int find_free_point (char **maze, int *x, int *y, int xc, int yc, int xsize, int ysize)
 
static void make_wall_free_list (int xsize, int ysize, free_walls_struct *)
 
char ** maze_gen (int xsize, int ysize, int option, int _unused_layers)
 
static void pop_wall_point (int *x, int *y, free_walls_struct *)
 

Detailed Description

Typedef Documentation

◆ free_walls_struct

Contains free walls in the map.

Function Documentation

◆ fill_maze_full()

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 301 of file maze_gen.c.

References find_free_point(), pop_wall_point(), RANDOM, free_walls_struct::wall_free_size, diamondslots::x, and diamondslots::y.

Referenced by maze_gen().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fill_maze_sparse()

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 334 of file maze_gen.c.

References find_free_point(), pop_wall_point(), RANDOM, free_walls_struct::wall_free_size, diamondslots::x, and diamondslots::y.

Referenced by maze_gen().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_free_point()

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 192 of file maze_gen.c.

References disinfect::count, make_face_from_files::int, RANDOM, diamondslots::x, and diamondslots::y.

Referenced by fill_maze_full(), and fill_maze_sparse().

+ Here is the caller graph for this function:

◆ make_wall_free_list()

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 121 of file maze_gen.c.

References disinfect::count, 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:

◆ maze_gen()

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

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.
_unused_layersunused.
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 59 of file maze_gen.c.

References fill_maze_full(), fill_maze_sparse(), make_wall_free_list(), CFweardisguise::option, pop_wall_point(), nlohmann::detail::void(), 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:

◆ pop_wall_point()

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 npc_dialog::index, RANDOM, free_walls_struct::wall_free_size, free_walls_struct::wall_x_list, free_walls_struct::wall_y_list, diamondslots::x, and diamondslots::y.

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

+ Here is the caller graph for this function: