1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-21 12:17:12 +01:00

Implement a new event to receive notifications when a vehicle handling rule has changed.

This commit is contained in:
Sandu Liviu Catalin 2016-08-18 15:21:50 +03:00
parent db522913d3
commit f86c12bff2
6 changed files with 45 additions and 7 deletions

View File

@ -501,6 +501,7 @@ protected:
Function mOnTyreStatus; Function mOnTyreStatus;
Function mOnDamageData; Function mOnDamageData;
Function mOnRadio; Function mOnRadio;
Function mOnHandlingRule;
}; };
public: public:
@ -1027,6 +1028,7 @@ public:
void EmitVehicleTyreStatus(Int32 vehicle_id, Int32 old_status, Int32 new_status); void EmitVehicleTyreStatus(Int32 vehicle_id, Int32 old_status, Int32 new_status);
void EmitVehicleDamageData(Int32 vehicle_id, Uint32 old_data, Uint32 new_data); void EmitVehicleDamageData(Int32 vehicle_id, Uint32 old_data, Uint32 new_data);
void EmitVehicleRadio(Int32 vehicle_id, Int32 old_radio, Int32 new_radio); void EmitVehicleRadio(Int32 vehicle_id, Int32 old_radio, Int32 new_radio);
void EmitVehicleHandlingRule(Int32 vehicle_id, Float32 old_data, Float32 new_data);
void EmitServerOption(Int32 option, bool value, Int32 header, Object & payload); void EmitServerOption(Int32 option, bool value, Int32 header, Object & payload);
void EmitScriptReload(Int32 header, Object & payload); void EmitScriptReload(Int32 header, Object & payload);
void EmitScriptLoaded(); void EmitScriptLoaded();
@ -1179,6 +1181,7 @@ private:
Function mOnVehicleTyreStatus; Function mOnVehicleTyreStatus;
Function mOnVehicleDamageData; Function mOnVehicleDamageData;
Function mOnVehicleRadio; Function mOnVehicleRadio;
Function mOnVehicleHandlingRule;
Function mOnServerOption; Function mOnServerOption;
Function mOnScriptReload; Function mOnScriptReload;
Function mOnScriptLoaded; Function mOnScriptLoaded;

View File

@ -885,6 +885,15 @@ void Core::EmitVehicleRadio(Int32 vehicle_id, Int32 old_radio, Int32 new_radio)
Emit(_vehicle.mOnRadio, old_radio, new_radio); Emit(_vehicle.mOnRadio, old_radio, new_radio);
Emit(mOnVehicleRadio, _vehicle.mObj, old_radio, new_radio); Emit(mOnVehicleRadio, _vehicle.mObj, old_radio, new_radio);
} }
// ------------------------------------------------------------------------------------------------
void Core::EmitVehicleHandlingRule(Int32 vehicle_id, Float32 old_data, Float32 new_data)
{
VehicleInst & _vehicle = m_Vehicles.at(vehicle_id);
Emit(_vehicle.mOnHandlingRule, old_data, new_data);
Emit(mOnVehicleHandlingRule, _vehicle.mObj, old_data, new_data);
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Core::EmitServerOption(Int32 option, bool value, Int32 header, Object & payload) void Core::EmitServerOption(Int32 option, bool value, Int32 header, Object & payload)
{ {

View File

@ -260,6 +260,7 @@ void Core::ResetFunc(VehicleInst & inst)
inst.mOnTyreStatus.ReleaseGently(); inst.mOnTyreStatus.ReleaseGently();
inst.mOnDamageData.ReleaseGently(); inst.mOnDamageData.ReleaseGently();
inst.mOnRadio.ReleaseGently(); inst.mOnRadio.ReleaseGently();
inst.mOnHandlingRule.ReleaseGently();
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -376,6 +377,7 @@ void Core::ResetFunc()
Core::Get().mOnVehicleTyreStatus.ReleaseGently(); Core::Get().mOnVehicleTyreStatus.ReleaseGently();
Core::Get().mOnVehicleDamageData.ReleaseGently(); Core::Get().mOnVehicleDamageData.ReleaseGently();
Core::Get().mOnVehicleRadio.ReleaseGently(); Core::Get().mOnVehicleRadio.ReleaseGently();
Core::Get().mOnVehicleHandlingRule.ReleaseGently();
Core::Get().mOnServerOption.ReleaseGently(); Core::Get().mOnServerOption.ReleaseGently();
Core::Get().mOnScriptReload.ReleaseGently(); Core::Get().mOnScriptReload.ReleaseGently();
Core::Get().mOnScriptLoaded.ReleaseGently(); Core::Get().mOnScriptLoaded.ReleaseGently();
@ -497,6 +499,7 @@ Function & Core::GetEvent(Int32 evid)
case EVT_VEHICLETYRESTATUS: return mOnVehicleTyreStatus; case EVT_VEHICLETYRESTATUS: return mOnVehicleTyreStatus;
case EVT_VEHICLEDAMAGEDATA: return mOnVehicleDamageData; case EVT_VEHICLEDAMAGEDATA: return mOnVehicleDamageData;
case EVT_VEHICLERADIO: return mOnVehicleRadio; case EVT_VEHICLERADIO: return mOnVehicleRadio;
case EVT_VEHICLEHANDLINGRULE: return mOnVehicleHandlingRule;
case EVT_SERVEROPTION: return mOnServerOption; case EVT_SERVEROPTION: return mOnServerOption;
case EVT_SCRIPTRELOAD: return mOnScriptReload; case EVT_SCRIPTRELOAD: return mOnScriptReload;
case EVT_SCRIPTLOADED: return mOnScriptLoaded; case EVT_SCRIPTLOADED: return mOnScriptLoaded;
@ -685,6 +688,7 @@ Function & Core::GetVehicleEvent(Int32 id, Int32 evid)
case EVT_VEHICLETYRESTATUS: return inst.mOnTyreStatus; case EVT_VEHICLETYRESTATUS: return inst.mOnTyreStatus;
case EVT_VEHICLEDAMAGEDATA: return inst.mOnDamageData; case EVT_VEHICLEDAMAGEDATA: return inst.mOnDamageData;
case EVT_VEHICLERADIO: return inst.mOnRadio; case EVT_VEHICLERADIO: return inst.mOnRadio;
case EVT_VEHICLEHANDLINGRULE: return inst.mOnHandlingRule;
default: return NullFunction(); default: return NullFunction();
} }
} }

