mirror of https://github.com/OpenTTD/OpenTTD
Add: Console command
parent
940f480fb0
commit
df2c809d1c
|
@ -1129,6 +1129,52 @@ DEF_CONSOLE_CMD(ConNewGame)
|
|||
return true;
|
||||
}
|
||||
|
||||
DEF_CONSOLE_CMD(ConNewHeightMapGame)
|
||||
{
|
||||
if (argc == 0) {
|
||||
IConsolePrint(CC_HELP, "Load a game by name or index. Usage: 'newheightmapgame [<file | number> [seed]]'");
|
||||
IConsolePrint(CC_HELP, "The server can force a new game using 'newheightmapgame'; any client joined will rejoin after the server is done generating the new game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (argc > 3) return false;
|
||||
|
||||
bool heightmap_loaded = true;
|
||||
std::string_view file;
|
||||
|
||||
if (argc == 1) {
|
||||
file = _file_to_saveload.title;
|
||||
}
|
||||
|
||||
if (argc >= 2) {
|
||||
file = argv[1];
|
||||
}
|
||||
|
||||
/* ConLoad command actually uses
|
||||
_console_file_list.ValidateFileList()
|
||||
here, but for this procedure build a file list for mere savegames, instead of merely validating */
|
||||
_console_file_list.BuildFileList(FT_HEIGHTMAP, SLO_LOAD);
|
||||
const FiosItem *item = _console_file_list.FindItem(file);
|
||||
if (item != NULL) {
|
||||
if (GetAbstractFileType(item->type) == FT_HEIGHTMAP) {
|
||||
_switch_mode = SM_LOAD_HEIGHTMAP;
|
||||
_file_to_saveload.SetMode(item->type);
|
||||
_file_to_saveload.name = FiosBrowseTo(item);
|
||||
_file_to_saveload.title = item->title;
|
||||
|
||||
StartNewGameWithoutGUI((argc == 3) ? strtoul(argv[2], NULL, 10) : GENERATE_NEW_SEED);
|
||||
} else {
|
||||
IConsolePrint(CC_ERROR, "{}: Not a heightmap.", file);
|
||||
}
|
||||
} else {
|
||||
IConsolePrint(CC_ERROR, "{}: No such file or directory.", file);
|
||||
}
|
||||
|
||||
_console_file_list.InvalidateFileList();
|
||||
|
||||
return heightmap_loaded;
|
||||
}
|
||||
|
||||
DEF_CONSOLE_CMD(ConRestart)
|
||||
{
|
||||
if (argc == 0) {
|
||||
|
@ -2518,6 +2564,7 @@ void IConsoleStdLibRegister()
|
|||
IConsole::CmdRegister("list_cmds", ConListCommands);
|
||||
IConsole::CmdRegister("list_aliases", ConListAliases);
|
||||
IConsole::CmdRegister("newgame", ConNewGame);
|
||||
IConsole::CmdRegister("newheightmapgame", ConNewHeightMapGame);
|
||||
IConsole::CmdRegister("restart", ConRestart);
|
||||
IConsole::CmdRegister("reload", ConReload);
|
||||
IConsole::CmdRegister("getseed", ConGetSeed);
|
||||
|
|
Loading…
Reference in New Issue