Crossfire Server, Trunk
artifact.c File Reference
#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
 
#define KEY_ANIMATION_SUFFIX   "animation_suffix"
 
#define KEY_FACE_SUFFIX   "face_suffix"
 

Functions

void add_abilities (object *op, const object *change)
 
uint16_t artifact_get_face (const artifact *art)
 
static void compute_face_name (char *buf, size_t size, const char *name, const char *suffix)
 
void dump_artifacts (void)
 
const artifactfind_artifact (const object *op, const char *name)
 
const artifactlistfind_artifactlist (int type)
 
static artifactlistfind_artifactlist_internal (int type)
 
void free_all_artifacts (void)
 
static void free_artifact (artifact *at)
 
static void free_artifactlist (artifactlist *al)
 
void generate_artifact (object *op, int difficulty)
 
static artifactget_empty_artifact (void)
 
static artifactlistget_empty_artifactlist (void)
 
void give_artifact_abilities (object *op, const object *artifact)
 
void init_artifacts (BufferReader *reader, const char *filename)
 
int legal_artifact_combination (const object *op, const artifact *art)
 

Variables

int artifact_init
 

Detailed Description

Everything concerning artifacts.

See also
Treasure lists

Definition in file artifact.c.

Macro Definition Documentation

◆ ARTIFACT_TRIES

#define ARTIFACT_TRIES   2

Give 1 re-roll attempt per artifact

Definition at line 131 of file artifact.c.

◆ KEY_ANIMATION_SUFFIX

#define KEY_ANIMATION_SUFFIX   "animation_suffix"

Definition at line 277 of file artifact.c.

◆ KEY_FACE_SUFFIX

#define KEY_FACE_SUFFIX   "face_suffix"

Definition at line 276 of file artifact.c.

Function Documentation

◆ add_abilities()

void add_abilities ( object *  op,
const object *  change 
)

Apply artifact properties to an object.

Parameters
opobject to apply changes to.
changechanges to apply, with fields handled as described in the artifacts file.

For items that do not need identifying, use their identified face/animation immediately. This should make seas of generated creatures look more interesting.

Daniel Hawkins 2018-01-07

Add query flags to perform the same treatment for identified items or artifacts that come identified. Also make sure we have op->arch. Otherwise it segfaults when we don't.

2018-01-08

Definition at line 285 of file artifact.c.

References add_refcount(), animate::anim, arch_to_object(), blank_face, buf, change_attr_value(), CLEAR_FLAG, compute_face_name(), FLAG_ALIVE, FLAG_ANIMATE, FLAG_BLIND, FLAG_CLIENT_ANIM_RANDOM, FLAG_CONFUSED, FLAG_CURSED, FLAG_DAMNED, FLAG_IDENTIFIED, FLAG_LIFESAVE, FLAG_MAKE_INVIS, FLAG_NO_SAVE, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_REFLECTING, FLAG_SEE_IN_DARK, FLAG_STAND_STILL, FLAG_STEALTH, FLAG_XRAYS, FOR_INV_FINISH, FOR_INV_PREPARE, free_string(), get_attr_value(), make_face_from_files::int, commongive::inv, is_identified(), castle_read::key, KEY_ANIMATION_SUFFIX, KEY_FACE_SUFFIX, llevDebug, LOG(), MAX_BUF, Face::name, NROFATTACKS, NUM_STATS, object_copy(), object_free_drop_inventory(), object_get_value(), object_give_identified_properties(), object_insert_in_ob(), object_new(), object_remove(), object_set_msg(), object_set_value(), object_update_speed(), give::op, QUERY_FLAG, set_abs_magic(), SET_FLAG, sstring, Ice::tmp, try_find_animation(), and try_find_face().

Referenced by artifact_describe(), and give_artifact_abilities().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ artifact_get_face()

uint16_t 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 709 of file artifact.c.

References artifactstruct::allowed, artifactstruct::allowed_size, archininventory::arch, spell_arrow::archetype, blank_face, find_archetype(), get_next_archetype(), artifactstruct::item, linked_char::name, and linked_char::next.

+ Here is the call graph for this function:

◆ compute_face_name()

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 255 of file artifact.c.

References buf, give::name, strlcpy(), and castle_read::suffix.

Referenced by add_abilities().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_artifacts()

void dump_artifacts ( void  )

For debugging purposes. Dumps all tables.

Todo:
use LOG() instead of fprintf.

Definition at line 683 of file artifact.c.

References artifactstruct::allowed, artifactstruct::chance, artifactstruct::difficulty, first_artifactlist, artifactstruct::item, artifactliststruct::items, logfile, artifactstruct::next, artifactliststruct::next, give::next, artifactliststruct::total_chance, and artifactliststruct::type.

Referenced by init_beforeplay().

+ Here is the caller graph for this function:

◆ find_artifact()

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

Searches and returns a specific artifact compatible with an object, NULL if not found.

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

Definition at line 657 of file artifact.c.

References find_artifactlist_internal(), find_string(), artifactstruct::item, legal_artifact_combination(), guildoracle::list, give::name, artifactstruct::next, give::op, and sstring.

Referenced by add_one_item(), save_object_in_sb(), and while().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_artifactlist()

const artifactlist* find_artifactlist ( int  type)

Finds the artifact list for a certain item type.

Parameters
typeitem type to get the artifacts of.
Returns
NULL if no suitable list found.

Definition at line 647 of file artifact.c.

References find_artifactlist_internal(), and make_face_from_files::type.

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:

◆ find_artifactlist_internal()

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.

Parameters
typeobject type to get artifacts for.
Returns
NULL if no suitable list found.

Definition at line 533 of file artifact.c.

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

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

+ Here is the caller graph for this function:

◆ free_all_artifacts()

void free_all_artifacts ( void  )

Free all artifact-related information.

Definition at line 125 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:

◆ free_artifact()

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 be free()d.

Definition at line 80 of file artifact.c.

References artifactstruct::allowed, free_charlinks(), free_string(), artifactstruct::item, artifactstruct::next, give::next, and object_free_key_values().

Referenced by free_artifactlist().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ free_artifactlist()

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 110 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:

◆ generate_artifact()

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.

Parameters
opobject to attempt to transform.
difficultylimit for artifact difficulty.

Definition at line 143 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(), artifactstruct::next, give::op, RANDOM, and artifactliststruct::total_chance.

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:

◆ get_empty_artifact()

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 fatal(), OUT_OF_MEMORY, and Floor::t.

Referenced by init_artifacts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_empty_artifactlist()

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:

◆ give_artifact_abilities()

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.

Parameters
opobject to give properties to.
artifactwhat properties to apply.

Definition at line 194 of file artifact.c.

References add_abilities(), add_refcount(), add_string(), free_string(), MAX_BUF, and give::op.

Referenced by add_one_item(), CREArtifactPanel::artifactChanged(), cast_create_missile(), command_create(), generate_artifact(), make_item_from_recipe(), recipe_get_face(), save_object_in_sb(), and while().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_artifacts()

void init_artifacts ( BufferReader reader,
const char *  filename 
)

◆ legal_artifact_combination()

int legal_artifact_combination ( const object *  op,
const artifact art 
)

Checks if op can be combined with art.

Parameters
opobject to test.
artartifact to test.
Returns
1 if 'op' can be 'art', 0 else.

Definition at line 216 of file artifact.c.

References artifactstruct::allowed, llevDebug, LOG(), give::name, give::op, and Ice::tmp.

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

◆ artifact_init

int artifact_init

1 if doing archetypes initialization

Definition at line 28 of file artifact.c.

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