Skip to content

Commit

Permalink
Merge pull request #9 from lopezloo/master
Browse files Browse the repository at this point in the history
Add is/setVehicleWindowOpen
  • Loading branch information
qaisjp committed Aug 9, 2015
2 parents fabc022 + 696256c commit 7f7e3e1
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 1 deletion.
29 changes: 29 additions & 0 deletions MTA10/game_sa/CVehicleSA.cpp
Expand Up @@ -2743,3 +2743,32 @@ bool CVehicleSA::SetPlateText( const SString& strText )
}
return bReturn;
}

bool CVehicleSA::SetWindowOpenFlagState ( unsigned char ucWindow, bool bState )
{
if ( ucWindow > 6 )
return false;
unsigned char ucWindows [ 7 ] = { 0, 1, 8, 9, 10, 11, 18 };
ucWindow = ucWindows [ ucWindow ];

DWORD dwThis = ( DWORD ) GetVehicleInterface ( );
DWORD dwFunc;
if ( bState )
{
dwFunc = FUNC_CVehicle_SetWindowOpenFlag;
}
else
{
dwFunc = FUNC_CVehicle_ClearWindowOpenFlag;
}
bool bReturn = false;

_asm
{
mov ecx, dwThis
push ucWindow
call dwFunc
mov bReturn, al
}
return bReturn;
}
4 changes: 4 additions & 0 deletions MTA10/game_sa/CVehicleSA.h
Expand Up @@ -123,6 +123,9 @@ class CVehicleSA;
#define FUNC_CVehicle__SetRemap 0x6D0C00
#define FUNC_CVehicle_CustomCarPlate_TextureCreate 0x6D10E0

#define FUNC_CVehicle_SetWindowOpenFlag 0x6D3080
#define FUNC_CVehicle_ClearWindowOpenFlag 0x6D30B0

// from CBike
#define FUNC_Bike_PlaceOnRoadProperly 0x6BEEB0
#define FUNC_Automobile_PlaceOnRoadProperly 0x6AF420
Expand Down Expand Up @@ -783,6 +786,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
bool GetComponentVisible ( const SString& vehicleComponent, bool &bVisible );
std::map < SString, SVehicleFrame > & GetComponentMap ( void ) { return m_ExtraFrames; }
bool SetPlateText ( const SString& strText );
bool SetWindowOpenFlagState ( unsigned char ucWindow, bool bState );

void UpdateLandingGearPosition ( );

Expand Down
10 changes: 10 additions & 0 deletions MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -3365,6 +3365,16 @@ bool CStaticFunctionDefinitions::GetHeliBladeCollisionsEnabled ( CClientVehicle&
return Vehicle.AreHeliBladeCollisionsEnabled ( );
}

bool CStaticFunctionDefinitions::SetVehicleWindowOpen ( CClientVehicle& Vehicle, uchar ucWindow, bool bOpen )
{
return Vehicle.SetWindowOpen ( ucWindow, bOpen );
}

bool CStaticFunctionDefinitions::IsVehicleWindowOpen ( CClientVehicle& Vehicle, uchar ucWindow )
{
return Vehicle.IsWindowOpen ( ucWindow );
}

