示例#1
0
bool CKeysyncPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    // Got a player to write?
    if ( m_pSourceElement )
    {
        CPlayer * pSourcePlayer = static_cast < CPlayer * > ( m_pSourceElement );
        CVehicle* pVehicle = pSourcePlayer->GetOccupiedVehicle ();

        // Write the source player id
        ElementID PlayerID = pSourcePlayer->GetID ();
        BitStream.WriteCompressed ( PlayerID );

        // Write the keysync data
        const CControllerState& ControllerState = pSourcePlayer->GetPad ()->GetCurrentControllerState ();
        const CControllerState& LastControllerState = pSourcePlayer->GetPad ()->GetLastControllerState ();
        WriteSmallKeysync ( ControllerState, LastControllerState, BitStream );

        // Flags
        SKeysyncFlags flags;
        flags.data.bIsDucked = ( pSourcePlayer->IsDucked () == true );
        flags.data.bIsChoking = ( pSourcePlayer->IsChoking () == true );
        flags.data.bAkimboTargetUp = ( pSourcePlayer->IsAkimboArmUp () == true );
        flags.data.bSyncingVehicle = ( pVehicle != NULL && pSourcePlayer->GetOccupiedVehicleSeat () == 0 );

        // Write the flags
        BitStream.Write ( &flags );

        // If he's shooting
        if ( ControllerState.ButtonCircle )
        {
            // Write his current weapon slot
            unsigned int uiSlot = pSourcePlayer->GetWeaponSlot ();
            SWeaponSlotSync slot;
            slot.data.uiSlot = uiSlot;
            BitStream.Write ( &slot );

            if ( CWeaponNames::DoesSlotHaveAmmo ( uiSlot ) )
            {
                // Write his ammo in clip
                SWeaponAmmoSync ammo ( pSourcePlayer->GetWeaponType (), false, true );
                ammo.data.usAmmoInClip = pSourcePlayer->GetWeaponAmmoInClip ();
                BitStream.Write ( &ammo );

                // Write the weapon aim data
                SWeaponAimSync aim ( 0.0f );
                aim.data.vecOrigin = pSourcePlayer->GetSniperSourceVector ();
                pSourcePlayer->GetTargettingVector ( aim.data.vecTarget );
                aim.data.fArm = pSourcePlayer->GetAimDirection ();
                BitStream.Write ( &aim );

                // Write the driveby aim directoin
                BitStream.Write ( pSourcePlayer->GetDriveByDirection () );
            }
            else
            {
                pSourcePlayer->SetWeaponAmmoInClip ( 1 );
                pSourcePlayer->SetWeaponTotalAmmo ( 1 );
            }
        }

        // If he's in a vehicle, read out the small vehicle specific data
        if ( flags.data.bSyncingVehicle )
        {
            WriteVehicleSpecific ( pVehicle, BitStream );

            if ( pVehicle->GetUpgrades ()->HasUpgrade ( 1087 ) ) // Hydraulics?
            {
                BitStream.Write ( ControllerState.RightStickX );
                BitStream.Write ( ControllerState.RightStickY );
            }

            if ( pVehicle->GetVehicleType () == VEHICLE_PLANE ||
                 pVehicle->GetVehicleType () == VEHICLE_HELI )
            {
                BitStream.WriteBit ( ControllerState.LeftShoulder2 != 0);
                BitStream.WriteBit ( ControllerState.RightShoulder2 != 0);
            }
        }

        return true;
    }

    return false;
}
示例#2
0
//
// Should do the same this as what CKeysyncPacket::Write() does
//
bool CSimKeysyncPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    // Write the source player id
    BitStream.Write ( m_PlayerID );

    // Write the keysync data
    WriteSmallKeysync ( m_sharedControllerState, BitStream );

    // Write the rotations
    SKeysyncRotation rotation;
    rotation.data.fPlayerRotation = m_Cache.fPlayerRotation;
    rotation.data.fCameraRotation = m_Cache.fCameraRotation;
    BitStream.Write ( &rotation );

    // Write the flags
    BitStream.Write ( &m_Cache.flags );

    // If he's shooting or aiming
    if ( m_sharedControllerState.ButtonCircle || ( m_sharedControllerState.RightShoulder1 ) )
    {
        // Write his current weapon slot
        unsigned int uiSlot = m_Cache.ucWeaponSlot;   // check m_Cache.bWeaponCorrect ! 
        SWeaponSlotSync slot;
        slot.data.uiSlot = uiSlot;
        BitStream.Write ( &slot );

        if ( CWeaponNames::DoesSlotHaveAmmo ( uiSlot ) )
        {
            // Write his ammo in clip
            SWeaponAmmoSync ammo ( m_ucPlayerGotWeaponType, false, true );
            ammo.data.usAmmoInClip = m_Cache.usAmmoInClip;
            BitStream.Write ( &ammo );

            // Write the weapon aim data
            SWeaponAimSync aim ( 0.0f );
            aim.data.vecOrigin = m_Cache.vecSniperSource;
            aim.data.vecTarget = m_Cache.vecTargetting;
            aim.data.fArm = m_Cache.fAimDirection;
            BitStream.Write ( &aim );

            // Write the driveby aim directoin
            BitStream.Write ( m_Cache.ucDriveByDirection );
        }
    }

    // If he's in a vehicle, read out the small vehicle specific data
    if ( m_bPlayerHasOccupiedVehicle && m_Cache.flags.data.bSyncingVehicle )
    {
        if ( CVehicleManager::HasTurret ( m_usVehicleGotModel ) )
            BitStream.Write ( &m_Cache.turretSync );

        if ( m_bVehicleHasHydraulics )
        {
            BitStream.Write ( m_sharedControllerState.RightStickX );
            BitStream.Write ( m_sharedControllerState.RightStickY );
        }

        if ( m_bVehicleIsPlaneOrHeli )
        {
            BitStream.WriteBit ( m_sharedControllerState.LeftShoulder2 != 0);
            BitStream.WriteBit ( m_sharedControllerState.RightShoulder2 != 0);
        }
    }

    return true;
}