Crossfire Server, Branch 1.12  R12190
Defines | Functions | Variables
treasure.c File Reference

Everything concerning treasures and artifacts. More...

#include <stdlib.h>
#include <global.h>
#include <treasure.h>
#include <loader.h>
#include <sproto.h>
Include dependency graph for treasure.c:

Go to the source code of this file.

Defines

#define ALLOWED_COMBINATION
#define ARTIFACT_TRIES   2
 Give 1 re-roll attempt per artifact.
#define DICE2   (get_magic(2) == 2 ? 2 : 1)
#define DICESPELL   (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3)
#define TREASURE_DEBUG
 TREASURE_DEBUG does some checking on the treasurelists after loading.

Functions

void add_abilities (object *op, object *change)
 Used in artifact generation.
static void change_treasure (treasure *t, object *op)
 if there are change_xxx commands in the treasure, we include the changes in the generated object
static void check_treasurelist (const treasure *t, const treasurelist *tl)
 Checks if a treasure if valid.
static void create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries)
 Creates all the treasures.
static void create_one_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries)
 Creates one treasure from the list.
void create_treasure (treasurelist *t, object *op, int flag, int difficulty, int tries)
 This calls the appropriate treasure creation function.
void dump_artifacts (void)
 For debugging purposes.
void dump_monster_treasure (const char *name)
 For debugging purposes.
static void dump_monster_treasure_rec (const char *name, treasure *t, int depth)
 For debugging purposes.
artifactlistfind_artifactlist (int type)
 Searches the artifact lists and returns one that has the same type of objects on it.
treasurelistfind_treasurelist (const char *name)
 Searches for the given treasurelist in the globally linked list of treasurelists which has been built by load_treasures().
static void fix_flesh_item (object *item, object *donor)
 fix_flesh_item() - objects of type FLESH are similar to type FOOD, except they inherit properties (name, food value, etc).
void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags)
 fix_generated_item(): This is called after an item is generated, in order to set it up right.
void free_all_treasures (void)
 Free all treasure-related memory.
static void free_artifact (artifact *at)
 Totally frees an artifact, its next items, and such.
static void free_artifactlist (artifactlist *al)
 Free specified list and its items.
static void free_charlinks (linked_char *lc)
 Frees a link structure and its next items.
static void free_treasurestruct (treasure *t)
 Frees a treasure, including its yes, no and next items.
void generate_artifact (object *op, int difficulty)
 Decides randomly which artifact the object should be turned into.
object * generate_treasure (treasurelist *t, int difficulty)
 This is similar to the old generate treasure function.
static artifactget_empty_artifact (void)
 Allocate and return the pointer to an empty artifact structure.
static artifactlistget_empty_artifactlist (void)
 Allocate and return the pointer to an empty artifactlist structure.
static treasureget_empty_treasure (void)
 Allocate and return the pointer to an empty treasure structure.
static treasurelistget_empty_treasurelist (void)
 Allocate and return the pointer to an empty treasurelist structure.
static int get_magic (int diff)
 get_magic(diff) will return a random number between 0 and 4.
void give_artifact_abilities (object *op, object *artifact)
 Fixes the given object, giving it the abilities and titles it should have due to the second artifact-template.
void init_archetype_pointers (void)
 Initialize global archtype pointers:
void init_artifacts (void)
 Builds up the lists of artifacts from the file in the libdir.
int legal_artifact_combination (object *op, artifact *art)
 Checks if op can be combined with art.
static int level_for_item (const object *op, int difficulty, int retmult)
 Calculate the appropriate level for wands staves and scrolls.
static treasureload_treasure (FILE *fp, int *line)
 Reads one treasure from the file, including the 'yes', 'no' and 'more' options.
void load_treasures (void)
 Opens LIBDIR/treasure and reads all treasure-declarations from it.
static int magic_from_difficulty (int difficulty)
 This is used when determining the magical bonus created on specific maps.
static void put_treasure (object *op, object *creator, int flags)
 Inserts generated treasure where it should go.
void set_abs_magic (object *op, int magic)
 Sets magical bonus in an object, and recalculates the effect on the armour variable, and the effect on speed of armour.
static void set_magic (int difficulty, object *op, int max_magic, int flags)
 Sets a random magical bonus in the given object based upon the given difficulty, and the given max possible bonus.
static void set_ring_bonus (object *op, int bonus)
 Randomly adds one magical ability to the given object.
static int special_potion (object *op)
 Check if object is a special potion.

Variables

int artifact_init
 1 if doing archetypes initialization
static const int difftomagic_list [DIFFLEVELS][MAXMAGIC+1]
 Based upon the specified difficulty and upon the difftomagic_list array, a random magical bonus is returned.
const char *const spell_mapping []

Detailed Description

Everything concerning treasures and artifacts.

See also:
Treasure lists

Definition in file treasure.c.


Define Documentation

Definition at line 36 of file treasure.c.

#define ARTIFACT_TRIES   2

Give 1 re-roll attempt per artifact.

Definition at line 1897 of file treasure.c.

Referenced by generate_artifact().

#define DICE2   (get_magic(2) == 2 ? 2 : 1)

Definition at line 1041 of file treasure.c.

Referenced by fix_generated_item().

#define DICESPELL   (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3)

Definition at line 1042 of file treasure.c.

#define TREASURE_DEBUG

TREASURE_DEBUG does some checking on the treasurelists after loading.

It is useful for finding bugs in the treasures file. Since it only slows the startup some (and not actual game play), it is by default left on

Definition at line 44 of file treasure.c.


Function Documentation

void add_abilities ( object *  op,
object *  change 
)

Used in artifact generation.

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

Definition at line 1653 of file treasure.c.

References add_refcount(), animate_object(), arch_to_object(), blank_face, change_attr_value(), CLEAR_FLAG, copy_object(), FLAG_ALIVE, FLAG_ANIMATE, FLAG_BLIND, FLAG_CURSED, FLAG_DAMNED, FLAG_LIFESAVE, FLAG_MAKE_INVIS, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_SEE_IN_DARK, FLAG_STAND_STILL, FLAG_STEALTH, FLAG_XRAYS, free_object(), free_string(), get_attr_value(), get_object(), HORN, insert_ob_in_ob(), llevDebug, LOG(), NROFATTACKS, NUM_STATS, POTION, QUERY_FLAG, remove_ob(), set_abs_magic(), SET_FLAG, and update_ob_speed().

Referenced by artifact_msg(), and give_artifact_abilities().

Here is the call graph for this function:

Here is the caller graph for this function:

void dump_artifacts ( void  )
void dump_monster_treasure ( const char *  name)

For debugging purposes.

Dumps all treasures for a given monster. Created originally by Raphael Quinet for debugging the alchemy code.

Definition at line 1515 of file treasure.c.

References dump_monster_treasure_rec(), first_archetype, logfile, and strcasecmp().

Referenced by init_beforeplay().

Here is the call graph for this function:

Here is the caller graph for this function:

static void dump_monster_treasure_rec ( const char *  name,
treasure t,
int  depth 
) [static]

For debugging purposes.

Dumps all treasures recursively (see below).

Definition at line 1470 of file treasure.c.

References find_treasurelist(), FLESH, treasurestruct::item, treasureliststruct::items, logfile, treasurestruct::name, treasurestruct::next, treasurestruct::next_no, and treasurestruct::next_yes.

Referenced by dump_monster_treasure().

Here is the call graph for this function:

Here is the caller graph for this function:

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 1431 of file treasure.c.

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

Referenced by artifact_msg(), cast_create_missile(), command_create(), generate_artifact(), init_artifacts(), and locate_recipe_artifact().

Here is the caller graph for this function:

static void fix_flesh_item ( object *  item,
object *  donor 
) [static]

fix_flesh_item() - objects of type FLESH are similar to type FOOD, except they inherit properties (name, food value, etc).

based on the original owner (or 'donor' if you like). -b.t.

Definition at line 1955 of file treasure.c.

References AT_ACID, AT_POISON, find_archetype(), FLAG_MONSTER, FLAG_NO_STEAL, FLESH, FREE_AND_COPY, isqrt(), llevError, LOG(), MAX_BUF, NROFATTACKS, POISON, QUERY_FLAG, SET_FLAG, and snprintf().

Referenced by fix_generated_item().

Here is the call graph for this function:

Here is the caller graph for this function:

void fix_generated_item ( object *  op,
object *  creator,
int  difficulty,
int  max_magic,
int  flags 
)

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

This produced magical bonuses, puts spells into scrolls/books/wands, makes it unidentified, hides the value, etc.

4/28/96 added creator object from which op may now inherit properties based on op->type. Right now, which stuff the creator passes on is object type dependant. I know this is a spagetti manuever, but is there a cleaner way to do this? b.t.

Parameters:
opobject to fix.
creatorfor who op was created. Can be NULL.
difficultydifficulty level.
max_magicmaximum magic for the item.
flags
  • GT_ENVIRONMENT: if not set, calls fix_flesh_item().
  • GT_STARTEQUIP: Sets ::FLAG_STARTEQIUP on item if appropriate, or clears the item's value.
  • GT_MINIMAL: Does minimal processing on the object - just enough to make it a working object - don't change magic, value, etc, but set it material type as appropriate, for objects that need spell objects, set those, etc

Definition at line 1070 of file treasure.c.

References add_string(), AMULET, amulet_arch, ARMOUR, BOOK, BRACERS, calc_item_power(), CHANCE_FOR_ARTIFACT, CLOAK, CONTAINER, create_archetype(), create_treasure(), crown_arch, DICE2, fix_flesh_item(), FLAG_ALIVE, FLAG_BLESSED, FLAG_CURSED, FLAG_DAMNED, FLAG_IS_THROWN, FLAG_MONSTER, FLAG_NO_PICK, FLAG_STARTEQUIP, FREE_AND_COPY, free_object(), generate_artifact(), GET_ANIM_ID, get_power_from_ench(), GT_ENVIRONMENT, GT_MINIMAL, GT_ONLY_GOOD, GT_STARTEQUIP, HELMET, HORN, insert_ob_in_ob(), level_for_item(), llevDebug, LOG(), MAX, MONEY, NUM_ANIMATIONS, POTION, QUERY_FLAG, remove_ob(), RING, ring_arch, rndm(), ROD, RUNE, SCROLL, SET_ANIMATION, SET_FLAG, set_magic(), set_materialname(), set_ring_bonus(), SHIELD, special_potion(), SPELL, spell_mapping, SPELLBOOK, tailor_readable_ob(), TRAP, trap_adjust(), WAND, and WEAPON.

Referenced by convert_item(), create_all_treasures(), create_one_treasure(), god_gives_present(), move_creator(), and polymorph_item().

Here is the call graph for this function:

Here is the caller graph for this function:

void free_all_treasures ( void  )

Free all treasure-related memory.

Definition at line 2131 of file treasure.c.

References first_artifactlist, first_treasurelist, free_artifactlist(), free_string(), free_treasurestruct(), treasureliststruct::items, treasureliststruct::name, and treasureliststruct::next.

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 free_object(). Note that it isn't on the usual item list, so some tweaking is required.

Definition at line 2086 of file treasure.c.

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

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 2116 of file treasure.c.

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

Referenced by free_all_treasures().

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 2068 of file treasure.c.

References linked_char::next.

Referenced by free_artifact().

Here is the caller graph for this function:

static void free_treasurestruct ( treasure t) [static]

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

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

Definition at line 2052 of file treasure.c.

References treasurestruct::next, treasurestruct::next_no, and treasurestruct::next_yes.

Referenced by free_all_treasures().

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 1906 of file treasure.c.

References ARTIFACT_TRIES, artifactstruct::chance, FABS, find_artifactlist(), give_artifact_abilities(), artifactstruct::item, artifactliststruct::items, legal_artifact_combination(), llevDebug, llevError, LOG(), artifactstruct::next, 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:

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 1412 of file treasure.c.

References artifactstruct::allowed, 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 1393 of file treasure.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:

static int get_magic ( int  diff) [static]

get_magic(diff) will return a random number between 0 and 4.

diff can be any value above 2. The higher the diff-variable, the higher is the chance of returning a low number. It is only used in fix_generated_treasure() to set bonuses on rings and amulets. Another scheme is used to calculate the magic of weapons and armours.

