16#include "network/core/network_game_info.h"
44#include "3rdparty/fmt/chrono.h"
48#include "table/strings.h"
109#define DEF_CONSOLE_CMD(function) static bool function([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[])
110#define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo)
124 if (echo)
IConsolePrint(
CC_ERROR,
"You cannot use this command because there is no network available.");
134DEF_CONSOLE_HOOK(ConHookServerOnly)
149DEF_CONSOLE_HOOK(ConHookClientOnly)
164DEF_CONSOLE_HOOK(ConHookNeedNetwork)
179DEF_CONSOLE_HOOK(ConHookNeedNonDedicatedNetwork)
194DEF_CONSOLE_HOOK(ConHookNoNetwork)
207DEF_CONSOLE_HOOK(ConHookServerOrNoNetwork)
216DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
219 if (_game_mode == GM_MENU) {
223 return ConHookNoNetwork(echo);
232DEF_CONSOLE_CMD(ConResetEngines)
235 IConsolePrint(
CC_HELP,
"Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'.");
248DEF_CONSOLE_CMD(ConResetEnginePool)
251 IConsolePrint(
CC_HELP,
"Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
255 if (_game_mode == GM_MENU) {
274DEF_CONSOLE_CMD(ConResetTile)
299DEF_CONSOLE_CMD(ConZoomToLevel)
326 if (argv[1][0] ==
'-') {
358DEF_CONSOLE_CMD(ConScrollToTile)
364 IConsolePrint(
CC_HELP,
"'instant' will immediately move and redraw viewport without smooth scrolling.");
367 if (argc < 2)
return false;
369 uint32_t arg_index = 1;
370 bool instant =
false;
371 if (strcmp(argv[arg_index],
"instant") == 0) {
376 switch (argc - arg_index) {
412DEF_CONSOLE_CMD(ConSave)
420 std::string filename = argv[1];
439DEF_CONSOLE_CMD(ConSaveConfig)
442 IConsolePrint(
CC_HELP,
"Saves the configuration for new games to the configuration file, typically 'openttd.cfg'.");
443 IConsolePrint(
CC_HELP,
"It does not save the configuration of the current game to the configuration file.");
452DEF_CONSOLE_CMD(ConLoad)
459 if (argc != 2)
return false;
461 const char *file = argv[1];
464 if (item !=
nullptr) {
478DEF_CONSOLE_CMD(ConLoadScenario)
481 IConsolePrint(
CC_HELP,
"Load a scenario by name or index. Usage: 'load_scenario <file | number>'.");
485 if (argc != 2)
return false;
487 const char *file = argv[1];
490 if (item !=
nullptr) {
504DEF_CONSOLE_CMD(ConLoadHeightmap)
507 IConsolePrint(
CC_HELP,
"Load a heightmap by name or index. Usage: 'load_heightmap <file | number>'.");
511 if (argc != 2)
return false;
513 const char *file = argv[1];
516 if (item !=
nullptr) {
530DEF_CONSOLE_CMD(ConRemove)
537 if (argc != 2)
return false;
539 const char *file = argv[1];
542 if (item !=
nullptr) {
556DEF_CONSOLE_CMD(ConListFiles)
559 IConsolePrint(
CC_HELP,
"List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'.");
572DEF_CONSOLE_CMD(ConListScenarios)
588DEF_CONSOLE_CMD(ConListHeightmaps)
604DEF_CONSOLE_CMD(ConChangeDirectory)
611 if (argc != 2)
return false;
613 const char *file = argv[1];
616 if (item !=
nullptr) {
617 switch (item->type) {
618 case FIOS_TYPE_DIR:
case FIOS_TYPE_DRIVE:
case FIOS_TYPE_PARENT:
631DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
646DEF_CONSOLE_CMD(ConClearBuffer)
653 IConsoleClearBuffer();
663static bool ConKickOrBan(
const char *argv,
bool ban,
const std::string &reason)
667 if (strchr(argv,
'.') ==
nullptr && strchr(argv,
':') ==
nullptr) {
706DEF_CONSOLE_CMD(ConKick)
709 IConsolePrint(
CC_HELP,
"Kick a client from a network game. Usage: 'kick <ip | client-id> [<kick-reason>]'.");
714 if (argc != 2 && argc != 3)
return false;
717 if (argc == 2)
return ConKickOrBan(argv[1],
false, {});
720 size_t kick_message_length = strlen(argv[2]);
721 if (kick_message_length >= 255) {
722 IConsolePrint(
CC_ERROR,
"Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
725 return ConKickOrBan(argv[1],
false, argv[2]);
729DEF_CONSOLE_CMD(ConBan)
732 IConsolePrint(
CC_HELP,
"Ban a client from a network game. Usage: 'ban <ip | client-id> [<ban-reason>]'.");
738 if (argc != 2 && argc != 3)
return false;
741 if (argc == 2)
return ConKickOrBan(argv[1],
true, {});
744 size_t kick_message_length = strlen(argv[2]);
745 if (kick_message_length >= 255) {
746 IConsolePrint(
CC_ERROR,
"Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
749 return ConKickOrBan(argv[1],
true, argv[2]);
753DEF_CONSOLE_CMD(ConUnBan)
756 IConsolePrint(
CC_HELP,
"Unban a client from a network game. Usage: 'unban <ip | banlist-index>'.");
761 if (argc != 2)
return false;
771 index = atoi(argv[1]) - 1U;
785DEF_CONSOLE_CMD(ConBanList)
803DEF_CONSOLE_CMD(ConPauseGame)
810 if (_game_mode == GM_MENU) {
825DEF_CONSOLE_CMD(ConUnpauseGame)
832 if (_game_mode == GM_MENU) {
851DEF_CONSOLE_CMD(ConRcon)
854 IConsolePrint(
CC_HELP,
"Remote control the server from another client. Usage: 'rcon <password> <command>'.");
855 IConsolePrint(
CC_HELP,
"Remember to enclose the command in quotes, otherwise only the first parameter is sent.");
856 IConsolePrint(
CC_HELP,
"When your client's public key is in the 'authorized keys' for 'rcon', the password is not checked and may be '*'.");
860 if (argc < 3)
return false;
870DEF_CONSOLE_CMD(ConStatus)
873 IConsolePrint(
CC_HELP,
"List the status of all clients connected to the server. Usage 'status'.");
881DEF_CONSOLE_CMD(ConServerInfo)
885 IConsolePrint(
CC_HELP,
"You can change these values by modifying settings 'network.max_clients' and 'network.max_companies'.");
897DEF_CONSOLE_CMD(ConClientNickChange)
900 IConsolePrint(
CC_HELP,
"Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'.");
917 std::string client_name(argv[2]);
931DEF_CONSOLE_CMD(ConJoinCompany)
939 CompanyID company_id = (
CompanyID)(atoi(argv[1]) <= MAX_COMPANIES ? atoi(argv[1]) - 1 : atoi(argv[1]));
942 if (info ==
nullptr) {
949 IConsolePrint(
CC_ERROR,
"Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
978DEF_CONSOLE_CMD(ConMoveClient)
981 IConsolePrint(
CC_HELP,
"Move a client to another company. Usage: 'move <client-id> <company-id>'.");
982 IConsolePrint(
CC_HELP,
"For valid client-id see 'clients', for valid company-id see 'companies', use 255 for moving to spectators.");
987 CompanyID company_id = (
CompanyID)(atoi(argv[2]) <= MAX_COMPANIES ? atoi(argv[2]) - 1 : atoi(argv[2]));
996 IConsolePrint(
CC_ERROR,
"Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
1021DEF_CONSOLE_CMD(ConResetCompany)
1024 IConsolePrint(
CC_HELP,
"Remove an idle company from the game. Usage: 'reset_company <company-id>'.");
1025 IConsolePrint(
CC_HELP,
"For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
1029 if (argc != 2)
return false;
1035 IConsolePrint(
CC_ERROR,
"Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
1049 assert(ci !=
nullptr);
1062DEF_CONSOLE_CMD(ConNetworkClients)
1065 IConsolePrint(
CC_HELP,
"Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'.");
1074DEF_CONSOLE_CMD(ConNetworkReconnect)
1077 IConsolePrint(
CC_HELP,
"Reconnect to server to which you were connected last time. Usage: 'reconnect [<company>]'.");
1078 IConsolePrint(
CC_HELP,
"Company 255 is spectator (default, if not specified), 0 means creating new company.");
1084 switch (playas.base()) {
1090 if (playas < CompanyID::Begin() + 1 || playas > MAX_COMPANIES + 1)
return false;
1105DEF_CONSOLE_CMD(ConNetworkConnect)
1108 IConsolePrint(
CC_HELP,
"Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'.");
1109 IConsolePrint(
CC_HELP,
"IP can contain port and company: 'IP[:Port][#Company]', eg: 'server.ottd.org:443#2'.");
1110 IConsolePrint(
CC_HELP,
"Company #255 is spectator all others are a certain company with Company 1 being #1.");
1114 if (argc < 2)
return false;
1123DEF_CONSOLE_CMD(ConExec)
1130 if (argc < 2)
return false;
1134 if (!script_file.has_value()) {
1135 if (argc == 2 || atoi(argv[2]) != 0)
IConsolePrint(
CC_ERROR,
"Script file '{}' not found.", argv[1]);
1140 IConsolePrint(
CC_ERROR,
"Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
1148 while (fgets(cmdline,
sizeof(cmdline), *script_file) !=
nullptr) {
1150 for (
char *cmdptr = cmdline; *cmdptr !=
'\0'; cmdptr++) {
1151 if (*cmdptr ==
'\n' || *cmdptr ==
'\r') {
1164 if (ferror(*script_file) != 0) {
1172DEF_CONSOLE_CMD(ConSchedule)
1174 if (argc < 3 || std::string_view(argv[1]) !=
"on-next-calendar-month") {
1175 IConsolePrint(
CC_HELP,
"Schedule a local script to execute later. Usage: 'schedule on-next-calendar-month <script>'.");
1186 const std::string_view filename = std::string_view(argv[2]);
1188 IConsolePrint(
CC_INFO,
"Script file '{}' was already scheduled to execute at the start of next calendar month.", filename);
1192 IConsolePrint(
CC_INFO,
"Script file '{}' scheduled to execute at the start of next calendar month.", filename);
1201DEF_CONSOLE_CMD(ConReturn)
1215extern bool CloseConsoleLogIfActive();
1216extern std::span<const GRFFile> GetAllGRFFiles();
1220DEF_CONSOLE_CMD(ConScript)
1222 extern std::optional<FileHandle> _iconsole_output_file;
1225 IConsolePrint(
CC_HELP,
"Start or stop logging console output to a file. Usage: 'script <filename>'.");
1230 if (!CloseConsoleLogIfActive()) {
1231 if (argc < 2)
return false;
1234 if (!_iconsole_output_file.has_value()) {
1245DEF_CONSOLE_CMD(ConEcho)
1252 if (argc < 2)
return false;
1257DEF_CONSOLE_CMD(ConEchoC)
1260 IConsolePrint(
CC_HELP,
"Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'.");
1264 if (argc < 3)
return false;
1269DEF_CONSOLE_CMD(ConNewGame)
1273 IConsolePrint(
CC_HELP,
"The server can force a new game using 'newgame'; any client joined will rejoin after the server is done generating the new game.");
1281DEF_CONSOLE_CMD(ConRestart)
1283 if (argc == 0 || argc > 2) {
1285 IConsolePrint(
CC_HELP,
"Restarts a game, using either the current or newgame (default) settings.");
1286 IConsolePrint(
CC_HELP,
" * if you started from a new game, and your current/newgame settings haven't changed, the game will be identical to when you started it.");
1287 IConsolePrint(
CC_HELP,
" * if you started from a savegame / scenario / heightmap, the game might be different, because the current/newgame settings might differ.");
1291 if (argc == 1 || std::string_view(argv[1]) ==
"newgame") {
1302DEF_CONSOLE_CMD(ConReload)
1328 std::istringstream in(full_string);
1330 while (std::getline(in, line)) {
1335template <
typename F,
typename ... Args>
1336bool PrintList(F list_function, Args... args)
1338 std::string output_str;
1339 auto inserter = std::back_inserter(output_str);
1340 list_function(inserter, args...);
1346DEF_CONSOLE_CMD(ConListAILibs)
1356DEF_CONSOLE_CMD(ConListAI)
1366DEF_CONSOLE_CMD(ConListGameLibs)
1376DEF_CONSOLE_CMD(ConListGame)
1386DEF_CONSOLE_CMD(ConStartAI)
1388 if (argc == 0 || argc > 3) {
1390 IConsolePrint(
CC_HELP,
"Start a new AI. If <AI> is given, it starts that specific AI (if found).");
1391 IConsolePrint(
CC_HELP,
"If <settings> is given, it is parsed and the AI settings are set to that.");
1395 if (_game_mode != GM_NORMAL) {
1421 if (c->index != n)
break;
1427 config->
Change(argv[1], -1,
false);
1433 const char *e = strrchr(argv[1],
'.');
1435 size_t name_length = e - argv[1];
1438 int version = atoi(e);
1439 config->
Change(std::string(argv[1], name_length), version,
true);
1458DEF_CONSOLE_CMD(ConReloadAI)
1462 IConsolePrint(
CC_HELP,
"Reload the AI with the given company id. For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
1466 if (_game_mode != GM_NORMAL) {
1496DEF_CONSOLE_CMD(ConStopAI)
1500 IConsolePrint(
CC_HELP,
"Stop the AI with the given company id. For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
1504 if (_game_mode != GM_NORMAL) {
1533DEF_CONSOLE_CMD(ConRescanAI)
1550DEF_CONSOLE_CMD(ConRescanGame)
1567DEF_CONSOLE_CMD(ConRescanNewGRF)
1575 IConsolePrint(
CC_ERROR,
"NewGRF scanning is already running. Please wait until completed to run again.");
1581DEF_CONSOLE_CMD(ConGetSeed)
1585 IConsolePrint(
CC_HELP,
"The seed can be used to reproduce the exact same map as the game started with.");
1593DEF_CONSOLE_CMD(ConGetDate)
1596 IConsolePrint(
CC_HELP,
"Returns the current date (year-month-day) of the game. Usage: 'getdate'.");
1605DEF_CONSOLE_CMD(ConGetSysDate)
1608 IConsolePrint(
CC_HELP,
"Returns the current date (year-month-day) of your system. Usage: 'getsysdate'.");
1617DEF_CONSOLE_CMD(ConAlias)
1622 IConsolePrint(
CC_HELP,
"Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'.");
1626 if (argc < 3)
return false;
1629 if (alias ==
nullptr) {
1637DEF_CONSOLE_CMD(ConScreenShot)
1640 IConsolePrint(
CC_HELP,
"Create a screenshot of the game. Usage: 'screenshot [viewport | normal | big | giant | heightmap | minimap] [no_con] [size <width> <height>] [<filename>]'.");
1641 IConsolePrint(
CC_HELP,
" 'viewport' (default) makes a screenshot of the current viewport (including menus, windows).");
1645 IConsolePrint(
CC_HELP,
" 'heightmap' makes a heightmap screenshot of the map that can be loaded in as heightmap.");
1646 IConsolePrint(
CC_HELP,
" 'minimap' makes a top-viewed minimap screenshot of the whole world which represents one tile by one pixel.");
1647 IConsolePrint(
CC_HELP,
" 'no_con' hides the console to create the screenshot (only useful in combination with 'viewport').");
1648 IConsolePrint(
CC_HELP,
" 'size' sets the width and height of the viewport to make a screenshot of (only useful in combination with 'normal' or 'big').");
1649 IConsolePrint(
CC_HELP,
" A filename ending in # will prevent overwriting existing files and will number files counting upwards.");
1653 if (argc > 7)
return false;
1657 uint32_t height = 0;
1659 uint32_t arg_index = 1;
1661 if (argc > arg_index) {
1662 if (strcmp(argv[arg_index],
"viewport") == 0) {
1665 }
else if (strcmp(argv[arg_index],
"normal") == 0) {
1668 }
else if (strcmp(argv[arg_index],
"big") == 0) {
1671 }
else if (strcmp(argv[arg_index],
"giant") == 0) {
1674 }
else if (strcmp(argv[arg_index],
"heightmap") == 0) {
1677 }
else if (strcmp(argv[arg_index],
"minimap") == 0) {
1683 if (argc > arg_index && strcmp(argv[arg_index],
"no_con") == 0) {
1692 if (argc > arg_index + 2 && strcmp(argv[arg_index],
"size") == 0) {
1703 if (argc > arg_index) {
1705 name = argv[arg_index];
1709 if (argc > arg_index) {
1718DEF_CONSOLE_CMD(ConInfoCmd)
1721 IConsolePrint(
CC_HELP,
"Print out debugging information about a command. Usage: 'info_cmd <cmd>'.");
1725 if (argc < 2)
return false;
1728 if (cmd ==
nullptr) {
1740DEF_CONSOLE_CMD(ConDebugLevel)
1743 IConsolePrint(
CC_HELP,
"Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'.");
1744 IConsolePrint(
CC_HELP,
"Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'\"s.");
1748 if (argc > 2)
return false;
1759DEF_CONSOLE_CMD(ConExit)
1772DEF_CONSOLE_CMD(ConPart)
1775 IConsolePrint(
CC_HELP,
"Leave the currently joined/running game (only ingame). Usage: 'part'.");
1779 if (_game_mode != GM_NORMAL)
return false;
1790DEF_CONSOLE_CMD(ConHelp)
1797 if (cmd !=
nullptr) {
1798 cmd->
proc(0,
nullptr);
1803 if (alias !=
nullptr) {
1805 if (cmd !=
nullptr) {
1806 cmd->
proc(0,
nullptr);
1817 IConsolePrint(TC_LIGHT_BLUE,
" ---- OpenTTD Console Help ---- ");
1829DEF_CONSOLE_CMD(ConListCommands)
1838 if (argv[1] ==
nullptr || cmd->
name.find(argv[1]) != std::string::npos) {
1846DEF_CONSOLE_CMD(ConListAliases)
1853 for (
auto &it :
IConsole::Aliases()) {
1855 if (argv[1] ==
nullptr || alias->
name.find(argv[1]) != std::string::npos) {
1863DEF_CONSOLE_CMD(ConCompanies)
1872 std::string company_name =
GetString(STR_COMPANY_NAME, c->index);
1875 IConsolePrint(
CC_INFO,
"#:{}({}) Company Name: '{}' Year Founded: {} Money: {} Loan: {} Value: {} (T:{}, R:{}, P:{}, S:{}) {}",
1876 c->index + 1, colour, company_name,
1877 c->inaugurated_year, (int64_t)c->money, (int64_t)c->current_loan, (int64_t)
CalculateCompanyValue(c),
1879 c->group_all[
VEH_ROAD].num_vehicle,
1881 c->group_all[
VEH_SHIP].num_vehicle,
1882 c->is_ai ?
"AI" :
"");
1888DEF_CONSOLE_CMD(ConSay)
1891 IConsolePrint(
CC_HELP,
"Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'.");
1895 if (argc != 2)
return false;
1907DEF_CONSOLE_CMD(ConSayCompany)
1910 IConsolePrint(
CC_HELP,
"Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'.");
1911 IConsolePrint(
CC_HELP,
"CompanyNo is the company that plays as company <companyno>, 1 through max_companies.");
1915 if (argc != 3)
return false;
1933DEF_CONSOLE_CMD(ConSayClient)
1936 IConsolePrint(
CC_HELP,
"Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'.");
1941 if (argc != 3)
return false;
1960enum ConNetworkAuthorizedKeyAction : uint8_t {
1966static void PerformNetworkAuthorizedKeyAction(std::string_view name,
NetworkAuthorizedKeys *authorized_keys, ConNetworkAuthorizedKeyAction action,
const std::string &authorized_key,
CompanyID company = CompanyID::Invalid())
1975 if (authorized_keys->
Contains(authorized_key)) {
1980 if (company == CompanyID::Invalid()) {
1981 authorized_keys->
Add(authorized_key);
1990 if (!authorized_keys->
Contains(authorized_key)) {
1995 if (company == CompanyID::Invalid()) {
1996 authorized_keys->
Remove(authorized_key);
2006DEF_CONSOLE_CMD(ConNetworkAuthorizedKey)
2009 IConsolePrint(
CC_HELP,
"List and update authorized keys. Usage: 'authorized_key list [type]|add [type] [key]|remove [type] [key]'.");
2012 IConsolePrint(
CC_HELP,
" remove: remove the given key from the authorized keys of the given type; use 'all' to remove all authorized keys.");
2013 IConsolePrint(
CC_HELP,
"Instead of a key, use 'client:<id>' to add/remove the key of that given client.");
2021 ConNetworkAuthorizedKeyAction action;
2022 std::string_view action_string = argv[1];
2024 action = CNAKA_LIST;
2028 action = CNAKA_REMOVE;
2034 std::string authorized_key;
2035 if (action != CNAKA_LIST) {
2041 authorized_key = argv[3];
2043 std::string id_string(authorized_key.substr(7));
2045 if (authorized_key.empty()) {
2057 std::string_view type = argv[2];
2059 for (
auto [name, authorized_keys] :
_console_cmd_authorized_keys) PerformNetworkAuthorizedKeyAction(name, authorized_keys, action, authorized_key);
2060 for (
Company *c :
Company::Iterate()) PerformNetworkAuthorizedKeyAction(fmt::format(
"company:{}", c->index + 1), &c->allow_list, action, authorized_key, c->index);
2065 std::string id_string(type.substr(8));
2072 PerformNetworkAuthorizedKeyAction(type, &c->
allow_list, action, authorized_key, c->
index);
2079 PerformNetworkAuthorizedKeyAction(name, authorized_keys, action, authorized_key);
2089#if defined(WITH_ZLIB)
2095 static const std::initializer_list<std::pair<std::string_view, ContentType>> content_types = {
2103 for (
const auto &ct : content_types) {
2133 static const char *
const types[] = {
"Base graphics",
"NewGRF",
"AI",
"AI library",
"Scenario",
"Heightmap",
"Base sound",
"Base music",
"Game script",
"GS library" };
2135 static const char *
const states[] = {
"Not selected",
"Selected",
"Dep Selected",
"Installed",
"Unknown" };
2138 IConsolePrint(state_to_colour[ci.
state],
"{}, {}, {}, {}, {:08X}, {}", ci.
id, types[ci.
type - 1], states[ci.
state], ci.
name, ci.
unique_id,
FormatArrayAsHex(ci.
md5sum));
2141DEF_CONSOLE_CMD(ConContent)
2144 if (cb ==
nullptr) {
2150 IConsolePrint(
CC_HELP,
"Query, select and download content. Usage: 'content update|upgrade|select [id]|unselect [all|id]|state [filter]|download'.");
2153 IConsolePrint(
CC_HELP,
" select: select a specific item given by its id. If no parameter is given, all selected content will be listed.");
2154 IConsolePrint(
CC_HELP,
" unselect: unselect a specific item given by its id or 'all' to unselect all.");
2155 IConsolePrint(
CC_HELP,
" state: show the download/select state of all downloadable content. Optionally give a filter string.");
2226DEF_CONSOLE_CMD(ConFont)
2232 IConsolePrint(
CC_HELP,
" The \"Currently active\" configuration is the one actually in effect (after interface scaling and replacing unavailable fonts).");
2233 IConsolePrint(
CC_HELP,
" The \"Requested\" configuration is the one requested via console command or config file.");
2237 IConsolePrint(
CC_HELP,
" Set <font name> to \"\" for the default font. Note that <size> has no effect if the default font is in use, and fixed defaults are used instead.");
2238 IConsolePrint(
CC_HELP,
" If the sprite font is enabled in Game Options, it is used instead of the default font.");
2239 IConsolePrint(
CC_HELP,
" The <size> is automatically multiplied by the current interface scaling.");
2244 for (argfs =
FS_BEGIN; argfs < FS_END; argfs++) {
2249 if (argc > 1 && argfs == FS_END)
return false;
2253 std::string font = setting->
font;
2254 uint size = setting->
size;
2256 uint8_t arg_index = 2;
2260 font = argv[arg_index++];
2263 if (argc > arg_index) {
2271 SetFont(argfs, font, size);
2290DEF_CONSOLE_CMD(ConSetting)
2298 if (argc == 1 || argc > 3)
return false;
2303 IConsoleSetSetting(argv[1], argv[2]);
2309DEF_CONSOLE_CMD(ConSettingNewgame)
2312 IConsolePrint(
CC_HELP,
"Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'.");
2317 if (argc == 1 || argc > 3)
return false;
2322 IConsoleSetSetting(argv[1], argv[2],
true);
2328DEF_CONSOLE_CMD(ConListSettings)
2335 if (argc > 2)
return false;
2341DEF_CONSOLE_CMD(ConGamelogPrint)
2344 IConsolePrint(
CC_HELP,
"Print logged fundamental changes to the game since the start. Usage: 'gamelog'.");
2352DEF_CONSOLE_CMD(ConNewGRFReload)
2355 IConsolePrint(
CC_HELP,
"Reloads all active NewGRFs from disk. Equivalent to reapplying NewGRFs via the settings, but without asking for confirmation. This might crash OpenTTD!");
2363DEF_CONSOLE_CMD(ConListDirs)
2365 struct SubdirNameMap {
2370 static const SubdirNameMap subdir_name_map[] = {
2388 IConsolePrint(
CC_HELP,
"List all search paths or default directories for various categories.");
2390 std::string cats = subdir_name_map[0].name;
2392 for (
const SubdirNameMap &sdn : subdir_name_map) {
2393 if (!first) cats = cats +
", " + sdn.name;
2400 std::set<std::string> seen_dirs;
2401 for (
const SubdirNameMap &sdn : subdir_name_map) {
2406 std::string path = FioGetDirectory(sp, sdn.subdir);
2408 if (seen_dirs.find(path) != seen_dirs.end())
continue;
2409 seen_dirs.insert(path);
2414 if (!sdn.default_only || exists) {
2416 if (sdn.default_only)
break;
2429DEF_CONSOLE_CMD(ConNewGRFProfile)
2432 IConsolePrint(
CC_HELP,
"Collect performance data about NewGRF sprite requests and callbacks. Sub-commands can be abbreviated.");
2438 IConsolePrint(
CC_HELP,
" Unselect one or more GRFs from profiling. Use the keyword \"all\" instead of a GRF number to unselect all. Removing an active profiler aborts data collection.");
2440 IConsolePrint(
CC_HELP,
" Begin profiling all selected GRFs. If a number of ticks is provided, profiling stops after that many game ticks. There are 74 ticks in a calendar day.");
2448 std::span<const GRFFile> files = GetAllGRFFiles();
2454 for (
const auto &grf : files) {
2456 bool selected = profiler != _newgrf_profilers.end();
2457 bool active = selected && profiler->active;
2459 const char *statustext = active ?
" (active)" : selected ?
" (selected)" :
"";
2460 IConsolePrint(tc,
"{}: [{:08X}] {}{}", i, std::byteswap(grf.grfid), grf.filename, statustext);
2468 for (
size_t argnum = 2; argnum < argc; ++argnum) {
2469 int grfnum = atoi(argv[argnum]);
2470 if (grfnum < 1 || grfnum > (
int)files.size()) {
2474 const GRFFile *grf = &files[grfnum - 1];
2475 if (std::any_of(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; })) {
2476 IConsolePrint(
CC_WARNING,
"GRF number {} [{:08X}] is already selected for profiling.", grfnum, std::byteswap(grf->grfid));
2479 _newgrf_profilers.emplace_back(grf);
2486 for (
size_t argnum = 2; argnum < argc; ++argnum) {
2488 _newgrf_profilers.clear();
2491 int grfnum = atoi(argv[argnum]);
2492 if (grfnum < 1 || grfnum > (
int)files.size()) {
2496 const GRFFile *grf = &files[grfnum - 1];
2511 if (!grfids.empty()) grfids +=
", ";
2512 fmt::format_to(std::back_inserter(grfids),
"[{:08X}]", std::byteswap(pr.
grffile->grfid));
2519 uint64_t ticks = std::max(atoi(argv[2]), 1);
2523 }
else if (_newgrf_profilers.empty()) {
2526 IConsolePrint(
CC_ERROR,
"Did not start profiling for any GRFs, all selected GRFs are already profiling.");
2533 NewGRFProfiler::FinishAll();
2554static void IConsoleDebugLibRegister()
2562DEF_CONSOLE_CMD(ConFramerate)
2573DEF_CONSOLE_CMD(ConFramerateWindow)
2598 if (std::isgraph(
GB(label, 24, 8)) && std::isgraph(
GB(label, 16, 8)) && std::isgraph(
GB(label, 8, 8)) && std::isgraph(
GB(label, 0, 8))) {
2599 return fmt::format(
"{:c}{:c}{:c}{:c}",
GB(label, 24, 8),
GB(label, 16, 8),
GB(label, 8, 8),
GB(label, 0, 8));
2602 return fmt::format(
"{:08X}", std::byteswap(label));
2605static void ConDumpRoadTypes()
2614 std::map<uint32_t, const GRFFile *> grfs;
2617 if (rti->
label == 0)
continue;
2620 if (grf !=
nullptr) {
2622 grfs.emplace(grfid, grf);
2626 RoadTypeIsTram(rt) ?
"Tram" :
"Road",
2634 GetStringPtr(rti->strings.name)
2637 for (
const auto &grf : grfs) {
2642static void ConDumpRailTypes()
2652 std::map<uint32_t, const GRFFile *> grfs;
2655 if (rti->
label == 0)
continue;
2658 if (grf !=
nullptr) {
2660 grfs.emplace(grfid, grf);
2672 GetStringPtr(rti->strings.name)
2675 for (
const auto &grf : grfs) {
2680static void ConDumpCargoTypes()
2700 std::map<uint32_t, const GRFFile *> grfs;
2703 const GRFFile *grf = spec->grffile;
2704 if (grf !=
nullptr) {
2706 grfs.emplace(grfid, grf);
2708 IConsolePrint(
CC_DEFAULT,
" {:02d} Bit: {:2d}, Label: {}, Callback mask: 0x{:02X}, Cargo class: {}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}, GRF: {:08X}, {}",
2712 spec->callback_mask.base(),
2730 GetStringPtr(spec->name)
2733 for (
const auto &grf : grfs) {
2739DEF_CONSOLE_CMD(ConDumpInfo)
2759 ConDumpCargoTypes();
2770void IConsoleStdLibRegister()
2846#if defined(WITH_ZLIB)
2902 IConsoleDebugLibRegister();
Base functions for all AIs.
AIConfig stores the configuration settings of every AI.
constexpr enable_if_t< is_integral_v< T >, T > byteswap(T x) noexcept
Custom implementation of std::byteswap; remove once we build with C++23.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
@ NotPourable
Not Pourable (open wagon, but not hopper wagon)
@ Powderized
Powderized, moist protected (powder/silo wagon)
@ Hazardous
Hazardous cargo (Nuclear Fuel, Explosives, etc.)
@ NonPotable
Non-potable / non-food / dirty.
@ Bulk
Bulk cargo (Coal, Grain etc., Ores, Fruit)
@ Liquid
Liquids (Oil, Water, Rubber)
@ Potable
Potable / food / clean.
@ Oversized
Oversized (stake/flatbed wagon)
@ Armoured
Armoured cargo (Valuables, Gold, Diamonds)
@ Refrigerated
Refrigerated cargo (Food, Fruit)
@ Express
Express cargo (Goods, Food, Candy, but also possible for passengers)
@ Special
Special bit used for livery refit tricks instead of normal cargoes.
@ PieceGoods
Piece goods (Livestock, Wood, Steel, Paper)
@ Covered
Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for AIScanner::GetAIConsoleList.
static bool CanStartNew()
Is it possible to start a new AI company?
static void Rescan()
Rescans all searchpaths for available AIs.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
void SelectUpgrade()
Select everything that's an update for something we've got.
void DownloadSelectedContent(uint &files, uint &bytes, bool fallback=false)
Actually begin downloading the content we selected.
void Select(ContentID cid)
Select a specific content id.
void UnselectAll()
Unselect everything that we've not downloaded so far.
void RequestContentList(ContentType type)
Request the content list for the given type.
void AddCallback(ContentCallback *cb)
Add a callback to this class.
void Unselect(ContentID cid)
Unselect a specific content id.
static bool IsConnected()
Check whether the client is actually connected (and in the game).
File list storage for the console, for caching the last 'ls' command.
void ValidateFileList(bool force_reload=false)
(Re-)validate the file storage cache.
bool file_list_valid
If set, the file list is valid.
AbstractFileType abstract_filetype
The abstract file type to list.
void InvalidateFileList()
Declare the file storage cache as being invalid, also clears all stored files.
bool show_dirs
Whether to show directories in the file list.
static std::optional< FileHandle > Open(const std::string &filename, const std::string &mode)
Open an RAII file handle if possible.
List of file information.
const FiosItem * FindItem(const std::string_view file)
Find file information of a file by its name from the file list.
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs)
Construct a file list with the given kind of files, for the stated purpose.
Font cache for basic fonts.
virtual std::string GetFontName()=0
Get the name of this font.
bool HasParent()
Check whether the font cache has a parent.
virtual int GetFontSize() const
Get the nominal font size of the font.
static FontCache * Get(FontSize fs)
Get the font cache of a given font size.
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for GameScanner::GetConsoleList.
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for GameScanner::GetConsoleLibraryList.
void PrintConsole()
Print the gamelog data to the console.
An interval timer will fire every interval, and will continue to fire until it is deleted.
Simple helper to (more easily) manage authorized keys.
bool Contains(std::string_view key) const
Check whether the given key is contains in these authorized keys.
bool Add(std::string_view key)
Add the given key to the authorized keys, when it is not already contained.
bool Remove(std::string_view key)
Remove the given key from the authorized keys, when it is exists.
This struct contains all the info that is needed to draw and construct tracks.
RailTypeLabel label
Unique 32 bit rail type identifier.
RailTypeFlags flags
Bit mask of rail type flags.
const GRFFile * grffile[RTSG_END]
NewGRF providing the Action3 for the railtype.
RoadTypeLabel label
Unique 32 bit road type identifier.
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
void Change(std::optional< std::string > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
static Date date
Current date in days (day counter).
Functions related to commands.
Commands
List of commands.
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
ReferenceThroughBaseContainer< std::array< Colours, MAX_COMPANIES > > _company_colours
NOSAVE: can be determined from company structs.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Command definitions related to companies.
Functions related to companies.
@ CCA_NEW_AI
Create a new AI company.
@ CCA_DELETE
Delete a company.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
@ CALCA_REMOVE
Remove a public key.
@ CALCA_ADD
Create a public key.
static constexpr CompanyID COMPANY_NEW_COMPANY
The client wants a new company.
@ CRR_NONE
Dummy reason for actions that don't need one.
@ CRR_MANUAL
The company is manually removed.
static const uint NETWORK_PUBLIC_KEY_LENGTH
The maximum length of the hexadecimal encoded public keys, in bytes including '\0'.
bool GetArgumentInteger(uint32_t *value, const char *arg)
Change a string into its number representation.
void IConsoleCmdExec(const std::string &command_string, const uint recurse_count)
Execute a given command passed to us.
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
static void OutputContentState(const ContentInfo &ci)
Outputs content state information to console.
static std::vector< std::pair< std::string_view, NetworkAuthorizedKeys * > > _console_cmd_authorized_keys
All the known authorized keys with their name.
static std::string _scheduled_monthly_script
Script scheduled to execute by the 'schedule' console command (empty if no script is scheduled).
void ShowFramerateWindow()
Open the general framerate window.
static IntervalTimer< TimerGameCalendar > _scheduled_monthly_timer
Timer that runs every month of game time for the 'schedule' console command.
static ConsoleFileList _console_file_list_scenario
File storage cache for scenarios.
static ConsoleFileList _console_file_list_heightmap
File storage cache for heightmaps.
static std::string FormatLabel(uint32_t label)
Format a label as a string.
void ConPrintFramerate()
Print performance statistics to game console.
static uint _script_current_depth
Depth of scripts running (used to abort execution when #ConReturn is encountered).
static ContentType StringToContentType(const char *str)
Resolve a string to a content type.
static bool NetworkAvailable(bool echo)
Check network availability and inform in console about failure of detection.
static ConsoleFileList _console_file_list_savegame
File storage cache for savegames.
static void PrintLineByLine(const std::string &full_string)
Print a text buffer line by line to the console.
Console functions used outside of the console code.
void IConsoleClose()
Close the in-game console.
Internally used functions for the console.
@ CHR_HIDE
Hide the existence of the command.
@ CHR_DISALLOW
Disallow command execution.
@ CHR_ALLOW
Allow command execution.
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
static const TextColour CC_HELP
Colour for help lines.
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
static const TextColour CC_INFO
Colour for information lines.
static const TextColour CC_COMMAND
Colour for the console's commands.
static const TextColour CC_WARNING
Colour for warning lines.
static const TextColour CC_DEBUG
Colour for debug output.
static const TextColour CC_DEFAULT
Default colour of the console.
static const TextColour CC_ERROR
Colour for error lines.
void SetDebugString(const char *s, void(*error_func)(const std::string &))
Set debugging levels by parsing the text in s.
std::string GetDebugString()
Print out the current debug-level.
Functions related to debugging.
void StartupEngines()
Start/initialise all our engines.
Functions related to engines.
bool FioRemove(const std::string &filename)
Remove a file.
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
bool FileExists(const std::string &filename)
Test whether the given filename exists.
std::optional< FileHandle > FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Functions for Standard In/Out file operations.
@ SLO_SAVE
File is being saved.
@ SLO_LOAD
File is being loaded.
AbstractFileType GetAbstractFileType(FiosType fios_type)
Extract the abstract file type from a FiosType.
@ DFT_GAME_FILE
Save game or scenario file.
Searchpath
Types of searchpaths OpenTTD might use.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
@ AI_LIBRARY_DIR
Subdirectory for all AI libraries.
@ SCREENSHOT_DIR
Subdirectory for all screenshots.
@ SOCIAL_INTEGRATION_DIR
Subdirectory for all social integration plugins.
@ GAME_LIBRARY_DIR
Subdirectory for all GS libraries.
@ AI_DIR
Subdirectory for all AI files.
@ SCENARIO_DIR
Base directory for all scenarios.
@ BASE_DIR
Base directory for all subdirectories.
@ SAVE_DIR
Base directory for all savegames.
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
@ GAME_DIR
Subdirectory for all game scripts.
AbstractFileType
The different abstract types of files that the system knows about.
@ FT_SCENARIO
old or new scenario
@ FT_HEIGHTMAP
heightmap file
@ FT_SAVEGAME
old or new savegame
@ FT_INVALID
Invalid or unknown file type.
std::string FiosGetCurrentPath()
Get the current path/working directory.
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at _fios_path.
Declarations for savegames operations.
void InitFontCache(bool monospace)
(Re)initialize the font cache related things, i.e.
Functions to read fonts from files and cache them.
FontCacheSubSetting * GetFontCacheSubSetting(FontSize fs)
Get the settings of a given font size.
Base functions for all Games.
Gamelog _gamelog
Gamelog instance.
Functions to be called to log fundamental changes to the game.
Functions related to world/map generation.
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
void StartNewGameWithoutGUI(uint32_t seed)
Start a normal game without the GUI.
PauseModes _pause_mode
The current pause mode.
SwitchMode _switch_mode
The next mainloop command.
FontSize
Available font sizes.
@ FS_MONO
Index of the monospaced font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Functions related to OTTD's landscape.
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Miscellaneous command definitions.
ClientID _redirect_console_to_client
If not invalid, redirect the console output to a client.
bool _network_available
is network mode available?
bool _networking
are we in networking mode?
StringList _network_ban_list
The banned clients.
bool _network_dedicated
are we a dedicated server?
bool _network_server
network-server is active
ClientID _network_own_client_id
Our client identifier.
bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password)
Join a client to the server at with the given connection string.
Basic functions/variables used all over the place.
AdminID _redirect_console_to_admin
Redirection of the (remote) console to the admin.
Server part of the admin network protocol.
Base core network types and some helper functions to access them.
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data)
Send a chat message.
bool NetworkIsValidClientName(const std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
void NetworkClientRequestMove(CompanyID company_id)
Notify the server of this client wanting to be moved to another company.
void NetworkClientSendRcon(const std::string &password, const std::string &command)
Send a remote console command.
Client part of the network protocol.
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
Part of the network protocol handling content distribution.
std::string _network_server_invite_code
Our invite code as indicated by the Game Coordinator.
Network functions used by other parts of OpenTTD.
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64_t data=0, bool from_admin=false)
Send an actual chat message.
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name)
Change the client name of the given client.
void NetworkPrintClients()
Print all the clients to the console.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason)
Ban, or kick, everyone joined from the given client's IP.
void NetworkServerKickClient(ClientID client_id, const std::string &reason)
Kick a single client.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
std::string_view NetworkGetPublicKeyOfClient(ClientID client_id)
Get the public key of the client with the given id.
void NetworkServerShowStatusToConsole()
Show the status message of all clients on the console.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
ClientID
'Unique' identifier to be given to clients
@ INVALID_CLIENT_ID
Client is not part of anything.
@ CLIENT_ID_SERVER
Servers always have this ID.
Base for the NewGRF implementation.
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Profiling of NewGRF action 2 handling.
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
@ Error
A game paused because a (critical) error.
@ Normal
A game normally paused.
@ SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
@ SM_MENU
Switch to game intro menu.
@ SM_RESTARTGAME
Restart --> 'Random game' with current settings.
@ SM_RELOADGAME
Reload the savegame / scenario / heightmap you started the game with.
@ SM_LOAD_GAME
Load game, Play Scenario.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
RailTypeFlag
Railtype flag bit numbers.
@ Catenary
Bit number for drawing a catenary.
@ Allow90Deg
Bit number for always allowed 90 degree turns, regardless of setting.
@ Disallow90Deg
Bit number for never allowed 90 degree turns, regardless of setting.
@ Hidden
Bit number for hiding from selection.
@ NoSpriteCombine
Bit number for using non-combined junctions.
@ NoLevelCrossing
Bit number for disallowing level crossings.
@ RTSG_GROUND
Main group of ground images.
RailType
Enumeration for all possible railtypes.
@ RAILTYPE_BEGIN
Used for iterations.
@ RAILTYPE_END
Used for iterations.
RoadTypeFlag
Roadtype flag bit numbers.
@ NoHouses
Bit number for setting this roadtype as not house friendly.
@ TownBuild
Bit number for allowing towns to build this roadtype.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
@ ROTSG_GROUND
Required: Main group of ground images.
RoadType
The different roadtypes we support.
@ ROADTYPE_END
Used for iterations.
@ ROADTYPE_BEGIN
Used for iterations.
A number of safeguards to prevent using unsafe methods.
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
Main Save or Load function where the high-level saveload functions are handled.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Functions/types related to saving and loading games.
@ SL_OK
completed successfully
bool MakeScreenshot(ScreenshotType t, const std::string &name, uint32_t width, uint32_t height)
Schedule making a screenshot.
Functions to make screenshots.
ScreenshotType
Type of requested screenshot.
@ SC_VIEWPORT
Screenshot of viewport.
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
@ SC_HEIGHTMAP
Heightmap of the world.
@ SC_WORLD
World screenshot.
@ SC_MINIMAP
Minimap screenshot.
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
void SaveToConfig()
Save the values to the configuration file.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
ClientSettings _settings_client
The current settings for this game.
Functions related to setting/changing the settings.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
bool StrContainsIgnoreCase(const std::string_view str, const std::string_view value)
Checks if a string is contained in another string, while ignoring the case of the characters.
bool StrEqualsIgnoreCase(const std::string_view str1, const std::string_view str2)
Compares two string( view)s for equality, while ignoring the case of the characters.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
bool StrStartsWithIgnoreCase(std::string_view str, const std::string_view prefix)
Check whether the given string starts with the given prefix, ignoring case.
void StrTrimInPlace(std::string &str)
Trim the spaces from given string in place, i.e.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Functions related to OTTD's strings.
bool ai_in_multiplayer
so we allow AIs in multiplayer
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Specification of a cargo type.
NetworkSettings network
settings related to the network
GUISettings gui
settings related to the GUI
NetworkAuthorizedKeys allow_list
Public keys of clients that are allowed to join this company.
static bool IsHumanID(auto index)
Is this company a company not controlled by a NoAI program?
void OnConnect(bool success) override
Callback for when the connection has finished.
void OnDownloadComplete(ContentID cid) override
We have finished downloading a file.
void OnDisconnect() override
Callback for when the connection got disconnected.
Callbacks for notifying others about incoming data.
Container for all important information about a piece of content.
uint32_t unique_id
Unique ID; either GRF ID or shortname.
MD5Hash md5sum
The MD5 checksum.
State state
Whether the content info is selected (for download)
std::string name
Name of the content.
ContentID id
Unique (server side) ID for the content.
ContentType type
Type of content.
@ AUTOSELECTED
The content has been selected as dependency.
@ SELECTED
The content has been manually selected.
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
void Set(const FiosItem &item)
Set the title of the file.
Deals with finding savegames.
Settings for a single font.
std::string font
The name of the font, or path to the font.
uint size
The (requested) size of the font.
Dynamic data of a loaded NewGRF.
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?...
ZoomLevel zoom_min
minimum zoom out level
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
ZoomLevel zoom_max
maximum zoom out level
uint8_t map_x
X size of map.
uint8_t map_y
Y size of map.
uint32_t generation_seed
noise seed for world generation
AISettings ai
what may the AI do?
GameCreationSettings game_creation
settings used during the creation of a game (map)
–Aliases– Aliases are like shortcuts for complex functions, variable assignments, etc.
std::string cmdline
command(s) that is/are being aliased
std::string name
name of the alias
IConsoleCmdProc * proc
process executed when command is typed
IConsoleHook * hook
any special trigger action that needs executing
std::string name
name of command
static IConsoleAlias * AliasGet(const std::string &name)
Find the alias pointed to by its string.
static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook=nullptr)
Register a new command to be used in the console.
static IConsoleCmd * CmdGet(const std::string &name)
Find the command pointed to by its string.
static void AliasRegister(const std::string &name, const std::string &cmd)
Register a an alias for an already existing command in the console.
static uint SizeY()
Get the size of the map along the Y.
static debug_inline uint SizeX()
Get the size of the map along the X.
static debug_inline uint LogX()
Logarithm of the map size along the X side.
static uint LogY()
Logarithm of the map size along the y side.
static debug_inline uint Size()
Get the size of the map.
Container for all information known about a client.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
bool CanJoinCompany(CompanyID company_id) const
Returns whether the given company can be joined by this client.
CompanyID client_playas
As which company is this client playing (CompanyID)
ClientID client_id
Client identifier (same as ClientState->client_id)
uint8_t clients_on
Current count of clients on server.
uint8_t max_clients
maximum amount of clients
uint8_t max_companies
maximum amount of companies
NetworkAuthorizedKeys admin_authorized_keys
Public keys of clients that are authorized to use the admin network.
NetworkAuthorizedKeys rcon_authorized_keys
Public keys of clients that are authorized to use the rconsole (server side).
std::string last_joined
Last joined server.
NetworkAuthorizedKeys server_authorized_keys
Public keys of clients that are authorized to connect to the game.
Callback profiler for NewGRF development.
static void StartTimer(uint64_t ticks)
Start the timeout timer that will finish all profiling sessions.
bool active
Is this profiler collecting data.
const GRFFile * grffile
Which GRF is being profiled.
static void AbortTimer()
Abort the timeout timer, so the timer callback is never called.
static size_t GetNumItems()
Returns number of valid items in the pool.
Tindex index
Index of this pool item.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * GetIfValid(auto index)
Returns Titem with given index.
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
Data structure for viewport, display of a part of the world.
ZoomLevel zoom
The zoom level of the viewport.
Data structure for an opened window.
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
uint32_t ContentID
Unique identifier for the content.
ContentType
The values in the enum are important; they are used as database 'keys'.
@ CONTENT_TYPE_AI_LIBRARY
The content consists of an AI library.
@ CONTENT_TYPE_BASE_GRAPHICS
The content consists of base graphics.
@ CONTENT_TYPE_AI
The content consists of an AI.
@ CONTENT_TYPE_SCENARIO
The content consists of a scenario.
@ CONTENT_TYPE_NEWGRF
The content consists of a NewGRF.
@ CONTENT_TYPE_BEGIN
Helper to mark the begin of the types.
@ CONTENT_TYPE_END
Helper to mark the end of the types.
@ CONTENT_TYPE_HEIGHTMAP
The content consists of a heightmap.
Definition of Interval and OneShot timers.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
@ ZOOM_IN
Zoom in (get more detailed view).
@ ZOOM_OUT
Zoom out (get helicopter view).
Window * GetMainWindow()
Get the main window, i.e.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Window functions not directly related to making/drawing windows.
@ WC_CONSOLE
Console; Window numbers:
@ ZOOM_LVL_MAX
Maximum zoom level.
@ ZOOM_LVL_MIN
Minimum zoom level.