Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GangZone, LocalGangZone to main iterators. #682

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions YSI_Data/y_foreach/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions YSI_Data/y_foreach/y_foreach_entry.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
97 changes: 96 additions & 1 deletion YSI_Data/y_foreach/y_foreach_iterators.inc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ Optional plugins:
ITERATOR__ PlayersFromVehicles<MAX_PLAYERS>;
#endif

#if _FOREACH_GANGZONES
new
#if _FOREACH_LOCALS
ITERATOR__ LocalGangZone<MAX_GANG_ZONES>,
#endif
ITERATOR__ GangZone<MAX_GANG_ZONES>;
#endif

/*-------------------------------------------------------------------------*//**
* <library>y_iterate</library>
* <param name="cur">The current iterator step.</param>
Expand Down Expand Up @@ -531,9 +539,23 @@ stock Iter_All_Internal(const array[], size, value)
* </remarks>
*//*------------------------------------------------------------------------**/

#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
Expand Down Expand Up @@ -871,6 +893,10 @@ stock Iter_All_Internal(const array[], size, value)
#endif

static stock const
/**
* <library>y_iterate</library>
*/
YSI_gsIter_GangZoneDo[] = "Iter_GangZoneDo",
/**
* <library>y_iterate</library>
*/
Expand Down Expand Up @@ -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