Crossfire Server, Trunk  R20513
Macros | Functions | Variables
artifact.c File Reference

Everything concerning artifacts. More...

#include "global.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "loader.h"
Include dependency graph for artifact.c:

Go to the source code of this file.

Macros

#define ARTIFACT_TRIES   2
 Give 1 re-roll attempt per artifact. More...
 

Functions

void add_abilities (object *op, const object *change)
 Used in artifact generation. More...
 
unsigned artifact_get_face (const artifact *art)
 Get a suitable face number for representing an artifact. More...
 
static void compute_face_name (char *buf, size_t size, const char *name, const char *suffix)
 Compute the name of a face with a suffix, taking into account names like '.123' or '.1xx'. More...
 
void dump_artifacts (void)
 For debugging purposes. More...
 
const artifactfind_artifact (const object *op, const char *name)
 Searches and returns a specific artifact, NULL if not found. More...
 
const artifactlistfind_artifactlist (int type)
 Searches the artifact lists and returns one that has the same type of objects on it. More...
 
static artifactlistfind_artifactlist_internal (int type)
 Searches the artifact lists and returns one that has the same type of objects on it, non-const version of find_artifactlist() used only during artifact loading. More...
 
void free_all_artifacts (void)
 Free all artifact-related information. More...
 
static void free_artifact (artifact *at)
 Totally frees an artifact, its next items, and such. More...
 
static void free_artifactlist (artifactlist *al)
 Free specified list and its items. More...
 
static void free_charlinks (linked_char *lc)
 Frees a link structure and its next items. More...
 
void generate_artifact (object *op, int difficulty)
 Decides randomly which artifact the object should be turned into. More...
 
static artifactget_empty_artifact (void)
 Allocate and return the pointer to an empty artifact structure. More...
 
static artifactlistget_empty_artifactlist (void)
 Allocate and return the pointer to an empty artifactlist structure. More...
 
void give_artifact_abilities (object *op, const object *artifact)
 Fixes the given object, giving it the abilities and titles it should have due to the second artifact-template. More...
 
void init_artifacts (void)
 Builds up the lists of artifacts from the file in the libdir. More...
 
int legal_artifact_combination (const object *op, const artifact *art)
 Checks if op can be combined with art. More...
 

Variables

int artifact_init
 1 if doing archetypes initialization More...
 

Detailed Description

Everything concerning artifacts.

See also
Treasure lists

Definition in file artifact.c.

Macro Definition Documentation

#define ARTIFACT_TRIES   2

Give 1 re-roll attempt per artifact.

Definition at line 146 of file artifact.c.

Referenced by generate_artifact().

Function Documentation

void add_abilities ( object op,
const object change 
)

Used in artifact generation.

The bonuses of the first object is modified by the bonuses of the second object.

Definition at line 284 of file artifact.c.

References liv::ac, add_refcount(), obj::anim_speed, obj::animation_id, animations, obj::arch, arch_to_object(), obj::attacktype, blank_face, change_attr_value(), CLEAR_FLAG, compute_face_name(), liv::dam, liv::exp, obj::face, find_face(), FLAG_ALIVE, FLAG_ANIMATE, FLAG_BLIND, FLAG_CLIENT_ANIM_RANDOM, FLAG_CURSED, FLAG_DAMNED, FLAG_LIFESAVE, FLAG_MAKE_INVIS, FLAG_NO_SAVE, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_SEE_IN_DARK, FLAG_STAND_STILL, FLAG_STEALTH, FLAG_XRAYS, liv::food, FOR_INV_FINISH, FOR_INV_PREPARE, free_string(), obj::gen_sp_armour, get_attr_value(), liv::hp, obj::inv, obj::item_power, obj::last_sp, obj::level, llevDebug, LOG(), liv::luck, obj::magic, obj::material, obj::materialname, MAX_BUF, liv::maxhp, liv::maxsp, obj::move_type, obj::msg, new_face_struct::name, animations_struct::name, new_faces, obj::nrof, NROFATTACKS, NUM_STATS, new_face_struct::number, object_copy(), object_free_drop_inventory(), object_get_value(), object_insert_in_ob(), object_new(), object_remove(), object_set_msg(), object_set_value(), object_update_speed(), obj::other_arch, obj::path_attuned, obj::path_denied, obj::path_repelled, POTION, QUERY_FLAG, obj::race, RANDOM, obj::resist, ROD, set_abs_magic(), SET_FLAG, obj::slaying, snprintf, liv::sp, obj::speed, obj::stats, try_find_animation(), obj::type, obj::value, liv::wc, and obj::weight.

