Crossfire Server, Trunk
|
#include "global.h"
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../include/autoconf.h"
#include "random_map.h"
Go to the source code of this file.
Functions | |
mapstruct * | find_style (const char *dirname, const char *stylename, int difficulty) |
void | free_style_maps (void) |
int | load_dir (const char *dir, char ***namelist, int skip_dirs) |
mapstruct * | load_style_map (char *style_name) |
object * | pick_random_object (mapstruct *style) |
static int | pointer_strcmp (const void *p1, const void *p2) |
Variables | |
mapstruct * | styles = NULL |
Those functions deal with style for random maps.
Definition in file style.cpp.
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
dirname | where to look. |
stylename | style to use, can be NULL. |
difficulty | style difficulty. |
Definition at line 180 of file style.cpp.
References Settings::datadir, load_dir(), load_style_map(), item::q, RANDOM, settings, and strlcpy().
Referenced by make_map_floor(), make_map_walls(), place_chest(), place_exits(), place_fountain_with_specials(), place_monsters(), place_special_exit(), place_specials_in_map(), put_decor(), and put_doors().
void free_style_maps | ( | void | ) |
Frees cached style maps.
Definition at line 312 of file style.cpp.
References delete_map(), llevDebug, LOG(), give::next, mapstruct::next, and styles.
Referenced by cleanup().
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.
dir | directory to list. | |
[out] | namelist | list of files found. |
skip_dirs | if non 0, don't list directories. |
Definition at line 74 of file style.cpp.
References closedir(), give::name, opendir(), pointer_strcmp(), readdir(), strdup_local, and nlohmann::detail::void().
Referenced by find_style().
mapstruct* load_style_map | ( | char * | style_name | ) |
Loads specified map (or take it from cache list).
style_name | map to load. |
Definition at line 131 of file style.cpp.
References first_map, MAP_STYLE, mapfile_load(), mapstruct::next, mapstruct::path, styles, and Ice::tmp.
Referenced by find_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.
style | map to pick from. |
Definition at line 289 of file style.cpp.
References GET_MAP_OB, HEAD, MAP_HEIGHT, MAP_WIDTH, RANDOM, CFInsulter::style, diamondslots::x, and diamondslots::y.
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().
|
static |
Char comparison for sorting purposes.
p1 | |
p2 | pointers to compare. |
Definition at line 43 of file style.cpp.
Referenced by load_dir().
mapstruct* styles = NULL |
Loaded styles maps cache, to avoid having to load all the time.
Definition at line 122 of file style.cpp.
Referenced by command_style_map_info(), free_style_maps(), and load_style_map().