Atrinik Server 2.5
Functions | Variables
random_maps/style.c File Reference
#include <global.h>

Go to the source code of this file.

Functions

static int pointer_strcmp (const void *p1, const void *p2)
int load_dir (const char *dir, char ***namelist, int skip_dirs)
mapstructload_style_map (char *style_name)
mapstructfind_style (char *dirname, char *stylename, int difficulty)
objectpick_random_object (mapstruct *style)
void free_style_maps ()

Variables

mapstructstyles = NULL

Detailed Description

Those functions deal with style for random maps.

Definition in file style.c.


Function Documentation

mapstruct* find_style ( char *  dirname,
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 difficulty 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.

Definition at line 174 of file style.c.

void free_style_maps ( )

Frees cached style maps.

Definition at line 335 of file style.c.

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.

Parameters:
dirName of the directory to scan.
namelistArray of file names returned. It needs to be freed by the caller.
skip_dirsIf 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.
Returns:
-1 if directory is invalid, number of files otherwise.

Definition at line 60 of file style.c.

mapstruct* load_style_map ( char *  style_name)

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

Parameters:
style_nameMap to load.
Returns:
The loaded map.

Definition at line 115 of file style.c.

object* pick_random_object ( mapstruct style)

Picks a random object from a style map.

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

Definition at line 305 of file style.c.

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

Char comparison for sorting purposes.

Parameters:
p1First pointer to compare.
p2Second pointer to compare.
Returns:
Return of strcmp() on pointed strings.

Definition at line 37 of file style.c.


Variable Documentation

mapstruct* styles = NULL

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

Definition at line 109 of file style.c.