Navigation Menu

Skip to content

Commit

Permalink
Followup to #1644: Add get/setVehicleModelWheelSize (#1648)
Browse files Browse the repository at this point in the history
This addresses the review @qaisjp made on PR #1644 after it got
merged.
  • Loading branch information
AlexTMjugador committed Sep 1, 2020
1 parent be82d1c commit eb2ca52
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 53 deletions.
31 changes: 0 additions & 31 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -3603,23 +3603,6 @@ bool CStaticFunctionDefinitions::SetVehicleWindowOpen(CClientVehicle& Vehicle, u
return Vehicle.SetWindowOpen(ucWindow, bOpen);
}

bool CStaticFunctionDefinitions::SetVehicleModelWheelSize(unsigned short usModel, eResizableVehicleWheelGroup eWheelGroup, float fWheelSize)
{
if (CClientVehicleManager::IsValidModel(usModel))
{
auto pModelInfo = g_pGame->GetModelInfo(usModel);
if (pModelInfo)
{
pModelInfo->SetVehicleWheelSize(eWheelGroup, fWheelSize);
// Restream needed to update ride height
m_pVehicleManager->RestreamVehicles(usModel);

return true;
}
}
return false;
}

bool CStaticFunctionDefinitions::IsVehicleWindowOpen(CClientVehicle& Vehicle, uchar ucWindow)
{
return Vehicle.IsWindowOpen(ucWindow);
Expand Down Expand Up @@ -3653,20 +3636,6 @@ bool CStaticFunctionDefinitions::GetVehicleModelDummyPosition(unsigned short usM
return false;
}

bool CStaticFunctionDefinitions::GetVehicleModelWheelSize(unsigned short usModel, eResizableVehicleWheelGroup eWheelGroup, float& fWheelSize)
{
if (CClientVehicleManager::IsValidModel(usModel) && eWheelGroup != eResizableVehicleWheelGroup::ALL_WHEELS)
{
auto pModelInfo = g_pGame->GetModelInfo(usModel);
if (pModelInfo)
{
fWheelSize = pModelInfo->GetVehicleWheelSize(eWheelGroup);
return true;
}
}
return false;
}

bool CStaticFunctionDefinitions::SetVehicleModelExhaustFumesPosition(unsigned short usModel, CVector& vecPosition)
{
if (CClientVehicleManager::IsValidModel(usModel))
Expand Down
2 changes: 0 additions & 2 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Expand Up @@ -226,7 +226,6 @@ class CStaticFunctionDefinitions
static bool GetVehicleModelExhaustFumesPosition(unsigned short usModel, CVector& vecPosition);
static bool SetVehicleModelDummyPosition(unsigned short usModel, eVehicleDummies eDummy, CVector& vecPosition);
static bool GetVehicleModelDummyPosition(unsigned short usModel, eVehicleDummies eDummy, CVector& vecPosition);
static bool GetVehicleModelWheelSize(unsigned short usModel, eResizableVehicleWheelGroup eWheelGroup, float& fWheelSize);

// Vehicle set functions
static bool FixVehicle(CClientEntity& Entity);
Expand Down Expand Up @@ -271,7 +270,6 @@ class CStaticFunctionDefinitions
static bool SetVehiclePlateText(CClientEntity& Entity, const SString& strText);
static bool SetHeliBladeCollisionsEnabled(CClientVehicle& Vehicle, bool bEnabled);
static bool SetVehicleWindowOpen(CClientVehicle& Vehicle, uchar ucWindow, bool bOpen);
static bool SetVehicleModelWheelSize(unsigned short usModel, eResizableVehicleWheelGroup eWheelGroup, float fWheelSize);

// Object get funcs
static CClientObject* CreateObject(CResource& Resource, unsigned short usModelID, const CVector& vecPosition, const CVector& vecRotation, bool bLowLod);
Expand Down
43 changes: 23 additions & 20 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Expand Up @@ -4077,38 +4077,41 @@ bool CLuaVehicleDefs::SetVehicleWheelScale(CClientVehicle* const pVehicle, const
std::variant<float, std::unordered_map<std::string, float>> CLuaVehicleDefs::GetVehicleModelWheelSize(
const unsigned short usModel, const std::optional<eResizableVehicleWheelGroup> eWheelGroup)
{
eResizableVehicleWheelGroup eActualWheelGroup = eWheelGroup.value_or(eResizableVehicleWheelGroup::ALL_WHEELS);
CModelInfo* pModelInfo = nullptr;
if (CClientVehicleManager::IsValidModel(usModel))
pModelInfo = g_pGame->GetModelInfo(usModel);

if (!pModelInfo)
throw std::invalid_argument("Invalid model ID");

eResizableVehicleWheelGroup eActualWheelGroup = eWheelGroup.value_or(eResizableVehicleWheelGroup::ALL_WHEELS);
if (eActualWheelGroup == eResizableVehicleWheelGroup::ALL_WHEELS)
{
float fFrontWheelSize;
if (!CStaticFunctionDefinitions::GetVehicleModelWheelSize(usModel, eResizableVehicleWheelGroup::FRONT_AXLE, fFrontWheelSize))
throw std::invalid_argument("Invalid model ID");

float fRearWheelSize;
if (!CStaticFunctionDefinitions::GetVehicleModelWheelSize(usModel, eResizableVehicleWheelGroup::REAR_AXLE, fRearWheelSize))
throw std::invalid_argument("Invalid model ID");

// Return a table like { ["front_axle"] = 0.7, ["rear_axle"] = 0.8 }
return std::unordered_map<std::string, float>{
{"front_axle", fFrontWheelSize},
{"rear_axle", fRearWheelSize},
{"front_axle", pModelInfo->GetVehicleWheelSize(eResizableVehicleWheelGroup::FRONT_AXLE)},
{"rear_axle", pModelInfo->GetVehicleWheelSize(eResizableVehicleWheelGroup::REAR_AXLE)},
};
}
else
{
float fWheelSize;
if (!CStaticFunctionDefinitions::GetVehicleModelWheelSize(usModel, eActualWheelGroup, fWheelSize))
throw std::invalid_argument("Invalid model ID");

return fWheelSize;
}
return pModelInfo->GetVehicleWheelSize(eActualWheelGroup);
}

bool CLuaVehicleDefs::SetVehicleModelWheelSize(const unsigned short usModel, const eResizableVehicleWheelGroup eWheelGroup, const float fWheelSize)
{
CModelInfo* pModelInfo = nullptr;

if (fWheelSize <= 0)
throw std::invalid_argument("Invalid wheel size");

return CStaticFunctionDefinitions::SetVehicleModelWheelSize(usModel, eWheelGroup, fWheelSize);
if (CClientVehicleManager::IsValidModel(usModel))
pModelInfo = g_pGame->GetModelInfo(usModel);

if (!pModelInfo)
throw std::invalid_argument("Invalid model ID");

pModelInfo->SetVehicleWheelSize(eWheelGroup, fWheelSize);
// Restream needed to update ride height
m_pVehicleManager->RestreamVehicles(usModel);

return true;
}

0 comments on commit eb2ca52

Please sign in to comment.