Crossfire Server, Trunk
init.cpp File Reference
#include "global.h"
#include <stdlib.h>
#include <string.h>
#include "object.h"
#include "output_file.h"
#include "assets.h"
#include "AssetsManager.h"
+ Include dependency graph for init.cpp:

Go to the source code of this file.

Functions

void free_globals (void)
 
void init_attackmess (BufferReader *reader, const char *filename)
 
static void init_clocks (void)
 
static void init_defaults (void)
 
static void init_dynamic (void)
 
static void init_emergency_mappath (void)
 
static void init_environ (void)
 
void init_globals (void)
 
void init_library (void)
 
void load_assets (void)
 
void write_todclock (void)
 

Variables

archetypeamulet_arch
 
attackmess_t attack_mess [NROFATTACKMESS][MAXATTACKMESS]
 
Chaos_Attacks ATTACKS [22]
 
const char *const attacktype_desc [NROFATTACKS]
 
sstring blocks_prayer
 
const char *const change_resist_msg [NROFATTACKS]
 
archetypecrown_arch
 
archetypeempty_archetype
 
int exiting
 
artifactlistfirst_artifactlist
 
mapstructfirst_map
 
char first_map_ext_path [MAX_BUF]
 
char first_map_path [MAX_BUF]
 
playerfirst_player
 
regionfirst_region
 
FILE * logfile
 
materialtype_tmaterialt
 
long nrofallowedstr
 
long nrofartifacts
 
long nroferrors
 
long ob_count
 
const char *const resist_color [NROFATTACKS]
 
const char *const resist_plus [NROFATTACKS]
 
const char *const resist_save [NROFATTACKS]
 
archetypering_arch
 
struct Settings settings
 
const char *const spellpathnames [NRSPELLPATHS]
 
struct Statistics statistics
 
long trying_emergency_save
 
const char * undead_name
 

Detailed Description

Basic initialization for the common library.

Definition in file init.cpp.

Function Documentation

◆ free_globals()

void free_globals ( void  )

Cleans all memory allocated for global variables.

Will clear:

  • attack messages
  • emergency map settings
  • friendly list
  • experience
  • regions

Definition at line 443 of file init.cpp.

References assets_free(), attack_mess, blocks_prayer, clear_friendly_list(), Settings::emergency_mapname, first_region, FREE_AND_CLEAR, FREE_AND_CLEAR_STR, free_experience(), regiondef::jailmap, regiondef::longname, MAXATTACKMESS, navar-midane_pickup::msg, regiondef::msg, regiondef::name, regiondef::next, NROFATTACKMESS, settings, and undead_name.

Referenced by cleanup().

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

◆ init_attackmess()

void init_attackmess ( BufferReader reader,
const char *  filename 
)

Initializes the attack messages. Called by init_library().

Memory will be cleared by free_globals().

Definition at line 577 of file init.cpp.

References attack_mess, buf, attackmess::buf1, attackmess::buf2, attackmess::buf3, bufferreader_next_line(), npc_dialog::filename, attackmess::level, level, llevDebug, LOG(), strdup_local, and mail_login::total.

Referenced by assets_collect().

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

◆ init_clocks()

static void init_clocks ( void  )
static

Initializes the gametime and TOD counters Called by init_library().

Definition at line 541 of file init.cpp.

References npc_dialog::filename, llevDebug, llevError, Settings::localdir, LOG(), MAX_BUF, settings, todtick, and write_todclock().

Referenced by init_library().

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

◆ init_defaults()

static void init_defaults ( void  )
static

Initialises global variables which can be changed by options. Called by init_library().

Definition at line 478 of file init.cpp.

References nroferrors.

Referenced by init_globals().

+ Here is the caller graph for this function:

◆ init_dynamic()

static void init_dynamic ( void  )
static

Initializes first_map_path from the archetype collection, and check that some required archetype actually exist.

Must be called after archetypes have been initialized.

Note
will call exit() in case of error.

Definition at line 491 of file init.cpp.

References archt::clone, delete_map(), EXIT_PATH, fatal(), first_map_path, get_archetype_by_type_subtype(), llevError, LOG(), MAP, MAP_TYPE_DEFAULT, MAP_TYPE_LEGACY, ready_map_name(), SEE_LAST_ERROR, and strlcpy().

