Crossfire Server, Branch 1.12  R12190
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
static void check_treasurelist (const treasure *t, const treasurelist *tl)
 Checks if a treasure if valid.
static void create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries)
 Creates all the treasures.
static void create_one_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries)
 Creates one treasure from the list.
void create_treasure (treasurelist *t, object *op, int flag, int difficulty, int tries)
 This calls the appropriate treasure creation function.
treasurelistfind_treasurelist (const char *name)
 Searches for the given treasurelist in the globally linked list of treasurelists which has been built by load_treasures().
object * generate_treasure (treasurelist *t, int difficulty)
 This is similar to the old generate treasure function.
static treasureget_empty_treasure (void)
 Allocate and return the pointer to an empty treasure structure.
static treasurelistget_empty_treasurelist (void)
 Allocate and return the pointer to an empty treasurelist structure.
static treasureload_treasure (FILE *fp, int *line)
 Reads one treasure from the file, including the 'yes', 'no' and 'more' options.
void load_treasures (void)
 Opens LIBDIR/treasure and reads all treasure-declarations from it.
static void put_treasure (object *op, object *creator, int flags)
 Inserts generated treasure where it should go.

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

References add_string(), treasurestruct::change_arch, FREE_AND_COPY, free_string(), _change_arch::name, _change_arch::slaying, and _change_arch::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 200 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 390 of file treasure.c.

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

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

References arch_to_object(), treasurestruct::chance, change_treasure(), create_treasure(), find_treasurelist(), fix_generated_item(), FLAG_CURSED, FLAG_DAMNED, GT_INVISIBLE, GT_ONLY_GOOD, treasurestruct::item, treasureliststruct::items, llevDebug, llevError, LOG(), treasurestruct::magic, treasurestruct::name, treasurestruct::next, treasurestruct::nrof, put_treasure(), QUERY_FLAG, 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 499 of file treasure.c.

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

Referenced by auto_apply(), command_create(), create_all_treasures(), create_one_treasure(), do_auto_apply(), fix_auto_apply(), fix_generated_item(), fix_summon_pet(), generate_monster_arch(), generate_monster_inv(), generate_treasure(), give_initial_items(), god_intervention(), key_change_class(), polymorph_living(), put_a_monster(), rune_attack(), and summon_object().

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

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

Referenced by 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(), 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 
)

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.

Parameters:
ttreasure list to generate from.
difficultytreasure difficulty.
Returns:
generated treasure. Can be NULL if no suitable treasure was found.

Definition at line 524 of file treasure.c.

References create_treasure(), free_object(), get_object(), llevError, LOG(), and remove_ob().

Referenced by auto_apply(), 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 109 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 91 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 138 of file treasure.c.

References add_string(), treasurestruct::chance, treasurestruct::change_arch, 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, _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 224 of file treasure.c.

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

Referenced by load_archetypes(), and main().

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

References FLAG_MONSTER, FLAG_OBJ_ORIGINAL, GT_APPLY, GT_ENVIRONMENT, insert_ob_in_map(), insert_ob_in_ob(), monster_check_apply(), QUERY_FLAG, SET_FLAG, and SPELL.

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: