Crossfire Server, Trunk  R20513
Functions
Treasure lists

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...
 
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...
 
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 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 void put_treasure (object *op, object *creator, int flags)
 Inserts generated treasure where it should go. More...
 

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 two places:

During the collect process, all .trs files will be aggregated to the lib/treasures files to produce the final treasures files.

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

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

References add_string(), treasurestruct::change_arch, FREE_AND_COPY, free_string(), _change_arch::name, obj::name, obj::name_pl, _change_arch::slaying, obj::slaying, _change_arch::title, and obj::title.

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:

static void check_treasurelist ( const 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 197 of file treasure.c.

References treasurestruct::chance, find_treasurelist(), treasurestruct::item, llevError, LOG(), treasurestruct::name, treasureliststruct::name, treasurestruct::next, treasurestruct::next_no, and treasurestruct::next_yes.

Referenced by load_treasures().

Here is the call graph for this function:

Here is the caller graph for this function:

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

References arch_to_object(), treasurestruct::chance, change_treasure(), archt::clone, create_treasure(), find_treasurelist(), fix_generated_item(), GT_INVISIBLE, obj::invisible, treasurestruct::item, treasurestruct::magic, treasurestruct::name, treasurestruct::next, treasurestruct::next_no, treasurestruct::next_yes, treasurestruct::nrof, obj::nrof, put_treasure(), and RANDOM.

Referenced by create_treasure().

Here is the call graph for this function:

Here is the caller graph for this function:

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

References arch_to_object(), treasurestruct::chance, change_treasure(), archt::clone, create_treasure(), find_treasurelist(), fix_generated_item(), FLAG_CURSED, FLAG_DAMNED, GT_INVISIBLE, GT_ONLY_GOOD, obj::invisible, treasurestruct::item, treasureliststruct::items, llevDebug, llevError, LOG(), treasurestruct::magic, treasurestruct::name, treasurestruct::next, treasurestruct::nrof, obj::nrof, put_treasure(), QUERY_FLAG, RANDOM, and treasureliststruct::total_chance.

Referenced by create_treasure().

Here is the call graph for this function:

Here is the caller graph for this function:

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

References create_all_treasures(), create_one_treasure(), treasureliststruct::items, llevDebug, LOG(), and treasureliststruct::total_chance.

Referenced by apply_auto(), apply_auto_fix(), apply_race_and_class(), command_create(), create_all_treasures(), create_one_treasure(), do_auto_apply(), 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(), and rune_attack().

Here is the call graph for this function:

Here is the caller graph for this function:

treasurelist* find_treasurelist ( const char *  name)

Searches for the given treasurelist in the globally linked list of treasurelists which has been built by load_treasures().

Will LOG() to error if not found.

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

Definition at line 292 of file treasure.c.

References find_string(), first_treasurelist, llevError, LOG(), treasureliststruct::name, and treasureliststruct::next.

Referenced by apply_race_and_class(), check_treasurelist(), create_all_treasures(), create_one_treasure(), dragon_ability_gain(), dump_monster_treasure_rec(), find_treasure_by_name(), god_intervention(), key_change_class(), place_chest(), resurrect_player(), second_arch_pass(), START_TEST(), treasure_find_matching_type(), and CREUtils::treasureNode().

Here is the call graph for this function:

Here is the caller graph for this function:

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

References create_treasure(), obj::inv, llevError, LOG(), object_free_drop_inventory(), object_new(), and object_remove().

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:

static treasure* get_empty_treasure ( void  )
static

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

References treasurestruct::chance, fatal(), treasurestruct::item, treasurestruct::magic, treasurestruct::name, treasurestruct::next, treasurestruct::next_no, treasurestruct::next_yes, treasurestruct::nrof, and OUT_OF_MEMORY.

Referenced by load_treasure().

Here is the call graph for this function:

Here is the caller graph for this function:

static treasurelist* get_empty_treasurelist ( void  )
static

Allocate and return the pointer to an empty treasurelist structure.

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

Definition at line 85 of file treasure.c.

References fatal(), and OUT_OF_MEMORY.

Referenced by load_treasures().

Here is the call graph for this function:

Here is the caller graph for this function:

static treasure* load_treasure ( FILE *  fp,
int *  line 
)
static

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

Parameters
fpfile to read from.
[out]lineposition in file.
Returns
read structure, never NULL.
Todo:
check if change_name is still used, and remove it if no.

Definition at line 132 of file treasure.c.

References add_string(), treasurestruct::chance, treasurestruct::change_arch, fatal(), find_archetype(), get_empty_treasure(), treasurestruct::item, llevError, LOG(), treasurestruct::magic, MAX_BUF, _change_arch::name, treasurestruct::name, treasurestruct::next, treasurestruct::next_no, treasurestruct::next_yes, treasurestruct::nrof, nroftreasures, SEE_LAST_ERROR, _change_arch::slaying, and _change_arch::title.

Referenced by load_treasures().

Here is the call graph for this function:

Here is the caller graph for this function:

void load_treasures ( void  )

Opens LIBDIR/treasure and reads all treasure-declarations from it.

Each treasure is parsed with the help of load_treasure().

Will LOG() if file can't be accessed.

Definition at line 221 of file treasure.c.

References add_string(), treasurestruct::chance, check_treasurelist(), Settings::datadir, first_treasurelist, get_empty_treasurelist(), treasurestruct::item, treasureliststruct::items, llevError, load_treasure(), LOG(), MAX_BUF, treasurestruct::name, treasureliststruct::name, archt::name, treasurestruct::next, treasureliststruct::next, treasurestruct::next_no, treasurestruct::next_yes, settings, snprintf, treasureliststruct::total_chance, and Settings::treasures.

Referenced by ResourcesManager::load(), and load_archetypes().

Here is the call graph for this function:

Here is the caller graph for this function:

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

References FLAG_OBJ_ORIGINAL, GT_ENVIRONMENT, INS_NO_MERGE, INS_NO_WALK_ON, obj::map, object_insert_in_map_at(), object_insert_in_ob(), SET_FLAG, SPELL, obj::type, obj::x, and obj::y.

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: