Mach III Logo by Spliff (spliff@vweb.net.au) Half-Life Development, Tutorials,
Modifications, and more!

Hosted by
PlanetHalfLife

NEWS
PROJECTS

SprView

SprMake

Source

ARTICLES

PainRift

Interview

"The Motion"

WANT ADS
TUTORIAL
LINKS
CREDITS

(c) 1999
Mach III Enterprises

 

[ Secondary Fire ] Gauss Turret ] Hornet Gun Turret ] Laser Spot ]

SECONDARY FIRE

Here's how you PREPARE a turret to support the secondary fire mode. What the turret actually does can be altered at your discretion, because we'll be making a virtual function that could be overriden to your heart's content...


All modifications will be in the "dlls\func_tank.cpp"...

  • In the definition of CFuncTank, you will see the definition for the Fire virtual function, as such:

    virtual void Fire( const Vector &barrelEnd, const Vector &forward,
                       entvars_t *pevAttacker );

    Right under it, we want to add our own secondary fire function...

    //*** NEW - SECONDARY FIRE
    virtual void SecondaryFire( const Vector &barrelEnd, const Vector &forward,
         entvars_t *pevAttacker );

  • Now we need to give it some basic functionality, so that the non-overriden "children" of CFuncTank (CFuncTankLaser, CFuncTankGun, etc...) know how to deal with it. For arguments sake, we'll give the secondary fire the default functionality of the primary fire.

    Therefore, right after the body of
    CFuncTank::Fire...

    //*** NEW - SECONDARY FIRE
    void CFuncTank::SecondaryFire( const Vector &barrelEnd, const Vector &forward,
         entvars_t *pevAttacker )
    {
        Fire(barrelEnd, forward, pevAttacker);
    }

  • Now the engine needs to call it. As was moderately discussed in the section header, all fire checking is done through the CFuncTank::ControllerPostFrame function. There, by default, it checks if the "IN_ATTACK" flag is set, which is the case when primary fire is in use. We want to check for secondary fire, or "IN_ATTACK2". Therefore, in the aforementioned CFuncTank::ControllerPostFrame function, we need to mirror the primary fire code:

    if ( m_pController->pev->button & IN_ATTACK )
    {
        Vector vecForward;
        UTIL_MakeVectorsPrivate( pev->angles, vecForward, NULL, NULL );

        m_fireLast = gpGlobals->time - (1/m_fireRate) - 0.01;
            // to make sure the gun doesn't fire too many bullets

        Fire( BarrelPosition(), vecForward, m_pController->pev );
           
        // HACKHACK -- make some noise (that the AI can hear)
        if ( m_pController && m_pController->IsPlayer() )
            ((CBasePlayer *)m_pController)->m_iWeaponVolume = LOUD_GUN_VOLUME;

        m_flNextAttack = gpGlobals->time + (1/m_fireRate);
    }


    //*** NEW - SECONDARY FIRE
    else if ( m_pController->pev->button & IN_ATTACK2 )
    {
        Vector vecForward;
        UTIL_MakeVectorsPrivate( pev->angles, vecForward, NULL, NULL );

        m_fireLast = gpGlobals->time - (1/m_fireRate) - 0.01;
            // to make sure the gun doesn't fire too many bullets

        SecondaryFire( BarrelPosition(), vecForward, m_pController->pev );
           
        // HACKHACK -- make some noise (that the AI can hear)
        if ( m_pController && m_pController->IsPlayer() )
            ((CBasePlayer *)m_pController)->m_iWeaponVolume = LOUD_GUN_VOLUME;

        m_flNextAttack = gpGlobals->time + (1/m_fireRate);
    }

    The only differences between the two is the check of "IN_ATTACK2" and the fact that it calls SecondaryFire and not Fire.

  • That's pretty much all there is to it. Now, actually creating different secondary fire modes is another story altogether!

 

TUTORIALS

LEGEND

WEAPONS
ITEMS
WORLD
ENTITIES
SPECIAL
EFFECTS
HEADS-UP
DISPLAY
GAME
INTERFACE
TURRETS
OTHER