OpenTTD Source: src/openttd.h Source File

OpenTTD Source 15.3

openttd.h
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef OPENTTD_H
11#define OPENTTD_H
12
13#include <atomic>
14#include <chrono>
15#include "core/enum_type.hpp"
16
18 enum GameMode : uint8_t {
19 GM_MENU,
20 GM_NORMAL,
21 GM_EDITOR,
22 GM_BOOTSTRAP
23};
24
26 enum SwitchMode : uint8_t {
27 SM_NONE,
28 SM_NEWGAME,
29 SM_RESTARTGAME,
30 SM_RELOADGAME,
31 SM_EDITOR,
32 SM_LOAD_GAME,
33 SM_MENU,
34 SM_SAVE_GAME,
35 SM_SAVE_HEIGHTMAP,
36 SM_GENRANDLAND,
37 SM_LOAD_SCENARIO,
38 SM_START_HEIGHTMAP,
39 SM_LOAD_HEIGHTMAP,
40 SM_RESTART_HEIGHTMAP,
41 SM_JOIN_GAME,
42};
43
45 enum DisplayOptions : uint8_t {
46 DO_SHOW_TOWN_NAMES = 0,
47 DO_SHOW_STATION_NAMES = 1,
48 DO_SHOW_SIGNS = 2,
49 DO_FULL_ANIMATION = 3,
50 DO_FULL_DETAIL = 5,
51 DO_SHOW_WAYPOINT_NAMES = 6,
52 DO_SHOW_COMPETITOR_SIGNS = 7,
53};
54
55 struct GameSessionStats {
56 std::chrono::steady_clock::time_point start_time;
57 std::string savegame_id;
58 std::optional<size_t> savegame_size;
59};
60
61extern GameMode _game_mode;
62extern SwitchMode _switch_mode;
63extern GameSessionStats _game_session_stats;
64extern std::atomic<bool> _exit_game;
65extern bool _save_config;
66
68 enum class PauseMode : uint8_t {
69 Normal = 0,
70 SaveLoad = 1,
71 Join = 2,
72 Error = 3,
73 ActiveClients = 4,
74 GameScript = 5,
75 LinkGraph = 6,
76 CommandDuringPause = 7,
77};
78using PauseModes = EnumBitSet<PauseMode, uint8_t>;
79
81extern PauseModes _pause_mode;
82
83void AskExitGame();
84void AskExitToGameMenu();
85
86int openttd_main(std::span<std::string_view> arguments);
87void StateGameLoop();
88void HandleExitGameRequest();
89
90void SwitchToMode(SwitchMode new_mode);
91
92bool RequestNewGRFScan(struct NewGRFScanCallback *callback = nullptr);
93void GenerateSavegameId();
94
95void OpenBrowser(const std::string &url);
96void ChangeAutosaveFrequency(bool reset);
97
98#endif /* OPENTTD_H */
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
LinkGraph
A connected component of a link graph.
Definition linkgraph.h:37
enum_type.hpp
Type (helpers) for enums.
DisplayOptions
DisplayOptions
Display Options.
Definition openttd.h:45
DO_SHOW_TOWN_NAMES
@ DO_SHOW_TOWN_NAMES
Display town names.
Definition openttd.h:46
DO_SHOW_COMPETITOR_SIGNS
@ DO_SHOW_COMPETITOR_SIGNS
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
Definition openttd.h:52
DO_FULL_DETAIL
@ DO_FULL_DETAIL
Also draw details of track and roads.
Definition openttd.h:50
DO_SHOW_SIGNS
@ DO_SHOW_SIGNS
Display signs.
Definition openttd.h:48
DO_SHOW_WAYPOINT_NAMES
@ DO_SHOW_WAYPOINT_NAMES
Display waypoint names.
Definition openttd.h:51
DO_SHOW_STATION_NAMES
@ DO_SHOW_STATION_NAMES
Display station names.
Definition openttd.h:47
DO_FULL_ANIMATION
@ DO_FULL_ANIMATION
Perform palette animation.
Definition openttd.h:49
openttd_main
int openttd_main(std::span< std::string_view > arguments)
Main entry point for this lovely game.
Definition openttd.cpp:500
ChangeAutosaveFrequency
void ChangeAutosaveFrequency(bool reset)
Reset the interval of the autosave.
Definition openttd.cpp:1314
_game_session_stats
GameSessionStats _game_session_stats
Statistics about the current session.
Definition gfx.cpp:51
StateGameLoop
void StateGameLoop()
State controlling game loop.
Definition openttd.cpp:1210
GenerateSavegameId
void GenerateSavegameId()
Generate an unique savegame ID.
Definition misc.cpp:87
PauseMode
PauseMode
Modes of pausing we've got.
Definition openttd.h:68
PauseMode::Error
@ Error
A game paused because a (critical) error.
PauseMode::GameScript
@ GameScript
A game paused by a game script.
PauseMode::ActiveClients
@ ActiveClients
A game paused for 'min_active_clients'.
PauseMode::Normal
@ Normal
A game normally paused.
PauseMode::Join
@ Join
A game paused for 'pause_on_join'.
PauseMode::CommandDuringPause
@ CommandDuringPause
A game paused, and a command executed during the pause; resets on autosave.
GameMode
GameMode
Mode which defines the state of the game.
Definition openttd.h:18
RequestNewGRFScan
bool RequestNewGRFScan(struct NewGRFScanCallback *callback=nullptr)
Request a new NewGRF scan.
Definition openttd.cpp:1327
_pause_mode
PauseModes _pause_mode
The current pause mode.
Definition gfx.cpp:50
SwitchMode
SwitchMode
Mode which defines what mode we're switching to.
Definition openttd.h:26
SM_START_HEIGHTMAP
@ SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
Definition openttd.h:38
SM_RESTART_HEIGHTMAP
@ SM_RESTART_HEIGHTMAP
Load a heightmap and start a new game from it with current settings.
Definition openttd.h:40
SM_LOAD_SCENARIO
@ SM_LOAD_SCENARIO
Load scenario from scenario editor.
Definition openttd.h:37
SM_GENRANDLAND
@ SM_GENRANDLAND
Generate random land within scenario editor.
Definition openttd.h:36
SM_JOIN_GAME
@ SM_JOIN_GAME
Join a network game.
Definition openttd.h:41
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition openttd.h:33
SM_RESTARTGAME
@ SM_RESTARTGAME
Restart --> 'Random game' with current settings.
Definition openttd.h:29
SM_RELOADGAME
@ SM_RELOADGAME
Reload the savegame / scenario / heightmap you started the game with.
Definition openttd.h:30
SM_SAVE_HEIGHTMAP
@ SM_SAVE_HEIGHTMAP
Save heightmap.
Definition openttd.h:35
SM_LOAD_HEIGHTMAP
@ SM_LOAD_HEIGHTMAP
Load heightmap from scenario editor.
Definition openttd.h:39
SM_SAVE_GAME
@ SM_SAVE_GAME
Save game.
Definition openttd.h:34
SM_LOAD_GAME
@ SM_LOAD_GAME
Load game, Play Scenario.
Definition openttd.h:32
SM_EDITOR
@ SM_EDITOR
Switch to scenario editor.
Definition openttd.h:31
SM_NEWGAME
@ SM_NEWGAME
New Game --> 'Random game'.
Definition openttd.h:28
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:49
GameSessionStats
Definition openttd.h:55
GameSessionStats::start_time
std::chrono::steady_clock::time_point start_time
Time when the current game was started.
Definition openttd.h:56
GameSessionStats::savegame_id
std::string savegame_id
Unique ID of the savegame.
Definition openttd.h:57
GameSessionStats::savegame_size
std::optional< size_t > savegame_size
Size of the last saved savegame in bytes, or std::nullopt if not saved yet.
Definition openttd.h:58
NewGRFScanCallback
Callback for NewGRF scanning.
Definition newgrf_config.h:222
SaveLoad
SaveLoad type struct.
Definition saveload.h:732