From 3a38d75a16d6a65352cccd8c84a36f25e36fa0ba Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Sun, 17 Feb 2019 16:01:31 +1100 Subject: [PATCH] store the gangzone areas into an iterator and use iter_next --- .../irresistible/cnr/features/gangs/turfs.pwn | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gamemodes/irresistible/cnr/features/gangs/turfs.pwn b/gamemodes/irresistible/cnr/features/gangs/turfs.pwn index fd474d2..21d7eba 100644 --- a/gamemodes/irresistible/cnr/features/gangs/turfs.pwn +++ b/gamemodes/irresistible/cnr/features/gangs/turfs.pwn @@ -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;