Changeset - r25620:86e7c867add2
[Not reviewed]
master
0 1 0
Patric Stout - 3 years ago 2021-06-10 18:11:50
truebrain@openttd.org
Change: allow pause/unpause console command in single player too (#9342)
1 file changed with 27 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -157,17 +157,30 @@ DEF_CONSOLE_HOOK(ConHookNoNetwork)
 
		if (echo) IConsoleError("This command is forbidden in multiplayer.");
 
		return CHR_DISALLOW;
 
	}
 
	return CHR_ALLOW;
 
}
 

	
 
/**
 
 * Check if are either in singleplayer or a server.
 
 * @return True iff we are either in singleplayer or a server.
 
 */
 
DEF_CONSOLE_HOOK(ConHookServerOrNoNetwork)
 
{
 
	if (_networking && !_network_server) {
 
		if (echo) IConsoleError("This command is only available to a network server.");
 
		return CHR_DISALLOW;
 
	}
 
	return CHR_ALLOW;
 
}
 

	
 
DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
 
{
 
	if (_settings_client.gui.newgrf_developer_tools) {
 
		if (_game_mode == GM_MENU) {
 
			if (echo) IConsoleError("This command is only available in game and editor.");
 
			if (echo) IConsoleError("This command is only available in-game and in the editor.");
 
			return CHR_DISALLOW;
 
		}
 
		return ConHookNoNetwork(echo);
 
	}
 
	return CHR_HIDE;
 
}
 
@@ -206,13 +219,13 @@ DEF_CONSOLE_CMD(ConResetEnginePool)
 
	if (argc == 0) {
 
		IConsoleHelp("Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
 
		return true;
 
	}
 

	
 
	if (_game_mode == GM_MENU) {
 
		IConsoleError("This command is only available in game and editor.");
 
		IConsoleError("This command is only available in-game and in the editor.");
 
		return true;
 
	}
 

	
 
	if (!EngineOverrideManager::ResetToCurrentNewGRFConfig()) {
 
		IConsoleError("This can only be done when there are no vehicles in the game.");
 
		return true;
 
@@ -619,12 +632,17 @@ DEF_CONSOLE_CMD(ConPauseGame)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("Pause a network game. Usage: 'pause'");
 
		return true;
 
	}
 

	
 
	if (_game_mode == GM_MENU) {
 
		IConsoleError("This command is only available in-game and in the editor.");
 
		return true;
 
	}
 

	
 
	if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) {
 
		DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
 
		if (!_networking) IConsolePrint(CC_DEFAULT, "Game paused.");
 
	} else {
 
		IConsolePrint(CC_DEFAULT, "Game is already paused.");
 
	}
 
@@ -636,12 +654,17 @@ DEF_CONSOLE_CMD(ConUnpauseGame)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("Unpause a network game. Usage: 'unpause'");
 
		return true;
 
	}
 

	
 
	if (_game_mode == GM_MENU) {
 
		IConsoleError("This command is only available in-game and in the editor.");
 
		return true;
 
	}
 

	
 
	if ((_pause_mode & PM_PAUSED_NORMAL) != PM_UNPAUSED) {
 
		DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE);
 
		if (!_networking) IConsolePrint(CC_DEFAULT, "Game unpaused.");
 
	} else if ((_pause_mode & PM_PAUSED_ERROR) != PM_UNPAUSED) {
 
		IConsolePrint(CC_DEFAULT, "Game is in error state and cannot be unpaused via console.");
 
	} else if (_pause_mode != PM_UNPAUSED) {
 
@@ -2390,14 +2413,14 @@ void IConsoleStdLibRegister()
 
	IConsole::CmdRegister("client_name",             ConClientNickChange, ConHookServerOnly);
 
	IConsole::CmdRegister("kick",                    ConKick,             ConHookServerOnly);
 
	IConsole::CmdRegister("ban",                     ConBan,              ConHookServerOnly);
 
	IConsole::CmdRegister("unban",                   ConUnBan,            ConHookServerOnly);
 
	IConsole::CmdRegister("banlist",                 ConBanList,          ConHookServerOnly);
 

	
 
	IConsole::CmdRegister("pause",                   ConPauseGame,        ConHookServerOnly);
 
	IConsole::CmdRegister("unpause",                 ConUnpauseGame,      ConHookServerOnly);
 
	IConsole::CmdRegister("pause",                   ConPauseGame,        ConHookServerOrNoNetwork);
 
	IConsole::CmdRegister("unpause",                 ConUnpauseGame,      ConHookServerOrNoNetwork);
 

	
 
	IConsole::CmdRegister("company_pw",              ConCompanyPassword,  ConHookNeedNetwork);
 
	IConsole::AliasRegister("company_password",      "company_pw %+");
 

	
 
	IConsole::AliasRegister("net_frame_freq",        "setting frame_freq %+");
 
	IConsole::AliasRegister("net_sync_freq",         "setting sync_freq %+");
0 comments (0 inline, 0 general)