Skip to content

Commit

Permalink
Add newheightmapgame command
Browse files Browse the repository at this point in the history
  • Loading branch information
Berbe committed Feb 26, 2019
1 parent 7ac17f5 commit 9924659
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/console_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,52 @@ DEF_CONSOLE_CMD(ConNewGame)
return true;
}

DEF_CONSOLE_CMD(ConNewHeightMapGame)
{
bool answer = true;

This comment has been minimized.

Copy link
@planetmaker

planetmaker Feb 26, 2019

probably not the most descriptive variable name. Maybe like 'heightmap_loaded'


if (argc == 0) {
IConsoleHelp("Load a game by name or index. Usage: 'newheightmapgame [<file | number> [seed]]'");
IConsoleHelp("The server can force a new game using 'newheightmapgame'; any client joined will rejoin after the server is done generating the new game.");
}

if (argc >=1 && argc <= 3) {
const char *file = NULL;

if (argc == 1) {
file = _file_to_saveload.title;
}

if (argc >= 2) {
file = argv[1];
}

// _console_file_list.ValidateFileList();

This comment has been minimized.

Copy link
@planetmaker

planetmaker Feb 26, 2019

This commented-out line should not be here. Or should it not be commented out?

_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.SetName(FiosBrowseTo(item));
_file_to_saveload.SetTitle(item->title);

StartNewHeightMapGameWithoutGUI((argc == 3) ? strtoul(argv[2], NULL, 10) : GENERATE_NEW_SEED);
} else {
IConsolePrintF(CC_ERROR, "%s: Not a heightmap.", file);
}
} else {
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
}

_console_file_list.InvalidateFileList();
}

if (argc > 3) answer = false;

return answer;
}

DEF_CONSOLE_CMD(ConRestart)
{
if (argc == 0) {
Expand Down Expand Up @@ -1943,6 +1989,7 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("list_cmds", ConListCommands);
IConsoleCmdRegister("list_aliases", ConListAliases);
IConsoleCmdRegister("newgame", ConNewGame);
IConsoleCmdRegister("newheightmapgame", ConNewHeightMapGame);
IConsoleCmdRegister("restart", ConRestart);
IConsoleCmdRegister("getseed", ConGetSeed);
IConsoleCmdRegister("getdate", ConGetDate);
Expand Down
1 change: 1 addition & 0 deletions src/genworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void IncreaseGeneratingWorldProgress(GenWorldProgress cls);
void PrepareGenerateWorldProgress();
void ShowGenerateWorldProgress();
void StartNewGameWithoutGUI(uint32 seed);
void StartNewHeightMapGameWithoutGUI(uint32 seed);
void ShowCreateScenario();
void StartScenarioEditor();

Expand Down
18 changes: 18 additions & 0 deletions src/genworld_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,24 @@ void StartNewGameWithoutGUI(uint32 seed)
StartGeneratingLandscape(GLWM_GENERATE);
}

/**
* Start a normal game from a heightmap file without the GUI.
* @param seed The seed of the new game.
*/
void StartNewHeightMapGameWithoutGUI(uint32 seed)
{
/* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
_settings_newgame.game_creation.generation_seed = seed;

uint x = 0;
uint y = 0;

/* If the function returns negative, it means there was a problem loading the heightmap */

This comment has been minimized.

Copy link
@planetmaker

planetmaker Feb 26, 2019

Comment mis-match with code. You query not for <0, but for != 0

if (!GetHeightmapDimensions(_file_to_saveload.detail_ftype, _file_to_saveload.name, &x, &y)) return;

StartGeneratingLandscape(GLWM_HEIGHTMAP);
}

struct CreateScenarioWindow : public Window
{
uint widget_id;
Expand Down

0 comments on commit 9924659

Please sign in to comment.