Skip to content

Commit

Permalink
Add rotor functions for plane (#2548)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Alejandro González <[email protected]>
Co-authored-by: lopez <[email protected]>
Co-authored-by: patrikjuvonen <[email protected]>
  • Loading branch information
4 people authored Dec 20, 2023
1 parent a81ea88 commit a920915
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 2 deletions.
31 changes: 30 additions & 1 deletion Client/game_sa/CPlaneSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,41 @@ class CPlaneSAInterface : public CAutomobileSAInterface
{
// + 2508 = undercarrige possition (float - 1.0 = up, 0.0 = down)
// fill this
public:
float m_fLeftRightSkid;
float m_fSteeringUpDown;
float m_fSteeringLeftRight;
float m_fAccelerationBreakStatus;
float m_fAccelerationBreakStatusPrev;
float m_fSteeringFactor;
float field_9A0;
float m_planeCreationHeading; // The heading when plane is created or placed on road properly
float m_maxAltitude;
float m_altitude;
float m_minAltitude;
float m_planeHeading;
float m_planeHeadingPrev;
float m_forwardZ;
uint32_t m_nStartedFlyingTime;
float m_fPropSpeed; // Rotor speed 0x09C4
float field_9C8;
float m_fLandingGearStatus;
int32_t m_planeDamageWave;
FxSystem_c** m_pGunParticles;
uint8_t m_nFiringMultiplier;
int32_t field_9DC;
int32_t field_9E0;
int32_t field_9E4;
FxSystem_c* m_apJettrusParticles[4];
FxSystem_c* m_pSmokeParticle;
uint32_t m_nSmokeTimer;
bool m_bSmokeEjectorEnabled;
};
static_assert(sizeof(CPlaneSAInterface) == 0xA04, "Invalid size for CPlaneSAInterface");

class CPlaneSA final : public virtual CPlane, public virtual CAutomobileSA
{
public:
CPlaneSA(CPlaneSAInterface* pInterface);

CPlaneSAInterface* GetPlaneInterface() { return reinterpret_cast<CPlaneSAInterface*>(GetInterface()); }
};
13 changes: 13 additions & 0 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CGameSA.h"
#include "CProjectileInfoSA.h"
#include "CTrainSA.h"
#include "CPlaneSA.h"
#include "CVehicleSA.h"
#include "CVisibilityPluginsSA.h"
#include "CWorldSA.h"
Expand Down Expand Up @@ -487,6 +488,18 @@ void CVehicleSA::SetTrainSpeed(float fSpeed)
pInterface->m_fTrainSpeed = fSpeed;
}

void CVehicleSA::SetPlaneRotorSpeed(float fSpeed)
{
auto pInterface = static_cast<CPlaneSAInterface*>(GetInterface());
pInterface->m_fPropSpeed = fSpeed;
}

float CVehicleSA::GetPlaneRotorSpeed()
{
auto pInterface = static_cast<CPlaneSAInterface*>(GetInterface());
return pInterface->m_fPropSpeed;
}

bool CVehicleSA::GetTrainDirection()
{
auto pInterface = static_cast<CTrainSAInterface*>(GetInterface());
Expand Down
3 changes: 3 additions & 0 deletions Client/game_sa/CVehicleSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
bool GetTyresDontBurst() { return GetVehicleInterface()->m_nVehicleFlags.bTyresDontBurst; };
unsigned short GetAdjustablePropertyValue() { return *reinterpret_cast<unsigned short*>(reinterpret_cast<unsigned long>(m_pInterface) + 2156); };
float GetHeliRotorSpeed() { return *reinterpret_cast<float*>(reinterpret_cast<unsigned int>(m_pInterface) + 2124); };
float GetPlaneRotorSpeed();

unsigned long GetExplodeTime() { return *reinterpret_cast<unsigned long*>(reinterpret_cast<unsigned int>(m_pInterface) + 1240); };

char GetNitroCount() { return GetVehicleInterface()->m_nNitroBoosts; }
Expand All @@ -565,6 +567,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
*reinterpret_cast<unsigned short*>(reinterpret_cast<unsigned int>(m_pInterface) + 2156) = usAdjustableProperty;
};
void SetHeliRotorSpeed(float fSpeed) { *reinterpret_cast<float*>(reinterpret_cast<unsigned int>(m_pInterface) + 2124) = fSpeed; };
void SetPlaneRotorSpeed(float fSpeed);
void SetExplodeTime(unsigned long ulTime) { *reinterpret_cast<unsigned long*>(reinterpret_cast<unsigned int>(m_pInterface) + 1240) = ulTime; };
void SetRadioStatus(bool bStatus) { *reinterpret_cast<unsigned char*>(reinterpret_cast<unsigned int>(m_pInterface) + 0x1D3) = bStatus; };

