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 immunity has changed.

This commit is contained in:
Sandu Liviu Catalin 2016-08-18 14:45:12 +03:00
parent ebc168e558
commit 732769aff2
6 changed files with 31 additions and 4 deletions

View File

@ -496,6 +496,7 @@ protected:
Function mOnRotation;
Function mOnOption;
Function mOnWorld;
Function mOnImmunity;
};
public:
@ -1017,6 +1018,7 @@ public:
void EmitVehicleRotation(Int32 vehicle_id);
void EmitVehicleOption(Int32 vehicle_id, Int32 option_id, bool value, Int32 header, Object & payload);
void EmitVehicleWorld(Int32 vehicle_id, Int32 old_world, Int32 new_world);
void EmitVehicleImmunity(Int32 vehicle_id, Int32 old_immunity, Int32 new_immunity);
void EmitServerOption(Int32 option, bool value, Int32 header, Object & payload);
void EmitScriptReload(Int32 header, Object & payload);
void EmitScriptLoaded();
@ -1164,6 +1166,7 @@ private:
Function mOnVehicleRotation;
Function mOnVehicleOption;
Function mOnVehicleWorld;
Function mOnVehicleImmunity;
Function mOnServerOption;
Function mOnScriptReload;
Function mOnScriptLoaded;

View File

@ -846,6 +846,14 @@ void Core::EmitVehicleWorld(Int32 vehicle_id, Int32 old_world, Int32 new_world)
Emit(mOnVehicleWorld, _vehicle.mObj, old_world, new_world);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitVehicleImmunity(Int32 vehicle_id, Int32 old_immunity, Int32 new_immunity)
{
VehicleInst & _vehicle = m_Vehicles.at(vehicle_id);
Emit(_vehicle.mOnImmunity, old_immunity, new_immunity);
Emit(mOnVehicleImmunity, _vehicle.mObj, old_immunity, new_immunity);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitServerOption(Int32 option, bool value, Int32 header, Object & payload)
{

View File

@ -255,6 +255,7 @@ void Core::ResetFunc(VehicleInst & inst)
inst.mOnRotation.ReleaseGently();
inst.mOnOption.ReleaseGently();
inst.mOnWorld.ReleaseGently();
inst.mOnImmunity.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
@ -366,6 +367,7 @@ void Core::ResetFunc()
Core::Get().mOnVehicleRotation.ReleaseGently();
Core::Get().mOnVehicleOption.ReleaseGently();
Core::Get().mOnVehicleWorld.ReleaseGently();
Core::Get().mOnVehicleImmunity.ReleaseGently();
Core::Get().mOnServerOption.ReleaseGently();
Core::Get().mOnScriptReload.ReleaseGently();
Core::Get().mOnScriptLoaded.ReleaseGently();
@ -482,6 +484,7 @@ Function & Core::GetEvent(Int32 evid)
case EVT_VEHICLEROTATION: return mOnVehicleRotation;
case EVT_VEHICLEOPTION: return mOnVehicleOption;
case EVT_VEHICLEWORLD: return mOnVehicleWorld;
case EVT_VEHICLEIMMUNITY: return mOnVehicleImmunity;
case EVT_SERVEROPTION: return mOnServerOption;
case EVT_SCRIPTRELOAD: return mOnScriptReload;
case EVT_SCRIPTLOADED: return mOnScriptLoaded;
@ -665,6 +668,7 @@ Function & Core::GetVehicleEvent(Int32 id, Int32 evid)
case EVT_VEHICLEROTATION: return inst.mOnRotation;
case EVT_VEHICLEOPTION: return inst.mOnOption;
case EVT_VEHICLEWORLD: return inst.mOnWorld;
case EVT_VEHICLEIMMUNITY: return inst.mOnImmunity;
default: return NullFunction();
}
}

View File

@ -312,12 +312,22 @@ Int32 CVehicle::GetImmunity() const
}
// ------------------------------------------------------------------------------------------------
void CVehicle::SetImmunity(Int32 flags) const
void CVehicle::SetImmunity(Int32 flags)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
// Grab the current value for this property
const Int32 current = _Func->GetVehicleImmunityFlags(m_ID);
// Avoid property unwind from a recursive call
_Func->SetVehicleImmunityFlags(m_ID, flags);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & VEHICLECL_EMIT_VEHICLE_IMMUNITY))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_IMMUNITY);
// Now forward the event call
Core::Get().EmitVehicleImmunity(m_ID, current, flags);
}
}
// ------------------------------------------------------------------------------------------------

View File

@ -13,7 +13,8 @@ namespace SqMod {
enum VehicleCircularLocks
{
VEHICLECL_EMIT_VEHICLE_OPTION = (1 << 0),
VEHICLECL_EMIT_VEHICLE_WORLD = (2 << 0)
VEHICLECL_EMIT_VEHICLE_WORLD = (2 << 0),
VEHICLECL_EMIT_VEHICLE_IMMUNITY = (3 << 0)
};
/* ------------------------------------------------------------------------------------------------
@ -259,7 +260,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the immunity flags of the managed vehicle entity.
*/
void SetImmunity(Int32 flags) const;
void SetImmunity(Int32 flags);
/* --------------------------------------------------------------------------------------------
* Explode the managed vehicle entity.

View File

@ -391,6 +391,7 @@ enum EventType
EVT_VEHICLEROTATION,
EVT_VEHICLEOPTION,
EVT_VEHICLEWORLD,
EVT_VEHICLEIMMUNITY,
EVT_SERVEROPTION,
EVT_SCRIPTRELOAD,
EVT_SCRIPTLOADED,