diff --git a/Client/game_sa/CPhysicalSA.cpp b/Client/game_sa/CPhysicalSA.cpp index 2c46480bda0..499d7fa9202 100644 --- a/Client/game_sa/CPhysicalSA.cpp +++ b/Client/game_sa/CPhysicalSA.cpp @@ -135,6 +135,16 @@ void CPhysicalSA::SetTurnMass(float fTurnMass) ((CPhysicalSAInterface*)this->GetInterface())->m_fTurnMass = fTurnMass; } +float CPhysicalSA::GetAirResistance(void) +{ + return ((CPhysicalSAInterface*)this->GetInterface())->m_fAirResistance; +} + +void CPhysicalSA::SetAirResistance(float fAirResistance) +{ + ((CPhysicalSAInterface*)this->GetInterface())->m_fAirResistance = fAirResistance; +} + float CPhysicalSA::GetElasticity(void) { return ((CPhysicalSAInterface*)this->GetInterface())->m_fElasticity; @@ -155,6 +165,17 @@ void CPhysicalSA::SetBuoyancyConstant(float fBuoyancyConstant) ((CPhysicalSAInterface*)this->GetInterface())->m_fBuoyancyConstant = fBuoyancyConstant; } +void CPhysicalSA::GetCenterOfMass(CVector & vecCenterOfMass) +{ + vecCenterOfMass = ((CPhysicalSAInterface*)this->GetInterface())->m_vecCenterOfMass; +} + + +void CPhysicalSA::SetCenterOfMass(CVector & vecCenterOfMass) +{ + ((CPhysicalSAInterface*)this->GetInterface())->m_vecCenterOfMass = vecCenterOfMass; +} + VOID CPhysicalSA::ProcessCollision() { DEBUG_TRACE("VOID CPhysicalSA::ProcessCollision()"); diff --git a/Client/game_sa/CPhysicalSA.h b/Client/game_sa/CPhysicalSA.h index c1bdaa93d83..2f4fd0ece6e 100644 --- a/Client/game_sa/CPhysicalSA.h +++ b/Client/game_sa/CPhysicalSA.h @@ -9,8 +9,7 @@ * *****************************************************************************/ -#ifndef __CGAMESA_PHYSICAL -#define __CGAMESA_PHYSICAL +#pragma once #include #include "CEntitySA.h" @@ -125,10 +124,14 @@ class CPhysicalSA : public virtual CPhysical, public virtual CEntitySA void SetMass(float fMass); float GetTurnMass(void); void SetTurnMass(float fTurnMass); + float GetAirResistance(void); + void SetAirResistance(float fAirResistance); float GetElasticity(void); void SetElasticity(float fElasticity); float GetBuoyancyConstant(void); void SetBuoyancyConstant(float fBuoyancyConstant); + void GetCenterOfMass(CVector& vecCenterOfMass); + void SetCenterOfMass(CVector& vecCenterOfMass); void ProcessCollision(void); void AddToMovingList(void); @@ -155,10 +158,6 @@ class CPhysicalSA : public virtual CPhysical, public virtual CEntitySA /* VOID SetMassMultiplier(FLOAT fMassMultiplier); FLOAT GetMassMultiplier(); - VOID SetAirResistance(FLOAT fAirResistance); - FLOAT GetAirResistance(); - VOID SetCenterOfMass(CVector * vecCenterOfMass); - CVector * GetCenterOfMass(); BOOL GetExtraHeavy(); VOID SetExtraHeavy(BOOL bExtraHeavy); @@ -173,5 +172,3 @@ class CPhysicalSA : public virtual CPhysical, public virtual CEntitySA BYTE GetLevel(); VOID SetLevel(BYTE LivesInThisLevel);*/ }; - -#endif diff --git a/Client/mods/deathmatch/logic/CClientObject.cpp b/Client/mods/deathmatch/logic/CClientObject.cpp index 01d80cf989f..5e9bfe77e1f 100644 --- a/Client/mods/deathmatch/logic/CClientObject.cpp +++ b/Client/mods/deathmatch/logic/CClientObject.cpp @@ -40,6 +40,11 @@ CClientObject::CClientObject(CClientManager* pManager, ElementID ID, unsigned sh m_bBreakingDisabled = false; m_bRespawnEnabled = true; m_fMass = -1.0f; + m_fTurnMass = -1.0f; + m_fAirResistance = -1.0f; + m_fElasticity = -1.0f; + m_fBuoyancyConstant = -1.0f; + m_vecCenterOfMass = CVector(0.0f, 0.0f, 0.0f); m_pModelInfo = g_pGame->GetModelInfo(usModel); @@ -511,10 +516,20 @@ void CClientObject::Create(void) SetAlpha(m_ucAlpha); m_pObject->SetHealth(m_fHealth); - // Set object mass + // Set object properties if (m_fMass != -1.0f) m_pObject->SetMass(m_fMass); - + if (m_fTurnMass != -1.0f) + m_pObject->SetTurnMass(m_fTurnMass); + if (m_fAirResistance != -1.0f) + m_pObject->SetAirResistance(m_fAirResistance); + if (m_fElasticity != -1.0f) + m_pObject->SetElasticity(m_fElasticity); + if (m_fBuoyancyConstant != -1.0f) + m_pObject->SetBuoyancyConstant(m_fBuoyancyConstant); + if (m_vecCenterOfMass.fX != 0.0f || m_vecCenterOfMass.fY != 0.0f || m_vecCenterOfMass.fZ != 0.0f) + m_pObject->SetCenterOfMass(m_vecCenterOfMass); + // Reattach to an entity + any entities attached to this ReattachEntities(); @@ -730,6 +745,86 @@ void CClientObject::SetMass(float fMass) m_fMass = fMass; } +float CClientObject::GetTurnMass(void) +{ + if (m_pObject) + return m_pObject->GetTurnMass(); + + return m_fTurnMass; +} + +void CClientObject::SetTurnMass(float fTurnMass) +{ + if (m_pObject) + m_pObject->SetTurnMass(fTurnMass); + + m_fTurnMass = fTurnMass; +} + +float CClientObject::GetAirResistance(void) +{ + if (m_pObject) + return m_pObject->GetAirResistance(); + + return m_fAirResistance; +} + +void CClientObject::SetAirResistance(float fAirResistance) +{ + if (m_pObject) + m_pObject->SetAirResistance(fAirResistance); + + m_fAirResistance = fAirResistance; +} + +float CClientObject::GetElasticity(void) +{ + if (m_pObject) + return m_pObject->GetElasticity(); + + return m_fElasticity; +} + +void CClientObject::SetElasticity(float fElasticity) +{ + if (m_pObject) + m_pObject->SetElasticity(fElasticity); + + m_fElasticity = fElasticity; +} + +float CClientObject::GetBuoyancyConstant(void) +{ + if (m_pObject) + return m_pObject->GetBuoyancyConstant(); + + return m_fBuoyancyConstant; +} + +void CClientObject::SetBuoyancyConstant(float fBuoyancyConstant) +{ + if (m_pObject) + m_pObject->SetBuoyancyConstant(fBuoyancyConstant); + + m_fBuoyancyConstant = fBuoyancyConstant; +} + +void CClientObject::GetCenterOfMass(CVector& vecCenterOfMass) const +{ + if (m_pObject) + m_pObject->GetCenterOfMass(vecCenterOfMass); + else + vecCenterOfMass = m_vecCenterOfMass; +} + +void CClientObject::SetCenterOfMass(const CVector& vecCenterOfMass) +{ + if (m_pObject) + m_pObject->SetCenterOfMass(const_cast(vecCenterOfMass)); + + m_vecCenterOfMass = vecCenterOfMass; +} + void CClientObject::SetVisibleInAllDimensions(bool bVisible, unsigned short usNewDimension) { m_bVisibleInAllDimensions = bVisible; diff --git a/Client/mods/deathmatch/logic/CClientObject.h b/Client/mods/deathmatch/logic/CClientObject.h index 3765799e336..d6f14be8981 100644 --- a/Client/mods/deathmatch/logic/CClientObject.h +++ b/Client/mods/deathmatch/logic/CClientObject.h @@ -87,6 +87,16 @@ class CClientObject : public CClientStreamElement float GetHealth(void); void SetHealth(float fHealth); + float GetTurnMass(void); + void SetTurnMass(float fTurnMass); + float GetAirResistance(void); + void SetAirResistance(float fAirResistance); + float GetElasticity(void); + void SetElasticity(float fElasticity); + float GetBuoyancyConstant(void); + void SetBuoyancyConstant(float fBuoyancyConstant); + void GetCenterOfMass(CVector& vecCenterOfMass) const; + void SetCenterOfMass(const CVector& vecCenterOfMass); bool IsBreakable(bool bCheckModelList = true); bool SetBreakable(bool bBreakable); @@ -135,6 +145,11 @@ class CClientObject : public CClientStreamElement bool m_bBeingRespawned; bool m_bRespawnEnabled; float m_fMass; + float m_fTurnMass; + float m_fAirResistance; + float m_fElasticity; + float m_fBuoyancyConstant; + CVector m_vecCenterOfMass; bool m_bVisibleInAllDimensions = false; CVector m_vecMoveSpeed; diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 8ec7da4aa96..b5e473a4028 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1081,7 +1081,6 @@ bool CStaticFunctionDefinitions::SetElementRotation(CClientEntity& Entity, const { Vehicle.SetRotationDegrees(ConvertEulerRotationOrder(vecRotation, argumentRotOrder, EULER_ZYX)); } - break; } case CCLIENTOBJECT: @@ -3765,6 +3764,36 @@ bool CStaticFunctionDefinitions::GetObjectMass(CClientObject& Object, float& fMa return true; } +bool CStaticFunctionDefinitions::GetObjectTurnMass(CClientObject& Object, float& fTurnMass) +{ + fTurnMass = Object.GetTurnMass(); + return true; +} + +bool CStaticFunctionDefinitions::GetObjectAirResistance(CClientObject& Object, float& fAirResistance) +{ + fAirResistance = Object.GetAirResistance(); + return true; +} + +bool CStaticFunctionDefinitions::GetObjectElasticity(CClientObject& Object, float& fElasticity) +{ + fElasticity = Object.GetElasticity(); + return true; +} + +bool CStaticFunctionDefinitions::GetObjectBuoyancyConstant(CClientObject& Object, float& fBuoyancyConstant) +{ + fBuoyancyConstant = Object.GetBuoyancyConstant(); + return true; +} + +bool CStaticFunctionDefinitions::GetObjectCenterOfMass(CClientObject& Object, CVector& vecCenterOfMass) +{ + Object.GetCenterOfMass(vecCenterOfMass); + return true; +} + bool CStaticFunctionDefinitions::SetObjectRotation(CClientEntity& Entity, const CVector& vecRotation) { RUN_CHILDREN(SetObjectRotation(**iter, vecRotation)) @@ -3935,6 +3964,75 @@ bool CStaticFunctionDefinitions::SetObjectMass(CClientEntity& Entity, float fMas return false; } +bool CStaticFunctionDefinitions::SetObjectTurnMass(CClientEntity& Entity, float fTurnMass) +{ + if (fTurnMass >= 0.0f) + { + RUN_CHILDREN(SetObjectTurnMass(**iter, fTurnMass)) + + if (IS_OBJECT(&Entity)) + { + CDeathmatchObject& Object = static_cast(Entity); + Object.SetTurnMass(fTurnMass); + return true; + } + } + return false; +} + +bool CStaticFunctionDefinitions::SetObjectAirResistance(CClientEntity& Entity, float fAirResistance) +{ + RUN_CHILDREN(SetObjectAirResistance(**iter, fAirResistance)) + + if (IS_OBJECT(&Entity)) + { + CDeathmatchObject& Object = static_cast(Entity); + Object.SetAirResistance(fAirResistance); + return true; + } + return false; +} + +bool CStaticFunctionDefinitions::SetObjectElasticity(CClientEntity& Entity, float fElasticity) +{ + RUN_CHILDREN(SetObjectElasticity(**iter, fElasticity)) + + if (IS_OBJECT(&Entity)) + { + CDeathmatchObject& Object = static_cast(Entity); + Object.SetElasticity(fElasticity); + return true; + } + return false; +} + +bool CStaticFunctionDefinitions::SetObjectBuoyancyConstant(CClientEntity& Entity, float fBuoyancyConstant) +{ + RUN_CHILDREN(SetObjectBuoyancyConstant(**iter, fBuoyancyConstant)) + + if (IS_OBJECT(&Entity)) + { + CDeathmatchObject& Object = static_cast(Entity); + Object.SetBuoyancyConstant(fBuoyancyConstant); + return true; + } + return false; +} + +bool CStaticFunctionDefinitions::SetObjectCenterOfMass(CClientEntity& Entity, const CVector& vecCenterOfMass) +{ + RUN_CHILDREN(SetObjectCenterOfMass(**iter, vecCenterOfMass)) + + if (IS_OBJECT(&Entity)) + { + CDeathmatchObject& Object = static_cast(Entity); + Object.SetCenterOfMass(vecCenterOfMass); + return true; + } + + return false; +} + bool CStaticFunctionDefinitions::SetObjectVisibleInAllDimensions(CClientEntity& Entity, bool bVisible, unsigned short usNewDimension) { RUN_CHILDREN(SetObjectVisibleInAllDimensions(**iter, bVisible, usNewDimension)) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h index e1218360727..465c4aba141 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -274,6 +274,11 @@ class CStaticFunctionDefinitions static bool GetObjectScale(CClientObject& Object, CVector& vecScale); static bool IsObjectBreakable(CClientObject& Object, bool& bBreakable); static bool GetObjectMass(CClientObject& Object, float& fMass); + static bool GetObjectTurnMass(CClientObject& Object, float& fTurnMass); + static bool GetObjectAirResistance(CClientObject& Object, float& fAirResistance); + static bool GetObjectElasticity(CClientObject& Object, float& fElasticity); + static bool GetObjectBuoyancyConstant(CClientObject& Object, float& fBuoyancyConstant); + static bool GetObjectCenterOfMass(CClientObject& Object, CVector& vecCenterOfMass); static bool IsObjectVisibleInAllDimensions(CClientEntity& Entity); // Object set funcs @@ -288,6 +293,11 @@ class CStaticFunctionDefinitions static bool RespawnObject(CClientEntity& Entity); static bool ToggleObjectRespawn(CClientEntity& Entity, bool bRespawn); static bool SetObjectMass(CClientEntity& Entity, float fMass); + static bool SetObjectTurnMass(CClientEntity& Entity, float fTurnMass); + static bool SetObjectAirResistance(CClientEntity& Entity, float fAirResistance); + static bool SetObjectElasticity(CClientEntity& Entity, float fElasticity); + static bool SetObjectBuoyancyConstant(CClientEntity& Entity, float fBuoyancyConstant); + static bool SetObjectCenterOfMass(CClientEntity& Entity, const CVector& vecCenterOfMass); static bool SetObjectVisibleInAllDimensions(CClientEntity& Entity, bool bVisible, unsigned short usNewDimension = 0); // Radar-area get funcs diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp index 2f310470524..edb54bf9948 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp @@ -370,6 +370,16 @@ ADD_ENUM(VEHICLE_COMPONENT_EXTRA_1, "extra_1") ADD_ENUM(VEHICLE_COMPONENT_EXTRA_2, "extra_2") IMPLEMENT_ENUM_END("vehicle-component") +IMPLEMENT_ENUM_BEGIN(eObjectProperty) +ADD_ENUM(OBJECT_PROPERTY_ALL, "all") +ADD_ENUM(OBJECT_PROPERTY_MASS, "mass") +ADD_ENUM(OBJECT_PROPERTY_TURNMASS, "turn_mass") +ADD_ENUM(OBJECT_PROPERTY_AIRRESISTANCE, "air_resistance") +ADD_ENUM(OBJECT_PROPERTY_ELASTICITY, "elasticity") +ADD_ENUM(OBJECT_PROPERTY_CENTEROFMASS, "center_of_mass") +ADD_ENUM(OBJECT_PROPERTY_BUOYANCY, "buoyancy") +IMPLEMENT_ENUM_END("object-property") + IMPLEMENT_ENUM_BEGIN(eFontType) ADD_ENUM(FONT_DEFAULT, "default") ADD_ENUM(FONT_DEFAULT_BOLD, "default-bold") diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h index f479ce301ae..b6e40644caa 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h @@ -39,6 +39,7 @@ DECLARE_ENUM(EEntityTypeMask); DECLARE_ENUM(eWeaponState); DECLARE_ENUM(eWeaponFlags); DECLARE_ENUM(eVehicleComponent); +DECLARE_ENUM(eObjectProperty); DECLARE_ENUM(eFontType); DECLARE_ENUM(eFontQuality); DECLARE_ENUM(eAudioLookupIndex); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp index caf23109516..e454f151ce8 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp @@ -20,7 +20,7 @@ void CLuaObjectDefs::LoadFunctions(void) CLuaCFunctions::AddFunction("isObjectStatic", IsObjectStatic); CLuaCFunctions::AddFunction("getObjectScale", GetObjectScale); CLuaCFunctions::AddFunction("isObjectBreakable", IsObjectBreakable); - CLuaCFunctions::AddFunction("getObjectMass", GetObjectMass); + CLuaCFunctions::AddFunction("getObjectProperty", GetObjectProperty); // Object set funcs CLuaCFunctions::AddFunction("moveObject", MoveObject); @@ -31,7 +31,7 @@ void CLuaObjectDefs::LoadFunctions(void) CLuaCFunctions::AddFunction("breakObject", BreakObject); CLuaCFunctions::AddFunction("respawnObject", RespawnObject); CLuaCFunctions::AddFunction("toggleObjectRespawn", ToggleObjectRespawn); - CLuaCFunctions::AddFunction("setObjectMass", SetObjectMass); + CLuaCFunctions::AddFunction("setObjectProperty", SetObjectProperty); } void CLuaObjectDefs::AddClass(lua_State* luaVM) @@ -47,15 +47,15 @@ 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_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 lua_classfunction(luaVM, "toggleObjectRespawn", "toggleObjectRespawn"); @@ -138,7 +138,7 @@ int CLuaObjectDefs::IsObjectStatic(lua_State* luaVM) int CLuaObjectDefs::GetObjectScale(lua_State* luaVM) { - // float getObjectScale ( object theObject ) + // float, float, float getObjectScale ( object theObject ) CClientObject* pObject; CScriptArgReader argStream(luaVM); @@ -197,20 +197,123 @@ int CLuaObjectDefs::IsObjectBreakable(lua_State* luaVM) return 1; } -int CLuaObjectDefs::GetObjectMass(lua_State* luaVM) +int CLuaObjectDefs::GetObjectProperties (lua_State* luaVM) { - // float getObjectMass ( object theObject ) - CClientObject* pObject; - float fMass; + lua_pushstring(luaVM, "all"); + return GetObjectProperty(luaVM); +} + +int CLuaObjectDefs::GetObjectProperty(lua_State* luaVM) +{ + // float, float, float getObjectProperty ( object theObject, string property ) + CClientObject* pObject; + eObjectProperty eProp; CScriptArgReader argStream(luaVM); argStream.ReadUserData(pObject); + argStream.ReadEnumString(eProp, eObjectProperty::OBJECT_PROPERTY_MAX); + if (!argStream.HasErrors()) { - if (CStaticFunctionDefinitions::GetObjectMass(*pObject, fMass)) + switch (eProp) { - lua_pushnumber(luaVM, fMass); - return 1; + case OBJECT_PROPERTY_ALL: + { + lua_newtable(luaVM); + + lua_pushnumber(luaVM, pObject->GetMass()); + lua_setfield(luaVM, -2, "mass"); + + lua_pushnumber(luaVM, pObject->GetTurnMass()); + lua_setfield(luaVM, -2, "turn_mass"); + + lua_pushnumber(luaVM, pObject->GetAirResistance()); + lua_setfield(luaVM, -2, "air_resistance"); + + lua_pushnumber(luaVM, pObject->GetElasticity()); + lua_setfield(luaVM, -2, "elasticity"); + + lua_createtable(luaVM, 3, 0); + CVector vecCenter; + pObject->GetCenterOfMass(vecCenter); + lua_pushnumber(luaVM, 1); + lua_pushnumber(luaVM, vecCenter.fX); + lua_settable(luaVM, -3); + lua_pushnumber(luaVM, 2); + lua_pushnumber(luaVM, vecCenter.fY); + lua_settable(luaVM, -3); + lua_pushnumber(luaVM, 3); + lua_pushnumber(luaVM, vecCenter.fZ); + lua_settable(luaVM, -3); + lua_setfield(luaVM, -2, "center_of_mass"); + + lua_pushnumber(luaVM, pObject->GetBuoyancyConstant()); + lua_setfield(luaVM, -2, "buoyancy"); + return 1; + break; + } + case OBJECT_PROPERTY_MASS: + { + float fMass; + if (CStaticFunctionDefinitions::GetObjectMass(*pObject, fMass)) + { + lua_pushnumber(luaVM, fMass); + return 1; + } + break; + } + case OBJECT_PROPERTY_TURNMASS: + { + float fTurnMass; + if (CStaticFunctionDefinitions::GetObjectTurnMass(*pObject, fTurnMass)) + { + lua_pushnumber(luaVM, fTurnMass); + return 1; + } + break; + } + case OBJECT_PROPERTY_AIRRESISTANCE: + { + float fAirResistance; + if (CStaticFunctionDefinitions::GetObjectAirResistance(*pObject, fAirResistance)) + { + lua_pushnumber(luaVM, fAirResistance); + return 1; + } + break; + } + case OBJECT_PROPERTY_ELASTICITY: + { + float fElasticity; + if (CStaticFunctionDefinitions::GetObjectElasticity(*pObject, fElasticity)) + { + lua_pushnumber(luaVM, fElasticity); + return 1; + } + break; + } + case OBJECT_PROPERTY_CENTEROFMASS: + { + CVector vecCenterOfMass; + if (CStaticFunctionDefinitions::GetObjectCenterOfMass(*pObject, vecCenterOfMass)) + { + lua_pushnumber(luaVM, vecCenterOfMass.fX); + lua_pushnumber(luaVM, vecCenterOfMass.fY); + lua_pushnumber(luaVM, vecCenterOfMass.fZ); + return 3; + } + break; + } + case OBJECT_PROPERTY_BUOYANCY: + { + float fBuoyancyConstant; + if (CStaticFunctionDefinitions::GetObjectBuoyancyConstant(*pObject, fBuoyancyConstant)) + { + lua_pushnumber(luaVM, fBuoyancyConstant); + return 1; + } + break; + } } } else @@ -442,22 +545,100 @@ int CLuaObjectDefs::ToggleObjectRespawn(lua_State* luaVM) return 1; } -int CLuaObjectDefs::SetObjectMass(lua_State* luaVM) +int CLuaObjectDefs::SetObjectProperty(lua_State* luaVM) { - // bool setObjectMass ( object theObject, float fMass ) - CClientEntity* pEntity; - float fMass; + // bool setObjectProperty ( object theObject, string property, ... ) + CClientEntity* pEntity; + eObjectProperty eProp; CScriptArgReader argStream(luaVM); argStream.ReadUserData(pEntity); - argStream.ReadNumber(fMass); + argStream.ReadEnumString(eProp); + + if (!argStream.HasErrors() && eProp == OBJECT_PROPERTY_ALL) + { + argStream.SetTypeError(GetEnumTypeName(eProp), 2); + } if (!argStream.HasErrors()) { - if (CStaticFunctionDefinitions::SetObjectMass(*pEntity, fMass)) + switch (eProp) { - lua_pushboolean(luaVM, true); - return 1; + case OBJECT_PROPERTY_MASS: + { + float fMass; + argStream.ReadNumber(fMass); + if (CStaticFunctionDefinitions::SetObjectMass(*pEntity, fMass)) + { + lua_pushboolean(luaVM, true); + return 1; + } + break; + } + case OBJECT_PROPERTY_TURNMASS: + { + float fTurnMass; + argStream.ReadNumber(fTurnMass); + if (CStaticFunctionDefinitions::SetObjectTurnMass(*pEntity, fTurnMass)) + { + lua_pushboolean(luaVM, true); + return 1; + } + break; + } + case OBJECT_PROPERTY_AIRRESISTANCE: + { + float fAirResistance; + argStream.ReadNumber(fAirResistance); + if (CStaticFunctionDefinitions::SetObjectAirResistance(*pEntity, fAirResistance)) + { + lua_pushboolean(luaVM, true); + return 1; + } + break; + } + case OBJECT_PROPERTY_ELASTICITY: + { + float fElasticity; + argStream.ReadNumber(fElasticity); + if (CStaticFunctionDefinitions::SetObjectElasticity(*pEntity, fElasticity)) + { + lua_pushboolean(luaVM, true); + return 1; + } + break; + } + case OBJECT_PROPERTY_CENTEROFMASS: + { + CVector vecCenterOfMass; + if (argStream.NextIsVector3D()) + { + argStream.ReadVector3D(vecCenterOfMass); + } + else + { + argStream.ReadNumber(vecCenterOfMass.fX); + argStream.ReadNumber(vecCenterOfMass.fY); + argStream.ReadNumber(vecCenterOfMass.fZ); + } + if (CStaticFunctionDefinitions::SetObjectCenterOfMass(*pEntity, vecCenterOfMass)) + { + lua_pushboolean(luaVM, true); + return 1; + } + break; + } + case OBJECT_PROPERTY_BUOYANCY: + { + float fBuoyancyConstant; + argStream.ReadNumber(fBuoyancyConstant); + if (CStaticFunctionDefinitions::SetObjectBuoyancyConstant(*pEntity, fBuoyancyConstant)) + { + lua_pushboolean(luaVM, true); + return 1; + } + break; + } } } else diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h index 48e42ece9fd..49884781264 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h @@ -25,7 +25,8 @@ class CLuaObjectDefs : public CLuaDefs LUA_DECLARE(IsObjectStatic); LUA_DECLARE(GetObjectScale); LUA_DECLARE(IsObjectBreakable); - LUA_DECLARE(GetObjectMass); + LUA_DECLARE(GetObjectProperty); + LUA_DECLARE(GetObjectProperties); // Object set funcs LUA_DECLARE(SetObjectRotation); @@ -37,5 +38,5 @@ class CLuaObjectDefs : public CLuaDefs LUA_DECLARE(BreakObject); LUA_DECLARE(RespawnObject); LUA_DECLARE(ToggleObjectRespawn); - LUA_DECLARE(SetObjectMass); -}; \ No newline at end of file + LUA_DECLARE(SetObjectProperty); +}; diff --git a/Client/sdk/game/CPhysical.h b/Client/sdk/game/CPhysical.h index a951f061df9..2230e6b2b6c 100644 --- a/Client/sdk/game/CPhysical.h +++ b/Client/sdk/game/CPhysical.h @@ -28,10 +28,14 @@ class CPhysical : public virtual CEntity virtual void SetMass(float fMass) = 0; virtual float GetTurnMass(void) = 0; virtual void SetTurnMass(float fTurnMass) = 0; + virtual float GetAirResistance(void) = 0; + virtual void SetAirResistance(float fAirResistance) = 0; virtual float GetElasticity(void) = 0; virtual void SetElasticity(float fElasticity) = 0; virtual float GetBuoyancyConstant(void) = 0; virtual void SetBuoyancyConstant(float fBuoyancyConstant) = 0; + virtual void GetCenterOfMass(CVector& vecCenterOfMass) = 0; + virtual void SetCenterOfMass(CVector& vecCenterOfMass) = 0; virtual void ProcessCollision(void) = 0; virtual void AddToMovingList(void) = 0; diff --git a/Client/sdk/game/Common.h b/Client/sdk/game/Common.h index bcfe17026d1..57cd5ddf7c5 100644 --- a/Client/sdk/game/Common.h +++ b/Client/sdk/game/Common.h @@ -1511,4 +1511,16 @@ enum eVehicleComponent VEHICLE_COMPONENT_MAX, }; +enum eObjectProperty +{ + OBJECT_PROPERTY_ALL, + OBJECT_PROPERTY_MASS, + OBJECT_PROPERTY_TURNMASS, + OBJECT_PROPERTY_AIRRESISTANCE, + OBJECT_PROPERTY_ELASTICITY, + OBJECT_PROPERTY_CENTEROFMASS, + OBJECT_PROPERTY_BUOYANCY, + OBJECT_PROPERTY_MAX, +}; + #endif