Skip to content

Commit 8a64fd4

Browse files
Synchronize changes from 1.6 master branch [ci skip]
a08e38d Fix #2852: add optional 'property' parameter to getVehicleHandling function (#3177)
2 parents e2bded1 + a08e38d commit 8a64fd4

File tree

2 files changed

+114
-1
lines changed

2 files changed

+114
-1
lines changed

Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,12 +2649,69 @@ int CLuaVehicleDefs::SetVehicleHandling(lua_State* luaVM)
26492649

26502650
int CLuaVehicleDefs::GetVehicleHandling(lua_State* luaVM)
26512651
{
2652+
// table getVehicleHandling ( element theVehicle, [ string property ] )
26522653
CClientVehicle* pVehicle = NULL;
26532654
CScriptArgReader argStream(luaVM);
26542655
argStream.ReadUserData(pVehicle);
26552656

26562657
if (!argStream.HasErrors())
26572658
{
2659+
if (argStream.NextIsString())
2660+
{
2661+
SString strProperty;
2662+
argStream.ReadString(strProperty);
2663+
2664+
eHandlingProperty eProperty = g_pGame->GetHandlingManager()->GetPropertyEnumFromName(strProperty);
2665+
if (eProperty == HANDLING_MAX)
2666+
{
2667+
argStream.SetCustomError("Invalid property");
2668+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
2669+
lua_pushboolean(luaVM, false);
2670+
return 1;
2671+
}
2672+
2673+
float fValue = 0.0f;
2674+
CVector vecValue = CVector(0.0f, 0.0f, 0.0f);
2675+
SString strValue = "";
2676+
unsigned int uiValue = 0;
2677+
unsigned char ucValue = 0;
2678+
if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, fValue))
2679+
{
2680+
lua_pushnumber(luaVM, fValue);
2681+
}
2682+
else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, uiValue))
2683+
{
2684+
lua_pushnumber(luaVM, uiValue);
2685+
}
2686+
else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, ucValue))
2687+
{
2688+
lua_pushnumber(luaVM, ucValue);
2689+
}
2690+
else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, strValue))
2691+
{
2692+
lua_pushstring(luaVM, strValue);
2693+
}
2694+
else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, vecValue))
2695+
{
2696+
lua_createtable(luaVM, 3, 0);
2697+
lua_pushnumber(luaVM, 1);
2698+
lua_pushnumber(luaVM, vecValue.fX);
2699+
lua_settable(luaVM, -3);
2700+
lua_pushnumber(luaVM, 2);
2701+
lua_pushnumber(luaVM, vecValue.fY);
2702+
lua_settable(luaVM, -3);
2703+
lua_pushnumber(luaVM, 3);
2704+
lua_pushnumber(luaVM, vecValue.fZ);
2705+
lua_settable(luaVM, -3);
2706+
}
2707+
else
2708+
{
2709+
argStream.SetCustomError("Invalid property");
2710+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
2711+
lua_pushboolean(luaVM, false);
2712+
}
2713+
return 1;
2714+
}
26582715
CHandlingEntry* pEntry = pVehicle->GetHandlingData();
26592716

26602717
lua_newtable(luaVM);

Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,70 @@ int CLuaHandlingDefs::SetModelHandling(lua_State* luaVM)
390390

391391
int CLuaHandlingDefs::GetVehicleHandling(lua_State* luaVM)
392392
{
393-
// table getVehicleHandling ( element theVehicle )
393+
// table getVehicleHandling ( element theVehicle, [ string property ] )
394394
CVehicle* pVehicle;
395395

396396
CScriptArgReader argStream(luaVM);
397397
argStream.ReadUserData(pVehicle);
398398

399399
if (!argStream.HasErrors())
400400
{
401+
if (argStream.NextIsString())
402+
{
403+
SString strProperty;
404+
argStream.ReadString(strProperty);
405+
406+
eHandlingProperty eProperty = m_pHandlingManager->GetPropertyEnumFromName(strProperty);
407+
if (eProperty == HANDLING_MAX)
408+
{
409+
argStream.SetCustomError("Invalid property");
410+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
411+
lua_pushboolean(luaVM, false);
412+
return 1;
413+
}
414+
415+
float fValue = 0.0f;
416+
CVector vecValue = CVector(0.0f, 0.0f, 0.0f);
417+
SString strValue = "";
418+
unsigned int uiValue = 0;
419+
unsigned char ucValue = 0;
420+
if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, fValue))
421+
{
422+
lua_pushnumber(luaVM, fValue);
423+
}
424+
else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, uiValue))
425+
{
426+
lua_pushnumber(luaVM, uiValue);
427+
}
428+
else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, ucValue))
429+
{
430+
lua_pushnumber(luaVM, ucValue);
431+
}
432+
else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, strValue))
433+
{
434+
lua_pushstring(luaVM, strValue);
435+
}
436+
else if (CStaticFunctionDefinitions::GetVehicleHandling(pVehicle, eProperty, vecValue))
437+
{
438+
lua_createtable(luaVM, 3, 0);
439+
lua_pushnumber(luaVM, 1);
440+
lua_pushnumber(luaVM, vecValue.fX);
441+
lua_settable(luaVM, -3);
442+
lua_pushnumber(luaVM, 2);
443+
lua_pushnumber(luaVM, vecValue.fY);
444+
lua_settable(luaVM, -3);
445+
lua_pushnumber(luaVM, 3);
446+
lua_pushnumber(luaVM, vecValue.fZ);
447+
lua_settable(luaVM, -3);
448+
}
449+
else
450+
{
451+
argStream.SetCustomError("Invalid property");
452+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
453+
lua_pushboolean(luaVM, false);
454+
}
455+
return 1;
456+
}
401457
CHandlingEntry* pEntry = pVehicle->GetHandlingData();
402458

403459
lua_newtable(luaVM);

0 commit comments

Comments
 (0)