OpenTTD Source: src/openttd.cpp File Reference

OpenTTD Source 1.11.0-RC1

Data Structures | Functions | Variables
openttd.cpp File Reference
`#include "stdafx.h"`
`#include "blitter/factory.hpp"`
`#include "sound/sound_driver.hpp"`
`#include "music/music_driver.hpp"`
`#include "video/video_driver.hpp"`
`#include "fontcache.h"`
`#include "error.h"`
`#include "gui.h"`
`#include "base_media_base.h"`
`#include "saveload/saveload.h"`
`#include "company_func.h"`
`#include "command_func.h"`
`#include "news_func.h"`
`#include "fios.h"`
`#include "aircraft.h"`
`#include "roadveh.h"`
`#include "train.h"`
`#include "ship.h"`
`#include "console_func.h"`
`#include "screenshot.h"`
`#include "network/network.h"`
`#include "network/network_func.h"`
`#include "ai/ai.hpp"`
`#include "ai/ai_config.hpp"`
`#include "settings_func.h"`
`#include "genworld.h"`
`#include "progress.h"`
`#include "strings_func.h"`
`#include "date_func.h"`
`#include "vehicle_func.h"`
`#include "gamelog.h"`
`#include "animated_tile_func.h"`
`#include "roadstop_base.h"`
`#include "elrail_func.h"`
`#include "rev.h"`
`#include "highscore.h"`
`#include "station_base.h"`
`#include "crashlog.h"`
`#include "engine_func.h"`
`#include "core/random_func.hpp"`
`#include "rail_gui.h"`
`#include "road_gui.h"`
`#include "core/backup_type.hpp"`
`#include "hotkeys.h"`
`#include "newgrf.h"`
`#include "misc/getoptdata.h"`
`#include "game/game.hpp"`
`#include "game/game_config.hpp"`
`#include "town.h"`
`#include "subsidy_func.h"`
`#include "gfx_layout.h"`
`#include "viewport_func.h"`
`#include "viewport_sprite_sorter.h"`
`#include "framerate_type.h"`
`#include "industry.h"`
`#include "linkgraph/linkgraphschedule.h"`
`#include <stdarg.h>`
`#include <system_error>`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | AfterNewGRFScan
| Callback structure of statements to be executed after the NewGRF scan. More...

## Functions
void | CallLandscapeTick ()
void | IncreaseDate ()
| Increases the tick counter, increases date and possibly calls procedures that have to be called daily, monthly or yearly.
void | DoPaletteAnimations ()
void | MusicLoop ()
| Check music playback status and start/stop/song-finished. More...
void | ResetMusic ()
void | CallWindowGameTickEvent ()
| Dispatch OnGameTick event over all windows.
bool | HandleBootstrap ()
| Handle all procedures for bootstrapping OpenTTD without a base graphics set. More...
Company * | DoStartupNewCompany (bool is_ai, CompanyID company=INVALID_COMPANY)
| Create a new company and sets all company variables default values. More...
void | ShowOSErrorBox (const char *buf, bool system)
void CDECL | usererror (const char *s,...)
| Error handling for fatal user errors. More...
void CDECL | error (const char *s,...)
| Error handling for fatal non-user errors. More...
void CDECL | ShowInfoF (const char *str,...)
| Shows some information on the console/a popup box depending on the OS. More...
static void | ShowHelp ()
| Show the help message when someone passed a wrong parameter.
static void | WriteSavegameInfo (const char *name)
static void | ParseResolution (Dimension *res, const char *s)
| Extract the resolution from the given string and store it in the 'res' parameter. More...
static void | ShutdownGame ()
| Uninitializes drivers, frees allocated memory, cleans pools, ... More...
static void | LoadIntroGame (bool load_newgrfs=true)
| Load the introduction game. More...
void | MakeNewgameSettingsLive ()
void | OpenBrowser (const char *url)
int | openttd_main (int argc, char *argv[])
| Main entry point for this lovely game. More...
void | HandleExitGameRequest ()
static void | MakeNewGameDone ()
static void | MakeNewGame (bool from_heightmap, bool reset_settings)
static void | MakeNewEditorWorldDone ()
static void | MakeNewEditorWorld ()
bool | SafeLoad (const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf=nullptr)
| Load the specified savegame but on error do different things. More...
void | SwitchToMode (SwitchMode new_mode)
static void | CheckCaches ()
| Check the validity of some of the caches. More...
void | StateGameLoop ()
| State controlling game loop. More...
static void | DoAutosave ()
| Create an autosave. More...
void | RequestNewGRFScan (NewGRFScanCallback *callback)
| Request a new NewGRF scan. More...
void | GameLoop ()