bool CStaticFunctionDefinitions::SetElementCollisionsEnabled ( CClientEntity& Entity, bool bEnabled )
{
switch ( Entity.GetType () )
Expand Down
2 changes: 2 additions & 0 deletions MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Expand Up @@ -221,6 +221,7 @@ class CStaticFunctionDefinitions
static bool GetVehicleNitroCount ( CClientVehicle& Vehicle, char& cCount );
static bool GetVehicleNitroLevel ( CClientVehicle& Vehicle, float& fLevel );
static bool GetHeliBladeCollisionsEnabled ( CClientVehicle& Vehicle );
static bool IsVehicleWindowOpen ( CClientVehicle& Vehicle, uchar ucWindow );

// Vehicle set functions
static bool FixVehicle ( CClientEntity& Entity );
Expand Down Expand Up @@ -262,6 +263,7 @@ class CStaticFunctionDefinitions
static bool SetVehicleNitroLevel ( CClientEntity& Entity, float fLevel );
static bool SetVehiclePlateText ( CClientEntity& Entity, const SString& strText );
static bool SetHeliBladeCollisionsEnabled ( CClientVehicle& Vehicle, bool bEnabled );
static bool SetVehicleWindowOpen ( CClientVehicle& Vehicle, uchar ucWindow, bool bOpen );

// Object get funcs
static CClientObject* CreateObject ( CResource& Resource, unsigned short usModelID, const CVector& vecPosition, const CVector& vecRotation, bool bLowLod );
Expand Down
27 changes: 26 additions & 1 deletion MTA10/mods/shared_logic/CClientPed.cpp
Expand Up @@ -5576,12 +5576,37 @@ void CClientPed::SetDoingGangDriveby ( bool bDriveby )
}
else if ( bDriveby )
{
bool bRight = ( GetOccupiedVehicleSeat ( ) % 2 == 0 ) ? false : true;
char cSeat = GetOccupiedVehicleSeat ( );
bool bRight = ( cSeat % 2 != 0 );
CTask * pTask = g_pGame->GetTasks ()->CreateTaskSimpleGangDriveBy ( NULL, NULL, 0.0f, 0, 0, bRight );
if ( pTask )
{
pTask->SetAsPedTask ( m_pPlayerPed, TASK_PRIORITY_PRIMARY );
}

char cWindow = -1;
switch ( cSeat )
{
case 0:
cWindow = WINDOW_LEFT_FRONT;
break;

case 1:
cWindow = WINDOW_RIGHT_FRONT;
break;

case 2:
cWindow = WINDOW_LEFT_BACK;
break;

case 3:
cWindow = WINDOW_RIGHT_BACK;
break;
}
if ( cWindow != -1 )
{
GetOccupiedVehicle ( )->SetWindowOpen ( cWindow, true );
}
}
}
m_bDoingGangDriveby = bDriveby;
Expand Down
30 changes: 30 additions & 0 deletions MTA10/mods/shared_logic/CClientVehicle.cpp
Expand Up @@ -145,6 +145,11 @@ CClientVehicle::CClientVehicle ( CClientManager* pManager, ElementID ID, unsigne
m_fNitroLevel = 1.0f;
m_cNitroCount = 0;

for ( unsigned int i = 0; i < MAX_WINDOWS; ++i )
{
m_bWindowOpen [ i ] = false;
}

#ifdef MTA_DEBUG
m_pLastSyncer = NULL;
m_ulLastSyncTime = 0;
Expand Down Expand Up @@ -2829,6 +2834,9 @@ void CClientVehicle::Create ( void )
for ( unsigned char i = 0; i < 6; ++i )
SetDoorOpenRatio ( i, m_fDoorOpenRatio [ i ], 0, true );

for ( unsigned char i = 0; i < MAX_WINDOWS; ++i )
SetWindowOpen ( i, m_bWindowOpen [ i ] );


// Re-apply handling entry
if ( m_pHandlingEntry )
Expand Down Expand Up @@ -4935,3 +4943,25 @@ char CClientVehicle::GetNitroCount ( )
return m_cNitroCount;
}

bool CClientVehicle::SetWindowOpen ( uchar ucWindow, bool bOpen )
{
if ( ucWindow < MAX_WINDOWS )
{
m_bWindowOpen [ ucWindow ] = bOpen;
if ( m_pVehicle )
{
return m_pVehicle->SetWindowOpenFlagState ( ucWindow, bOpen );
}
return true;
}
return false;
}

bool CClientVehicle::IsWindowOpen ( uchar ucWindow )
{
if ( ucWindow < MAX_WINDOWS )
{
return m_bWindowOpen [ ucWindow ];
}
return false;
}
16 changes: 16 additions & 0 deletions MTA10/mods/shared_logic/CClientVehicle.h
Expand Up @@ -63,6 +63,18 @@ enum eDelayedSyncVehicleData
DELAYEDSYNC_VEHICLE_TURNSPEED,
};

enum eWindow
{
WINDOW_BIKESHIELD = 0,
WINDOW_REAR,
WINDOW_RIGHT_FRONT,
WINDOW_RIGHT_BACK,
WINDOW_LEFT_FRONT,
WINDOW_LEFT_BACK,
WINDOW_WINDSHIELD,
MAX_WINDOWS
};

namespace EComponentBase
{
enum EComponentBaseType
Expand Down Expand Up @@ -369,6 +381,9 @@ class CClientVehicle : public CClientStreamElement
void SetNitroCount ( char cCount );
void SetNitroLevel ( float fLevel );

bool IsWindowOpen ( uchar ucWindow );
bool SetWindowOpen ( uchar ucWindow, bool bOpen );

bool IsNitroInstalled ( void );

float GetDistanceFromGround ( void );
Expand Down Expand Up @@ -655,6 +670,7 @@ class CClientVehicle : public CClientStreamElement
bool m_bEnableHeliBladeCollisions;
CMatrix m_matCreate;
unsigned char m_ucFellThroughMapCount;
SFixedArray < bool, MAX_WINDOWS > m_bWindowOpen;

public:
#ifdef MTA_DEBUG
Expand Down
50 changes: 50 additions & 0 deletions MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Vehicle.cpp
Expand Up @@ -3152,3 +3152,53 @@ int CLuaFunctionDefs::GetHeliBladeCollisionsEnabled ( lua_State* luaVM )
lua_pushboolean ( luaVM, false );
return 1;
}


