Crossfire Server, Branch 1.12  R12190
Functions | Variables
style.c File Reference

Those functions deal with style for random maps. More...

#include <global.h>
#include <random_map.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../include/autoconf.h"
Include dependency graph for style.c:

Go to the source code of this file.

Functions

mapstructfind_style (const char *dirname, const char *stylename, int difficulty)
 Loads and returns the map requested.
void free_style_maps (void)
 Frees cached style maps.
int load_dir (const char *dir, char ***namelist, int skip_dirs)
 This is our own version of scandir/select_regular_files/sort.
mapstructload_style_map (char *style_name)
 Loads specified map (or take it from cache list).
object * pick_random_object (mapstruct *style)
 Picks a random object from a style map.
static int pointer_strcmp (const void *p1, const void *p2)
 Char comparison for sorting purposes.

Variables

mapstructstyles = NULL
 Loaded styles maps cache, to avoid having to load all the time.

Detailed Description

Those functions deal with style for random maps.

Todo:
couldn't load_dir() be merged with a function in common library?

Definition in file style.c.


Function Documentation

mapstruct* find_style ( const char *  dirname,
const char *  stylename,
int  difficulty 
)

Loads and returns the map requested.

Dirname, for example, is "/styles/wallstyles", stylename, is, for example, "castle", difficulty is -1 when difficulty is irrelevant to the style. If dirname is given, but stylename isn't, and difficult is -1, it returns a random style map. Otherwise, it tries to match the difficulty given with a style file, named style_name_# where # is an integer

Parameters:
dirnamewhere to look.
stylenamestyle to use, can be NULL.
difficultystyle difficulty.
Returns:
style, or NULL if none suitable.
Todo:
better document.

Definition at line 177 of file style.c.

References Settings::datadir, find_style(), load_dir(), load_style_map(), S_ISDIR, settings, and snprintf().

Referenced by find_style(), make_map_floor(), make_map_walls(), place_chest(), place_exits(), place_fountain_with_specials(), place_monsters(), place_special_exit(), place_specials_in_map(), place_treasure(), put_decor(), and put_doors().

Here is the call graph for this function:

Here is the caller graph for this function:

void free_style_maps ( void  )

Frees cached style maps.

Definition at line 300 of file style.c.

References delete_map(), llevDebug, LOG(), and mapdef::next.

Referenced by cleanup().

Here is the call graph for this function:

Here is the caller graph for this function:

int load_dir ( const char *  dir,
char ***  namelist,
int  skip_dirs 
)

This is our own version of scandir/select_regular_files/sort.

To support having subdirectories in styles, we need to know if in fact the directory we read is a subdirectory. However, we can't get that through the normal dirent entry. So instead, we do our own where we do have the full directory path so can do stat calls to see if in fact it is a directory. dir is the name of the director to scan. namelist is the array of file names returned. IT needs to be freed by the caller. skip_dirs controls our behavioru - if nonzero, we don't skip any subdirectories - if zero, we store those away, since there are cases where we want to choose a random directory.

Parameters:
dirdirectory to list.
[out]namelistlist of files found.
skip_dirsif non 0, don't list directories.
Returns:
-1 if dir is invalid, number of files else.

Definition at line 83 of file style.c.

References closedir(), dirent::d_name, NAME_MAX, opendir(), pointer_strcmp(), readdir(), S_ISDIR, snprintf(), and strdup_local().

Referenced by find_style().

Here is the call graph for this function:

Here is the caller graph for this function:

mapstruct* load_style_map ( char *  style_name)

Loads specified map (or take it from cache list).

Parameters:
style_namemap to load.
Returns:
map.

Definition at line 131 of file style.c.

References first_map, load_original_map(), MAP_STYLE, mapdef::next, mapdef::path, and styles.

Referenced by find_style().

Here is the call graph for this function:

Here is the caller graph for this function:

object* pick_random_object ( mapstruct style)

Picks a random object from a style map.

Redone by MSW so it should be faster and not use static variables to generate tables.

Parameters:
stylemap to pick from.
Returns:
random object. Can be NULL.

Definition at line 275 of file style.c.

References GET_MAP_OB, MAP_HEIGHT, and MAP_WIDTH.

Referenced by make_map_floor(), make_map_walls(), place_chest(), place_exits(), place_fountain_with_specials(), place_monsters(), place_special_exit(), put_decor(), and put_doors().

Here is the caller graph for this function:

static int pointer_strcmp ( const void *  p1,
const void *  p2 
) [static]

Char comparison for sorting purposes.

Parameters:
p1
p2pointers to compare.
Returns:
return of strcmp() on pointed strings.

Definition at line 53 of file style.c.

Referenced by load_dir().

Here is the caller graph for this function:


Variable Documentation

mapstruct* styles = NULL

Loaded styles maps cache, to avoid having to load all the time.

Definition at line 122 of file style.c.

Referenced by command_style_map_info(), and load_style_map().