void UpdateAmmoState() { C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); C_BaseCombatWeapon *wpn = player ? player->GetActiveWeapon() : NULL; if (player && wpn && wpn->UsesSecondaryAmmo()) { SetAmmo(player->GetAmmoCount(wpn->GetSecondaryAmmoType())); } if ( m_hCurrentActiveWeapon != wpn ) { if ( wpn->UsesSecondaryAmmo() ) { // we've changed to a weapon that uses secondary ammo GetClientMode()->GetViewportAnimationController()->StartAnimationSequence("WeaponUsesSecondaryAmmo"); } else { // we've changed away from a weapon that uses secondary ammo GetClientMode()->GetViewportAnimationController()->StartAnimationSequence("WeaponDoesNotUseSecondaryAmmo"); } m_hCurrentActiveWeapon = wpn; } }
//----------------------------------------------------------------------------- // Purpose: Save CPU cycles by letting the HUD system early cull // costly traversal. Called per frame, return true if thinking and // painting need to occur. //----------------------------------------------------------------------------- bool CHudCrosshair::ShouldDraw( void ) { bool bNeedsDraw; if ( m_bHideCrosshair ) return false; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return false; C_BaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if ( pWeapon && !pWeapon->ShouldDrawCrosshair() ) return false; /* disabled to avoid assuming it's an HL2 player. // suppress crosshair in zoom. if ( pPlayer->m_HL2Local.m_bZooming ) return false; */ // draw a crosshair only if alive or spectating in eye bNeedsDraw = m_pCrosshair && crosshair.GetInt() && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && //!pPlayer->IsInVGuiInputMode() && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); return ( bNeedsDraw && CHudElement::ShouldDraw() ); }
void CBeam::OnDataChanged( DataUpdateType_t updateType ) { MarkMessageReceived(); // Make sure that the correct model is referenced for this entity SetModelPointer( modelinfo->GetModel( GetModelIndex() ) ); // Convert weapon world models to viewmodels if they're weapons being carried by the local player for (int i=0;i<MAX_BEAM_ENTS;i++) { C_BaseEntity *pEnt = m_hAttachEntity[i].Get(); if ( pEnt ) { C_BaseCombatWeapon *pWpn = dynamic_cast<C_BaseCombatWeapon *>(pEnt); if ( pWpn && pWpn->IsCarriedByLocalPlayer() ) { C_BasePlayer *player = ToBasePlayer( pWpn->GetOwner() ); C_BaseViewModel *pViewModel = player ? player->GetViewModel( 0 ) : NULL; if ( pViewModel ) { // Get the viewmodel and use it instead m_hAttachEntity.Set( i, pViewModel ); } } } } // Compute the bounds here... Vector mins, maxs; ComputeBounds( mins, maxs ); SetCollisionBounds( mins, maxs ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- C_BaseCombatWeapon *CBaseHudWeaponSelection::GetNextActivePos( int iSlot, int iSlotPos ) { if ( iSlotPos >= MAX_WEAPON_POSITIONS || iSlot >= MAX_WEAPON_SLOTS ) return NULL; int iLowestPosition = MAX_WEAPON_POSITIONS; C_BaseCombatWeapon *pNextWeapon = NULL; C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); if ( !player ) return NULL; for ( int i = 0; i < MAX_WEAPONS; i++ ) { C_BaseCombatWeapon *pWeapon = player->GetWeapon( i ); if ( !pWeapon ) continue; if ( CanBeSelectedInHUD( pWeapon ) && pWeapon->GetSlot() == iSlot ) { // If this weapon is lower in the slot than the current lowest, and above our desired position, it's our new winner if ( pWeapon->GetPosition() <= iLowestPosition && pWeapon->GetPosition() >= iSlotPos ) { iLowestPosition = pWeapon->GetPosition(); pNextWeapon = pWeapon; } } } return pNextWeapon; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CHudWeapon::Paint( void ) { C_GstringPlayer *player =LocalGstringPlayer(); if ( !player ) return; // GSTRINGMIGRATION if ( player->IsInSpacecraft() ) { player->GetSpacecraft()->UpdateCrosshair( m_pCrosshair ); return; } // END GSTRINGMIGRATION MDLCACHE_CRITICAL_SECTION(); C_BaseCombatWeapon *pWeapon = player->GetActiveWeapon(); if ( pWeapon ) { pWeapon->Redraw(); } else { if ( m_pCrosshair ) { m_pCrosshair->ResetCrosshair(); } } }
void UpdateAmmoState() { C_BaseCombatWeapon *wpn = GetActiveWeapon(); C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); if (player && wpn && wpn->UsesSecondaryAmmo()) { SetAmmo(player->GetAmmoCount(wpn->GetSecondaryAmmoType())); } if ( m_hCurrentActiveWeapon != wpn ) { if ( wpn->UsesSecondaryAmmo() ) { // we've changed to a weapon that uses secondary ammo g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("WeaponUsesSecondaryAmmo"); } else { // we've changed away from a weapon that uses secondary ammo g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("WeaponDoesNotUseSecondaryAmmo"); } m_hCurrentActiveWeapon = wpn; // Get the icon we should be displaying m_iconSecondaryAmmo = gWR.GetAmmoIconFromWeapon( m_hCurrentActiveWeapon->GetSecondaryAmmoType() ); } }
//----------------------------------------------------------------------------- // Purpose //----------------------------------------------------------------------------- void C_BaseViewModel::FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options ) { // We override sound requests so that we can play them locally on the owning player if ( ( event == AE_CL_PLAYSOUND ) || ( event == CL_EVENT_SOUND ) ) { // Only do this if we're owned by someone if ( GetOwner() != NULL ) { CLocalPlayerFilter filter; EmitSound( filter, GetOwner()->GetSoundSourceIndex(), options, &GetAbsOrigin() ); return; } } // Otherwise pass the event to our associated weapon C_BaseCombatWeapon *pWeapon = GetActiveWeapon(); if ( pWeapon ) { // NVNT notify the haptics system of our viewmodel's event if ( haptics ) haptics->ProcessHapticEvent(4,"Weapons",pWeapon->GetName(),"AnimationEvents",VarArgs("%i",event)); bool bResult = pWeapon->OnFireEvent( this, origin, angles, event, options ); if ( !bResult ) { BaseClass::FireEvent( origin, angles, event, options ); } } }
//----------------------------------------------------------------------------- // Purpose: Think //----------------------------------------------------------------------------- void CHud::Think(void) { // Determine the visibility of all hud elements for ( int i = 0; i < m_HudList.Size(); i++ ) { // Visible? bool visible = m_HudList[i]->ShouldDraw(); m_HudList[i]->SetActive( visible ); // If it's a vgui panel, hide/show as appropriate vgui::Panel *pPanel = dynamic_cast<vgui::Panel*>(m_HudList[i]); if ( pPanel && pPanel->IsVisible() != visible ) { pPanel->SetVisible( visible ); } else if ( !pPanel ) { // All HUD elements should now derive from vgui!!! Assert( 0 ); } if ( visible ) { m_HudList[i]->ProcessInput(); } } // Let the active weapon at the keybits C_BaseCombatWeapon *pWeapon = GetActiveWeapon(); if ( pWeapon ) { pWeapon->HandleInput(); } }
//----------------------------------------------------------------------------- // Purpose: Returns the first weapon for a given slot. //----------------------------------------------------------------------------- C_BaseCombatWeapon *CBaseHudWeaponSelection::GetFirstPos( int iSlot ) { int iLowestPosition = MAX_WEAPON_POSITIONS; C_BaseCombatWeapon *pFirstWeapon = NULL; C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); if ( !player ) return NULL; for ( int i = 0; i < MAX_WEAPONS; i++ ) { C_BaseCombatWeapon *pWeapon = player->GetWeapon( i ); if ( !pWeapon ) continue; if ( ( pWeapon->GetSlot() == iSlot ) && (pWeapon->VisibleInWeaponSelection()) ) { // If this weapon is lower in the slot than the current lowest, it's our new winner if ( pWeapon->GetPosition() <= iLowestPosition ) { iLowestPosition = pWeapon->GetPosition(); pFirstWeapon = pWeapon; } } } return pFirstWeapon; }
//----------------------------------------------------------------------------- // Purpose //----------------------------------------------------------------------------- void C_BaseViewModel::FireEvent( const Vector& origin, const QAngle& angles, int eventNum, const char *options ) { // We override sound requests so that we can play them locally on the owning player if ( ( eventNum == AE_CL_PLAYSOUND ) || ( eventNum == CL_EVENT_SOUND ) ) { // Only do this if we're owned by someone if ( GetOwner() != NULL ) { CLocalPlayerFilter filter; EmitSound( filter, GetOwner()->GetSoundSourceIndex(), options, &GetAbsOrigin() ); return; } } C_BasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( !pOwner ) return; ACTIVE_SPLITSCREEN_PLAYER_GUARD_ENT( pOwner ); // Otherwise pass the event to our associated weapon C_BaseCombatWeapon *pWeapon = pOwner->GetActiveWeapon(); if ( pWeapon ) { bool bResult = pWeapon->OnFireEvent( this, origin, angles, eventNum, options ); if ( !bResult ) { if ( eventNum == AE_CLIENT_EFFECT_ATTACH && ::input->CAM_IsThirdPerson() ) return; BaseClass::FireEvent( origin, angles, eventNum, options ); } } }
void CHudCrosshair::Paint( void ) { if ( !m_pCrosshair ) return; if ( !IsCurrentViewAccessAllowed() ) return; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return; float x, y; bool bBehindCamera; GetDrawPosition ( &x, &y, &bBehindCamera, m_vecCrossHairOffsetAngle ); if( bBehindCamera ) return; float flWeaponScale = 1.f; int iTextureW = m_pCrosshair->Width(); int iTextureH = m_pCrosshair->Height(); C_BaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if ( pWeapon ) { pWeapon->GetWeaponCrosshairScale( flWeaponScale ); } float flPlayerScale = 1.0f; #ifdef TF_CLIENT_DLL Color clr( cl_crosshair_red.GetInt(), cl_crosshair_green.GetInt(), cl_crosshair_blue.GetInt(), 255 ); flPlayerScale = cl_crosshair_scale.GetFloat() / 32.0f; // the player can change the scale in the options/multiplayer tab #else Color clr = m_clrCrosshair; #endif float flWidth = flWeaponScale * flPlayerScale * (float)iTextureW; float flHeight = flWeaponScale * flPlayerScale * (float)iTextureH; int iWidth = (int)( flWidth + 0.5f ); int iHeight = (int)( flHeight + 0.5f ); int iX = (int)( x + 0.5f ); int iY = (int)( y + 0.5f ); if (pPlayer->IsInVGuiInputMode() && m_pVGUIHoverIcon) m_pVGUIHoverIcon->DrawSelf( iX - (m_pVGUIHoverIcon->Width() / 2), iY - (m_pVGUIHoverIcon->Height() / 2), m_pVGUIHoverIcon->Width(), m_pVGUIHoverIcon->Height(), Color(0, 255, 0, 255)); else { m_pCrosshair->DrawSelfCropped( iX - (iWidth / 2), iY - (iHeight + 2), 0, 0, iTextureW, iTextureH, iWidth, iHeight, clr); } }
//Might be able to handle this better... void HapticsHandleMsg_SPHapWeapEvent( int iActivity ) { C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); C_BaseCombatWeapon* weap = NULL; if(pPlayer) weap = pPlayer->GetActiveWeapon(); if(weap) haptics->ProcessHapticEvent(4,"Weapons",weap->GetName(),"Activities",VarArgs("%i",iActivity)); }
//----------------------------------------------------------------------------- // Purpose: Think //----------------------------------------------------------------------------- void CHud::Think(void) { #if defined( REPLAY_ENABLED ) // Don't draw this extern IEngineClientReplay *g_EngineClientReplay; const bool bPlayingReplay = g_pEngineClientReplay && g_pEngineClientReplay->IsPlayingReplayDemo(); #endif // Determine the visibility of all hud elements for ( int i = 0; i < m_HudList.Size(); i++ ) { // Visible? bool visible = m_HudList[i]->ShouldDraw(); #if defined( REPLAY_ENABLED ) visible = visible && !bPlayingReplay; #endif m_HudList[i]->SetActive( visible ); // If it's a vgui panel, hide/show as appropriate vgui::Panel *pPanel = dynamic_cast<vgui::Panel*>(m_HudList[i]); if ( pPanel && pPanel->IsVisible() != visible ) { pPanel->SetVisible( visible ); } else if ( !pPanel ) { // All HUD elements should now derive from vgui!!! Assert( 0 ); } if ( visible ) { m_HudList[i]->ProcessInput(); } } // Let the active weapon at the keybits C_BaseCombatWeapon *pWeapon = GetActiveWeapon(); if ( pWeapon ) { pWeapon->HandleInput(); } if ( ( m_flScreenShotTime > 0 ) && ( m_flScreenShotTime < gpGlobals->curtime ) ) { if ( !IsX360() ) { engine->ClientCmd( "screenshot" ); } m_flScreenShotTime = -1; } }
//----------------------------------------------------------------------------- // Purpose: Render the weapon. Draw the Viewmodel if the weapon's being carried // by this player, otherwise draw the worldmodel. //----------------------------------------------------------------------------- int C_BaseViewModel::DrawModel( int flags ) { if ( !m_bReadyToDraw ) return 0; if ( flags & STUDIO_RENDER ) { // Determine blending amount and tell engine float blend = (float)( GetFxBlend() / 255.0f ); // Totally gone if ( blend <= 0.0f ) return 0; // Tell engine render->SetBlend( blend ); float color[3]; GetColorModulation( color ); render->SetColorModulation( color ); } C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); C_BaseCombatWeapon *pWeapon = GetOwningWeapon(); int ret; // If the local player's overriding the viewmodel rendering, let him do it if ( pPlayer && pPlayer->IsOverridingViewmodel() ) { ret = pPlayer->DrawOverriddenViewmodel( this, flags ); } else if ( pWeapon && pWeapon->IsOverridingViewmodel() ) { ret = pWeapon->DrawOverriddenViewmodel( this, flags ); } else { ret = BaseClass::DrawModel( flags ); } // Now that we've rendered, reset the animation restart flag if ( flags & STUDIO_RENDER ) { if ( m_nOldAnimationParity != m_nAnimationParity ) { m_nOldAnimationParity = m_nAnimationParity; } // Tell the weapon itself that we've rendered, in case it wants to do something if ( pWeapon ) { pWeapon->ViewModelDrawn( this ); } } return ret; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_BaseViewModel::GetBoneControllers(float controllers[MAXSTUDIOBONECTRLS]) { BaseClass::GetBoneControllers( controllers ); // Tell the weapon itself that we've rendered, in case it wants to do something C_BaseCombatWeapon *pWeapon = GetActiveWeapon(); if ( pWeapon ) { pWeapon->GetViewmodelBoneControllers( this, controllers ); } }
void Aimbot::UpdateValues() { C_BasePlayer* localplayer = (C_BasePlayer*) entityList->GetClientEntity(engine->GetLocalPlayer()); if (!localplayer || !localplayer->GetAlive()) return; C_BaseCombatWeapon* activeWeapon = (C_BaseCombatWeapon*) entityList->GetClientEntityFromHandle(localplayer->GetActiveWeapon()); if (!activeWeapon) return; ItemDefinitionIndex index = ItemDefinitionIndex::INVALID; if (Settings::Aimbot::weapons.find(*activeWeapon->GetItemDefinitionIndex()) != Settings::Aimbot::weapons.end()) index = *activeWeapon->GetItemDefinitionIndex(); const AimbotWeapon_t& currentWeaponSetting = Settings::Aimbot::weapons.at(index); Settings::Aimbot::enabled = currentWeaponSetting.enabled; Settings::Aimbot::silent = currentWeaponSetting.silent; Settings::Aimbot::friendly = currentWeaponSetting.friendly; Settings::Aimbot::bone = currentWeaponSetting.bone; Settings::Aimbot::aimkey = currentWeaponSetting.aimkey; Settings::Aimbot::aimkeyOnly = currentWeaponSetting.aimkeyOnly; Settings::Aimbot::Smooth::enabled = currentWeaponSetting.smoothEnabled; Settings::Aimbot::Smooth::value = currentWeaponSetting.smoothAmount; Settings::Aimbot::Smooth::type = currentWeaponSetting.smoothType; Settings::Aimbot::ErrorMargin::enabled = currentWeaponSetting.errorMarginEnabled; Settings::Aimbot::ErrorMargin::value = currentWeaponSetting.errorMarginValue; Settings::Aimbot::AutoAim::enabled = currentWeaponSetting.autoAimEnabled; Settings::Aimbot::AutoAim::fov = currentWeaponSetting.autoAimFov; Settings::Aimbot::AimStep::enabled = currentWeaponSetting.aimStepEnabled; Settings::Aimbot::AimStep::value = currentWeaponSetting.aimStepValue; Settings::Aimbot::AutoPistol::enabled = currentWeaponSetting.autoPistolEnabled; Settings::Aimbot::AutoShoot::enabled = currentWeaponSetting.autoShootEnabled; Settings::Aimbot::AutoShoot::autoscope = currentWeaponSetting.autoScopeEnabled; Settings::Aimbot::RCS::enabled = currentWeaponSetting.rcsEnabled; Settings::Aimbot::RCS::always_on = currentWeaponSetting.rcsAlwaysOn; Settings::Aimbot::RCS::valueX = currentWeaponSetting.rcsAmountX; Settings::Aimbot::RCS::valueY = currentWeaponSetting.rcsAmountY; Settings::Aimbot::NoShoot::enabled = currentWeaponSetting.noShootEnabled; Settings::Aimbot::IgnoreJump::enabled = currentWeaponSetting.ignoreJumpEnabled; Settings::Aimbot::Smooth::Salting::enabled = currentWeaponSetting.smoothSaltEnabled; Settings::Aimbot::Smooth::Salting::multiplier = currentWeaponSetting.smoothSaltMultiplier; Settings::Aimbot::SmokeCheck::enabled = currentWeaponSetting.smokeCheck; Settings::Aimbot::FlashCheck::enabled = currentWeaponSetting.flashCheck; Settings::Aimbot::AutoWall::enabled = currentWeaponSetting.autoWallEnabled; Settings::Aimbot::AutoWall::value = currentWeaponSetting.autoWallValue; Settings::Aimbot::AutoSlow::enabled = currentWeaponSetting.autoSlow; Settings::Aimbot::AutoSlow::minDamage = currentWeaponSetting.autoSlowMinDamage; for (int i = (int) Hitbox::HITBOX_HEAD; i <= (int) Hitbox::HITBOX_ARMS; i++) Settings::Aimbot::AutoWall::bones[i] = currentWeaponSetting.autoWallBones[i]; Settings::Aimbot::AutoAim::realDistance = currentWeaponSetting.autoAimRealDistance; }
//----------------------------------------------------------------------------- // Purpose: Save CPU cycles by letting the HUD system early cull // costly traversal. Called per frame, return true if thinking and // painting need to occur. //----------------------------------------------------------------------------- bool CHudCrosshair::ShouldDraw( void ) { bool bNeedsDraw; if ( m_bHideCrosshair ) return false; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return false; C_BaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if ( pWeapon && !pWeapon->ShouldDrawCrosshair() ) return false; #ifdef PORTAL // C_Portal_Player *portalPlayer = ToPortalPlayer(pPlayer); // if ( portalPlayer && portalPlayer->IsSuppressingCrosshair() ) // return false; #endif // PORTAL /* disabled to avoid assuming it's an HL2 player. // suppress crosshair in zoom. if ( pPlayer->m_HL2Local.m_bZooming ) return false; */ // draw a crosshair only if alive or spectating in eye if ( IsX360() ) { bNeedsDraw = m_pCrosshair && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && ( !pPlayer->IsSuitEquipped() || g_pGameRules->IsMultiplayer() ) && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } else { bNeedsDraw = m_pCrosshair && crosshair.GetInt() && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && !pPlayer->IsInVGuiInputMode() && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } return ( bNeedsDraw && CHudElement::ShouldDraw() ); }
void CHudWeapon::Paint( void ) { C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); if ( !player ) return; MDLCACHE_CRITICAL_SECTION(); C_BaseCombatWeapon *pWeapon = player->GetActiveWeapon(); if ( pWeapon ) pWeapon->Redraw(); else if ( m_pCrosshair ) m_pCrosshair->ResetCrosshair(); }
//----------------------------------------------------------------------------- // Purpose: Overload our muzzle flash and send it to any actively held weapon //----------------------------------------------------------------------------- void C_BaseCombatCharacter::DoMuzzleFlash() { // Our weapon takes our muzzle flash command C_BaseCombatWeapon *pWeapon = GetActiveWeapon(); if ( pWeapon ) { pWeapon->DoMuzzleFlash(); //NOTENOTE: We do not chain to the base here } else { BaseClass::DoMuzzleFlash(); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- Vector GetTracerOrigin( const CEffectData &data ) { Vector vecStart = data.m_vStart; QAngle vecAngles; int iAttachment = data.m_nAttachmentIndex;; // Attachment? if ( data.m_fFlags & TRACER_FLAG_USEATTACHMENT ) { C_BaseViewModel *pViewModel = NULL; // If the entity specified is a weapon being carried by this player, use the viewmodel instead IClientRenderable *pRenderable = data.GetRenderable(); if ( !pRenderable ) return vecStart; C_BaseEntity *pEnt = data.GetEntity(); // This check should probably be for all multiplayer games, investigate later #if defined( HL2MP ) || defined( TF_CLIENT_DLL ) || defined( TF_CLASSIC_CLIENT ) if ( pEnt && pEnt->IsDormant() ) return vecStart; #endif C_BaseCombatWeapon *pWpn = dynamic_cast<C_BaseCombatWeapon *>( pEnt ); if ( pWpn && pWpn->ShouldDrawUsingViewModel() ) { C_BasePlayer *player = ToBasePlayer( pWpn->GetOwner() ); // Use GetRenderedWeaponModel() instead? pViewModel = player ? player->GetViewModel( 0 ) : NULL; if ( pViewModel ) { // Get the viewmodel and use it instead pRenderable = pViewModel; } } // Get the attachment origin if ( !pRenderable->GetAttachment( iAttachment, vecStart, vecAngles ) ) { DevMsg( "GetTracerOrigin: Couldn't find attachment %d on model %s\n", iAttachment, modelinfo->GetModelName( pRenderable->GetModel() ) ); } } return vecStart; }
//----------------------------------------------------------------------------- // get owning weapon (for viewmodels) //----------------------------------------------------------------------------- int CClientTools::GetOwningWeaponEntIndex( int entindex ) { C_BaseEntity *pEnt = C_BaseEntity::Instance( entindex ); C_BaseViewModel *pViewModel = dynamic_cast< C_BaseViewModel* >( pEnt ); if ( pViewModel ) { C_BaseCombatWeapon *pWeapon = pViewModel->GetOwningWeapon(); if ( pWeapon ) { return pWeapon->entindex(); } } return -1; }
//----------------------------------------------------------------------------- // Purpose: // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool C_BaseViewModel::IsTransparent( void ) { // See if the local player wants to override the viewmodel's rendering C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer && pPlayer->IsOverridingViewmodel() ) { return pPlayer->ViewModel_IsTransparent(); } C_BaseCombatWeapon *pWeapon = GetOwningWeapon(); if ( pWeapon && pWeapon->IsOverridingViewmodel() ) return pWeapon->ViewModel_IsTransparent(); return BaseClass::IsTransparent(); }
//----------------------------------------------------------------------------- // Purpose: called every frame to get ammo info from the weapon //----------------------------------------------------------------------------- void CDoDHudAmmo::OnThink() { C_BaseCombatWeapon *wpn = GetActiveWeapon(); C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); hudlcd->SetGlobalStat( "(weapon_print_name)", wpn ? wpn->GetPrintName() : " " ); hudlcd->SetGlobalStat( "(weapon_name)", wpn ? wpn->GetName() : " " ); if ( !wpn || !player || !wpn->UsesPrimaryAmmo() ) { hudlcd->SetGlobalStat( "(ammo_primary)", "n/a" ); hudlcd->SetGlobalStat( "(ammo_secondary)", "n/a" ); SetPaintEnabled( false ); SetPaintBackgroundEnabled( false ); return; } else { SetPaintEnabled( true ); SetPaintBackgroundEnabled( true ); } // get the ammo in our clip int ammo1 = wpn->Clip1(); int ammo2; if ( ammo1 < 0 ) { // we don't use clip ammo, just use the total ammo count ammo1 = player->GetAmmoCount( wpn->GetPrimaryAmmoType() ); ammo2 = 0; } else { // we use clip ammo, so the second ammo is the total ammo ammo2 = player->GetAmmoCount( wpn->GetPrimaryAmmoType() ); } hudlcd->SetGlobalStat( "(ammo_primary)", VarArgs( "%d", ammo1 ) ); hudlcd->SetGlobalStat( "(ammo_secondary)", VarArgs( "%d", ammo2 ) ); if ( wpn == m_hCurrentActiveWeapon ) { // same weapon, just update counts SetAmmo( ammo1, true ); SetAmmo2( ammo2, true ); } else { // diferent weapon, change without triggering SetAmmo( ammo1, false ); SetAmmo2( ammo2, false ); // update whether or not we show the total ammo display m_bUsesClips = wpn->UsesClipsForAmmo1(); m_hCurrentActiveWeapon = wpn; } }
//----------------------------------------------------------------------------- // Purpose: // Output : int //----------------------------------------------------------------------------- uint8 C_BaseViewModel::OverrideAlphaModulation( uint8 nAlpha ) { ACTIVE_SPLITSCREEN_PLAYER_GUARD_ENT( GetOwner() ); // See if the local player wants to override the viewmodel's rendering C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer && pPlayer->IsOverridingViewmodel() ) return pPlayer->AlphaProp()->ComputeRenderAlpha(); C_BaseCombatWeapon *pWeapon = GetOwningWeapon(); if ( pWeapon && pWeapon->IsOverridingViewmodel() ) return pWeapon->AlphaProp()->ComputeRenderAlpha(); return nAlpha; }
//----------------------------------------------------------------------------- // Purpose: // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- RenderableTranslucencyType_t C_BaseViewModel::ComputeTranslucencyType( void ) { ACTIVE_SPLITSCREEN_PLAYER_GUARD_ENT( GetOwner() ); // See if the local player wants to override the viewmodel's rendering C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer && pPlayer->IsOverridingViewmodel() ) return pPlayer->ComputeTranslucencyType(); C_BaseCombatWeapon *pWeapon = GetOwningWeapon(); if ( pWeapon && pWeapon->IsOverridingViewmodel() ) return pWeapon->ComputeTranslucencyType(); return BaseClass::ComputeTranslucencyType(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- Vector GetTracerOrigin( const CEffectData &data ) { Vector vecStart = data.m_vStart; QAngle vecAngles; int iAttachment = data.m_nAttachmentIndex;; // Attachment? if ( data.m_fFlags & TRACER_FLAG_USEATTACHMENT ) { C_BaseViewModel *pViewModel = NULL; // If the entity specified is a weapon being carried by this player, use the viewmodel instead IClientRenderable *pRenderable = data.GetRenderable(); if ( !pRenderable ) return vecStart; C_BaseEntity *pEnt = data.GetEntity(); FOR_EACH_VALID_SPLITSCREEN_PLAYER( hh ) { ACTIVE_SPLITSCREEN_PLAYER_GUARD( hh ); C_BaseCombatWeapon *pWpn = ToBaseCombatWeapon( pEnt ); if ( pWpn && pWpn->IsCarriedByLocalPlayer() ) { C_BasePlayer *player = ToBasePlayer( pWpn->GetOwner() ); pViewModel = player ? player->GetViewModel( 0 ) : NULL; if ( pViewModel ) { // Get the viewmodel and use it instead pRenderable = pViewModel; break; } } } // Get the attachment origin if ( !pRenderable->GetAttachment( iAttachment, vecStart, vecAngles ) ) { DevMsg( "GetTracerOrigin: Couldn't find attachment %d on model %s\n", iAttachment, modelinfo->GetModelName( pRenderable->GetModel() ) ); } }
void CASWNightVisionSelfIllumProxy::OnBind( void *pC_BaseEntity ) { Assert( m_pResult ); C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer(); if ( !pPlayer || !pC_BaseEntity ) { SetFloatResult( 0.0f ); return; } C_ASW_Marine *pMarine = pPlayer->GetMarine(); if ( !pMarine ) { SetFloatResult( 0.0f ); return; } if ( C_JaS_Alien_Controller::AutoList().Count() ) { C_JaS_Alien_Controller *pAlienController = dynamic_cast<C_JaS_Alien_Controller *>( C_JaS_Alien_Controller::AutoList().Head()->GetEntity() ); if ( pAlienController->m_hBuzzerOverride ) { SetFloatResult( 255.0f ); return; } } C_BaseCombatWeapon* pExtraItem = pMarine->GetWeapon( 2 ); if ( pExtraItem && pExtraItem->Classify() == CLASS_ASW_NIGHT_VISION ) { C_ASW_Weapon_Night_Vision *pVision = assert_cast<CASW_Weapon_Night_Vision*>( pExtraItem ); float flVisionAlpha = pVision->m_flVisionAlpha; if ( flVisionAlpha != 0.0f ) { SetFloatResult( flVisionAlpha / 255.0f * asw_night_vision_self_illum_multiplier.GetFloat() ); return; } } if ( pPlayer->IsSniperScopeActive() && g_bRenderingGlows ) { SetFloatResult( asw_sniper_scope_self_illum_multiplier.GetFloat() ); return; } SetFloatResult( 0.0f ); }
//----------------------------------------------------------------------------- // Purpose: Save CPU cycles by letting the HUD system early cull // costly traversal. Called per frame, return true if thinking and // painting need to occur. //----------------------------------------------------------------------------- bool CDAHudCrosshair::ShouldDraw( void ) { // OnThink isn't called when the thing isn't visible so force it to update. CalculateCrosshair(); bool bNeedsDraw; if ( m_bHideCrosshair ) return false; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return false; C_BaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if ( pWeapon && !pWeapon->ShouldDrawCrosshair() ) return false; ConVarRef cl_observercrosshair("cl_observercrosshair"); // draw a crosshair only if alive or spectating in eye if ( IsX360() ) { bNeedsDraw = m_pCrosshair && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && ( !pPlayer->IsSuitEquipped() || g_pGameRules->IsMultiplayer() ) && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } else { bNeedsDraw = m_pCrosshair && da_crosshair.GetInt() && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && !pPlayer->IsInVGuiInputMode() && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } return ( bNeedsDraw && CHudElement::ShouldDraw() ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- bool C_BaseViewModel::UsesPowerOfTwoFrameBufferTexture( void ) { // See if the local player wants to override the viewmodel's rendering C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer && pPlayer->IsOverridingViewmodel() ) { return pPlayer->ViewModel_IsUsingFBTexture(); } C_BaseCombatWeapon *pWeapon = GetOwningWeapon(); if ( pWeapon && pWeapon->IsOverridingViewmodel() ) { return pWeapon->ViewModel_IsUsingFBTexture(); } return BaseClass::UsesPowerOfTwoFrameBufferTexture(); }
void CBliinkHudAmmo::Paint() { C_BliinkPlayer* pBliinkPlayer = ToBliinkPlayer(C_BasePlayer::GetLocalPlayer()); if( !pBliinkPlayer ) return; if( pBliinkPlayer->State_Get() != STATE_BLIINK_SURVIVOR ) return; C_BaseCombatWeapon* pWeapon = pBliinkPlayer->GetActiveWeapon(); if( !pWeapon ) return; if( pWeapon->IsMeleeWeapon() ) return; int iClipCount = pWeapon->Clip1(); int iAmmoCount = pBliinkPlayer->GetAmmoCount( pWeapon->GetPrimaryAmmoType() ); vgui::IScheme* pScheme = vgui::scheme()->GetIScheme(GetScheme()); int wide, tall; SetPaintBorderEnabled(false); // Drawing background surface()->DrawSetTexture( m_nAmmoBack ); surface()->DrawTexturedRect( 0, 0, 128, 64 ); // Drawing ammo count (clip/ammo) wchar_t pNumberText[12]; V_snwprintf( pNumberText, ARRAYSIZE(pNumberText), L"%d : %d", iClipCount, iAmmoCount ); vgui::HFont hNumberFont = pScheme->GetFont( "BliinkHUDLarge" ); surface()->GetTextSize(hNumberFont, pNumberText, wide, tall); int number_xpos = (int) floor(64.0f - ((float) wide)/2.0f); int number_ypos = (int) floor(32.0f - ((float) tall)/2.0f); surface()->DrawSetTextFont( hNumberFont ); surface()->DrawSetTextColor( 210, 210, 210, 255 ); surface()->DrawSetTextPos( number_xpos, number_ypos ); surface()->DrawPrintText( pNumberText, wcslen(pNumberText) ); }