Crossfire Server, Trunk
style.c File Reference
#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"
+ 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)
 
void free_style_maps (void)
 
int load_dir (const char *dir, char ***namelist, int skip_dirs)
 
mapstructload_style_map (char *style_name)
 
objectpick_random_object (mapstruct *style)
 
static int pointer_strcmp (const void *p1, const void *p2)
 

Variables

mapstructstyles = NULL
 

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

◆ find_style()

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 180 of file style.c.

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().

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

◆ free_style_maps()

void free_style_maps ( void  )

Frees cached style maps.

Definition at line 312 of file style.c.

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

Referenced by cleanup().

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

◆ load_dir()

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 74 of file style.c.

References closedir(), dirent, give::name, NAME_MAX, opendir(), pointer_strcmp(), readdir(), strdup_local, and nlohmann::detail::void().

Referenced by find_style().

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

◆ load_style_map()

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, MAP_STYLE, mapfile_load(), mapdef::next, mapdef::path, styles, and Ice::tmp.

Referenced by find_style().

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

◆ pick_random_object()

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 289 of file style.c.

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().

+ Here is the caller graph for this function:

◆ pointer_strcmp()

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 43 of file style.c.

Referenced by load_dir().

+ Here is the caller graph for this function:

Variable Documentation

◆ styles

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(), free_style_maps(), and load_style_map().