Special case player number 1/2 in ApplyGameCommand

This function, oddly, used to take a 1 or 2 for the player number where
other nearby functions (e.g. IsPlayerEnabled) would take the proper enum
value, 0 or 1.  If the old-style syntax (raw number) is used, also use
the old-style interpretation.
This commit is contained in:
Devin J. Pohly
2014-02-23 16:41:19 -05:00
parent 10d872db3f
commit bb1b6a81c6
+10 -1
View File
@@ -2223,8 +2223,17 @@ public:
static int ApplyGameCommand( T* p, lua_State *L )
{
PlayerNumber pn = PLAYER_INVALID;
if( lua_gettop(L) >= 2 && !lua_isnil(L,2) )
if( lua_gettop(L) >= 2 && !lua_isnil(L,2) ) {
// Legacy behavior: if an old-style numerical argument
// is given, decrement it before trying to parse
if( lua_isnumber(L,2) ) {
int arg = (int) lua_tonumber( L, 2 );
arg--;
LuaHelpers::Push( L, arg );
lua_replace( L, -2 );
}
pn = Enum::Check<PlayerNumber>(L, 2);
}
p->ApplyGameCommand(SArg(1),pn);
return 0;
}