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

This commit is contained in:
Sandu Liviu Catalin 2016-08-18 15:13:33 +03:00
parent 69325ed2cc
commit db522913d3
6 changed files with 35 additions and 4 deletions

View File

@ -500,6 +500,7 @@ protected:
Function mOnPartStatus;
Function mOnTyreStatus;
Function mOnDamageData;
Function mOnRadio;
};
public:
@ -1025,6 +1026,7 @@ public:
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 EmitVehicleRadio(Int32 vehicle_id, Int32 old_radio, Int32 new_radio);
void EmitServerOption(Int32 option, bool value, Int32 header, Object & payload);
void EmitScriptReload(Int32 header, Object & payload);
void EmitScriptLoaded();
@ -1176,6 +1178,7 @@ private:
Function mOnVehiclePartStatus;
Function mOnVehicleTyreStatus;
Function mOnVehicleDamageData;
Function mOnVehicleRadio;
Function mOnServerOption;
Function mOnScriptReload;
Function mOnScriptLoaded;

View File

@ -878,6 +878,13 @@ void Core::EmitVehicleDamageData(Int32 vehicle_id, Uint32 old_data, Uint32 new_d
Emit(mOnVehicleDamageData, _vehicle.mObj, old_data, new_data);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitVehicleRadio(Int32 vehicle_id, Int32 old_radio, Int32 new_radio)
{
VehicleInst & _vehicle = m_Vehicles.at(vehicle_id);
Emit(_vehicle.mOnRadio, old_radio, new_radio);
Emit(mOnVehicleRadio, _vehicle.mObj, old_radio, new_radio);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitServerOption(Int32 option, bool value, Int32 header, Object & payload)
{

View File

@ -259,6 +259,7 @@ void Core::ResetFunc(VehicleInst & inst)
inst.mOnPartStatus.ReleaseGently();
inst.mOnTyreStatus.ReleaseGently();
inst.mOnDamageData.ReleaseGently();
inst.mOnRadio.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
@ -374,6 +375,7 @@ void Core::ResetFunc()
Core::Get().mOnVehiclePartStatus.ReleaseGently();
Core::Get().mOnVehicleTyreStatus.ReleaseGently();
Core::Get().mOnVehicleDamageData.ReleaseGently();
Core::Get().mOnVehicleRadio.ReleaseGently();
Core::Get().mOnServerOption.ReleaseGently();
Core::Get().mOnScriptReload.ReleaseGently();
Core::Get().mOnScriptLoaded.ReleaseGently();
@ -494,6 +496,7 @@ Function & Core::GetEvent(Int32 evid)
case EVT_VEHICLEPARTSTATUS: return mOnVehiclePartStatus;
case EVT_VEHICLETYRESTATUS: return mOnVehicleTyreStatus;
case EVT_VEHICLEDAMAGEDATA: return mOnVehicleDamageData;
case EVT_VEHICLERADIO: return mOnVehicleRadio;
case EVT_SERVEROPTION: return mOnServerOption;
case EVT_SCRIPTRELOAD: return mOnScriptReload;
case EVT_SCRIPTLOADED: return mOnScriptLoaded;
@ -681,6 +684,7 @@ Function & Core::GetVehicleEvent(Int32 id, Int32 evid)
case EVT_VEHICLEPARTSTATUS: return inst.mOnPartStatus;
case EVT_VEHICLETYRESTATUS: return inst.mOnTyreStatus;
case EVT_VEHICLEDAMAGEDATA: return inst.mOnDamageData;
case EVT_VEHICLERADIO: return inst.mOnRadio;
default: return NullFunction();
}
}

View File

@ -964,12 +964,27 @@ Int32 CVehicle::GetRadio() const
}
// ------------------------------------------------------------------------------------------------
void CVehicle::SetRadio(Int32 radio) const
void CVehicle::SetRadio(Int32 radio)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
// Grab the current value for this property
const Int32 current = _Func->GetVehicleRadio(m_ID);
// Don't even bother if it's the same value
if (current == radio)
{
return;
}
// Avoid property unwind from a recursive call
_Func->SetVehicleRadio(m_ID, radio);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & VEHICLECL_EMIT_VEHICLE_RADIO))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_RADIO);
// Now forward the event call
Core::Get().EmitVehicleRadio(m_ID, current, radio);
}
}
// ------------------------------------------------------------------------------------------------

View File

@ -17,7 +17,8 @@ enum VehicleCircularLocks
VEHICLECL_EMIT_VEHICLE_IMMUNITY = (3 << 0),
VEHICLECL_EMIT_VEHICLE_PARTSTATUS = (4 << 0),
VEHICLECL_EMIT_VEHICLE_TYRESTATUS = (5 << 0),
VEHICLECL_EMIT_VEHICLE_DAMAGEDATA = (6 << 0)
VEHICLECL_EMIT_VEHICLE_DAMAGEDATA = (6 << 0),
VEHICLECL_EMIT_VEHICLE_RADIO = (7 << 0)
};
/* ------------------------------------------------------------------------------------------------
@ -563,7 +564,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the radio of the managed vehicle entity.
*/
void SetRadio(Int32 radio) const;
void SetRadio(Int32 radio);
/* --------------------------------------------------------------------------------------------
* Retrieve the turret rotation of the managed vehicle entity.

View File

@ -395,6 +395,7 @@ enum EventType
EVT_VEHICLEPARTSTATUS,
EVT_VEHICLETYRESTATUS,
EVT_VEHICLEDAMAGEDATA,
EVT_VEHICLERADIO,
EVT_SERVEROPTION,
EVT_SCRIPTRELOAD,
EVT_SCRIPTLOADED,