Atrinik Server  4.0
Functions | Variables
style.c File Reference
#include <global.h>
#include <toolkit/string.h>
#include <object.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 (const char *dirname, const char *stylename, int difficulty)
 
objectpick_random_object (mapstruct *style)
 
void free_style_maps (void)
 

Variables

mapstructstyles = NULL
 

Detailed Description

Those functions deal with style for random maps.

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

void free_style_maps ( void  )

Frees cached style maps.

Definition at line 312 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 71 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 124 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 286 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 43 of file style.c.

Variable Documentation

mapstruct* styles = NULL

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

Definition at line 115 of file style.c.