1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +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 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;

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);
}
// ------------------------------------------------------------------------------------------------
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)
{

View File

@ -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();
}
}

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();
// 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);
}
}
// ------------------------------------------------------------------------------------------------

View File

@ -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.

View File

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