Crossfire Server, Trunk
treasure.c File Reference
#include "global.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <math.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
 

Functions

static void change_treasure (treasure *t, object *op)
 
static void create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries)
 
static void create_one_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries)
 
void create_treasure (treasurelist *t, object *op, int flag, int difficulty, int tries)
 
void dump_monster_treasure (const char *name)
 
static void dump_monster_treasure_rec (const char *name, treasure *t, int depth)
 
static void fix_flesh_item (object *item, const object *donor)
 
void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags)
 
objectgenerate_treasure (treasurelist *t, int difficulty)
 
treasureget_empty_treasure (void)
 
static int get_magic (int diff)
 
void init_archetype_pointers (void)
 
static int level_for_item (const object *op, int difficulty)
 
static int magic_from_difficulty (int difficulty)
 
static void put_treasure (object *op, object *creator, int flags)
 
void set_abs_magic (object *op, int magic)
 
static void set_magic (int difficulty, object *op, int max_magic, int flags)
 
static void set_ring_bonus (object *op, int bonus)
 
static int special_potion (object *op)
 
static void trap_adjust (object *trap, int difficulty)
 
void treasure_free (treasure *t)
 
treasuretreasure_insert (treasurelist *list, int position)
 
void treasure_remove_item (treasurelist *list, int position)
 

Variables

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

Detailed Description

Everything concerning treasures.

See also
Treasure lists

Definition in file treasure.c.

Macro Definition Documentation

◆ DICE2

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

Definition at line 847 of file treasure.c.

◆ DICESPELL

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

Definition at line 848 of file treasure.c.

◆ num_resist_table

#define num_resist_table   19

Number of items in resist_table.

Definition at line 46 of file treasure.c.

Function Documentation

◆ dump_monster_treasure()

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

References archt::clone, dump_monster_treasure_rec(), is_valid_types_gen::found, get_next_archetype(), treasureliststruct::items, logfile, give::name, obj::name, archt::name, 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:

◆ dump_monster_treasure_rec()

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

References find_treasurelist(), FLESH, treasureliststruct::items, logfile, give::name, and Floor::t.

Referenced by dump_monster_treasure().

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

◆ fix_flesh_item()

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

References obj::arch, AT_ACID, AT_POISON, obj::attacktype, liv::Con, liv::exp, find_archetype(), FLAG_MONSTER, FLAG_NO_STEAL, FLESH, FREE_AND_COPY, liv::hp, if(), isqrt(), obj::level, llevError, LOG(), MAX_BUF, obj::name, archt::name, NROFATTACKS, POISON, QUERY_FLAG, archt::reference_count, obj::resist, SET_FLAG, obj::stats, try_find_face(), and obj::weight.

Referenced by fix_generated_item().

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

◆ fix_generated_item()

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 876 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, flags, FREE_AND_COPY, generate_artifact(), GET_ANIM_ID, get_power_from_ench(), GT_ENVIRONMENT, GT_MINIMAL, GT_ONLY_GOOD, GT_STARTEQUIP, HELMET, obj::level, level_for_item(), llevDebug, LOG(), MONEY, NUM_ANIMATIONS, object_free_drop_inventory(), object_insert_in_ob(), object_remove(), give::op, POTION, QUERY_FLAG, RANDOM, 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(), Ice::tmp, TRAP, trap_adjust(), obj::type, 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:

◆ get_magic()

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

References RANDOM.

◆ init_archetype_pointers()

void init_archetype_pointers ( void  )

Initialize global archtype pointers:

Definition at line 55 of file treasure.c.

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

Referenced by init_beforeplay().

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

◆ level_for_item()

static int level_for_item ( const object op,
int  difficulty 
)
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.
Returns
generated level, 0 if invalid item.

Definition at line 301 of file treasure.c.

References level, llevError, LOG(), MAX_SPELLITEM_LEVEL, give::op, and rndm().

Referenced by fix_generated_item().

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

◆ magic_from_difficulty()

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

◆ set_abs_magic()

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.

Patched to utilize settings values for the speed/weight adjustments, rather than hardcoded ones. Daniel Hawkins 2021-01-19

Parameters
opobject we're modifying.
magicmagic modifier.

Definition at line 590 of file treasure.c.

References Settings::armor_speed_improvement, Settings::armor_speed_linear, Settings::armor_weight_linear, Settings::armor_weight_reduction, ARMOUR, ARMOUR_SPEED, give::op, RANDOM, and settings.

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

+ Here is the caller graph for this function:

◆ set_magic()

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

References FLAG_CURSED, flags, GT_ONLY_GOOD, magic_from_difficulty(), give::op, 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:

◆ set_ring_bonus()

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

References AMULET, Ice::b, FABS, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, get_attr_value(), num_resist_table, give::op, ring_occidental_mages::r, RANDOM, 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:

◆ special_potion()

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

References NROFATTACKS, and give::op.

Referenced by fix_generated_item().

+ Here is the caller graph for this function:

◆ trap_adjust()

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

◆ treasure_free()

void treasure_free ( treasure t)

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

References Floor::t, and treasure_free().

Referenced by Treasures::destroy(), TreasureWrapper::doRemoveChild(), Treasures::replace(), treasure_free(), and treasure_remove_item().

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

◆ treasure_insert()

treasure* treasure_insert ( treasurelist list,
int  position 
)

Insert a new treasure in the treasure list, at a specific position in the children list.

Parameters
listlist to insert the new treasure into.
positionif less than the number of items then before this item, else at end of list.
Returns
inserted item, never null.

Definition at line 1391 of file treasure.c.

References get_empty_treasure(), guildoracle::list, and treasurestruct::next.

Referenced by TreasureListWrapper::drop(), and START_TEST().

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

◆ treasure_remove_item()

void treasure_remove_item ( treasurelist list,
int  position 
)

Remove the treasure at the specified position from the list.

Parameters
listlist to remove the treasure from.
positionindex of the treasure to remove, 0-based, negative value is ignored.

Definition at line 1414 of file treasure.c.

References guildoracle::list, give::next, treasurestruct::next, and treasure_free().

Referenced by TreasureListWrapper::removeChild(), and START_TEST().

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

Variable Documentation

◆ difftomagic_list

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

Referenced by magic_from_difficulty().

◆ resist_table

int resist_table[]
static
Initial value:

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

Referenced by set_ring_bonus().

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