int CLuaFunctionDefs::SetVehicleWindowOpen ( lua_State* luaVM )
{
// bool setVehicleWindowOpen ( vehicle theVehicle, int iWindow, bool bOpen )
CClientVehicle* pVehicle; uchar ucWindow; bool bOpen;

CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pVehicle );
argStream.ReadNumber ( ucWindow );
argStream.ReadBool ( bOpen );

if ( !argStream.HasErrors() )
{
if ( CStaticFunctionDefinitions::SetVehicleWindowOpen ( *pVehicle, ucWindow, bOpen ) )
{
lua_pushboolean ( luaVM, true );
return 1;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

lua_pushboolean ( luaVM, false );
return 1;
}

int CLuaFunctionDefs::IsVehicleWindowOpen ( lua_State* luaVM )
{
// bool isVehicleWindowOpen ( vehicle theVehicle, int iWindow )
CClientVehicle* pVehicle; uchar ucWindow;

CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pVehicle );
argStream.ReadNumber ( ucWindow );

if ( !argStream.HasErrors() )
{
if ( CStaticFunctionDefinitions::IsVehicleWindowOpen ( *pVehicle, ucWindow ) )
{
lua_pushboolean ( luaVM, true );
return 1;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

lua_pushboolean ( luaVM, false );
return 1;
}
2 changes: 2 additions & 0 deletions MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h
Expand Up @@ -353,6 +353,7 @@ class CLuaFunctionDefs
LUA_DECLARE ( GetVehicleNitroCount );
LUA_DECLARE ( GetVehicleNitroLevel );
LUA_DECLARE ( GetHeliBladeCollisionsEnabled );
LUA_DECLARE ( IsVehicleWindowOpen );

// Vehicle set functions
LUA_DECLARE ( FixVehicle );
Expand Down Expand Up @@ -407,6 +408,7 @@ class CLuaFunctionDefs
LUA_DECLARE ( SetVehicleNitroLevel );
LUA_DECLARE ( SetVehiclePlateText );
LUA_DECLARE ( SetHeliBladeCollisionsEnabled );
LUA_DECLARE ( SetVehicleWindowOpen );

// Object create funcs
LUA_DECLARE ( CreateObject );
Expand Down
2 changes: 2 additions & 0 deletions MTA10/mods/shared_logic/lua/CLuaManager.cpp
Expand Up @@ -521,6 +521,7 @@ void CLuaManager::LoadCFunctions ( void )
CLuaCFunctions::AddFunction ( "getVehicleNitroCount", CLuaFunctionDefs::GetVehicleNitroCount );
CLuaCFunctions::AddFunction ( "getVehicleNitroLevel", CLuaFunctionDefs::GetVehicleNitroLevel );
CLuaCFunctions::AddFunction ( "getHeliBladeCollisionsEnabled", CLuaFunctionDefs::GetHeliBladeCollisionsEnabled );
CLuaCFunctions::AddFunction ( "isVehicleWindowOpen", CLuaFunctionDefs::IsVehicleWindowOpen );

// Vehicle set funcs
CLuaCFunctions::AddFunction ( "createVehicle", CLuaFunctionDefs::CreateVehicle );
Expand Down Expand Up @@ -573,6 +574,7 @@ void CLuaManager::LoadCFunctions ( void )
CLuaCFunctions::AddFunction ( "setVehicleNitroLevel", CLuaFunctionDefs::SetVehicleNitroLevel );
CLuaCFunctions::AddFunction ( "setVehiclePlateText", CLuaFunctionDefs::SetVehiclePlateText );
CLuaCFunctions::AddFunction ( "setHeliBladeCollisionsEnabled", CLuaFunctionDefs::SetHeliBladeCollisionsEnabled );
CLuaCFunctions::AddFunction ( "setVehicleWindowOpen", CLuaFunctionDefs::SetVehicleWindowOpen );

// Object create/destroy funcs
CLuaCFunctions::AddFunction ( "createObject", CLuaFunctionDefs::CreateObject );
Expand Down
1 change: 1 addition & 0 deletions MTA10/sdk/game/CVehicle.h
Expand Up @@ -315,6 +315,7 @@ class CVehicle : public virtual CPhysical
virtual std::map < SString, SVehicleFrame > & GetComponentMap ( void ) = 0;
virtual void UpdateLandingGearPosition ( void ) = 0;
virtual bool SetPlateText ( const SString& strText ) = 0;
virtual bool SetWindowOpenFlagState ( unsigned char ucWindow, bool bState ) = 0;
};

#endif

0 comments on commit 7f7e3e1

Please sign in to comment.