Crossfire Server, Trunk  R20513
Functions
random_map.c File Reference

Routines for random map generation. More...

#include "global.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "maze_gen.h"
#include "random_map.h"
#include "room_gen.h"
#include "rproto.h"
#include "sproto.h"
Include dependency graph for random_map.c:

Go to the source code of this file.

Functions

int can_make_wall (char **maze, int dx, int dy, int dir, RMParms *RP)
 Checks the layout to see if we can stick a horizontal (dir = 0) wall (or vertical, dir == 1) here which ends up on other walls sensibly. More...
 
void doorify_layout (char **maze, RMParms *RP)
 Puts doors at appropriate locations in a layout. More...
 
void dump_layout (char **layout, RMParms *RP)
 Dumps specified layout using printf(). More...
 
mapstructgenerate_random_map (const char *OutFileName, RMParms *RP, char **use_layout)
 Main random map routine. More...
 
char ** layoutgen (RMParms *RP)
 This function builds the actual layout. More...
 
int make_wall (char **maze, int x, int y, int dir)
 Cuts the layout horizontally or vertically by a wall with a door. More...
 
void roomify_layout (char **maze, RMParms *RP)
 Take a layout and make some rooms in it. More...
 
char ** rotate_layout (char **maze, int rotation, RMParms *RP)
 Takes a map and rotates it. More...
 
char ** symmetrize_layout (char **maze, int sym, RMParms *RP)
 Takes a map and makes it symmetric: adjusts Xsize and Ysize to produce a symmetric map. More...
 
StringBufferwrite_map_parameters_to_string (const RMParms *RP)
 Creates a suitable message for exit from RP. More...
 

Detailed Description

Routines for random map generation.

Todo:
Explain process, layout signs (#, C, <, >) and such. Use constants for common spot types.

Definition in file random_map.c.

Function Documentation

int can_make_wall ( char **  maze,
int  dx,
int  dy,
int  dir,
RMParms RP 
)

Checks the layout to see if we can stick a horizontal (dir = 0) wall (or vertical, dir == 1) here which ends up on other walls sensibly.

Parameters
mazelayout.
dx
dycoordinates to check
dirdirection:
  • 0: horizontally.
  • 1: vertically.
RPrandom map parameters.
Returns
-1 if wall can't be made, possibly wall length else.

Definition at line 544 of file random_map.c.

References surround_flag2(), RMParms::Xsize, and RMParms::Ysize.

Referenced by roomify_layout().

Here is the call graph for this function:

Here is the caller graph for this function:

void doorify_layout ( char **  maze,
RMParms RP 
)

Puts doors at appropriate locations in a layout.

Parameters
mazelayout.
RPmap parameters.

Definition at line 683 of file random_map.c.

References RANDOM, surround_flag(), RMParms::Xsize, and RMParms::Ysize.

Referenced by layoutgen().

Here is the call graph for this function:

Here is the caller graph for this function:

void dump_layout ( char **  layout,
RMParms RP 
)

Dumps specified layout using printf().

Parameters
layoutlayout to dump.
RPlayout parameters.

Definition at line 44 of file random_map.c.

References RMParms::Xsize, and RMParms::Ysize.

Referenced by generate_random_map(), and layoutgen().

Here is the caller graph for this function:

mapstruct* generate_random_map ( const char *  OutFileName,
RMParms RP,
char **  use_layout 
)
char** layoutgen ( RMParms RP)

This function builds the actual layout.

Selects the layout based on parameters and gives it whatever arguments it needs.

Parameters
RPrandom map parameters.
Returns
layout, must be free()d be caller.
Todo:
use an array for name/style mapping. Refactor to call only one function for each (will make it easier to override later on).

Definition at line 208 of file random_map.c.

References doorify_layout(), dump_layout(), expand2x(), RMParms::expand2x, RMParms::layoutoptions1, RMParms::layoutoptions2, RMParms::layoutstyle, make_snake_layout(), make_square_spiral_layout(), map_gen_onion(), map_gen_spiral(), RMParms::map_layout_style, maze_gen(), MAZE_LAYOUT, MIN_RANDOM_MAP_SIZE, NO_SYM, NROFLAYOUTS, ONION_LAYOUT, OPT_WALLS_ONLY, RANDOM, RANDOM_SYM, ROGUELIKE_LAYOUT, roguelike_layout_gen(), roomify_layout(), SNAKE_LAYOUT, SPIRAL_LAYOUT, SQUARE_SPIRAL_LAYOUT, symmetrize_layout(), RMParms::symmetry, RMParms::symmetry_used, X_SYM, RMParms::Xsize, XY_SYM, Y_SYM, and RMParms::Ysize.

Referenced by generate_random_map().

Here is the call graph for this function:

Here is the caller graph for this function:

int make_wall ( char **  maze,
int  x,
int  y,
int  dir 
)

Cuts the layout horizontally or vertically by a wall with a door.

Parameters
mazelayout.
x
ywhere to put the door.
dirwall direction:
  • 0: horizontally.
  • 1: vertically.
Returns
0

Definition at line 644 of file random_map.c.

Referenced by make_square_spiral_layout(), and roomify_layout().

Here is the caller graph for this function:

void roomify_layout ( char **  maze,
RMParms RP 
)

Take a layout and make some rooms in it.

Works best on onions.

Parameters
mazelayout to alter.
RPmap parameters.

Definition at line 496 of file random_map.c.

References can_make_wall(), make_wall(), RANDOM, RMParms::Xsize, and RMParms::Ysize.

Referenced by layoutgen().

Here is the call graph for this function:

Here is the caller graph for this function:

char** rotate_layout ( char **  maze,
int  rotation,
RMParms RP 
)

Takes a map and rotates it.

This completes the onion layouts, making them possibly centered on any wall. It'll modify Xsize and Ysize if they're swapped.

Parameters
mazelayout to rotate, will be free()d by this function.
rotationhow to rotate:
  • 0: don't do anything.
  • 1: rotate 90 deg clockwise.
  • 2: rotate 180 deg.
  • 3: rotate 90 deg counter-clockwise.
RPrandom map parameters.
Returns
new layout, must be free()d be caller. NULL if invalid rotation.

Definition at line 424 of file random_map.c.

References RMParms::Xsize, and RMParms::Ysize.

Referenced by generate_random_map().

Here is the caller graph for this function:

char** symmetrize_layout ( char **  maze,
int  sym,
RMParms RP 
)

Takes a map and makes it symmetric: adjusts Xsize and Ysize to produce a symmetric map.

Parameters
mazelayout to symmetrize. Will be free()d by this function.
symhow to make symetric, a Random map symetry value.
RPmap parameters.
Returns
new layout, must be free()d by caller.

Definition at line 343 of file random_map.c.

References connect_spirals(), RMParms::map_layout_style, NO_SYM, ROGUELIKE_LAYOUT, SPIRAL_LAYOUT, RMParms::symmetry_used, X_SYM, RMParms::Xsize, XY_SYM, Y_SYM, and RMParms::Ysize.

Referenced by layoutgen().

Here is the call graph for this function:

Here is the caller graph for this function:

StringBuffer* write_map_parameters_to_string ( const RMParms RP)