Referenced by artifact_describe(), and give_artifact_abilities().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned artifact_get_face ( const artifact art)

Get a suitable face number for representing an artifact.

Parameters
artwhat to get the face of.
Returns
face, -1 as unsigned if none could be found.

Definition at line 692 of file artifact.c.

References artifactstruct::allowed, artifactstruct::allowed_size, blank_face, archt::clone, obj::face, find_archetype(), first_archetype, artifactstruct::item, linked_char::name, archt::name, linked_char::next, archt::next, new_face_struct::number, and obj::type.

Here is the call graph for this function:

static void compute_face_name ( char *  buf,
size_t  size,
const char *  name,
const char *  suffix 
)
static

Compute the name of a face with a suffix, taking into account names like '.123' or '.1xx'.

Parameters
bufwhere to put the resulting name.
sizelength of buf.
namebase face name.
suffixsuffix to add to the face name.

Definition at line 260 of file artifact.c.

References snprintf.

Referenced by add_abilities().

Here is the caller graph for this function:

void dump_artifacts ( void  )
const artifact* find_artifact ( const object op,
const char *  name 
)

Searches and returns a specific artifact, NULL if not found.

Parameters
opitem to search for.
nameartifact name.
Returns
matching artifact, NULL if none matched.

Definition at line 640 of file artifact.c.

References find_artifactlist_internal(), find_string(), artifactstruct::item, artifactliststruct::items, legal_artifact_combination(), obj::name, artifactstruct::next, and obj::type.

Referenced by add_one_item(), and save_object().

Here is the call graph for this function:

Here is the caller graph for this function:

const artifactlist* find_artifactlist ( int  type)

Searches the artifact lists and returns one that has the same type of objects on it.

Returns
NULL if no suitable list found.

Definition at line 630 of file artifact.c.

References find_artifactlist_internal().

Referenced by artifact_msg(), cast_create_missile(), command_create(), generate_artifact(), locate_recipe_artifact(), and CREFormulaePanel::setItem().

Here is the call graph for this function:

Here is the caller graph for this function:

static artifactlist* find_artifactlist_internal ( int  type)
static

Searches the artifact lists and returns one that has the same type of objects on it, non-const version of find_artifactlist() used only during artifact loading.

Returns
NULL if no suitable list found.

Definition at line 500 of file artifact.c.

References first_artifactlist, artifactliststruct::next, and artifactliststruct::type.

Referenced by find_artifact(), find_artifactlist(), and init_artifacts().

Here is the caller graph for this function:

void free_all_artifacts ( void  )

Free all artifact-related information.

Definition at line 140 of file artifact.c.

References first_artifactlist, and free_artifactlist().

Referenced by cleanup().

Here is the call graph for this function:

Here is the caller graph for this function:

static void free_artifact ( artifact at)
static

Totally frees an artifact, its next items, and such.

Parameters
atartifact to free. Pointer is free()d too, so becomes invalid.
Note
Objects at->item are malloc()ed by init_artifacts(), so can simply be free()d.

But artifact inventory is a 'real' object, that may be created for 'old' objects. So should be destroyed through object_free_drop_inventory(). Note that it isn't on the usual item list, so some tweaking is required.

Definition at line 95 of file artifact.c.