Expand Down
48 changes: 48 additions & 0 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ CClientVehicle::CClientVehicle(CClientManager* pManager, ElementID ID, unsigned
m_HeadLightColor = SColorRGBA(255, 255, 255, 255);
m_bHeliSearchLightVisible = false;
m_fHeliRotorSpeed = 0.0f;
m_fPlaneRotorSpeed = 0.0f;
m_bHasCustomHandling = false;
m_ucVariation = ucVariation;
m_ucVariation2 = ucVariation2;
Expand Down Expand Up @@ -1537,6 +1538,14 @@ float CClientVehicle::GetHeliRotorSpeed()
return m_fHeliRotorSpeed;
}

float CClientVehicle::GetPlaneRotorSpeed()
{
if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_PLANE)
return m_pVehicle->GetPlaneRotorSpeed();

return m_fPlaneRotorSpeed;
}

void CClientVehicle::SetHeliRotorSpeed(float fSpeed)
{
if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI)
Expand All @@ -1545,6 +1554,45 @@ void CClientVehicle::SetHeliRotorSpeed(float fSpeed)
m_fHeliRotorSpeed = fSpeed;
}

void CClientVehicle::SetPlaneRotorSpeed(float fSpeed)
{
if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_PLANE)
m_pVehicle->SetPlaneRotorSpeed(fSpeed);

m_fPlaneRotorSpeed = fSpeed;
}

bool CClientVehicle::GetRotorSpeed(float& speed)
{
if (m_eVehicleType == CLIENTVEHICLE_PLANE)
{
speed = GetPlaneRotorSpeed();
return true;
}
else if (m_eVehicleType == CLIENTVEHICLE_HELI)
{
speed = GetHeliRotorSpeed();
return true;
}

return false;
}

bool CClientVehicle::SetRotorSpeed(float fSpeed)
{
switch (m_eVehicleType)
{
case CLIENTVEHICLE_HELI:
SetHeliRotorSpeed(fSpeed);
return true;
case CLIENTVEHICLE_PLANE:
SetPlaneRotorSpeed(fSpeed);
return true;
default:
return false;
}
}

bool CClientVehicle::IsHeliSearchLightVisible()
{
if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI)
Expand Down
8 changes: 7 additions & 1 deletion Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,13 @@ class CClientVehicle : public CClientStreamElement

// TODO: Make the class remember on virtualization
float GetHeliRotorSpeed();
void SetHeliRotorSpeed(float fSpeed);
float GetPlaneRotorSpeed();

bool GetRotorSpeed(float&);
bool SetRotorSpeed(float);

void SetHeliRotorSpeed(float fSpeed);
void SetPlaneRotorSpeed(float fSpeed);
bool IsHeliSearchLightVisible();
void SetHeliSearchLightVisible(bool bVisible);

