Crossfire Server, Trunk  R21670
arch.c File Reference
#include "global.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "loader.h"
+ Include dependency graph for arch.c:

Go to the source code of this file.

Functions

static void add_arch (archetype *at)
 
void arch_info (object *op)
 
objectarch_to_object (archetype *at)
 
void check_generators (void)
 
static void check_spells (void)
 
void check_summoned (void)
 
void clear_archetable (void)
 
objectcreate_archetype (const char *name)
 
objectcreate_archetype_by_object_name (const char *name)
 
objectcreate_singularity (const char *name)
 
void dump_all_archetypes (void)
 
void dump_arch (archetype *at, StringBuffer *sb)
 
archetypefind_archetype (const char *name)
 
archetypefind_archetype_by_object_name (const char *name)
 
archetypefind_archetype_by_object_type_name (int type, const char *name)
 
static void first_arch_pass (FILE *fp)
 
void free_all_archs (void)
 
void free_arch (archetype *at)
 
archetypeget_archetype_by_skill_name (const char *skill, int type)
 
archetypeget_archetype_by_type_subtype (int type, int subtype)
 
archetypeget_archetype_struct (void)
 
static unsigned long hasharch (const char *str, int tablesize)
 
static void init_archetable (void)
 
void init_archetypes (void)
 
static void load_archetypes (void)
 
objectobject_create_arch (archetype *at)
 
static void second_arch_pass (FILE *fp)
 
archetypetry_find_archetype (const char *name)
 

Variables

static int arch_cmp = 0
 
int arch_init
 
static int arch_search = 0
 
static archetypearch_table [ARCHTABLE]
 

Detailed Description

All archetype-related functions.

Note
The naming of these functions is really poor - they are all pretty much named '.._arch_...', but they may more may not return archetypes. Some make the arch_to_object call, and thus return an object. Perhaps those should be called 'archob' functions to denote they return an object derived from the archetype. MSW 2003-04-29
Todo:
make the functions use the same order for parameters (type first, then name, or the opposite).

Definition in file arch.c.

Function Documentation

◆ add_arch()

static void add_arch ( archetype at)
static

Adds an archetype to the hashtable. Will call fatal() if archetype table is too small to contain archetypes.

Definition at line 710 of file arch.c.

References ARCHTABLE, ARCHTABLE_TOO_SMALL, fatal(), hasharch(), and archt::name.

Referenced by init_archetable().

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

◆ arch_info()

void arch_info ( object op)

Stores debug-information about how efficient the hashtable used for archetypes has been in the static errmsg array.

Definition at line 199 of file arch.c.