Definition at line 1030 of file treasure.c.

void give_artifact_abilities ( object *  op,
object *  artifact 
)

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

Definition at line 1884 of file treasure.c.

References add_abilities(), add_string(), free_string(), MAX_BUF, and snprintf().

Referenced by cast_create_missile(), command_create(), generate_artifact(), and make_item_from_recipe().

Here is the call graph for this function:

Here is the caller graph for this function:

void init_archetype_pointers ( void  )

Initialize global archtype pointers:

Definition at line 66 of file treasure.c.

References amulet_arch, crown_arch, find_archetype(), ring_arch, staff_arch, and warn_archetypes.

Referenced by init_beforeplay().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Checks if op can be combined with art.

Definition at line 1849 of file treasure.c.

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

Referenced by generate_artifact(), and locate_recipe_artifact().

Here is the call graph for this function:

Here is the caller graph for this function:

static int level_for_item ( const object *  op,
int  difficulty,
int  retmult 
) [static]

Calculate the appropriate level for wands staves and scrolls.

This code presumes that op has had its spell object created (in op->inv)

Parameters:
opitem we're trying to get the level of
difficultymap difficulty.
retmultif 1, return the multiplier, not the level, for computing value
Returns:
generated level, 0 if invalid item.

Definition at line 554 of file treasure.c.

References llevError, LOG(), MAX_SPELLITEM_LEVEL, and rndm().

Referenced by fix_generated_item().

Here is the call graph for this function:

Here is the caller graph for this function:

static int magic_from_difficulty ( int  difficulty) [static]

This is used when determining the magical bonus created on specific maps.

Parameters:
difficultydifficulty.
Returns:
random magic bonus.

Definition at line 808 of file treasure.c.

References DIFFLEVELS, difftomagic_list, llevError, LOG(), and MAXMAGIC.

Referenced by set_magic().

Here is the call graph for this function:

Here is the caller graph for this function:

void set_abs_magic ( object *  op,
int  magic 
)

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 844 of file treasure.c.

References ARMOUR, and ARMOUR_SPEED.

Referenced by add_abilities(), command_create(), and set_magic().

Here is the caller graph for this function:

static void set_magic ( int  difficulty,
object *  op,
int  max_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 megative.

Parameters:
difficultydifficulty we want the item to be.
opthe object.
max_magicwhat should be the maximum magic of the item.
flagscombination of GT_xxx flags.

Definition at line 880 of file treasure.c.

References FLAG_CURSED, GT_ONLY_GOOD, magic_from_difficulty(), set_abs_magic(), and SET_FLAG.

Referenced by command_create(), and fix_generated_item().

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_ring_bonus ( object *  op,
int  bonus 
) [static]

Randomly adds one magical ability to the given object.

Modified for Partial Resistance in many ways: 1) Since rings can have multiple bonuses, if the same bonus is rolled again, increase it - the bonuses now stack with other bonuses previously rolled and ones the item might natively have. 2) Add code to deal with new PR method.

Changes the item's value.

Parameters:
opring or amulet to change.
bonusbonus to add to item.

Definition at line 909 of file treasure.c.

References AMULET, FABS, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, get_attr_value(), num_resist_table, resist_table, set_attr_value(), and SET_FLAG.

Referenced by fix_generated_item().

Here is the call graph for this function:

Here is the caller graph for this function:

static int special_potion ( object *  op) [static]

Check if object is a special potion.

Parameters:
opobject to check.
Returns:
1 if op is a special potion (resistance, attribute, ...), 0 else.

Definition at line 2024 of file treasure.c.

References NROFATTACKS.

Referenced by fix_generated_item().

Here is the caller graph for this function:


Variable Documentation

1 if doing archetypes initialization

Definition at line 61 of file treasure.c.

Referenced by init_artifacts().

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

Based upon the specified difficulty and upon the difftomagic_list array, a random magical bonus is returned.

This is a new way of calculating the chance for an item to have a specific magical bonus The array has two arguments, the difficulty of the level, and the magical bonus "wanted".

Definition at line 594 of file treasure.c.

Referenced by magic_from_difficulty().

const char* const spell_mapping[]

Referenced by check_spells(), and fix_generated_item().