Expand Down Expand Up @@ -641,6 +646,7 @@ class CClientVehicle : public CClientStreamElement
bool m_bIsOnGround;
bool m_bHeliSearchLightVisible;
float m_fHeliRotorSpeed;
float m_fPlaneRotorSpeed;
const CHandlingEntry* m_pOriginalHandlingEntry = nullptr;
CHandlingEntry* m_pHandlingEntry = nullptr;
const CFlyingHandlingEntry* m_pOriginalFlyingHandlingEntry = nullptr;
Expand Down
18 changes: 18 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void CLuaVehicleDefs::LoadFunctions()
{"getVehicleNameFromModel", GetVehicleNameFromModel},
{"getVehicleAdjustableProperty", GetVehicleAdjustableProperty},
{"getHelicopterRotorSpeed", GetHelicopterRotorSpeed},
{"getVehicleRotorSpeed", ArgumentParser<GetVehicleRotorSpeed>},
{"getVehicleEngineState", GetVehicleEngineState},
{"isTrainDerailed", IsTrainDerailed},
{"isTrainDerailable", IsTrainDerailable},
Expand Down Expand Up @@ -118,6 +119,7 @@ void CLuaVehicleDefs::LoadFunctions()
{"setVehicleFrozen", SetVehicleFrozen},
{"setVehicleAdjustableProperty", SetVehicleAdjustableProperty},
{"setHelicopterRotorSpeed", SetHelicopterRotorSpeed},
{"setVehicleRotorSpeed", ArgumentParser<SetVehicleRotorSpeed>},
{"setTrainDerailed", SetTrainDerailed},
{"setTrainDerailable", SetTrainDerailable},
{"setTrainDirection", SetTrainDirection},
Expand Down Expand Up @@ -1293,6 +1295,17 @@ int CLuaVehicleDefs::GetHelicopterRotorSpeed(lua_State* luaVM)
return 1;
}

std::variant<bool, float> CLuaVehicleDefs::GetVehicleRotorSpeed(CClientVehicle* pVehicle)
{
float fSpeed;
if (pVehicle->GetRotorSpeed(fSpeed))
{
return fSpeed;
}
else
return false;
}

int CLuaVehicleDefs::IsTrainDerailed(lua_State* luaVM)
{
CClientVehicle* pVehicle = NULL;
Expand Down Expand Up @@ -2204,6 +2217,11 @@ int CLuaVehicleDefs::SetHelicopterRotorSpeed(lua_State* luaVM)
return 1;
}

bool CLuaVehicleDefs::SetVehicleRotorSpeed(CClientVehicle* pVehicle, float fSpeed)
{
return pVehicle->SetRotorSpeed(fSpeed);
}

int CLuaVehicleDefs::SetTrainDerailed(lua_State* luaVM)
{
CClientVehicle* pVehicle = NULL;
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CLuaVehicleDefs : public CLuaDefs
LUA_DECLARE(GetVehicleNameFromModel);
LUA_DECLARE(GetVehicleAdjustableProperty);
LUA_DECLARE(GetHelicopterRotorSpeed);
static std::variant<bool, float> GetVehicleRotorSpeed(CClientVehicle* pVehicle);
LUA_DECLARE(GetVehicleEngineState);
LUA_DECLARE(IsTrainDerailed);
LUA_DECLARE(IsTrainDerailable);
Expand Down Expand Up @@ -117,6 +118,7 @@ class CLuaVehicleDefs : public CLuaDefs
LUA_DECLARE(SetVehicleFrozen);
LUA_DECLARE(SetVehicleAdjustableProperty);
LUA_DECLARE(SetHelicopterRotorSpeed);
static bool SetVehicleRotorSpeed(CClientVehicle* pVehicle, float fSpeed);
LUA_DECLARE(SetTrainDerailed);
LUA_DECLARE(SetTrainDerailable);
LUA_DECLARE(SetTrainDirection);
Expand Down
2 changes: 2 additions & 0 deletions Client/sdk/game/CVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class CVehicle : public virtual CPhysical
virtual bool GetTyresDontBurst() = 0;
virtual unsigned short GetAdjustablePropertyValue() = 0;
virtual float GetHeliRotorSpeed() = 0;
virtual float GetPlaneRotorSpeed() = 0;
virtual unsigned long GetExplodeTime() = 0;

virtual char GetNitroCount() = 0;
Expand All @@ -219,6 +220,7 @@ class CVehicle : public virtual CPhysical
virtual void SetTyresDontBurst(bool bTyresDontBurst) = 0;
virtual void SetAdjustablePropertyValue(unsigned short usAdjustableProperty) = 0;
virtual void SetHeliRotorSpeed(float fSpeed) = 0;
virtual void SetPlaneRotorSpeed(float fSpeed) = 0;
virtual void SetTaxiLightOn(bool bLightState) = 0;
virtual void SetExplodeTime(unsigned long ulTime) = 0;
virtual void SetRadioStatus(bool bStatus) = 0;
Expand Down

0 comments on commit a920915

Please sign in to comment.