Referenced by init_library().

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

◆ init_emergency_mappath()

static void init_emergency_mappath ( void  )
static

This loads the emergency map information from a .emergency file in the map directory. Doing this makes it easier to switch between map distributions (don't need to recompile. Note that there is no reason I see that this could not be re-loaded during play, but it seems like there should be little reason to do that.

Note
If file doesn't exist, will not do anything.

Definition at line 274 of file init.cpp.

References Settings::datadir, Settings::emergency_mapname, EMERGENCY_MAPPATH, Settings::emergency_x, Settings::emergency_y, npc_dialog::filename, llevDebug, llevError, LOG(), Settings::mapdir, MAX_BUF, settings, and strdup_local.

Referenced by init_library().

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

◆ init_environ()

static void init_environ ( void  )
static

Initializes values from the environmental variables. it needs to be called very early, since command line options should overwrite these if specified.

Definition at line 365 of file init.cpp.

References Settings::datadir, Settings::localdir, Settings::mapdir, Settings::playerdir, settings, Settings::templatedir, Settings::tmpdir, and Settings::uniquedir.

Referenced by init_library().

+ Here is the caller graph for this function:

◆ init_globals()

void init_globals ( void  )

Initialises all global variables. Might use environment-variables as default for some of them.

Setups logfile, and such variables.

Definition at line 397 of file init.cpp.

References add_string(), amulet_arch, blocks_prayer, exiting, first_artifactlist, first_map, first_map_ext_path, first_player, init_defaults(), llevError, LOG(), logfile, Settings::logfilename, nrofallowedstr, nrofartifacts, ring_arch, settings, statistics, trying_emergency_save, and undead_name.

Referenced by cctk_init_std_archetypes(), generate_map(), init_library(), ResourcesManager::load(), and main().

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

◆ init_library()

void init_library ( void  )

It is vital that init_library() is called by any functions using this library. If you want to lessen the size of the program using the library, you can replace the call to init_library() with init_globals() and init_function_pointers(). Good idea to also call init_hash_table if you are doing any object loading.

Definition at line 324 of file init.cpp.

References assets_init(), attack_mess, attackmess::buf1, attackmess::buf2, attackmess::buf3, FALSE, fatal(), getManager(), i18n_init(), Settings::ignore_assets_errors, init_block(), init_clocks(), init_dynamic(), init_emergency_mappath(), init_environ(), init_experience(), init_globals(), init_hash_table(), init_objects(), init_stats(), attackmess::level, level, llevError, load_assets(), LOG(), MAXATTACKMESS, SEE_LAST_ERROR, and settings.

Referenced by generate_map(), init(), ResourcesManager::load(), and main().

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

◆ load_assets()

void load_assets ( void  )

Definition at line 311 of file init.cpp.

References ASSETS_ALL, assets_collect(), assets_end_load(), Settings::datadir, and settings.

Referenced by command_recollect(), and init_library().

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

◆ write_todclock()

void write_todclock ( void  )

Write out the current time to the file so time does not reset every time the server reboots.

Definition at line 524 of file init.cpp.

References npc_dialog::filename, Settings::localdir, MAX_BUF, of_close(), of_open(), settings, and todtick.

Referenced by clean_tmp_files(), init_clocks(), and tick_the_clock().

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

Variable Documentation

◆ amulet_arch

archetype * amulet_arch

Definition at line 125 of file init.cpp.

Referenced by fix_generated_item(), init_archetype_pointers(), and init_globals().

◆ attack_mess

◆ ATTACKS

Chaos_Attacks ATTACKS[22]
Initial value:
= {
{ AT_PHYSICAL, 0 },
{ AT_PHYSICAL, 0 },
{ AT_PHYSICAL, 0 },
{ AT_MAGIC, 1 },
{ AT_MAGIC, 1 },
{ AT_MAGIC, 1 },
{ AT_FIRE, 2 },
{ AT_FIRE, 2 },
{ AT_FIRE, 2 },
{ AT_ELECTRICITY, 3 },
{ AT_COLD, 4 },
{ AT_COLD, 4 },
{ AT_COLD, 4 },
{ AT_CONFUSION, 5 },
{ AT_POISON, 7 },
{ AT_POISON, 7 },
{ AT_POISON, 7 },
{ AT_SLOW, 8 },
{ AT_PARALYZE, 9 },
{ AT_FEAR, 10 }
}

Some local definitions for shuffle_attack().

Definition at line 81 of file init.cpp.

Referenced by hit_player(), and shuffle_attack().

◆ attacktype_desc

const char* const attacktype_desc[NROFATTACKS]
Initial value:
= {
"physical", "magic", "fire", "electricity", "cold", "confusion", "acid",
"drain", "weapon magic", "ghost hit", "poison", "slow", "paralyze",
"turn undead", "fear", "cancellation", "deplete", "death", "chaos",
"counterspell", "god power", "holy word", "blind", "internal", "life stealing",
"disease"
}

Short description of names of the attacktypes

Definition at line 40 of file init.cpp.

Referenced by command_resistances(), CREScriptEngine::CREScriptEngine(), describe_god(), main(), and CREMainWindow::onReportMaterials().

◆ blocks_prayer

sstring blocks_prayer

For update_position() mostly.

Definition at line 127 of file init.cpp.

Referenced by free_globals(), init_globals(), and update_position().

◆ change_resist_msg

const char* const change_resist_msg[NROFATTACKS]
Initial value:
= {
"physical", "magic", "fire", "electricity", "cold", "confusion", "acid",
"draining", "weapon magic", "ghosts", "poison", "slow", "paralyze",
"turn undead", "fear", "cancellation", "depletion", "death attacks", "chaos",
"counterspell", "god power", "holy word", "blinding attacks", "internal",
"life stealing", "disease"
}

These are the descriptions of the resistances displayed when a player puts on/takes off an item. See change_abil() in living.c.

Definition at line 70 of file init.cpp.

Referenced by change_abil(), command_resistances(), describe_item(), dragon_eat_flesh(), dragon_level_gain(), perceive_self(), and potion_type_apply().

◆ crown_arch

archetype * crown_arch

Definition at line 125 of file init.cpp.

Referenced by fix_generated_item(), and init_archetype_pointers().

◆ empty_archetype

archetype* empty_archetype

◆ exiting

int exiting

True if the game is about to exit.

Definition at line 115 of file init.cpp.

Referenced by init_globals(), and LOG().

◆ first_artifactlist

◆ first_map

◆ first_map_ext_path

char first_map_ext_path[MAX_BUF]

Path used for per-race start maps.

Definition at line 121 of file init.cpp.

Referenced by CREMapInformationManager::browseMaps(), init_globals(), and key_change_class().

◆ first_map_path

char first_map_path[MAX_BUF]

◆ first_player

◆ first_region

◆ logfile

◆ materialt

◆ nrofallowedstr

long nrofallowedstr

Only used in malloc_info().

Definition at line 117 of file init.cpp.

Referenced by init_globals(), ArtifactLoader::load(), and malloc_info().

◆ nrofartifacts

long nrofartifacts

Only used in malloc_info().

Definition at line 116 of file init.cpp.

Referenced by init_globals(), ArtifactLoader::load(), and malloc_info().

◆ nroferrors

long nroferrors

If it exceeds MAX_ERRORS, call fatal()

Definition at line 112 of file init.cpp.

Referenced by init_defaults(), LOG(), and server_main().

◆ ob_count

long ob_count

Definition at line 123 of file init.cpp.

Referenced by object_new().

◆ resist_color

const char* const resist_color[NROFATTACKS]
Initial value:
= {
"#FF15CD", "#930C76", "red", "blue", "#2CFFFF", NULL, NULL, NULL, NULL, NULL, "green", NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
}

Colors to add to the resistances for media tags.

Definition at line 61 of file init.cpp.

Referenced by describe_resistance().

◆ resist_plus

const char* const resist_plus[NROFATTACKS]
Initial value:
= {
"armour", "resist magic", "resist fire", "resist electricity", "resist cold",
"resist confusion", "resist acid", "resist drain",
"resist weaponmagic", "resist ghosthit", "resist poison", "resist slow",
"resist paralyzation", "resist turn undead", "resist fear",
"resist cancellation", "resist depletion", "resist death", "resist chaos",
"resist counterspell", "resist god power", "resist holy word",
"resist blindness", "resist internal", "resist life stealing",
"resist diseases"
}

Attack types to show to the player.

Definition at line 49 of file init.cpp.

Referenced by MonsterResistances::buildGraph(), describe_resistance(), and old_describe_monster().

◆ resist_save

const char* const resist_save[NROFATTACKS]
Initial value:
= {
"physical ", "magic ", "fire ", "electricity ", "cold ", "confusion ", "acid ",
"drain ", "weaponmagic ", "ghosthit ", "poison ", "slow ", "paralyze ",
"turn_undead ", "fear ", "cancellation ", "deplete ", "death ", "chaos ",
"counterspell ", "godpower ", "holyword ", "blind ", "internal ", "life_stealing ",
"disease "
}

Attack types.

Definition at line 31 of file init.cpp.

Referenced by get_ob_diff().

◆ ring_arch

archetype* ring_arch

Definition at line 125 of file init.cpp.

Referenced by fix_generated_item(), init_archetype_pointers(), and init_globals().

◆ settings

struct Settings settings

Server settings.

Definition at line 139 of file init.cpp.

Referenced by CREFilterDialog::accept(), CREReportDialog::accept(), account_block_create(), account_char_load_from_file(), account_char_save(), account_new_cmd(), accounts_load(), accounts_save(), add_me_cmd(), add_player_exp(), add_server_collect_hooks(), apply_check_item_power(), apply_check_personalized_blessings(), apply_death_exp_penalty(), apply_race_and_class(), AssetOriginAndCreationDialog::AssetOriginAndCreationDialog(), assets_collect(), attack_ob_simple(), attempt_steal(), block_until_new_connection(), calc_perm_exp(), calc_skill_exp(), cast_create_town_portal(), cast_spell(), cctk_init_std_archetypes(), cctk_setdatadir(), cctk_setlog(), cfapi_system_directory(), cfcitybell_init(), change_abil(), check_exp_loss(), check_login(), check_pick(), check_probe(), check_race_and_class(), checkbanned(), checkdm(), citylife_init(), clean_tmp_files(), CREMapInformationManager::clearCache(), CREMainWindow::closeEvent(), command_abil(), command_addexp(), command_banish(), command_create(), command_debug(), command_help(), command_loadtest(), command_nowiz(), command_patch(), command_players(), command_purge_quest_definitions(), command_search_items(), command_settings(), command_title(), compute_price_variation_with_bargaining(), convert_item(), create_items_path(), create_overlay_pathname(), create_pathname(), create_player_cmd(), create_template_pathname(), CREMainWindow::createMenus(), CREExperienceWindow::CREExperienceWindow(), CREFilterDialog::CREFilterDialog(), CREMainWindow::CREMainWindow(), CREReportDialog::CREReportDialog(), CRESettingsDialog::CRESettingsDialog(), crypt_string(), dead_player(), delete_character(), display_motd(), do_symptoms(), do_throw(), dragon_eat_flesh(), dump_experience(), enter_exit(), enter_player_maplevel(), enter_player_savebed(), exp_level(), FaceMakerDialog::FaceMakerDialog(), fatal(), CREMainWindow::fillFacesets(), find_help_file_in(), find_maps(), find_spot_for_submap(), find_style(), MessageManager::findPrePost(), fix_object(), fix_player(), forbid_play(), free_globals(), free_server(), get_cha_bonus(), get_cleric_chance(), get_con_bonus(), get_dam_bonus(), get_dex_bonus(), get_fear_bonus(), get_grace_bonus(), get_learn_spell(), get_sp_bonus(), get_speed_bonus(), get_thaco_bonus(), get_turn_bonus(), get_weight_limit(), god_enchants_weapon(), help_topics(), ChangesDock::helpReady(), hiscore_init(), hit_player(), i18n_init(), improve_armour(), improve_weapon(), CREPixmap::init(), init_beforeplay(), init_book_archive(), init_clocks(), init_emergency_mappath(), init_environ(), init_experience(), init_globals(), init_library(), init_modules(), init_server(), init_startup(), init_stats(), initPlugins(), is_legal_2ways_exit(), key_change_class(), key_confirm_quit(), kill_object(), kill_player(), kill_player_not_permadeath(), kill_player_permadeath(), knowledge_read_player_data(), knowledge_write_player_data(), level_exp(), list_players(), ResourcesManager::load(), load_assets(), load_settings(), load_table_float(), load_table_int(), CREMapInformationManager::loadCache(), MessageManager::loadDirectory(), LOG(), main(), map_path(), map_remove_unique_files(), metaserver2_init(), monsterFight(), object_clear(), CREMainWindow::onReportQuests(), CREMainWindow::onToolReloadAssets(), MessageFile::parseFile(), pay_for_item(), pick_up_object(), player_lvl_adj(), plugins_init_plugin(), process_events(), process_players1(), quest_read_player_data(), quest_write_player_data(), random_house_generator_init(), rangetostring(), read_map_log(), ready_map_name(), resurrect_player(), roll_stats(), MessageFile::save(), save_map(), save_player(), scroll_failure(), scroll_type_apply(), send_exp_table(), send_file(), send_new_char_info(), send_news(), send_rules(), set_abs_magic(), set_confdir(), set_csport(), set_datadir(), set_debug(), set_disable_plugin(), set_dumpmon1(), set_dumpmon2(), set_dumpmon3(), set_dumpmon4(), set_dumpmon5(), set_dumpmon6(), set_dumpmon7(), set_dumpmon8(), set_dumpmon9(), set_dumpmont(), set_ignore_assets_errors(), set_localdir(), set_logfile(), set_mapdir(), set_mondebug(), set_playerdir(), set_regions(), set_templatedir(), set_tmpdir(), set_uniquedir(), CREPixmap::setFaceset(), setup(), CREPixmap::setUseFacesetFallback(), show_skills(), SP_level_spellpoint_cost(), spell_failure(), spellbook_type_apply(), START_TEST(), CREMapInformationManager::storeCache(), swap_map(), town_portal_destroy_existing(), unset_debug(), CREResourcesWindow::updateFilters(), CREResourcesWindow::updateReports(), verify_player(), while(), write_book_archive(), write_map_log(), write_scroll(), and write_todclock().

◆ spellpathnames

const char* const spellpathnames[NRSPELLPATHS]
Initial value:
= {
"Protection",
"Fire",
"Frost",
"Electricity",
"Missiles",
"Self",
"Summoning",
"Abjuration",
"Restoration",
"Detonation",
"Mind",
"Creation",
"Teleportation",
"Information",
"Transmutation",
"Transferrence",
"Turning",
"Wounding",
"Death",
"Light"
}

Perhaps not the best place for this, but needs to be in some file in the common area so that standalone programs, like the random map generator, can be built.

Definition at line 239 of file init.cpp.

Referenced by describe_spellpath_attenuation(), dragon_ability_gain(), send_spell_paths(), and spellpath_msg().

◆ statistics

struct Statistics statistics

Merged spell statistics.

Definition at line 232 of file init.cpp.

Referenced by init_globals(), main(), object_merge_spell(), and ok_to_put_more().

◆ trying_emergency_save

long trying_emergency_save

True when emergency_save() is reached.

Definition at line 111 of file init.cpp.

Referenced by emergency_save(), init_globals(), and LOG().

◆ undead_name

const char* undead_name
AT_POISON
#define AT_POISON
Definition: attack.h:86
AT_MAGIC
#define AT_MAGIC
Definition: attack.h:77
AT_ELECTRICITY
#define AT_ELECTRICITY
Definition: attack.h:79
AT_PHYSICAL
#define AT_PHYSICAL
Definition: attack.h:76
AT_COLD
#define AT_COLD
Definition: attack.h:80
AT_SLOW
#define AT_SLOW
Definition: attack.h:87
AT_FEAR
#define AT_FEAR
Definition: attack.h:90
AT_CONFUSION
#define AT_CONFUSION
Definition: attack.h:81
AT_PARALYZE
#define AT_PARALYZE
Definition: attack.h:88
AT_FIRE
#define AT_FIRE
Definition: attack.h:78