Crossfire Server, Trunk
Treasure lists

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)
 
treasurelistfind_treasurelist (const char *name)
 
objectgenerate_treasure (treasurelist *t, int difficulty)
 
treasureget_empty_treasure (void)
 
treasureTreasureLoader::loadTreasure (BufferReader *reader, const std::string &filename)
 
static void put_treasure (object *op, object *creator, int flags)
 

Detailed Description

Introduction

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:

Treasure files

Treasures are defined in .trs files in the archetypes tree. For historical reasons, many are groupes in treasures.trs at the root or archetypes.

Treasure generation

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.

Treasure file format

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:

Either arch or list must be set.

Simple example

treasure rod
 arch rod_light
 chance 2
 no
  arch rod_heavy
  chance 1
  end
end

This treasure means:

Complex example

 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:

Function Documentation

◆ change_treasure()

static void change_treasure ( treasure t,
object op 
)
static

if there are change_xxx commands in the treasure, we include the changes in the generated object

Parameters
ttreasure.
opactual 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().

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

◆ check_treasurelist()

static void check_treasurelist ( treasure t,
const treasurelist tl 
)
static

Checks if a treasure if valid. Will also check its yes and no options.

Will LOG() to error.

Parameters
ttreasure to check.
tlneeded 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.

+ Here is the call graph for this function:

◆ create_all_treasures()

static void create_all_treasures ( treasure t,
object op,
int  flag,
int  difficulty,
int  tries 
)
static

Creates all the treasures.

Parameters
twhat to generate.
opfor who to generate the treasure.
flagcombination of GT_xxx values.
difficultymap difficulty.
triesto 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().

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

◆ create_one_treasure()

static void create_one_treasure ( treasurelist tl,
object op,
int  flag,
int  difficulty,
int  tries 
)
static

Creates one treasure from the list.

Parameters
tlwhat to generate.
opfor who to generate the treasure.
flagcombination of GT_xxx values.
difficultymap difficulty.
triesto avoid infinite recursion.
Note
can abort() if treasure has errors.

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().

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

◆ create_treasure()

void create_treasure ( treasurelist t,
object op,
int  flag,
int  difficulty,
int  tries 
)

This calls the appropriate treasure creation function.

Parameters
twhat to generate.
opfor who to generate the treasure.
flagcombination of GT_xxx values.
difficultymap difficulty.
triesto 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().

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

◆ do_single_item()

static void do_single_item ( treasure t,
object op,
int  flag,
int  difficulty 
)
static

Creates the item for a treasure.

Parameters
twhat to generate.
opfor who to generate the treasure.
flagcombination of GT_xxx values.
difficultymap 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().

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

◆ find_treasurelist()

treasurelist* find_treasurelist ( const char *  name)

Search for the given treasurelist by name.

Parameters
nametreasure list to search.
Returns
match, or NULL if treasurelist doesn't exist or is 'none'.

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().

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

◆ generate_treasure()

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.

Warning
an error will be LOG()ed if more than one item is generated.
Parameters
ttreasure list to generate from.
difficultytreasure difficulty.
Returns
generated treasure. Can be NULL if no suitable treasure was found.

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().

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

◆ get_empty_treasure()

treasure* get_empty_treasure ( void  )

Allocate and return the pointer to an empty treasure structure.

Returns
new structure, blanked, never NULL.
Note
will call fatal() if memory allocation error.

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().

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

◆ loadTreasure()

treasure * TreasureLoader::loadTreasure ( BufferReader reader,
const std::string &  filename 
)
private

Reads one treasure, including the 'yes', 'no' and 'more' options.

Parameters
readerwhere to read from.
filenamefull path of the file for logging purposes.
Todo:
check if change_name is still used, and remove it if no.

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().

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

◆ put_treasure()

static void put_treasure ( object op,
object creator,
int  flags 
)
static

Inserts generated treasure where it should go.

Parameters
optreasure just generated.
creatorfor which object the treasure is being generated.
flagscombination 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().

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