Permalink
Browse files

Make exhaust position vehicle specific for setVehicleModelDummyPosition

Two new properties added to setVehicleModelDummyPosition:

exhaust_left
exhaust_right
  • Loading branch information...
codenulls committed Dec 23, 2018
1 parent f0ee264 commit d6b283180b6882c232d918b4c2d46b17f870c6dd
@@ -917,7 +917,7 @@ void* CModelInfoSA::SetVehicleSuspensionData(void* pSuspensionLines)
return pOrigSuspensionLines;
}

CVector CModelInfoSA::GetVehicleExhaustFumesPosition()
CVector* CModelInfoSA::GetVehicleExhaustFumesPosition()
{
return GetVehicleDummyPosition(eVehicleDummies::EXHAUST);
}
@@ -927,23 +927,29 @@ void CModelInfoSA::SetVehicleExhaustFumesPosition(const CVector& vecPosition)
return SetVehicleDummyPosition(eVehicleDummies::EXHAUST, vecPosition);
}

CVector CModelInfoSA::GetVehicleDummyPosition(eVehicleDummies eDummy)
CVector* CModelInfoSA::GetVehicleDummyPosition(eVehicleDummies eDummy)
{
if (!IsVehicle())
return CVector();
// There are only 15 dummies in GTA.
if (!IsVehicle() || eDummy > VEH_UNKNOWNDUMMY)
{
static CVector vecDefaultPosition = CVector();
return &vecDefaultPosition;
}

// Request model load right now if not loaded yet (#9897)
if (!IsLoaded())
Request(BLOCKING, "GetVehicleDummyPosition");

auto pVehicleModel = reinterpret_cast<CVehicleModelInfoSAInterface*>(m_pInterface);
return pVehicleModel->pVisualInfo->vecDummies[eDummy];
return &pVehicleModel->pVisualInfo->vecDummies[eDummy];
}

