Script:Files:script/teams/gdf.script

From Mod Wiki
Revision as of 10:14, 5 November 2007 by Wizz (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
object team_gdf {
    void    preinit();
    void    syncFields();
    void    destroy();

    boolean    OnAllowRespawn( entity p );
    void    RespawnWaves();

    void    OnNextRespawnTimeChanged();
    void    SetRespawnTimer( float t );

    float    GetMineLimit();

    void    GiveSpawnItems( entity p );
    float    GetHealthBoost( entity p );

    void    OnSoldierUpgrade( entity p, float oldLevel, float newLevel, boolean isSpawn );
    void    OnMedicUpgrade( entity p, float oldLevel, float newLevel, boolean isSpawn );
    void    OnCovertOpsUpgrade( entity p, float oldLevel, float newLevel, boolean isSpawn );
    void    OnBattleSenseUpgrade( entity p, float oldLevel, float newLevel, boolean isSpawn );
    void    OnLightWeaponsUpgrade( entity p, float oldLevel, float newLevel, boolean isSpawn );
    void    OnProficiencyUpgrade( entity p, float type, float oldLevel, float newLevel );

    boolean    HasConstructionBonus( entity p );
    boolean    HasRepairBonus( entity p );
    boolean    HasDisarmBonus( entity p );
    boolean    HasChargeArmBonus( entity p );
    boolean    HasSelfArmingMines( entity p );
    boolean    HasFastFireSupportLock( entity p );
    boolean    HasFastFireSupportRecharge( entity p );
    boolean    HasFastHackBonus( entity p );
    boolean    HasVehicleArmorBonus( entity p );
    boolean    HasEnhancedRadar( entity p );
    boolean    HasPersonalJammer( entity p );
    boolean    CanRequestVehicle( entity p );
    boolean    HasEfficientDecoys( entity p );
    boolean    HasSpreadBonus( entity p );
    boolean    HasFastTargetLock( entity p );
    float    GetMaxSupplies( entity p );
    boolean    CanStab( entity p );

    void    CreatePersonnelAuras( entity p );

    float    GetFireSupportDelayScale();

    float    GetWeaponSpeedBonus( entity p );

    void    RegenPulse( entity p );

    void    KillSpawnWaves();
    void    SetRespawnWait( float time );

    void    OnMapStart();

    float    allowRespawnTime;
    float    nextRespawnTime;

    float   GetNextRespawnTime() { return nextRespawnTime; }
}

void team_gdf::syncFields() {
    syncBroadcast( "nextRespawnTime" );
    syncCallback( "nextRespawnTime", "OnNextRespawnTimeChanged" );
}

void team_gdf::OnNextRespawnTimeChanged() {
    SetRespawnTimer( nextRespawnTime );
}


void team_gdf::preinit() {
    gdfTeam = self;

    repairItem                    = "inventory/tools/pliers";
    hackItem                    = "inventory/tools/pliers_hack";
    chargeArmItem                = "inventory/tools/pliers/charge";
    chargeDisarmItem            = "inventory/tools/pliers";
    armItem                        = "inventory/tools/pliers";
    constructItem                = "inventory/tools/pliers";
    disguiseItem                = "inventory/tools/pliers_hack";
    reviveItem                    = "inventory/tools/defibrillator";
    stabItem                    = "inventory/weapons/knife";
    disguisedStabItem            = "inventory/weapons/spikes/gdf";
    plantItem                    = "inventory/items/he_charge";
    spawnHostDisarmItem            = "inventory/tools/defibrillator";

    respawnWait                    = 20.f;

    structureName                = sys.localizeString( "game/struct/commandcenter" );

    spottingProficiency            = GetProficiency( "pro_covertops_spot" );
    radarSpottingProficiency    = GetProficiency( "pro_covertops_radar_spot" );
    repairProficiency            = GetProficiency( "pro_engineer_repair" );
    reviveProficiency            = GetProficiency( "pro_medic_revive" );
    reviveWaitProficiency        = GetProficiency( "pro_battlesense_revive_wait" );
    backstabDisguisedProficiency= GetProficiency( "pro_covertops_backstab_disguised" );

    reviveMeToolTip1            = GetToolTip( getKey( "tt_player_revive_1" ) );
    reviveMeToolTip2            = GetToolTip( getKey( "tt_player_revive_2" ) );
    parachuteToolTip            = GetToolTip( getKey( "tt_player_parachute" ) );

    vehicleRepairTask            = GetPlayerTask( getKey( "task_vehicle_repair" ) );
    captureSpawnTask            = GetPlayerTask( getKey( "task_capture_spawn" ) );
    liberateSpawnTaskCovertOnly    = GetPlayerTask( getKey( "task_liberate_spawn_covert" ) );
    liberateSpawnTask            = GetPlayerTask( getKey( "task_liberate_spawn" ) );
}

void team_gdf::KillSpawnWaves() {
    sys.killThread( "RespawnWaves_gdf" );
}

void team_gdf::OnMapStart() {
    OnMapStart_Base();

    KillSpawnWaves();

    if ( !sys.isClient() ) {
        thread RespawnWaves();
    }
}

void team_gdf::destroy() {
    KillSpawnWaves();
}

boolean team_gdf::OnAllowRespawn( entity p ) {
    return sys.getTime() < allowRespawnTime;
}

void team_gdf::RespawnWaves() {
    sys.threadName( "RespawnWaves_gdf" );

    allowRespawnTime = sys.getTime() + 1.f;

    sys.wait( 0.5f );

    while ( true ) {
        nextRespawnTime = sys.getTime() + respawnWait;
        SetRespawnTimer( nextRespawnTime );

        sys.wait( respawnWait );

        allowRespawnTime = sys.getTime() + 0.5f;
        MarkWaitingPlayers();
    }
}

void team_gdf::SetRespawnTimer( float t ) {
    player p = sys.getLocalPlayer();
    if( p != $null_entity ) {
        sys.setGUIFloat( GUI_GLOBALS_HANDLE, "gameHud.gdfRespawnTime", nextRespawnTime * 1000 );
        player viewPlayer = sys.getLocalViewPlayer();
        if ( viewPlayer != $null_entity ) {
            team_base team = viewPlayer.getGameTeam();
            if ( team == gdfTeam ) {
                sys.setGUIFloat( GUI_GLOBALS_HANDLE, "gameHud.spectatingRespawnTime", nextRespawnTime * 1000 );
            }
        }
    }
}

float team_gdf::GetMineLimit() {
    return 3.f;
}

void team_gdf::OnSoldierUpgrade( entity p, float oldLevel, float newLevel, boolean isSpawn ) {
    ON_UPGRADE( 2 ) {
        UpgradeClip( p, g_ammoRocketLauncher, 2 );
        UpgradeClip( p, g_ammoGPMG, 100 );

        if ( isSpawn ) {
            p.setAmmo( g_ammoRocketLauncher, p.getAmmo( g_ammoRocketLauncher ) + 2 );
            p.setAmmo( g_ammoGPMG, p.getAmmo( g_ammoGPMG ) + 100 );
        }
    }
}

void team_gdf::OnMedicUpgrade( entity p, float oldLevel, float newLevel, boolean isSpawn ) {
}

void team_gdf::OnBattleSenseUpgrade( entity p, float oldLevel, float newLevel, boolean isSpawn ) {
    ON_UPGRADE( 1 ) {
        p.setSprintScale( 1.1f );
    }

    ON_UPGRADE( 2 ) {
        if ( isSpawn ) {
            p.setArmor( 0.2f );
        }
    }

    ON_UPGRADE( 4 ) {
        p.vStartRegenThread();
    }
}

void team_gdf::OnLightWeaponsUpgrade( entity p, float oldLevel, float newLevel, boolean isSpawn ) {
    ON_UPGRADE( 1 ) {
        UpgradeClip( p, g_ammoPistol, 10 );
        UpgradeClip( p, g_ammoMachinePistol, 20 );
        UpgradeClip( p, g_ammoAssaultRifle, 40 );
        UpgradeClip( p, g_ammoShotgun, 10 );
        UpgradeClip( p, g_ammoSniperRifle, 10 );
        if ( isSpawn ) {
            UpgradeAmmo( p, g_ammoMachinePistol, 20 );
            UpgradeAmmo( p, g_ammoAssaultRifle, 40 );
            UpgradeAmmo( p, g_ammoShotgun, 10 );
            UpgradeAmmo( p, g_ammoSniperRifle, 10 );
            UpgradeAmmo( p, g_ammoPistol, 10 );
        }
    }

    ON_UPGRADE( 2 ) {
        UpgradeClip( p, g_ammoGrenade, 1 );
        if ( isSpawn ) {
            UpgradeAmmo( p, g_ammoGrenade, 1 );
        }
    }
}

void team_gdf::OnCovertOpsUpgrade( entity p, float oldLevel, float newLevel, boolean isSpawn ) {
    ON_UPGRADE( 4 ) {
        float index;
        float limit = sys.getMaxClients();
        for ( index = 0; index < limit; index++ ) {
            entity other = sys.getClient( index );
            if ( other == $null_entity ) {
                continue;
            }

            other.vOnLocalTeamChanged();
        }
    }
}

void team_gdf::GiveSpawnItems( entity p ) {
    OnSoldierUpgrade( p, 0, p.getProficiency( g_proficiencySoldier ), true );
    OnMedicUpgrade( p, 0, p.getProficiency( g_proficiencyMedic ), true );
    OnCovertOpsUpgrade( p, 0, p.getProficiency( g_proficiencyCovertOps ), true );
    OnBattleSenseUpgrade( p, 0, p.getProficiency( g_proficiencyBattleSense ), true );
    OnLightWeaponsUpgrade( p, 0, p.getProficiency( g_proficiencyLightWeapons ), true );
}

void team_gdf::OnProficiencyUpgrade( entity p, float type, float oldLevel, float newLevel ) {
    if ( type == g_proficiencySoldier ) {
        OnSoldierUpgrade( p, oldLevel, newLevel, false );
    } else if ( type == g_proficiencyMedic ) {
        OnMedicUpgrade( p, oldLevel, newLevel, false );
    } else if ( type == g_proficiencyCovertOps ) {
        OnCovertOpsUpgrade( p, oldLevel, newLevel, false );
    } else if ( type == g_proficiencyBattleSense ) {
        OnBattleSenseUpgrade( p, oldLevel, newLevel, false );
    } else if ( type == g_proficiencyLightWeapons ) {
        OnLightWeaponsUpgrade( p, oldLevel, newLevel, false );
    }
}

boolean    team_gdf::HasConstructionBonus( entity p ) {
    return p.getProficiency( g_proficiencyEngineer ) >= 3;
}

boolean    team_gdf::HasRepairBonus( entity p ) {
    return p.getProficiency( g_proficiencyEngineer ) >= 2;
}

boolean    team_gdf::HasDisarmBonus( entity p ) {
    return p.getProficiency( g_proficiencyEngineer ) >= 3;
}

boolean    team_gdf::HasChargeArmBonus( entity p ) {
    return p.getProficiency( g_proficiencySoldier ) >= 3;
}

boolean    team_gdf::HasSelfArmingMines( entity p ) {
    return p.getProficiency( g_proficiencyEngineer ) >= 4;
}

boolean    team_gdf::HasFastFireSupportLock( entity p ) {
    return p.getProficiency( g_proficiencyFieldOps ) >= 3;
}

boolean    team_gdf::HasFastFireSupportRecharge( entity p ) {
    return p.getProficiency( g_proficiencyFieldOps ) >= 4;
}

boolean    team_gdf::HasFastHackBonus( entity p ) {
    return p.getProficiency( g_proficiencyCovertOps ) >= 3;
}

boolean    team_gdf::HasVehicleArmorBonus( entity p ) {
    return p.getProficiency( g_proficiencyVehicle ) >= 4;
}

boolean    team_gdf::HasEnhancedRadar( entity p ) {
    return p.getProficiency( g_proficiencyCovertOps ) >= 2;
}

boolean    team_gdf::HasPersonalJammer( entity p ) {
    if ( p.getPlayerClass() != g_playerClassCovertOps ) {
        return false;
    }
    return p.getProficiency( g_proficiencyCovertOps ) >= 4;
}

boolean    team_gdf::HasFastTargetLock( entity p ) {
    return p.getProficiency( g_proficiencySoldier ) >= 1;
}

boolean    team_gdf::CanRequestVehicle( entity p ) {
    return p.getProficiency( g_proficiencyVehicle ) >= 1;
}

boolean    team_gdf::HasEfficientDecoys( entity p ) {
    return p.getProficiency( g_proficiencyVehicle ) >= 2;
}

boolean    team_gdf::HasSpreadBonus( entity p ) {
    return p.getProficiency( g_proficiencyLightWeapons ) >= 3;
}

boolean    team_gdf::CanStab( entity p ) {
    return ( p.getPlayerClass() == g_playerClassCovertOps ) || p.isDisguised();
}

float team_gdf::GetMaxSupplies( entity p ) {
    if ( p.getProficiency( g_proficiencyMedic ) >= 2 ) {
        return 2.f;
    }
    return 1.f;
}

float team_gdf::GetWeaponSpeedBonus( entity p ) {
    if ( p.getPlayerClass() == g_playerClassSoldier ) {
        if ( p.getProficiency( g_proficiencySoldier ) >= 4 ) {
            return 0.5f;
        }
    }

    return 0.f;
}

float team_gdf::GetHealthBoost( entity p ) {
    float bonus = 0.f;

    float playerClass = p.getPlayerClass();
    if ( playerClass == g_playerClassSoldier ) {
        bonus = bonus + 20.f;
    }

    float maxClients = sys.getMaxClients();
    float index;
    float boost = 0;
    for ( index = 0; index < maxClients; index++ ) {
        entity other = sys.getClient( index );
        if ( other == $null_entity ) {
            continue;
        }

        if ( other.getGameTeam() != self ) {
            continue;
        }

        if ( other.hasAbility( "healthBoost" ) ) {
            boost = boost + HEALTH_BOOST;

            if ( boost >= MAX_HEALTH_BOOST ) {
                boost = MAX_HEALTH_BOOST;
                break;
            }
        }
    }

    bonus = bonus + boost;

    return bonus;
}

void team_gdf::SetRespawnWait( float time ) {
    respawnWait = time;
}

void team_gdf::CreatePersonnelAuras( entity p ) {
    if ( !sys.isClient() ) {
        if ( p.getProficiency( g_proficiencyBattleSense ) >= 4 ) {
            p.vStartRegenThread();
        }
    }
}

void team_gdf::RegenPulse( entity p ) {
    float current = p.getHealth();
    float limit = p.getMaxHealth();
    if ( current >= limit ) {
        return;
    }

    current = current + 1;
    if ( current > limit ) {
        current = limit;
    }
    p.setHealth( current );
}

float team_gdf::GetFireSupportDelayScale() {
    float count = CountPlayersOfClass( g_playerClassFieldOps ) - 1;
    float scale = 1.f;
    if ( count > 0 ) {
        scale = scale + ( count * 0.5f );
    }
    return scale;
}