References artifactstruct::allowed, free_charlinks(), free_string(), artifactstruct::item, obj::msg, obj::name, obj::name_pl, artifactstruct::next, obj::next, object_free_key_values(), and obj::title.

Referenced by free_artifactlist().

Here is the call graph for this function:

Here is the caller graph for this function:

static void free_artifactlist ( artifactlist al)
static

Free specified list and its items.

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

Definition at line 125 of file artifact.c.

References free_artifact(), artifactliststruct::items, and artifactliststruct::next.

Referenced by free_all_artifacts().

Here is the call graph for this function:

Here is the caller graph for this function:

static void free_charlinks ( linked_char lc)
static

Frees a link structure and its next items.

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

Definition at line 77 of file artifact.c.

References linked_char::next.

Referenced by free_artifact().

Here is the caller graph for this function:

void generate_artifact ( object op,
int  difficulty 
)

Decides randomly which artifact the object should be turned into.

Makes sure that the item can become that artifact (means magic, difficulty, and Allowed fields properly). Then calls give_artifact_abilities in order to actually create the artifact.

Definition at line 155 of file artifact.c.

References ARTIFACT_TRIES, artifactstruct::chance, FABS, find_artifactlist(), give_artifact_abilities(), artifactstruct::item, artifactliststruct::items, legal_artifact_combination(), llevDebug, llevError, LOG(), obj::magic, obj::name, artifactstruct::next, RANDOM, artifactliststruct::total_chance, and obj::type.

Referenced by alchemy_failure_effect(), fix_generated_item(), generate_monster_arch(), generate_monster_inv(), and START_TEST().

Here is the call graph for this function:

Here is the caller graph for this function:

static artifact* get_empty_artifact ( void  )
static

Allocate and return the pointer to an empty artifact structure.

Returns
new structure blanked, never NULL.
Note
will fatal() if memory error.

Definition at line 58 of file artifact.c.

References artifactstruct::allowed, artifactstruct::allowed_size, artifactstruct::chance, artifactstruct::difficulty, fatal(), artifactstruct::item, artifactstruct::next, and OUT_OF_MEMORY.

Referenced by init_artifacts().

Here is the call graph for this function:

Here is the caller graph for this function:

static artifactlist* get_empty_artifactlist ( void  )
static

Allocate and return the pointer to an empty artifactlist structure.

Returns
new structure blanked, never NULL.
Note
will fatal() if memory error.

Definition at line 39 of file artifact.c.

References fatal(), artifactliststruct::items, artifactliststruct::next, OUT_OF_MEMORY, and artifactliststruct::total_chance.

Referenced by init_artifacts().

Here is the call graph for this function:

Here is the caller graph for this function:

void give_artifact_abilities ( object op,
const object artifact 
)

Fixes the given object, giving it the abilities and titles it should have due to the second artifact-template.

Definition at line 203 of file artifact.c.

References add_abilities(), add_refcount(), add_string(), obj::artifact, free_string(), MAX_BUF, obj::name, snprintf, and obj::title.

Referenced by add_one_item(), CREArtifactPanel::artifactChanged(), cast_create_missile(), command_create(), generate_artifact(), knowledge_alchemy_face(), make_item_from_recipe(), and save_object().

Here is the call graph for this function:

Here is the caller graph for this function:

void init_artifacts ( void  )
int legal_artifact_combination ( const object op,
const artifact art 
)

Checks if op can be combined with art.

Definition at line 221 of file artifact.c.

References artifactstruct::allowed, obj::arch, llevDebug, LOG(), linked_char::name, obj::name, archt::name, and linked_char::next.

Referenced by command_create(), CREArtifactPanel::computeMadeViaAlchemy(), find_artifact(), generate_artifact(), and locate_recipe_artifact().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

int artifact_init

1 if doing archetypes initialization

Definition at line 28 of file artifact.c.

Referenced by init_artifacts(), local_check_loaded_object(), and teardown().