//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWarsWeapon::GetShootOriginAndDirection( Vector &vShootOrigin, Vector &vShootDirection) { CBaseEntity *pOwner = GetOwner(); if( !pOwner ) return; CUnitBase *pUnit = pOwner->MyUnitPointer(); if( !pUnit ) return; #if 0 #ifdef CLIENT_DLL if( pUnit->GetCommander() && !ShouldDrawLocalPlayer() ) { QAngle vDummy; C_BasePlayer *player = ToBasePlayer( pUnit->GetCommander() ); C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); if ( vm->GetAttachment( iAttachment, vShootOrigin, vDummy ) ) { AngleVectors( QAngle(pUnit->m_fEyePitch, pUnit->m_fEyeYaw, 0.0), &vShootDirection ); return; } } } #endif // CLIENT_DLL #endif // 0 vShootOrigin = pUnit->Weapon_ShootPosition(); AngleVectors( QAngle(pUnit->m_fEyePitch, pUnit->m_fEyeYaw, 0.0), &vShootDirection ); }
//----------------------------------------------------------------------------- // Purpose: // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool C_BaseCombatWeapon::ShouldDraw( void ) { if ( m_iWorldModelIndex == 0 ) return false; // FIXME: All weapons with owners are set to transmit in CBaseCombatWeapon::UpdateTransmitState, // even if they have EF_NODRAW set, so we have to check this here. Ideally they would never // transmit except for the weapons owned by the local player. if ( IsEffectActive( EF_NODRAW ) ) return false; C_BaseCombatCharacter *pOwner = GetOwner(); // weapon has no owner, always draw it if ( !pOwner ) return true; bool bIsActive = ( m_iState == WEAPON_IS_ACTIVE ); C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer(); // carried by local player? if ( pOwner == pLocalPlayer ) { // Only ever show the active weapon if ( !bIsActive ) return false; // 3rd person mode if ( ShouldDrawLocalPlayer() ) return true; // don't draw active weapon if not in some kind of 3rd person mode, the viewmodel will do that return false; } // If it's a player, then only show active weapons if ( pOwner->IsPlayer() ) { // Show it if it's active... return bIsActive; } // FIXME: We may want to only show active weapons on NPCs // These are carried by AIs; always show them return true; }
bool C_BaseCombatWeapon::GetShootPosition( Vector &vOrigin, QAngle &vAngles ) { // Get the entity because the weapon doesn't have the right angles. C_BaseCombatCharacter *pEnt = ToBaseCombatCharacter( GetOwner() ); if ( pEnt ) { if ( pEnt == C_BasePlayer::GetLocalPlayer() ) { vAngles = pEnt->EyeAngles(); } else { vAngles = pEnt->GetRenderAngles(); } } else { vAngles.Init(); } QAngle vDummy; if ( IsActiveByLocalPlayer() && !ShouldDrawLocalPlayer() ) { C_BasePlayer *player = ToBasePlayer( pEnt ); C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); if ( vm->GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } } else { // Thirdperson int iAttachment = LookupAttachment( "muzzle" ); if ( GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } vOrigin = GetRenderOrigin(); return false; }
//----------------------------------------------------------------------------- // Purpose: // Input : bnewentity - //----------------------------------------------------------------------------- void C_BaseCombatWeapon::OnDataChanged( DataUpdateType_t updateType ) { BaseClass::OnDataChanged(updateType); CHandle< C_BaseCombatWeapon > handle = this; // If it's being carried by the *local* player, on the first update, // find the registered weapon for this ID C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); C_BaseCombatCharacter *pOwner = GetOwner(); // check if weapon is carried by local player bool bIsLocalPlayer = pPlayer && pPlayer == pOwner; if ( bIsLocalPlayer && !ShouldDrawLocalPlayer() ) { // If I was just picked up, or created & immediately carried, add myself to this client's list of weapons if ( (m_iState != WEAPON_NOT_CARRIED ) && (m_iOldState == WEAPON_NOT_CARRIED) ) { // Tell the HUD this weapon's been picked up if ( ShouldDrawPickup() ) { CBaseHudWeaponSelection *pHudSelection = GetHudWeaponSelection(); if ( pHudSelection ) { pHudSelection->OnWeaponPickup( this ); } pPlayer->EmitSound( "Player.PickupWeapon" ); } } } else // weapon carried by other player or not at all { // BRJ 10/14/02 // FIXME: Remove when Yahn's client-side prediction is done // It's a hacky workaround for the model indices fighting // (GetRenderBounds uses the model index, which is for the view model) SetModelIndex( GetWorldModelIndex() ); } UpdateVisibility(); m_iOldState = m_iState; m_bJustRestored = false; }
//----------------------------------------------------------------------------- // Purpose: // Input : bnewentity - //----------------------------------------------------------------------------- void C_BaseCombatWeapon::OnDataChanged( DataUpdateType_t updateType ) { BaseClass::OnDataChanged(updateType); CHandle< C_BaseCombatWeapon > handle = this; // If it's being carried by the *local* player, on the first update, // find the registered weapon for this ID C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); C_BaseCombatCharacter *pOwner = GetOwner(); // check if weapon is carried by local player bool bIsLocalPlayer = pPlayer && pPlayer == pOwner; if ( bIsLocalPlayer && !ShouldDrawLocalPlayer() ) { // If I was just picked up, or created & immediately carried, add myself to this client's list of weapons if ( (m_iState != WEAPON_NOT_CARRIED ) && (m_iOldState == WEAPON_NOT_CARRIED) ) { // Tell the HUD this weapon's been picked up if ( ShouldDrawPickup() ) { CBaseHudWeaponSelection *pHudSelection = GetHudWeaponSelection(); if ( pHudSelection ) { pHudSelection->OnWeaponPickup( this ); } pPlayer->EmitSound( "Player.PickupWeapon" ); } } } else // weapon carried by other player or not at all { // See comment below EnsureCorrectRenderingModel(); } UpdateVisibility(); m_iOldState = m_iState; m_bJustRestored = false; }
// If the local player is visible (thirdperson mode, tf2 taunts, etc., then make sure that we are using the // w_ (world) model not the v_ (view) model or else the model can flicker, etc. // Otherwise, if we're not the local player, always use the world model void C_BaseCombatWeapon::EnsureCorrectRenderingModel() { C_BasePlayer *localplayer = C_BasePlayer::GetLocalPlayer(); if ( localplayer && localplayer == GetOwner() && !ShouldDrawLocalPlayer() ) { return; } // BRJ 10/14/02 // FIXME: Remove when Yahn's client-side prediction is done // It's a hacky workaround for the model indices fighting // (GetRenderBounds uses the model index, which is for the view model) SetModelIndex( GetWorldModelIndex() ); // Validate our current sequence just in case ( in theory the view and weapon models should have the same sequences for sequences that overlap at least ) CStudioHdr *pStudioHdr = GetModelPtr(); if ( pStudioHdr && GetSequence() >= pStudioHdr->GetNumSeq() ) { SetSequence( 0 ); } }