Script:Files:script/vehicles/anansi.script

From Mod Wiki
Revision as of 09:58, 5 November 2007 by Wizz (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
/*
===================================================================================================

HELI

===================================================================================================
*/
object vehicle_heli : vehicle_base {
    void            init();
    void            syncFields();

    void            OnUpdateHud( entity p, float guiHandle );

    float            collectiveMin;
    float            collectiveMax;

    float            spiralHealth;
    void            OnSpiralHealthSynced();
}

void vehicle_heli::syncFields() {
    syncBroadcast( "spiralHealth" );
    syncCallback( "spiralHealth", "OnSpiralHealthSynced" );
}

void vehicle_heli::init() {
    collectiveMin                        = getFloatKey( "collective_min" );
    collectiveMax                        = getFloatKey( "collective_max" );

    if ( sys.random( 1.0f ) < 0.9f ) {
        spiralHealth = getFloatKey( "spiral_health" );
        OnSpiralHealthSynced();
    } else {
        spiralHealth = 0;
    }
}

void vehicle_heli::OnSpiralHealthSynced() {
    setDeathThroeHealth( spiralHealth );
    float maxHealth = getMaxHealth();
    spiralHealthFrac = spiralHealth / maxHealth;

    float remainingRange = maxHealth - spiralHealth;
    float klaxonHealth = remainingRange * klaxonThreshold + spiralHealth;
    klaxonThreshold = klaxonHealth / maxHealth;
}

void vehicle_heli::OnUpdateHud( entity p, float guiHandle ) {
    entity driver = getDriver();
    if ( driver != p ) {
        return;
    }

    inputSetPlayer( driver );
    float collective = inputGetCollective();
    sys.setGUIFloat( GUI_GLOBALS_HANDLE, "vehicles.collectiveValue", ( collective - collectiveMin ) / ( collectiveMax - collectiveMin ));
}

/*
===================================================================================================

EARTH HELI

===================================================================================================
*/
object vehicle_heli_earth : vehicle_heli {
    void            preinit();
    void            destroy();
};

void vehicle_heli_earth::preinit() {
}

void vehicle_heli_earth::destroy() {
    stopEffect( "fx_downdraft" );
}

/*
===================================================================================================

ANANSI

===================================================================================================
*/
object vehicle_anansi : vehicle_heli_earth {
    void            OnWeaponSelected( entity p, float index );
};

void vehicle_anansi::OnWeaponSelected( entity p, float index ) {
    if ( !sys.isClient() ) {
        if ( index == 0 ) {
            FireDecoy( p );
        } else if ( index == 1 ) {
            selectVehicleWeapon( p, "fafff" );
        } else if ( index == 2 ) {
            selectVehicleWeapon( p, "law" );
        }
    }
}