Atrinik Server  4.0
Functions | Variables
arch.c File Reference
#include <global.h>
#include <arch.h>
#include <artifact.h>
#include <loader.h>
#include <toolkit/string.h>

Go to the source code of this file.

Functions

static void arch_free (archetype_t *at)
 
static void arch_load (void)
 
void arch_init (void)
 
void arch_deinit (void)
 
static archetype_tarch_new (void)
 
static void arch_pass_first (FILE *fp)
 
static void arch_pass_second (FILE *fp, const char *filename)
 
void arch_add (archetype_t *at)
 
archetype_tarch_find (const char *name)
 
objectarch_get (const char *name)
 
objectarch_to_object (archetype_t *at)
 
archetype_tarch_clone (archetype_t *at)
 

Variables

archetype_tarch_table = NULL
 
archetype_tarches [ARCH_MAX] = {NULL}
 
bool arch_in_init = false
 
static objectclone_op
 
static const char *const arch_names [ARCH_MAX]
 

Detailed Description

Arch related functions.

Definition in file arch.c.

Function Documentation

void arch_add ( archetype_t at)

Adds an archetype to the hashtable.

Must be called within archetypes initialization time-frame (arch_in_init == true).

Parameters
atArchetype to add.

Definition at line 390 of file arch.c.

archetype_t* arch_clone ( archetype_t at)

Clones the specified archetype.

Parameters
atThe archetype to clone.
Returns
New archetype.
Warning
The archetype's name is not cloned.

Definition at line 464 of file arch.c.

void arch_deinit ( void  )

Frees all memory allocated to archetypes.

After calling this, it's possible to call arch_init() again to reload data.

Definition at line 104 of file arch.c.

archetype_t* arch_find ( const char *  name)

Finds, using the hashtable, which archetype matches the given name.

Parameters
nameArchetype name to find. Can be NULL.
Returns
Pointer to the found archetype, otherwise NULL.

Definition at line 407 of file arch.c.

static void arch_free ( archetype_t at)
static

Frees the specified archetype structure.

Parameters
atArchetype to free.

Definition at line 137 of file arch.c.

object* arch_get ( const char *  name)

Finds which archetype matches the given name, and returns a new object containing a copy of the archetype.

If the archetype cannot be found, object_create_singularity() is used to create a singularity. Thus the return value is never NULL.

Parameters
nameArchetype name. Can be NULL.
Returns
Object of specified archetype, or a singularity. Will never be NULL.

Definition at line 430 of file arch.c.

void arch_init ( void  )

Initializes the archetypes hash table (read from file).

arches are also initialized.

Definition at line 78 of file arch.c.

static void arch_load ( void  )
static

Loads all archetypes, artifacts and treasures.

Reads and parses the archetype file using arch_pass_first(), then initializes the artifacts and treasures. Afterwards, calls arch_pass_second(), which does the second pass initialization of archetypes and artifacts.

Definition at line 354 of file arch.c.

static archetype_t* arch_new ( void  )
static

Allocates, initializes and returns the pointer to an archetype structure.

Returns
New archetype structure, never NULL.

Definition at line 122 of file arch.c.

static void arch_pass_first ( FILE *  fp)
static

Reads/parses the archetype-file, and copies into a linked list of archetype structures.

Parameters
fpOpened file descriptor which will be used to read the archetypes.

Definition at line 161 of file arch.c.

static void arch_pass_second ( FILE *  fp,
const char *  filename 
)
static

Reads the archetype file once more, and links all pointers between archetypes and treasure lists. Must be called after first_arch_pass().

Parameters
fpFile from which to read. Won't be rewinded.
filenameFilename fp is being read from.

Definition at line 211 of file arch.c.

object* arch_to_object ( archetype_t at)

Creates and returns a new object which is a copy of the given archetype.

Parameters
atArchetype from which to get an object.
Returns
New object, never NULL.

Definition at line 446 of file arch.c.

Variable Documentation

bool arch_in_init = false

True if doing arch initialization.

Definition at line 50 of file arch.c.

const char* const arch_names[ARCH_MAX]
static
Initial value:
= {
"waypoint", "empty_archetype", "base_info", "level_up", "ring_normal",
"ring_generic", "amulet_normal", "amulet_generic", "inv_group_next",
"inv_group_prev", "inv_start", "inv_end"
}

Used to initialize the arches array.

Definition at line 63 of file arch.c.

archetype_t* arch_table = NULL

The archetype hash table.

Definition at line 41 of file arch.c.

archetype_t* arches[ARCH_MAX] = {NULL}

Pointers to cached archetypes. Initialized from arch_names.

Definition at line 45 of file arch.c.

object* clone_op
static

Used to create archetype's clone object in arch_new(), to avoid a lot of calls to object_get().

Is allocated - and gets destroyed - in arch_init().

Definition at line 58 of file arch.c.