Go to the documentation of this file.
44 #include "table/strings.h"
89 #define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[])
90 #define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo)
104 if (echo)
IConsolePrint(
CC_ERROR,
"You cannot use this command because there is no network available.");
184 if (_game_mode == GM_MENU) {
188 return ConHookNoNetwork(echo);
200 IConsolePrint(
CC_HELP,
"Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'.");
216 IConsolePrint(
CC_HELP,
"Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
220 if (_game_mode == GM_MENU) {
273 "The lowest zoom-in level allowed by current client settings is {}." :
274 "The lowest supported zoom-in level is {}.",
280 "The highest zoom-out level allowed by current client settings is {}." :
281 "The highest supported zoom-out level is {}.",
327 IConsolePrint(
CC_HELP,
"'instant' will immediately move and redraw viewport without smooth scrolling.");
330 if (argc < 2)
return false;
332 uint32 arg_index = 1;
333 bool instant =
false;
334 if (strcmp(argv[arg_index],
"instant") == 0) {
339 switch (argc - arg_index) {
383 char *filename =
str_fmt(
"%s.sav", argv[1]);
405 IConsolePrint(
CC_HELP,
"Saves the configuration for new games to the configuration file, typically 'openttd.cfg'.");
406 IConsolePrint(
CC_HELP,
"It does not save the configuration of the current game to the configuration file.");
422 if (argc != 2)
return false;
424 const char *file = argv[1];
427 if (item !=
nullptr) {
451 if (argc != 2)
return false;
453 const char *file = argv[1];
456 if (item !=
nullptr) {
457 if (unlink(item->name) != 0) {
473 IConsolePrint(
CC_HELP,
"List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'.");
493 if (argc != 2)
return false;
495 const char *file = argv[1];
498 if (item !=
nullptr) {
499 switch (item->type) {
500 case FIOS_TYPE_DIR:
case FIOS_TYPE_DRIVE:
case FIOS_TYPE_PARENT:
538 IConsoleClearBuffer();
548 static bool ConKickOrBan(
const char *argv,
bool ban,
const std::string &reason)
552 if (strchr(argv,
'.') ==
nullptr && strchr(argv,
':') ==
nullptr) {
594 IConsolePrint(
CC_HELP,
"Kick a client from a network game. Usage: 'kick <ip | client-id> [<kick-reason>]'.");
599 if (argc != 2 && argc != 3)
return false;
602 if (argc == 2)
return ConKickOrBan(argv[1],
false, {});
605 size_t kick_message_length = strlen(argv[2]);
606 if (kick_message_length >= 255) {
607 IConsolePrint(
CC_ERROR,
"Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
610 return ConKickOrBan(argv[1],
false, argv[2]);
617 IConsolePrint(
CC_HELP,
"Ban a client from a network game. Usage: 'ban <ip | client-id> [<ban-reason>]'.");
623 if (argc != 2 && argc != 3)
return false;
626 if (argc == 2)
return ConKickOrBan(argv[1],
true, {});
629 size_t kick_message_length = strlen(argv[2]);
630 if (kick_message_length >= 255) {
631 IConsolePrint(
CC_ERROR,
"Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
634 return ConKickOrBan(argv[1],
true, argv[2]);
641 IConsolePrint(
CC_HELP,
"Unban a client from a network game. Usage: 'unban <ip | banlist-index>'.");
646 if (argc != 2)
return false;
656 index = atoi(argv[1]) - 1U;
695 if (_game_mode == GM_MENU) {
717 if (_game_mode == GM_MENU) {
739 IConsolePrint(
CC_HELP,
"Remote control the server from another client. Usage: 'rcon <password> <command>'.");
740 IConsolePrint(
CC_HELP,
"Remember to enclose the command in quotes, otherwise only the first parameter is sent.");
744 if (argc < 3)
return false;
757 IConsolePrint(
CC_HELP,
"List the status of all clients connected to the server. Usage 'status'.");
769 IConsolePrint(
CC_HELP,
"You can change these values by modifying settings 'network.max_clients' and 'network.max_companies'.");
784 IConsolePrint(
CC_HELP,
"Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'.");
801 std::string client_name(argv[2]);
818 IConsolePrint(
CC_HELP,
"Request joining another company. Usage: 'join <company-id> [<password>]'.");
860 IConsolePrint(
CC_HELP,
"Move a client to another company. Usage: 'move <client-id> <company-id>'.");
861 IConsolePrint(
CC_HELP,
"For valid client-id see 'clients', for valid company-id see 'companies', use 255 for moving to spectators.");
903 IConsolePrint(
CC_HELP,
"Remove an idle company from the game. Usage: 'reset_company <company-id>'.");
904 IConsolePrint(
CC_HELP,
"For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
908 if (argc != 2)
return false;
943 IConsolePrint(
CC_HELP,
"Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'.");
955 IConsolePrint(
CC_HELP,
"Reconnect to server to which you were connected last time. Usage: 'reconnect [<company>]'.");
956 IConsolePrint(
CC_HELP,
"Company 255 is spectator (default, if not specified), 0 means creating new company.");
968 if (playas < COMPANY_FIRST + 1 || playas >
MAX_COMPANIES + 1)
return false;
986 IConsolePrint(
CC_HELP,
"Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'.");
987 IConsolePrint(
CC_HELP,
"IP can contain port and company: 'IP[:Port][#Company]', eg: 'server.ottd.org:443#2'.");
988 IConsolePrint(
CC_HELP,
"Company #255 is spectator all others are a certain company with Company 1 being #1.");
992 if (argc < 2)
return false;
1008 if (argc < 2)
return false;
1012 if (script_file ==
nullptr) {
1013 if (argc == 2 || atoi(argv[2]) != 0)
IConsolePrint(
CC_ERROR,
"Script file '{}' not found.", argv[1]);
1019 IConsolePrint(
CC_ERROR,
"Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
1027 while (fgets(cmdline,
sizeof(cmdline), script_file) !=
nullptr) {
1029 for (
char *cmdptr = cmdline; *cmdptr !=
'\0'; cmdptr++) {
1030 if (*cmdptr ==
'\n' || *cmdptr ==
'\r') {
1043 if (ferror(script_file)) {
1066 extern bool CloseConsoleLogIfActive();
1070 extern FILE *_iconsole_output_file;
1073 IConsolePrint(
CC_HELP,
"Start or stop logging console output to a file. Usage: 'script <filename>'.");
1078 if (!CloseConsoleLogIfActive()) {
1079 if (argc < 2)
return false;
1081 _iconsole_output_file = fopen(argv[1],
"ab");
1082 if (_iconsole_output_file ==
nullptr) {
1100 if (argc < 2)
return false;
1108 IConsolePrint(
CC_HELP,
"Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'.");
1112 if (argc < 3)
return false;
1121 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.");
1133 IConsolePrint(
CC_HELP,
"Restarts a game. It tries to reproduce the exact same map as the game started with.");
1135 IConsolePrint(
CC_HELP,
" * restarting games started in another version might create another map due to difference in map generation.");
1136 IConsolePrint(
CC_HELP,
" * restarting games based on scenarios, loaded games or heightmaps will start a new game based on the settings stored in the scenario/savegame.");
1152 IConsolePrint(
CC_HELP,
" * if you started from a savegame / scenario / heightmap, that exact same savegame / scenario / heightmap will be loaded.");
1170 std::istringstream in(full_string);
1172 while (std::getline(in, line)) {
1231 if (argc == 0 || argc > 3) {
1233 IConsolePrint(
CC_HELP,
"Start a new AI. If <AI> is given, it starts that specific AI (if found).");
1234 IConsolePrint(
CC_HELP,
"If <settings> is given, it is parsed and the AI settings are set to that.");
1238 if (_game_mode != GM_NORMAL) {
1264 if (c->index != n)
break;
1270 config->
Change(argv[1], -1,
false);
1276 char *name =
stredup(argv[1]);
1277 char *e = strrchr(name,
'.');
1282 int version = atoi(e);
1283 config->
Change(name, version,
true);
1307 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.");
1311 if (_game_mode != GM_NORMAL) {
1345 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.");
1349 if (_game_mode != GM_NORMAL) {
1420 IConsolePrint(
CC_ERROR,
"NewGRF scanning is already running. Please wait until completed to run again.");
1430 IConsolePrint(
CC_HELP,
"The seed can be used to reproduce the exact same map as the game started with.");
1441 IConsolePrint(
CC_HELP,
"Returns the current date (year-month-day) of the game. Usage: 'getdate'.");
1454 IConsolePrint(
CC_HELP,
"Returns the current date (year-month-day) of your system. Usage: 'getsysdate'.");
1458 char buffer[
lengthof(
"2000-01-02 03:04:05")];
1470 IConsolePrint(
CC_HELP,
"Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'.");
1474 if (argc < 3)
return false;
1477 if (alias ==
nullptr) {
1488 IConsolePrint(
CC_HELP,
"Create a screenshot of the game. Usage: 'screenshot [viewport | normal | big | giant | heightmap | minimap] [no_con] [size <width> <height>] [<filename>]'.");
1489 IConsolePrint(
CC_HELP,
" 'viewport' (default) makes a screenshot of the current viewport (including menus, windows).");
1493 IConsolePrint(
CC_HELP,
" 'heightmap' makes a heightmap screenshot of the map that can be loaded in as heightmap.");
1494 IConsolePrint(
CC_HELP,
" 'minimap' makes a top-viewed minimap screenshot of the whole world which represents one tile by one pixel.");
1495 IConsolePrint(
CC_HELP,
" 'no_con' hides the console to create the screenshot (only useful in combination with 'viewport').");
1496 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').");
1497 IConsolePrint(
CC_HELP,
" A filename ending in # will prevent overwriting existing files and will number files counting upwards.");
1501 if (argc > 7)
return false;
1507 uint32 arg_index = 1;
1509 if (argc > arg_index) {
1510 if (strcmp(argv[arg_index],
"viewport") == 0) {
1513 }
else if (strcmp(argv[arg_index],
"normal") == 0) {
1516 }
else if (strcmp(argv[arg_index],
"big") == 0) {
1519 }
else if (strcmp(argv[arg_index],
"giant") == 0) {
1522 }
else if (strcmp(argv[arg_index],
"heightmap") == 0) {
1525 }
else if (strcmp(argv[arg_index],
"minimap") == 0) {
1531 if (argc > arg_index && strcmp(argv[arg_index],
"no_con") == 0) {
1540 if (argc > arg_index + 2 && strcmp(argv[arg_index],
"size") == 0) {
1551 if (argc > arg_index) {
1553 name = argv[arg_index];
1557 if (argc > arg_index) {
1569 IConsolePrint(
CC_HELP,
"Print out debugging information about a command. Usage: 'info_cmd <cmd>'.");
1573 if (argc < 2)
return false;
1576 if (cmd ==
nullptr) {
1591 IConsolePrint(
CC_HELP,
"Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'.");
1592 IConsolePrint(
CC_HELP,
"Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'\"s.");
1596 if (argc > 2)
return false;
1623 IConsolePrint(
CC_HELP,
"Leave the currently joined/running game (only ingame). Usage: 'part'.");
1627 if (_game_mode != GM_NORMAL)
return false;
1640 if (cmd !=
nullptr) {
1641 cmd->
proc(0,
nullptr);
1646 if (alias !=
nullptr) {
1648 if (cmd !=
nullptr) {
1649 cmd->
proc(0,
nullptr);
1660 IConsolePrint(TC_LIGHT_BLUE,
" ---- OpenTTD Console Help ---- ");
1679 for (
auto &it : IConsole::Commands()) {
1681 if (argv[1] ==
nullptr || cmd->
name.find(argv[1]) != std::string::npos) {
1696 for (
auto &it : IConsole::Aliases()) {
1698 if (argv[1] ==
nullptr || alias->
name.find(argv[1]) != std::string::npos) {
1715 char company_name[512];
1717 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
1719 const char *password_state =
"";
1721 password_state =
"AI";
1728 IConsolePrint(
CC_INFO,
"#:{}({}) Company Name: '{}' Year Founded: {} Money: {} Loan: {} Value: {} (T:{}, R:{}, P:{}, S:{}) {}",
1729 c->index + 1, colour, company_name,
1732 c->group_all[
VEH_ROAD].num_vehicle,
1734 c->group_all[
VEH_SHIP].num_vehicle,
1744 IConsolePrint(
CC_HELP,
"Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'.");
1748 if (argc != 2)
return false;
1763 IConsolePrint(
CC_HELP,
"Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'.");
1764 IConsolePrint(
CC_HELP,
"CompanyNo is the company that plays as company <companyno>, 1 through max_companies.");
1768 if (argc != 3)
return false;
1789 IConsolePrint(
CC_HELP,
"Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'.");
1794 if (argc != 3)
return false;
1810 IConsolePrint(
CC_HELP,
"Change the password of a company. Usage: 'company_pw <company-no> \"<password>\".");
1812 IConsolePrint(
CC_HELP,
"Change the password of your or any other company. Usage: 'company_pw [<company-no>] \"<password>\"'.");
1814 IConsolePrint(
CC_HELP,
"Change the password of your company. Usage: 'company_pw \"<password>\"'.");
1822 std::string password;
1823 const char *errormsg;
1828 errormsg =
"You have to own a company to make use of this command.";
1830 company_id = (
CompanyID)(atoi(argv[1]) - 1);
1832 errormsg =
"You have to specify the ID of a valid human controlled company.";
1844 if (password.empty()) {
1854 #if defined(WITH_ZLIB)
1860 static const char *
const inv_lookup[] = {
"",
"base",
"newgrf",
"ai",
"ailib",
"scenario",
"heightmap" };
1861 for (uint i = 1 ; i <
lengthof(inv_lookup); i++) {
1862 if (strcasecmp(str, inv_lookup[i]) == 0)
return (
ContentType)i;
1891 static const char *
const types[] = {
"Base graphics",
"NewGRF",
"AI",
"AI library",
"Scenario",
"Heightmap",
"Base sound",
"Base music",
"Game script",
"GS library" };
1893 static const char *
const states[] = {
"Not selected",
"Selected",
"Dep Selected",
"Installed",
"Unknown" };
1896 char buf[
sizeof(ci->
md5sum) * 2 + 1];
1898 IConsolePrint(state_to_colour[ci->
state],
"{}, {}, {}, {}, {:08X}, {}", ci->
id, types[ci->
type - 1], states[ci->
state], ci->
name, ci->
unique_id, buf);
1904 if (cb ==
nullptr) {
1910 IConsolePrint(
CC_HELP,
"Query, select and download content. Usage: 'content update|upgrade|select [id]|unselect [all|id]|state [filter]|download'.");
1913 IConsolePrint(
CC_HELP,
" select: select a specific item given by its id. If no parameter is given, all selected content will be listed.");
1914 IConsolePrint(
CC_HELP,
" unselect: unselect a specific item given by its id or 'all' to unselect all.");
1915 IConsolePrint(
CC_HELP,
" state: show the download/select state of all downloadable content. Optionally give a filter string.");
1920 if (strcasecmp(argv[1],
"update") == 0) {
1925 if (strcasecmp(argv[1],
"upgrade") == 0) {
1930 if (strcasecmp(argv[1],
"select") == 0) {
1938 }
else if (strcasecmp(argv[2],
"all") == 0) {
1952 if (strcasecmp(argv[1],
"unselect") == 0) {
1957 if (strcasecmp(argv[2],
"all") == 0) {
1965 if (strcasecmp(argv[1],
"state") == 0) {
1968 if (argc > 2 && strcasestr((*iter)->name.c_str(), argv[2]) ==
nullptr)
continue;
1974 if (strcasecmp(argv[1],
"download") == 0) {
1995 IConsolePrint(
CC_HELP,
" Set <name> to \"\" for the sprite font (size and aa have no effect on sprite font).");
2000 for (argfs =
FS_BEGIN; argfs < FS_END; argfs++) {
2001 if (argc > 1 && strcasecmp(argv[1], FontSizeToName(argfs)) == 0)
break;
2005 if (argc > 1 && argfs == FS_END)
return false;
2009 std::string font = setting->
font;
2010 uint size = setting->
size;
2011 bool aa = setting->
aa;
2015 if (argc > arg_index) {
2017 if (strcasecmp(argv[arg_index],
"aa") == 0 || strcasecmp(argv[arg_index],
"noaa") == 0) {
2018 aa = strncasecmp(argv[arg_index++],
"no", 2) != 0;
2019 if (argc > arg_index)
return false;
2024 font = argv[arg_index++];
2029 if (argc > arg_index) {
2038 if (argc > arg_index) {
2040 if (strcasecmp(argv[arg_index],
"aa") != 0 && strcasecmp(argv[arg_index],
"noaa") != 0)
return false;
2041 aa = strncasecmp(argv[arg_index++],
"no", 2) != 0;
2042 if (argc > arg_index)
return false;
2045 SetFont(argfs, font, size, aa);
2070 if (argc == 1 || argc > 3)
return false;
2075 IConsoleSetSetting(argv[1], argv[2]);
2084 IConsolePrint(
CC_HELP,
"Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'.");
2089 if (argc == 1 || argc > 3)
return false;
2094 IConsoleSetSetting(argv[1], argv[2],
true);
2107 if (argc > 2)
return false;
2122 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!");
2132 struct SubdirNameMap {
2137 static const SubdirNameMap subdir_name_map[] = {
2154 IConsolePrint(
CC_HELP,
"List all search paths or default directories for various categories.");
2156 std::string cats = subdir_name_map[0].name;
2158 for (
const SubdirNameMap &sdn : subdir_name_map) {
2159 if (!first) cats = cats +
", " + sdn.name;
2166 std::set<std::string> seen_dirs;
2167 for (
const SubdirNameMap &sdn : subdir_name_map) {
2168 if (strcasecmp(argv[1], sdn.name) != 0)
continue;
2172 std::string path = FioGetDirectory(sp, sdn.subdir);
2174 if (seen_dirs.find(path) != seen_dirs.end())
continue;
2175 seen_dirs.insert(path);
2180 if (!sdn.default_only || exists) {
2182 if (sdn.default_only)
break;
2198 IConsolePrint(
CC_HELP,
"Collect performance data about NewGRF sprite requests and callbacks. Sub-commands can be abbreviated.");
2204 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.");
2206 IConsolePrint(
CC_HELP,
" Begin profiling all selected GRFs. If a number of days is provided, profiling stops after that many in-game days.");
2214 extern const std::vector<GRFFile *> &GetAllGRFFiles();
2215 const std::vector<GRFFile *> &files = GetAllGRFFiles();
2218 if (argc == 1 || strncasecmp(argv[1],
"lis", 3) == 0) {
2222 auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; });
2223 bool selected = profiler != _newgrf_profilers.end();
2224 bool active = selected && profiler->active;
2226 const char *statustext = active ?
" (active)" : selected ?
" (selected)" :
"";
2234 if (strncasecmp(argv[1],
"sel", 3) == 0 && argc >= 3) {
2235 for (
size_t argnum = 2; argnum < argc; ++argnum) {
2236 int grfnum = atoi(argv[argnum]);
2237 if (grfnum < 1 || grfnum > (
int)files.size()) {
2241 GRFFile *grf = files[grfnum - 1];
2242 if (std::any_of(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; })) {
2246 _newgrf_profilers.emplace_back(grf);
2252 if (strncasecmp(argv[1],
"uns", 3) == 0 && argc >= 3) {
2253 for (
size_t argnum = 2; argnum < argc; ++argnum) {
2254 if (strcasecmp(argv[argnum],
"all") == 0) {
2255 _newgrf_profilers.clear();
2258 int grfnum = atoi(argv[argnum]);
2259 if (grfnum < 1 || grfnum > (
int)files.size()) {
2263 GRFFile *grf = files[grfnum - 1];
2264 auto pos = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; });
2265 if (pos != _newgrf_profilers.end()) _newgrf_profilers.erase(pos);
2271 if (strncasecmp(argv[1],
"sta", 3) == 0) {
2279 if (!grfids.empty()) grfids +=
", ";
2280 char grfidstr[12]{ 0 };
2288 int days = std::max(atoi(argv[2]), 1);
2289 _newgrf_profile_end_date =
_date + days;
2291 char datestrbuf[32]{ 0 };
2293 GetString(datestrbuf, STR_JUST_DATE_ISO,
lastof(datestrbuf));
2296 _newgrf_profile_end_date =
MAX_DAY;
2298 }
else if (_newgrf_profilers.empty()) {
2301 IConsolePrint(
CC_ERROR,
"Did not start profiling for any GRFs, all selected GRFs are already profiling.");
2307 if (strncasecmp(argv[1],
"sto", 3) == 0) {
2308 NewGRFProfiler::FinishAll();
2313 if (strncasecmp(argv[1],
"abo", 3) == 0) {
2317 _newgrf_profile_end_date =
MAX_DAY;
2329 static void IConsoleDebugLibRegister()
2368 static void ConDumpRoadTypes()
2377 std::map<uint32, const GRFFile *> grfs;
2380 if (rti->
label == 0)
continue;
2383 if (grf !=
nullptr) {
2385 grfs.emplace(grfid, grf);
2389 RoadTypeIsTram(rt) ?
"Tram" :
"Road",
2400 for (
const auto &grf : grfs) {
2405 static void ConDumpRailTypes()
2415 std::map<uint32, const GRFFile *> grfs;
2418 if (rti->
label == 0)
continue;
2421 if (grf !=
nullptr) {
2423 grfs.emplace(grfid, grf);
2438 for (
const auto &grf : grfs) {
2443 static void ConDumpCargoTypes()
2458 std::map<uint32, const GRFFile *> grfs;
2461 if (!spec->
IsValid())
continue;
2464 if (grf !=
nullptr) {
2466 grfs.emplace(grfid, grf);
2468 IConsolePrint(
CC_DEFAULT,
" {:02d} Bit: {:2d}, Label: {:c}{:c}{:c}{:c}, Callback mask: 0x{:02X}, Cargo class: {}{}{}{}{}{}{}{}{}{}{}, GRF: {:08X}, {}",
2485 GetStringPtr(spec->
name)
2488 for (
const auto &grf : grfs) {
2503 if (strcasecmp(argv[1],
"roadtypes") == 0) {
2508 if (strcasecmp(argv[1],
"railtypes") == 0) {
2513 if (strcasecmp(argv[1],
"cargotypes") == 0) {
2514 ConDumpCargoTypes();
2525 void IConsoleStdLibRegister()
2594 #if defined(WITH_ZLIB)
2651 IConsoleDebugLibRegister();
@ VEH_AIRCRAFT
Aircraft vehicle type.
static uint MapLogX()
Logarithm of the map size along the X side.
RoadTypeFlags flags
Bit mask of road type flags.
void NetworkClientSendRcon(const std::string &password, const std::string &command)
Send a remote console command.
@ ROTF_NO_LEVEL_CROSSING
Bit number for disabling level crossing.
static ConsoleFileList _console_file_list
File storage cache for the console.
Callbacks for notifying others about incoming data.
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
@ ROADTYPE_END
Used for iterations.
std::string name
Name of the content.
@ CC_COVERED
Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
IConsoleCmdProc * proc
process executed when command is typed
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
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.
@ CRR_NONE
Dummy reason for actions that don't need one.
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.
@ INVALID_CLIENT_ID
Client is not part of anything.
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.
Settings for a single font.
@ SM_LOAD_GAME
Load game, Play Scenario.
static void OutputContentState(const ContentInfo *const ci)
Outputs content state information to console.
@ ZOOM_OUT
Zoom out (get helicopter view).
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64 data=0, bool from_admin=false)
Send an actual chat message.
uint8 map_y
Y size of map.
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.
@ CCA_DELETE
Delete a company.
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?...
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
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.
void NetworkClientRequestMove(CompanyID company_id, const std::string &pass)
Notify the server of this client wanting to be moved to another company.
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)
ViewportData * viewport
Pointer to viewport data, if present.
bool _network_server
network-server is active
@ GAME_LIBRARY_DIR
Subdirectory for all GS libraries.
const GRFFile * grffile
Which GRF is being profiled.
void SaveToConfig()
Save the values to the configuration file.
@ SCREENSHOT_DIR
Subdirectory for all screenshots.
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.
static std::string GetConsoleList(bool newest_only=false)
Wrapper function for GameScanner::GetConsoleList.
static std::string GetConsoleLibraryList()
Wrapper function for GameScanner::GetConsoleLibraryList.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Searchpath
Types of searchpaths OpenTTD might use.
bool aa
Whether to do anti aliasing or not.
uint8 FindFirstBit(uint64 x)
Search the first set bit in a 64 bit variable.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
This struct contains all the info that is needed to draw and construct tracks.
static IConsoleAlias * AliasGet(const std::string &name)
Find the alias pointed to by its string.
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.
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
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...
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
ClientSettings _settings_client
The current settings for this game.
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
@ ZOOM_LVL_MAX
Maximum zoom level.
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.
void SetDebugString(const char *s, void(*error_func)(const char *))
Set debugging levels by parsing the text in s.
#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.
ZoomLevel zoom_max
maximum zoom out level
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.
std::string cmdline
command(s) that is/are being aliased
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'.
uint size
The (requested) size of the font.
AdminIndex _redirect_console_to_admin
Redirection of the (remote) console to the admin.
static const TextColour CC_DEFAULT
Default colour of the console.
uint8 bitnum
Cargo bit number, is INVALID_CARGO for a non-used spec.
IConsoleHook * hook
any special trigger action that needs executing
GameCreationSettings game_creation
settings used during the creation of a game (map)
std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password)
Change the company password of a given company.
std::string name
name of command
@ 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.
@ ZOOM_LVL_MIN
Minimum zoom level.
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
@ ZOOM_IN
Zoom in (get more detailed view).
@ BASE_DIR
Base directory for all subdirectories.
Data structure for viewport, display of a part of the world.
static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook=nullptr)
Register a new command to be used in the console.
@ 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.
static std::string GetConsoleLibraryList()
Wrapper function for AIScanner::GetAIConsoleLibraryList.
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.
std::string last_joined
Last joined server.
bool HasParent()
Check whether the font cache has a parent.
@ SLO_SAVE
File is being saved.
@ ROTF_HIDDEN
Bit number for hidden from construction.
static const TextColour CC_HELP
Colour for help lines.
@ RTF_HIDDEN
Bit number for hiding from selection.
@ AI_DIR
Subdirectory for all AI files.
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 StrTrimInPlace(std::string &str)
Trim the spaces from given string in place, i.e.
void UnselectAll()
Unselect everything that we've not downloaded so far.
@ CC_PIECE_GOODS
Piece goods (Livestock, Wood, Steel, Paper)
std::string font
The name of the font, or path to the font.
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.
bool FileExists(const std::string &filename)
Test whether the given filename exists.
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 InitFontCache(bool monospace)
(Re)initialize the font cache related things, i.e.
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.
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.
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.
static FontCacheSubSetting * GetFontCacheSubSetting(FontSize fs)
Get the settings of a given font size.
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.
std::string password
The password for the company.
@ GAME_DIR
Subdirectory for all game scripts.
@ SCENARIO_DIR
Base directory for all scenarios.
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name)
Change the client name of the given client.
@ CLIENT_ID_SERVER
Servers always have this ID.
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
NetworkCompanyState * _network_company_states
Statistics about some companies.
@ SELECTED
The content has been manually selected.
static const TextColour CC_DEBUG
Colour for debug output.
bool _networking
are we in networking mode?
void GamelogPrintConsole()
Print the gamelog data to the console.
static size_t Format(char *buffer, const char *last, const char *format) NOACCESS(2) WARN_TIME_FORMAT(3)
Format the current time with the given strftime format specifiers.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason)
Ban, or kick, everyone joined from the given client's IP.
@ 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.
@ CRR_MANUAL
The company is manually removed.
bool active
Is this profiler collecting data.
bool _network_dedicated
are we a dedicated server?
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
static const TextColour CC_COMMAND
Colour for the console's commands.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
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)
@ CCA_NEW_AI
Create a new AI company.
File list storage for the console, for caching the last 'ls' command.
ClientID _network_own_client_id
Our client identifier.
std::string name
name of the alias
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data)
Send a chat message.
ZoomLevel zoom_min
minimum zoom out level
AISettings ai
what may the AI do?
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.
virtual std::string GetFontName()=0
Get the name of this font.
@ SC_WORLD
World screenshot.
Font cache for basic fonts.
@ 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.
@ 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.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
ContentID
Unique identifier for the content.
static void AliasRegister(const std::string &name, const std::string &cmd)
Register a an alias for an already existing command in the console.
@ 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.
virtual int GetFontSize() const
Get the nominal font size of the font.
static ContentType StringToContentType(const char *str)
Resolve a string to a content type.
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:
RoadType
The different roadtypes we support.
void Select(ContentID cid)
Select a specific content id.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
StringID name
Name of this type of cargo.
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
@ WC_MAIN_WINDOW
Main window; Window numbers:
@ 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.
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.
State state
Whether the content info is selected (for download)
bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password, const std::string &join_company_password)
Join a client to the server at with the given connection string.
uint32 unique_id
Unique ID; either GRF ID or shortname.
@ AI_LIBRARY_DIR
Subdirectory for all AI libraries.
static std::string GetConsoleList(bool newest_only=false)
Wrapper function for AIScanner::GetAIConsoleList.
@ 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.
ZoomLevel zoom
The zoom level of the viewport.
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)
@ CHR_HIDE
Hide the existence of the command.
@ FS_MONO
Index of the monospaced font in the font tables.
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 NetworkServerKickClient(ClientID client_id, const std::string &reason)
Kick a single client.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
FontSize
Available font sizes.
Data structure for an opened window.
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
@ VEH_TRAIN
Train vehicle type.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
@ 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.
static void Rescan()
Rescans all searchpaths for available AIs.
@ VEH_SHIP
Ship vehicle type.
@ PM_PAUSED_ERROR
A game paused because a (critical) error.
std::string _network_server_invite_code
Our invite code as indicated by the Game Coordinator.
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
@ ROADTYPE_BEGIN
Used for iterations.
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...
bool NetworkIsValidClientName(const std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
bool ai_in_multiplayer
so we allow AIs in multiplayer
static IConsoleCmd * CmdGet(const std::string &name)
Find the command pointed to by its string.
Dynamic data of a loaded NewGRF.
GUISettings gui
settings related to the GUI
void FioFCloseFile(FILE *f)
Close a file in a safe way.
static FontCache * Get(FontSize fs)
Get the font cache of a given font size.
ConstContentIterator Begin() const
Get the begin of the content inf iterator.
uint8 max_companies
maximum amount of companies
static void PrintLineByLine(const std::string &full_string)
Print a text buffer line by line to the console.
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
@ SM_RESTARTGAME
Restart --> 'Random game' with current settings.
@ RAILTYPE_BEGIN
Used for iterations.
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.