## Variables
std::string | _config_file
| Configuration file of OpenTTD.
bool | _save_config = false
bool | _request_newgrf_scan = false
NewGRFScanCallback * | _request_newgrf_scan_callback = nullptr
static const OptionData | _options []
| Options of OpenTTD. More...

## Detailed Description

Functions related to starting OpenTTD.

Definition in file openttd.cpp.

## Function Documentation

## ◆ CheckCaches()

static void CheckCaches | ( |  | ) |
| static

Check the validity of some of the caches.

Especially in the sense of desyncs between the cached value and what the value would be when calculated from the 'base' data.

Definition at line 1152 of file openttd.cpp.

## ◆ DoAutosave()

static void DoAutosave | ( |  | ) |
| static

Create an autosave.

The default name is "autosave#.sav". However with the setting 'keep_all_autosave' the name defaults to company-name + date

Definition at line 1425 of file openttd.cpp.

## ◆ DoStartupNewCompany()

Company* DoStartupNewCompany | ( | bool | is_ai,
|  | CompanyID | company = `INVALID_COMPANY`
| ) |  |

Create a new company and sets all company variables default values.

Parameters

  is_ai | is an AI company?
  company | CompanyID to use for the new company

Returns
  the company struct

Definition at line 539 of file company_cmd.cpp.

## ◆ error()

void CDECL error | ( | const char * | s,
|  |  | ...
| ) |  |

Error handling for fatal non-user errors.

Parameters

  s | the string to print.

Note
  Does NEVER return.

Definition at line 131 of file openttd.cpp.

References VideoDriver::GetInstance(), lastof, and vseprintf().

Referenced by ScriptInfo::AddLabels(), ScriptInfo::AddSetting(), AllocateMap(), ScriptInfo::CheckMethod(), CheckTrainAttachment(), NetworkUDPSocketHandler::CloseConnection(), NetworkHTTPSocketHandler::CloseConnection(), CmdConvertRail(), CmdStartStopVehicle(), DEFINE_POOL_METHOD(), DisableStaticNewGRFInfluencingNonStaticNewGRFs(), BaseMedia< GraphicsSet >::GetSet(), MallocError(), NetworkExecuteLocalCommandQueue(), ReallocError(), RemoveFromRailBaseStation(), Squirrel::RunError(), ServerNetworkAdminSocketHandler::SendClientError(), ServerNetworkAdminSocketHandler::SendError(), ServerNetworkGameSocketHandler::SendError(), VideoDriver_SDL_OpenGL::Start(), VideoDriver_SDL_Base::Start(), strecpy(), Squirrel::ThrowError(), and TranslateGRFStrings().

## ◆ HandleBootstrap()

bool HandleBootstrap | ( |  | ) |

Handle all procedures for bootstrapping OpenTTD without a base graphics set.

This requires all kinds of trickery that is needed to avoid the use of sprites from the base graphics set which are pretty interwoven.

Returns
  True if a base set exists, otherwise false.

Definition at line 279 of file bootstrap_gui.cpp.

References _network_available, BlitterFactory::GetCurrentBlitter(), and BaseMedia< GraphicsSet >::GetUsedSet().

## ◆ LoadIntroGame()

static void LoadIntroGame | ( | bool | load_newgrfs = `true` | ) |
| static

Load the introduction game.

Parameters

  load_newgrfs | Whether to load the NewGRFs or not.

Definition at line 337 of file openttd.cpp.

## ◆ MusicLoop()

void MusicLoop | ( |  | ) |

Check music playback status and start/stop/song-finished.

Called from main loop.

Definition at line 422 of file music_gui.cpp.

References _music.

## ◆ openttd_main()

int openttd_main | ( | int | argc,
|  | char * | argv[]
| ) |  |

Main entry point for this lovely game.

Parameters

  argc | The number of arguments passed to this game.
  argv | The values of the arguments.

Returns
  0 when there is no error.

Definition at line 546 of file openttd.cpp.

## ◆ ParseResolution()

static void ParseResolution | ( | Dimension * | res,
|  | const char * | s
| ) |  |
| static

Extract the resolution from the given string and store it in the 'res' parameter.

Parameters

  res | variable to store the resolution in.
  s | the string to decompose.

Definition at line 287 of file openttd.cpp.

References ShowInfoF().

## ◆ RequestNewGRFScan()

void RequestNewGRFScan | ( | NewGRFScanCallback * | callback | ) |

Request a new NewGRF scan.

This will be executed on the next game-tick. This is mostly needed to ensure NewGRF scans (which are blocking) are done in the game-thread, and not in the draw-thread (which most often triggers this request).

Parameters

  callback | Optional callback to call when NewGRF scan is completed.

Definition at line 1454 of file openttd.cpp.

Referenced by NetworkContentDownloadStatusWindow::~NetworkContentDownloadStatusWindow().

## ◆ SafeLoad()

