store the gangzone areas into an iterator and use iter_next

This commit is contained in:
Lorenc Pekaj 2019-02-17 16:01:31 +11:00
parent 0cf9853cd7
commit 3a38d75a16

View File

@ -81,11 +81,12 @@ enum E_TURF_ZONE_DATA {
new
g_gangTurfData [ MAX_TURFS ] [ E_TURF_ZONE_DATA ],
Iterator: turfs < MAX_TURFS >,
Iterator: gangzoneturfs < MAX_TURFS >,
Float: g_weekAveragePlayers = 0.0,
Float: g_weekSecondsElapsed = 0.0,
g_gangHardpointRotation = -1, // it will begin at 0 this way
g_gangHardpointRotation = -1,
g_gangHardpointTurf = INVALID_GANG_TURF,
g_gangHardpointPreviousTurf = INVALID_GANG_TURF,
g_gangHardpointAttacker = INVALID_GANG_ID,
@ -109,10 +110,14 @@ stock Float: Turf_GetHardpointPrizePool( Float: max_payout = 500000.0 )
/* ** Hooks ** */
hook OnGameModeInit( )
{
/* ** Gangzone Allocation ** */
// Gangzone Allocation
for ( new i = 0; i < sizeof( g_gangzoneData ); i ++ ) {
Turf_Create( g_gangzoneData[ i ] [ E_MIN_X ], g_gangzoneData[ i ] [ E_MIN_Y ], g_gangzoneData[ i ] [ E_MAX_X ], g_gangzoneData[ i ] [ E_MAX_Y ], INVALID_GANG_ID, COLOR_GANGZONE, .bordersize = GANGZONE_DEFAULT_BORDER_SIZE, .numbersize = GANGZONE_DEFAULT_NUMBER_SIZE );
new turfid = Turf_Create( g_gangzoneData[ i ] [ E_MIN_X ], g_gangzoneData[ i ] [ E_MIN_Y ], g_gangzoneData[ i ] [ E_MAX_X ], g_gangzoneData[ i ] [ E_MAX_Y ], INVALID_GANG_ID, COLOR_GANGZONE, .bordersize = GANGZONE_DEFAULT_BORDER_SIZE, .numbersize = GANGZONE_DEFAULT_NUMBER_SIZE );
Iter_Add( gangzoneturfs, turfid );
}
// Reset Iterator
g_gangHardpointRotation = Iter_Last( gangzoneturfs );
return 1;
}
@ -227,8 +232,15 @@ stock Turf_CreateHardpoint( )
}
// fixed zone rotation
if ( ! ( 0 <= g_gangHardpointRotation ++ < sizeof( g_gangzoneData ) - 1 ) ) {
g_gangHardpointRotation = 0;
new current_rotation = g_gangHardpointRotation;
// reset rotation
if ( current_rotation >= Iter_Last( gangzoneturfs ) ) {
g_gangHardpointRotation = Iter_First( gangzoneturfs );
}
// get next in rotation
else {
g_gangHardpointRotation = Iter_Next( gangzoneturfs, current_rotation );
}
// allocate new hardpoint
@ -310,7 +322,7 @@ hook OnServerGameDayEnd( )
}
// reset hardpoint
g_gangHardpointPreviousTurf = g_gangHardpointTurf;
g_gangHardpointPreviousTurf = Iter_Prev( gangzoneturfs, g_gangHardpointTurf );
g_gangHardpointTurf = INVALID_GANG_TURF;
g_weekAveragePlayers = 0.0;
g_weekSecondsElapsed = 0.0;