2018-09-09 16:01:29 +00:00
/*
* Irresistible Gaming (c) 2018
* Developed by Lorenc Pekaj
2018-10-16 15:20:20 +00:00
* Module: cnr\features\gangs\turfs.pwn
* Purpose: turfing module for gangs
2018-09-09 16:01:29 +00:00
*/
/* ** Includes ** */
#include < YSI\y_hooks >
2018-11-18 09:57:12 +00:00
/* ** Gang Zone Numbers ** */
#define GANGZONE_DEFAULT_BORDER_SIZE 2.0 // default thickness of borders
#define GANGZONE_DEFAULT_NUMBER_SIZE 0.6 // default thickness of numbers
#include < gangzones >
2018-09-09 16:01:29 +00:00
/* ** Definitions ** */
#if defined MAX_FACILITIES
#define MAX_TURFS ( sizeof( g_gangzoneData ) + MAX_FACILITIES )
#else
#define MAX_TURFS ( sizeof( g_gangzoneData ) )
#endif
#define INVALID_GANG_TURF ( -1 )
#define TAKEOVER_NEEDED_PEOPLE ( 1 )
2018-11-09 16:02:14 +00:00
#define COLOR_GANGZONE 0x00000080
#define COLOR_HARDPOINT 0xFF000080
2018-09-09 16:01:29 +00:00
2018-11-10 06:57:54 +00:00
/* ** Macros ** */
#define ShowHardpointIconForPlayer(%0) \
Streamer_AppendArrayData( STREAMER_TYPE_MAP_ICON, g_gangHardpointMapIcon, E_STREAMER_PLAYER_ID, %0 )
#define HideHardpointIconForPlayer(%0) \
Streamer_RemoveArrayData( STREAMER_TYPE_MAP_ICON, g_gangHardpointMapIcon, E_STREAMER_PLAYER_ID, %0 )
2018-09-09 16:01:29 +00:00
/* ** Variables ** */
enum e_GANG_ZONE_DATA
{
Float: E_MIN_X,
Float: E_MIN_Y,
Float: E_MAX_X,
Float: E_MAX_Y,
E_CITY
};
2018-11-09 16:02:14 +00:00
static const
2018-09-09 16:01:29 +00:00
g_gangzoneData[ ] [ e_GANG_ZONE_DATA ] =
{
2018-11-10 03:44:16 +00:00
{ -1725.0, 1301.5, -1538.0, 1437.5, CITY_SF },
{ -2868.0, 1012.5, -2768.0, 1217.5, CITY_SF },
{ -2497.0, 932.5, -2392.0, 1069.5, CITY_SF },
{ -2054.0, 1084.5, -1892.0, 1171.5, CITY_SF },
{ -1569.0, 822.5, -1418.0, 1019.5, CITY_SF },
2018-11-18 11:41:56 +00:00
{ -2088.0, 573.5, -2008.0, 728.5, CITY_SF },
{ -2523.0, 571.5, -2390.0, 705.5, CITY_SF },
2018-11-10 03:44:16 +00:00
{ -2766.0, 324.5, -2651.0, 426.5, CITY_SF },
{ -2386.0, 70.5, -2273.0, 227.5, CITY_SF },
{ -2139.0, 115.5, -2013.0, 311.5, CITY_SF },
{ -2001.0, 69.5, -1911.0, 219.5, CITY_SF },
{ -2096.0, -279.5, -2011.0, -111.5, CITY_SF },
{ -2523.0, -321.5, -2264.0, -215.5, CITY_SF },
{ -2153.0, -515.5, -1960.0, -374.5, CITY_SF },
2018-11-18 09:57:12 +00:00
{ -2600.0, -68.5, -2504.0, 34.5, CITY_SF },
2018-11-18 11:41:56 +00:00
{ -2245.0, 571.5, -2146.0, 727.5, CITY_SF },
2018-11-18 09:57:12 +00:00
{ -1755.0, -80.5, -1658.0, 27.5, CITY_SF }
2018-09-09 16:01:29 +00:00
}
;
/* ** Variables ** */
enum E_TURF_ZONE_DATA {
E_ID,
E_OWNER,
E_COLOR,
E_AREA,
E_FACILITY_GANG
};
new
g_gangTurfData [ MAX_TURFS ] [ E_TURF_ZONE_DATA ],
Iterator: turfs < MAX_TURFS >,
2018-11-10 06:57:54 +00:00
Float: g_weekAveragePlayers = 0.0,
Float: g_weekSecondsElapsed = 0.0,
2018-11-18 09:57:12 +00:00
g_gangHardpointRotation = -1, // it will begin at 0 this way
2018-11-09 16:02:14 +00:00
g_gangHardpointTurf = INVALID_GANG_TURF,
2018-11-10 03:44:16 +00:00
g_gangHardpointPreviousTurf = INVALID_GANG_TURF,
2018-11-09 16:02:14 +00:00
g_gangHardpointAttacker = INVALID_GANG_ID,
2018-11-10 06:57:54 +00:00
g_gangHardpointMapIcon = -1,
2018-11-09 16:02:14 +00:00
g_gangHardpointCaptureTime [ MAX_GANGS ]
2018-09-09 16:01:29 +00:00
;
/* ** Forwards ** */
forward OnPlayerUpdateGangZone( playerid, zoneid );
2018-11-09 16:02:14 +00:00
stock Float: Turf_GetHardpointPrizePool( Float: max_payout = 500000.0 )
{
new
2018-11-11 01:38:26 +00:00
Float: total_payout = ( g_weekAveragePlayers / g_weekSecondsElapsed ) * 7500.0;
2018-11-09 16:02:14 +00:00
return total_payout < max_payout ? total_payout : max_payout;
}
2018-09-09 16:01:29 +00:00
/* ** Hooks ** */
hook OnGameModeInit( )
{
/* ** Gangzone Allocation ** */
2018-11-09 16:02:14 +00:00
for ( new i = 0; i < sizeof( g_gangzoneData ); i ++ ) {
2018-11-18 09:57:12 +00:00
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 );
2018-09-09 16:01:29 +00:00
}
return 1;
}
2018-11-09 16:02:14 +00:00
hook OnServerTickSecond( )
2018-10-16 15:20:20 +00:00
{
2018-11-09 16:02:14 +00:00
new
hardpoint_turf = g_gangHardpointTurf;
if ( hardpoint_turf == INVALID_GANG_TURF ) {
return Turf_CreateHardpoint( );
}
2018-11-10 06:57:54 +00:00
// accumulate average player count
g_weekAveragePlayers += float( Iter_Count( Player ) );
g_weekSecondsElapsed ++;
// begin auto turf takeover etc
2018-11-09 16:02:14 +00:00
if ( g_gangHardpointAttacker != INVALID_GANG_ID )
2018-10-16 15:20:20 +00:00
{
2018-11-09 16:02:14 +00:00
new total_in_turf = Turf_GetPlayersInTurf( hardpoint_turf );
new attacking_members = GetPlayersInGangZone( hardpoint_turf, g_gangHardpointAttacker );
2018-10-16 15:20:20 +00:00
2018-11-09 16:02:14 +00:00
// no attacking members inside the turf
if ( ! attacking_members )
2018-10-16 15:20:20 +00:00
{
new
2018-11-09 16:02:14 +00:00
new_attacker = INVALID_GANG_ID;
2018-11-10 03:44:16 +00:00
foreach ( new playerid : Player ) if ( GetPlayerGang( playerid ) != INVALID_GANG_ID && IsPlayerInDynamicArea( playerid, g_gangTurfData[ hardpoint_turf ] [ E_AREA ] ) && Turf_IsAbleToTakeover( playerid ) ) {
2018-11-09 16:02:14 +00:00
new_attacker = GetPlayerGang( playerid );
break;
}
2018-11-10 03:44:16 +00:00
if ( new_attacker != INVALID_GANG_ID ) {
SendClientMessageToGang( g_gangHardpointAttacker, g_gangData[ g_gangHardpointAttacker ] [ E_COLOR ], "[TURF] "COL_WHITE"The territory hardpoint is now being contested by %s!", ReturnGangName( new_attacker ) );
}
2018-11-09 16:02:14 +00:00
Turf_SetHardpointAttacker( new_attacker );
}
new
current_attacker = g_gangHardpointAttacker;
2018-10-16 15:20:20 +00:00
2018-11-09 16:02:14 +00:00
// the attacker could be changed from above, so double checking
if ( current_attacker != INVALID_GANG_ID )
{
// add seconds
g_gangHardpointCaptureTime[ current_attacker ] ++;
2018-11-10 06:57:54 +00:00
// get capture time
2018-11-09 16:02:14 +00:00
new total_capture_seconds = Turf_GetTotalCaptureSeconds( );
// alert gang members
2018-11-10 03:44:16 +00:00
foreach ( new playerid : Player ) if ( GetPlayerGang( playerid ) != INVALID_GANG_ID && IsPlayerInDynamicArea( playerid, g_gangTurfData[ hardpoint_turf ] [ E_AREA ] ) && Turf_IsAbleToTakeover( playerid ) )
2018-10-16 15:20:20 +00:00
{
2018-11-09 16:02:14 +00:00
new player_gang = GetPlayerGang( playerid );
// calculate player earnings
new potential_earnings = total_capture_seconds > 0 ? floatround( float( g_gangHardpointCaptureTime[ player_gang ] ) / float( total_capture_seconds ) * Turf_GetHardpointPrizePool( ) ) : 0;
// message the attacker that they gotta attack
if ( player_gang == current_attacker )
{
new
rivals_members = total_in_turf - attacking_members;
if ( rivals_members ) {
2018-11-10 06:57:54 +00:00
ShowPlayerHelpDialog( playerid, 2500, "~b~Defend~w~ from %d enemy gang member%s!~n~~n~Earning potential is ~g~%s", rivals_members, rivals_members == 1 ? ( "" ) : ( "s" ), cash_format( potential_earnings ) );
2018-11-09 16:02:14 +00:00
} else {
2018-11-11 01:29:41 +00:00
ShowPlayerHelpDialog( playerid, 2500, "~g~%s~w~ is in control for %s!~n~~n~Earning potential is ~g~%s", ReturnGangName( current_attacker ), TimeConvert( g_gangHardpointCaptureTime[ current_attacker ] ), cash_format( potential_earnings ) );
2018-11-09 16:02:14 +00:00
}
}
// message the defender
else if ( player_gang != current_attacker ) {
2018-11-10 06:57:54 +00:00
ShowPlayerHelpDialog( playerid, 2500, "~r~Kill~w~ %d %s member%s!~n~~n~Earning potential is ~r~%s", attacking_members, ReturnGangName( current_attacker ), attacking_members == 1 ? ( "" ) : ( "s" ), cash_format( potential_earnings ) );
2018-11-09 16:02:14 +00:00
}
}
}
}
else
{
new
new_attacker = INVALID_GANG_ID;
2018-10-16 15:20:20 +00:00
2018-11-10 03:44:16 +00:00
foreach ( new playerid : Player ) if ( GetPlayerGang( playerid ) != INVALID_GANG_ID && IsPlayerInDynamicArea( playerid, g_gangTurfData[ hardpoint_turf ] [ E_AREA ] ) && Turf_IsAbleToTakeover( playerid ) ) {
2018-11-09 16:02:14 +00:00
new_attacker = GetPlayerGang( playerid );
break;
}
2018-10-16 15:20:20 +00:00
2018-11-09 16:02:14 +00:00
Turf_SetHardpointAttacker( new_attacker );
}
return 1;
}
stock Turf_GetPlayersInTurf( turfid )
{
new
players_accum = 0;
foreach ( new g : gangs ) {
players_accum += GetPlayersInGangZone( turfid, g );
}
return players_accum;
}
2018-10-16 15:20:20 +00:00
2018-11-09 16:02:14 +00:00
stock Turf_CreateHardpoint( )
{
// reset gang accumulated time
for ( new i = 0; i < sizeof ( g_gangHardpointCaptureTime ); i ++ ) {
g_gangHardpointCaptureTime[ i ] = 0;
}
2018-11-18 09:57:12 +00:00
// fixed zone rotation
if ( ! ( 0 <= g_gangHardpointRotation ++ < sizeof( g_gangzoneData ) - 1 ) ) {
g_gangHardpointRotation = 0;
2018-11-09 16:02:14 +00:00
}
// allocate new hardpoint
2018-11-18 09:57:12 +00:00
g_gangHardpointTurf = g_gangHardpointRotation;
2018-11-09 16:02:14 +00:00
g_gangHardpointAttacker = INVALID_GANG_ID;
2018-11-10 06:57:54 +00:00
DestroyDynamicMapIcon( g_gangHardpointMapIcon );
2018-11-09 16:02:14 +00:00
2018-11-10 03:44:16 +00:00
// update hardpoint textdraw
foreach ( new playerid : Player )
{
if ( g_gangHardpointPreviousTurf != INVALID_GANG_TURF && IsPlayerInDynamicArea( playerid, g_gangTurfData[ g_gangHardpointPreviousTurf ] [ E_AREA ] ) ) {
CallLocalFunction( "OnPlayerUpdateGangZone", "dd", playerid, g_gangHardpointPreviousTurf );
}
else if ( g_gangHardpointTurf != INVALID_GANG_TURF && IsPlayerInDynamicArea( playerid, g_gangTurfData[ g_gangHardpointTurf ] [ E_AREA ] ) ) {
CallLocalFunction( "OnPlayerUpdateGangZone", "dd", playerid, g_gangHardpointTurf );
}
}
2018-11-10 06:57:54 +00:00
// create map icon
new
Float: middle_x, Float: middle_y;
Turf_GetMiddlePos( g_gangHardpointTurf, middle_x, middle_y );
g_gangHardpointMapIcon = CreateDynamicMapIcon( middle_x, middle_y, 0.0, 19, -1, -1, -1, 0, 3000.0, MAPICON_GLOBAL );
Streamer_RemoveArrayData( STREAMER_TYPE_MAP_ICON, g_gangHardpointMapIcon, E_STREAMER_PLAYER_ID, 0 );
2018-11-09 16:02:14 +00:00
// redraw gangzones
Turf_RedrawGangZonesForAll( );
return 1;
}
hook OnGangUnload( gangid, bool: deleted )
{
g_gangHardpointCaptureTime[ gangid ] = 0;
return 1;
}
2018-11-10 06:57:54 +00:00
hook OnPlayerLeaveGang( playerid, gangid, reason )
{
HideHardpointIconForPlayer( playerid );
return 1;
}
hook OnPlayerJoinGang( playerid, gangid )
{
ShowHardpointIconForPlayer( playerid );
return 1;
}
2018-11-09 16:02:14 +00:00
hook OnServerGameDayEnd( )
{
new
total_capture_seconds = Turf_GetTotalCaptureSeconds( );
// payout gangs if there is any capable
if ( total_capture_seconds )
{
// payout gangs
foreach ( new g : gangs )
{
2018-11-10 03:44:16 +00:00
new Float: capture_ratio = float( g_gangHardpointCaptureTime[ g ] ) / float( total_capture_seconds );
new earnings = floatround( capture_ratio * Turf_GetHardpointPrizePool( ) );
2018-11-09 16:02:14 +00:00
if ( earnings > 0 )
{
2018-11-10 03:44:16 +00:00
g_gangData[ g ] [ E_RESPECT ] += floatround( capture_ratio * 100.0 ); // give the gang a % of respect out of how much they captured
GiveGangCash( g, earnings );
SaveGangData( g );
2018-11-09 16:02:14 +00:00
SendClientMessageToGang( g, g_gangData[ g ] [ E_COLOR ], "[GANG] "COL_GOLD"%s"COL_WHITE" has been earned from territories and deposited in the gang bank account.", cash_format( earnings ) );
}
2018-10-16 15:20:20 +00:00
}
}
2018-11-09 16:02:14 +00:00
// reset hardpoint
2018-11-10 03:44:16 +00:00
g_gangHardpointPreviousTurf = g_gangHardpointTurf;
2018-11-09 16:02:14 +00:00
g_gangHardpointTurf = INVALID_GANG_TURF;
2018-11-10 06:57:54 +00:00
g_weekAveragePlayers = 0.0;
g_weekSecondsElapsed = 0.0;
2018-11-09 16:02:14 +00:00
return 1;
}
hook OnPlayerSpawn( playerid )
{
Turf_RedrawPlayerGangZones( playerid );
2018-10-16 15:20:20 +00:00
return 1;
}
2018-09-09 16:01:29 +00:00
hook OnPlayerEnterDynArea( playerid, areaid )
{
if ( ! IsPlayerNPC( playerid ) )
{
new
first_turf = Turf_GetFirstTurf( playerid );
2018-11-09 16:02:14 +00:00
// update textdraws
2018-09-09 16:01:29 +00:00
CallLocalFunction( "OnPlayerUpdateGangZone", "dd", playerid, first_turf );
}
return Y_HOOKS_CONTINUE_RETURN_1;
}
2018-11-09 16:02:14 +00:00
stock Turf_SetHardpointAttacker( gangid )
{
if ( g_gangHardpointAttacker == INVALID_GANG_ID && gangid == INVALID_GANG_ID )
return;
// set current attacker
g_gangHardpointAttacker = gangid;
// alert gang
2018-11-10 03:44:16 +00:00
if ( gangid != INVALID_GANG_ID ) {
SendClientMessageToGang( gangid, g_gangData[ gangid ] [ E_COLOR ], "[TURF] "COL_WHITE"The gang is now contesting the territory hardpoint!" );
}
// update label
foreach ( new playerid : Player ) if ( g_gangHardpointTurf != INVALID_GANG_TURF && IsPlayerInDynamicArea( playerid, g_gangTurfData[ g_gangHardpointTurf ] [ E_AREA ] ) ) {
CallLocalFunction( "OnPlayerUpdateGangZone", "dd", playerid, g_gangHardpointTurf );
}
2018-11-09 16:02:14 +00:00
// redraw
Turf_RedrawGangZonesForAll( );
}
2018-09-09 16:01:29 +00:00
hook OnPlayerLeaveDynArea( playerid, areaid )
{
if ( ! IsPlayerNPC( playerid ) )
{
new
total_areas = GetPlayerNumberDynamicAreas( playerid );
// reduced to another area
if ( total_areas )
{
new
first_turf = Turf_GetFirstTurf( playerid );
CallLocalFunction( "OnPlayerUpdateGangZone", "dd", playerid, first_turf );
}
// if the player is in no areas, then they left
else CallLocalFunction( "OnPlayerUpdateGangZone", "dd", playerid, INVALID_GANG_TURF );
}
return Y_HOOKS_CONTINUE_RETURN_1;
}
2018-11-10 03:44:16 +00:00
public OnPlayerUpdateGangZone( playerid, zoneid )
{
if ( ! IsPlayerMovieMode( playerid ) )
{
if ( zoneid == INVALID_GANG_TURF )
return PlayerTextDrawSetString( playerid, g_ZoneOwnerTD[ playerid ], "_" );
if ( g_gangTurfData[ zoneid ] [ E_FACILITY_GANG ] != INVALID_GANG_ID ) {
PlayerTextDrawSetString( playerid, g_ZoneOwnerTD[ playerid ], sprintf( "~p~(FACILITY)~n~~w~~h~%s", ReturnGangName( g_gangTurfData[ zoneid ] [ E_OWNER ] ) ) );
} else {
if ( g_gangTurfData[ g_gangHardpointTurf ] [ E_ID ] != g_gangTurfData[ zoneid ] [ E_ID ] ) {
PlayerTextDrawSetString( playerid, g_ZoneOwnerTD[ playerid ], "~b~~h~(INACTIVE HARDPOINT)~n~~w~~h~Unchallenged" );
} else {
2018-11-23 18:22:32 +00:00
DisablePlayerSpawnProtection( playerid );
2018-11-10 03:44:16 +00:00
PlayerTextDrawSetString( playerid, g_ZoneOwnerTD[ playerid ], sprintf( "~r~~h~(ACTIVE HARDPOINT)~n~~w~~h~%s", g_gangHardpointAttacker != INVALID_GANG_ID ? ( ReturnGangName( g_gangHardpointAttacker ) ) : ( "Unchallenged" ) ) );
}
}
}
return 1;
}
2018-09-09 16:01:29 +00:00
/* ** Functions ** */
2018-11-18 09:57:12 +00:00
stock Turf_Create( Float: min_x, Float: min_y, Float: max_x, Float: max_y, owner_id = INVALID_GANG_ID, color = COLOR_GANGZONE, facility_gang_id = INVALID_GANG_ID, Float: bordersize = GANGZONE_DEFAULT_BORDER_SIZE, Float: numbersize = 0.0 )
2018-09-09 16:01:29 +00:00
{
new
id = Iter_Free( turfs );
if ( id != ITER_NONE )
{
// set turf owners
g_gangTurfData[ id ] [ E_OWNER ] = owner_id;
g_gangTurfData[ id ] [ E_COLOR ] = color;
g_gangTurfData[ id ] [ E_FACILITY_GANG ] = facility_gang_id;
// create area
2018-11-18 09:57:12 +00:00
g_gangTurfData[ id ] [ E_ID ] = GangZoneCreate( min_x, min_y, max_x, max_y, .bordersize = bordersize, .numbersize = numbersize );
2018-09-09 16:01:29 +00:00
g_gangTurfData[ id ] [ E_AREA ] = CreateDynamicRectangle( min_x, min_y, max_x, max_y, 0, 0 );
// add to iterator
Iter_Add( turfs, id );
}
return id;
}
stock Turf_GetOwner( id ) {
return g_gangTurfData[ id ] [ E_OWNER ];
}
stock Turf_GetFacility( id ) {
return g_gangTurfData[ id ] [ E_FACILITY_GANG ];
}
stock Turf_GetFirstTurf( playerid )
{
new
current_areas[ 4 ];
GetPlayerDynamicAreas( playerid, current_areas );
foreach( new i : Reverse(turfs) )
{
if ( current_areas[ 0 ] == g_gangTurfData[ i ] [ E_AREA ] || current_areas[ 1 ] == g_gangTurfData[ i ] [ E_AREA ] || current_areas[ 2 ] == g_gangTurfData[ i ] [ E_AREA ] || current_areas[ 3 ] == g_gangTurfData[ i ] [ E_AREA ] )
{
return i;
}
}
return -1;
}
2018-10-16 15:20:20 +00:00
stock Turf_ResetGangTurfs( gangid )
{
foreach ( new z : turfs )
{
if ( g_gangTurfData[ z ] [ E_OWNER ] == gangid )
{
new
facility_gang = g_gangTurfData[ z ] [ E_FACILITY_GANG ];
if ( g_gangTurfData[ z ] [ E_FACILITY_GANG ] != INVALID_GANG_ID && Iter_Contains( gangs, g_gangTurfData[ z ] [ E_FACILITY_GANG ] ) )
{
g_gangTurfData[ z ] [ E_COLOR ] = setAlpha( g_gangData[ facility_gang ] [ E_COLOR ], 0x80 );
g_gangTurfData[ z ] [ E_OWNER ] = facility_gang;
GangZoneShowForAll( g_gangTurfData[ z ] [ E_ID ], g_gangTurfData[ z ] [ E_COLOR ] );
}
else
{
g_gangTurfData[ z ] [ E_COLOR ] = COLOR_GANGZONE;
g_gangTurfData[ z ] [ E_OWNER ] = INVALID_GANG_ID;
GangZoneShowForAll( g_gangTurfData[ z ] [ E_ID ], COLOR_GANGZONE );
}
}
}
}
stock Turf_ShowGangOwners( playerid )
{
if ( ! Iter_Count( turfs ) )
return SendError( playerid, "There is currently no trufs on the server." );
szHugeString[ 0 ] = '\0';
foreach( new turfid : turfs )
{
new
szLocation[ MAX_ZONE_NAME ], Float: min_x, Float: min_y;
Streamer_GetFloatData( STREAMER_TYPE_AREA, g_gangTurfData[ turfid ] [ E_AREA ], E_STREAMER_MIN_X, min_x );
Streamer_GetFloatData( STREAMER_TYPE_AREA, g_gangTurfData[ turfid ] [ E_AREA ], E_STREAMER_MIN_Y, min_y );
GetZoneFromCoordinates( szLocation, min_x, min_y );
if ( g_gangTurfData[ turfid ][ E_OWNER ] == INVALID_GANG_ID ) {
format( szHugeString, sizeof( szHugeString ), "%s%s\t"COL_GREY"Unoccupied\n", szHugeString, szLocation );
}
else {
format( szHugeString, sizeof( szHugeString ), "%s%s\t{%06x}%s\n", szHugeString, szLocation, g_gangTurfData[ turfid ][ E_COLOR ] >>> 8 , ReturnGangName( g_gangTurfData[ turfid ][ E_OWNER ] ) );
}
}
return ShowPlayerDialog( playerid, DIALOG_NULL, DIALOG_STYLE_TABLIST, ""COL_WHITE"Gang Turfs", szHugeString, "Close", "" );
}
2018-11-09 16:02:14 +00:00
stock Turf_GetCentrePos( zoneid, &Float: X, &Float: Y ) // should return the centre but will do for now
{
Streamer_GetFloatData( STREAMER_TYPE_AREA, g_gangTurfData[ zoneid ] [ E_AREA ], E_STREAMER_MIN_X, X );
Streamer_GetFloatData( STREAMER_TYPE_AREA, g_gangTurfData[ zoneid ] [ E_AREA ], E_STREAMER_MIN_Y, Y );
}
2018-11-10 03:44:16 +00:00
stock GetPlayersInGangZone( z, g )
2018-11-09 16:02:14 +00:00
{
if ( g == INVALID_GANG_ID )
return 0;
2018-11-10 03:44:16 +00:00
new
count = 0;
2018-11-09 16:02:14 +00:00
2018-11-10 03:44:16 +00:00
foreach ( new i : Player ) if ( p_GangID[ i ] == g && IsPlayerInDynamicArea( i, g_gangTurfData[ z ] [ E_AREA ] ) && Turf_IsAbleToTakeover( i ) ) {
count++;
2018-11-09 16:02:14 +00:00
}
return count;
}
2018-11-10 03:44:16 +00:00
stock Turf_IsAbleToTakeover( i ) {
new
Float: Z;
GetPlayerPos( i, Z, Z, Z );
2018-11-14 14:11:44 +00:00
return p_Class[ i ] == CLASS_CIVILIAN && ! p_AntiSpawnKillEnabled{ i } && ! IsPlayerPassive( i ) && ! IsPlayerAdminOnDuty( i ) && GetPlayerState( i ) != PLAYER_STATE_SPECTATING && ! IsPlayerAFK( i ) && Z <= 250.0;
2018-11-10 03:44:16 +00:00
}
2018-11-09 16:02:14 +00:00
stock Turf_RedrawPlayerGangZones( playerid )
2018-10-16 15:20:20 +00:00
{
foreach ( new x : turfs )
{
2018-11-09 16:02:14 +00:00
if ( g_gangHardpointTurf == g_gangTurfData[ x ] [ E_ID ] ) {
if ( g_gangHardpointAttacker != INVALID_GANG_ID ) {
GangZoneStopFlashForPlayer( playerid, g_gangTurfData[ x ] [ E_ID ] );
GangZoneFlashForPlayer( playerid, g_gangTurfData[ x ] [ E_ID ], setAlpha( g_gangData[ g_gangHardpointAttacker ] [ E_COLOR ], 0x80 ) );
} else {
GangZoneHideForPlayer( playerid, g_gangTurfData[ x ] [ E_ID ] );
GangZoneShowForPlayer( playerid, g_gangTurfData[ x ] [ E_ID ], g_gangHardpointTurf == g_gangTurfData[ x ] [ E_ID ] ? COLOR_HARDPOINT : g_gangTurfData[ x ] [ E_COLOR ] );
}
2018-10-16 15:20:20 +00:00
} else {
GangZoneHideForPlayer( playerid, g_gangTurfData[ x ] [ E_ID ] );
GangZoneShowForPlayer( playerid, g_gangTurfData[ x ] [ E_ID ], g_gangTurfData[ x ] [ E_COLOR ] );
}
}
2018-11-10 06:57:54 +00:00
if ( GetPlayerClass( playerid ) == CLASS_CIVILIAN && GetPlayerGang( playerid ) != INVALID_GANG_ID ) {
ShowHardpointIconForPlayer( playerid );
} else {
HideHardpointIconForPlayer( playerid );
}
2018-10-16 15:20:20 +00:00
return 1;
}
2018-11-09 16:02:14 +00:00
stock Turf_RedrawGangZonesForAll( )
2018-10-16 15:20:20 +00:00
{
2018-11-09 16:02:14 +00:00
foreach ( new x : turfs )
{
if ( g_gangHardpointTurf == g_gangTurfData[ x ] [ E_ID ] ) {
if ( g_gangHardpointAttacker != INVALID_GANG_ID ) {
GangZoneStopFlashForAll( g_gangTurfData[ x ] [ E_ID ] );
GangZoneFlashForAll( g_gangTurfData[ x ] [ E_ID ], setAlpha( g_gangData[ g_gangHardpointAttacker ] [ E_COLOR ], 0x80 ) );
} else {
GangZoneHideForAll( g_gangTurfData[ x ] [ E_ID ] );
GangZoneShowForAll( g_gangTurfData[ x ] [ E_ID ], g_gangHardpointTurf == g_gangTurfData[ x ] [ E_ID ] ? COLOR_HARDPOINT : g_gangTurfData[ x ] [ E_COLOR ] );
}
} else {
GangZoneHideForAll( g_gangTurfData[ x ] [ E_ID ] );
GangZoneShowForAll( g_gangTurfData[ x ] [ E_ID ], g_gangTurfData[ x ] [ E_COLOR ] );
}
}
2018-11-10 06:57:54 +00:00
foreach ( new playerid : Player ) {
if ( GetPlayerClass( playerid ) == CLASS_CIVILIAN && GetPlayerGang( playerid ) != INVALID_GANG_ID ) {
ShowHardpointIconForPlayer( playerid );
} else {
HideHardpointIconForPlayer( playerid );
}
}
2018-11-09 16:02:14 +00:00
return 1;
}
stock Turf_GetTotalCaptureSeconds( ) {
new
accum_seconds = 0;
for ( new i = 0; i < sizeof ( g_gangHardpointCaptureTime ); i ++ ) {
accum_seconds += g_gangHardpointCaptureTime[ i ];
}
return accum_seconds;
2018-10-16 15:20:20 +00:00
}
2018-11-10 06:57:54 +00:00
stock Turf_GetMiddlePos( zoneid, &Float: middle_x, &Float: middle_y )
{
new
Float: min_x, Float: min_y, Float: max_x, Float: max_y;
Streamer_GetFloatData( STREAMER_TYPE_AREA, g_gangTurfData[ zoneid ] [ E_AREA ], E_STREAMER_MIN_X, min_x );
Streamer_GetFloatData( STREAMER_TYPE_AREA, g_gangTurfData[ zoneid ] [ E_AREA ], E_STREAMER_MIN_Y, min_y );
Streamer_GetFloatData( STREAMER_TYPE_AREA, g_gangTurfData[ zoneid ] [ E_AREA ], E_STREAMER_MAX_X, max_x );
Streamer_GetFloatData( STREAMER_TYPE_AREA, g_gangTurfData[ zoneid ] [ E_AREA ], E_STREAMER_MAX_Y, max_y );
middle_x = ( min_x + max_x ) / 2.0;
middle_y = ( min_y + max_y ) / 2.0;
}