void CModelInfoSA::SetVehicleDummyPosition(eVehicleDummies eDummy, const CVector& vecPosition)
{
if (!IsVehicle())
if (!IsVehicle() || eDummy > VEH_UNKNOWNDUMMY)
{
return;
}

// Request model load right now if not loaded yet (#9897)
if (!IsLoaded())
@@ -344,9 +344,9 @@ class CModelInfoSA : public CModelInfo
unsigned int GetNumRemaps(void);
void* GetVehicleSuspensionData(void);
void* SetVehicleSuspensionData(void* pSuspensionLines);
CVector GetVehicleExhaustFumesPosition() override;
CVector* GetVehicleExhaustFumesPosition() override;
void SetVehicleExhaustFumesPosition(const CVector& vecPosition) override;
CVector GetVehicleDummyPosition(eVehicleDummies eDummy) override;
CVector* GetVehicleDummyPosition(eVehicleDummies eDummy) override;
void SetVehicleDummyPosition(eVehicleDummies eDummy, const CVector& vecPosition) override;
static void ResetAllVehicleDummies();

@@ -282,6 +282,7 @@ CClientGame::CClientGame(bool bLocalPlay)
g_pMultiplayer->SetGameEntityRenderHandler(CClientGame::StaticGameEntityRenderHandler);
g_pMultiplayer->SetFxSystemDestructionHandler(CClientGame::StaticFxSystemDestructionHandler);
g_pMultiplayer->SetDrivebyAnimationHandler(CClientGame::StaticDrivebyAnimationHandler);
g_pMultiplayer->SetVehicleAddExhaustParticlesHandler(CClientGame::StaticVehicleAddExhaustParticlesHandler);
g_pMultiplayer->SetPedStepHandler(CClientGame::StaticPedStepHandler);
g_pMultiplayer->SetVehicleWeaponHitHandler(CClientGame::StaticVehicleWeaponHitHandler);
g_pGame->SetPreWeaponFireHandler(CClientGame::PreWeaponFire);
@@ -444,6 +445,7 @@ CClientGame::~CClientGame(void)
g_pMultiplayer->SetGameModelRemoveHandler(NULL);
g_pMultiplayer->SetGameEntityRenderHandler(NULL);
g_pMultiplayer->SetDrivebyAnimationHandler(nullptr);
g_pMultiplayer->SetVehicleAddExhaustParticlesHandler(nullptr);
g_pMultiplayer->SetPedStepHandler(nullptr);
g_pMultiplayer->SetVehicleWeaponHitHandler(nullptr);
g_pGame->SetPreWeaponFireHandler(NULL);
@@ -3809,6 +3811,12 @@ AnimationId CClientGame::StaticDrivebyAnimationHandler(AnimationId animGroup, As
return g_pClientGame->DrivebyAnimationHandler(animGroup, animId);
}

void CClientGame::StaticVehicleAddExhaustParticlesHandler(CVehicleSAInterface* pInterface, CVector** pLeftFumesPosition, CVector** pRightFumesPosition)
{
g_pClientGame->VehicleAddExhaustParticlesHandler(pInterface, pLeftFumesPosition, pRightFumesPosition);

}

void CClientGame::StaticPedStepHandler(CPedSAInterface* pPed, bool bFoot)
{
return g_pClientGame->PedStepHandler(pPed, bFoot);
@@ -6734,6 +6742,38 @@ AnimationId CClientGame::DrivebyAnimationHandler(AnimationId animId, AssocGroupI
return animId;
}

void CClientGame::VehicleAddExhaustParticlesHandler(CVehicleSAInterface* pInterface, CVector** pLeftFumesPosition, CVector** pRightFumesPosition)
{
CPools* pPools = g_pGame->GetPools();
SClientEntity<CVehicleSA>* pVehicleClientEntity = pPools->GetVehicle((DWORD*)pInterface);
if (pVehicleClientEntity)
{
CClientVehicle* pVehicle = reinterpret_cast<CClientVehicle*>(pVehicleClientEntity->pClientEntity);
if (pVehicle)
{
CModelInfo* pModelInfo = pVehicle->GetModelInfo();
if (!pModelInfo)
{
return;
}

*pLeftFumesPosition = pVehicle->GetDummyPosition(EXHAUST_LEFT);
*pRightFumesPosition = pVehicle->GetDummyPosition(EXHAUST_RIGHT);
if (!(*pLeftFumesPosition))
{
*pLeftFumesPosition = pModelInfo->GetVehicleDummyPosition(EXHAUST);
}

if (!(*pRightFumesPosition))
{
*pRightFumesPosition = pModelInfo->GetVehicleDummyPosition(EXHAUST);
(*pRightFumesPosition)->fX *= -1;
}

}
}
}

//////////////////////////////////////////////////////////////////
//
// CClientGame::SetFileCacheRoot
@@ -528,6 +528,7 @@ class CClientGame
static void StaticVehicleWeaponHitHandler(SVehicleWeaponHitEvent& event);

static AnimationId StaticDrivebyAnimationHandler(AnimationId animGroup, AssocGroupId animId);
static void StaticVehicleAddExhaustParticlesHandler(CVehicleSAInterface* pInterface, CVector** pLeftFumesPosition, CVector** pRightFumesPosition);

bool DamageHandler(CPed* pDamagePed, CEventDamage* pEvent);
void DeathHandler(CPed* pKilledPed, unsigned char ucDeathReason, unsigned char ucBodyPart);
@@ -565,7 +566,7 @@ class CClientGame
bool WorldSoundHandler(const SWorldSoundEvent& event);
void TaskSimpleBeHitHandler(CPedSAInterface* pPedAttacker, ePedPieceTypes hitBodyPart, int hitBodySide, int weaponId);
AnimationId DrivebyAnimationHandler(AnimationId animGroup, AssocGroupId animId);

void VehicleAddExhaustParticlesHandler(CVehicleSAInterface* pInterface, CVector** pLeftFumesPosition, CVector** pRightFumesPosition);
static bool StaticProcessMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
bool ProcessMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

@@ -4599,6 +4599,29 @@ bool CClientVehicle::GetComponentScale(const SString& vehicleComponent, CVector&
return false;
}

void CClientVehicle::SetDummyPosition(eVehicleDummies eDummy, const CVector& vecPosition)
{
if (eDummy == EXHAUST)
{
SetDummyPosition(EXHAUST_LEFT, vecPosition);
SetDummyPosition(EXHAUST_RIGHT, {vecPosition.fX*-1,vecPosition.fY, vecPosition.fZ});
return;
}
SVehicleDummy & vehicleDummy = m_arrDummies[eDummy];
vehicleDummy.bSet = true;
vehicleDummy.vecPosition = vecPosition;
}

CVector* CClientVehicle::GetDummyPosition(eVehicleDummies eDummy)
{
SVehicleDummy & vehicleDummy = m_arrDummies[eDummy];
if (vehicleDummy.bSet)
{
return &vehicleDummy.vecPosition;
}
return nullptr;
}

bool CClientVehicle::ResetComponentScale(const SString& vehicleComponent)
{
// set our rotation on the model
@@ -23,6 +23,7 @@ class CClientVehicle;
#include "CClientStreamElement.h"
#include "CClientVehicleManager.h"
#include "CVehicleUpgrades.h"
#include <array>

#define INVALID_PASSENGER_SEAT 0xFF
#define DEFAULT_VEHICLE_HEALTH 1000
@@ -133,6 +134,12 @@ class CClientVehicle : public CClientStreamElement
friend class CClientVehicleManager;
friend class CClientGame; // TEMP HACK

struct SVehicleDummy
{
bool bSet;
CVector vecPosition;
};

protected: // Use CDeathmatchVehicle constructor for now. Will get removed later when this class is
// cleaned up.
CClientVehicle(CClientManager* pManager, ElementID ID, unsigned short usModel, unsigned char ucVariation, unsigned char ucVariation2);
@@ -480,6 +487,9 @@ class CClientVehicle : public CClientStreamElement
bool SetComponentScale(const SString& vehicleComponent, CVector vecScale, EComponentBaseType base = EComponentBase::PARENT);
bool GetComponentScale(const SString& vehicleComponent, CVector& vecScale, EComponentBaseType base = EComponentBase::PARENT);

void SetDummyPosition(eVehicleDummies eDummy, const CVector& vecPosition);
CVector* GetDummyPosition(eVehicleDummies eDummy);

bool SetComponentVisible(const SString& vehicleComponent, bool bVisible);
bool GetComponentVisible(const SString& vehicleComponent, bool& bVisible);
std::map<SString, SVehicleComponentData>::iterator ComponentsBegin(void) { return m_ComponentData.begin(); }
@@ -671,6 +681,8 @@ class CClientVehicle : public CClientStreamElement
unsigned char m_ucFellThroughMapCount;
SFixedArray<bool, MAX_WINDOWS> m_bWindowOpen;

std::array<SVehicleDummy, VEHICLE_TOTAL_MTA_DUMMIES> m_arrDummies = {0};

public:
#ifdef MTA_DEBUG
CClientPlayer* m_pLastSyncer;
@@ -3512,6 +3512,14 @@ bool CStaticFunctionDefinitions::SetVehicleModelDummyPosition(unsigned short usM
if (pModelInfo)
{
pModelInfo->SetVehicleDummyPosition(eDummies, vecPosition);
CClientVehicleManager* pVehicleManager = m_pManager->GetVehicleManager();
for (auto it = pVehicleManager->IterBegin(); it != pVehicleManager->IterEnd(); ++it)
{
if ((*it)->GetModel() == usModel)
{
(*it)->SetDummyPosition(eDummies, vecPosition);
}
}
return true;
}
}
@@ -3525,13 +3533,37 @@ bool CStaticFunctionDefinitions::GetVehicleModelDummyPosition(unsigned short usM
auto pModelInfo = g_pGame->GetModelInfo(usModel);
if (pModelInfo)
{
vecPosition = pModelInfo->GetVehicleDummyPosition(eDummies);
vecPosition = *pModelInfo->GetVehicleDummyPosition(eDummies);
return true;
}
}
return false;
}

bool CStaticFunctionDefinitions::GetVehicleModelDummyPosition(CClientVehicle* pVehicle, unsigned short usModel, eVehicleDummies eDummy, CVector& vecPosition)
{
if (pVehicle)
{
CVector * pPosition = pVehicle->GetDummyPosition(eDummy);
if (pPosition)
{
vecPosition = *pPosition;
return true;
}

if (CStaticFunctionDefinitions::GetVehicleModelDummyPosition(pVehicle->GetModel(), EXHAUST, vecPosition))
{
if (eDummy == EXHAUST_RIGHT)
{
vecPosition.fX *= -1;
}
return true;
}
}

return CStaticFunctionDefinitions::GetVehicleModelDummyPosition(usModel, eDummy, vecPosition);
}

bool CStaticFunctionDefinitions::SetVehicleModelExhaustFumesPosition(unsigned short usModel, CVector& vecPosition)
{
if (CClientVehicleManager::IsValidModel(usModel))
@@ -3553,7 +3585,7 @@ bool CStaticFunctionDefinitions::GetVehicleModelExhaustFumesPosition(unsigned sh
auto pModelInfo = g_pGame->GetModelInfo(usModel);
if (pModelInfo)
{
vecPosition = pModelInfo->GetVehicleExhaustFumesPosition();
vecPosition = *pModelInfo->GetVehicleExhaustFumesPosition();
return true;
}
}
@@ -226,7 +226,7 @@ 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 GetVehicleModelDummyPosition(CClientVehicle* pVehicle, unsigned short usModel, eVehicleDummies eDummy, CVector& vecPosition);
// Vehicle set functions
static bool FixVehicle(CClientEntity& Entity);
static bool BlowVehicle(CClientEntity& Entity);
@@ -522,6 +522,11 @@ ADD_ENUM(HAND_REST, "hand_rest")
ADD_ENUM(EXHAUST_SECONDARY, "exhaust_second")
ADD_ENUM(WING_AIRTRAIL, "wing_airtrail")
ADD_ENUM(VEH_GUN, "veh_gun")
ADD_ENUM(VEH_UNKNOWNDUMMY, "veh_unknowndummy")

// anything above is not part of gta
ADD_ENUM(EXHAUST_LEFT, "exhaust_left")
ADD_ENUM(EXHAUST_RIGHT, "exhaust_right")
IMPLEMENT_ENUM_END("vehicle-dummy")

//
Oops, something went wrong.

0 comments on commit d6b2831

Please sign in to comment.