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

Everything concerning treasures. More...

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

Go to the source code of this file.

Macros

#define DICE2   (get_magic(2) == 2 ? 2 : 1)
 
#define DICESPELL   (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3)
 
#define num_resist_table   19
 Number of items in resist_table. More...
 
#define TREASURE_DEBUG
 TREASURE_DEBUG does some checking on the treasurelists after loading. More...
 

Functions

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 More...
 
static void check_treasurelist (const treasure *t, const treasurelist *tl)
 Checks if a treasure if valid. More...
 
static void create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries)
 Creates all the treasures. More...
 
static void create_one_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries)
 Creates one treasure from the list. More...
 
void create_treasure (treasurelist *t, object *op, int flag, int difficulty, int tries)
 This calls the appropriate treasure creation function. More...
 
void dump_monster_treasure (const char *name)
 For debugging purposes. More...
 
static void dump_monster_treasure_rec (const char *name, treasure *t, int depth)
 For debugging purposes. More...
 
treasurelistfind_treasurelist (const char *name)
 Searches for the given treasurelist in the globally linked list of treasurelists which has been built by load_treasures(). More...
 
static void fix_flesh_item (object *item, const object *donor)
 Objects of type FLESH are similar to type FOOD, except they inherit properties (name, food value, etc). More...
 
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. More...
 
void free_all_treasures (void)
 Free all treasure-related memory. More...
 
static void free_treasurestruct (treasure *t)
 Frees a treasure, including its yes, no and next items. More...
 
objectgenerate_treasure (treasurelist *t, int difficulty)
 Generate a treasure from a list generating a single item. More...
 
static treasureget_empty_treasure (void)
 Allocate and return the pointer to an empty treasure structure. More...
 
static treasurelistget_empty_treasurelist (void)
 Allocate and return the pointer to an empty treasurelist structure. More...
 
static int get_magic (int diff)
 get_magic(diff) will return a random number between 0 and 4. More...
 
void init_archetype_pointers (void)
 Initialize global archtype pointers: More...
 
static int level_for_item (const object *op, int difficulty, int retmult)
 Calculate the appropriate level for wands staves and scrolls. More...
 
static treasureload_treasure (FILE *fp, int *line)
 Reads one treasure from the file, including the 'yes', 'no' and 'more' options. More...
 
void load_treasures (void)
 Opens LIBDIR/treasure and reads all treasure-declarations from it. More...
 
static int magic_from_difficulty (int difficulty)
 This is used when determining the magical bonus created on specific maps. More...
 
static void put_treasure (object *op, object *creator, int flags)
 Inserts generated treasure where it should go. More...
 
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. More...
 
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. More...
 
static void set_ring_bonus (object *op, int bonus)
 Randomly adds one magical ability to the given object. More...
 
static int special_potion (object *op)
 Check if object is a special potion. More...
 
static void trap_adjust (object *trap, int difficulty)
 Adjust trap difficulty to the map. More...
 
static objectlinktreasure_find_matching_type (treasure *t, int type, objectlink *olp, int tries)
 This is the function that does the actual work for treasurelist_find_matching_type(). More...
 
objectlinktreasurelist_find_matching_type (const treasurelist *randomitems, int type, int traverse)
 This function looks at the passed in treasurelist and returns all objects on it, or on treasurelists it references, of matching type. More...
 

Variables

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. More...
 
static int resist_table []
 Resistances which can show up on rings and amulets. More...
 
const char *const spell_mapping []
 

Detailed Description

Everything concerning treasures.

See also
Treasure lists

Definition in file treasure.c.

Macro Definition Documentation

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

Definition at line 1081 of file treasure.c.

Referenced by fix_generated_item().

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

Definition at line 1082 of file treasure.c.

#define num_resist_table   19

Number of items in resist_table.

Definition at line 53 of file treasure.c.

Referenced by set_ring_bonus().

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

Function Documentation

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

References archt::clone, dump_monster_treasure_rec(), first_archetype, treasureliststruct::items, logfile, obj::name, archt::name, archt::next, obj::randomitems, strcasecmp(), and obj::title.

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

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

Referenced by dump_monster_treasure().

Here is the call graph for this function:

Here is the caller graph for this function:

static void fix_flesh_item ( object item,
const object donor 
)
static

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.

Parameters
itemFLESH item to fix based on the donor.
donorwhat monster will give item.

Definition at line 1476 of file treasure.c.

References obj::arch, AT_ACID, AT_POISON, obj::attacktype, liv::Con, liv::exp, obj::face, find_archetype(), find_face(), FLAG_MONSTER, FLAG_NO_STEAL, FLESH, liv::food, FREE_AND_COPY, liv::hp, isqrt(), obj::level, llevError, LOG(), MAX_BUF, new_face_struct::name, obj::name, archt::name, obj::name_pl, new_faces, NROFATTACKS, obj::other_arch, POISON, QUERY_FLAG, archt::reference_count, obj::resist, SET_FLAG, snprintf, obj::stats, obj::type, obj::value, and obj::weight.

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

References add_string(), AMULET, amulet_arch, obj::arch, ARMOUR, BOOK, BRACERS, calc_item_power(), CHANCE_FOR_ARTIFACT, CLOAK, CONTAINER, create_archetype(), create_treasure(), crown_arch, obj::dam_modifier, DICE2, mapdef::difficulty, obj::duration_modifier, liv::exp, fix_flesh_item(), FLAG_ALIVE, FLAG_BLESSED, FLAG_CURSED, FLAG_DAMNED, FLAG_IS_THROWN, FLAG_MONSTER, FLAG_NO_PICK, FLAG_STARTEQUIP, liv::food, FREE_AND_COPY, generate_artifact(), GET_ANIM_ID, get_power_from_ench(), GT_ENVIRONMENT, GT_MINIMAL, GT_ONLY_GOOD, GT_STARTEQUIP, HELMET, obj::inv, obj::item_power, obj::level, level_for_item(), llevDebug, LOG(), obj::magic, obj::map, MONEY, obj::msg, obj::name, obj::name_pl, obj::nrof, NUM_ANIMATIONS, object_free_drop_inventory(), object_insert_in_ob(), object_remove(), POTION, QUERY_FLAG, RANDOM, obj::randomitems, obj::range_modifier, RING, ring_arch, rndm(), ROD, rod_adjust(), RUNE, SCROLL, SET_ANIMATION, SET_FLAG, set_magic(), set_materialname(), set_ring_bonus(), SHIELD, obj::slaying, liv::sp, special_potion(), SPELL, spell_mapping, SPELLBOOK, obj::stats, tailor_readable_ob(), obj::title, TRAP, trap_adjust(), obj::type, obj::value, 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 1597 of file treasure.c.

References first_treasurelist, 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_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 1583 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:

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

References RANDOM.

void init_archetype_pointers ( void  )

Initialize global archtype pointers:

Definition at line 64 of file treasure.c.

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

Referenced by init_beforeplay().

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

References obj::dam_modifier, obj::duration_modifier, obj::inv, obj::level, llevError, LOG(), MAX_SPELLITEM_LEVEL, obj::name, obj::range_modifier, 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 800 of file treasure.c.

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

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

References obj::arch, ARMOUR, ARMOUR_SPEED, archt::clone, obj::magic, RANDOM, obj::type, and obj::weight.

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

References liv::ac, AMULET, liv::dam, liv::exp, FABS, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, liv::food, get_attr_value(), liv::hp, num_resist_table, RANDOM, obj::resist, resist_table, set_attr_value(), SET_FLAG, liv::sp, obj::stats, obj::type, obj::value, and liv::wc.

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

References obj::attacktype, liv::Cha, liv::Con, liv::Dex, liv::Int, NROFATTACKS, liv::Pow, obj::resist, obj::stats, liv::Str, and liv::Wis.

Referenced by fix_generated_item().

Here is the caller graph for this function:

static void trap_adjust ( object trap,
int  difficulty 
)
static

Adjust trap difficulty to the map.

The default traps are too strong for wimpy level 1 players, and unthreatening to anyone of high level

Parameters
traptrap to adjust.
difficultymap difficulty.

Definition at line 1043 of file treasure.c.

References AT_DEATH, AT_POISON, obj::attacktype, liv::Cha, liv::dam, obj::inv, obj::level, obj::other_arch, rndm(), and obj::stats.

Referenced by fix_generated_item().

