Beispiel #1
0
//------------------------------------------------------------------------
void CTactical::StartFire(EntityId shooterId)
{
	if (!m_pWeapon->IsBusy())
	{
		m_pWeapon->RequestStartFire();
		if (m_pWeapon->IsServer())
			NetStartFire(shooterId);
	}
}
void CWeapon::NetUpdateFireMode(SEntityUpdateContext& ctx)
{
    // CGunTurret and CVehicleWeapon overide NetAllowUpdate to perform their own checks.
    if(NetAllowUpdate(true))
    {
        m_netNextShot -= ctx.fFrameTime;

        if(IsReloading())
            return;	// reloading, bail

        if((!m_isFiringStarted) && (m_isFiring || m_shootCounter > 0))
        {
            m_isFiringStarted = true;
            m_netNextShot = 0.f;
            NetStartFire();
            EnableUpdate(true, eIUS_FireMode);
        }

        if(m_fm)
        {
            if(m_shootCounter > 0 && m_netNextShot <= 0.0f)
            {
                // Aside from the prediction handle, needed for the server, NetShoot/Ex parameters
                // are no longer used, these will need removing when the client->server RMI's are tided up
                m_fm->NetShoot(Vec3(0.f, 0.f, 0.f), 0);
                m_shootCounter--;

                //if fireRate == 0.0f, set m_netNextShot to 0.0f, otherwise increment by 60.f / fireRate.
                //	fres used to avoid microcoded instructions, fsel to avoid branching - Rich S
                const float fRawFireRate		= m_fm->GetFireRate();
                const float fFireRateSelect = -fabsf(fRawFireRate);
                const float fFireRateForDiv = (float)__fsel(fFireRateSelect, 1.0f, fRawFireRate);
                const float fNextShot				= (float)__fsel(fFireRateSelect, 0.0f, m_netNextShot + (60.f * __fres(fFireRateForDiv)));
                m_netNextShot = fNextShot;
            }
        }

        if(m_isFiringStarted && !m_isFiring && m_shootCounter <= 0)
        {
            m_isFiringStarted = false;
            NetStopFire();
            EnableUpdate(false, eIUS_FireMode);
        }

        // this needs to happen here, or NetStopFire interrupts the animation
        if(m_doMelee && m_melee)
        {
            m_melee->NetAttack();
            m_doMelee= false;
        }
    }

}
//------------------------------------------------------------------------
IMPLEMENT_RMI(CWeapon, SvRequestStartFire)
{
    CHECK_OWNER_REQUEST();

    CActor *pActor=GetActorByNetChannel(pNetChannel);
    IActor *pLocalActor=m_pGameFramework->GetClientActor();
    bool isLocal = pLocalActor && pActor && (pLocalActor->GetChannelId() == pActor->GetChannelId());

    if (!isLocal)
    {
        NetSetIsFiring(true);
        NetStartFire();
    }

    return true;
}