46#include "3rdparty/fmt/chrono.h"
54#include "table/strings.h"
86static std::optional<T>
ParseType(std::string_view arg)
89 if (i.has_value())
return static_cast<T>(*i);
140 if (echo)
IConsolePrint(
CC_ERROR,
"You cannot use this command because there is no network available.");
255 IConsolePrint(
CC_HELP,
"Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'.");
271 IConsolePrint(
CC_HELP,
"Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
293static bool ConResetTile(std::span<std::string_view> argv)
301 if (argv.size() == 2) {
319 switch (argv.size()) {
339 if (level.has_value()) {
340 auto zoom_lvl =
static_cast<ZoomLevel>(*level);
370 IConsolePrint(
CC_HELP,
"'instant' will immediately move and redraw viewport without smooth scrolling.");
373 if (argv.size() < 2)
return false;
375 uint32_t arg_index = 1;
376 bool instant =
false;
377 if (argv[arg_index] ==
"instant") {
382 switch (argv.size() - arg_index) {
385 if (result.has_value()) {
399 if (x.has_value() && y.has_value()) {
418static bool ConSave(std::span<std::string_view> argv)
425 if (argv.size() == 2) {
426 std::string filename = fmt::format(
"{}.sav", argv[1]);
447 IConsolePrint(
CC_HELP,
"Saves the configuration for new games to the configuration file, typically 'openttd.cfg'.");
448 IConsolePrint(
CC_HELP,
"It does not save the configuration of the current game to the configuration file.");
458static bool ConLoad(std::span<std::string_view> argv)
465 if (argv.size() != 2)
return false;
467 std::string_view file = argv[1];
470 if (item !=
nullptr) {
488 IConsolePrint(
CC_HELP,
"Load a scenario by name or index. Usage: 'load_scenario <file | number>'.");
492 if (argv.size() != 2)
return false;
494 std::string_view file = argv[1];
497 if (item !=
nullptr) {
515 IConsolePrint(
CC_HELP,
"Load a heightmap by name or index. Usage: 'load_heightmap <file | number>'.");
519 if (argv.size() != 2)
return false;
521 std::string_view file = argv[1];
524 if (item !=
nullptr) {
546 if (argv.size() != 2)
return false;
548 std::string_view file = argv[1];
551 if (item !=
nullptr) {
572 IConsolePrint(
CC_HELP,
"List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'.");
624 if (argv.size() != 2)
return false;
626 std::string_view file = argv[1];
629 if (item !=
nullptr) {
670 IConsoleClearBuffer();
687static bool ConKickOrBan(std::string_view arg,
bool ban, std::string_view reason)
691 if (arg.find_first_of(
".:") == std::string::npos) {
693 if (!client_id.has_value()) {
735static bool ConKick(std::span<std::string_view> argv)
738 IConsolePrint(
CC_HELP,
"Kick a client from a network game. Usage: 'kick <ip | client-id> [<kick-reason>]'.");
743 if (argv.size() != 2 && argv.size() != 3)
return false;
746 if (argv.size() == 2)
return ConKickOrBan(argv[1],
false, {});
749 size_t kick_message_length = argv[2].size();
750 if (kick_message_length >= 255) {
751 IConsolePrint(
CC_ERROR,
"Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
759static bool ConBan(std::span<std::string_view> argv)
762 IConsolePrint(
CC_HELP,
"Ban a client from a network game. Usage: 'ban <ip | client-id> [<ban-reason>]'.");
768 if (argv.size() != 2 && argv.size() != 3)
return false;
771 if (argv.size() == 2)
return ConKickOrBan(argv[1],
true, {});
774 size_t kick_message_length = argv[2].size();
775 if (kick_message_length >= 255) {
776 IConsolePrint(
CC_ERROR,
"Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
784static bool ConUnBan(std::span<std::string_view> argv)
787 IConsolePrint(
CC_HELP,
"Unban a client from a network game. Usage: 'unban <ip | banlist-index>'.");
792 if (argv.size() != 2)
return false;
886static bool ConRcon(std::span<std::string_view> argv)
889 IConsolePrint(
CC_HELP,
"Remote control the server from another client. Usage: 'rcon <password> <command>'.");
890 IConsolePrint(
CC_HELP,
"Remember to enclose the command in quotes, otherwise only the first parameter is sent.");
891 IConsolePrint(
CC_HELP,
"When your client's public key is in the 'authorized keys' for 'rcon', the password is not checked and may be '*'.");
895 if (argv.size() < 3)
return false;
909 IConsolePrint(
CC_HELP,
"List the status of all clients connected to the server. Usage 'status'.");
922 IConsolePrint(
CC_HELP,
"You can change these values by modifying settings 'network.max_clients' and 'network.max_companies'.");
937 if (argv.size() != 3) {
938 IConsolePrint(
CC_HELP,
"Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'.");
944 if (!client_id.has_value()) {
980 if (company_id.has_value() && *company_id <= MAX_COMPANIES)
return static_cast<CompanyID
>(*company_id - 1);
987 if (argv.size() < 2) {
994 if (!company_id.has_value()) {
1000 if (info ==
nullptr) {
1007 IConsolePrint(
CC_ERROR,
"Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
1039 if (argv.size() < 3) {
1040 IConsolePrint(
CC_HELP,
"Move a client to another company. Usage: 'move <client-id> <company-id>'.");
1041 IConsolePrint(
CC_HELP,
"For valid client-id see 'clients', for valid company-id see 'companies', use 255 for moving to spectators.");
1046 if (!client_id.has_value()) {
1053 if (!company_id.has_value()) {
1059 if (ci ==
nullptr) {
1065 IConsolePrint(
CC_ERROR,
"Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
1094 IConsolePrint(
CC_HELP,
"Remove an idle company from the game. Usage: 'reset_company <company-id>'.");
1095 IConsolePrint(
CC_HELP,
"For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
1099 if (argv.size() != 2)
return false;
1102 if (!index.has_value()) {
1109 IConsolePrint(
CC_ERROR,
"Company does not exist. company-id must be between 1 and {}.", MAX_COMPANIES);
1123 assert(ci !=
nullptr);
1140 IConsolePrint(
CC_HELP,
"Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'.");
1153 IConsolePrint(
CC_HELP,
"Reconnect to server to which you were connected last time. Usage: 'reconnect [<company-id>]'.");
1154 IConsolePrint(
CC_HELP,
"Company 255 is spectator (default, if not specified), 254 means creating new company.");
1160 if (argv.size() >= 2) {
1162 if (!company_id.has_value()) {
1167 playas = *company_id;
1185 IConsolePrint(
CC_HELP,
"Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'.");
1186 IConsolePrint(
CC_HELP,
"IP can contain port and company: 'IP[:Port][#Company]', eg: 'server.ottd.org:443#2'.");
1187 IConsolePrint(
CC_HELP,
"Company #255 is spectator all others are a certain company with Company 1 being #1.");
1191 if (argv.size() < 2)
return false;
1201static bool ConExec(std::span<std::string_view> argv)
1205 IConsolePrint(
CC_HELP,
"By passing '0' after the script name, no warning about a missing script file will be shown.");
1209 if (argv.size() < 2)
return false;
1213 if (!script_file.has_value()) {
1214 if (argv.size() == 2 || argv[2] !=
"0")
IConsolePrint(
CC_ERROR,
"Script file '{}' not found.", argv[1]);
1219 IConsolePrint(
CC_ERROR,
"Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
1227 while (fgets(buffer,
sizeof(buffer), *script_file) !=
nullptr) {
1229 std::string_view cmdline{buffer};
1230 auto last_non_newline = cmdline.find_last_not_of(
"\r\n");
1231 if (last_non_newline != std::string_view::npos) cmdline = cmdline.substr(0, last_non_newline + 1);
1241 if (ferror(*script_file) != 0) {
1252 if (argv.size() < 3 || std::string_view(argv[1]) !=
"on-next-calendar-month") {
1253 IConsolePrint(
CC_HELP,
"Schedule a local script to execute later. Usage: 'schedule on-next-calendar-month <script>'.");
1264 std::string_view filename = std::string_view(argv[2]);
1266 IConsolePrint(
CC_INFO,
"Script file '{}' was already scheduled to execute at the start of next calendar month.", filename);
1270 IConsolePrint(
CC_INFO,
"Script file '{}' scheduled to execute at the start of next calendar month.", filename);
1294extern bool CloseConsoleLogIfActive();
1295extern std::span<const GRFFile> GetAllGRFFiles();
1302 extern std::optional<FileHandle> _iconsole_output_file;
1305 IConsolePrint(
CC_HELP,
"Start or stop logging console output to a file. Usage: 'script <filename>'.");
1310 if (!CloseConsoleLogIfActive()) {
1311 if (argv.size() < 2)
return false;
1314 if (!_iconsole_output_file.has_value()) {
1325static bool ConEcho(std::span<std::string_view> argv)
1332 if (argv.size() < 2)
return false;
1341 IConsolePrint(
CC_HELP,
"Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'.");
1345 if (argv.size() < 3)
return false;
1362 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.");
1367 if (argv.size() >= 2) {
1369 if (!param.has_value()) {
1383 if (argv.empty() || argv.size() > 2) {
1385 IConsolePrint(
CC_HELP,
"Restarts a game, using either the current or newgame (default) settings.");
1386 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.");
1387 IConsolePrint(
CC_HELP,
" * if you started from a savegame / scenario / heightmap, the game might be different, because the current/newgame settings might differ.");
1391 if (argv.size() == 1 || std::string_view(argv[1]) ==
"newgame") {
1429 std::istringstream in(full_string);
1431 while (std::getline(in, line)) {
1442template <
typename F,
typename ... Args>
1445 std::string output_str;
1446 auto inserter = std::back_inserter(output_str);
1447 list_function(inserter, args...);
1500 if (argv.empty() || argv.size() > 3) {
1502 IConsolePrint(
CC_HELP,
"Start a new AI. If <AI> is given, it starts that specific AI (if found).");
1503 IConsolePrint(
CC_HELP,
"If <settings> is given, it is parsed and the AI settings are set to that.");
1533 if (c->index != n)
break;
1538 if (argv.size() >= 2) {
1539 config->
Change(argv[1], -1,
false);
1549 if (!version.has_value()) {
1553 config->
Change(name, *version,
true);
1561 if (argv.size() == 3) {
1575 if (argv.size() != 2) {
1577 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.");
1592 if (!company_id.has_value()) {
1619 if (argv.size() != 2) {
1621 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.");
1636 if (!company_id.has_value()) {
1704 IConsolePrint(
CC_ERROR,
"NewGRF scanning is already running. Please wait until completed to run again.");
1715 IConsolePrint(
CC_HELP,
"The seed can be used to reproduce the exact same map as the game started with.");
1727 IConsolePrint(
CC_HELP,
"Returns the current date (year-month-day) of the game. Usage: 'getdate'.");
1740 IConsolePrint(
CC_HELP,
"Returns the current date (year-month-day) of your system. Usage: 'getsysdate'.");
1754 IConsolePrint(
CC_HELP,
"Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'.");
1758 if (argv.size() < 3)
return false;
1761 if (alias ==
nullptr) {
1773 IConsolePrint(
CC_HELP,
"Create a screenshot of the game. Usage: 'screenshot [viewport | normal | big | giant | heightmap | minimap] [no_con] [size <width> <height>] [<filename>]'.");
1774 IConsolePrint(
CC_HELP,
" 'viewport' (default) makes a screenshot of the current viewport (including menus, windows).");
1778 IConsolePrint(
CC_HELP,
" 'heightmap' makes a heightmap screenshot of the map that can be loaded in as heightmap.");
1779 IConsolePrint(
CC_HELP,
" 'minimap' makes a top-viewed minimap screenshot of the whole world which represents one tile by one pixel.");
1780 IConsolePrint(
CC_HELP,
" 'no_con' hides the console to create the screenshot (only useful in combination with 'viewport').");
1781 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').");
1782 IConsolePrint(
CC_HELP,
" A filename ending in # will prevent overwriting existing files and will number files counting upwards.");
1786 if (argv.size() > 7)
return false;
1790 uint32_t height = 0;
1792 uint32_t arg_index = 1;
1794 if (argv.size() > arg_index) {
1795 if (argv[arg_index] ==
"viewport") {
1798 }
else if (argv[arg_index] ==
"normal") {
1801 }
else if (argv[arg_index] ==
"big") {
1804 }
else if (argv[arg_index] ==
"giant") {
1807 }
else if (argv[arg_index] ==
"heightmap") {
1810 }
else if (argv[arg_index] ==
"minimap") {
1816 if (argv.size() > arg_index && argv[arg_index] ==
"no_con") {
1825 if (argv.size() > arg_index + 2 && argv[arg_index] ==
"size") {
1832 if (!t.has_value()) {
1839 if (!t.has_value()) {
1847 if (argv.size() > arg_index) {
1849 name = argv[arg_index];
1853 if (argv.size() > arg_index) {
1866 IConsolePrint(
CC_HELP,
"Print out debugging information about a command. Usage: 'info_cmd <cmd>'.");
1870 if (argv.size() < 2)
return false;
1873 if (cmd ==
nullptr) {
1889 IConsolePrint(
CC_HELP,
"Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'.");
1890 IConsolePrint(
CC_HELP,
"Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'\"s.");
1894 if (argv.size() > 2)
return false;
1896 if (argv.size() == 1) {
1906static bool ConExit(std::span<std::string_view> argv)
1920static bool ConPart(std::span<std::string_view> argv)
1923 IConsolePrint(
CC_HELP,
"Leave the currently joined/running game (only ingame). Usage: 'part'.");
1939static bool ConHelp(std::span<std::string_view> argv)
1941 if (argv.size() == 2) {
1946 if (cmd !=
nullptr) {
1952 if (alias !=
nullptr) {
1954 if (cmd !=
nullptr) {
1986 for (
auto &it : IConsole::Commands()) {
1988 if (argv.size() <= 1|| cmd->
name.find(argv[1]) != std::string::npos) {
2004 for (
auto &it : IConsole::Aliases()) {
2006 if (argv.size() <= 1 || alias->
name.find(argv[1]) != std::string::npos) {
2024 std::string company_name =
GetString(STR_COMPANY_NAME, c->index);
2027 IConsolePrint(
CC_INFO,
"#:{}({}) Company Name: '{}' Year Founded: {} Money: {} Loan: {} Value: {} (T:{}, R:{}, P:{}, S:{}) {}",
2028 c->index + 1, colour, company_name,
2029 c->inaugurated_year, (int64_t)c->money, (int64_t)c->current_loan, (int64_t)
CalculateCompanyValue(c),
2034 c->is_ai ?
"AI" :
"");
2041static bool ConSay(std::span<std::string_view> argv)
2044 IConsolePrint(
CC_HELP,
"Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'.");
2048 if (argv.size() != 2)
return false;
2064 IConsolePrint(
CC_HELP,
"Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'.");
2065 IConsolePrint(
CC_HELP,
"CompanyNo is the company that plays as company <companyno>, 1 through max_companies.");
2069 if (argv.size() != 3)
return false;
2072 if (!company_id.has_value()) {
2096 IConsolePrint(
CC_HELP,
"Chat to a certain client in a multiplayer game. Usage: 'say_client <client-id> \"<msg>\"'.");
2101 if (argv.size() != 3)
return false;
2104 if (!client_id.has_value()) {
2142 if (authorized_keys->Contains(authorized_key)) {
2147 if (company == CompanyID::Invalid()) {
2148 authorized_keys->Add(authorized_key);
2157 if (!authorized_keys->Contains(authorized_key)) {
2162 if (company == CompanyID::Invalid()) {
2163 authorized_keys->Remove(authorized_key);
2176 if (argv.size() <= 2) {
2177 IConsolePrint(
CC_HELP,
"List and update authorized keys. Usage: 'authorized_key list [type]|add [type] [key]|remove [type] [key]'.");
2180 IConsolePrint(
CC_HELP,
" remove: remove the given key from the authorized keys of the given type; use 'all' to remove all authorized keys.");
2181 IConsolePrint(
CC_HELP,
"Instead of a key, use 'client:<id>' to add/remove the key of that given client.");
2190 std::string_view action_string = argv[1];
2202 std::string authorized_key;
2204 if (argv.size() <= 3) {
2209 authorized_key = argv[3];
2213 if (!value.has_value() || authorized_key.empty()) {
2225 std::string_view type = argv[2];
2227 for (
auto [name, authorized_keys] :
_console_cmd_authorized_keys) PerformNetworkAuthorizedKeyAction(name, authorized_keys, action, authorized_key);
2228 for (
Company *c :
Company::Iterate()) PerformNetworkAuthorizedKeyAction(fmt::format(
"company:{}", c->index + 1), &c->allow_list, action, authorized_key, c->index);
2240 PerformNetworkAuthorizedKeyAction(type, &c->
allow_list, action, authorized_key, c->index);
2247 PerformNetworkAuthorizedKeyAction(name, authorized_keys, action, authorized_key);
2257#if defined(WITH_ZLIB)
2266 static const std::initializer_list<std::pair<std::string_view, ContentType>> content_types = {
2274 for (
const auto &ct : content_types) {
2305 "",
"Base graphics",
"NewGRF",
"AI",
"AI library",
"Scenario",
"Heightmap",
"Base sound",
"Base music",
"Game script",
"GS library"
2308 "Not selected",
"Selected",
"Dep Selected",
"Installed",
"Unknown"
2314 IConsolePrint(state_to_colour[ci.
state],
"{}, {}, {}, {}, {:08X}, {}", ci.
id, types[ci.
type], states[ci.
state], ci.
name, ci.
unique_id,
FormatArrayAsHex(ci.
md5sum));
2326 if (argv.size() <= 1) {
2327 IConsolePrint(
CC_HELP,
"Query, select and download content. Usage: 'content update|upgrade|select [id]|unselect [all|id]|state [filter]|download'.");
2330 IConsolePrint(
CC_HELP,
" select: select a specific item given by its id. If no parameter is given, all selected content will be listed.");
2331 IConsolePrint(
CC_HELP,
" unselect: unselect a specific item given by its id or 'all' to unselect all.");
2332 IConsolePrint(
CC_HELP,
" state: show the download/select state of all downloadable content. Optionally give a filter string.");
2348 if (argv.size() <= 2) {
2372 if (argv.size() <= 2) {
2421static bool ConFont(std::span<std::string_view> argv)
2427 IConsolePrint(
CC_HELP,
" The \"Currently active\" configuration is the one actually in effect (after interface scaling and replacing unavailable fonts).");
2428 IConsolePrint(
CC_HELP,
" The \"Requested\" configuration is the one requested via console command or config file.");
2432 IConsolePrint(
CC_HELP,
" Set <font name> to \"\" for the default font. Note that <size> has no effect if the default font is in use, and fixed defaults are used instead.");
2433 IConsolePrint(
CC_HELP,
" If the sprite font is enabled in Game Options, it is used instead of the default font.");
2434 IConsolePrint(
CC_HELP,
" The <size> is automatically multiplied by the current interface scaling.");
2438 if (argv.size() > 2) {
2444 std::string font = setting->
font;
2445 uint size = setting->
size;
2446 uint8_t arg_index = 2;
2450 font = argv[arg_index++];
2453 if (argv.size() > arg_index) {
2456 if (v.has_value()) {
2462 SetFont(argfs, font, size);
2490 if (argv.size() == 1 || argv.size() > 3)
return false;
2492 if (argv.size() == 2) {
2495 IConsoleSetSetting(argv[1], argv[2]);
2505 IConsolePrint(
CC_HELP,
"Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'.");
2510 if (argv.size() == 1 || argv.size() > 3)
return false;
2512 if (argv.size() == 2) {
2515 IConsoleSetSetting(argv[1], argv[2],
true);
2529 if (argv.size() > 2)
return false;
2539 IConsolePrint(
CC_HELP,
"Print logged fundamental changes to the game since the start. Usage: 'gamelog'.");
2551 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!");
2562 struct SubdirNameMap {
2563 std::string_view name;
2567 static const SubdirNameMap subdir_name_map[] = {
2584 if (argv.size() != 2) {
2585 IConsolePrint(
CC_HELP,
"List all search paths or default directories for various categories.");
2587 std::string cats{subdir_name_map[0].name};
2589 for (
const SubdirNameMap &sdn : subdir_name_map) {
2600 std::set<std::string> seen_dirs;
2601 for (
const SubdirNameMap &sdn : subdir_name_map) {
2606 std::string path = FioGetDirectory(sp, sdn.subdir);
2608 if (seen_dirs.find(path) != seen_dirs.end())
continue;
2609 seen_dirs.insert(path);
2614 if (!sdn.default_only || exists) {
2616 if (sdn.default_only)
break;
2633 IConsolePrint(
CC_HELP,
"Collect performance data about NewGRF sprite requests and callbacks. Sub-commands can be abbreviated.");
2639 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.");
2641 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.");
2649 std::span<const GRFFile> files = GetAllGRFFiles();
2655 for (
const auto &grf : files) {
2657 bool selected = profiler != _newgrf_profilers.end();
2658 bool active = selected && profiler->active;
2660 std::string_view statustext = active ?
" (active)" : selected ?
" (selected)" :
"";
2669 for (
size_t argnum = 2; argnum < argv.size(); ++argnum) {
2671 if (!grfnum.has_value() || *grfnum < 1 ||
static_cast<size_t>(*grfnum) > files.size()) {
2675 const GRFFile *grf = &files[*grfnum - 1];
2676 if (std::any_of(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; })) {
2680 _newgrf_profilers.emplace_back(grf);
2687 for (
size_t argnum = 2; argnum < argv.size(); ++argnum) {
2689 _newgrf_profilers.clear();
2693 if (!grfnum.has_value() || *grfnum < 1 ||
static_cast<size_t>(*grfnum) > files.size()) {
2697 const GRFFile *grf = &files[*grfnum - 1];
2712 if (!grfids.empty()) grfids +=
", ";
2719 if (argv.size() >= 3) {
2721 if (!ticks.has_value()) {
2722 IConsolePrint(
CC_ERROR,
"No valid amount of ticks was given, profiling will not stop automatically.");
2728 }
else if (_newgrf_profilers.empty()) {
2731 IConsolePrint(
CC_ERROR,
"Did not start profiling for any GRFs, all selected GRFs are already profiling.");
2738 NewGRFProfiler::FinishAll();
2759static void IConsoleDebugLibRegister()
2806 std::map<GrfID, const GRFFile *> grfs;
2812 if (grf !=
nullptr) {
2814 grfs.emplace(grfid, grf);
2818 RoadTypeIsTram(rt) ?
"Tram" :
"Road",
2829 for (
const auto &grf : grfs) {
2845 std::map<GrfID, const GRFFile *> grfs;
2851 if (grf !=
nullptr) {
2853 grfs.emplace(grfid, grf);
2868 for (
const auto &grf : grfs) {
2894 std::map<GrfID, const GRFFile *> grfs;
2897 const GRFFile *grf = spec->grffile;
2898 if (grf !=
nullptr) {
2900 grfs.emplace(grfid, grf);
2902 IConsolePrint(
CC_DEFAULT,
" {:02d} Bit: {:2d}, Label: {}, Callback mask: 0x{:02X}, Cargo class: {}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}, GRF: {}, {}",
2905 spec->label.AsString(),
2906 spec->callback_mask.base(),
2924 GetStringPtr(spec->name)
2927 for (
const auto &grf : grfs) {
2935 if (argv.size() != 2) {
3037#if defined(WITH_ZLIB)
3093 IConsoleDebugLibRegister();
Base functions for all AIs.
AIConfig stores the configuration settings of every AI.
@ NotPourable
Not Pourable (open wagon, but not hopper wagon).
@ Powderized
Powderized, moist protected (powder/silo wagon).
@ Hazardous
Hazardous cargo (Nuclear Fuel, Explosives, etc.).
@ NonPotable
Non-potable / non-food / dirty.
@ Bulk
Bulk cargo (Coal, Grain etc., Ores, Fruit).
@ Liquid
Liquids (Oil, Water, Rubber).
@ Potable
Potable / food / clean.
@ Oversized
Oversized (stake/flatbed wagon).
@ Armoured
Armoured cargo (Valuables, Gold, Diamonds).
@ Refrigerated
Refrigerated cargo (Food, Fruit).
@ Express
Express cargo (Goods, Food, Candy, but also possible for passengers).
@ Special
Special bit used for livery refit tricks instead of normal cargoes.
@ PieceGoods
Piece goods (Livestock, Wood, Steel, Paper).
@ Covered
Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.).
AI instantion of script configuration.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=ScriptSettingSource::Default)
Get the AI configuration of specific company.
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Get the list of registered scripts to print on the console.
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Get the list of registered scripts to print on the console.
static bool CanStartNew()
Is it possible to start a new AI company?
static void Rescan()
Rescans all searchpaths for available AIs.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
static bool IsConnected()
Check whether the client is actually connected (and in the game).
File list storage for the console, for caching the last 'ls' command.
void ValidateFileList(bool force_reload=false)
(Re-)validate the file storage cache.
bool file_list_valid
If set, the file list is valid.
AbstractFileType abstract_filetype
The abstract file type to list.
void InvalidateFileList()
Declare the file storage cache as being invalid, also clears all stored files.
bool show_dirs
Whether to show directories in the file list.
Iterate a range of enum values.
static std::optional< FileHandle > Open(const std::string &filename, std::string_view mode)
Open an RAII file handle if possible.
List of file information.
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs)
Construct a file list with the given kind of files, for the stated purpose.
Font cache for basic fonts.
virtual std::string GetFontName()=0
Get the name of this font.
bool HasParent()
Check whether the font cache has a parent.
virtual int GetFontSize() const
Get the nominal font size of the font.
static void LoadFontCaches(FontSizes fontsizes)
(Re)initialize the font cache related things, i.e.
static FontCache * Get(FontSize fs)
Get the font cache of a given font size.
static void Rescan()
Rescans all searchpaths for available Game scripts.
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Get the list of registered scripts to print on the console.
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Get the list of registered scripts to print on the console.
An interval timer will fire every interval, and will continue to fire until it is deleted.
Simple helper to (more easily) manage authorized keys.
This struct contains all the info that is needed to draw and construct tracks.
struct RailTypeInfo::@157247141350136173143103254227157213063052244122 strings
Strings associated with the rail type.
EnumIndexArray< const GRFFile *, RailSpriteType, RailSpriteType::End > grffile
NewGRF providing the Action3 for the railtype.
RailTypeLabel label
Unique 32 bit rail type identifier.
StringID name
Name of this rail type.
RailTypeFlags flags
Bit mask of rail type flags.
RoadTypeLabel label
Unique 32 bit road type identifier.
RoadTypeFlags flags
Bit mask of road type flags.
struct RoadTypeInfo::@070000167274302256150317022075324310363002361255 strings
Strings associated with the rail type.
StringID name
Name of this rail type.
EnumIndexArray< const GRFFile *, RoadSpriteType, RoadSpriteType::End > grffile
NewGRF providing the Action3 for the roadtype.
bool HasScript() const
Is this config attached to an Script?
void Change(std::optional< std::string_view > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
void StringToSettings(std::string_view value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
Parse data from a string / buffer.
std::optional< T > TryReadIntegerBase(int base, bool clamp=false)
Try to read and parse an integer in number 'base', and then advance the reader.
std::string_view ReadUntilChar(char c, SeparatorUsage sep)
Read data until the first occurrence of 8-bit char 'c', and advance reader.
@ SKIP_ONE_SEPARATOR
Read and discard one separator, do not include it in the result.
bool AnyBytesLeft() const noexcept
Check whether any bytes left to read.
static const std::string_view WHITESPACE_NO_NEWLINE
ASCII whitespace characters, excluding new-line.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
static Date date
Current date in days (day counter).
Functions related to commands.
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
TypedIndexContainer< std::array< Colours, MAX_COMPANIES >, CompanyID > _company_colours
NOSAVE: can be determined from company structs.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Command definitions related to companies.
Functions related to companies.
@ NewAI
Create a new AI company.
@ Delete
Delete a company.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
@ RemoveKey
Remove a public key.
@ AddKey
Create a public key.
static constexpr CompanyID COMPANY_NEW_COMPANY
The client wants a new company.
@ None
Dummy reason for actions that don't need one.
@ Manual
The company is manually removed.
static const uint NETWORK_PUBLIC_KEY_LENGTH
The maximum length of the hexadecimal encoded public keys, in bytes including '\0'.
void IConsolePrint(ExtendedTextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
void IConsoleCmdExec(std::string_view command_string, const uint recurse_count)
Execute a given command passed to us.
static bool ConEcho(std::span< std::string_view > argv)
Simply print the arguments.
static bool ConRescanAI(std::span< std::string_view > argv)
Rescan the folder structure for new/changed AIs and libraries.
static void OutputContentState(const ContentInfo &ci)
Outputs content state information to console.
static bool ConListScenarios(std::span< std::string_view > argv)
List all the scenarios.
static bool ConReturn(std::span< std::string_view > argv)
End the execution of the current script.
static const std::initializer_list< std::pair< std::string_view, NetworkAuthorizedKeys * > > _console_cmd_authorized_keys
All the known authorized keys with their name.
ConNetworkAuthorizedKeyAction
Actions that can be performed on authorized keys from the console.
@ Remove
Remove an authorized key.
@ List
List all authorized keys.
@ Add
Add an authorized key.
static FontSize GetFontSizeByName(std::string_view name)
Get FontSize by name.
static std::string _scheduled_monthly_script
Script scheduled to execute by the 'schedule' console command (empty if no script is scheduled).
static bool ConScrollToTile(std::span< std::string_view > argv)
Scroll to a tile on the map.
static bool ConReload(std::span< std::string_view > argv)
Reload a game from the loaded savegame/scenario/heightmap.
static bool ConFont(std::span< std::string_view > argv)
Managing the font configuration.
static bool ConStatus(std::span< std::string_view > argv)
Get the status of connected clients.
static bool ConScreenShot(std::span< std::string_view > argv)
Make a screenshot.
static bool ConMoveClient(std::span< std::string_view > argv)
Move a client to a specific company.
static bool ConNetworkClients(std::span< std::string_view > argv)
List the clients.
bool PrintList(F list_function, Args... args)
Helper to print a list to the console.
static bool ConHelp(std::span< std::string_view > argv)
Show generic help and specific help for commands.
static bool ConSaveConfig(std::span< std::string_view > argv)
Explicitly save the configuration.
static std::optional< CompanyID > ParseCompanyID(std::string_view arg)
Helper to parse a company ID.
static bool ConBanList(std::span< std::string_view > argv)
Show the list of banned clients.
void ShowFramerateWindow()
Open the general framerate window.
static bool ConNewGRFReload(std::span< std::string_view > argv)
Reload all active NewGRFs.
static bool ConSayCompany(std::span< std::string_view > argv)
Say something to all clients in your company in a network game.
static bool ConResetEngines(std::span< std::string_view > argv)
Reset status of all engines.
static void ConDumpRailTypes()
List all rail types and their configuration.
static bool ConLoad(std::span< std::string_view > argv)
Load a savegame.
static bool ConEchoC(std::span< std::string_view > argv)
Print the arguments in a particular colour.
static bool ConAlias(std::span< std::string_view > argv)
Create an alias for a command.
static bool ConJoinCompany(std::span< std::string_view > argv)
As client, join a company.
static bool ConPrintWorkingDirectory(std::span< std::string_view > argv)
Print the current working directory.
static bool ConListAI(std::span< std::string_view > argv)
List all AI scripts.
static bool ConClearBuffer(std::span< std::string_view > argv)
Clear the console's buffer.
static std::optional< T > ParseType(std::string_view arg)
Parse an integer using ParseInteger and convert it to the requested type.
static bool ConListCommands(std::span< std::string_view > argv)
List all registered commands that are not hidden.
static bool ConResetCompany(std::span< std::string_view > argv)
Remove a company from the game.
static bool ConPauseGame(std::span< std::string_view > argv)
Manually pause the game.
static bool ConRestart(std::span< std::string_view > argv)
Restart the game.
static bool ConCompanies(std::span< std::string_view > argv)
List all companies.
static bool ConNewGRFProfile(std::span< std::string_view > argv)
Management of NewGRF profiling.
static bool ConListDirs(std::span< std::string_view > argv)
List the locations of all of the game's different sub directories.
static bool ConKick(std::span< std::string_view > argv)
Kick a user from a network game.
static bool ConResetEnginePool(std::span< std::string_view > argv)
Reset status of the engine pool.
static bool ConClientNickChange(std::span< std::string_view > argv)
Change the name of a client.
static bool ConNetworkAuthorizedKey(std::span< std::string_view > argv)
Management of authorized keys.
static bool ConUnpauseGame(std::span< std::string_view > argv)
Manually unpause the game.
static ConsoleHookResult ConHookServerOrNoNetwork(bool echo)
Check if are either in singleplayer or a server.
static bool ConListGameLibs(std::span< std::string_view > argv)
List all game script libraries.
static bool ConDumpInfo(std::span< std::string_view > argv)
Dump information about some NewGRF types.
static bool ConFramerate(std::span< std::string_view > argv)
Show the current framerate statistics.
static bool ConListGame(std::span< std::string_view > argv)
List all game scripts.
static ConsoleFileList _console_file_list_scenario
File storage cache for scenarios.
static ConsoleFileList _console_file_list_heightmap
File storage cache for heightmaps.
static bool ConDebugLevel(std::span< std::string_view > argv)
Change the debug levels of the game.
static ConsoleHookResult ConHookServerOnly(bool echo)
Check whether we are a server.
static bool ConListSettings(std::span< std::string_view > argv)
List all settings.
static const IntervalTimer< TimerGameCalendar > _scheduled_monthly_timer
Timer that runs every month of game time for the 'schedule' console command.
static bool ConLoadScenario(std::span< std::string_view > argv)
Load a scenario.
static bool ConSayClient(std::span< std::string_view > argv)
Say something to a specific client in a network game.
static bool ConGetDate(std::span< std::string_view > argv)
Get the current game date.
static bool ConLoadHeightmap(std::span< std::string_view > argv)
Load a heightmap.
static bool ConGamelogPrint(std::span< std::string_view > argv)
Print the gamelog.
static bool ConInfoCmd(std::span< std::string_view > argv)
Get debug information about a command.
static bool ConListAliases(std::span< std::string_view > argv)
List all registered aliases.
static bool ConPart(std::span< std::string_view > argv)
Part the game, i.e.
static bool ConSave(std::span< std::string_view > argv)
Save the map to a file.
static bool ConRemove(std::span< std::string_view > argv)
Remove a savegame file from disk.
static bool ConNetworkReconnect(std::span< std::string_view > argv)
Connect to the last client you were connected to.
static bool ConBan(std::span< std::string_view > argv)
Ban a user from a network game.
void ConPrintFramerate()
Print performance statistics to game console.
void IConsoleStdLibRegister()
Console command registration.
static ConsoleHookResult ConHookNeedNetwork(bool echo)
Check whether we are in a multiplayer game.
static ConsoleHookResult ConHookClientOnly(bool echo)
Check whether we are a client in a network game.
static bool ConListHeightmaps(std::span< std::string_view > argv)
List all the heightmaps.
static bool ConStartAI(std::span< std::string_view > argv)
Start a new AI.
static bool ConStopAI(std::span< std::string_view > argv)
Stop a currently running AI.
static ConsoleHookResult ConHookNewGRFDeveloperTool(bool echo)
Check whether NewGRF developer tools are enabled.
static bool ConZoomToLevel(std::span< std::string_view > argv)
Zoom map to given level.
static ContentType StringToContentType(std::string_view str)
Resolve a string to a content type.
static bool ConRescanNewGRF(std::span< std::string_view > argv)
Rescan the folder structure for new/changed NewGRFs.
static void ConDumpRoadTypes()
List all road types and their configuration.
static bool ConExec(std::span< std::string_view > argv)
Run a local script file.
static bool ConServerInfo(std::span< std::string_view > argv)
Get information like client/company count/limits for the server.
static bool ConSchedule(std::span< std::string_view > argv)
Schedule the execution of a script.
static void ConDumpCargoTypes()
List all cargo types and their configuration.
static bool ConScript(std::span< std::string_view > argv)
Enable or disable logging of console output.
static bool ConGetSysDate(std::span< std::string_view > argv)
Get the current system date.
static bool ConSay(std::span< std::string_view > argv)
Say something to all clients in a network game.
static uint _script_current_depth
Depth of scripts running (used to abort execution when ConReturn is encountered).
static bool ConExit(std::span< std::string_view > argv)
Exit the game, i.e.
static bool ConChangeDirectory(std::span< std::string_view > argv)
Change the dir via console.
static bool ConListAILibs(std::span< std::string_view > argv)
List all AI libraries.
static bool ConKickOrBan(std::string_view arg, bool ban, std::string_view reason)
Helper to kick or ban a user.
static bool ConSettingNewgame(std::span< std::string_view > argv)
Change settings of for a new game.
static bool NetworkAvailable(bool echo)
Check network availability and inform in console about failure of detection.
static bool ConRescanGame(std::span< std::string_view > argv)
Rescan the folder structure for new/changed game scripts and libraries.
static ConsoleHookResult ConHookNeedNonDedicatedNetwork(bool echo)
Check whether we are in a multiplayer game and are playing, i.e.
static bool ConRcon(std::span< std::string_view > argv)
Run a console command on the server.
static bool ConListFiles(std::span< std::string_view > argv)
List all the files in the current dir via console.
static bool ConGetSeed(std::span< std::string_view > argv)
Get the seed that was used to create this game.
static bool ConContent(std::span< std::string_view > argv)
Downloading of content from the server.
static ConsoleFileList _console_file_list_savegame
File storage cache for savegames.
static bool ConReloadAI(std::span< std::string_view > argv)
Reload/restart an AI.
static bool ConNetworkConnect(std::span< std::string_view > argv)
Connect to a specific server.
static bool ConFramerateWindow(std::span< std::string_view > argv)
Show the framerate statistics window.
static bool ConSetting(std::span< std::string_view > argv)
Change settings of the current game.
static ConsoleHookResult ConHookNoNetwork(bool echo)
Check whether we are in singleplayer mode.
static void PrintLineByLine(const std::string &full_string)
Print a text buffer line by line to the console.
static bool ConNewGame(std::span< std::string_view > argv)
Start/create a new game.
static bool ConUnBan(std::span< std::string_view > argv)
Unban a user from a network game.
Console functions used outside of the console code.
void IConsoleClose()
Close the in-game console.
Internally used functions for the console.
ConsoleHookResult
Return values of console hooks (IConsoleHook).
@ Disallow
Disallow command execution.
@ Allow
Allow command execution.
@ Hide
Hide the existence of the command.
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
static const TextColour CC_HELP
Colour for help lines.
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
static const TextColour CC_INFO
Colour for information lines.
static const TextColour CC_COMMAND
Colour for the console's commands.
static const TextColour CC_WARNING
Colour for warning lines.
static const TextColour CC_DEBUG
Colour for debug output.
static const TextColour CC_DEFAULT
Default colour of the console.
static const TextColour CC_ERROR
Colour for error lines.
void SetDebugString(std::string_view s, SetDebugStringErrorFunc error_func)
Set debugging levels by parsing the text in s.
std::string GetDebugString()
Print out the current debug-level.
Functions related to debugging.
void StartupEngines()
Start/initialise all our engines.
Functions related to engines.
#define T
Climate temperate.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
bool FioRemove(const std::string &filename)
Remove a file.
std::optional< FileHandle > FioFOpenFile(std::string_view filename, std::string_view mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
bool FileExists(std::string_view filename)
Test whether the given filename exists.
bool FioCheckFileExists(std::string_view filename, Subdirectory subdir)
Check whether the given file exists.
Functions for standard in/out file operations.
@ Save
File is being saved.
@ Load
File is being loaded.
@ FiosDrive
A drive (letter) entry.
@ GameFile
Save game or scenario file.
@ FiosDirectory
A directory entry.
@ FiosParent
A parent directory entry.
Searchpath
Types of searchpaths OpenTTD might use.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
@ Base
Base directory for all subdirectories.
@ Autosave
Subdirectory of save for autosaves.
@ NewGrf
Subdirectory for all NewGRFs.
@ Screenshot
Subdirectory for all screenshots.
@ GsLibrary
Subdirectory for all GS libraries.
@ Scenario
Base directory for all scenarios.
@ Heightmap
Subdirectory of scenario for heightmaps.
@ Ai
Subdirectory for all AI files.
@ SocialIntegration
Subdirectory for all social integration plugins.
@ Gs
Subdirectory for all game scripts.
@ Baseset
Subdirectory for all base data (base sets, intro game).
@ Save
Base directory for all savegames.
@ AiLibrary
Subdirectory for all AI libraries.
AbstractFileType
The different abstract types of files that the system knows about.
@ Savegame
old or new savegame
@ Invalid
Invalid or unknown file type.
@ Scenario
old or new scenario
@ Heightmap
heightmap file
std::string FiosGetCurrentPath()
Get the current path/working directory.
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at _fios_path.
Declarations for savegames operations.
Functions to read fonts from files and cache them.
FontCacheSubSetting * GetFontCacheSubSetting(FontSize fs)
Get the settings of a given font size.
Base functions for all Games.
Gamelog _gamelog
Gamelog instance.
Functions to be called to log fundamental changes to the game.
Functions related to world/map generation.
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
void StartNewGameWithoutGUI(uint32_t seed)
Start a normal game without the GUI.
PauseModes _pause_mode
The current pause mode.
SwitchMode _switch_mode
The next mainloop command.
FontSize
Available font sizes.
@ End
Marker for the end of the enumerations.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ Begin
Marker for the begin of the range.
@ LightBlue
Light blue colour.
@ End
Marker for the end of the range.
Functions related to OTTD's landscape.
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Miscellaneous command definitions.
ClientID _redirect_console_to_client
If not invalid, redirect the console output to a client.
uint8_t NetworkSpectatorCount()
Get the number of clients that are playing as a spectator.
bool _network_available
is network mode available?
bool _networking
are we in networking mode?
StringList _network_ban_list
The banned clients.
bool _network_dedicated
are we a dedicated server?
bool _network_server
network-server is active
bool NetworkClientConnectGame(std::string_view connection_string, CompanyID default_company, const std::string &join_server_password)
Join a client to the server at with the given connection string.
ClientID _network_own_client_id
Our client identifier.
Basic functions/variables used all over the place.
AdminID _redirect_console_to_admin
Redirection of the (remote) console to the admin.
Server part of the admin network protocol.
Base core network types and some helper functions to access them.
void NetworkClientSendChat(NetworkAction action, NetworkChatDestinationType type, int dest, std::string_view msg, int64_t data)
Send a chat message.
void NetworkClientSendRcon(std::string_view password, std::string_view command)
Send a remote console command.
void NetworkClientRequestMove(CompanyID company_id)
Notify the server of this client wanting to be moved to another company.
bool NetworkIsValidClientName(std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
Client part of the network protocol.
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
Part of the network protocol handling content distribution.
std::string _network_server_invite_code
Our invite code as indicated by the Game Coordinator.
Network functions used by other parts of OpenTTD.
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name)
Change the client name of the given client.
void NetworkPrintClients()
Print all the clients to the console.
void NetworkServerSendChat(NetworkAction action, NetworkChatDestinationType type, int dest, std::string_view msg, ClientID from_id, int64_t data=0, bool from_admin=false)
Send an actual chat message.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
void NetworkServerKickClient(ClientID client_id, std::string_view reason)
Kick a single client.
std::string_view NetworkGetPublicKeyOfClient(ClientID client_id)
Get the public key of the client with the given id.
void NetworkServerShowStatusToConsole()
Show the status message of all clients on the console.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, std::string_view reason)
Ban, or kick, everyone joined from the given client's IP.
NetworkServerGameInfo _network_game_info
Information about our game.
Convert NetworkGameInfo to Packet and back.
@ ChatTeam
A chat sent to all clients of a team/company.
@ ChatClient
A chat sent to a specific client.
@ ChatBroadcast
A chat broadcast to all clients.
@ Client
Send message/notice to only a certain client (Private).
@ Team
Send message/notice to everyone playing the same company (Team).
@ Broadcast
Send message/notice to all clients (All).
ClientID
'Unique' identifier to be given to clients
@ Invalid
Client is not part of anything.
@ Server
Servers always have this ID.
Base for the NewGRF implementation.
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Profiling of NewGRF action 2 handling.
Label< struct GrfIDTag > GrfID
The unique identifier of a NewGRF.
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
@ Error
A game paused because a (critical) error.
@ Normal
A game normally paused.
@ LoadGame
Load game, Play Scenario.
@ StartHeightmap
Load a heightmap and start a new game from it.
@ ReloadGame
Reload the savegame / scenario / heightmap you started the game with.
@ Menu
Switch to game intro menu.
@ RestartGame
Restart --> 'Random game' with current settings.
@ Ground
Main group of ground images.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
@ Catenary
Bit number for drawing a catenary.
@ Allow90Deg
Bit number for always allowed 90 degree turns, regardless of setting.
@ Disallow90Deg
Bit number for never allowed 90 degree turns, regardless of setting.
@ Hidden
Bit number for hiding from selection.
@ NoSpriteCombine
Bit number for using non-combined junctions.
@ NoLevelCrossing
Bit number for disallowing level crossings.
RailType
Enumeration for all possible railtypes.
@ RAILTYPE_END
Used for iterations.
@ Catenary
Bit number for adding catenary.
@ NoHouses
Bit number for setting this roadtype as not house friendly.
@ Hidden
Bit number for hidden from construction.
@ NoLevelCrossing
Bit number for disabling level crossing.
@ TownBuild
Bit number for allowing towns to build this roadtype.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
@ Ground
Required: Main group of ground images.
RoadType
The different roadtypes we support.
@ ROADTYPE_END
Used for iterations.
A number of safeguards to prevent using unsafe methods.
SaveLoadResult SaveOrLoad(std::string_view filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
Main Save or Load function where the high-level saveload functions are handled.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit).
Functions related to saving and loading games.
@ Ok
completed successfully
bool MakeScreenshot(ScreenshotType t, const std::string &name, uint32_t width, uint32_t height)
Schedule making a screenshot.
Functions to make screenshots.
ScreenshotType
Type of requested screenshot.
@ SC_VIEWPORT
Screenshot of viewport.
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
@ SC_HEIGHTMAP
Heightmap of the world.
@ SC_WORLD
World screenshot.
@ SC_MINIMAP
Minimap screenshot.
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
void IConsoleGetSetting(std::string_view name, bool force_newgame)
Output value of a specific setting to the console.
void SaveToConfig()
Save the values to the configuration file.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void IConsoleListSettings(std::string_view prefilter)
List all settings and their value to the console.
ClientSettings _settings_client
The current settings for this game.
Functions related to setting/changing the settings.
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
bool StrEqualsIgnoreCase(std::string_view str1, std::string_view str2)
Compares two string( view)s for equality, while ignoring the case of the characters.
bool StrStartsWithIgnoreCase(std::string_view str, std::string_view prefix)
Check whether the given string starts with the given prefix, ignoring case.
bool StrContainsIgnoreCase(std::string_view str, std::string_view value)
Checks if a string is contained in another string, while ignoring the case of the characters.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
Functions related to low-level strings.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Functions related to OTTD's strings.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
constexpr bool Empty() const
Check whether the label is empty.
std::string AsString() const
Get the label as a std::string.
Specification of a cargo type.
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
NetworkAuthorizedKeys allow_list
Public keys of clients that are allowed to join this company.
static bool IsHumanID(auto index)
Is this company a company not controlled by a NoAI program?
void OnConnect(bool success) override
Callback for when the connection has finished.
void OnDownloadComplete(ContentID cid) override
We have finished downloading a file.
void OnDisconnect() override
Callback for when the connection got disconnected.
Callbacks for notifying others about incoming data.
Container for all important information about a piece of content.
uint32_t unique_id
Unique ID; either GRF ID or shortname.
MD5Hash md5sum
The MD5 checksum.
State state
Whether the content info is selected (for download).
std::string name
Name of the content.
ContentID id
Unique (server side) ID for the content.
ContentType type
Type of content.
@ Selected
The content has been manually selected.
@ Autoselected
The content has been selected as dependency.
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Deals with finding savegames.
DetailedFileType detailed
Detailed file type.
AbstractFileType abstract
Abstract file type.
Settings for a single font.
std::string font
The name of the font, or path to the font.
uint size
The (requested) size of the font.
Dynamic data of a loaded NewGRF.
–Aliases– Aliases are like shortcuts for complex functions, variable assignments, etc.
std::string cmdline
command(s) that is/are being aliased
std::string name
name of the alias
–Commands– Commands are commands, or functions.
IConsoleCmdProc * proc
process executed when command is typed
IConsoleHook * hook
any special trigger action that needs executing
std::string name
name of command
static void AliasRegister(const std::string &name, std::string_view cmd)
Register a an alias for an already existing command in the console.
static IConsoleAlias * AliasGet(const std::string &name)
Find the alias pointed to by its string.
static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook=nullptr)
Register a new command to be used in the console.
static IConsoleCmd * CmdGet(const std::string &name)
Find the command pointed to by its string.
static uint SizeX()
Get the size of the map along the X.
static uint SizeY()
Get the size of the map along the Y.
static uint LogX()
Logarithm of the map size along the X side.
static uint LogY()
Logarithm of the map size along the y side.
static uint Size()
Get the size of the map.
Container for all information known about a client.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
bool CanJoinCompany(CompanyID company_id) const
Returns whether the given company can be joined by this client.
CompanyID client_playas
As which company is this client playing (CompanyID).
ClientID client_id
Client identifier (same as ClientState->client_id).
Callback profiler for NewGRF development.
static void StartTimer(uint64_t ticks)
Start the timeout timer that will finish all profiling sessions.
const GRFFile * grffile
Which GRF is being profiled.
static void AbortTimer()
Abort the timeout timer, so the timer callback is never called.
static Pool::IterateWrapper< Company > Iterate(size_t from=0)
static size_t GetNumItems()
static bool IsValidID(auto index)
static Company * GetIfValid(auto index)
static constexpr size_t MAX_SIZE
Data structure for viewport, display of a part of the world.
ZoomLevel zoom
The zoom level of the viewport.
Data structure for an opened window.
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
uint32_t ContentID
Unique identifier for the content.
ContentType
The values in the enum are important; they are received over the network from the content servers.
@ Scenario
The content consists of a scenario.
@ Heightmap
The content consists of a heightmap.
@ BaseGraphics
The content consists of base graphics.
@ Ai
The content consists of an AI.
@ End
Helper to mark the end of the types.
@ NewGRF
The content consists of a NewGRF.
@ AiLibrary
The content consists of an AI library.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition of Interval and OneShot timers.
@ Aircraft
Aircraft vehicle type.
@ Train
Train vehicle type.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
@ ZOOM_IN
Zoom in (get more detailed view).
@ ZOOM_OUT
Zoom out (get helicopter view).
Window * GetMainWindow()
Get the main window, i.e.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Window functions not directly related to making/drawing windows.
ZoomLevel
All zoom levels we know.
@ Begin
Begin for iteration.