Here is the call graph for this function:

Here is the caller graph for this function:

static objectlink* treasure_find_matching_type ( treasure t,
int  type,
objectlink olp,
int  tries 
)
static

This is the function that does the actual work for treasurelist_find_matching_type().

See notes below on what we are doing here. Note that the logic here follows that of create_all_treasures(), except we do not care about difficulty or chances.

Parameters
ttreasure entry we are working on.
typeobject type we are matching against.
olplinked list pointer, may be null.
triesFor each depth, increases by one. This is needed because treasurelists can loop back on each other (A->B, B->C, C->A), so we needto make sure we do not get in an infinite loop.
Returns
linked list of entries. This may be NULL if nothing is found.

Definition at line 1630 of file treasure.c.

References archt::clone, find_treasurelist(), get_objectlink(), treasurestruct::item, treasureliststruct::items, treasurestruct::name, treasurestruct::next, oblnk::next, treasurestruct::next_no, treasurestruct::next_yes, oblnk::ob, and obj::type.

Referenced by treasurelist_find_matching_type().

Here is the call graph for this function:

Here is the caller graph for this function:

objectlink* treasurelist_find_matching_type ( const treasurelist randomitems,
int  type,
int  traverse 
)

This function looks at the passed in treasurelist and returns all objects on it, or on treasurelists it references, of matching type.

The oblinkpt linked list will return a pointer to all the archetype clones. This is useful for functions that need to examine treasurelists and potentially revoke or add a partial set of items on the list. This removes the need of other functions to have their own parsing logic of treasurelists. Note that this will return all objects that may show up on the the treasurelist of matching type. This does not look at difficulty, yes/no combinations, etc. In general, functions that call this should have some idea of what the treasurelist may be/what it may have on it. The contents of the linked list may not be unique - it is entirely possible that due to treasurelist traversals, the same item shows up multiple times, and there is no check here for that. The order of items on the returned linked list should not be taken to be meaningful in any way - based on different processing algorithms, the results could change. As of this writing, order is reverse from that of the treasurelists, simply because that is fastest way to process them.

Parameters
randomitemsThe treasurelist to examine.
typethe object type (arch->clone.type) to match against.
traverseIf true, then this will process any treasurelists that this treasurelist points to, and so on.
Returns
oblinkpt linked list containing pointers to the arch->clone fields. Those objects should not be altered in any way, and must be copied to a new object before being used. the returned oblinkpt must be freed with free_objectlink(), otherwise, this will result in a memory leak.

Definition at line 1707 of file treasure.c.

References treasureliststruct::items, and treasure_find_matching_type().

Referenced by START_TEST().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

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

Referenced by magic_from_difficulty().

int resist_table[]
static
Initial value:
= {
}
#define ATNR_TURN_UNDEAD
Definition: attack.h:62
#define ATNR_DEPLETE
Definition: attack.h:65
#define ATNR_SLOW
Definition: attack.h:60
#define ATNR_CONFUSION
Definition: attack.h:54
#define ATNR_PARALYZE
Definition: attack.h:61
#define ATNR_LIFE_STEALING
Definition: attack.h:73
#define ATNR_DEATH
Definition: attack.h:66
#define ATNR_BLIND
Definition: attack.h:71
#define ATNR_FEAR
Definition: attack.h:63
#define ATNR_MAGIC
Definition: attack.h:50
#define ATNR_HOLYWORD
Definition: attack.h:70
#define ATNR_PHYSICAL
Definition: attack.h:49
#define ATNR_ELECTRICITY
Definition: attack.h:52
#define ATNR_POISON
Definition: attack.h:59
#define ATNR_DRAIN
Definition: attack.h:56
#define ATNR_GHOSTHIT
Definition: attack.h:58
#define ATNR_COLD
Definition: attack.h:53
#define ATNR_ACID
Definition: attack.h:55
#define ATNR_FIRE
Definition: attack.h:51
#define ATNR_DISEASE
Definition: attack.h:74

Resistances which can show up on rings and amulets.

If you want to weight things so certain resistances show up more often than others, just add more entries in the table for the protections you want to show up.

Definition at line 44 of file treasure.c.

Referenced by set_ring_bonus().

const char* const spell_mapping[]

Referenced by fix_generated_item().