Skip to content

Function: isVehicleWheelCollided #146

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

Merged
merged 9 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Client/game_sa/CDamageManagerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ VOID CDamageManagerSA::SetDoorStatus ( eDoors bDoor, BYTE bDoorStatus )
}
}

BYTE CDamageManagerSA::GetWheelStatus ( eWheels bWheel )
BYTE CDamageManagerSA::GetWheelStatus ( eWheelPosition bWheel )
{
DEBUG_TRACE("BYTE CDamageManagerSA::GetWheelStatus ( eWheels bWheel )");
DEBUG_TRACE("BYTE CDamageManagerSA::GetWheelStatus ( eWheelPosition bWheel )");
if(bWheel < MAX_WHEELS) return internalInterface->Wheel[bWheel];
return NULL;
}

VOID CDamageManagerSA::SetWheelStatus ( eWheels bWheel, BYTE bTireStatus )
VOID CDamageManagerSA::SetWheelStatus ( eWheelPosition bWheel, BYTE bTireStatus )
{
DEBUG_TRACE("VOID CDamageManagerSA::SetWheelStatus ( eWheels bWheel, BYTE bTireStatus )");
DEBUG_TRACE("VOID CDamageManagerSA::SetWheelStatus ( eWheelPosition bWheel, BYTE bTireStatus )");
if(bWheel < MAX_WHEELS)
{
// Different than before?
Expand Down
4 changes: 2 additions & 2 deletions Client/game_sa/CDamageManagerSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class CDamageManagerSA : public CDamageManager
VOID SetEngineStatus ( BYTE bEngineState );
BYTE GetDoorStatus ( eDoors bDoor );
VOID SetDoorStatus ( eDoors bDoor, BYTE bDoorStatus );
BYTE GetWheelStatus ( eWheels bWheel );
VOID SetWheelStatus ( eWheels bWheel, BYTE bTireStatus );
BYTE GetWheelStatus ( eWheelPosition bWheel );
VOID SetWheelStatus ( eWheelPosition bWheel, BYTE bTireStatus );
BYTE GetPanelStatus ( BYTE bPanel );
unsigned long GetPanelStatus ( void );
VOID SetPanelStatus ( BYTE bPanel, BYTE bPanelStatus );
Expand Down
24 changes: 22 additions & 2 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,26 @@ void CVehicleSA::SetBikeWheelStatus ( BYTE bWheel, BYTE bStatus )
else if ( bWheel == 1 ) * ( BYTE * ) ( (DWORD)this->GetInterface() + 0x65D ) = bStatus;
}

bool CVehicleSA::IsWheelCollided ( BYTE eWheelPosition )
{
CVehicleSAInterface * vehicle = (CVehicleSAInterface *)this->GetInterface ();

switch ( vehicle->m_type )
{
case 0:
if ( eWheelPosition < 4 )
return vehicle->wheelCollisionState[eWheelPosition] == 4.f;
break;

case 9:
if ( eWheelPosition < 2 )
return *(float *)( (DWORD)vehicle + 0x730 + eWheelPosition * 8 ) == 4.f ||
*(float *)( (DWORD)vehicle + 0x734 + eWheelPosition * 8 ) == 4.f;
break;
}
return false;
}

void CVehicleSA::SetTaxiLightOn ( bool bLightOn )
{
DEBUG_TRACE("void CVehicleSA::SetTaxiLight ( bool bLightOn )");
Expand Down Expand Up @@ -2127,7 +2147,7 @@ CObject * CVehicleSA::SpawnFlyingComponent ( int i_1, unsigned int ui_2 )
}


void CVehicleSA::SetWheelVisibility ( eWheels wheel, bool bVisible )
void CVehicleSA::SetWheelVisibility ( eWheelPosition wheel, bool bVisible )
{
CVehicleSAInterface * vehicle = (CVehicleSAInterface *)this->GetInterface();
RwFrame * pFrame = NULL;
Expand Down Expand Up @@ -2157,7 +2177,7 @@ void CVehicleSA::SetWheelVisibility ( eWheels wheel, bool bVisible )
}


CVector CVehicleSA::GetWheelPosition ( eWheels wheel )
CVector CVehicleSA::GetWheelPosition ( eWheelPosition wheel )
{
switch (wheel)
{
Expand Down
25 changes: 19 additions & 6 deletions Client/game_sa/CVehicleSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,13 @@ class CVehicleSAInterface : public CPhysicalSAInterface
RwTexture* m_pCustomPlateTexture;

//1420
BYTE Padding225[20];
BYTE Padding225[4];

//1424
BYTE m_type; // 0 = car/plane, 5 = boat, 6 = train, 9 = bike

//1425
BYTE Padding226[15];

//1440
unsigned char m_ucTrackNodeID; // Current node on train tracks
Expand Down Expand Up @@ -493,7 +499,6 @@ class CVehicleSAInterface : public CPhysicalSAInterface
RwFrame * pWindscreen;
RwFrame * pExhaust;


// Hacked in from jb-contribs branch
RwFrame * pSpecialParts[5]; // 1688
RwFrame * pExtraParts[5]; // 1708
Expand All @@ -504,11 +509,17 @@ class CVehicleSAInterface : public CPhysicalSAInterface
CColPointSAInterface WheelFrontRightColPoint;
CColPointSAInterface WheelRearRightColPoint;

BYTE padding280[260];
BYTE padding275[32];
// 2036
float wheelCollisionState[MAX_WHEELS];

// 2052
BYTE padding280[224];

// 2276
float m_fBurningTime;
};
static_assert(sizeof(CVehicleSAInterface) == 1688 + 576 + 4 , "Invalid size for CVehicleSAInterface");
static_assert(sizeof(CVehicleSAInterface) == 1688 + 576 + 4 + 12 , "Invalid size for CVehicleSAInterface");

class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
{
Expand Down Expand Up @@ -727,15 +738,17 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
BYTE GetBikeWheelStatus ( BYTE bWheel );
void SetBikeWheelStatus ( BYTE bWheel, BYTE bStatus );

bool IsWheelCollided ( BYTE eWheelPosition );

void GetGravity ( CVector* pvecGravity ) const { *pvecGravity = m_vecGravity; }
void SetGravity ( const CVector* pvecGravity );

inline SColor GetHeadLightColor ( void ) { return m_HeadLightColor; }
inline void SetHeadLightColor ( const SColor color ) { m_HeadLightColor = color; }

CObject * SpawnFlyingComponent ( int i_1, unsigned int ui_2 );
void SetWheelVisibility ( eWheels wheel, bool bVisible );
CVector GetWheelPosition ( eWheels wheel );
void SetWheelVisibility ( eWheelPosition wheel, bool bVisible );
CVector GetWheelPosition ( eWheelPosition wheel );

bool IsHeliSearchLightVisible ( void );
void SetHeliSearchLightVisible ( bool bVisible );
Expand Down
10 changes: 7 additions & 3 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ unsigned char CClientVehicle::GetWheelStatus ( unsigned char ucWheel )
if ( m_pVehicle )
{
if ( HasDamageModel () )
return m_pVehicle->GetDamageManager ()->GetWheelStatus ( static_cast < eWheels > ( ucWheel ) );
return m_pVehicle->GetDamageManager ()->GetWheelStatus ( static_cast < eWheelPosition > ( ucWheel ) );
if ( m_eVehicleType == CLIENTVEHICLE_BIKE && ucWheel < 2 )
return m_pVehicle->GetBikeWheelStatus ( ucWheel );
}
Expand All @@ -1498,6 +1498,10 @@ unsigned char CClientVehicle::GetWheelStatus ( unsigned char ucWheel )
return 0;
}

bool CClientVehicle::IsWheelCollided ( unsigned char ucWheel )
{
return m_pVehicle->IsWheelCollided ( ucWheel );
}

unsigned char CClientVehicle::GetPanelStatus ( unsigned char ucPanel )
{
Expand Down Expand Up @@ -1559,10 +1563,10 @@ void CClientVehicle::SetWheelStatus ( unsigned char ucWheel, unsigned char ucSta
// Do we have a damage model?
if ( HasDamageModel () )
{
m_pVehicle->GetDamageManager ()->SetWheelStatus ( ( eWheels ) ( ucWheel ), ucGTAStatus );
m_pVehicle->GetDamageManager ()->SetWheelStatus ( ( eWheelPosition ) ( ucWheel ), ucGTAStatus );

// Update the wheel's visibility
m_pVehicle->SetWheelVisibility ( ( eWheels ) ucWheel, ( ucStatus != DT_WHEEL_MISSING ) );
m_pVehicle->SetWheelVisibility ( ( eWheelPosition ) ucWheel, ( ucStatus != DT_WHEEL_MISSING ) );
}
else if ( m_eVehicleType == CLIENTVEHICLE_BIKE && ucWheel < 2 )
m_pVehicle->SetBikeWheelStatus ( ucWheel, ucGTAStatus );
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class CClientVehicle : public CClientStreamElement
bool HasDamageModel ( void ) { return m_bHasDamageModel; }
unsigned char GetDoorStatus ( unsigned char ucDoor );
unsigned char GetWheelStatus ( unsigned char ucWheel );
bool IsWheelCollided ( unsigned char ucWheel );
unsigned char GetPanelStatus ( unsigned char ucPanel );
unsigned char GetLightStatus ( unsigned char ucLight );

Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientWeapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void CClientWeapon::Fire ( bool bServerFire )
if ( m_itargetWheel <= MAX_WHEELS )
{
CClientVehicle * pTarget = (CClientVehicle*)(CClientEntity *)m_pTarget;
vecTarget = pTarget->GetGameVehicle()->GetWheelPosition ( (eWheels)m_itargetWheel );
vecTarget = pTarget->GetGameVehicle()->GetWheelPosition ( (eWheelPosition)m_itargetWheel );
}
else
m_pTarget->GetPosition( vecTarget );
Expand Down
6 changes: 6 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,12 @@ IMPLEMENT_ENUM_BEGIN ( eCursorType )
ADD_ENUM ( CURSORTYPE_SEG_SIZING, "segment_sizing" ) // segment sizing cursor (note: not in use)
IMPLEMENT_ENUM_END ( "cursor-type" )

IMPLEMENT_ENUM_BEGIN ( eWheelPosition )
ADD_ENUM ( FRONT_LEFT_WHEEL, "front_left" )
ADD_ENUM ( REAR_LEFT_WHEEL, "rear_left" )
ADD_ENUM ( FRONT_RIGHT_WHEEL, "front_right" )
ADD_ENUM ( REAR_RIGHT_WHEEL, "rear_right" )
IMPLEMENT_ENUM_END ( "wheel-position" )

//
// Get best guess at name of userdata type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ DECLARE_ENUM( EComponentBase::EComponentBaseType );
DECLARE_ENUM( eWebBrowserMouseButton );
DECLARE_ENUM( eTrayIconType )
DECLARE_ENUM( eCursorType )
DECLARE_ENUM( eWheelPosition )

enum eDXHorizontalAlign
{
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 @@ -40,6 +40,7 @@ void CLuaVehicleDefs::LoadFunctions ( void )
CLuaCFunctions::AddFunction ( "getVehiclePaintjob", GetVehiclePaintjob );
CLuaCFunctions::AddFunction ( "getVehiclePlateText", GetVehiclePlateText );
CLuaCFunctions::AddFunction ( "getVehicleWheelStates", GetVehicleWheelStates );
CLuaCFunctions::AddFunction ( "isVehicleWheelCollided", IsVehicleWheelCollided );
CLuaCFunctions::AddFunction ( "isVehicleDamageProof", IsVehicleDamageProof );
CLuaCFunctions::AddFunction ( "isVehicleFuelTankExplodable", IsVehicleFuelTankExplodable );
CLuaCFunctions::AddFunction ( "isVehicleFrozen", IsVehicleFrozen );
Expand Down Expand Up @@ -170,6 +171,7 @@ void CLuaVehicleDefs::AddClass ( lua_State* luaVM )
lua_classfunction ( luaVM, "getPaintjob", "getVehiclePaintjob" );
lua_classfunction ( luaVM, "getTurretPosition", "getVehicleTurretPosition" );
lua_classfunction ( luaVM, "getWheelStates", "getVehicleWheelStates" );
lua_classfunction ( luaVM, "isWheelCollided", "isVehicleWheelCollided" );
lua_classfunction ( luaVM, "getDoorOpenRatio", "getVehicleDoorOpenRatio" );
lua_classfunction ( luaVM, "getVariant", "getVehicleVariant" );
lua_classfunction ( luaVM, "getHandling", "getVehicleHandling" );
Expand Down Expand Up @@ -913,6 +915,22 @@ int CLuaVehicleDefs::GetVehicleWheelStates ( lua_State* luaVM )
return 1;
}

int CLuaVehicleDefs::IsVehicleWheelCollided ( lua_State* luaVM )
{
CClientVehicle* pVehicle = nullptr; eWheelPosition wheel;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pVehicle );
argStream.ReadEnumStringOrNumber ( wheel );

if ( !argStream.HasErrors () )
lua_pushboolean ( luaVM, pVehicle->IsWheelCollided ( wheel ) );
else
{
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
lua_pushboolean ( luaVM, false );
}
return 1;
}

int CLuaVehicleDefs::GetVehicleDoorState ( lua_State* luaVM )
{
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CLuaVehicleDefs : public CLuaDefs
LUA_DECLARE ( GetVehicleUpgradeSlotName );
LUA_DECLARE ( GetVehicleCompatibleUpgrades );
LUA_DECLARE ( GetVehicleWheelStates );
LUA_DECLARE ( IsVehicleWheelCollided );
LUA_DECLARE ( GetVehicleDoorState );
LUA_DECLARE ( GetVehicleLightState );
LUA_DECLARE ( GetVehiclePanelState );
Expand Down
6 changes: 3 additions & 3 deletions Client/sdk/game/CDamageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ enum eDoors
MAX_DOORS
};

enum eWheels
enum eWheelPosition
{
FRONT_LEFT_WHEEL = 0,
REAR_LEFT_WHEEL,
Expand Down Expand Up @@ -131,8 +131,8 @@ class CDamageManager
virtual VOID SetEngineStatus ( BYTE bEngineState ) = 0;
virtual BYTE GetDoorStatus ( eDoors bDoor ) = 0;
virtual VOID SetDoorStatus ( eDoors bDoor, BYTE bDoorStatus ) = 0;
virtual BYTE GetWheelStatus ( eWheels bTire ) = 0;
virtual VOID SetWheelStatus ( eWheels bTire, BYTE bTireStatus ) = 0;
virtual BYTE GetWheelStatus ( eWheelPosition bTire ) = 0;
virtual VOID SetWheelStatus ( eWheelPosition bTire, BYTE bTireStatus ) = 0;
virtual BYTE GetPanelStatus ( BYTE bPanel ) = 0;
virtual unsigned long GetPanelStatus ( void ) = 0;
virtual VOID SetPanelStatus ( BYTE bPanel, BYTE bPanelStatus ) = 0;
Expand Down
6 changes: 4 additions & 2 deletions Client/sdk/game/CVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class CVehicle : public virtual CPhysical
virtual BYTE GetBikeWheelStatus ( BYTE bWheel ) = 0;
virtual void SetBikeWheelStatus ( BYTE bWheel, BYTE bStatus ) = 0;

virtual bool IsWheelCollided ( BYTE bWheel ) = 0;

virtual class CVehicleSAInterface* GetVehicleInterface () = 0;


Expand Down Expand Up @@ -265,8 +267,8 @@ class CVehicle : public virtual CPhysical
virtual void SetHeadLightColor ( const SColor color ) = 0;

virtual CObject * SpawnFlyingComponent ( int i_1, unsigned int ui_2 ) = 0;
virtual void SetWheelVisibility ( eWheels wheel, bool bVisible ) = 0;
virtual CVector GetWheelPosition ( eWheels wheel ) = 0;
virtual void SetWheelVisibility ( eWheelPosition wheel, bool bVisible ) = 0;
virtual CVector GetWheelPosition ( eWheelPosition wheel ) = 0;

virtual bool IsHeliSearchLightVisible ( void ) = 0;
virtual void SetHeliSearchLightVisible ( bool bVisible ) = 0;
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ enum eDoors
MAX_DOORS
};

enum eWheels
enum eWheelPosition
{
FRONT_LEFT_WHEEL = 0,
REAR_LEFT_WHEEL,
Expand Down