Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setVehicleRespawnRotation function and tweaked OOP variants #338

Merged
merged 4 commits into from Sep 4, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+50 −8
Diff settings

Always

Just for now

@@ -6726,17 +6726,31 @@ bool CStaticFunctionDefinitions::GetVehicleRespawnPosition(CElement* pElement, C
return false;
}

bool CStaticFunctionDefinitions::SetVehicleRespawnPosition(CElement* pElement, const CVector& vecPosition, const CVector& vecRotation)
bool CStaticFunctionDefinitions::SetVehicleRespawnRotation(CElement* pElement, const CVector& vecRotation)
{
assert(pElement);
RUN_CHILDREN(SetVehicleRespawnPosition(*iter, vecPosition, vecRotation))
RUN_CHILDREN(SetVehicleRespawnRotation(*iter, vecRotation))

if (IS_VEHICLE(pElement))
{
CVehicle* pVehicle = static_cast<CVehicle*>(pElement);
pVehicle->SetRespawnRotationDegrees(vecRotation);

return true;
}

return false;
}

bool CStaticFunctionDefinitions::SetVehicleRespawnPosition(CElement* pElement, const CVector& vecPosition)
{
assert(pElement);
RUN_CHILDREN(SetVehicleRespawnPosition(*iter, vecPosition))

if (IS_VEHICLE(pElement))
{
CVehicle* pVehicle = static_cast<CVehicle*>(pElement);
pVehicle->SetRespawnPosition(vecPosition);
pVehicle->SetRespawnRotationDegrees(vecRotation);

return true;
}
@@ -303,7 +303,8 @@ class CStaticFunctionDefinitions
static bool SetVehicleRespawnDelay(CElement* pElement, unsigned long ulTime);
static bool GetVehicleRespawnPosition(CElement* pElement, CVector& vecPosition);
static bool GetVehicleRespawnRotation(CElement* pElement, CVector& vecRotation);
static bool SetVehicleRespawnPosition(CElement* pElement, const CVector& vecPosition, const CVector& vecRotation);
static bool SetVehicleRespawnRotation(CElement* pElement, const CVector& vecRotation);
static bool SetVehicleRespawnPosition(CElement* pElement, const CVector& vecPosition);
static bool ToggleVehicleRespawn(CElement* pElement, bool bRespawn);
static bool ResetVehicleExplosionTime(CElement* pElement);
static bool ResetVehicleIdleTime(CElement* pElement);
@@ -84,6 +84,7 @@ void CLuaVehicleDefs::LoadFunctions()
CLuaCFunctions::AddFunction("setVehicleRespawnDelay", SetVehicleRespawnDelay);
CLuaCFunctions::AddFunction("setVehicleIdleRespawnDelay", SetVehicleIdleRespawnDelay);
CLuaCFunctions::AddFunction("setVehicleRespawnPosition", SetVehicleRespawnPosition);
CLuaCFunctions::AddFunction("setVehicleRespawnRotation", SetVehicleRespawnRotation);
CLuaCFunctions::AddFunction("getVehicleRespawnPosition", GetVehicleRespawnPosition);
CLuaCFunctions::AddFunction("getVehicleRespawnRotation", GetVehicleRespawnRotation);
CLuaCFunctions::AddFunction("respawnVehicle", RespawnVehicle);
@@ -186,6 +187,8 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "getWheelStates", "getVehicleWheelStates");
lua_classfunction(luaVM, "getDoorOpenRatio", "getVehicleDoorOpenRatio");
lua_classfunction(luaVM, "getHandling", "getVehicleHandling");
lua_classfunction(luaVM, "getRespawnPosition", "getVehicleRespawnPosition");
lua_classfunction(luaVM, "getRespawnRotation", "getVehicleRespawnRotation");

