Go to the documentation of this file.
43 #include "table/strings.h"
84 #define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[])
85 #define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo)
99 if (echo)
IConsoleError(
"You cannot use this command because there is no network available.");
114 if (echo)
IConsoleError(
"This command is only available to a network server.");
129 if (echo)
IConsoleError(
"This command is not available to a network server.");
144 if (echo)
IConsoleError(
"Not connected. This command is only available in multiplayer.");
157 if (echo)
IConsoleError(
"This command is forbidden in multiplayer.");
166 if (_game_mode == GM_MENU) {
167 if (echo)
IConsoleError(
"This command is only available in game and editor.");
170 return ConHookNoNetwork(echo);
191 IConsoleHelp(
"Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'");
207 IConsoleHelp(
"Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
211 if (_game_mode == GM_MENU) {
212 IConsoleError(
"This command is only available in game and editor.");
217 IConsoleError(
"This can only be done when there are no vehicles in the game.");
233 IConsoleHelp(
"Reset a tile to bare land. Usage: 'resettile <tile>'");
234 IConsoleHelp(
"Tile can be either decimal (34161) or hexadecimal (0x4a5B)");
264 IConsoleHelp(
"Usage: 'scrollto <tile>' or 'scrollto <x> <y>'");
265 IConsoleHelp(
"Numbers can be either decimal (34161) or hexadecimal (0x4a5B).");
306 IConsoleHelp(
"Save the current game. Usage: 'save <filename>'");
311 char *filename =
str_fmt(
"%s.sav", argv[1]);
333 IConsoleHelp(
"Saves the configuration for new games to the configuration file, typically 'openttd.cfg'.");
334 IConsoleHelp(
"It does not save the configuration of the current game to the configuration file.");
346 IConsoleHelp(
"Load a game by name or index. Usage: 'load <file | number>'");
350 if (argc != 2)
return false;
352 const char *file = argv[1];
355 if (item !=
nullptr) {
375 IConsoleHelp(
"Remove a savegame by name or index. Usage: 'rm <file | number>'");
379 if (argc != 2)
return false;
381 const char *file = argv[1];
384 if (item !=
nullptr) {
401 IConsoleHelp(
"List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'");
417 IConsoleHelp(
"Change the dir via console. Usage: 'cd <directory | number>'");
421 if (argc != 2)
return false;
423 const char *file = argv[1];
426 if (item !=
nullptr) {
427 switch (item->type) {
428 case FIOS_TYPE_DIR:
case FIOS_TYPE_DRIVE:
case FIOS_TYPE_PARENT:
446 IConsoleHelp(
"Print out the current working directory. Usage: 'pwd'");
462 IConsoleHelp(
"Clear the console buffer. Usage: 'clear'");
466 IConsoleClearBuffer();
476 static bool ConKickOrBan(
const char *argv,
bool ban,
const char *reason)
480 if (strchr(argv,
'.') ==
nullptr && strchr(argv,
':') ==
nullptr) {
522 IConsoleHelp(
"Kick a client from a network game. Usage: 'kick <ip | client-id> [<kick-reason>]'");
523 IConsoleHelp(
"For client-id's, see the command 'clients'");
527 if (argc != 2 && argc != 3)
return false;
530 if (argc == 2)
return ConKickOrBan(argv[1],
false,
nullptr);
533 size_t kick_message_length = strlen(argv[2]);
534 if (kick_message_length >= 255) {
535 IConsolePrintF(
CC_ERROR,
"ERROR: Maximum kick message length is 254 characters. You entered " PRINTF_SIZE
" characters.", kick_message_length);
538 return ConKickOrBan(argv[1],
false, argv[2]);
545 IConsoleHelp(
"Ban a client from a network game. Usage: 'ban <ip | client-id> [<ban-reason>]'");
546 IConsoleHelp(
"For client-id's, see the command 'clients'");
547 IConsoleHelp(
"If the client is no longer online, you can still ban his/her IP");
551 if (argc != 2 && argc != 3)
return false;
554 if (argc == 2)
return ConKickOrBan(argv[1],
true,
nullptr);
557 size_t kick_message_length = strlen(argv[2]);
558 if (kick_message_length >= 255) {
559 IConsolePrintF(
CC_ERROR,
"ERROR: Maximum kick message length is 254 characters. You entered " PRINTF_SIZE
" characters.", kick_message_length);
562 return ConKickOrBan(argv[1],
true, argv[2]);
569 IConsoleHelp(
"Unban a client from a network game. Usage: 'unban <ip | banlist-index>'");
570 IConsoleHelp(
"For a list of banned IP's, see the command 'banlist'");
574 if (argc != 2)
return false;
584 index = atoi(argv[1]) - 1U;
603 IConsoleHelp(
"List the IP's of banned clients: Usage 'banlist'");
638 IConsoleHelp(
"Unpause a network game. Usage: 'unpause'");
659 IConsoleHelp(
"Remote control the server from another client. Usage: 'rcon <password> <command>'");
660 IConsoleHelp(
"Remember to enclose the command in quotes, otherwise only the first parameter is sent");
664 if (argc < 3)
return false;
677 IConsoleHelp(
"List the status of all clients connected to the server. Usage 'status'");
688 IConsoleHelp(
"List current and maximum client/company limits. Usage 'server_info'");
689 IConsoleHelp(
"You can change these values by modifying settings 'network.max_clients', 'network.max_companies' and 'network.max_spectators'");
703 IConsoleHelp(
"Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'");
704 IConsoleHelp(
"For client-id's, see the command 'clients'");
711 IConsoleError(
"Please use the command 'name' to change your own name!");
730 IConsoleHelp(
"Request joining another company. Usage: join <company-id> [<password>]");
731 IConsoleHelp(
"For valid company-id see company list, use 255 for spectator");
749 IConsoleError(
"Cannot join spectators, maximum number of spectators reached.");
777 IConsoleHelp(
"Move a client to another company. Usage: move <client-id> <company-id>");
778 IConsoleHelp(
"For valid client-id see 'clients', for valid company-id see 'companies', use 255 for moving to spectators");
787 IConsoleError(
"Invalid client-id, check the command 'clients' for valid client-id's.");
807 IConsoleError(
"You cannot move someone to where he/she already is!");
820 IConsoleHelp(
"Remove an idle company from the game. Usage: 'reset_company <company-id>'");
821 IConsoleHelp(
"For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
825 if (argc != 2)
return false;
841 IConsoleError(
"Cannot remove company: a client is connected to that company.");
846 IConsoleError(
"Cannot remove company: the server is connected to that company.");
860 IConsoleHelp(
"Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'");
872 IConsoleHelp(
"Reconnect to server to which you were connected last time. Usage: 'reconnect [<company>]'");
873 IConsoleHelp(
"Company 255 is spectator (default, if not specified), 0 means creating new company.");
874 IConsoleHelp(
"All others are a certain company with Company 1 being #1");
885 if (playas < COMPANY_FIRST + 1 || playas >
MAX_COMPANIES + 1)
return false;
904 IConsoleHelp(
"Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'");
905 IConsoleHelp(
"IP can contain port and company: 'IP[:Port][#Company]', eg: 'server.ottd.org:443#2'");
906 IConsoleHelp(
"Company #255 is spectator all others are a certain company with Company 1 being #1");
910 if (argc < 2)
return false;
912 const char *port =
nullptr;
913 const char *company =
nullptr;
922 if (company !=
nullptr) {
933 if (port !=
nullptr) {
938 NetworkClientConnectGame(ip, rport, join_as);
950 IConsoleHelp(
"Execute a local script file. Usage: 'exec <script> <?>'");
954 if (argc < 2)
return false;
958 if (script_file ==
nullptr) {
959 if (argc == 2 || atoi(argv[2]) != 0)
IConsoleError(
"script file not found");
964 IConsoleError(
"Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
972 while (fgets(cmdline,
sizeof(cmdline), script_file) !=
nullptr) {
974 for (
char *cmdptr = cmdline; *cmdptr !=
'\0'; cmdptr++) {
975 if (*cmdptr ==
'\n' || *cmdptr ==
'\r') {
988 if (ferror(script_file)) {
989 IConsoleError(
"Encountered error while trying to read from script file");
1000 IConsoleHelp(
"Stop executing a running script. Usage: 'return'");
1011 extern bool CloseConsoleLogIfActive();
1015 extern FILE *_iconsole_output_file;
1018 IConsoleHelp(
"Start or stop logging console output to a file. Usage: 'script <filename>'");
1019 IConsoleHelp(
"If filename is omitted, a running log is stopped if it is active");
1023 if (!CloseConsoleLogIfActive()) {
1024 if (argc < 2)
return false;
1027 _iconsole_output_file = fopen(argv[1],
"ab");
1028 if (_iconsole_output_file ==
nullptr)
IConsoleError(
"could not open file");
1038 IConsoleHelp(
"Print back the first argument to the console. Usage: 'echo <arg>'");
1042 if (argc < 2)
return false;
1050 IConsoleHelp(
"Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'");
1054 if (argc < 3)
return false;
1062 IConsoleHelp(
"Start a new game. Usage: 'newgame [seed]'");
1063 IConsoleHelp(
"The server can force a new game using 'newgame'; any client joined will rejoin after the server is done generating the new game.");
1075 IConsoleHelp(
"Restarts a game. It tries to reproduce the exact same map as the game started with.");
1077 IConsoleHelp(
" * restarting games started in another version might create another map due to difference in map generation");
1078 IConsoleHelp(
" * restarting games based on scenarios, loaded games or heightmaps will start a new game based on the settings stored in the scenario/savegame");
1094 IConsoleHelp(
" * if you started from a savegame / scenario / heightmap, that exact same savegame / scenario / heightmap will be loaded.");
1095 IConsoleHelp(
" * if you started from a new game, this acts the same as 'restart'.");
1115 for (
char *p2 = buf; *p2 !=
'\0'; p2++) {
1166 if (argc == 0 || argc > 3) {
1167 IConsoleHelp(
"Start a new AI. Usage: 'start_ai [<AI>] [<settings>]'");
1168 IConsoleHelp(
"Start a new AI. If <AI> is given, it starts that specific AI (if found).");
1169 IConsoleHelp(
"If <settings> is given, it is parsed and the AI settings are set to that.");
1173 if (_game_mode != GM_NORMAL) {
1187 IConsoleWarning(
"AIs are not allowed in multiplayer by configuration.");
1199 if (c->index != n)
break;
1205 config->
Change(argv[1], -1,
false);
1211 char *name =
stredup(argv[1]);
1212 char *e = strrchr(name,
'.');
1217 int version = atoi(e);
1218 config->
Change(name, version,
true);
1241 IConsoleHelp(
"Reload an AI. Usage: 'reload_ai <company-id>'");
1242 IConsoleHelp(
"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.");
1246 if (_game_mode != GM_NORMAL) {
1279 IConsoleHelp(
"Stop an AI. Usage: 'stop_ai <company-id>'");
1280 IConsoleHelp(
"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.");
1284 if (_game_mode != GM_NORMAL) {
1316 IConsoleHelp(
"Rescan the AI dir for scripts. Usage: 'rescan_ai'");
1321 IConsoleWarning(
"Only the server can rescan the AI dir for scripts.");
1333 IConsoleHelp(
"Rescan the Game Script dir for scripts. Usage: 'rescan_game'");
1338 IConsoleWarning(
"Only the server can rescan the Game Script dir for scripts.");
1350 IConsoleHelp(
"Rescan the data dir for NewGRFs. Usage: 'rescan_newgrf'");
1355 IConsoleWarning(
"NewGRF scanning is already running. Please wait until completed to run again.");
1364 IConsoleHelp(
"Returns the seed used to create this game. Usage: 'getseed'");
1365 IConsoleHelp(
"The seed can be used to reproduce the exact same map as the game started with.");
1376 IConsoleHelp(
"Returns the current date (year-month-day) of the game. Usage: 'getdate'");
1389 IConsoleHelp(
"Returns the current date (year-month-day) of your system. Usage: 'getsysdate'");
1395 auto timeinfo = localtime(&t);
1396 IConsolePrintF(
CC_DEFAULT,
"System Date: %04d-%02d-%02d %02d:%02d:%02d", timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
1406 IConsoleHelp(
"Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'");
1410 if (argc < 3)
return false;
1413 if (alias ==
nullptr) {
1425 IConsoleHelp(
"Create a screenshot of the game. Usage: 'screenshot [viewport | normal | big | giant | heightmap | minimap] [no_con] [size <width> <height>] [<filename>]'");
1426 IConsoleHelp(
"'viewport' (default) makes a screenshot of the current viewport (including menus, windows, ..), "
1427 "'normal' makes a screenshot of the visible area, "
1428 "'big' makes a zoomed-in screenshot of the visible area, "
1429 "'giant' makes a screenshot of the whole map, "
1430 "'heightmap' makes a heightmap screenshot of the map that can be loaded in as heightmap, "
1431 "'minimap' makes a top-viewed minimap screenshot of the whole world which represents one tile by one pixel. "
1432 "'no_con' hides the console to create the screenshot (only useful in combination with 'viewport'). "
1433 "'size' sets the width and height of the viewport to make a screenshot of (only useful in combination with 'normal' or 'big').");
1437 if (argc > 7)
return false;
1443 uint32 arg_index = 1;
1445 if (argc > arg_index) {
1446 if (strcmp(argv[arg_index],
"viewport") == 0) {
1449 }
else if (strcmp(argv[arg_index],
"normal") == 0) {
1452 }
else if (strcmp(argv[arg_index],
"big") == 0) {
1455 }
else if (strcmp(argv[arg_index],
"giant") == 0) {
1458 }
else if (strcmp(argv[arg_index],
"heightmap") == 0) {
1461 }
else if (strcmp(argv[arg_index],
"minimap") == 0) {
1467 if (argc > arg_index && strcmp(argv[arg_index],
"no_con") == 0) {
1469 IConsoleError(
"'no_con' can only be used in combination with 'viewport'");
1476 if (argc > arg_index + 2 && strcmp(argv[arg_index],
"size") == 0) {
1479 IConsoleError(
"'size' can only be used in combination with 'normal' or 'big'");
1487 if (argc > arg_index) {
1489 name = argv[arg_index];
1493 if (argc > arg_index) {
1505 IConsoleHelp(
"Print out debugging information about a command. Usage: 'info_cmd <cmd>'");
1509 if (argc < 2)
return false;
1512 if (cmd ==
nullptr) {
1528 IConsoleHelp(
"Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'");
1529 IConsoleHelp(
"Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'s");
1533 if (argc > 2)
return false;
1560 IConsoleHelp(
"Leave the currently joined/running game (only ingame). Usage: 'part'");
1564 if (_game_mode != GM_NORMAL)
return false;
1578 if (cmd !=
nullptr) {
1579 cmd->
proc(0,
nullptr);
1584 if (alias !=
nullptr) {
1586 if (cmd !=
nullptr) {
1587 cmd->
proc(0,
nullptr);
1613 IConsoleHelp(
"List all registered commands. Usage: 'list_cmds [<pre-filter>]'");
1618 if (argv[1] ==
nullptr || strstr(cmd->
name, argv[1]) !=
nullptr) {
1629 IConsoleHelp(
"List all registered aliases. Usage: 'list_aliases [<pre-filter>]'");
1634 if (argv[1] ==
nullptr || strstr(alias->
name, argv[1]) !=
nullptr) {
1645 IConsoleHelp(
"List the details of all companies in the game. Usage 'companies'");
1651 char company_name[512];
1653 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
1655 const char *password_state =
"";
1657 password_state =
"AI";
1664 IConsolePrintF(
CC_INFO,
"#:%d(%s) Company Name: '%s' Year Founded: %d Money: " OTTD_PRINTF64
" Loan: " OTTD_PRINTF64
" Value: " OTTD_PRINTF64
" (T:%d, R:%d, P:%d, S:%d) %s",
1665 c->index + 1, colour, company_name,
1668 c->group_all[
VEH_ROAD].num_vehicle,
1670 c->group_all[
VEH_SHIP].num_vehicle,
1680 IConsoleHelp(
"Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'");
1684 if (argc != 2)
return false;
1699 IConsoleHelp(
"Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'");
1700 IConsoleHelp(
"CompanyNo is the company that plays as company <companyno>, 1 through max_companies");
1704 if (argc != 3)
return false;
1725 IConsoleHelp(
"Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'");
1726 IConsoleHelp(
"For client-id's, see the command 'clients'");
1730 if (argc != 3)
return false;
1745 const char *helpmsg;
1748 helpmsg =
"Change the password of a company. Usage: 'company_pw <company-no> \"<password>\"";
1750 helpmsg =
"Change the password of your or any other company. Usage: 'company_pw [<company-no>] \"<password>\"'";
1752 helpmsg =
"Change the password of your company. Usage: 'company_pw \"<password>\"'";
1761 const char *password;
1762 const char *errormsg;
1767 errormsg =
"You have to own a company to make use of this command.";
1769 company_id = (
CompanyID)(atoi(argv[1]) - 1);
1771 errormsg =
"You have to specify the ID of a valid human controlled company.";
1793 #if defined(WITH_ZLIB)
1799 static const char *
const inv_lookup[] = {
"",
"base",
"newgrf",
"ai",
"ailib",
"scenario",
"heightmap" };
1800 for (uint i = 1 ; i <
lengthof(inv_lookup); i++) {
1801 if (strcasecmp(str, inv_lookup[i]) == 0)
return (
ContentType)i;
1830 static const char *
const types[] = {
"Base graphics",
"NewGRF",
"AI",
"AI library",
"Scenario",
"Heightmap",
"Base sound",
"Base music",
"Game script",
"GS library" };
1832 static const char *
const states[] = {
"Not selected",
"Selected",
"Dep Selected",
"Installed",
"Unknown" };
1835 char buf[
sizeof(ci->
md5sum) * 2 + 1];
1837 IConsolePrintF(state_to_colour[ci->
state],
"%d, %s, %s, %s, %08X, %s", ci->
id, types[ci->
type - 1], states[ci->
state], ci->
name, ci->
unique_id, buf);
1843 if (cb ==
nullptr) {
1849 IConsoleHelp(
"Query, select and download content. Usage: 'content update|upgrade|select [id]|unselect [all|id]|state [filter]|download'");
1850 IConsoleHelp(
" update: get a new list of downloadable content; must be run first");
1851 IConsoleHelp(
" upgrade: select all items that are upgrades");
1852 IConsoleHelp(
" select: select a specific item given by its id. If no parameter is given, all selected content will be listed");
1853 IConsoleHelp(
" unselect: unselect a specific item given by its id or 'all' to unselect all");
1854 IConsoleHelp(
" state: show the download/select state of all downloadable content. Optionally give a filter string");
1855 IConsoleHelp(
" download: download all content you've selected");
1859 if (strcasecmp(argv[1],
"update") == 0) {
1864 if (strcasecmp(argv[1],
"upgrade") == 0) {
1869 if (strcasecmp(argv[1],
"select") == 0) {
1877 }
else if (strcasecmp(argv[2],
"all") == 0) {
1884 IConsoleError(
"'select all' is no longer supported since 1.11");
1891 if (strcasecmp(argv[1],
"unselect") == 0) {
1896 if (strcasecmp(argv[2],
"all") == 0) {
1904 if (strcasecmp(argv[1],
"state") == 0) {
1907 if (argc > 2 && strcasestr((*iter)->name, argv[2]) ==
nullptr)
continue;
1913 if (strcasecmp(argv[1],
"download") == 0) {
1928 IConsoleHelp(
"Change setting for all clients. Usage: 'setting <name> [<value>]'");
1929 IConsoleHelp(
"Omitting <value> will print out the current value of the setting.");
1933 if (argc == 1 || argc > 3)
return false;
1938 IConsoleSetSetting(argv[1], argv[2]);
1947 IConsoleHelp(
"Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'");
1948 IConsoleHelp(
"Omitting <value> will print out the current value of the setting.");
1952 if (argc == 1 || argc > 3)
return false;
1957 IConsoleSetSetting(argv[1], argv[2],
true);
1966 IConsoleHelp(
"List settings. Usage: 'list_settings [<pre-filter>]'");
1970 if (argc > 2)
return false;
1985 IConsoleHelp(
"Reloads all active NewGRFs from disk. Equivalent to reapplying NewGRFs via the settings, but without asking for confirmation. This might crash OpenTTD!");
1996 IConsoleHelp(
"Collect performance data about NewGRF sprite requests and callbacks. Sub-commands can be abbreviated.");
1998 IConsoleHelp(
" List all NewGRFs that can be profiled, and their status.");
1999 IConsoleHelp(
"Usage: newgrf_profile select <grf-num>...");
2000 IConsoleHelp(
" Select one or more GRFs for profiling.");
2001 IConsoleHelp(
"Usage: newgrf_profile unselect <grf-num>...");
2002 IConsoleHelp(
" 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.");
2003 IConsoleHelp(
"Usage: newgrf_profile start [<num-days>]");
2004 IConsoleHelp(
" Begin profiling all selected GRFs. If a number of days is provided, profiling stops after that many in-game days.");
2006 IConsoleHelp(
" End profiling and write the collected data to CSV files.");
2008 IConsoleHelp(
" End profiling and discard all collected data.");
2012 extern const std::vector<GRFFile *> &GetAllGRFFiles();
2013 const std::vector<GRFFile *> &files = GetAllGRFFiles();
2016 if (argc == 1 || strncasecmp(argv[1],
"lis", 3) == 0) {
2020 auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; });
2021 bool selected = profiler != _newgrf_profilers.end();
2022 bool active = selected && profiler->active;
2024 const char *statustext = active ?
" (active)" : selected ?
" (selected)" :
"";
2032 if (strncasecmp(argv[1],
"sel", 3) == 0 && argc >= 3) {
2033 for (
size_t argnum = 2; argnum < argc; ++argnum) {
2034 int grfnum = atoi(argv[argnum]);
2035 if (grfnum < 1 || grfnum > (
int)files.size()) {
2039 GRFFile *grf = files[grfnum - 1];
2040 if (std::any_of(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; })) {
2044 _newgrf_profilers.emplace_back(grf);
2050 if (strncasecmp(argv[1],
"uns", 3) == 0 && argc >= 3) {
2051 for (
size_t argnum = 2; argnum < argc; ++argnum) {
2052 if (strcasecmp(argv[argnum],
"all") == 0) {
2053 _newgrf_profilers.clear();
2056 int grfnum = atoi(argv[argnum]);
2057 if (grfnum < 1 || grfnum > (
int)files.size()) {
2061 GRFFile *grf = files[grfnum - 1];
2062 auto pos = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; });
2063 if (pos != _newgrf_profilers.end()) _newgrf_profilers.erase(pos);
2069 if (strncasecmp(argv[1],
"sta", 3) == 0) {
2077 if (!grfids.empty()) grfids +=
", ";
2078 char grfidstr[12]{ 0 };
2086 int days = std::max(atoi(argv[2]), 1);
2087 _newgrf_profile_end_date =
_date + days;
2089 char datestrbuf[32]{ 0 };
2091 GetString(datestrbuf, STR_JUST_DATE_ISO,
lastof(datestrbuf));
2094 _newgrf_profile_end_date =
MAX_DAY;
2096 }
else if (_newgrf_profilers.empty()) {
2105 if (strncasecmp(argv[1],
"sto", 3) == 0) {
2106 NewGRFProfiler::FinishAll();
2111 if (strncasecmp(argv[1],
"abo", 3) == 0) {
2115 _newgrf_profile_end_date =
MAX_DAY;
2127 static void IConsoleDebugLibRegister()
2140 IConsoleHelp(
"Show frame rate and game speed information");
2158 IConsoleError(
"Can not open frame rate window on a dedicated server");
2166 static void ConDumpRoadTypes()
2175 std::map<uint32, const GRFFile *> grfs;
2178 if (rti->
label == 0)
continue;
2181 if (grf !=
nullptr) {
2183 grfs.emplace(grfid, grf);
2187 RoadTypeIsTram(rt) ?
"Tram" :
"Road",
2198 for (
const auto &grf : grfs) {
2203 static void ConDumpRailTypes()
2213 std::map<uint32, const GRFFile *> grfs;
2216 if (rti->
label == 0)
continue;
2219 if (grf !=
nullptr) {
2221 grfs.emplace(grfid, grf);
2236 for (
const auto &grf : grfs) {
2241 static void ConDumpCargoTypes()
2256 std::map<uint32, const GRFFile *> grfs;
2259 if (!spec->
IsValid())
continue;
2262 if (grf !=
nullptr) {
2264 grfs.emplace(grfid, grf);
2266 IConsolePrintF(
CC_DEFAULT,
" %02u Bit: %2u, Label: %c%c%c%c, Callback mask: 0x%02X, Cargo class: %c%c%c%c%c%c%c%c%c%c%c, GRF: %08X, %s",
2283 GetStringPtr(spec->
name)
2286 for (
const auto &grf : grfs) {
2296 IConsoleHelp(
"Usage: dump_info roadtypes|railtypes|cargotypes");
2297 IConsoleHelp(
" Show information about road/tram types, rail types or cargo types.");
2301 if (strcasecmp(argv[1],
"roadtypes") == 0) {
2306 if (strcasecmp(argv[1],
"railtypes") == 0) {
2311 if (strcasecmp(argv[1],
"cargotypes") == 0) {
2312 ConDumpCargoTypes();
2323 void IConsoleStdLibRegister()
2389 #if defined(WITH_ZLIB)
2448 IConsoleDebugLibRegister();
@ VEH_AIRCRAFT
Aircraft vehicle type.
static uint MapLogX()
Logarithm of the map size along the X side.
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
RoadTypeFlags flags
Bit mask of road type flags.
@ ROTF_NO_LEVEL_CROSSING
Bit number for disabling level crossing.
static ConsoleFileList _console_file_list
File storage cache for the console.
void NetworkClientSendRcon(const char *password, const char *command)
Send a remote console command.
Callbacks for notifying others about incoming data.
uint32 TileIndex
The index/ID of a Tile.
static const TextColour CC_INFO
Colour for information lines.
@ ROTSG_GROUND
Required: Main group of ground images.
@ CC_HAZARDOUS
Hazardous cargo (Nuclear Fuel, Explosives, etc.)
uint8 callback_mask
Bitmask of cargo callbacks that have to be called.
uint32 generation_seed
noise seed for world generation
@ CC_COVERED
Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
void SetDebugString(const char *s)
Set debugging levels by parsing the text in s.
IConsoleCmdProc * proc
process executed when command is typed
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
static const uint16 NETWORK_DEFAULT_PORT
The default port of the game server (TCP & UDP)
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
CargoLabel label
Unique label of the cargo type.
StringID FiosGetDescText(const char **path, uint64 *total_free)
Get descriptive texts.
@ SAVE_DIR
Base directory for all savegames.
void NetworkServerShowStatusToConsole()
Show the status message of all clients on the console.
ContentType type
Type of content.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
ConstContentIterator End() const
Get the end of the content inf iterator.
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
uint8 max_spectators
maximum amount of spectators
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
@ ROTF_CATENARY
Bit number for adding catenary.
ScreenshotType
Type of requested screenshot.
@ SM_LOAD_GAME
Load game, Play Scenario.
static void OutputContentState(const ContentInfo *const ci)
Outputs content state information to console.
struct RoadTypeInfo::@44 strings
Strings associated with the rail type.
uint8 map_y
Y size of map.
bool NetworkMaxSpectatorsReached()
Check if max_spectatos has been reached on the server (local check only).
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
uint8 max_clients
maximum amount of clients
void SetTitle(const char *title)
Set the title of the file.
@ ROTF_TOWN_BUILD
Bit number for allowing towns to build this roadtype.
CompanyID client_playas
As which company is this client playing (CompanyID)
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?...
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.
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
@ SC_HEIGHTMAP
Heightmap of the world.
@ CC_EXPRESS
Express cargo (Goods, Food, Candy, but also possible for passengers)
bool _network_server
network-server is active
const GRFFile * grffile
Which GRF is being profiled.
void SaveToConfig()
Save the values to the configuration file.
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
char * cmdline
command(s) that is/are being aliased
IConsoleCmd * _iconsole_cmds
list of registered commands
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
char password[NETWORK_PASSWORD_LENGTH]
The password for the company.
This struct contains all the info that is needed to draw and construct tracks.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
@ DFT_GAME_FILE
Save game or scenario file.
const GRFFile * grffile[RTSG_END]
NewGRF providing the Action3 for the railtype.
void SetName(const char *name)
Set the name of the file.
void ConPrintFramerate()
Print performance statistics to game console.
static bool CanStartNew()
Is it possible to start a new AI company?
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ ROADTYPE_END
Used for iterations.
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
ClientSettings _settings_client
The current settings for this game.
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
Specification of a cargo type.
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
@ CC_LIQUID
Liquids (Oil, Water, Rubber)
@ CONTENT_TYPE_END
Helper to mark the end of the types.
#define MAX_DAY
The number of days till the last day.
@ VEH_ROAD
Road vehicle type.
@ CC_PASSENGERS
Passengers.
NetworkServerGameInfo _network_game_info
Information about our game.
ClientID _redirect_console_to_client
If not invalid, redirect the console output to a client.
void StartupEngines()
Start/initialise all our engines.
Owner
Enum for all companies/owners.
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
List of file information.
void InvalidateFileList()
Declare the file storage cache as being invalid, also clears all stored files.
const typedef ContentInfo *const * ConstContentIterator
Iterator for the constant content vector.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static const AdminIndex INVALID_ADMIN_ID
An invalid admin marker.
static const uint32 GENERATE_NEW_SEED
Create a new random seed.
ContentType
The values in the enum are important; they are used as database 'keys'.
AdminIndex _redirect_console_to_admin
Redirection of the (remote) console to the admin.
static const TextColour CC_DEFAULT
Default colour of the console.
IConsoleAlias * IConsoleAliasGet(const char *name)
Find the alias pointed to by its string.
uint8 bitnum
Cargo bit number, is INVALID_CARGO for a non-used spec.
IConsoleHook * hook
any special trigger action that needs executing
IConsoleCmd * IConsoleCmdGet(const char *name)
Find the command pointed to by its string.
GameCreationSettings game_creation
settings used during the creation of a game (map)
void Clear()
Remove all items from the list.
@ PM_UNPAUSED
A normal unpaused game.
static uint MapSizeX()
Get the size of the map along the X.
StringID name
Name of this rail type.
void RequestContentList(ContentType type)
Request the content list for the given type.
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
@ BASE_DIR
Base directory for all subdirectories.
static char * GetConsoleLibraryList(char *p, const char *last)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
@ COMPANY_NEW_COMPANY
The client wants a new company.
static uint MapSize()
Get the size of the map.
@ SLO_LOAD
File is being loaded.
static uint _script_current_depth
Depth of scripts running (used to abort execution when #ConReturn is encountered).
RailType
Enumeration for all possible railtypes.
@ RTF_CATENARY
Bit number for drawing a catenary.
Date _date
Current date in days (day counter)
@ CC_SPECIAL
Special bit used for livery refit tricks instead of normal cargoes.
void OnDownloadComplete(ContentID cid)
We have finished downloading a file.
@ SLO_SAVE
File is being saved.
@ CCA_NEW_AI
Create a new AI company.
@ ROTF_HIDDEN
Bit number for hidden from construction.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
char last_host[NETWORK_HOSTNAME_LENGTH]
IP address of the last joined server.
bool FiosDelete(const char *name)
Delete a file.
@ RTF_HIDDEN
Bit number for hiding from selection.
@ CMD_PAUSE
pause the game
static bool IsConnected()
Check whether the client is actually connected (and in the game).
bool IsValid() const
Tests for validity of this cargospec.
FILE * FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
void UnselectAll()
Unselect everything that we've not downloaded so far.
@ CC_PIECE_GOODS
Piece goods (Livestock, Wood, Steel, Paper)
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Construct a file list with the given kind of files, for the stated purpose.
Container for all important information about a piece of content.
ClientID
'Unique' identifier to be given to clients
void OnDisconnect()
Callback for when the connection got disconnected.
@ RTF_DISALLOW_90DEG
Bit number for never allowed 90 degree turns, regardless of setting.
void ShowFramerateWindow()
Open the general framerate window.
@ CC_BULK
Bulk cargo (Coal, Grain etc., Ores, Fruit)
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
void IConsoleError(const char *string)
It is possible to print error information to the console.
void ParseConnectionString(const char **company, const char **port, char *connection_string)
Converts a string to ip/port/company Format: IP:port::company.
const struct GRFFile * grffile
NewGRF where #group belongs to.
Deals with finding savegames.
PauseMode _pause_mode
The current pause mode.
byte md5sum[16]
The MD5 checksum.
static void IConsoleHelp(const char *str)
Show help for the console.
void Unselect(ContentID cid)
Unselect a specific content id.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ CHR_ALLOW
Allow command execution.
bool GetArgumentInteger(uint32 *value, const char *arg)
Change a string into its number representation.
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
void NetworkPrintClients()
Print all the clients to the console.
@ MAX_COMPANIES
Maximum number of companies.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
const char * FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
const FiosItem * FindItem(const char *file)
Find file information of a file by its name from the file list.
@ ROTF_NO_HOUSES
Bit number for setting this roadtype as not house friendly.
char * RemoveUnderscores(char *name)
Remove underscores from a string; the string will be modified!
@ CLIENT_ID_SERVER
Servers always have this ID.
NetworkCompanyState * _network_company_states
Statistics about some companies.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
@ SELECTED
The content has been manually selected.
static const TextColour CC_DEBUG
Colour for debug output.
bool _networking
are we in networking mode?
uint16 last_port
port of the last joined server
void GamelogPrintConsole()
Print the gamelog data to the console.
@ RTSG_GROUND
Main group of ground images.
void ValidateFileList(bool force_reload=false)
(Re-)validate the file storage cache.
StringID name
Name of this rail type.
static uint MapSizeY()
Get the size of the map along the Y.
bool active
Is this profiler collecting data.
@ ROADTYPE_BEGIN
Used for iterations.
bool _network_dedicated
are we a dedicated server?
IConsoleAlias * _iconsole_aliases
list of registered aliases
@ CRR_MANUAL
The company is manually removed.
void DownloadSelectedContent(uint &files, uint &bytes, bool fallback=false)
Actually begin downloading the content we selected.
static bool IsHumanID(size_t index)
Is this company a company not controlled by a NoAI program?
@ FT_SAVEGAME
old or new savegame
void IConsolePrint(TextColour colour_code, const char *string)
Handle the printing of text entered into the console or redirected there by any other means.
RoadType
The different roadtypes we support.
static const TextColour CC_COMMAND
Colour for the console's commands.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
bool file_list_valid
If set, the file list is valid.
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
void StartNewGameWithoutGUI(uint32 seed)
Start a normal game without the GUI.
ClientID client_id
Client identifier (same as ClientState->client_id)
File list storage for the console, for caching the last 'ls' command.
static char * GetConsoleList(char *p, const char *last, bool newest_only=false)
Wrapper function for AIScanner::GetAIConsoleList.
ClientID _network_own_client_id
Our client identifier.
char * name
name of the alias
bool NetworkServerChangeClientName(ClientID client_id, const char *new_name)
Change the client name of the given client.
AISettings ai
what may the AI do?
void NetworkServerKickClient(ClientID client_id, const char *reason)
Kick a single client.
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
SwitchMode _switch_mode
The next mainloop command.
void OnConnect(bool success)
Callback for when the connection has finished.
RailTypeFlags flags
Bit mask of rail type flags.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Callback profiler for NewGRF development.
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
@ SC_WORLD
World screenshot.
@ CC_ARMOURED
Armoured cargo (Valuables, Gold, Diamonds)
static size_t GetNumItems()
Returns number of valid items in the pool.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
RoadTypeLabel label
Unique 32 bit road type identifier.
char *CDECL str_fmt(const char *str,...)
Format, "printf", into a newly allocated string.
uint8 map_x
X size of map.
IConsoleAlias * next
next alias in list
@ AUTOSELECTED
The content has been selected as dependency.
@ COMPANY_SPECTATOR
The client is spectating.
@ RAILTYPE_END
Used for iterations.
@ CC_REFRIGERATED
Refrigerated cargo (Food, Fruit)
DEF_CONSOLE_CMD(ConResetEngines)
Reset status of all engines.
@ WC_CONSOLE
Console; Window numbers:
const char * GetDebugString()
Print out the current debug-level.
static void PrintLineByLine(char *buf)
Print a text buffer line by line to the console.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data=0, bool from_admin=false)
Send an actual chat message.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const char *reason)
Ban, or kick, everyone joined from the given client's IP.
ContentID
Unique identifier for the content.
@ PM_PAUSED_NORMAL
A game normally paused.
–Aliases– Aliases are like shortcuts for complex functions, variable assignments, etc.
uint16 classes
Classes of this cargo type.
@ NUM_CARGO
Maximal number of cargo types in a game.
@ RTF_ALLOW_90DEG
Bit number for always allowed 90 degree turns, regardless of setting.
RailTypeLabel label
Unique 32 bit rail type identifier.
@ CONTENT_TYPE_BEGIN
Helper to mark the begin of the types.
char * name
name of command
static ContentType StringToContentType(const char *str)
Resolve a string to a content type.
IConsoleCmd * next
next command in list
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
void Select(ContentID cid)
Select a specific content id.
StringID name
Name of this type of cargo.
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
struct RailtypeInfo::@41 strings
Strings associated with the rail type.
@ RTF_NO_SPRITE_COMBINE
Bit number for using non-combined junctions.
static const TextColour CC_ERROR
Colour for error lines.
@ SM_RELOADGAME
Reload the savegame / scenario / heightmap you started the game with.
@ SM_MENU
Switch to game intro menu.
@ CMD_COMPANY_CTRL
used in multiplayer to create a new companies etc.
bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
Schedule making a screenshot.
void AddCallback(ContentCallback *cb)
Add a callback to this class.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
static bool NetworkAvailable(bool echo)
Check network availability and inform in console about failure of detection.
@ CHR_DISALLOW
Disallow command execution.
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
const char * NetworkChangeCompanyPassword(CompanyID company_id, const char *password)
Change the company password of a given company.
State state
Whether the content info is selected (for download)
uint32 unique_id
Unique ID; either GRF ID or shortname.
@ RTF_NO_LEVEL_CROSSING
Bit number for disallowing level crossings.
#define lengthof(x)
Return the length of an fixed size array.
Data structure to convert between Date and triplet (year, month, and day).
StringList _network_ban_list
The banned clients.
NetworkSettings network
settings related to the network
void IConsoleClose()
Close the in-game console.
@ SC_VIEWPORT
Screenshot of viewport.
byte CargoID
Cargo slots to indicate a cargo type within a game.
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
void NetworkClientRequestMove(CompanyID company_id, const char *pass)
Notify the server of this client wanting to be moved to another company.
@ CHR_HIDE
Hide the existence of the command.
AbstractFileType GetAbstractFileType(FiosType fios_type)
Extract the abstract file type from a FiosType.
@ INVALID_COMPANY
An invalid company.
DEF_CONSOLE_HOOK(ConHookServerOnly)
Check whether we are a server.
void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
Execute a given command passed to us.
void Change(const char *name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook)
Register a new command to be used in the console.
void IConsoleAliasRegister(const char *name, const char *cmd)
Register a an alias for an already existing command in the console.
@ CCA_DELETE
Delete a company.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat message.
@ VEH_TRAIN
Train vehicle type.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
char name[32]
Name of the content.
@ SC_MINIMAP
Minimap screenshot.
byte clients_on
Current count of clients on server.
bool _network_available
is network mode available?
void SelectUpgrade()
Select everything that's an update for something we've got.
static const TextColour CC_WARNING
Colour for warning lines.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
void SetMode(FiosType ft)
Set the mode and file type of the file to save or load based on the type of file entry at the file sy...
ContentID id
Unique (server side) ID for the content.
void IConsoleWarning(const char *string)
It is possible to print warnings to the console.
static void Rescan()
Rescans all searchpaths for available AIs.
@ VEH_SHIP
Ship vehicle type.
@ PM_PAUSED_ERROR
A game paused because a (critical) error.
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
#define lastof(x)
Get the last element of an fixed size array.
@ SL_OK
completed successfully
static char * GetConsoleLibraryList(char *p, const char *last)
Wrapper function for GameScanner::GetConsoleLibraryList.
Container for all information known about a client.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
void CDECL IConsolePrintF(TextColour colour_code, const char *format,...)
Handle the printing of text entered into the console or redirected there by any other means.
uint8 FindFirstBit(uint32 x)
Search the first set bit in a 32 bit variable.
bool ai_in_multiplayer
so we allow AIs in multiplayer
static char * GetConsoleList(char *p, const char *last, bool newest_only=false)
Wrapper function for GameScanner::GetConsoleList.
Dynamic data of a loaded NewGRF.
GUISettings gui
settings related to the GUI
void FioFCloseFile(FILE *f)
Close a file in a safe way.
size_t Length() const
Get the number of files in the list.
ConstContentIterator Begin() const
Get the begin of the content inf iterator.
uint8 max_companies
maximum amount of companies
@ SM_RESTARTGAME
Restart --> 'Random game' with current settings.
@ RAILTYPE_BEGIN
Used for iterations.