Crossfire Server, Trunk
|
Functions | |
static void | change_treasure (treasure *t, object *op) |
static void | check_treasurelist (treasure *t, const treasurelist *tl) |
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 void | do_single_item (treasure *t, object *op, int flag, int difficulty) |
treasurelist * | find_treasurelist (const char *name) |
object * | generate_treasure (treasurelist *t, int difficulty) |
treasure * | get_empty_treasure (void) |
treasure * | TreasureLoader::loadTreasure (BufferReader *reader, const std::string &filename) |
static void | put_treasure (object *op, object *creator, int flags) |
Treasure lists specify what items an object can have when it is first created during a map initialisation.
Treasure lists contain items with a certain probability of apparition. When the list is instancied, so that for instance a monster can receive its items, the items are randomly chosen based on this probability, and inserted at the desired location.
Lists can reference other lists to group commony-used definitions.
The list format enables a yes-no structure, so that the presence of an item implies the presence of another (so arrows are given with a bow) or the absence of an item enables another item to be present (so a bow or a crossbow can be given, but not both).
Each item in the list has a chance factor, that determines its probability to be generated.
Treasure lists exist in two variations:
Treasures are defined in .trs files in the archetypes tree. For historical reasons, many are groupes in treasures.trs
at the root or archetypes.
When a treasure must be generated, a magic level is used to determine what items are eligible for generation. An item on a treasure list can only be generated if its magic field is less then the magic level specified.
Some flags can alter the generating behaviour. In particular, GT_ONLY_GOOD will forbid the generation of cursed or damned items.
A maximum of 100 tries will be done to generate an item, after which the generation is considered to have failed.
The format is a line by line description of the treasure, and its options. The text before the first space is the field, remaining of the line is the value.
A treasure list definition starts by a treasure, treasureone, yes, no or more parameter. If treasure or treasureone is used, the part on the right of the first space is the treasure list name. The definition must end by a end line.
The line can start by spaces that will be ignored. A line starting by # is a comment and will be totally ignored.
The following fields are available:
arch
of; in this case magic
is ignored. If the item
is incompatible with artifact
, then no item is generatedlist
will be generated with this difficulty instead of the current onelist
list
, minimum magic required for this list to be generated; for an item
, the maximum magic it can have (capping the magic from the difficulty), this may restrict artifacts which may be generated; does not apply if artifact
is setEither arch or list must be set.
treasure rod arch rod_light chance 2 no arch rod_heavy chance 1 end end
This treasure means:
treasure poor_old arch bow chance 5 yes arch arrow nrof 6 end more arch b_ssword_2 magic 1 chance 5 no arch b_ssword_1 chance 10 no arch b_dagger chance 15 no arch stoneaxe chance 20 no arch club chance 25 end end end end more arch b_small_shield chance 4 more arch silvercoin nrof 8 chance 10 end
Given the magic of 1 or more, this list has:
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 |
Checks if a treasure if valid. Will also check its yes and no options.
Will LOG() to error.
t | treasure to check. |
tl | needed only so that the treasure name can be printed out. |
Definition at line 93 of file assets.cpp.
References find_treasurelist(), llevError, LOG(), treasurelist::name, and Floor::t.
|
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().
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().
treasurelist* find_treasurelist | ( | const char * | name | ) |
Search for the given treasurelist by name.
name | treasure list to search. |
Definition at line 249 of file assets.cpp.
References AssetsCollection< T, Key >::get(), manager, give::name, and AssetsManager::treasures().
Referenced by apply_race_and_class(), check_treasurelist(), create_all_treasures(), create_one_treasure(), do_harvest(), do_magic(), dragon_ability_gain(), dump_monster_treasure_rec(), find_treasure_by_name(), god_intervention(), key_change_class(), place_chest(), resurrect_player(), START_TEST(), and while().
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 1386 of file treasure.cpp.
References fatal(), OUT_OF_MEMORY, and Floor::t.
Referenced by TreasureWrapper::doAddChild(), TreasureLoader::loadTreasure(), and treasure_insert().
|
private |
Reads one treasure, including the 'yes', 'no' and 'more' options.
reader | where to read from. |
filename | full path of the file for logging purposes. |
Definition at line 40 of file TreasureLoader.cpp.
References add_string(), buf, bufferreader_current_line(), bufferreader_next_line(), fatal(), npc_dialog::filename, free_string(), AssetsCollection< T, Key >::get(), get_empty_treasure(), llevError, LOG(), TreasureLoader::m_archetypes, MAX_BUF, nroftreasures, SEE_LAST_ERROR, Floor::t, and autojail::value.
Referenced by TreasureLoader::load().
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().