From 55b4a3d7ac1399f9527731663c2a3c6f67772aa5 Mon Sep 17 00:00:00 2001 From: shierru Date: Tue, 6 Aug 2024 23:10:32 +0300 Subject: [PATCH] Added GangZone, LocalGangZone to main iterators. --- YSI_Data/y_foreach/features.md | 16 ++++ YSI_Data/y_foreach/y_foreach_entry.inc | 16 ++++ YSI_Data/y_foreach/y_foreach_iterators.inc | 97 +++++++++++++++++++++- 3 files changed, 128 insertions(+), 1 deletion(-) diff --git a/YSI_Data/y_foreach/features.md b/YSI_Data/y_foreach/features.md index 65426b4e..2db84816 100644 --- a/YSI_Data/y_foreach/features.md +++ b/YSI_Data/y_foreach/features.md @@ -1140,6 +1140,22 @@ Loop over all passengers in any vehicle: foreach (new i : VehiclePassenger) ``` +### `GangZone` + +Loop over all gangzones: + +```pawn +foreach (new i : GangZone) +``` + +### `LocalGangZone` + +Loop over all gangzones created in the current mode: + +```pawn +foreach (new i : LocalGangZone) +``` + ### `Command` Loop over all y_commands command IDs: diff --git a/YSI_Data/y_foreach/y_foreach_entry.inc b/YSI_Data/y_foreach/y_foreach_entry.inc index 58924e58..5fb36070 100644 --- a/YSI_Data/y_foreach/y_foreach_entry.inc +++ b/YSI_Data/y_foreach/y_foreach_entry.inc @@ -285,6 +285,22 @@ Optional plugins: #define _FOREACH_LOCALS 0 #endif +// +// _FOREACH_GANGZONES +// +// Should the "GangZone" iterator be included? "GangZone" loops over all gangzones +// created on the server, "LocalGangZone" iterates over gangzones created only in +// the current script. They are the same when "YSI_NO_MASTER" is declared. +// Disabled by declaring "FOREACH_NO_GANGZONES". +// + +#define _FOREACH_GANGZONES 1 + +#if !defined GangZoneStopFlashForAll || defined FOREACH_NO_GANGZONES + #undef _FOREACH_GANGZONES + #define _FOREACH_GANGZONES 0 +#endif + // // _FOREACH_VEHICLES // diff --git a/YSI_Data/y_foreach/y_foreach_iterators.inc b/YSI_Data/y_foreach/y_foreach_iterators.inc index c63e7cf4..eaa1173c 100644 --- a/YSI_Data/y_foreach/y_foreach_iterators.inc +++ b/YSI_Data/y_foreach/y_foreach_iterators.inc @@ -137,6 +137,14 @@ Optional plugins: ITERATOR__ PlayersFromVehicles; #endif +#if _FOREACH_GANGZONES + new + #if _FOREACH_LOCALS + ITERATOR__ LocalGangZone, + #endif + ITERATOR__ GangZone; +#endif + /*-------------------------------------------------------------------------*//** * y_iterate * The current iterator step. @@ -531,9 +539,23 @@ stock Iter_All_Internal(const array[], size, value) * *//*------------------------------------------------------------------------**/ -#if _FOREACH_CHARACTERS || _FOREACH_VEHICLES || _FOREACH_ACTORS +#if _FOREACH_CHARACTERS || _FOREACH_VEHICLES || _FOREACH_ACTORS || _FOREACH_GANGZONES public OnYSIInit() { + #if _FOREACH_GANGZONES + Iter_Clear(GangZone); + for (new i = 0; i != MAX_GANG_ZONES; ++i) + { + #if defined IsValidGangZone + if (IsValidGangZone(i)) + #else + if (GangZoneStopFlashForAll(i)) + #endif + { + Iter_Add(GangZone, i); + } + } + #endif #if _FOREACH_VEHICLES Iter_Clear(Vehicle); #if _FOREACH_STREAMED @@ -871,6 +893,10 @@ stock Iter_All_Internal(const array[], size, value) #endif static stock const + /** + * y_iterate + */ + YSI_gsIter_GangZoneDo[] = "Iter_GangZoneDo", /** * y_iterate */ @@ -1267,3 +1293,72 @@ static stock const #define Iterator@VehicleDriver iteryield #endif +/* + + ,ad8888ba, + d8"' `"8b + d8' + 88 ,adPPYYba, 8b,dPPYba, ,adPPYb,d8 888888888 ,adPPYba, 8b,dPPYba, ,adPPYba, ,adPPYba, + 88 88888 "" `Y8 88P' `"8a a8" `Y88 a8P" a8" "8a 88P' `"8a a8P_____88 I8[ "" + Y8, 88 ,adPPPPP88 88 88 8b 88 ,d8P' 8b d8 88 88 8PP""""""" `"Y8ba, + Y8a. .a88 88, ,88 88 88 "8a, ,d88 ,d8" "8a, ,a8" 88 88 "8b, ,aa aa ]8I + `"Y88888P" `"8bbdP"Y8 88 88 `"YbbdP"Y8 888888888 `"YbbdP"' 88 88 `"Ybbd8"' `"YbbdP"' + aa, ,88 + "Y8bbdP" + +*/ + +#if _FOREACH_GANGZONES + forward void:Iter_GangZoneDo(bool:add, zoneid); + + public void:Iter_GangZoneDo(bool:add, zoneid) + { + // Because there may be multiple scripts running, we need to tell all of + // them when a vehicle is created or destroyed. + if (add) + { + Iter_Add(GangZone, zoneid); + } + else + { + Iter_Remove(GangZone, zoneid); + } + } + + stock Iter_GangZoneCreate(Float:minX, Float:minY, Float:maxX, Float:maxY) + { + new + ret = GangZoneCreate(minX, minY, maxX, maxY); + if (ret != INVALID_GANG_ZONE) + { + CallRemoteFunction(YSI_gsIter_GangZoneDo, YSI_gcII, true, ret); + #if _FOREACH_LOCALS + Iter_Add(LocalGangZone, ret); + #endif + } + return ret; + } + + #if defined _ALS_GangZoneCreate + #undef GangZoneCreate + #else + #define _ALS_GangZoneCreate + #endif + #define GangZoneCreate Iter_GangZoneCreate + + stock Iter_GangZoneDestroy(zoneid) + { + CallRemoteFunction(YSI_gsIter_GangZoneDo, YSI_gcII, false, zoneid); + #if _FOREACH_LOCALS + Iter_Remove(LocalGangZone, zoneid); + #endif + return GangZoneDestroy(zoneid); + } + + #if defined _ALS_GangZoneDestroy + #undef GangZoneDestroy + #else + #define _ALS_GangZoneDestroy + #endif + #define GangZoneDestroy Iter_GangZoneDestroy +#endif \ No newline at end of file