1 /*************************************************************************** 2 * Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> * 3 * * 4 * Part of the Free Heroes2 Engine: * 5 * http://sourceforge.net/projects/fheroes2 * 6 * * 7 * This program is free software; you can redistribute it and/or modify * 8 * it under the terms of the GNU General Public License as published by * 9 * the Free Software Foundation; either version 2 of the License, or * 10 * (at your option) any later version. * 11 * * 12 * This program is distributed in the hope that it will be useful, * 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 15 * GNU General Public License for more details. * 16 * * 17 * You should have received a copy of the GNU General Public License * 18 * along with this program; if not, write to the * 19 * Free Software Foundation, Inc., * 20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 21 ***************************************************************************/ 22 23 #ifndef H2GAME_H 24 #define H2GAME_H 25 26 #include <string> 27 28 #include "agg.h" 29 #include "game_mode.h" 30 #include "mp2.h" 31 #include "mus.h" 32 #include "types.h" 33 34 class Players; 35 class Heroes; 36 class Castle; 37 38 namespace Game 39 { 40 void Init( void ); 41 42 const std::string & GetLastSavename( void ); 43 void SetLastSavename( const std::string & ); 44 void SetLoadVersion( int ); 45 int GetLoadVersion( void ); 46 47 // type_t 48 enum 49 { 50 TYPE_MENU = 0, 51 TYPE_STANDARD = 0x01, 52 TYPE_CAMPAIGN = 0x02, 53 TYPE_HOTSEAT = 0x04, 54 TYPE_NETWORK = 0x08, 55 TYPE_BATTLEONLY = 0x10, 56 57 // TYPE_LOADFILE used in the Settings::LoadedGameVersion, if you change that value, 58 // change in that function as well. 59 TYPE_LOADFILE = 0x80, 60 TYPE_MULTI = TYPE_HOTSEAT 61 }; 62 // distance_t 63 enum 64 { 65 // UNUSED = 0, 66 VIEW_CASTLE = 1, 67 VIEW_HEROES = 2, 68 VIEW_TELESCOPE = 3, 69 VIEW_OBSERVATION_TOWER = 4, 70 VIEW_MAGI_EYES = 5 71 }; 72 73 enum 74 { 75 EVENT_NONE, 76 EVENT_BUTTON_NEWGAME, 77 EVENT_BUTTON_LOADGAME, 78 EVENT_BUTTON_HIGHSCORES, 79 EVENT_BUTTON_CREDITS, 80 EVENT_BUTTON_STANDARD, 81 EVENT_BUTTON_CAMPAIGN, 82 EVENT_BUTTON_MULTI, 83 EVENT_BUTTON_SETTINGS, 84 EVENT_BUTTON_SELECT, 85 EVENT_BUTTON_HOTSEAT, 86 EVENT_BUTTON_HOST, 87 EVENT_BUTTON_GUEST, 88 EVENT_BUTTON_BATTLEONLY, 89 EVENT_DEFAULT_READY, 90 EVENT_DEFAULT_EXIT, 91 EVENT_DEFAULT_LEFT, 92 EVENT_DEFAULT_RIGHT, 93 EVENT_SYSTEM_FULLSCREEN, 94 EVENT_SYSTEM_SCREENSHOT, 95 EVENT_SLEEPHERO, 96 EVENT_ENDTURN, 97 EVENT_NEXTHERO, 98 EVENT_NEXTTOWN, 99 EVENT_CONTINUE, 100 EVENT_SAVEGAME, 101 EVENT_LOADGAME, 102 EVENT_FILEOPTIONS, 103 EVENT_PUZZLEMAPS, 104 EVENT_INFOGAME, 105 EVENT_DIGARTIFACT, 106 EVENT_CASTSPELL, 107 EVENT_KINGDOM_INFO, 108 EVENT_VIEW_WORLD, 109 EVENT_DEFAULTACTION, 110 EVENT_OPENFOCUS, 111 EVENT_SYSTEMOPTIONS, 112 EVENT_BATTLE_CASTSPELL, 113 EVENT_BATTLE_RETREAT, 114 EVENT_BATTLE_SURRENDER, 115 EVENT_BATTLE_AUTOSWITCH, 116 EVENT_BATTLE_OPTIONS, 117 EVENT_BATTLE_HARDSKIP, 118 EVENT_BATTLE_SOFTSKIP, 119 EVENT_MOVELEFT, 120 EVENT_MOVERIGHT, 121 EVENT_MOVETOP, 122 EVENT_MOVEBOTTOM, 123 EVENT_MOVETOPLEFT, 124 EVENT_MOVETOPRIGHT, 125 EVENT_MOVEBOTTOMLEFT, 126 EVENT_MOVEBOTTOMRIGHT, 127 EVENT_SCROLLLEFT, 128 EVENT_SCROLLRIGHT, 129 EVENT_SCROLLUP, 130 EVENT_SCROLLDOWN, 131 EVENT_CTRLPANEL, 132 EVENT_SHOWRADAR, 133 EVENT_SHOWBUTTONS, 134 EVENT_SHOWSTATUS, 135 EVENT_SHOWICONS, 136 EVENT_STACKSPLIT_SHIFT, 137 EVENT_STACKSPLIT_CTRL, 138 EVENT_JOINSTACKS, 139 EVENT_UPGRADE_TROOP, 140 EVENT_DISMISS_TROOP, 141 EVENT_TOWN_DWELLING_LEVEL_1, 142 EVENT_TOWN_DWELLING_LEVEL_2, 143 EVENT_TOWN_DWELLING_LEVEL_3, 144 EVENT_TOWN_DWELLING_LEVEL_4, 145 EVENT_TOWN_DWELLING_LEVEL_5, 146 EVENT_TOWN_DWELLING_LEVEL_6, 147 EVENT_TOWN_WELL, 148 EVENT_TOWN_MARKETPLACE, 149 EVENT_TOWN_MAGE_GUILD, 150 EVENT_TOWN_SHIPYARD, 151 EVENT_TOWN_THIEVES_GUILD, 152 153 // town screen exclusive, not applied to build screen! 154 EVENT_TOWN_TAVERN, 155 EVENT_TOWN_JUMP_TO_BUILD_SELECTION, 156 157 EVENT_WELL_BUY_ALL_CREATURES, 158 159 EVENT_LAST, 160 }; 161 162 bool HotKeyPressEvent( int ); 163 bool HotKeyHoldEvent( const int eventID ); 164 165 void mainGameLoop( bool isFirstGameRun ); 166 167 fheroes2::GameMode MainMenu( bool isFirstGameRun ); 168 fheroes2::GameMode NewGame(); 169 fheroes2::GameMode LoadGame(); 170 fheroes2::GameMode HighScores(); 171 fheroes2::GameMode Credits(); 172 fheroes2::GameMode NewStandard(); 173 fheroes2::GameMode CampaignSelection(); 174 fheroes2::GameMode NewSuccessionWarsCampaign(); 175 fheroes2::GameMode NewPriceOfLoyaltyCampaign(); 176 fheroes2::GameMode NewMulti(); 177 fheroes2::GameMode NewHotSeat(); 178 fheroes2::GameMode NewBattleOnly(); 179 fheroes2::GameMode NewNetwork(); // To be utilized in future. 180 fheroes2::GameMode LoadStandard(); 181 fheroes2::GameMode LoadCampaign(); 182 fheroes2::GameMode LoadMulti(); 183 fheroes2::GameMode LoadHotseat(); 184 fheroes2::GameMode ScenarioInfo(); 185 fheroes2::GameMode SelectCampaignScenario( const fheroes2::GameMode prevMode, const bool allowToRestart ); 186 fheroes2::GameMode SelectScenario(); 187 fheroes2::GameMode StartGame(); 188 fheroes2::GameMode StartBattleOnly(); 189 fheroes2::GameMode DisplayLoadGameDialog(); 190 fheroes2::GameMode CompleteCampaignScenario( const bool isLoadingSaveFile ); 191 192 bool isSuccessionWarsCampaignPresent(); 193 bool isPriceOfLoyaltyCampaignPresent(); 194 195 void EnvironmentSoundMixer(); 196 void restoreSoundsForCurrentFocus(); 197 int GetKingdomColors( void ); 198 int GetActualKingdomColors( void ); 199 void DialogPlayers( int color, std::string ); 200 void SetCurrentMusic( const int mus ); 201 int CurrentMusic(); 202 u32 & MapsAnimationFrame( void ); 203 u32 GetRating( void ); 204 u32 GetGameOverScores( void ); 205 u32 GetLostTownDays( void ); 206 u32 GetViewDistance( u32 ); 207 u32 GetWhirlpoolPercent( void ); 208 u32 SelectCountPlayers( void ); 209 void ShowMapLoadingText( void ); 210 void PlayPickupSound( void ); 211 bool UpdateSoundsOnFocusUpdate(); 212 void SetUpdateSoundsOnFocusUpdate( bool update ); 213 void OpenHeroesDialog( Heroes & hero, bool updateFocus, bool windowIsGameWorld, bool disableDismiss = false ); 214 void OpenCastleDialog( Castle & castle, bool updateFocus = true ); 215 // Returns the difficulty level based on the type of game. 216 int getDifficulty(); 217 void LoadPlayers( const std::string & mapFileName, Players & players ); 218 void saveDifficulty( const int difficulty ); 219 void SavePlayers( const std::string & mapFileName, const Players & players ); 220 221 std::string GetSaveDir(); 222 std::string GetSaveFileExtension(); 223 std::string GetSaveFileExtension( const int gameType ); 224 225 // Useful for restoring background music after playing short-term music effects 226 class MusicRestorer 227 { 228 public: MusicRestorer()229 MusicRestorer() 230 : _music( CurrentMusic() ) 231 {} 232 233 MusicRestorer( const MusicRestorer & ) = delete; 234 ~MusicRestorer()235 ~MusicRestorer() 236 { 237 if ( _music == MUS::UNUSED || _music == MUS::UNKNOWN ) { 238 SetCurrentMusic( _music ); 239 } 240 else { 241 AGG::PlayMusic( _music, true, true ); 242 } 243 } 244 245 MusicRestorer & operator=( const MusicRestorer & ) = delete; 246 247 private: 248 const int _music; 249 }; 250 251 namespace ObjectFadeAnimation 252 { 253 struct FadeTask 254 { 255 FadeTask(); 256 257 FadeTask( MP2::MapObjectType object_, uint32_t objectIndex_, uint32_t animationIndex_, int32_t fromIndex_, int32_t toIndex_, uint8_t alpha_, bool fadeOut_, 258 bool fadeIn_, uint8_t objectTileset_ ); 259 260 MP2::MapObjectType object; 261 uint32_t objectIndex; 262 uint32_t animationIndex; 263 int32_t fromIndex; 264 int32_t toIndex; 265 uint8_t alpha; 266 bool fadeOut; 267 bool fadeIn; 268 uint8_t objectTileset; 269 }; 270 271 const FadeTask & GetFadeTask(); 272 273 void PrepareFadeTask( const MP2::MapObjectType object, int32_t fromTile, int32_t toTile, bool fadeOut, bool fadeIn ); 274 void PerformFadeTask(); 275 } 276 277 int32_t GetStep4Player( const int32_t currentId, const int32_t width, const int32_t totalCount ); 278 std::string CountScoute( uint32_t count, int scoute, bool shorts = false ); 279 std::string CountThievesGuild( uint32_t monsterCount, int guildCount ); 280 } 281 282 #define HotKeyCloseWindow ( Game::HotKeyPressEvent( Game::EVENT_DEFAULT_EXIT ) || Game::HotKeyPressEvent( Game::EVENT_DEFAULT_READY ) ) 283 284 #endif 285