Crossfire Server, Branch 1.12  R12190
Functions
random_map.c File Reference

random map generation main routines. More...

#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <global.h>
#include <maze_gen.h>
#include <room_gen.h>
#include <random_map.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.
void doorify_layout (char **maze, RMParms *RP)
 Puts doors at appropriate locations in a layout.
void dump_layout (char **layout, RMParms *RP)
 Dumps specified layout using printf().
mapstructgenerate_random_map (const char *OutFileName, RMParms *RP, char **use_layout)
 Main random map routine.
char ** layoutgen (RMParms *RP)
 This function builds the actual layout.
int make_wall (char **maze, int x, int y, int dir)
 Cuts the layout horizontally or vertically by a wall with a door.
void roomify_layout (char **maze, RMParms *RP)
 Take a layout and make some rooms in it.
char ** rotate_layout (char **maze, int rotation, RMParms *RP)
 Takes a map and rotates it.
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.
void write_map_parameters_to_string (RMParms *RP, char *buf, int bufsize)
 Creates a suitable message for exit from RP.
void write_parameters_to_string (char *buf, int xsize_n, int ysize_n, const char *wallstyle_n, const char *floorstyle_n, const char *monsterstyle_n, const char *treasurestyle_n, const char *layoutstyle_n, const char *decorstyle_n, const char *doorstyle_n, const char *exitstyle_n, const char *final_map_n, const char *exit_on_final_map_n, const char *this_map_n, int layoutoptions1_n, int layoutoptions2_n, int layoutoptions3_n, int symmetry_n, int dungeon_depth_n, int dungeon_level_n, int difficulty_n, int difficulty_given_n, int decoroptions_n, int orientation_n, int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase)
 Converts various parameters to string suitable for an exit message.

Detailed Description

random map generation main routines.

Todo:
explain process, layout signs (# C < > ) and such. Use constants/defines for 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 516 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 636 of file random_map.c.

References 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 53 of file random_map.c.

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

Referenced by generate_random_map(), layoutgen(), and main().

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 203 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_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 602 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 471 of file random_map.c.

References can_make_wall(), make_wall(), 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 403 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 327 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:

void write_map_parameters_to_string ( RMParms RP,
char *  buf,
int  bufsize 
)
void write_parameters_to_string ( char *  buf,
int  xsize_n,
int  ysize_n,
const char *  wallstyle_n,
const char *  floorstyle_n,
const char *  monsterstyle_n,
const char *  treasurestyle_n,
const char *  layoutstyle_n,
const char *  decorstyle_n,
const char *  doorstyle_n,
const char *  exitstyle_n,
const char *  final_map_n,
const char *  exit_on_final_map_n,
const char *  this_map_n,
int  layoutoptions1_n,
int  layoutoptions2_n,
int  layoutoptions3_n,
int  symmetry_n,
int  dungeon_depth_n,
int  dungeon_level_n,
int  difficulty_n,
int  difficulty_given_n,
int  decoroptions_n,
int  orientation_n,
int  origin_x_n,
int  origin_y_n,
int  random_seed_n,
int  treasureoptions_n,
float  difficulty_increase 
)

Converts various parameters to string suitable for an exit message.

Parameters:
bufbuffer to write to.
xsize_n
ysize_n
wallstyle_n
floorstyle_n
monsterstyle_n
treasurestyle_n
layoutstyle_n
decorstyle_n
doorstyle_n
exitstyle_n
final_map_n
exit_on_final_map_n
this_map_n
layoutoptions1_n
layoutoptions2_n
layoutoptions3_n
symmetry_n
dungeon_depth_n
dungeon_level_n
difficulty_n
difficulty_given_n
decoroptions_n
orientation_n
origin_x_n
origin_y_n
random_seed_n
treasureoptions_n
difficulty_increaserandom map parameters.
Todo:
remove this and replace with calls to write_map_parameters_to_string().

Definition at line 877 of file random_map.c.

References snprintf().

Referenced by place_special_exit().

Here is the call graph for this function:

Here is the caller graph for this function: