Add abuse mode to mode plugin.

develop
Petr Mrázek 2012-02-22 22:46:12 +01:00
parent 58e3813d56
commit 252176d064
1 changed files with 77 additions and 49 deletions

@ -69,6 +69,9 @@ void printCurrentModes(t_gamemodes gm, Console & con)
case GAMETYPE_NONE:
con << "NONE)" << endl;
break;
default:
con << "!!UNKNOWN!!)" << endl;
break;
}
con << "Current game mode:\t" << gm.g_mode << " (";
switch (gm.g_mode)
@ -85,6 +88,9 @@ void printCurrentModes(t_gamemodes gm, Console & con)
case GAMEMODE_NONE:
con << "NONE)" << endl;
break;
default:
con << "!!UNKNOWN!!)" << endl;
break;
}
}
@ -92,13 +98,18 @@ command_result mode (Core * c, vector <string> & parameters)
{
string command = "";
bool set = false;
bool abuse = false;
t_gamemodes gm;
if(parameters.size())
for(auto iter = parameters.begin(); iter != parameters.end(); iter++)
{
if(parameters[0] == "set")
if((*iter) == "set")
{
set = true;
}
else if((*iter) == "abuse")
{
set = abuse = true;
}
else
return CR_WRONG_USAGE;
}
@ -110,7 +121,9 @@ command_result mode (Core * c, vector <string> & parameters)
printCurrentModes(gm, c->con);
if(set)
{
if( gm.g_mode == GAMEMODE_NONE || gm.g_type == GAMETYPE_VIEW_LEGENDS )
if(!abuse)
{
if( gm.g_mode == GAMEMODE_NONE || gm.g_type == GAMETYPE_VIEW_LEGENDS)
{
c->con.printerr("It is not safe to set modes in menus.\n");
return CR_FAILURE;
@ -138,7 +151,6 @@ command_result mode (Core * c, vector <string> & parameters)
c->con.printerr("This is not a valid selection.\n");
goto input_again;
}
switch(select)
{
case 0:
@ -162,6 +174,22 @@ command_result mode (Core * c, vector <string> & parameters)
gm.g_type = GAMETYPE_DWARF_RECLAIM;
break;
}
}
else
{
CommandHistory hist;
string selected;
c->con.lineedit("Enter new game mode number (c for exit): ",selected, hist);
if(selected == "c")
return CR_OK;
const char * start = selected.c_str();
gm.g_mode = (GameMode) strtol(start, 0, 10);
c->con.lineedit("Enter new game type number (c for exit): ",selected, hist);
if(selected == "c")
return CR_OK;
start = selected.c_str();
gm.g_type = (GameType) strtol(start, 0, 10);
}
c->Suspend();
world->WriteGameMode(gm);
c->Resume();