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

Go to the source code of this file.

Macros

#define CHANCE_FIX   (-1)
 

Functions

static void free_treasurestruct (treasure_t *t)
 
static void treasure_load_more (treasure_t **treasure, FILE *fp, const char *filename, uint64_t *linenum)
 
static void treasure_generate_internal (treasure_list_t *treasure_list, object *op, int difficulty, int flags, treasure_affinity_t *affinity, int artifact_chance, int tries, treasure_attrs_t *attrs)
 
static treasure_list_ttreasure_list_create (void)
 
static treasure_ttreasure_create (void)
 
static treasure_ttreasure_load_one (FILE *fp, const char *filename, uint64_t *linenum, treasure_affinity_t **affinity, int *artifact_chance)
 
static void treasure_load (void)
 
static void treasure_init_coins (void)
 
static void treasure_list_check (treasure_t *t, treasure_list_t *tl)
 
void treasure_init (void)
 
treasure_list_ttreasure_list_find (const char *name)
 
static int magic_from_difficulty (int difficulty)
 
static void treasure_set_magical_bonus (object *op, int magic)
 
static void treasure_set_magic (object *op, int difficulty, int max_magic, int fixed_magic, int chance_magic, int flags)
 
static void treasure_insert (object *op, object *creator, int flags)
 
static void treasure_apply_attrs (object *op, treasure_attrs_t *attrs)
 
static void treasure_set_quality (object *op, treasure_attrs_t *attrs)
 
static void treasure_set_material (object *op, treasure_attrs_t *attrs)
 
static void treasure_process_generated (object *op, object *creator, int difficulty, int flags, int artifact_chance, treasure_affinity_t *affinity, int max_magic, int fixed_magic, int chance_magic, treasure_attrs_t *attrs)
 
static void treasure_create_all (treasure_t *treasure, object *op, int difficulty, int flags, treasure_affinity_t *affinity, int artifact_chance, int tries, treasure_attrs_t *attrs)
 
static void treasure_create_one (treasure_list_t *treasure_list, object *op, int difficulty, int flags, treasure_affinity_t *affinity, int artifact_chance, int tries, treasure_attrs_t *attrs)
 
void treasure_generate (treasure_list_t *treasure_list, object *op, int difficulty, int flags)
 
objecttreasure_generate_single (treasure_list_t *treasure_list, int difficulty, int artifact_chance)
 
void free_all_treasures (void)
 
int get_environment_level (object *op)
 

Variables

const char *const coins [NUM_COINS+1]
 
static const int difftomagic_list [DIFFLEVELS][MAXMAGIC+1]
 
struct archetypecoins_arch [NUM_COINS]
 

Detailed Description

Everything concerning treasures.

Definition in file treasure.c.

Macro Definition Documentation

#define CHANCE_FIX   (-1)

Chance fix.

Definition at line 261 of file treasure.c.

Function Documentation

void free_all_treasures ( void  )

Free all treasure related memory.

Definition at line 1737 of file treasure.c.

static void free_treasurestruct ( treasure_t t)
static

Frees a treasure, including its yes, no and next items.

Parameters
tTreasure to free. Pointer is efree()d too, so becomes invalid.

Definition at line 1712 of file treasure.c.

int get_environment_level ( object op)

Gets the environment level for treasure generation for the given object.

Parameters
opObject to get environment level of.
Returns
The environment level, always at least 1.

Definition at line 1762 of file treasure.c.

static int magic_from_difficulty ( int  difficulty)
static

Calculate a magic value from the specified difficulty.

Parameters
difficulty
Returns
Magic value.

Definition at line 829 of file treasure.c.

static void treasure_apply_attrs ( object op,
treasure_attrs_t attrs 
)
static

Apply treasure attributes to the specified object.

Parameters
opGenerated treasure object.
attrsAttributes to apply.

Definition at line 1002 of file treasure.c.

static treasure_t* treasure_create ( void  )
static

Allocate and return a pointer to an empty treasure structure.