bool SafeLoad | ( | const std::string & | filename,
|  | SaveLoadOperation | fop,
|  | DetailedFileType | dft,
|  | GameMode | newgm,
|  | Subdirectory | subdir,
|  | struct LoadFilter * | lf = `nullptr`
| ) |  |

Load the specified savegame but on error do different things.

If loading fails due to corrupt savegame, bad version, etc. go back to a previous correct state. In the menu for example load the intro game again.

Parameters

  filename | file to be loaded
  fop | mode of loading, always SLO_LOAD
  newgm | switch to this mode of loading fails due to some unknown error
  subdir | default directory to look for filename, set to 0 if not needed
  lf | Load filter to use, if nullptr: use filename + subdir.

Definition at line 953 of file openttd.cpp.

References DFT_GAME_FILE, DFT_OLD_GAME_FILE, and SLO_LOAD.

## ◆ ShowInfoF()

void CDECL ShowInfoF | ( | const char * | str,
|  |  | ...
| ) |  |

Shows some information on the console/a popup box depending on the OS.

Parameters

  str | the text to show.

Definition at line 153 of file openttd.cpp.

References lastof, and vseprintf().

Referenced by CheckExternalFiles(), GetFontByFaceName(), ParseResolution(), and IniFile::ReportFileError().

## ◆ ShutdownGame()

static void ShutdownGame | ( |  | ) |
| static

Uninitializes drivers, frees allocated memory, cleans pools, ...

Generally, prepares the game for shutting down

Definition at line 304 of file openttd.cpp.

## ◆ StateGameLoop()

void StateGameLoop | ( |  | ) |

State controlling game loop.

The state must not be changed from anywhere but here. That check is enforced in DoCommand.

Definition at line 1344 of file openttd.cpp.

References _network_server, _networking, _pause_mode, Game::GameLoop(), HasModalProgress(), PerformanceMeasurer::Paused(), PFE_GAMELOOP, PFE_GL_AIRCRAFT, PFE_GL_ECONOMY, PFE_GL_LANDSCAPE, PFE_GL_ROADVEHS, PFE_GL_SHIPS, PFE_GL_TRAINS, PM_UNPAUSED, Layouter::ReduceLineCache(), PerformanceAccumulator::Reset(), StateGameLoop_LinkGraphPauseControl(), and UpdateLandscapingLimits().

Referenced by ClientNetworkGameSocketHandler::GameLoop().

## ◆ usererror()

void CDECL usererror | ( | const char * | s,
|  |  | ...
| ) |  |

Error handling for fatal user errors.

Parameters

  s | the string to print.

Note
  Does NEVER return.

Definition at line 102 of file openttd.cpp.

References lastof, and vseprintf().

Referenced by FioOpenFile(), LoadGrfFile(), LoadGrfFileIndexed(), LoadNextSprite(), DriverFactoryBase::SelectDriver(), and DriverFactoryBase::SelectDriverImpl().

## Variable Documentation

## ◆ _options

const OptionData _options[]
| static

Initial value:
= {
GETOPT_SHORT_VALUE('I'),
GETOPT_SHORT_VALUE('S'),
GETOPT_SHORT_VALUE('M'),
GETOPT_SHORT_VALUE('m'),
GETOPT_SHORT_VALUE('s'),
GETOPT_SHORT_VALUE('v'),
GETOPT_SHORT_VALUE('b'),
GETOPT_SHORT_OPTVAL('D'),
GETOPT_SHORT_OPTVAL('n'),
GETOPT_SHORT_VALUE('l'),
GETOPT_SHORT_VALUE('p'),
GETOPT_SHORT_VALUE('P'),
GETOPT_SHORT_NOVAL('f'),
GETOPT_SHORT_VALUE('r'),
GETOPT_SHORT_VALUE('t'),
GETOPT_SHORT_OPTVAL('d'),
GETOPT_SHORT_NOVAL('e'),
GETOPT_SHORT_OPTVAL('g'),
GETOPT_SHORT_VALUE('G'),
GETOPT_SHORT_VALUE('c'),
GETOPT_SHORT_NOVAL('x'),
GETOPT_SHORT_VALUE('q'),
GETOPT_SHORT_NOVAL('h'),
}

Options of OpenTTD.

Definition at line 511 of file openttd.cpp.

GETOPT_SHORT_NOVAL
#define GETOPT_SHORT_NOVAL(shortname)
Short option without value.
Definition: getoptdata.h:91
GETOPT_SHORT_OPTVAL
#define GETOPT_SHORT_OPTVAL(shortname)
Short option with optional value.
Definition: getoptdata.h:104
GETOPT_SHORT_VALUE
#define GETOPT_SHORT_VALUE(shortname)
Short option with value.
Definition: getoptdata.h:97