Go to the documentation of this file.
16 #include "network/core/network_game_info.h"
44 #include "table/strings.h"
45 #include "3rdparty/fmt/chrono.h"
92 #define DEF_CONSOLE_CMD(function) static bool function([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[])
93 #define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo)
107 if (echo)
IConsolePrint(
CC_ERROR,
"You cannot use this command because there is no network available.");
202 if (_game_mode == GM_MENU) {
206 return ConHookNoNetwork(echo);
218 IConsolePrint(
CC_HELP,
"Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'.");
234 IConsolePrint(
CC_HELP,
"Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
238 if (_game_mode == GM_MENU) {
309 if (argv[1][0] ==
'-') {
347 IConsolePrint(
CC_HELP,
"'instant' will immediately move and redraw viewport without smooth scrolling.");
350 if (argc < 2)
return false;
352 uint32_t arg_index = 1;
353 bool instant =
false;
354 if (strcmp(argv[arg_index],
"instant") == 0) {
359 switch (argc - arg_index) {
403 std::string filename = argv[1];
425 IConsolePrint(
CC_HELP,
"Saves the configuration for new games to the configuration file, typically 'openttd.cfg'.");
426 IConsolePrint(
CC_HELP,
"It does not save the configuration of the current game to the configuration file.");
442 if (argc != 2)
return false;
444 const char *file = argv[1];
447 if (item !=
nullptr) {
464 IConsolePrint(
CC_HELP,
"Load a scenario by name or index. Usage: 'load_scenario <file | number>'.");
468 if (argc != 2)
return false;
470 const char *file = argv[1];
473 if (item !=
nullptr) {
490 IConsolePrint(
CC_HELP,
"Load a heightmap by name or index. Usage: 'load_heightmap <file | number>'.");
494 if (argc != 2)
return false;
496 const char *file = argv[1];
499 if (item !=
nullptr) {
520 if (argc != 2)
return false;
522 const char *file = argv[1];
525 if (item !=
nullptr) {
526 if (unlink(item->name.c_str()) != 0) {
542 IConsolePrint(
CC_HELP,
"List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'.");
594 if (argc != 2)
return false;
596 const char *file = argv[1];
599 if (item !=
nullptr) {
600 switch (item->type) {
601 case FIOS_TYPE_DIR:
case FIOS_TYPE_DRIVE:
case FIOS_TYPE_PARENT:
636 IConsoleClearBuffer();
646 static bool ConKickOrBan(
const char *argv,
bool ban,
const std::string &reason)
650 if (strchr(argv,
'.') ==
nullptr && strchr(argv,
':') ==
nullptr) {
692 IConsolePrint(
CC_HELP,
"Kick a client from a network game. Usage: 'kick <ip | client-id> [<kick-reason>]'.");
697 if (argc != 2 && argc != 3)
return false;
700 if (argc == 2)
return ConKickOrBan(argv[1],
false, {});
703 size_t kick_message_length = strlen(argv[2]);
704 if (kick_message_length >= 255) {
705 IConsolePrint(
CC_ERROR,
"Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
708 return ConKickOrBan(argv[1],
false, argv[2]);
715 IConsolePrint(
CC_HELP,
"Ban a client from a network game. Usage: 'ban <ip | client-id> [<ban-reason>]'.");
721 if (argc != 2 && argc != 3)
return false;
724 if (argc == 2)
return ConKickOrBan(argv[1],
true, {});
727 size_t kick_message_length = strlen(argv[2]);
728 if (kick_message_length >= 255) {
729 IConsolePrint(
CC_ERROR,
"Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
732 return ConKickOrBan(argv[1],
true, argv[2]);
739 IConsolePrint(
CC_HELP,
"Unban a client from a network game. Usage: 'unban <ip | banlist-index>'.");
744 if (argc != 2)
return false;
754 index = atoi(argv[1]) - 1U;
793 if (_game_mode == GM_MENU) {
815 if (_game_mode == GM_MENU) {
837 IConsolePrint(
CC_HELP,
"Remote control the server from another client. Usage: 'rcon <password> <command>'.");
838 IConsolePrint(
CC_HELP,
"Remember to enclose the command in quotes, otherwise only the first parameter is sent.");
842 if (argc < 3)
return false;
855 IConsolePrint(
CC_HELP,
"List the status of all clients connected to the server. Usage 'status'.");
867 IConsolePrint(
CC_HELP,
"You can change these values by modifying settings 'network.max_clients' and 'network.max_companies'.");
882 IConsolePrint(
CC_HELP,
"Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'.");
899 std::string client_name(argv[2]);
916 IConsolePrint(
CC_HELP,
"Request joining another company. Usage: 'join <company-id> [<password>]'.");
924 if (info ==
nullptr) {
964 IConsolePrint(
CC_HELP,
"Move a client to another company. Usage: 'move <client-id> <company-id>'.");
965 IConsolePrint(
CC_HELP,
"For valid client-id see 'clients', for valid company-id see 'companies', use 255 for moving to spectators.");
1007 IConsolePrint(
CC_HELP,
"Remove an idle company from the game. Usage: 'reset_company <company-id>'.");
1008 IConsolePrint(
CC_HELP,
"For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
1012 if (argc != 2)
return false;
1032 assert(ci !=
nullptr);
1048 IConsolePrint(
CC_HELP,
"Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'.");
1060 IConsolePrint(
CC_HELP,
"Reconnect to server to which you were connected last time. Usage: 'reconnect [<company>]'.");
1061 IConsolePrint(
CC_HELP,
"Company 255 is spectator (default, if not specified), 0 means creating new company.");
1073 if (playas < COMPANY_FIRST + 1 || playas >
MAX_COMPANIES + 1)
return false;
1091 IConsolePrint(
CC_HELP,
"Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'.");
1092 IConsolePrint(
CC_HELP,
"IP can contain port and company: 'IP[:Port][#Company]', eg: 'server.ottd.org:443#2'.");
1093 IConsolePrint(
CC_HELP,
"Company #255 is spectator all others are a certain company with Company 1 being #1.");
1097 if (argc < 2)
return false;
1113 if (argc < 2)
return false;
1117 if (script_file ==
nullptr) {
1118 if (argc == 2 || atoi(argv[2]) != 0)
IConsolePrint(
CC_ERROR,
"Script file '{}' not found.", argv[1]);
1124 IConsolePrint(
CC_ERROR,
"Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
1132 while (fgets(cmdline,
sizeof(cmdline), script_file) !=
nullptr) {
1134 for (
char *cmdptr = cmdline; *cmdptr !=
'\0'; cmdptr++) {
1135 if (*cmdptr ==
'\n' || *cmdptr ==
'\r') {
1148 if (ferror(script_file)) {
1171 extern bool CloseConsoleLogIfActive();
1172 extern const std::vector<GRFFile *> &GetAllGRFFiles();
1178 extern FILE *_iconsole_output_file;
1181 IConsolePrint(
CC_HELP,
"Start or stop logging console output to a file. Usage: 'script <filename>'.");
1186 if (!CloseConsoleLogIfActive()) {
1187 if (argc < 2)
return false;
1189 _iconsole_output_file = fopen(argv[1],
"ab");
1190 if (_iconsole_output_file ==
nullptr) {
1208 if (argc < 2)
return false;
1216 IConsolePrint(
CC_HELP,
"Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'.");
1220 if (argc < 3)
return false;
1229 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.");
1239 if (argc == 0 || argc > 2) {
1241 IConsolePrint(
CC_HELP,
"Restarts a game, using either the current or newgame (default) settings.");
1242 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.");
1243 IConsolePrint(
CC_HELP,
" * if you started from a savegame / scenario / heightmap, the game might be different, because the current/newgame settings might differ.");
1247 if (argc == 1 || std::string_view(argv[1]) ==
"newgame") {
1284 std::istringstream in(full_string);
1286 while (std::getline(in, line)) {
1291 template <
typename F,
typename ... Args>
1292 bool PrintList(F list_function, Args... args)
1294 std::string output_str;
1295 auto inserter = std::back_inserter(output_str);
1296 list_function(inserter, args...);
1344 if (argc == 0 || argc > 3) {
1346 IConsolePrint(
CC_HELP,
"Start a new AI. If <AI> is given, it starts that specific AI (if found).");
1347 IConsolePrint(
CC_HELP,
"If <settings> is given, it is parsed and the AI settings are set to that.");
1351 if (_game_mode != GM_NORMAL) {
1377 if (c->index != n)
break;
1383 config->
Change(argv[1], -1,
false);
1389 const char *e = strrchr(argv[1],
'.');
1391 size_t name_length = e - argv[1];
1394 int version = atoi(e);
1395 config->
Change(std::string(argv[1], name_length), version,
true);
1418 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.");
1422 if (_game_mode != GM_NORMAL) {
1456 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.");
1460 if (_game_mode != GM_NORMAL) {
1531 IConsolePrint(
CC_ERROR,
"NewGRF scanning is already running. Please wait until completed to run again.");
1541 IConsolePrint(
CC_HELP,
"The seed can be used to reproduce the exact same map as the game started with.");
1552 IConsolePrint(
CC_HELP,
"Returns the current date (year-month-day) of the game. Usage: 'getdate'.");
1564 IConsolePrint(
CC_HELP,
"Returns the current date (year-month-day) of your system. Usage: 'getsysdate'.");
1578 IConsolePrint(
CC_HELP,
"Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'.");
1582 if (argc < 3)
return false;
1585 if (alias ==
nullptr) {
1596 IConsolePrint(
CC_HELP,
"Create a screenshot of the game. Usage: 'screenshot [viewport | normal | big | giant | heightmap | minimap] [no_con] [size <width> <height>] [<filename>]'.");
1597 IConsolePrint(
CC_HELP,
" 'viewport' (default) makes a screenshot of the current viewport (including menus, windows).");
1601 IConsolePrint(
CC_HELP,
" 'heightmap' makes a heightmap screenshot of the map that can be loaded in as heightmap.");
1602 IConsolePrint(
CC_HELP,
" 'minimap' makes a top-viewed minimap screenshot of the whole world which represents one tile by one pixel.");
1603 IConsolePrint(
CC_HELP,
" 'no_con' hides the console to create the screenshot (only useful in combination with 'viewport').");
1604 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').");
1605 IConsolePrint(
CC_HELP,
" A filename ending in # will prevent overwriting existing files and will number files counting upwards.");
1609 if (argc > 7)
return false;
1613 uint32_t height = 0;
1615 uint32_t arg_index = 1;
1617 if (argc > arg_index) {
1618 if (strcmp(argv[arg_index],
"viewport") == 0) {
1621 }
else if (strcmp(argv[arg_index],
"normal") == 0) {
1624 }
else if (strcmp(argv[arg_index],
"big") == 0) {
1627 }
else if (strcmp(argv[arg_index],
"giant") == 0) {
1630 }
else if (strcmp(argv[arg_index],
"heightmap") == 0) {
1633 }
else if (strcmp(argv[arg_index],
"minimap") == 0) {
1639 if (argc > arg_index && strcmp(argv[arg_index],
"no_con") == 0) {
1648 if (argc > arg_index + 2 && strcmp(argv[arg_index],
"size") == 0) {
1659 if (argc > arg_index) {
1661 name = argv[arg_index];
1665 if (argc > arg_index) {
1677 IConsolePrint(
CC_HELP,
"Print out debugging information about a command. Usage: 'info_cmd <cmd>'.");
1681 if (argc < 2)
return false;
1684 if (cmd ==
nullptr) {
1699 IConsolePrint(
CC_HELP,
"Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'.");
1700 IConsolePrint(
CC_HELP,
"Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'\"s.");
1704 if (argc > 2)
return false;
1731 IConsolePrint(
CC_HELP,
"Leave the currently joined/running game (only ingame). Usage: 'part'.");
1735 if (_game_mode != GM_NORMAL)
return false;
1753 if (cmd !=
nullptr) {
1754 cmd->
proc(0,
nullptr);
1759 if (alias !=
nullptr) {
1761 if (cmd !=
nullptr) {
1762 cmd->
proc(0,
nullptr);
1773 IConsolePrint(TC_LIGHT_BLUE,
" ---- OpenTTD Console Help ---- ");
1792 for (
auto &it : IConsole::Commands()) {
1794 if (argv[1] ==
nullptr || cmd->
name.find(argv[1]) != std::string::npos) {
1809 for (
auto &it : IConsole::Aliases()) {
1811 if (argv[1] ==
nullptr || alias->
name.find(argv[1]) != std::string::npos) {
1829 std::string company_name =
GetString(STR_COMPANY_NAME);
1831 const char *password_state =
"";
1833 password_state =
"AI";
1839 IConsolePrint(
CC_INFO,
"#:{}({}) Company Name: '{}' Year Founded: {} Money: {} Loan: {} Value: {} (T:{}, R:{}, P:{}, S:{}) {}",
1840 c->index + 1, colour, company_name,
1841 c->inaugurated_year, (int64_t)c->money, (int64_t)c->current_loan, (int64_t)
CalculateCompanyValue(c),
1843 c->group_all[
VEH_ROAD].num_vehicle,
1845 c->group_all[
VEH_SHIP].num_vehicle,
1855 IConsolePrint(
CC_HELP,
"Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'.");
1859 if (argc != 2)
return false;
1874 IConsolePrint(
CC_HELP,
"Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'.");
1875 IConsolePrint(
CC_HELP,
"CompanyNo is the company that plays as company <companyno>, 1 through max_companies.");
1879 if (argc != 3)
return false;
1900 IConsolePrint(
CC_HELP,
"Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'.");
1905 if (argc != 3)
return false;
1921 IConsolePrint(
CC_HELP,
"Change the password of a company. Usage: 'company_pw <company-no> \"<password>\".");
1923 IConsolePrint(
CC_HELP,
"Change the password of your or any other company. Usage: 'company_pw [<company-no>] \"<password>\"'.");
1925 IConsolePrint(
CC_HELP,
"Change the password of your company. Usage: 'company_pw \"<password>\"'.");
1933 std::string password;
1934 const char *errormsg;
1939 errormsg =
"You have to own a company to make use of this command.";
1941 company_id = (
CompanyID)(atoi(argv[1]) - 1);
1943 errormsg =
"You have to specify the ID of a valid human controlled company.";
1955 if (password.empty()) {
1965 #if defined(WITH_ZLIB)
1971 static const char *
const inv_lookup[] = {
"",
"base",
"newgrf",
"ai",
"ailib",
"scenario",
"heightmap" };
1972 for (uint i = 1 ; i <
lengthof(inv_lookup); i++) {
1980 void OnConnect(
bool success)
override
1990 void OnDownloadComplete(
ContentID cid)
override
2002 static const char *
const types[] = {
"Base graphics",
"NewGRF",
"AI",
"AI library",
"Scenario",
"Heightmap",
"Base sound",
"Base music",
"Game script",
"GS library" };
2004 static const char *
const states[] = {
"Not selected",
"Selected",
"Dep Selected",
"Installed",
"Unknown" };
2007 IConsolePrint(state_to_colour[ci->
state],
"{}, {}, {}, {}, {:08X}, {}", ci->
id, types[ci->
type - 1], states[ci->
state], ci->
name, ci->
unique_id,
FormatArrayAsHex(ci->
md5sum));
2013 if (cb ==
nullptr) {
2019 IConsolePrint(
CC_HELP,
"Query, select and download content. Usage: 'content update|upgrade|select [id]|unselect [all|id]|state [filter]|download'.");
2022 IConsolePrint(
CC_HELP,
" select: select a specific item given by its id. If no parameter is given, all selected content will be listed.");
2023 IConsolePrint(
CC_HELP,
" unselect: unselect a specific item given by its id or 'all' to unselect all.");
2024 IConsolePrint(
CC_HELP,
" state: show the download/select state of all downloadable content. Optionally give a filter string.");
2077 if (argc > 2 && strcasestr((*iter)->name.c_str(), argv[2]) ==
nullptr)
continue;
2104 IConsolePrint(
CC_HELP,
" Set <name> to \"\" for the sprite font (size and aa have no effect on sprite font).");
2109 for (argfs =
FS_BEGIN; argfs < FS_END; argfs++) {
2114 if (argc > 1 && argfs == FS_END)
return false;
2118 std::string font = setting->
font;
2119 uint size = setting->
size;
2120 bool aa = setting->
aa;
2126 if (argc > arg_index)
return false;
2131 font = argv[arg_index++];
2135 if (argc > arg_index) {
2144 if (argc > arg_index) {
2148 if (argc > arg_index)
return false;
2151 SetFont(argfs, font, size, aa);
2176 if (argc == 1 || argc > 3)
return false;
2181 IConsoleSetSetting(argv[1], argv[2]);
2190 IConsolePrint(
CC_HELP,
"Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'.");
2195 if (argc == 1 || argc > 3)
return false;
2200 IConsoleSetSetting(argv[1], argv[2],
true);
2213 if (argc > 2)
return false;
2222 IConsolePrint(
CC_HELP,
"Print logged fundamental changes to the game since the start. Usage: 'gamelog'.");
2233 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!");
2243 struct SubdirNameMap {
2248 static const SubdirNameMap subdir_name_map[] = {
2266 IConsolePrint(
CC_HELP,
"List all search paths or default directories for various categories.");
2268 std::string cats = subdir_name_map[0].name;
2270 for (
const SubdirNameMap &sdn : subdir_name_map) {
2271 if (!first) cats = cats +
", " + sdn.name;
2278 std::set<std::string> seen_dirs;
2279 for (
const SubdirNameMap &sdn : subdir_name_map) {
2284 std::string path = FioGetDirectory(sp, sdn.subdir);
2286 if (seen_dirs.find(path) != seen_dirs.end())
continue;
2287 seen_dirs.insert(path);
2292 if (!sdn.default_only || exists) {
2294 if (sdn.default_only)
break;
2310 IConsolePrint(
CC_HELP,
"Collect performance data about NewGRF sprite requests and callbacks. Sub-commands can be abbreviated.");
2316 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.");
2318 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.");
2326 const std::vector<GRFFile *> &files = GetAllGRFFiles();
2333 auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; });
2334 bool selected = profiler != _newgrf_profilers.end();
2335 bool active = selected && profiler->active;
2337 const char *statustext = active ?
" (active)" : selected ?
" (selected)" :
"";
2346 for (
size_t argnum = 2; argnum < argc; ++argnum) {
2347 int grfnum = atoi(argv[argnum]);
2348 if (grfnum < 1 || grfnum > (
int)files.size()) {
2352 GRFFile *grf = files[grfnum - 1];
2353 if (std::any_of(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; })) {
2357 _newgrf_profilers.emplace_back(grf);
2364 for (
size_t argnum = 2; argnum < argc; ++argnum) {
2366 _newgrf_profilers.clear();
2369 int grfnum = atoi(argv[argnum]);
2370 if (grfnum < 1 || grfnum > (
int)files.size()) {
2374 GRFFile *grf = files[grfnum - 1];
2375 auto pos = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; });
2376 if (pos != _newgrf_profilers.end()) _newgrf_profilers.erase(pos);
2390 if (!grfids.empty()) grfids +=
", ";
2391 fmt::format_to(std::back_inserter(grfids),
"[{:08X}]",
BSWAP32(pr.
grffile->grfid));
2398 uint64_t ticks = std::max(atoi(argv[2]), 1);
2402 }
else if (_newgrf_profilers.empty()) {
2405 IConsolePrint(
CC_ERROR,
"Did not start profiling for any GRFs, all selected GRFs are already profiling.");
2412 NewGRFProfiler::FinishAll();
2433 static void IConsoleDebugLibRegister()
2468 static void ConDumpRoadTypes()
2477 std::map<uint32_t, const GRFFile *> grfs;
2480 if (rti->
label == 0)
continue;
2483 if (grf !=
nullptr) {
2485 grfs.emplace(grfid, grf);
2489 RoadTypeIsTram(rt) ?
"Tram" :
"Road",
2500 for (
const auto &grf : grfs) {
2505 static void ConDumpRailTypes()
2515 std::map<uint32_t, const GRFFile *> grfs;
2518 if (rti->
label == 0)
continue;
2521 if (grf !=
nullptr) {
2523 grfs.emplace(grfid, grf);
2538 for (
const auto &grf : grfs) {
2543 static void ConDumpCargoTypes()
2558 std::map<uint32_t, const GRFFile *> grfs;
2560 if (!spec->IsValid())
continue;
2562 const GRFFile *grf = spec->grffile;
2563 if (grf !=
nullptr) {
2565 grfs.emplace(grfid, grf);
2567 IConsolePrint(
CC_DEFAULT,
" {:02d} Bit: {:2d}, Label: {:c}{:c}{:c}{:c}, Callback mask: 0x{:02X}, Cargo class: {}{}{}{}{}{}{}{}{}{}{}, GRF: {:08X}, {}",
2570 spec->label.base() >> 24, spec->label.base() >> 16, spec->label.base() >> 8, spec->label.base(),
2571 spec->callback_mask,
2573 (spec->classes &
CC_MAIL) != 0 ?
'm' :
'-',
2574 (spec->classes &
CC_EXPRESS) != 0 ?
'x' :
'-',
2576 (spec->classes &
CC_BULK) != 0 ?
'b' :
'-',
2578 (spec->classes &
CC_LIQUID) != 0 ?
'l' :
'-',
2581 (spec->classes &
CC_COVERED) != 0 ?
'c' :
'-',
2582 (spec->classes &
CC_SPECIAL) != 0 ?
'S' :
'-',
2584 GetStringPtr(spec->name)
2587 for (
const auto &grf : grfs) {
2613 ConDumpCargoTypes();
2624 void IConsoleStdLibRegister()
2699 #if defined(WITH_ZLIB)
2756 IConsoleDebugLibRegister();
@ VEH_AIRCRAFT
Aircraft vehicle type.
RoadTypeFlags flags
Bit mask of road type flags.
void NetworkClientSendRcon(const std::string &password, const std::string &command)
Send a remote console command.
bool show_dirs
Whether to show directories in the file list.
bool StrStartsWithIgnoreCase(std::string_view str, const std::string_view prefix)
Check whether the given string starts with the given prefix, ignoring case.
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.)
std::string FormatArrayAsHex(std::span< const byte > data)
Format a byte array into a continuous hex string.
@ 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.
@ FT_SCENARIO
old or new scenario
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
@ 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.
@ SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
ScreenshotType
Type of requested screenshot.
void ConPrintFramerate()
Print performance statistics to game console.
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 DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
@ RTF_NO_SPRITE_COMBINE
Bit number for using non-combined junctions.
static debug_inline uint LogX()
Logarithm of the map size along the X side.
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?...
Gamelog _gamelog
Gamelog instance.
@ 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.
static void AbortTimer()
Abort the timeout timer, so the timer callback is never called.
@ SCREENSHOT_DIR
Subdirectory for all screenshots.
@ ROTF_NO_LEVEL_CROSSING
Bit number for disabling level crossing.
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
static ConsoleFileList _console_file_list_savegame
File storage cache for savegames.
Searchpath
Types of searchpaths OpenTTD might use.
bool aa
Whether to do anti aliasing or not.
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.
This struct contains all the info that is needed to draw and construct tracks.
@ DFT_GAME_FILE
Save game or scenario file.
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
bool GetArgumentInteger(uint32_t *value, const char *arg)
Change a string into its number representation.
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.
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
@ 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?
void SetDebugString(const char *s, void(*error_func)(const std::string &))
Set debugging levels by parsing the text in s.
@ CC_LIQUID
Liquids (Oil, Water, Rubber)
@ CONTENT_TYPE_END
Helper to mark the end of the types.
@ VEH_ROAD
Road vehicle type.
@ CC_PASSENGERS
Passengers.
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.
struct RailTypeInfo::@26 strings
Strings associated with the rail type.
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.
std::string FiosGetCurrentPath()
Get the current path/working directory.
void StartNewGameWithoutGUI(uint32_t seed)
Start a normal game without the GUI.
MD5Hash md5sum
The MD5 checksum.
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 const AdminIndex INVALID_ADMIN_ID
An invalid admin marker.
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.
IConsoleHook * hook
any special trigger action that needs executing
GameCreationSettings game_creation
settings used during the creation of a game (map)
const FiosItem * FindItem(const std::string_view file)
Find file information of a file by its name from the file list.
void Change(std::optional< const std::string > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
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.
@ ROTF_CATENARY
Bit number for adding catenary.
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 NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
StringID name
Name of this rail type.
@ ZOOM_LVL_MIN
Minimum zoom level.
AbstractFileType
The different abstract types of files that the system knows about.
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
@ ZOOM_IN
Zoom in (get more detailed view).
@ RTF_DISALLOW_90DEG
Bit number for never allowed 90 degree turns, regardless of setting.
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
@ BASE_DIR
Base directory for all subdirectories.
std::string GetDebugString()
Print out the current debug-level.
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.
@ 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.
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
@ CC_SPECIAL
Special bit used for livery refit tricks instead of normal cargoes.
std::string last_joined
Last joined server.
bool HasParent()
Check whether the font cache has a parent.
@ SLO_SAVE
File is being saved.
static void StartTimer(uint64_t ticks)
Start the timeout timer that will finish all profiling sessions.
static const TextColour CC_HELP
Colour for help lines.
@ AI_DIR
Subdirectory for all AI files.
@ RTF_CATENARY
Bit number for drawing a catenary.
@ CCA_NEW_AI
Create a new AI company.
static bool IsConnected()
Check whether the client is actually connected (and in the game).
static ConsoleFileList _console_file_list_scenario
File storage cache for scenarios.
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.
void IConsoleCmdExec(const std::string &command_string, const uint recurse_count)
Execute a given command passed to us.
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for GameScanner::GetConsoleLibraryList.
@ CC_PIECE_GOODS
Piece goods (Livestock, Wood, Steel, Paper)
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for GameScanner::GetConsoleList.
std::string font
The name of the font, or path to the font.
Container for all important information about a piece of content.
bool FileExists(const std::string &filename)
Test whether the given filename exists.
@ RTF_ALLOW_90DEG
Bit number for always allowed 90 degree turns, regardless of setting.
void InitFontCache(bool monospace)
(Re)initialize the font cache related things, i.e.
@ CC_BULK
Bulk cargo (Coal, Grain etc., Ores, Fruit)
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Deals with finding savegames.
PauseMode _pause_mode
The current pause mode.
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.
RailTypeLabel label
Unique 32 bit rail type identifier.
void ShowFramerateWindow()
Open the general framerate window.
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.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
AbstractFileType abstract_filetype
The abstract file type to list.
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.
@ FT_INVALID
Invalid or unknown file type.
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?
FontCacheSubSetting * GetFontCacheSubSetting(FontSize fs)
Get the settings of a given font size.
@ RTF_HIDDEN
Bit number for hiding from selection.
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.
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
const GRFFile * grffile[RTSG_END]
NewGRF providing the Action3 for the railtype.
static const TextColour CC_COMMAND
Colour for the console's commands.
@ 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.
ClientID client_id
Client identifier (same as ClientState->client_id)
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
File list storage for the console, for caching the last 'ls' command.
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
ClientID _network_own_client_id
Our client identifier.
std::string name
name of the alias
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
ZoomLevel zoom_min
minimum zoom out level
static debug_inline uint SizeX()
Get the size of the map along the X.
static ConsoleFileList _console_file_list_heightmap
File storage cache for heightmaps.
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 PrintConsole()
Print the gamelog data to the console.
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.
uint32_t generation_seed
noise seed for world generation
ClientID
'Unique' identifier to be given to clients
@ CC_ARMOURED
Armoured cargo (Valuables, Gold, Diamonds)
static size_t GetNumItems()
Returns number of valid items in the pool.
uint8_t map_y
Y size of map.
RoadTypeLabel label
Unique 32 bit road type identifier.
uint8_t map_x
X size of map.
void Set(const FiosItem &item)
Set the title of the file.
static debug_inline uint Size()
Get the size of the map.
@ AUTOSELECTED
The content has been selected as dependency.
@ CRR_NONE
Dummy reason for actions that don't need one.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
@ COMPANY_SPECTATOR
The client is spectating.
@ RAILTYPE_END
Used for iterations.
@ CC_REFRIGERATED
Refrigerated cargo (Food, Fruit)
Window * GetMainWindow()
Get the main window, i.e.
DEF_CONSOLE_CMD(ConResetEngines)
Reset status of all engines.
@ WC_CONSOLE
Console; Window numbers:
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.
uint8_t max_clients
maximum amount of clients
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
uint8_t max_companies
maximum amount of companies
@ RTF_NO_LEVEL_CROSSING
Bit number for disallowing level crossings.
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.
@ 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.
RoadType
The different roadtypes we support.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
@ FT_HEIGHTMAP
heightmap file
void Select(ContentID cid)
Select a specific content id.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
@ INVALID_CLIENT_ID
Client is not part of anything.
struct RoadTypeInfo::@29 strings
Strings associated with the rail type.
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.
@ ROTF_TOWN_BUILD
Bit number for allowing towns to build this roadtype.
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
@ ROTF_HIDDEN
Bit number for hidden from construction.
void AddCallback(ContentCallback *cb)
Add a callback to this class.
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.
@ AI_LIBRARY_DIR
Subdirectory for all AI libraries.
#define lengthof(x)
Return the length of an fixed size array.
StringList _network_ban_list
The banned clients.
ZoomLevel zoom
The zoom level of the viewport.
@ ROTF_NO_HOUSES
Bit number for setting this roadtype as not house friendly.
@ SOCIAL_INTEGRATION_DIR
Subdirectory for all social integration plugins.
static uint LogY()
Logarithm of the map size along the y side.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
NetworkSettings network
settings related to the network
void IConsoleClose()
Close the in-game console.
@ SC_VIEWPORT
Screenshot of viewport.
@ 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.
RailTypeFlags flags
Bit mask of rail type flags.
void NetworkServerKickClient(ClientID client_id, const std::string &reason)
Kick a single client.
void OnDisconnect() override
Callback for when the connection got disconnected.
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data)
Send a chat message.
static Date date
Current date in days (day counter).
FontSize
Available font sizes.
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for AIScanner::GetAIConsoleList.
Data structure for an opened window.
@ VEH_TRAIN
Train vehicle type.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
bool MakeScreenshot(ScreenshotType t, std::string name, uint32_t width, uint32_t height)
Schedule making a screenshot.
@ 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.
ContentID id
Unique (server side) ID for the content.
@ CCA_DELETE
Delete a company.
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.
@ SL_OK
completed successfully
@ ROADTYPE_BEGIN
Used for iterations.
@ CLIENT_ID_SERVER
Servers always have this ID.
Container for all information known about a client.
@ CRR_MANUAL
The company is manually removed.
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs)
Construct a file list with the given kind of files, for the stated purpose.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
uint32_t unique_id
Unique ID; either GRF ID or shortname.
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.
static uint SizeY()
Get the size of the map along the Y.
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.
static void PrintLineByLine(const std::string &full_string)
Print a text buffer line by line to the console.
@ 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.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.