Skip to content

Commit

Permalink
Restore get/setObjectMass functions (#589)
Browse files Browse the repository at this point in the history
Partially reverts a9e4896
  • Loading branch information
samr46 authored and qaisjp committed Sep 25, 2018
1 parent b6c4d0e commit bc62ae1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp
Expand Up @@ -21,6 +21,7 @@ void CLuaObjectDefs::LoadFunctions(void)
{"isObjectStatic", IsObjectStatic},
{"getObjectScale", GetObjectScale},
{"isObjectBreakable", IsObjectBreakable},
{"getObjectMass", GetObjectMass},
{"getObjectProperty", GetObjectProperty},

// Object set funcs
Expand All @@ -32,6 +33,7 @@ void CLuaObjectDefs::LoadFunctions(void)
{"breakObject", BreakObject},
{"respawnObject", RespawnObject},
{"toggleObjectRespawn", ToggleObjectRespawn},
{"setObjectMass", SetObjectMass},
{"setObjectProperty", SetObjectProperty},
};

Expand All @@ -55,15 +57,18 @@ void CLuaObjectDefs::AddClass(lua_State* luaVM)

lua_classfunction(luaVM, "getScale", "getObjectScale");
lua_classfunction(luaVM, "isBreakable", "isObjectBreakable");
lua_classfunction(luaVM, "getMass", "getObjectMass");
lua_classfunction(luaVM, "getProperties", GetObjectProperties);
lua_classfunction(luaVM, "getProperty", "getObjectProperty");

lua_classfunction(luaVM, "setScale", "setObjectScale");
lua_classfunction(luaVM, "setBreakable", "setObjectBreakable");
lua_classfunction(luaVM, "setMass", "setObjectMass");
lua_classfunction(luaVM, "setProperty", "setObjectProperty");

lua_classvariable(luaVM, "scale", "setObjectScale", "getObjectScale");
lua_classvariable(luaVM, "breakable", "setObjectBreakable", "isObjectBreakable");
lua_classvariable(luaVM, "mass", "setObjectMass", "getObjectMass");
lua_classvariable(luaVM, "properties", nullptr, GetObjectProperties);

// Add deprecated methods for backwards compatibility
Expand Down Expand Up @@ -206,6 +211,29 @@ int CLuaObjectDefs::IsObjectBreakable(lua_State* luaVM)
return 1;
}

int CLuaObjectDefs::GetObjectMass(lua_State* luaVM)
{
// float getObjectMass ( object theObject )
CClientObject* pObject;
float fMass;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pObject);
if (!argStream.HasErrors())
{
if (CStaticFunctionDefinitions::GetObjectMass(*pObject, fMass))
{
lua_pushnumber(luaVM, fMass);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaObjectDefs::GetObjectProperties (lua_State* luaVM)
{
lua_pushstring(luaVM, "all");
Expand Down Expand Up @@ -545,6 +573,31 @@ int CLuaObjectDefs::ToggleObjectRespawn(lua_State* luaVM)
return 1;
}

int CLuaObjectDefs::SetObjectMass(lua_State* luaVM)
{
// bool setObjectMass ( object theObject, float fMass )
CClientEntity* pEntity;
float fMass;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pEntity);
argStream.ReadNumber(fMass);

if (!argStream.HasErrors())
{
if (CStaticFunctionDefinitions::SetObjectMass(*pEntity, fMass))
{
lua_pushboolean(luaVM, true);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaObjectDefs::SetObjectProperty(lua_State* luaVM)
{
// bool setObjectProperty ( object theObject, string property, ... )
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h
Expand Up @@ -25,6 +25,7 @@ class CLuaObjectDefs : public CLuaDefs
LUA_DECLARE(IsObjectStatic);
LUA_DECLARE(GetObjectScale);
LUA_DECLARE(IsObjectBreakable);
LUA_DECLARE(GetObjectMass);
LUA_DECLARE(GetObjectProperty);
LUA_DECLARE(GetObjectProperties);

Expand All @@ -38,5 +39,6 @@ class CLuaObjectDefs : public CLuaDefs
LUA_DECLARE(BreakObject);
LUA_DECLARE(RespawnObject);
LUA_DECLARE(ToggleObjectRespawn);
LUA_DECLARE(SetObjectMass);
LUA_DECLARE(SetObjectProperty);
};

0 comments on commit bc62ae1

Please sign in to comment.