Crossfire Server, Branch 1.12
R12190
|
All archetype-related functions. More...
Go to the source code of this file.
Defines | |
#define | TIME_ARCH_LOAD 0 |
If set, does a little timing on the archetype load. | |
Functions | |
static void | add_arch (archetype *at) |
Adds an archetype to the hashtable. | |
void | arch_info (object *op) |
Stores debug-information about how efficient the hashtable used for archetypes has been in the static errmsg array. | |
object * | arch_to_object (archetype *at) |
Creates and returns a new object which is a copy of the given archetype. | |
void | clear_archetable (void) |
Initialise the hashtable used by the archetypes. | |
object * | create_archetype (const char *name) |
Finds which archetype matches the given name, and returns a new object containing a copy of the archetype. | |
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"). | |
object * | create_singularity (const char *name) |
Creates a dummy object. | |
void | dump_all_archetypes (void) |
Dumps _all_ archetypes to debug-level output. | |
void | dump_arch (archetype *at, StringBuffer *sb) |
Dumps an archetype to buffer. | |
archetype * | find_archetype (const char *name) |
Finds, using the hashtable, which archetype matches the given 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"). | |
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. | |
static void | first_arch_pass (FILE *fp) |
Reads/parses the archetype-file, and copies into a linked list of archetype-structures. | |
void | free_all_archs (void) |
Frees all memory allocated to archetypes. | |
void | free_arch (archetype *at) |
Frees archetype. | |
archetype * | get_archetype_by_skill_name (const char *skill, int type) |
Retrieves an archetype by skill name and type. | |
archetype * | get_archetype_by_type_subtype (int type, int subtype) |
Retrieves an archetype by type and subtype. | |
archetype * | get_archetype_struct (void) |
Allocates, initialises and returns the pointer to an archetype structure. | |
static unsigned long | hasharch (const char *str, int tablesize) |
Hash-function used by the arch-hashtable. | |
static void | init_archetable (void) |
An alternative way to init the hashtable which is slower, but _works_... | |
void | init_archetypes (void) |
Initialises the internal linked list of archetypes (read from file). | |
static void | load_archetypes (void) |
Loads all archetypes and treasures. | |
object * | object_create_arch (archetype *at) |
Create a full object using the given archetype. | |
static void | second_arch_pass (FILE *fp) |
Reads the archetype file once more, and links all pointers between archetypes and treasure lists. | |
archetype * | try_find_archetype (const char *name) |
Finds, using the hashtable, which archetype matches the given name. | |
Variables | |
static int | arch_cmp = 0 |
How many strcmp's. | |
int | arch_init |
True if doing arch initialization. | |
static int | arch_search = 0 |
How many searches. | |
static archetype * | arch_table [ARCHTABLE] |
All archetype-related functions.
Definition in file arch.c.
#define TIME_ARCH_LOAD 0 |
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 715 of file arch.c.
References arch_table, ARCHTABLE, ARCHTABLE_TOO_SMALL, fatal(), and hasharch().
Referenced by init_archetable().
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 209 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().
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.
at | archetype from which to get an object. |
Definition at line 576 of file arch.c.
References copy_object_with_inv(), get_object(), llevError, LOG(), and warn_archetypes.
Referenced by add_abilities(), animate_bomb(), animate_weapon(), apply_builder_floor(), apply_builder_window(), cast_cause_disease(), cast_cone(), cast_consecrate(), cast_create_town_portal(), cast_destruction(), cast_detection(), 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(), do_turn(), dragon_ability_gain(), drain_specific_stat(), explode_bullet(), fire_arch_from_position(), fire_bolt(), fire_bullet(), fire_swarm(), fix_container_multipart(), fix_multipart_object(), fix_summon_pet(), fix_walls(), generate_monster_arch(), get_player(), get_spell_by_name(), give_skill_by_name(), god_gives_present(), hit_player(), include_map_in_map(), insert_multisquare_ob_in_map(), kill_player(), magic_wall(), make_map_floor(), make_map_walls(), mood_change(), move_aura(), move_ball_spell(), move_symptom(), object_create_arch(), pick_joined_wall(), place_chest(), place_exits(), place_monsters(), poison_living(), print_monsters(), put_a_monster(), put_decor(), put_doors(), put_floor(), remove_door(), remove_locked_door(), replace_insert_ob_in_map(), retrofit_joined_wall(), save_throw_object(), slow_living(), spell_effect(), spring_trap(), START_TEST(), summon_object(), write_mark(), and write_rune().
void clear_archetable | ( | void | ) |
Initialise the hashtable used by the archetypes.
Definition at line 219 of file arch.c.
References arch_table, and ARCHTABLE.
Referenced by free_all_archs(), load_archetypes(), and START_TEST().
object* create_archetype | ( | const char * | name | ) |
Finds which archetype matches the given name, and returns a new object containing a copy of the archetype.
name | archetype name |
Definition at line 625 of file arch.c.
References arch_to_object(), create_singularity(), and find_archetype().
Referenced by alchemy(), alchemy_failure_effect(), become_follower(), blind_living(), cast_bless(), cast_cause_disease(), cast_change_ability(), cast_create_missile(), cast_create_town_portal(), cast_curse(), cast_word_of_recall(), change_book(), charge_mana_effect(), confuse_living(), convert_item(), converter_type_move_on(), do_symptoms(), eat_special_food(), find_or_create_connection_for_map(), find_transmution_ob(), fire_swarm(), fix_generated_item(), god_examines_priest(), god_intervention(), grant_immunity(), handle_apply_yield(), keyplace(), kill_object(), kill_player(), local_check_loaded_object(), locate_recipe_artifact(), lock_and_hide_doors(), make_object_glow(), move_marker(), place_chest(), place_exits(), place_fountain_with_specials(), 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(), transmute_item_to_flower(), trap_show(), and write_rune().
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").
name | the name we're searching for (ex: "writing pen"), must not be null |
Definition at line 173 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().
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.
name | name to give the dummy object. |
Definition at line 603 of file arch.c.
References add_string(), FLAG_NO_PICK, get_object(), MAX_BUF, SET_FLAG, and snprintf().
Referenced by create_archetype(), create_archetype_by_object_name(), and START_TEST().
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 252 of file arch.c.
References dump_arch(), first_archetype, llevDebug, LOG(), stringbuffer_finish(), and stringbuffer_new().
Referenced by command_dumpallarchetypes().
void dump_arch | ( | archetype * | at, |
StringBuffer * | sb | ||
) |
Dumps an archetype to buffer.
at | archetype to dump. Must not be NULL. |
sb | buffer that will contain dumped information. |
Definition at line 243 of file arch.c.
References dump_object().
Referenced by dump_all_archetypes().
archetype* find_archetype | ( | const char * | name | ) |
Finds, using the hashtable, which archetype matches the given name.
Will LOG() if not found.
Definition at line 700 of file arch.c.
References llevError, LOG(), try_find_archetype(), and warn_archetypes.
Referenced by animate_bomb(), apply_builder_window(), apply_map_builder(), CREUtils::artifactNode(), can_pay(), cast_consecrate(), cast_create_missile(), cast_create_town_portal(), cast_heal(), cast_raise_dead_spell(), cctk_create_game_object(), change_luck(), check_recipe(), check_spells(), command_create(), command_use(), create_archetype(), drain_specific_stat(), dump_alchemy(), dump_alchemy_costs(), find_enclosed_spot(), find_next_coin(), fix_flesh_item(), fix_walls(), CREUtils::formulaeNode(), god_intervention(), init_archetype_pointers(), init_archetypes(), init_races(), kill_player(), load_treasure(), magic_wall(), make_formula_book(), op_on_battleground(), pay_from_container(), perceive_self(), place_exits(), poison_living(), potion_type_apply(), process_map(), put_a_monster(), replace_insert_ob_in_map(), save_throw_object(), second_arch_pass(), sell_item(), CREFormulaePanel::setRecipe(), slow_living(), and START_TEST().
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:
name | the name we're searching for (ex: "writing pen") |
Definition at line 70 of file arch.c.
References add_string(), first_archetype, and free_string().
Referenced by cfapi_object_create(), command_create(), create_archetype_by_object_name(), CREArtifactPanel::setArtifact(), and START_TEST().
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.
type | item type we're searching |
name | the name we're searching for (ex: "writing pen") |
Definition at line 96 of file arch.c.
References first_archetype.
Referenced by cast_create_food(), and START_TEST().
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().
fp | opened file descriptor which will be used to read the archetypes. |
Definition at line 357 of file arch.c.
References clear_object(), copy_object(), first_archetype, FLAG_MONSTER, free_object(), get_archetype_struct(), get_object(), LL_MORE, LL_NORMAL, load_object(), QUERY_FLAG, and SET_FLAG.
Referenced by load_archetypes().
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 298 of file arch.c.
References clear_archetable(), first_archetype, free_arch(), llevDebug, and LOG().
Referenced by cleanup(), and START_TEST().
void free_arch | ( | archetype * | at | ) |
Frees archetype.
at | archetype to free. Pointer becomes invalid after the call. |
Definition at line 273 of file arch.c.
References free_key_values(), and free_string().
Referenced by free_all_archs(), and free_object2().
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.
skill | skill to search for. Must not be NULL. |
type | item type to search for. -1 means that it doesn't matter. |
Definition at line 120 of file arch.c.
References first_archetype.
Referenced by give_skill_by_name(), and START_TEST().
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)
type | object type to search for. -1 means any |
subtype | object subtype to search for. -1 means any |
Definition at line 149 of file arch.c.
References first_archetype.
Referenced by CREUtils::artifactNode(), become_follower(), calculate_difficulty(), START_TEST(), and write_on_item().
archetype* get_archetype_struct | ( | void | ) |
Allocates, initialises and returns the pointer to an archetype structure.
Definition at line 323 of file arch.c.
References CALLOC, CLEAR_FLAG, clear_object(), fatal(), FLAG_FREED, FLAG_REMOVED, OUT_OF_MEMORY, and SET_FLAG.
Referenced by first_arch_pass(), local_check_loaded_object(), and START_TEST().
static unsigned long hasharch | ( | const char * | str, |
int | tablesize | ||
) | [static] |
Hash-function used by the arch-hashtable.
str | archetype name |
tablesize | size of the hash table |
Definition at line 644 of file arch.c.
References MAXSTRING.
Referenced by add_arch(), and try_find_archetype().
static void init_archetable | ( | void | ) | [static] |
An alternative way to init the hashtable which is slower, but _works_...
Definition at line 226 of file arch.c.
References add_arch(), first_archetype, llevDebug, and LOG().
Referenced by load_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 195 of file arch.c.
References arch_init, empty_archetype, find_archetype(), first_archetype, and load_archetypes().
Referenced by cctk_init_std_archetypes(), init_beforeplay(), init_library(), main(), and START_TEST().
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 507 of file arch.c.
References Settings::archetypes, check_generators(), clear_archetable(), close_and_delete(), Settings::datadir, first_arch_pass(), GETTIMEOFDAY, init_archetable(), llevDebug, llevError, load_treasures(), LOG(), MAX_BUF, open_and_uncompress(), second_arch_pass(), settings, snprintf(), and warn_archetypes.
Referenced by init_archetypes().
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.
at | archetype to instanciate. Must not be NULL. |
Definition at line 741 of file arch.c.
References arch_to_object().
Referenced by apply_map_builder(), cctk_create_game_object(), cfapi_object_create(), command_create(), command_use(), convert_item(), move_creator(), and START_TEST().
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.
fp | file fron which to read. Won't be rewinded. |
Definition at line 437 of file arch.c.
References create_archetype(), find_archetype(), find_treasurelist(), free_object(), insert_ob_in_ob(), llevError, LO_LINEMODE, load_object(), LOG(), and MAX_BUF.
Referenced by load_archetypes().
archetype* try_find_archetype | ( | const char * | name | ) |
Finds, using the hashtable, which archetype matches the given name.
Will not LOG() if not found.
Definition at line 671 of file arch.c.
References arch_cmp, arch_search, arch_table, ARCHTABLE, and hasharch().
Referenced by cfapi_map_present_arch_by_name(), cfapi_object_create(), cfapi_object_find_archetype_inside(), find_archetype(), pick_joined_wall(), retrofit_joined_wall(), send_race_info(), and CREArtifactPanel::setArtifact().
int arch_cmp = 0 [static] |
How many strcmp's.
Definition at line 52 of file arch.c.
Referenced by arch_info(), and try_find_archetype().
int arch_init |
True if doing arch initialization.
Definition at line 54 of file arch.c.
Referenced by init_archetypes(), and update_ob_speed().
int arch_search = 0 [static] |
How many searches.
Definition at line 53 of file arch.c.
Referenced by arch_info(), and try_find_archetype().
archetype* arch_table[ARCHTABLE] [static] |
Definition at line 51 of file arch.c.
Referenced by add_arch(), clear_archetable(), and try_find_archetype().