lua_classfunction(luaVM, "setColor", "setVehicleColor");
lua_classfunction(luaVM, "setDamageProof", "setVehicleDamageProof");
@@ -202,6 +205,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "setPanelState", "setVehiclePanelState");
lua_classfunction(luaVM, "setRespawnDelay", "setVehicleRespawnDelay");
lua_classfunction(luaVM, "setRespawnPosition", "setVehicleRespawnPosition");
lua_classfunction(luaVM, "setRespawnRotation", "setVehicleRespawnRotation");
lua_classfunction(luaVM, "setSirensOn", "setVehicleSirensOn");
lua_classfunction(luaVM, "setTurretPosition", "setVehicleTurretPosition");
lua_classfunction(luaVM, "setDoorOpenRatio", "setVehicleDoorOpenRatio");
@@ -251,7 +255,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
lua_classvariable(luaVM, "idleRespawnDelay", "setVehicleIdleRespawnDelay", NULL);
lua_classvariable(luaVM, "respawnDelay", "setVehicleRespawnDelay", NULL);
lua_classvariable(luaVM, "respawnPosition", "setVehicleRespawnPosition", "getVehicleRespawnPosition", SetVehicleRespawnPosition, OOP_GetVehicleRespawnPosition);
lua_classvariable(luaVM, "respawnRotation", NULL, "getVehicleRespawnRotation", NULL, OOP_GetVehicleRespawnRotation);
lua_classvariable(luaVM, "respawnRotation", "setVehicleRespawnRotation", "getVehicleRespawnRotation", SetVehicleRespawnRotation, OOP_GetVehicleRespawnRotation);
lua_classvariable(luaVM, "onGround", NULL, "isVehicleOnGround");
lua_classvariable(luaVM, "name", NULL, "getVehicleName");
lua_classvariable(luaVM, "vehicleType", NULL, "getVehicleType");
@@ -2326,20 +2330,42 @@ int CLuaVehicleDefs::GetVehicleRespawnPosition(lua_State* luaVM)
return 1;
}

int CLuaVehicleDefs::SetVehicleRespawnRotation(lua_State* luaVM)
{
CElement* pElement;
CVector vecRotation;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
argStream.ReadVector3D(vecRotation, CVector());

if (!argStream.HasErrors())
{
if (CStaticFunctionDefinitions::SetVehicleRespawnRotation(pElement, vecRotation))
{
lua_pushboolean(luaVM, true);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaVehicleDefs::SetVehicleRespawnPosition(lua_State* luaVM)
{
CElement* pElement;
CVector vecPosition;
CVector vecRotation;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pElement);
argStream.ReadVector3D(vecPosition);
argStream.ReadVector3D(vecRotation, CVector());

This comment has been minimized.

Copy link
@Addlibs

Addlibs Aug 23, 2018

Contributor

What about existing code? setVehicleRespawnPosition should retain the ability to set respawn rotations, as existing code could rely on this behaviour.

The most you could do is deprecate this for now, meaning add a warning like this or something, but retain the functionality (not tested nor attempted to compile):

if (argStream.NextIsVector3D())
{
    CVector vecRotation;
    argStream.ReadVector3D(vecRotation);

    // Set deprecation warning
    argStream.SetCustomWarning("Setting respawn rotation in setVehicleRespawnPosition is deprecated and may not work in future versions. Please consider using setVehicleRespawnRotation.");
    if (!argStream.HasErrors()) // Deprecation warning is printed out at this call
    {
        // Update position and rotation
    }
}
else if (!argStream.HasErrors())
{
    // Update position only
}

This comment has been minimized.

Copy link
@qaisjp

qaisjp Aug 23, 2018

Member

SetVehicleRespawnPosition should still support rotation due to backwards compat (don't change the functionality of this function)


if (!argStream.HasErrors())
{
if (CStaticFunctionDefinitions::SetVehicleRespawnPosition(pElement, vecPosition, vecRotation))
if (CStaticFunctionDefinitions::SetVehicleRespawnPosition(pElement, vecPosition))
{
lua_pushboolean(luaVM, true);
return 1;
@@ -90,6 +90,7 @@ class CLuaVehicleDefs : public CLuaDefs
LUA_DECLARE(SetVehicleIdleRespawnDelay);
LUA_DECLARE(SetVehicleRespawnDelay);
LUA_DECLARE(SetVehicleRespawnPosition);
LUA_DECLARE(SetVehicleRespawnRotation);
LUA_DECLARE_OOP(GetVehicleRespawnPosition);
LUA_DECLARE_OOP(GetVehicleRespawnRotation);
LUA_DECLARE(ToggleVehicleRespawn);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.