1 //////////////////////////////////////////////////////////////////////////////// 2 // Copyright (C) 2004-2011 by The Allacrost Project 3 // Copyright (C) 2012-2018 by Bertram (Valyria Tear) 4 // All Rights Reserved 5 // 6 // This code is licensed under the GNU GPL version 2. It is free software 7 // and you may modify it and/or redistribute it under the terms of this license. 8 // See http://www.gnu.org/copyleft/gpl.html for details. 9 //////////////////////////////////////////////////////////////////////////////// 10 11 #ifndef __GLOBAL_HEADER__ 12 #define __GLOBAL_HEADER__ 13 14 #include "utils/utils_strings.h" 15 16 #include "script/script_read.h" 17 #include "script/script_write.h" 18 19 #include "media/global_media.h" 20 #include "media/battle_media.h" 21 22 #include "skill_graph/skill_graph.h" 23 #include "actors/global_character_handler.h" 24 #include "actors/global_actor.h" 25 #include "actors/global_party.h" 26 27 #include "objects/global_inventory_handler.h" 28 #include "objects/global_armor.h" 29 #include "objects/global_weapon.h" 30 31 #include "global_skills.h" 32 33 #include "events/global_events.h" 34 #include "quests/quests.h" 35 #include "worldmap/worldmap_handler.h" 36 #include "maps/map_data_handler.h" 37 #include "shop/shop_data_handler.h" 38 #include "emotes/emote_handler.h" 39 40 //! \brief All calls to global code are wrapped inside this namespace. 41 namespace vt_global 42 { 43 44 class GameGlobal; 45 class GlobalSpirit; 46 47 //! \brief The singleton pointer responsible for the management of global game data. 48 extern GameGlobal* GlobalManager; 49 50 //! \brief Determines whether the code in the vt_global namespace should print debug statements or not. 51 extern bool GLOBAL_DEBUG; 52 53 /** **************************************************************************** 54 *** \brief Retains all the state information about the active game 55 *** 56 *** This class is a resource manager for the current state of the game that is 57 *** being played. 58 *** 59 *** \note This class is a singleton, even though it is technically not an engine 60 *** manager class. There can only be one game instance that the player is playing 61 *** at any given time. 62 *** ***************************************************************************/ 63 class GameGlobal : public vt_utils::Singleton<GameGlobal> 64 { 65 friend class vt_utils::Singleton<GameGlobal>; 66 67 public: 68 ~GameGlobal(); 69 70 bool SingletonInitialize(); 71 72 //! Reloads the persistent scripts. Used when changing the language for instance. ReloadGlobalScripts()73 bool ReloadGlobalScripts() 74 { _CloseGlobalScripts(); return _LoadGlobalScripts(); } 75 76 /** \brief Deletes all data stored within the GameGlobal class object 77 *** This function is meant to be called when the user quits the current game instance 78 *** and returns to the boot screen. It will delete all characters, inventory, and other 79 *** data relevant to the current game. 80 **/ 81 void ClearAllData(); 82 83 //! \brief Executes function NewGame() from global script 84 //! \returns whether it succeeded. 85 bool NewGame(); 86 87 /** \brief Loads all global data from a saved game file 88 *** \param filename The filename of the saved game file where to read the data from 89 *** \param slot_id The save slot the file correspond to. Used to set the correct cursor position 90 *** when further saving. 91 *** \return True if the game was successfully loaded, false if it was not 92 **/ 93 bool LoadGame(const std::string &filename, uint32_t slot_id); 94 95 /** \brief Saves all global data to a saved game file 96 *** \param filename The filename of the saved game file where to write the data to 97 *** \param slot_id The game slot id used for the save menu. 98 *** \param positions When used in a save point, the save map tile positions are given there. 99 *** \return True if the game was successfully saved, false if it was not 100 **/ 101 bool SaveGame(const std::string &filename, uint32_t slot_id, uint32_t x_position = 0, uint32_t y_position = 0); 102 103 //! \brief Attempts an autosave on the current slot, using given map and location. 104 bool AutoSave(const std::string& map_data_file, const std::string& map_script_file, 105 uint32_t stamina, 106 uint32_t x_position = 0, uint32_t y_position = 0); 107 108 //! \brief Gets the last load/save position. GetGameSlotId()109 uint32_t GetGameSlotId() const { 110 return _game_slot_id; 111 } 112 113 //! \note The overflow condition is not checked here: we just assume it will never occur AddDrunes(uint32_t amount)114 void AddDrunes(uint32_t amount) { 115 _drunes += amount; 116 } 117 118 //! \note The amount is only subtracted if the current funds is equal to or exceeds the amount to subtract SubtractDrunes(uint32_t amount)119 void SubtractDrunes(uint32_t amount) { 120 if(_drunes >= amount) _drunes -= amount; 121 } 122 SetDrunes(uint32_t amount)123 void SetDrunes(uint32_t amount) { 124 _drunes = amount; 125 } 126 GetDrunes()127 uint32_t GetDrunes() const { 128 return _drunes; 129 } 130 SetMaxExperienceLevel(uint32_t level)131 void SetMaxExperienceLevel(uint32_t level) { 132 _max_experience_level = level; 133 } 134 GetMaxExperienceLevel()135 uint32_t GetMaxExperienceLevel() const { 136 return _max_experience_level; 137 } 138 139 //! \brief Tells whether an enemy id is existing in the enemy data. 140 bool DoesEnemyExist(uint32_t enemy_id); 141 GetWeaponSkillsScript()142 vt_script::ReadScriptDescriptor& GetWeaponSkillsScript() { 143 return _weapon_skills_script; 144 } 145 GetMagicSkillsScript()146 vt_script::ReadScriptDescriptor& GetMagicSkillsScript() { 147 return _magic_skills_script; 148 } 149 GetSpecialSkillsScript()150 vt_script::ReadScriptDescriptor& GetSpecialSkillsScript() { 151 return _special_skills_script; 152 } 153 GetBareHandsSkillsScript()154 vt_script::ReadScriptDescriptor& GetBareHandsSkillsScript() { 155 return _bare_hands_skills_script; 156 } 157 GetStatusEffectsScript()158 vt_script::ReadScriptDescriptor& GetStatusEffectsScript() { 159 return _status_effects_script; 160 } 161 GetCharactersScript()162 vt_script::ReadScriptDescriptor& GetCharactersScript() { 163 return _characters_script; 164 } 165 GetEnemiesScript()166 vt_script::ReadScriptDescriptor& GetEnemiesScript() { 167 return _enemies_script; 168 } 169 GetMapSpriteScript()170 vt_script::ReadScriptDescriptor& GetMapSpriteScript() { 171 return _map_sprites_script; 172 } 173 174 //! \brief Get a reference to the skill graph handler GetCharacterHandler()175 CharacterHandler& GetCharacterHandler() { 176 return _character_handler; 177 } 178 179 //! \brief Get a reference to inventory handler GetInventoryHandler()180 InventoryHandler& GetInventoryHandler() { 181 return _inventory_handler; 182 } 183 184 //! \brief Get the reference to the skill graph handler GetSkillGraph()185 SkillGraph& GetSkillGraph() { 186 return _skill_graph; 187 } 188 GetGameEvents()189 GameEvents& GetGameEvents() { 190 return _game_events; 191 } 192 GetGameQuests()193 GameQuests& GetGameQuests() { 194 return _game_quests; 195 } 196 GetMapData()197 MapDataHandler& GetMapData() { 198 return _map_data_handler; 199 } 200 GetWorldMapData()201 WorldMapHandler& GetWorldMapData() { 202 return _worldmap_handler; 203 } 204 GetShopDataHandler()205 ShopDataHandler& GetShopDataHandler() { 206 return _shop_data_handler; 207 } 208 GetEmoteHandler()209 EmoteHandler& GetEmoteHandler() { 210 return _emote_handler; 211 } 212 213 //! \brief Gives access to global media files. 214 //! Note: The reference is passed non const to be able to give modifiable references 215 //! and pointers. Media()216 GlobalMedia& Media() { 217 return _global_media; 218 } 219 220 //! \brief Gives access to global battle media files. 221 //! Note: The reference is passed non const to be able to give modifiable references 222 //! and pointers. GetBattleMedia()223 BattleMedia& GetBattleMedia() { 224 return _battle_media; 225 } 226 227 private: 228 GameGlobal(); 229 230 //! \brief The slot id the game was loaded from/saved to, or 0 if none. 231 uint32_t _game_slot_id; 232 233 //! \brief The amount of financial resources (drunes) that the party currently has 234 uint32_t _drunes; 235 236 /** \brief Set the max level that can be reached by a character 237 *** This equals 100 by default, @see Set/GetMaxExperienceLevel() 238 **/ 239 uint32_t _max_experience_level; 240 241 //! \brief The container which stores all of the groups of events that have occured in the game 242 GameEvents _game_events; 243 244 CharacterHandler _character_handler; 245 246 InventoryHandler _inventory_handler; 247 248 SkillGraph _skill_graph; 249 250 GameQuests _game_quests; 251 252 MapDataHandler _map_data_handler; 253 254 WorldMapHandler _worldmap_handler; 255 256 ShopDataHandler _shop_data_handler; 257 258 EmoteHandler _emote_handler; 259 260 //! \brief member storing all the common media files. 261 GlobalMedia _global_media; 262 263 //! \brief member storing all the common battle media files. 264 BattleMedia _battle_media; 265 266 //! \name Global data and function script files 267 //@{ 268 //! \brief Contains character ID definitions and a number of useful functions 269 vt_script::ReadScriptDescriptor _global_script; 270 271 //! \brief Contains data and functional definitions for all weapon skills 272 vt_script::ReadScriptDescriptor _weapon_skills_script; 273 274 //! \brief Contains data and functional definitions for all magic skills 275 vt_script::ReadScriptDescriptor _magic_skills_script; 276 277 //! \brief Contains data and functional definitions for all special skills 278 vt_script::ReadScriptDescriptor _special_skills_script; 279 280 //! \brief Contains data and functional definitions for all bare hands skills 281 vt_script::ReadScriptDescriptor _bare_hands_skills_script; 282 283 //! \brief Contains functional definitions for all status effects 284 vt_script::ReadScriptDescriptor _status_effects_script; 285 286 //! \brief Contains data and functional definitions for characters 287 vt_script::ReadScriptDescriptor _characters_script; 288 289 //! \brief Contains data and functional definitions for enemies 290 vt_script::ReadScriptDescriptor _enemies_script; 291 292 //! \brief Contains data and functional definitions for sprites seen in game maps 293 vt_script::ReadScriptDescriptor _map_sprites_script; 294 295 //! \brief Contains data and functional definitions for map objects seen in game maps 296 vt_script::ReadScriptDescriptor _map_objects_script; 297 298 //! \brief Contains data and functional definitions for map treasures seen in game maps 299 vt_script::ReadScriptDescriptor _map_treasures_script; 300 //@} 301 302 //! \brief Loads every persistent scripts, used at the global initialization time. 303 bool _LoadGlobalScripts(); 304 305 //! \brief Unloads every persistent scripts by closing their files. 306 void _CloseGlobalScripts(); 307 }; 308 309 } // namespace vt_global 310 311 #endif // __GLOBAL_HEADER__ 312