View File

@ -1045,21 +1045,41 @@ Float32 CVehicle::GetHandlingRule(Int32 rule) const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CVehicle::SetHandlingRule(Int32 rule, Float32 data) const void CVehicle::SetHandlingRule(Int32 rule, Float32 data)
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); Validate();
// Perform the requested operation // Grab the current value for this property
const Float32 current = _Func->GetInstHandlingRule(m_ID, rule);
// Avoid property unwind from a recursive call
_Func->SetInstHandlingRule(m_ID, rule, data); _Func->SetInstHandlingRule(m_ID, rule, data);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & VEHICLECL_EMIT_VEHICLE_HANDLINGRULE))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_HANDLINGRULE);
// Now forward the event call
Core::Get().EmitVehicleHandlingRule(m_ID, current, data);
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CVehicle::ResetHandlingRule(Int32 rule) const void CVehicle::ResetHandlingRule(Int32 rule)
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); Validate();
// Perform the requested operation // Grab the current value for this property
const Float32 current = _Func->GetInstHandlingRule(m_ID, rule);
// Avoid property unwind from a recursive call
_Func->ResetInstHandlingRule(m_ID, rule); _Func->ResetInstHandlingRule(m_ID, rule);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & VEHICLECL_EMIT_VEHICLE_HANDLINGRULE))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_HANDLINGRULE);
// Now forward the event call
Core::Get().EmitVehicleHandlingRule(m_ID, current, _Func->GetInstHandlingRule(m_ID, rule));
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -18,7 +18,8 @@ enum VehicleCircularLocks
VEHICLECL_EMIT_VEHICLE_PARTSTATUS = (4 << 0), VEHICLECL_EMIT_VEHICLE_PARTSTATUS = (4 << 0),
VEHICLECL_EMIT_VEHICLE_TYRESTATUS = (5 << 0), VEHICLECL_EMIT_VEHICLE_TYRESTATUS = (5 << 0),
VEHICLECL_EMIT_VEHICLE_DAMAGEDATA = (6 << 0), VEHICLECL_EMIT_VEHICLE_DAMAGEDATA = (6 << 0),
VEHICLECL_EMIT_VEHICLE_RADIO = (7 << 0) VEHICLECL_EMIT_VEHICLE_RADIO = (7 << 0),
VEHICLECL_EMIT_VEHICLE_HANDLINGRULE = (8 << 0)
}; };
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
@ -594,12 +595,12 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the handling data of the managed vehicle entity. * Modify the handling data of the managed vehicle entity.
*/ */
void SetHandlingRule(Int32 rule, Float32 data) const; void SetHandlingRule(Int32 rule, Float32 data);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Reset the specified handling rule for the managed vehicle entity. * Reset the specified handling rule for the managed vehicle entity.
*/ */
void ResetHandlingRule(Int32 rule) const; void ResetHandlingRule(Int32 rule);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Reset all the handling rules for the managed vehicle entity. * Reset all the handling rules for the managed vehicle entity.

View File

@ -396,6 +396,7 @@ enum EventType
EVT_VEHICLETYRESTATUS, EVT_VEHICLETYRESTATUS,
EVT_VEHICLEDAMAGEDATA, EVT_VEHICLEDAMAGEDATA,
EVT_VEHICLERADIO, EVT_VEHICLERADIO,
EVT_VEHICLEHANDLINGRULE,
EVT_SERVEROPTION, EVT_SERVEROPTION,
EVT_SCRIPTRELOAD, EVT_SCRIPTRELOAD,
EVT_SCRIPTLOADED, EVT_SCRIPTLOADED,