Codechange: Return pair from instead of optional out parameter. (#13166)
[openttd-github.git] / src / openttd.h
blobf6728ee70db9ff304e8dc13154bc99241ea3e7cd
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file openttd.h Some generic types. */
10 #ifndef OPENTTD_H
11 #define OPENTTD_H
13 #include <atomic>
14 #include <chrono>
15 #include "core/enum_type.hpp"
17 /** Mode which defines the state of the game. */
18 enum GameMode {
19 GM_MENU,
20 GM_NORMAL,
21 GM_EDITOR,
22 GM_BOOTSTRAP
25 /** Mode which defines what mode we're switching to. */
26 enum SwitchMode {
27 SM_NONE,
28 SM_NEWGAME, ///< New Game --> 'Random game'.
29 SM_RESTARTGAME, ///< Restart --> 'Random game' with current settings.
30 SM_RELOADGAME, ///< Reload the savegame / scenario / heightmap you started the game with.
31 SM_EDITOR, ///< Switch to scenario editor.
32 SM_LOAD_GAME, ///< Load game, Play Scenario.
33 SM_MENU, ///< Switch to game intro menu.
34 SM_SAVE_GAME, ///< Save game.
35 SM_SAVE_HEIGHTMAP, ///< Save heightmap.
36 SM_GENRANDLAND, ///< Generate random land within scenario editor.
37 SM_LOAD_SCENARIO, ///< Load scenario from scenario editor.
38 SM_START_HEIGHTMAP, ///< Load a heightmap and start a new game from it.
39 SM_LOAD_HEIGHTMAP, ///< Load heightmap from scenario editor.
40 SM_RESTART_HEIGHTMAP, ///< Load a heightmap and start a new game from it with current settings.
41 SM_JOIN_GAME, ///< Join a network game.
44 /** Display Options */
45 enum DisplayOptions {
46 DO_SHOW_TOWN_NAMES = 0, ///< Display town names.
47 DO_SHOW_STATION_NAMES = 1, ///< Display station names.
48 DO_SHOW_SIGNS = 2, ///< Display signs.
49 DO_FULL_ANIMATION = 3, ///< Perform palette animation.
50 DO_FULL_DETAIL = 5, ///< Also draw details of track and roads.
51 DO_SHOW_WAYPOINT_NAMES = 6, ///< Display waypoint names.
52 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.
55 struct GameSessionStats {
56 std::chrono::steady_clock::time_point start_time; ///< Time when the current game was started.
57 std::string savegame_id; ///< Unique ID of the savegame.
58 std::optional<size_t> savegame_size; ///< Size of the last saved savegame in bytes, or std::nullopt if not saved yet.
61 extern GameMode _game_mode;
62 extern SwitchMode _switch_mode;
63 extern GameSessionStats _game_session_stats;
64 extern std::atomic<bool> _exit_game;
65 extern bool _save_config;
67 /** Modes of pausing we've got */
68 enum PauseMode : uint8_t {
69 PM_UNPAUSED = 0, ///< A normal unpaused game
70 PM_PAUSED_NORMAL = 1 << 0, ///< A game normally paused
71 PM_PAUSED_SAVELOAD = 1 << 1, ///< A game paused for saving/loading
72 PM_PAUSED_JOIN = 1 << 2, ///< A game paused for 'pause_on_join'
73 PM_PAUSED_ERROR = 1 << 3, ///< A game paused because a (critical) error
74 PM_PAUSED_ACTIVE_CLIENTS = 1 << 4, ///< A game paused for 'min_active_clients'
75 PM_PAUSED_GAME_SCRIPT = 1 << 5, ///< A game paused by a game script
76 PM_PAUSED_LINK_GRAPH = 1 << 6, ///< A game paused due to the link graph schedule lagging
77 PM_COMMAND_DURING_PAUSE = 1 << 7, ///< A game paused, and a command executed during the pause; resets on autosave
79 /** Pause mode bits when paused for network reasons. */
80 PMB_PAUSED_NETWORK = PM_PAUSED_ACTIVE_CLIENTS | PM_PAUSED_JOIN,
82 DECLARE_ENUM_AS_BIT_SET(PauseMode)
84 /** The current pause mode */
85 extern PauseMode _pause_mode;
87 void AskExitGame();
88 void AskExitToGameMenu();
90 int openttd_main(std::span<char * const> arguments);
91 void StateGameLoop();
92 void HandleExitGameRequest();
94 void SwitchToMode(SwitchMode new_mode);
96 bool RequestNewGRFScan(struct NewGRFScanCallback *callback = nullptr);
97 void GenerateSavegameId();
99 void OpenBrowser(const std::string &url);
100 void ChangeAutosaveFrequency(bool reset);
102 #endif /* OPENTTD_H */