Crossfire Server, Trunk
random_map.c File Reference
#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)
 
void doorify_layout (char **maze, RMParms *RP)
 
void dump_layout (char **layout, RMParms *RP)
 
mapstructgenerate_random_map (const char *OutFileName, RMParms *RP, char **use_layout, sstring reset_group)
 
char ** layoutgen (RMParms *RP)
 
int make_wall (char **maze, int x, int y, int dir)
 
void roomify_layout (char **maze, RMParms *RP)
 
char ** rotate_layout (char **maze, int rotation, RMParms *RP)
 
char ** symmetrize_layout (char **maze, int sym, RMParms *RP)
 
StringBufferwrite_map_parameters_to_string (const RMParms *RP)
 

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

◆ can_make_wall()

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

References surround_flag2(), diamondslots::x, RMParms::Xsize, diamondslots::y, and RMParms::Ysize.

Referenced by roomify_layout().

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

◆ doorify_layout()

void doorify_layout ( char **  maze,
RMParms RP 
)

Puts doors at appropriate locations in a layout.

Parameters
mazelayout.
RPmap parameters.

Definition at line 698 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:

◆ dump_layout()

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:

◆ generate_random_map()

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

Main random map routine. Generates a random map based on specified parameters.

Parameters
OutFileNamethe path the map should have.
RPparameters for generation.
use_layoutif not NULL, this should be a suitable layout.
reset_groupif not NULL, the reset group this map will be part of, else the path will be used.
Returns
Crossfire map, which should be free()d by caller.

Definition at line 76 of file random_map.c.

References add_string(), apply_auto_fix(), buf, calculate_difficulty(), change_map_light(), RMParms::darkness, RMParms::decoroptions, RMParms::decorstyle, RMParms::difficulty, mapdef::difficulty, RMParms::difficulty_given, RMParms::difficulty_increase, RMParms::doorstyle, dump_layout(), RMParms::dungeon_level, RMParms::exitstyle, RMParms::expand2x, RMParms::floorstyle, make_face_from_files::int, mapdef::last_reset_time, layoutgen(), make_map_floor(), make_map_walls(), RMParms::map_layout_style, MIN_RANDOM_MAP_SIZE, RMParms::monsterstyle, mapdef::msg, RMParms::orientation, mapdef::outdoor, mapdef::path, place_exits(), place_monsters(), place_specials_in_map(), place_treasure(), put_decor(), put_doors(), RANDOM, RMParms::random_seed, RMParms::region, mapdef::region, mapdef::reset_group, ROGUELIKE_LAYOUT, rotate_layout(), safe_strncpy, seconds(), set_darkness_map(), SRANDOM, stringbuffer_finish(), RMParms::treasureoptions, RMParms::treasurestyle, unblock_exits(), RMParms::wallstyle, write_map_parameters_to_string(), RMParms::Xsize, and RMParms::Ysize.

Referenced by cfapi_generate_random_map(), enter_random_map(), enter_random_template_map(), and generate_map().

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

◆ layoutgen()

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 226 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:

◆ make_wall()

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

References diamondslots::x, and diamondslots::y.

Referenced by make_square_spiral_layout(), and roomify_layout().

+ Here is the caller graph for this function:

◆ roomify_layout()

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 511 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:

◆ rotate_layout()

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

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

Referenced by generate_random_map().

+ Here is the caller graph for this function:

◆ symmetrize_layout()

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 361 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:

◆ write_map_parameters_to_string()