Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions rts/Lua/LuaSyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "LuaHashString.h"
#include "LuaMetalMap.h"
#include "LuaSyncedMoveCtrl.h"
#include "LuaUI.h"
#include "LuaUtils.h"
#include "Game/Game.h"
#include "Game/GameSetup.h"
Expand Down Expand Up @@ -141,6 +142,8 @@ bool LuaSyncedCtrl::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(AssignPlayerToTeam);
REGISTER_LUA_CFUNC(GameOver);
REGISTER_LUA_CFUNC(SetGlobalLos);
REGISTER_LUA_CFUNC(SetCheatingEnabled);
REGISTER_LUA_CFUNC(SetGodMode);

REGISTER_LUA_CFUNC(SetPlayerReadyState);
REGISTER_LUA_CFUNC(SetTeamStartPosition);
Expand Down Expand Up @@ -1024,6 +1027,40 @@ int LuaSyncedCtrl::SetGlobalLos(lua_State* L)
return 0;
}

/*** Changes whether activating cheats is allowed.
* Note that already activated cheats (e.g. god mode) stay active even if you disallow activating.
*
* @function Spring.SetCheatingEnabled
* @param cheatsEnabled boolean
* @return nil
*/
int LuaSyncedCtrl::SetCheatingEnabled(lua_State* L)
{
gs->cheatEnabled = luaL_checkboolean(L, 1);
return 0;
}

/*** Toggles 'god mode', i.e. whether control of teams other than one's own is allowed.
* Affects all teams.
*
* @function Spring.SetGodMode
* @param controlAllies boolean?
* @param controlEnemies boolean?
* @return nil
*/
int LuaSyncedCtrl::SetGodMode(lua_State* L)
{
const bool controlAllies = luaL_optboolean(L, 1, (gs->godMode & GODMODE_ATC_BIT) != 0);
const bool controlEnemies = luaL_optboolean(L, 2, (gs->godMode & GODMODE_ETC_BIT) != 0);

gs->godMode = controlAllies * GODMODE_ATC_BIT
+ controlEnemies * GODMODE_ETC_BIT;

CLuaUI::UpdateTeams();
CPlayer::UpdateControlledTeams();

return 0;
}

/***
* Game End
Expand Down
3 changes: 3 additions & 0 deletions rts/Lua/LuaSyncedCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class LuaSyncedCtrl
static int AssignPlayerToTeam(lua_State* L);
static int GameOver(lua_State* L);
static int SetGlobalLos(lua_State* L);
static int SetCheatingEnabled(lua_State* L);
static int SetGodMode(lua_State* L);

static int SetTeamStartPosition(lua_State* L);
static int SetPlayerReadyState(lua_State* L);

Expand Down