2009-08-21 22:21:05 +02:00
/*
* This file is part of OpenTTD .
* OpenTTD is free software ; you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation , version 2.
* OpenTTD is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
* See the GNU General Public License for more details . You should have received a copy of the GNU General Public License along with OpenTTD . If not , see < http : //www.gnu.org/licenses/>.
*/
2008-05-06 17:11:33 +02:00
/** @file openttd.h Some generic types. */
2005-07-24 16:12:37 +02:00
2005-07-15 23:28:26 +02:00
# ifndef OPENTTD_H
# define OPENTTD_H
2004-08-09 19:04:08 +02:00
2021-06-17 18:58:59 +02:00
# include <atomic>
2023-04-25 19:43:45 +02:00
# include <chrono>
2009-05-06 17:06:57 +02:00
# include "core/enum_type.hpp"
2011-02-14 20:52:26 +01:00
/** Mode which defines the state of the game. */
2009-02-25 01:14:46 +01:00
enum GameMode {
2007-12-23 00:30:28 +01:00
GM_MENU ,
GM_NORMAL ,
2009-02-25 01:14:46 +01:00
GM_EDITOR ,
2011-11-17 22:17:17 +01:00
GM_BOOTSTRAP
2007-12-23 00:30:28 +01:00
} ;
2011-02-14 20:52:26 +01:00
/** Mode which defines what mode we're switching to. */
2009-02-25 01:45:52 +01:00
enum SwitchMode {
SM_NONE ,
2019-03-05 05:04:39 +01:00
SM_NEWGAME , ///< New Game --> 'Random game'.
2024-02-03 15:48:54 +01:00
SM_RESTARTGAME , ///< Restart --> 'Random game' with current settings.
2021-01-08 16:23:07 +01:00
SM_RELOADGAME , ///< Reload the savegame / scenario / heightmap you started the game with.
2019-03-05 05:04:39 +01:00
SM_EDITOR , ///< Switch to scenario editor.
SM_LOAD_GAME , ///< Load game, Play Scenario.
SM_MENU , ///< Switch to game intro menu.
SM_SAVE_GAME , ///< Save game.
SM_SAVE_HEIGHTMAP , ///< Save heightmap.
SM_GENRANDLAND , ///< Generate random land within scenario editor.
SM_LOAD_SCENARIO , ///< Load scenario from scenario editor.
SM_START_HEIGHTMAP , ///< Load a heightmap and start a new game from it.
SM_LOAD_HEIGHTMAP , ///< Load heightmap from scenario editor.
SM_RESTART_HEIGHTMAP , ///< Load a heightmap and start a new game from it with current settings.
2021-05-01 14:41:25 +02:00
SM_JOIN_GAME , ///< Join a network game.
2004-08-09 19:04:08 +02:00
} ;
2011-05-14 20:38:54 +02:00
/** Display Options */
2010-05-13 11:44:44 +02:00
enum DisplayOptions {
2011-05-14 20:38:54 +02:00
DO_SHOW_TOWN_NAMES = 0 , ///< Display town names.
DO_SHOW_STATION_NAMES = 1 , ///< Display station names.
DO_SHOW_SIGNS = 2 , ///< Display signs.
DO_FULL_ANIMATION = 3 , ///< Perform palette animation.
DO_FULL_DETAIL = 5 , ///< Also draw details of track and roads.
DO_SHOW_WAYPOINT_NAMES = 6 , ///< Display waypoint names.
2011-08-01 20:41:21 +02:00
DO_SHOW_COMPETITOR_SIGNS = 7 , ///< Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are always shown, even if this option is turned off.
2007-04-05 09:49:04 +02:00
} ;
2024-03-16 08:58:56 +01:00
struct GameSessionStats {
std : : chrono : : steady_clock : : time_point start_time ; ///< Time when the current game was started.
std : : string savegame_id ; ///< Unique ID of the savegame.
std : : optional < size_t > savegame_size ; ///< Size of the last saved savegame in bytes, or std::nullopt if not saved yet.
} ;
2009-02-25 01:14:46 +01:00
extern GameMode _game_mode ;
2009-02-25 01:45:52 +01:00
extern SwitchMode _switch_mode ;
2024-03-16 08:58:56 +01:00
extern GameSessionStats _game_session_stats ;
2021-06-17 18:58:59 +02:00
extern std : : atomic < bool > _exit_game ;
2020-12-13 16:28:06 +01:00
extern bool _save_config ;
2009-05-06 17:06:57 +02:00
/** Modes of pausing we've got */
2024-03-16 23:59:32 +01:00
enum PauseMode : uint8_t {
2009-11-12 18:46:04 +01:00
PM_UNPAUSED = 0 , ///< A normal unpaused game
PM_PAUSED_NORMAL = 1 < < 0 , ///< A game normally paused
PM_PAUSED_SAVELOAD = 1 < < 1 , ///< A game paused for saving/loading
PM_PAUSED_JOIN = 1 < < 2 , ///< A game paused for 'pause_on_join'
PM_PAUSED_ERROR = 1 < < 3 , ///< A game paused because a (critical) error
PM_PAUSED_ACTIVE_CLIENTS = 1 < < 4 , ///< A game paused for 'min_active_clients'
2011-12-19 21:58:59 +01:00
PM_PAUSED_GAME_SCRIPT = 1 < < 5 , ///< A game paused by a game script
2019-01-22 19:31:08 +01:00
PM_PAUSED_LINK_GRAPH = 1 < < 6 , ///< A game paused due to the link graph schedule lagging
2023-04-27 17:21:29 +02:00
PM_COMMAND_DURING_PAUSE = 1 < < 7 , ///< A game paused, and a command executed during the pause; resets on autosave
2009-11-17 15:06:28 +01:00
2011-05-14 20:38:54 +02:00
/** Pause mode bits when paused for network reasons. */
2009-11-17 15:06:28 +01:00
PMB_PAUSED_NETWORK = PM_PAUSED_ACTIVE_CLIENTS | PM_PAUSED_JOIN ,
2009-05-06 17:06:57 +02:00
} ;
2010-03-23 23:25:43 +01:00
DECLARE_ENUM_AS_BIT_SET ( PauseMode )
2009-05-06 17:06:57 +02:00
/** The current pause mode */
2019-04-22 14:14:46 +02:00
extern PauseMode _pause_mode ;
2007-12-23 00:30:28 +01:00
2011-02-07 23:15:46 +01:00
void AskExitGame ( ) ;
void AskExitToGameMenu ( ) ;
2024-04-11 13:25:40 +02:00
int openttd_main ( std : : span < char * const > arguments ) ;
2023-01-29 09:28:24 +01:00
void StateGameLoop ( ) ;
2011-02-07 23:15:46 +01:00
void HandleExitGameRequest ( ) ;
2011-12-10 09:31:14 +01:00
void SwitchToMode ( SwitchMode new_mode ) ;
2021-04-12 20:53:04 +02:00
bool RequestNewGRFScan ( struct NewGRFScanCallback * callback = nullptr ) ;
2023-04-25 19:43:45 +02:00
void GenerateSavegameId ( ) ;
2021-03-09 14:53:51 +01:00
2023-11-29 01:17:05 +01:00
void OpenBrowser ( const std : : string & url ) ;
2023-04-27 17:21:29 +02:00
void ChangeAutosaveFrequency ( bool reset ) ;
2023-01-29 09:28:24 +01:00
2005-07-15 23:28:26 +02:00
# endif /* OPENTTD_H */