diff --git a/source/Core.hpp b/source/Core.hpp index 46ec87c6..1256ac29 100644 --- a/source/Core.hpp +++ b/source/Core.hpp @@ -499,6 +499,7 @@ protected: Function mOnImmunity; Function mOnPartStatus; Function mOnTyreStatus; + Function mOnDamageData; }; public: @@ -1023,6 +1024,7 @@ public: void EmitVehicleImmunity(Int32 vehicle_id, Int32 old_immunity, Int32 new_immunity); void EmitVehiclePartStatus(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 EmitServerOption(Int32 option, bool value, Int32 header, Object & payload); void EmitScriptReload(Int32 header, Object & payload); void EmitScriptLoaded(); @@ -1173,6 +1175,7 @@ private: Function mOnVehicleImmunity; Function mOnVehiclePartStatus; Function mOnVehicleTyreStatus; + Function mOnVehicleDamageData; Function mOnServerOption; Function mOnScriptReload; Function mOnScriptLoaded; diff --git a/source/CoreEvents.cpp b/source/CoreEvents.cpp index e660411f..d1ec582d 100644 --- a/source/CoreEvents.cpp +++ b/source/CoreEvents.cpp @@ -870,6 +870,14 @@ void Core::EmitVehicleTyreStatus(Int32 vehicle_id, Int32 old_status, Int32 new_s Emit(mOnVehicleTyreStatus, _vehicle.mObj, old_status, new_status); } +// ------------------------------------------------------------------------------------------------ +void Core::EmitVehicleDamageData(Int32 vehicle_id, Uint32 old_data, Uint32 new_data) +{ + VehicleInst & _vehicle = m_Vehicles.at(vehicle_id); + Emit(_vehicle.mOnDamageData, old_data, new_data); + Emit(mOnVehicleDamageData, _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 25337ace..d12374d7 100644 --- a/source/CoreUtils.cpp +++ b/source/CoreUtils.cpp @@ -258,6 +258,7 @@ void Core::ResetFunc(VehicleInst & inst) inst.mOnImmunity.ReleaseGently(); inst.mOnPartStatus.ReleaseGently(); inst.mOnTyreStatus.ReleaseGently(); + inst.mOnDamageData.ReleaseGently(); } // ------------------------------------------------------------------------------------------------ @@ -372,6 +373,7 @@ void Core::ResetFunc() Core::Get().mOnVehicleImmunity.ReleaseGently(); Core::Get().mOnVehiclePartStatus.ReleaseGently(); Core::Get().mOnVehicleTyreStatus.ReleaseGently(); + Core::Get().mOnVehicleDamageData.ReleaseGently(); Core::Get().mOnServerOption.ReleaseGently(); Core::Get().mOnScriptReload.ReleaseGently(); Core::Get().mOnScriptLoaded.ReleaseGently(); @@ -491,6 +493,7 @@ Function & Core::GetEvent(Int32 evid) case EVT_VEHICLEIMMUNITY: return mOnVehicleImmunity; case EVT_VEHICLEPARTSTATUS: return mOnVehiclePartStatus; case EVT_VEHICLETYRESTATUS: return mOnVehicleTyreStatus; + case EVT_VEHICLEDAMAGEDATA: return mOnVehicleDamageData; case EVT_SERVEROPTION: return mOnServerOption; case EVT_SCRIPTRELOAD: return mOnScriptReload; case EVT_SCRIPTLOADED: return mOnScriptLoaded; @@ -677,6 +680,7 @@ Function & Core::GetVehicleEvent(Int32 id, Int32 evid) case EVT_VEHICLEIMMUNITY: return inst.mOnImmunity; case EVT_VEHICLEPARTSTATUS: return inst.mOnPartStatus; case EVT_VEHICLETYRESTATUS: return inst.mOnTyreStatus; + case EVT_VEHICLEDAMAGEDATA: return inst.mOnDamageData; default: return NullFunction(); } } diff --git a/source/Entity/Vehicle.cpp b/source/Entity/Vehicle.cpp index e2f563fd..70924cd3 100644 --- a/source/Entity/Vehicle.cpp +++ b/source/Entity/Vehicle.cpp @@ -931,12 +931,27 @@ Uint32 CVehicle::GetDamageData() const } // ------------------------------------------------------------------------------------------------ -void CVehicle::SetDamageData(Uint32 data) const +void CVehicle::SetDamageData(Uint32 data) { // Validate the managed identifier Validate(); - // Perform the requested operation + // Grab the current value for this property + const Uint32 current = _Func->GetVehicleDamageData(m_ID); + // Don't even bother if it's the same value + if (current == data) + { + return; + } + // Avoid property unwind from a recursive call _Func->SetVehicleDamageData(m_ID, data); + // Avoid infinite recursive event loops + if (!(m_CircularLocks & VEHICLECL_EMIT_VEHICLE_DAMAGEDATA)) + { + // Prevent this event from triggering while executed + BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_DAMAGEDATA); + // Now forward the event call + Core::Get().EmitVehicleDamageData(m_ID, current, data); + } } // ------------------------------------------------------------------------------------------------ diff --git a/source/Entity/Vehicle.hpp b/source/Entity/Vehicle.hpp index d9fecb0b..1ab6609f 100644 --- a/source/Entity/Vehicle.hpp +++ b/source/Entity/Vehicle.hpp @@ -16,7 +16,8 @@ enum VehicleCircularLocks VEHICLECL_EMIT_VEHICLE_WORLD = (2 << 0), VEHICLECL_EMIT_VEHICLE_IMMUNITY = (3 << 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) }; /* ------------------------------------------------------------------------------------------------ @@ -552,7 +553,7 @@ public: /* -------------------------------------------------------------------------------------------- * Modify the damage data of the managed vehicle entity. */ - void SetDamageData(Uint32 data) const; + void SetDamageData(Uint32 data); /* -------------------------------------------------------------------------------------------- * Retrieve the radio of the managed vehicle entity. diff --git a/source/SqBase.hpp b/source/SqBase.hpp index b0f04e87..dafc5b2f 100644 --- a/source/SqBase.hpp +++ b/source/SqBase.hpp @@ -394,6 +394,7 @@ enum EventType EVT_VEHICLEIMMUNITY, EVT_VEHICLEPARTSTATUS, EVT_VEHICLETYRESTATUS, + EVT_VEHICLEDAMAGEDATA, EVT_SERVEROPTION, EVT_SCRIPTRELOAD, EVT_SCRIPTLOADED,