Crossfire Server, Trunk
|
#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 "assets.h"
#include "AssetsManager.h"
Go to the source code of this file.
Macros | |
#define | DICE2 (dice2()) |
#define | DICESPELL (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3) |
#define | num_resist_table 19 |
Functions | |
bool | chance (int a, int b) |
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) |
static int | dice2 () |
static void | do_single_item (treasure *t, object *op, int flag, int difficulty) |
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) |
object * | generate_treasure (treasurelist *t, int difficulty) |
treasure * | get_empty_treasure (void) |
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) |
treasure * | treasure_insert (treasurelist *list, int position) |
void | treasure_remove_item (treasurelist *list, int position) |
Variables | |
static archetype * | amulet_arch = NULL |
static archetype * | crown_arch = NULL |
static const int | difftomagic_list [DIFFLEVELS][MAXMAGIC+1] |
static int | resist_table [] |
static archetype * | ring_arch = NULL |
#define DICE2 (dice2()) |
Definition at line 861 of file treasure.cpp.
Definition at line 875 of file treasure.cpp.
#define num_resist_table 19 |
Number of items in resist_table.
Definition at line 53 of file treasure.cpp.
bool chance | ( | int | a, |
int | b | ||
) |
Return true with a probability of a/b.
Definition at line 866 of file treasure.cpp.
References disinfect::a, Ice::b, and RANDOM.
Referenced by artifact_describe(), attempt_steal(), dice2(), dragon_eat_flesh(), identify_object_with_skill(), make_formula_book(), resurrection_fails(), singing(), START_TEST(), trap_see(), use_oratory(), and writeRecipe().
if there are change_xxx commands in the treasure, we include the changes in the generated object
t | treasure. |
op | actual generated treasure. |
Definition at line 105 of file treasure.cpp.
References add_string(), FREE_AND_COPY, free_string(), give::op, and Floor::t.
Referenced by do_single_item().
|
static |
Creates all the treasures.
t | what to generate. |
op | for who to generate the treasure. |
flag | combination of GT_xxx values. |
difficulty | map difficulty. |
tries | to avoid infinite recursion. |
Definition at line 175 of file treasure.cpp.
References create_treasure(), do_single_item(), find_treasurelist(), give::op, RANDOM, and Floor::t.
Referenced by create_treasure().
|
static |
Creates one treasure from the list.
tl | what to generate. |
op | for who to generate the treasure. |
flag | combination of GT_xxx values. |
difficulty | map difficulty. |
tries | to avoid infinite recursion. |
Definition at line 210 of file treasure.cpp.
References create_treasure(), do_single_item(), find_treasurelist(), FLAG_CURSED, FLAG_DAMNED, GT_ONLY_GOOD, treasurelist::items, llevDebug, llevError, LOG(), give::op, QUERY_FLAG, RANDOM, Floor::t, treasurelist::total_chance, and autojail::value.
Referenced by create_treasure().
void create_treasure | ( | treasurelist * | t, |
object * | op, | ||
int | flag, | ||
int | difficulty, | ||
int | tries | ||
) |
This calls the appropriate treasure creation function.
t | what to generate. |
op | for who to generate the treasure. |
flag | combination of GT_xxx values. |
difficulty | map difficulty. |
tries | to avoid infinite recursion. |
Definition at line 263 of file treasure.cpp.
References create_all_treasures(), create_one_treasure(), llevDebug, llevError, LOG(), give::op, and Floor::t.
Referenced by apply_auto(), apply_auto_fix(), apply_race_and_class(), auto_apply_fix_inventory(), command_create(), create_all_treasures(), create_one_treasure(), do_artifact(), do_auto_apply(), do_harvest(), do_magic(), fix_generated_item(), fix_summon_pet(), generate_monster_arch(), generate_monster_inv(), generate_treasure(), give_initial_items(), god_intervention(), key_change_class(), CRETreasurePanel::onGenerate(), pets_summon_object(), polymorph_living(), put_a_monster(), rune_attack(), and START_TEST().
|
static |
Definition at line 871 of file treasure.cpp.
References chance().
Creates the item for a treasure.
t | what to generate. |
op | for who to generate the treasure. |
flag | combination of GT_xxx values. |
difficulty | map difficulty. |
Definition at line 139 of file treasure.cpp.
References arch_to_object(), change_treasure(), find_artifact(), fix_generated_item(), FREE_OBJ_FREE_INVENTORY, FREE_OBJ_NO_DESTROY_CALLBACK, give_artifact_abilities(), GT_INVISIBLE, make_face_from_files::int, artifact::item, legal_artifact_combination(), llevError, LOG(), object_free(), give::op, put_treasure(), RANDOM, Floor::t, and Ice::tmp.
Referenced by create_all_treasures(), and create_one_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 1244 of file treasure.cpp.
References AssetsManager::archetypes(), AssetsCollection< T, Key >::each(), is_valid_types_gen::found, getManager(), logfile, give::name, and strcasecmp().
Referenced by init_beforeplay().
|
static |
For debugging purposes. Dumps all treasures recursively (see below).
Definition at line 1199 of file treasure.cpp.
References find_treasurelist(), FLESH, treasurelist::items, logfile, give::name, and Floor::t.
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.
item | FLESH item to fix based on the donor. |
donor | what monster will give item. |
Definition at line 1272 of file treasure.cpp.
References object::arch, AT_ACID, AT_POISON, object::attacktype, living::Con, living::exp, find_archetype(), FLAG_MONSTER, FLAG_NO_STEAL, FLESH, FREE_AND_COPY, living::hp, if(), isqrt(), object::level, llevError, LOG(), MAX_BUF, object::name, archetype::name, NROFATTACKS, POISON, QUERY_FLAG, archetype::reference_count, object::resist, SET_FLAG, object::stats, try_find_face(), and object::weight.
Referenced by fix_generated_item().
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.
op | object to fix. |
creator | for who op was created. Can be NULL. |
difficulty | difficulty level. |
max_magic | maximum magic for the item. |
flags |
|
Definition at line 903 of file treasure.cpp.
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, object::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, object::slaying, living::sp, special_potion(), SPELL, spell_mapping, SPELLBOOK, object::stats, tailor_readable_ob(), Ice::tmp, TRAP, trap_adjust(), object::type, WAND, and WEAPON.
Referenced by do_item_conversion(), do_single_item(), god_gives_present(), move_creator(), and polymorph_item().
object* generate_treasure | ( | treasurelist * | t, |
int | difficulty | ||
) |
Generate a treasure from a list generating a single item. This is similar to the old generate treasure function. However, it instead takes a treasurelist. It is really just a wrapper around create_treasure(). We create a dummy object that the treasure gets inserted into, and then return that treasure.
t | treasure list to generate from. |
difficulty | treasure difficulty. |
Definition at line 295 of file treasure.cpp.
References create_treasure(), llevError, LOG(), guildjoin::ob, object_free_drop_inventory(), object_new(), object_remove(), Floor::t, and Ice::tmp.
Referenced by apply_auto(), cast_wonder(), and START_TEST().
treasure* get_empty_treasure | ( | void | ) |
Allocate and return the pointer to an empty treasure structure.
Definition at line 1380 of file treasure.cpp.
References fatal(), OUT_OF_MEMORY, and Floor::t.
Referenced by TreasureWrapper::doAddChild(), TreasureLoader::loadTreasure(), and treasure_insert().
void init_archetype_pointers | ( | void | ) |
Initialize global archtype pointers:
Definition at line 62 of file treasure.cpp.
References amulet_arch, crown_arch, find_archetype(), and ring_arch.
Referenced by init_beforeplay().
|
static |
Calculate the appropriate level for wands staves and scrolls.
This code presumes that op has had its spell object created (in op->inv)
op | item we're trying to get the level of |
difficulty | map difficulty. |
Definition at line 323 of file treasure.cpp.
References level, llevError, LOG(), MAX_SPELLITEM_LEVEL, give::op, and rndm().
Referenced by fix_generated_item().
|
static |
This is used when determining the magical bonus created on specific maps.
difficulty | difficulty. |
Definition at line 578 of file treasure.cpp.
References DIFFLEVELS, difftomagic_list, llevError, LOG(), MAXMAGIC, and RANDOM.
Referenced by set_magic().
Inserts generated treasure where it should go.
op | treasure just generated. |
creator | for which object the treasure is being generated. |
flags | combination of GT_xxx values. |
Definition at line 82 of file treasure.cpp.
References FLAG_OBJ_ORIGINAL, flags, GT_ENVIRONMENT, INS_NO_MERGE, INS_NO_WALK_ON, object::map, object_insert_in_map_at(), object_insert_in_ob(), give::op, SET_FLAG, SPELL, object::x, and object::y.
Referenced by do_single_item().
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. Neila Hawkins 2021-01-19
op | object we're modifying. |
magic | magic modifier. |
Definition at line 618 of file treasure.cpp.
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().
|
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.
difficulty | difficulty we want the item to be. |
op | the object. |
max_magic | what should be the maximum magic of the item. |
flags | combination of GT_xxx flags. |
Definition at line 666 of file treasure.cpp.
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().
|
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.
op | ring or amulet to change. |
bonus | bonus to add to item. |
Definition at line 695 of file treasure.cpp.
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().
|
static |
Check if object is a special potion.
op | object to check. |
Definition at line 1347 of file treasure.cpp.
References NROFATTACKS, and give::op.
Referenced by fix_generated_item().
|
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
trap | trap to adjust. |
difficulty | map difficulty. |
Definition at line 823 of file treasure.cpp.
References AT_DEATH, AT_POISON, object::attacktype, living::Cha, living::dam, object::inv, object::level, object::other_arch, rndm(), and object::stats.
Referenced by fix_generated_item().
void treasure_free | ( | treasure * | t | ) |
Frees a treasure, including its yes, no and next items.
t | treasure to free. Pointer is free()d too, so becomes invalid. |
Definition at line 1401 of file treasure.cpp.
References free_string(), Floor::t, and treasure_free().
Referenced by asset_destroy(), TreasureWrapper::doRemoveChild(), Treasures::replace(), treasure_free(), and treasure_remove_item().
treasure* treasure_insert | ( | treasurelist * | list, |
int | position | ||
) |
Insert a new treasure in the treasure list, at a specific position in the children list.
list | list to insert the new treasure into. |
position | if less than the number of items then before this item, else at end of list. |
Definition at line 1422 of file treasure.cpp.
References get_empty_treasure(), guildoracle::list, and treasure::next.
Referenced by TreasureListWrapper::drop(), and START_TEST().
void treasure_remove_item | ( | treasurelist * | list, |
int | position | ||
) |
Remove the treasure at the specified position from the list.
list | list to remove the treasure from. |
position | index of the treasure to remove, 0-based, negative value is ignored. |
Definition at line 1445 of file treasure.cpp.
References guildoracle::list, give::next, treasure::next, and treasure_free().
Referenced by TreasureListWrapper::removeChild(), and START_TEST().
|
static |
Definition at line 50 of file treasure.cpp.
Referenced by fix_generated_item(), and init_archetype_pointers().
|
static |
Definition at line 50 of file treasure.cpp.
Referenced by fix_generated_item(), and init_archetype_pointers().
|
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 365 of file treasure.cpp.
Referenced by magic_from_difficulty().
|
static |
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 39 of file treasure.cpp.
Referenced by set_ring_bonus().
|
static |
Arches for rings, amulets and crowns.
Definition at line 50 of file treasure.cpp.
Referenced by fix_generated_item(), and init_archetype_pointers().