diff --git a/source/Core.hpp b/source/Core.hpp index c83cbec6..4bdb71c5 100644 --- a/source/Core.hpp +++ b/source/Core.hpp @@ -501,6 +501,7 @@ protected: Function mOnTyreStatus; Function mOnDamageData; Function mOnRadio; + Function mOnHandlingRule; }; public: @@ -1027,6 +1028,7 @@ public: void EmitVehicleTyreStatus(Int32 vehicle_id, Int32 old_status, Int32 new_status); void EmitVehicleDamageData(Int32 vehicle_id, Uint32 old_data, Uint32 new_data); 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 EmitScriptReload(Int32 header, Object & payload); void EmitScriptLoaded(); @@ -1179,6 +1181,7 @@ private: Function mOnVehicleTyreStatus; Function mOnVehicleDamageData; Function mOnVehicleRadio; + Function mOnVehicleHandlingRule; Function mOnServerOption; Function mOnScriptReload; Function mOnScriptLoaded; diff --git a/source/CoreEvents.cpp b/source/CoreEvents.cpp index b3c4b84e..d79eef8b 100644 --- a/source/CoreEvents.cpp +++ b/source/CoreEvents.cpp @@ -885,6 +885,15 @@ void Core::EmitVehicleRadio(Int32 vehicle_id, Int32 old_radio, Int32 new_radio) Emit(_vehicle.mOnRadio, 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) { diff --git a/source/CoreUtils.cpp b/source/CoreUtils.cpp index 74b9349c..6ee0666d 100644 --- a/source/CoreUtils.cpp +++ b/source/CoreUtils.cpp @@ -260,6 +260,7 @@ void Core::ResetFunc(VehicleInst & inst) inst.mOnTyreStatus.ReleaseGently(); inst.mOnDamageData.ReleaseGently(); inst.mOnRadio.ReleaseGently(); + inst.mOnHandlingRule.ReleaseGently(); } // ------------------------------------------------------------------------------------------------ @@ -376,6 +377,7 @@ void Core::ResetFunc() Core::Get().mOnVehicleTyreStatus.ReleaseGently(); Core::Get().mOnVehicleDamageData.ReleaseGently(); Core::Get().mOnVehicleRadio.ReleaseGently(); + Core::Get().mOnVehicleHandlingRule.ReleaseGently(); Core::Get().mOnServerOption.ReleaseGently(); Core::Get().mOnScriptReload.ReleaseGently(); Core::Get().mOnScriptLoaded.ReleaseGently(); @@ -497,6 +499,7 @@ Function & Core::GetEvent(Int32 evid) case EVT_VEHICLETYRESTATUS: return mOnVehicleTyreStatus; case EVT_VEHICLEDAMAGEDATA: return mOnVehicleDamageData; case EVT_VEHICLERADIO: return mOnVehicleRadio; + case EVT_VEHICLEHANDLINGRULE: return mOnVehicleHandlingRule; case EVT_SERVEROPTION: return mOnServerOption; case EVT_SCRIPTRELOAD: return mOnScriptReload; case EVT_SCRIPTLOADED: return mOnScriptLoaded; @@ -685,6 +688,7 @@ Function & Core::GetVehicleEvent(Int32 id, Int32 evid) case EVT_VEHICLETYRESTATUS: return inst.mOnTyreStatus; case EVT_VEHICLEDAMAGEDATA: return inst.mOnDamageData; case EVT_VEHICLERADIO: return inst.mOnRadio; + case EVT_VEHICLEHANDLINGRULE: return inst.mOnHandlingRule; default: return NullFunction(); } } diff --git a/source/Entity/Vehicle.cpp b/source/Entity/Vehicle.cpp index b6406f7e..ab004dd7 100644 --- a/source/Entity/Vehicle.cpp +++ b/source/Entity/Vehicle.cpp @@ -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(); - // 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); + // 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(); - // 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); + // 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)); + } } // ------------------------------------------------------------------------------------------------ diff --git a/source/Entity/Vehicle.hpp b/source/Entity/Vehicle.hpp index f7c02387..916ee985 100644 --- a/source/Entity/Vehicle.hpp +++ b/source/Entity/Vehicle.hpp @@ -18,7 +18,8 @@ enum VehicleCircularLocks VEHICLECL_EMIT_VEHICLE_PARTSTATUS = (4 << 0), VEHICLECL_EMIT_VEHICLE_TYRESTATUS = (5 << 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. */ - void SetHandlingRule(Int32 rule, Float32 data) const; + void SetHandlingRule(Int32 rule, Float32 data); /* -------------------------------------------------------------------------------------------- * 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. diff --git a/source/SqBase.hpp b/source/SqBase.hpp index 743f612f..3a0db0e2 100644 --- a/source/SqBase.hpp +++ b/source/SqBase.hpp @@ -396,6 +396,7 @@ enum EventType EVT_VEHICLETYRESTATUS, EVT_VEHICLEDAMAGEDATA, EVT_VEHICLERADIO, + EVT_VEHICLEHANDLINGRULE, EVT_SERVEROPTION, EVT_SCRIPTRELOAD, EVT_SCRIPTLOADED,