Returns
New structure, never NULL.

Definition at line 306 of file treasure.c.

static void treasure_create_all ( treasure_t treasure,
object op,
int  difficulty,
int  flags,
treasure_affinity_t *  affinity,
int  artifact_chance,
int  tries,
treasure_attrs_t attrs 
)
static

Creates all the treasures.

Parameters
treasureWhat to generate.
opFor whom to generate the treasure.
difficultyLevel difficulty.
flagsCombination of Treasure generation flags values.
affinityTreasure affinity.
artifact_chanceArtifact chance.
triesUsed to avoid infinite recursion.
attrsTreasure attributes.

Definition at line 1313 of file treasure.c.

static void treasure_create_one ( treasure_list_t treasure_list,
object op,
int  difficulty,
int  flags,
treasure_affinity_t *  affinity,
int  artifact_chance,
int  tries,
treasure_attrs_t attrs 
)
static

Creates one treasure from the list.

Parameters
treasure_listWhat to generate.
opFor whom to generate the treasure.
difficultyLevel difficulty.
flagsCombination of Treasure generation flags values.
affinityTreasure affinity.
artifact_chanceArtifact chance.
triesUsed to avoid infinite recursion.
attrsTreasure attributes.
Todo:
Get rid of the goto.

Definition at line 1416 of file treasure.c.

void treasure_generate ( treasure_list_t treasure_list,
object op,
int  difficulty,
int  flags 
)

Generate treasure inside the specified object based on the given treasure list.

Parameters
treasure_listWhat to generate.
opFor whom to generate the treasure.
difficultyLevel difficulty.
flagsCombination of Treasure generation flags values.

Definition at line 1641 of file treasure.c.

static void treasure_generate_internal ( treasure_list_t treasure_list,
object op,
int  difficulty,
int  flags,
treasure_affinity_t *  affinity,
int  artifact_chance,
int  tries,
treasure_attrs_t attrs 
)
static

Generate treasure inside the specified object based on the given treasure list.

Parameters
treasure_listWhat to generate.
opFor whom to generate the treasure.
difficultyLevel difficulty.
flagsCombination of Treasure generation flags values.
affinityTreasure affinity.
artifact_chanceArtifact chance.
triesTo avoid infinite recursion.
attrsTreasure attributes.

Definition at line 1579 of file treasure.c.

object* treasure_generate_single ( treasure_list_t treasure_list,
int  difficulty,
int  artifact_chance 
)

Generate a single object from the specified treasure list.

Parameters
treasure_listTreasure list to generate from.
difficultyTreasure difficulty.
artifact_chanceChance to generate an artifact.
Returns
Generated treasure. Can be NULL if no suitable treasure was found.

Definition at line 1672 of file treasure.c.

void treasure_init ( void  )

Initialize the treasure sub-system.

Definition at line 754 of file treasure.c.

static void treasure_init_coins ( void  )
static

Create money table, setting up pointers to the archetypes.

This is done for faster access to the coin archetypes.

Definition at line 690 of file treasure.c.

static void treasure_insert ( object op,
object creator,
int  flags 
)
static

Inserts generated treasure where it should go.

Parameters
opTreasure just generated.
creatorFor which object the treasure is being generated.
flagsCombination of Treasure generation flags values.

Definition at line 979 of file treasure.c.

static void treasure_list_check ( treasure_t t,
treasure_list_t tl 
)
static

Checks if a treasure if valid. Will also check its yes and no options.

Parameters
tTreasure to check.
tlNeeded only so that the treasure name can be printed out.

Definition at line 710 of file treasure.c.

static treasure_list_t* treasure_list_create ( void  )
static

Allocate and return a pointer to an empty treasure list structure.

Returns
New structure, never NULL.

Definition at line 288 of file treasure.c.

treasure_list_t* treasure_list_find ( const char *  name)

Searches for the given treasurelist in the globally linked list of treasure lists which has been built by treasure_load().

