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 damage data has changed.

This commit is contained in:
Sandu Liviu Catalin 2016-08-18 15:06:03 +03:00
parent 05443ba2d4
commit 69325ed2cc
6 changed files with 36 additions and 4 deletions

View File

@ -499,6 +499,7 @@ protected:
Function mOnImmunity; Function mOnImmunity;
Function mOnPartStatus; Function mOnPartStatus;
Function mOnTyreStatus; Function mOnTyreStatus;
Function mOnDamageData;
}; };
public: public:
@ -1023,6 +1024,7 @@ public:
void EmitVehicleImmunity(Int32 vehicle_id, Int32 old_immunity, Int32 new_immunity); void EmitVehicleImmunity(Int32 vehicle_id, Int32 old_immunity, Int32 new_immunity);
void EmitVehiclePartStatus(Int32 vehicle_id, Int32 old_status, Int32 new_status); void EmitVehiclePartStatus(Int32 vehicle_id, Int32 old_status, Int32 new_status);
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 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();
@ -1173,6 +1175,7 @@ private:
Function mOnVehicleImmunity; Function mOnVehicleImmunity;
Function mOnVehiclePartStatus; Function mOnVehiclePartStatus;
Function mOnVehicleTyreStatus; Function mOnVehicleTyreStatus;
Function mOnVehicleDamageData;
Function mOnServerOption; Function mOnServerOption;
Function mOnScriptReload; Function mOnScriptReload;
Function mOnScriptLoaded; Function mOnScriptLoaded;

View File

@ -870,6 +870,14 @@ void Core::EmitVehicleTyreStatus(Int32 vehicle_id, Int32 old_status, Int32 new_s
Emit(mOnVehicleTyreStatus, _vehicle.mObj, old_status, new_status); 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) void Core::EmitServerOption(Int32 option, bool value, Int32 header, Object & payload)
{ {

View File

@ -258,6 +258,7 @@ void Core::ResetFunc(VehicleInst & inst)
inst.mOnImmunity.ReleaseGently(); inst.mOnImmunity.ReleaseGently();
inst.mOnPartStatus.ReleaseGently(); inst.mOnPartStatus.ReleaseGently();
inst.mOnTyreStatus.ReleaseGently(); inst.mOnTyreStatus.ReleaseGently();
inst.mOnDamageData.ReleaseGently();
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -372,6 +373,7 @@ void Core::ResetFunc()
Core::Get().mOnVehicleImmunity.ReleaseGently(); Core::Get().mOnVehicleImmunity.ReleaseGently();
Core::Get().mOnVehiclePartStatus.ReleaseGently(); Core::Get().mOnVehiclePartStatus.ReleaseGently();
Core::Get().mOnVehicleTyreStatus.ReleaseGently(); Core::Get().mOnVehicleTyreStatus.ReleaseGently();
Core::Get().mOnVehicleDamageData.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();
@ -491,6 +493,7 @@ Function & Core::GetEvent(Int32 evid)
case EVT_VEHICLEIMMUNITY: return mOnVehicleImmunity; case EVT_VEHICLEIMMUNITY: return mOnVehicleImmunity;
case EVT_VEHICLEPARTSTATUS: return mOnVehiclePartStatus; case EVT_VEHICLEPARTSTATUS: return mOnVehiclePartStatus;
case EVT_VEHICLETYRESTATUS: return mOnVehicleTyreStatus; case EVT_VEHICLETYRESTATUS: return mOnVehicleTyreStatus;
case EVT_VEHICLEDAMAGEDATA: return mOnVehicleDamageData;
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;
@ -677,6 +680,7 @@ Function & Core::GetVehicleEvent(Int32 id, Int32 evid)
case EVT_VEHICLEIMMUNITY: return inst.mOnImmunity; case EVT_VEHICLEIMMUNITY: return inst.mOnImmunity;
case EVT_VEHICLEPARTSTATUS: return inst.mOnPartStatus; case EVT_VEHICLEPARTSTATUS: return inst.mOnPartStatus;
case EVT_VEHICLETYRESTATUS: return inst.mOnTyreStatus; case EVT_VEHICLETYRESTATUS: return inst.mOnTyreStatus;
case EVT_VEHICLEDAMAGEDATA: return inst.mOnDamageData;
default: return NullFunction(); default: return NullFunction();
} }
} }

View File

@ -931,12 +931,27 @@ Uint32 CVehicle::GetDamageData() const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CVehicle::SetDamageData(Uint32 data) const void CVehicle::SetDamageData(Uint32 data)
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); 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); _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);
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -16,7 +16,8 @@ enum VehicleCircularLocks
VEHICLECL_EMIT_VEHICLE_WORLD = (2 << 0), VEHICLECL_EMIT_VEHICLE_WORLD = (2 << 0),
VEHICLECL_EMIT_VEHICLE_IMMUNITY = (3 << 0), VEHICLECL_EMIT_VEHICLE_IMMUNITY = (3 << 0),
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)
}; };
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
@ -552,7 +553,7 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the damage data of the managed vehicle entity. * 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. * Retrieve the radio of the managed vehicle entity.

View File

@ -394,6 +394,7 @@ enum EventType
EVT_VEHICLEIMMUNITY, EVT_VEHICLEIMMUNITY,
EVT_VEHICLEPARTSTATUS, EVT_VEHICLEPARTSTATUS,
EVT_VEHICLETYRESTATUS, EVT_VEHICLETYRESTATUS,
EVT_VEHICLEDAMAGEDATA,
EVT_SERVEROPTION, EVT_SERVEROPTION,
EVT_SCRIPTRELOAD, EVT_SCRIPTRELOAD,
EVT_SCRIPTLOADED, EVT_SCRIPTLOADED,