References arch_cmp, arch_search, draw_ext_info_format(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DEBUG, and NDI_UNIQUE.

Referenced by command_archs().

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

◆ arch_to_object()

object* arch_to_object ( archetype at)

Creates and returns a new object which is a copy of the given archetype. This function returns NULL if given a NULL pointer, else an object.

Parameters
atarchetype from which to get an object.
Returns
object of specified type.
Note
object_new() will either allocate memory or call fatal(), so returned value is never NULL.

Definition at line 571 of file arch.c.

References obj::arch, archt::clone, llevError, LOG(), object_copy_with_inv(), and object_new().

Referenced by add_abilities(), add_one_item(), animate_bomb(), animate_weapon(), apply_builder_floor(), apply_builder_window(), CREArtifactPanel::artifactChanged(), cast_bless(), cast_cause_disease(), cast_change_ability(), cast_cone(), cast_consecrate(), cast_curse(), cast_destruction(), cast_detection(), cast_heal(), cast_light(), cast_polymorph(), cast_raise_dead_spell(), cast_smite_spell(), change_luck(), change_object(), command_create(), cone_drop(), create_all_treasures(), create_archetype(), create_archetype_by_object_name(), create_aura(), create_bomb(), create_one_treasure(), create_player_cmd(), do_turn(), dragon_ability_gain(), drain_specific_stat(), explode_bullet(), fire_arch_from_position(), fire_bolt(), fire_swarm(), fix_container_multipart(), fix_summon_pet(), fix_walls(), generate_monster_arch(), get_player(), get_spell_by_name(), give_skill_by_name(), god_gives_present(), kill_player(), kill_player_not_permadeath(), kill_player_permadeath(), knowledge_alchemy_face(), magic_wall(), make_map_floor(), make_map_walls(), mood_change(), move_aura(), move_ball_spell(), move_symptom(), object_create_arch(), object_fix_multipart(), object_replace_insert_in_map(), pets_summon_object(), pick_joined_wall(), place_exits(), poison_living(), potion_type_apply(), print_monsters(), put_a_monster(), put_decor(), put_doors(), put_floor(), put_in_icecube(), remove_door(), remove_locked_door(), retrofit_joined_wall(), save_object_in_sb(), slow_living_by(), spell_effect(), spring_trap(), START_TEST(), town_portal_find_force(), write_mark(), and write_rune().

+ Here is the call graph for this function:

◆ check_generators()

void check_generators ( void  )

Check all generators have the other_arch set or something in inventory.

Definition at line 469 of file arch.c.

References archt::clone, fatal(), first_archetype, FLAG_CONTENT_ON_GEN, FLAG_GENERATOR, obj::inv, llevError, LOG(), archt::name, archt::next, obj::other_arch, QUERY_FLAG, and SEE_LAST_ERROR.

Referenced by load_archetypes().

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

◆ check_spells()

static void check_spells ( void  )
static

This ensures all spells have a skill defined, calling fatal() if any error was found.

Definition at line 513 of file arch.c.

References archt::clone, fatal(), first_archetype, llevError, LOG(), obj::name, archt::name, archt::next, SEE_LAST_ERROR, obj::skill, SPELL, and obj::type.

Referenced by init_beforeplay(), and load_archetypes().

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

◆ check_summoned()

void check_summoned ( void  )

This checks all summonable items for move_type and other things. Will call fatal() if an error is found.

Definition at line 497 of file arch.c.

References archt::clone, fatal(), first_archetype, llevError, LOG(), obj::move_type, obj::name, archt::name, archt::next, obj::other_arch, SEE_LAST_ERROR, SP_SUMMON_GOLEM, SPELL, obj::subtype, and obj::type.

Referenced by load_archetypes().

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

◆ clear_archetable()

void clear_archetable ( void  )

Initialise the hashtable used by the archetypes.

Definition at line 208 of file arch.c.

References ARCHTABLE.

Referenced by free_all_archs(), load_archetypes(), and START_TEST().

+ Here is the caller graph for this function:

◆ create_archetype()

object* create_archetype ( const char *  name)

Finds which archetype matches the given name, and returns a new object containing a copy of the archetype.

Parameters
namearchetype name
Returns
object of specified archetype, or a singularity. Will never be NULL.
Todo:
replace with object_create_arch() which is multi-part aware.

Definition at line 620 of file arch.c.

References arch_to_object(), create_singularity(), and find_archetype().

Referenced by alchemy_failure_effect(), apply_handle_yield(), become_follower(), blind_living(), cast_bless(), cast_cause_disease(), cast_change_ability(), cast_create_missile(), cast_create_town_portal(), cast_curse(), cast_spell(), cast_word_of_recall(), change_book(), charge_mana_effect(), command_use(), confuse_living(), convert_item(), converter_type_move_on(), create_aura(), do_symptoms(), eat_special_food(), examine_monster(), find_or_create_connection_for_map(), find_transmution_ob(), fire_swarm(), fix_generated_item(), god_examines_priest(), god_intervention(), grant_immunity(), keyplace(), kill_object(), kill_player_not_permadeath(), local_check_loaded_object(), locate_recipe_artifact(), lock_and_hide_doors(), make_object_glow(), move_marker(), CREMainWindow::onReportSpellDamage(), place_alchemy_objects(), place_chest(), place_exits(), potion_type_apply(), pray_at_altar(), prayer_failure(), put_a_monster(), recharge(), save_throw_object(), scroll_failure(), second_arch_pass(), setup(), spell_failure(), START_TEST(), surround_by_doors(), swap_random_stats(), town_portal_destroy_existing(), transmute_item_to_flower(), trap_show(), and write_rune().

+ Here is the call graph for this function:

◆ create_archetype_by_object_name()

object* create_archetype_by_object_name ( const char *  name)

Creates an object given the name that appears during the game (for example, "writing pen" instead of "stylus").

Parameters
namethe name we're searching for (ex: "writing pen"), must not be null
Returns
a corresponding object if found; a singularity object if not found.
Note
Note by MSW - it appears that it takes the full name and keeps shortening it until it finds a match. I re-wrote this so that it doesn't malloc it each time - not that this function is used much, but it otherwise had a big memory leak.

Definition at line 161 of file arch.c.

References arch_to_object(), create_singularity(), find_archetype_by_object_name(), and MAX_BUF.

Referenced by god_intervention(), local_check_loaded_object(), and START_TEST().

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

◆ create_singularity()

object* create_singularity ( const char *  name)

Creates a dummy object. This function is called by get_archetype() if it fails to find the appropriate archetype. Thus get_archetype() will be guaranteed to always return an object, and never NULL.

Parameters
namename to give the dummy object.
Returns
object of specified name. It fill have the FLAG_NO_PICK flag set.
Note
object_new() will either allocate memory or call fatal(), so returned value is never NULL.

Definition at line 597 of file arch.c.

References add_string(), obj::arch, ARCH_SINGULARITY, empty_archetype, FLAG_NO_PICK, MAX_BUF, obj::name, obj::name_pl, object_new(), SET_FLAG, and snprintf.

Referenced by create_archetype(), create_archetype_by_object_name(), and START_TEST().

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

◆ dump_all_archetypes()

void dump_all_archetypes ( void  )

Dumps all archetypes to debug-level output. If you run crossfire with debug, and enter DM-mode, you can trigger this with the "dumpallarchetypes" command.

Definition at line 245 of file arch.c.

References dump_arch(), first_archetype, llevDebug, LOG(), archt::more, archt::next, stringbuffer_finish(), and stringbuffer_new().

Referenced by command_dumpallarchetypes().

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

◆ dump_arch()

void dump_arch ( archetype at,
StringBuffer sb 
)

Dumps an archetype to buffer.

Parameters
atarchetype to dump. Must not be NULL.
sbbuffer that will contain dumped information.

Definition at line 236 of file arch.c.

References archt::clone, and object_dump().

Referenced by dump_all_archetypes().

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

◆ find_archetype()

archetype* find_archetype ( const char *  name)

Finds, using the hashtable, which archetype matches the given name. Will LOG() if not found.

Returns
pointer to the found archetype, otherwise NULL.
See also
try_find_archetype
Todo:
replace by try_find_archetype() when suitable

Definition at line 695 of file arch.c.

References llevError, LOG(), and try_find_archetype().

Referenced by alchemy_object(), alchemyTable(), animate_bomb(), apply_builder_window(), apply_map_builder(), artifact_get_face(), can_pay(), cast_consecrate(), cast_create_missile(), cast_heal(), cast_raise_dead_spell(), cctk_create_game_object(), change_luck(), check_recipe(), check_spells(), CREMapInformationManager::checkInventory(), CREArtifactPanel::computeMadeViaAlchemy(), create_archetype(), do_harvest(), drain_specific_stat(), dump_alchemy(), dump_alchemy_costs(), find_enclosed_spot(), find_next_coin(), fix_flesh_item(), fix_walls(), CREUtils::formulaeNode(), init_archetype_pointers(), init_archetypes(), init_races(), kill_player_not_permadeath(), kill_player_permadeath(), knowledge_alchemy_can_use_item(), knowledge_alchemy_detail(), knowledge_alchemy_face(), knowledge_alchemy_summary(), knowledge_god_face(), knowledge_monster_detail(), knowledge_monster_face(), knowledge_monster_summary(), load_treasure(), magic_wall(), make_formula_book(), monsterFight(), msgfile_msg(), object_replace_insert_in_map(), op_on_battleground(), pay_from_container(), perceive_self(), place_exits(), place_fountain_with_specials(), poison_living(), CREMapInformationManager::process(), process_map(), put_a_monster(), put_in_icecube(), remove_depletion(), restore_player(), save_object_in_sb(), second_arch_pass(), sell_item(), CREWrapperFormulae::setFormulae(), CREFormulaePanel::setItem(), slow_living_by(), START_TEST(), and town_portal_destroy_existing().

+ Here is the call graph for this function:

◆ find_archetype_by_object_name()

archetype* find_archetype_by_object_name ( const char *  name)

This function retrieves an archetype given the name that appears during the game (for example, "writing pen" instead of "stylus"). It does not use the hashtable system, but browse the whole archlist each time. I suggest not to use it unless you really need it because of performance issue. It is currently used by scripting extensions (create-object). Params:

Parameters
namethe name we're searching for (ex: "writing pen")
Returns
the archetype found or NULL if nothing was found

Definition at line 57 of file arch.c.

References archt::clone, find_string(), first_archetype, obj::name, and archt::next.

Referenced by artifact_describe(), CREUtils::artifactNode(), cfapi_object_create(), command_create(), create_archetype_by_object_name(), knowledge_god_detail(), knowledge_god_validate(), and START_TEST().

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

◆ find_archetype_by_object_type_name()

archetype* find_archetype_by_object_type_name ( int  type,
const char *  name 
)

This function retrieves an archetype by type and name that appears during the game. It is basically the same as find_archetype_by_object_name() except that it considers only items of the given type.

Parameters
typeitem type we're searching
namethe name we're searching for (ex: "writing pen")

Definition at line 84 of file arch.c.

References archt::clone, first_archetype, obj::name, archt::next, and obj::type.

Referenced by cast_create_food(), and START_TEST().

+ Here is the caller graph for this function:

◆ first_arch_pass()

static void first_arch_pass ( FILE *  fp)
static

Reads/parses the archetype-file, and copies into a linked list of archetype-structures. Called through load_archetypes()

Will discard object in archetypes, those are handled by second_arch_pass().

Parameters
fpopened file descriptor which will be used to read the archetypes.

Definition at line 348 of file arch.c.

References obj::arch, archt::clone, obj::face, first_archetype, FLAG_MONSTER, get_archetype_struct(), obj::head, archt::head, LL_MORE, LL_NORMAL, LO_NEWFILE, load_object(), obj::more, archt::next, QUERY_FLAG, SET_FLAG, obj::speed_left, archt::tail_x, archt::tail_y, obj::x, and obj::y.

Referenced by load_archetypes().

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

◆ free_all_archs()

void free_all_archs ( void  )

Frees all memory allocated to archetypes. After calling this, it's possible to call again init_archetypes() to reload data.

Definition at line 289 of file arch.c.

References clear_archetable(), first_archetype, free_arch(), llevDebug, LOG(), archt::more, and archt::next.

Referenced by cleanup(), and START_TEST().

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

◆ free_arch()

void free_arch ( archetype at)

Frees archetype.

Parameters
atarchetype to free. Pointer becomes invalid after the call.

Definition at line 266 of file arch.c.

References archt::clone, free_string(), obj::msg, obj::name, archt::name, obj::name_pl, object_free_key_values(), obj::race, obj::slaying, and obj::title.

Referenced by free_all_archs(), and object_free().

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

◆ get_archetype_by_skill_name()

archetype* get_archetype_by_skill_name ( const char *  skill,
int  type 
)

Retrieves an archetype by skill name and type. This is a lot like the other get_archetype_ functions, with different options.

Parameters
skillskill to search for. Must not be NULL.
typeitem type to search for. -1 means that it doesn't matter.
Returns
matching archetype, or NULL if none found.

Definition at line 108 of file arch.c.

References archt::clone, first_archetype, archt::next, obj::skill, and obj::type.

Referenced by examine(), give_skill_by_name(), and START_TEST().

+ Here is the caller graph for this function:

◆ get_archetype_by_type_subtype()

archetype* get_archetype_by_type_subtype ( int  type,
int  subtype 
)

Retrieves an archetype by type and subtype. Similiar to other get_archetype_ functions. This returns the first archetype that matches both the type and subtype. type and subtype can be -1 to say ignore, but in this case, the match it does may not be very useful. This function is most useful when subtypes are known to be unique for a particular type (eg, skills)

Parameters
typeobject type to search for. -1 means any
subtypeobject subtype to search for. -1 means any
Returns
matching archetype, or NULL if none found.

Definition at line 137 of file arch.c.

References archt::clone, first_archetype, archt::next, obj::subtype, and obj::type.

Referenced by CREUtils::artifactNode(), become_follower(), calculate_difficulty(), create_player_cmd(), START_TEST(), and write_on_item().

+ Here is the caller graph for this function:

◆ get_archetype_struct()

archetype* get_archetype_struct ( void  )

Allocates, initialises and returns the pointer to an archetype structure.

Returns
new archetype structure, will never be NULL.
Note
this function will call fatal() if it can't allocate memory.

Definition at line 314 of file arch.c.

References CALLOC, CLEAR_FLAG, fatal(), FLAG_FREED, FLAG_REMOVED, object_clear(), OUT_OF_MEMORY, and SET_FLAG.

Referenced by first_arch_pass(), local_check_loaded_object(), and START_TEST().

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

◆ hasharch()

static unsigned long hasharch ( const char *  str,
int  tablesize 
)
static

Hash-function used by the arch-hashtable.

Parameters
strarchetype name
tablesizesize of the hash table
Returns
hash of the archetype name

Definition at line 639 of file arch.c.

References MAXSTRING.

Referenced by add_arch(), and try_find_archetype().

+ Here is the caller graph for this function:

◆ init_archetable()

static void init_archetable ( void  )
static

An alternative way to init the hashtable which is slower, but works...

Definition at line 215 of file arch.c.

References add_arch(), archt::clone, first_archetype, llevDebug, llevError, LOG(), archt::more, obj::name, archt::name, and archt::next.

Referenced by load_archetypes().

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

◆ init_archetypes()

void init_archetypes ( void  )

Initialises the internal linked list of archetypes (read from file). Then the global empty_archetype pointer is initialised. Can be called multiple times, will just return.

Definition at line 183 of file arch.c.

References arch_init, empty_archetype, fatal(), find_archetype(), first_archetype, load_archetypes(), and SEE_LAST_ERROR.

Referenced by cctk_init_std_archetypes(), generate_map(), init_beforeplay(), init_library(), main(), and START_TEST().

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

◆ load_archetypes()

static void load_archetypes ( void  )
static

Loads all archetypes and treasures. First initialises the archtype hash-table (init_archetable()). Reads and parses the archetype file (with the first and second-pass functions). Then initialises treasures by calling load_treasures().

Definition at line 534 of file arch.c.

References Settings::archetypes, check_generators(), check_spells(), check_summoned(), clear_archetable(), Settings::datadir, first_arch_pass(), init_archetable(), llevDebug, llevError, load_treasures(), LOG(), MAX_BUF, second_arch_pass(), settings, and snprintf.

Referenced by init_archetypes().

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

◆ object_create_arch()

object* object_create_arch ( archetype at)

Create a full object using the given archetype. This instanciate not only the archetype but also all linked archetypes in case of multisquare archetype.

Parameters
atarchetype to instanciate. Must not be NULL.
Returns
pointer to head of instance.
Note
will never return NULL.

Definition at line 736 of file arch.c.

References arch_to_object(), archt::clone, obj::head, obj::more, archt::more, obj::x, and obj::y.

Referenced by apply_map_builder(), cast_detection(), cctk_create_game_object(), cfapi_object_create(), command_create(), convert_item(), do_harvest(), CRECombatSimulator::fight(), include_map_in_map(), monsterFight(), move_creator(), msgfile_msg(), place_monsters(), and START_TEST().

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

◆ second_arch_pass()

static void second_arch_pass ( FILE *  fp)
static

Reads the archetype file once more, and links all pointers between archetypes and treasure lists. Must be called after first_arch_pass().

This also handles putting items in inventory when defined in archetype.

Parameters
fpfile fron which to read. Won't be rewinded.

Definition at line 416 of file arch.c.

References ARCHETYPE_ISSUE, archt::clone, create_archetype(), fatal(), find_archetype(), find_treasurelist(), llevError, LO_LINEMODE, load_object(), LOG(), MAX_BUF, archt::name, object_free_drop_inventory(), object_insert_in_ob(), obj::other_arch, and obj::randomitems.

Referenced by load_archetypes().

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

◆ try_find_archetype()

archetype* try_find_archetype ( const char *  name)

Finds, using the hashtable, which archetype matches the given name. Will not LOG() if not found.

Returns
pointer to the found archetype, otherwise NULL.
See also
find_archetype()

Definition at line 666 of file arch.c.

References arch_cmp, arch_search, ARCHTABLE, hasharch(), and archt::name.

Referenced by annotate_ob(), artifact_describe(), CREArtifactPanel::artifactChanged(), CREUtils::artifactNode(), cfapi_map_find_by_archetype_name(), cfapi_object_create(), cfapi_object_find_archetype_inside(), check_probe(), command_create(), create_player_cmd(), find_archetype(), knowledge_monster_validate(), pick_joined_wall(), retrofit_joined_wall(), send_arch_info(), and send_race_info().

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

Variable Documentation

◆ arch_cmp

int arch_cmp = 0
static

How many strcmp's

Definition at line 39 of file arch.c.

Referenced by arch_info(), and try_find_archetype().

◆ arch_init

int arch_init

True if doing arch initialization

Definition at line 41 of file arch.c.

Referenced by init_archetypes(), local_check_loaded_object(), object_update_speed(), and teardown().

◆ arch_search

int arch_search = 0
static

How many searches

Definition at line 40 of file arch.c.

Referenced by arch_info(), and try_find_archetype().

◆ arch_table

archetype* arch_table[ARCHTABLE]
static

Definition at line 38 of file arch.c.