1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-20 19:57:12 +01:00

Implement a new event to receive notifications when a pickup automatic status has changed.

This commit is contained in:
Sandu Liviu Catalin 2016-08-19 18:21:41 +03:00
parent 3def96b57a
commit cdc0ac7585
5 changed files with 37 additions and 6 deletions

View File

@ -305,6 +305,7 @@ protected:
Function mOnCollected;
Function mOnWorld;
Function mOnAlpha;
Function mOnAutomatic;
};
/* --------------------------------------------------------------------------------------------
@ -1015,6 +1016,7 @@ public:
void EmitObjectAlpha(Int32 object_id, Int32 old_alpha, Int32 new_alpha, Int32 time);
void EmitPickupWorld(Int32 pickup_id, Int32 old_world, Int32 new_world);
void EmitPickupAlpha(Int32 pickup_id, Int32 old_alpha, Int32 new_alpha);
void EmitPickupAutomatic(Int32 pickup_id, bool old_status, bool new_status);
void EmitObjectReport(Int32 object_id, bool old_status, bool new_status, bool touched);
void EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health);
void EmitPlayerArmour(Int32 player_id, Float32 old_armour, Float32 new_armour);
@ -1168,6 +1170,7 @@ private:
Function mOnPickupRespawn;
Function mOnPickupWorld;
Function mOnPickupAlpha;
Function mOnPickupAutomatic;
Function mOnCheckpointEntered;
Function mOnCheckpointExited;
Function mOnCheckpointWorld;

View File

@ -724,6 +724,14 @@ void Core::EmitPickupAlpha(Int32 pickup_id, Int32 old_alpha, Int32 new_alpha)
Emit(mOnPickupAlpha, _pickup.mObj, old_alpha, new_alpha);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitPickupAutomatic(Int32 pickup_id, bool old_status, bool new_status)
{
PickupInst & _pickup = m_Pickups.at(pickup_id);
Emit(_pickup.mOnAutomatic, old_status, new_status);
Emit(mOnPickupAutomatic, _pickup.mObj, old_status, new_status);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitObjectReport(Int32 object_id, bool old_status, bool new_status, bool touched)
{

View File

@ -167,6 +167,7 @@ void Core::ResetFunc(PickupInst & inst)
inst.mOnCollected.ReleaseGently();
inst.mOnWorld.ReleaseGently();
inst.mOnAlpha.ReleaseGently();
inst.mOnAutomatic.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
@ -354,9 +355,10 @@ void Core::ResetFunc()
Core::Get().mOnObjectReport.ReleaseGently();
Core::Get().mOnPickupClaimed.ReleaseGently();
Core::Get().mOnPickupCollected.ReleaseGently();
Core::Get().mOnPickupRespawn.ReleaseGently();
Core::Get().mOnPickupWorld.ReleaseGently();
Core::Get().mOnPickupAlpha.ReleaseGently();
Core::Get().mOnPickupRespawn.ReleaseGently();
Core::Get().mOnPickupAutomatic.ReleaseGently();
Core::Get().mOnCheckpointEntered.ReleaseGently();
Core::Get().mOnCheckpointExited.ReleaseGently();
Core::Get().mOnCheckpointWorld.ReleaseGently();
@ -483,9 +485,10 @@ Function & Core::GetEvent(Int32 evid)
case EVT_OBJECTREPORT: return mOnObjectReport;
case EVT_PICKUPCLAIMED: return mOnPickupClaimed;
case EVT_PICKUPCOLLECTED: return mOnPickupCollected;
case EVT_PICKUPRESPAWN: return mOnPickupRespawn;
case EVT_PICKUPWORLD: return mOnPickupWorld;
case EVT_PICKUPALPHA: return mOnPickupAlpha;
case EVT_PICKUPRESPAWN: return mOnPickupRespawn;
case EVT_PICKUPAUTOMATIC: return mOnPickupAutomatic;
case EVT_CHECKPOINTENTERED: return mOnCheckpointEntered;
case EVT_CHECKPOINTEXITED: return mOnCheckpointExited;
case EVT_CHECKPOINTWORLD: return mOnCheckpointWorld;
@ -606,6 +609,7 @@ Function & Core::GetPickupEvent(Int32 id, Int32 evid)
case EVT_PICKUPCOLLECTED: return inst.mOnCollected;
case EVT_PICKUPWORLD: return inst.mOnWorld;
case EVT_PICKUPALPHA: return inst.mOnAlpha;
case EVT_PICKUPAUTOMATIC: return inst.mOnAutomatic;
default: return NullFunction();
}
}

View File

@ -233,12 +233,27 @@ bool CPickup::GetAutomatic() const
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAutomatic(bool toggle) const
void CPickup::SetAutomatic(bool toggle)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
// Grab the current value for this property
const bool current = _Func->IsPickupAutomatic(m_ID);
// Don't even bother if it's the same value
if (current == toggle)
{
return;
}
// Avoid property unwind from a recursive call
_Func->SetPickupIsAutomatic(m_ID, toggle);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & PICKUPCL_EMIT_PICKUP_AUTOMATIC))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, PICKUPCL_EMIT_PICKUP_AUTOMATIC);
// Now forward the event call
Core::Get().EmitPickupAutomatic(m_ID, current, toggle);
}
}
// ------------------------------------------------------------------------------------------------

View File

@ -13,7 +13,8 @@ namespace SqMod {
enum PickupCircularLocks
{
PICKUPCL_EMIT_PICKUP_WORLD = (1 << 0),
PICKUPCL_EMIT_PICKUP_ALPHA = (2 << 0)
PICKUPCL_EMIT_PICKUP_ALPHA = (2 << 0),
PICKUPCL_EMIT_PICKUP_AUTOMATIC = (3 << 0)
};
/* ------------------------------------------------------------------------------------------------
@ -222,7 +223,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Set whether the managed pickup entity is automatic.
*/
void SetAutomatic(bool toggle) const;
void SetAutomatic(bool toggle);
/* --------------------------------------------------------------------------------------------
* Retrieve the automatic timer of the managed pickup entity.