Parameters
nameTreasure list name to search for.

Definition at line 789 of file treasure.c.

static void treasure_load ( void  )
static

Opens the collected treasures and reads all treasure declarations from it.

Each treasure is parsed with the help of treasure_load_one().

Definition at line 593 of file treasure.c.

static void treasure_load_more ( treasure_t **  treasure,
FILE *  fp,
const char *  filename,
uint64_t *  linenum 
)
static

Load more/yes/no section of a treasure list.

Parameters
[out]treasureWhere to load teasure into.
filenameFilename.
fpFile to read from.
[out]linenumLine number.

Definition at line 557 of file treasure.c.

static treasure_t* treasure_load_one ( FILE *  fp,
const char *  filename,
uint64_t *  linenum,
treasure_affinity_t **  affinity,
int *  artifact_chance 
)
static

Reads one treasure from the file, including the 'yes', 'no' and 'more' options.

Parameters
fpFile to read from.
filenameFilename.
[out]linenumLine number.
[out]affinityTreasure affinity.
[out]artifact_chanceArtifact chance.
Returns
Read structure, never NULL.

Definition at line 343 of file treasure.c.

static void treasure_process_generated ( object op,
object creator,
int  difficulty,
int  flags,
int  artifact_chance,
treasure_affinity_t *  affinity,
int  max_magic,
int  fixed_magic,
int  chance_magic,
treasure_attrs_t attrs 
)
static

This is called after an item is generated, in order to set it up right.

This produces magical bonuses, puts spells into scrolls/books/wands, makes it unidentified, generates artifacts, etc.

Parameters
opGenerated treasure object.
creatorFor who op was created. Can be NULL.
difficultyDifficulty level.
flagsCombination of Treasure generation flags.
artifact_chanceArtifact chance.
affinityTreasure affinity.
max_magicMaximum magic for the item.
fixed_magicFixed magic value.
chance_magicChance of magic.
attrsTreasure attributes to apply.

Definition at line 1194 of file treasure.c.

static void treasure_set_magic ( object op,
int  difficulty,
int  max_magic,
int  fixed_magic,
int  chance_magic,
int  flags 
)
static

Sets a random magical bonus in the given object based upon the given difficulty, and the given max possible bonus.

Item will be cursed if magic is negative.

Parameters
opThe object.
difficultyDifficulty we want the item to be.
max_magicWhat should be the maximum magic of the item.
fixed_magicFixed value of magic for the object.
chance_magicChance to get a magic bonus.
flagsCombination of Treasure generation flags flags.

Definition at line 937 of file treasure.c.

static void treasure_set_magical_bonus ( object op,
int  magic 
)
static

Sets magical bonus in an object, and recalculates the effect on the armour variable, and the effect on speed of armour.

This function doesn't work properly, should add use of archetypes to make it truly absolute.

Parameters
opObject we're modifying.
magicMagic modifier.

Definition at line 869 of file treasure.c.

static void treasure_set_material ( object op,
treasure_attrs_t attrs 
)
static

Set treasure object's object::material_real.

Parameters
opObject to set material_real for.
attrsTreasure attributes.

Definition at line 1060 of file treasure.c.

static void treasure_set_quality ( object op,
treasure_attrs_t attrs 
)
static

Set treasure object's object::item_quality.

Parameters
opObject to set item_quality for.
attrsTreasure attributes.

Definition at line 1029 of file treasure.c.

Variable Documentation

const char* const coins[NUM_COINS+1]
Initial value:
= {
"ambercoin",
"mithrilcoin",
"jadecoin",
"goldcoin",
"silvercoin",
"coppercoin",
NULL
}

All the coin arches.

Definition at line 38 of file treasure.c.

struct archetype* coins_arch[NUM_COINS]

Pointers to coin archetypes.

Definition at line 258 of file treasure.c.

const int difftomagic_list[DIFFLEVELS][MAXMAGIC+1]
static

Difficulty to magic chance list.

Definition at line 51 of file treasure.c.