1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Implement a new event to receive notifications when a vehicle part status has changed.

This commit is contained in:
Sandu Liviu Catalin 2016-08-18 14:51:55 +03:00
parent 732769aff2
commit 23948b5903
6 changed files with 37 additions and 5 deletions

View File

@ -497,6 +497,7 @@ protected:
Function mOnOption;
Function mOnWorld;
Function mOnImmunity;
Function mOnPartStatus;
};
public:
@ -1019,6 +1020,7 @@ public:
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 EmitVehiclePartStatus(Int32 vehicle_id, Int32 old_status, Int32 new_status);
void EmitServerOption(Int32 option, bool value, Int32 header, Object & payload);
void EmitScriptReload(Int32 header, Object & payload);
void EmitScriptLoaded();
@ -1167,6 +1169,7 @@ private:
Function mOnVehicleOption;
Function mOnVehicleWorld;
Function mOnVehicleImmunity;
Function mOnVehiclePartStatus;
Function mOnServerOption;
Function mOnScriptReload;
Function mOnScriptLoaded;

View File

@ -854,6 +854,14 @@ void Core::EmitVehicleImmunity(Int32 vehicle_id, Int32 old_immunity, Int32 new_i
Emit(mOnVehicleImmunity, _vehicle.mObj, old_immunity, new_immunity);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitVehiclePartStatus(Int32 vehicle_id, Int32 old_status, Int32 new_status)
{
VehicleInst & _vehicle = m_Vehicles.at(vehicle_id);
Emit(_vehicle.mOnPartStatus, old_status, new_status);
Emit(mOnVehiclePartStatus, _vehicle.mObj, old_status, new_status);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitServerOption(Int32 option, bool value, Int32 header, Object & payload)
{

View File

@ -256,6 +256,7 @@ void Core::ResetFunc(VehicleInst & inst)
inst.mOnOption.ReleaseGently();
inst.mOnWorld.ReleaseGently();
inst.mOnImmunity.ReleaseGently();
inst.mOnPartStatus.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
@ -368,6 +369,7 @@ void Core::ResetFunc()
Core::Get().mOnVehicleOption.ReleaseGently();
Core::Get().mOnVehicleWorld.ReleaseGently();
Core::Get().mOnVehicleImmunity.ReleaseGently();
Core::Get().mOnVehiclePartStatus.ReleaseGently();
Core::Get().mOnServerOption.ReleaseGently();
Core::Get().mOnScriptReload.ReleaseGently();
Core::Get().mOnScriptLoaded.ReleaseGently();
@ -485,6 +487,7 @@ Function & Core::GetEvent(Int32 evid)
case EVT_VEHICLEOPTION: return mOnVehicleOption;
case EVT_VEHICLEWORLD: return mOnVehicleWorld;
case EVT_VEHICLEIMMUNITY: return mOnVehicleImmunity;
case EVT_VEHICLEPARTSTATUS: return mOnVehiclePartStatus;
case EVT_SERVEROPTION: return mOnServerOption;
case EVT_SCRIPTRELOAD: return mOnScriptReload;
case EVT_SCRIPTLOADED: return mOnScriptLoaded;
@ -669,6 +672,7 @@ Function & Core::GetVehicleEvent(Int32 id, Int32 evid)
case EVT_VEHICLEOPTION: return inst.mOnOption;
case EVT_VEHICLEWORLD: return inst.mOnWorld;
case EVT_VEHICLEIMMUNITY: return inst.mOnImmunity;
case EVT_VEHICLEPARTSTATUS: return inst.mOnPartStatus;
default: return NullFunction();
}
}

View File

@ -865,12 +865,27 @@ Int32 CVehicle::GetPartStatus(Int32 part) const
}
// ------------------------------------------------------------------------------------------------
void CVehicle::SetPartStatus(Int32 part, Int32 status) const
void CVehicle::SetPartStatus(Int32 part, Int32 status)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetVehiclePartStatus(m_ID, part, status);
// Grab the current value for this property
const Int32 current = _Func->GetVehiclePartStatus(m_ID);
// Don't even bother if it's the same value
if (current == status)
{
return;
}
// Avoid property unwind from a recursive call
_Func->SetVehiclePartStatus(m_ID, status);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & VEHICLECL_EMIT_VEHICLE_PARTSTATUS))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_PARTSTATUS);
// Now forward the event call
Core::Get().EmitVehiclePartStatus(m_ID, current, status);
}
}
// ------------------------------------------------------------------------------------------------

View File

@ -14,7 +14,8 @@ enum VehicleCircularLocks
{
VEHICLECL_EMIT_VEHICLE_OPTION = (1 << 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)
};
/* ------------------------------------------------------------------------------------------------
@ -530,7 +531,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the part status of the managed vehicle entity.
*/
void SetPartStatus(Int32 part, Int32 status) const;
void SetPartStatus(Int32 part, Int32 status);
/* --------------------------------------------------------------------------------------------
* Retrieve the tyre status of the managed vehicle entity.

View File

@ -392,6 +392,7 @@ enum EventType
EVT_VEHICLEOPTION,
EVT_VEHICLEWORLD,
EVT_VEHICLEIMMUNITY,
EVT_VEHICLEPARTSTATUS,
EVT_SERVEROPTION,
EVT_SCRIPTRELOAD,
EVT_SCRIPTLOADED,