// // Think: // Used for selection of weapon menu item. // void CHudAmmo::Think() { if( m_bNeedsLocalUpdate ) { m_bNeedsLocalUpdate = false; if( m_pWeapon ) UpdateWeaponHUD( m_pWeapon, m_bOnTarget ); } if ( m_bPlayerDead ) return; CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer(); if ( Hud().GetWeaponBits() != pPlayer->GetWeapons().Get() ) { pPlayer->GetWeapons().Set( Hud().GetWeaponBits() ); for (int i = MAX_WEAPONS-1; i > 0; i-- ) { CBasePlayerWeapon *p = g_Prediction.GetWeapon(i); if ( p && p->GetWeaponInfo() ) { if ( Hud().GetWeaponBits() & ( 1 << p->GetWeaponInfo()->GetID() ) ) pPlayer->AddPlayerItem( p ); else pPlayer->RemovePlayerItem( p ); } } } if( !m_pActiveSel ) return; // has the player selected one? if (Hud().GetKeyBits() & IN_ATTACK) { if ( m_pActiveSel != (CBasePlayerWeapon *)1) { ServerCmd( m_pActiveSel->GetWeaponInfo()->GetWeaponName()); g_weaponselect = m_pActiveSel->GetWeaponInfo()->GetID(); } m_pLastSel = m_pActiveSel; m_pActiveSel = nullptr; Hud().ClearKeyBits( IN_ATTACK ); PlaySound("common/wpn_select.wav", 1); } }
void CEnvironment::Update() { Vector vecOrigin = Hud().GetOrigin(); if( g_iUser1 > 0 && g_iUser1 != OBS_ROAMING ) { if( cl_entity_t* pFollowing = gEngfuncs.GetEntityByIndex( g_iUser2 ) ) { vecOrigin = pFollowing->origin; } } vecOrigin.z += 36.0f; if( cl_weather->value > 3.0 ) { gEngfuncs.Cvar_SetValue( "cl_weather", 3.0 ); } m_flWeatherValue = cl_weather->value; if( !IEngineStudio.IsHardware() ) m_flWeatherValue = 0; m_vecWeatherOrigin = vecOrigin; UpdateWind(); if( m_bGrassActive ) { UpdateGrass(); } if( m_flWeatherTime <= gEngfuncs.GetClientTime() ) { switch( m_WeatherType ) { case WeatherType::NONE: break; case WeatherType::RAIN: { UpdateRain(); break; } case WeatherType::SNOW: { UpdateSnow(); break; } } } m_flOldTime = gEngfuncs.GetClientTime(); }
bool CHudFlashlight::Draw(float flTime) { if ( GetHud().GetHideHudBits().Any( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ) return true; int r, g, b, x, y, a; wrect_t rc; if (!( Hud().GetWeaponBits() & (1<<(WEAPON_SUIT)) )) return true; if (m_fOn) a = 225; else a = MIN_ALPHA; if (m_flBat < 0.20) GetHud().GetEmptyItemColor().UnpackRGB(r,g,b); else GetHud().GetPrimaryColor().UnpackRGB(r,g,b); ScaleColors(r, g, b, a); y = (m_prc1->bottom - m_prc2->top)/2; x = ScreenWidth - m_iWidth - m_iWidth/2 ; // Draw the flashlight casing SPR_Set(m_hSprite1, r, g, b ); SPR_DrawAdditive( 0, x, y, m_prc1); if ( m_fOn ) { // draw the flashlight beam x = ScreenWidth - m_iWidth/2; SPR_Set( m_hBeam, r, g, b ); SPR_DrawAdditive( 0, x, y, m_prcBeam ); } // draw the flashlight energy level x = ScreenWidth - m_iWidth - m_iWidth/2 ; int iOffset = m_iWidth * (1.0 - m_flBat); if (iOffset < m_iWidth) { rc = *m_prc2; rc.left += iOffset; SPR_Set(m_hSprite2, r, g, b ); SPR_DrawAdditive( 0, x + iOffset, y, &rc); } return true; }
void CHudAmmo::UpdateWeaponHUD( CBasePlayerWeapon* pWeapon, bool bOnTarget ) { auto pHUDInfo = pWeapon->GetWeaponInfo()->GetHUDInfo(); //TODO: define 90 constant - Solokiller if( Hud().GetFOV() >= 90 ) { // normal crosshairs if( bOnTarget && pHUDInfo->GetAutoAim().hSprite ) SetCrosshair( pHUDInfo->GetAutoAim().hSprite, pHUDInfo->GetAutoAim().rect, 255, 255, 255 ); else SetCrosshair( pHUDInfo->GetCrosshair().hSprite, pHUDInfo->GetCrosshair().rect, 255, 255, 255 ); } else { // zoomed crosshairs if( bOnTarget && pHUDInfo->GetZoomedAutoAim().hSprite ) SetCrosshair( pHUDInfo->GetZoomedAutoAim().hSprite, pHUDInfo->GetZoomedAutoAim().rect, 255, 255, 255 ); else SetCrosshair( pHUDInfo->GetZoomedCrosshair().hSprite, pHUDInfo->GetZoomedCrosshair().rect, 255, 255, 255 ); } m_fFade = 200.0f; //!!! GetFlags() |= HUD_ACTIVE; }
void CEnvironment::UpdateRain() { m_flWeatherTime = gEngfuncs.GetClientTime() + 0.3f; Vector vecPlayerDir = g_vPlayerVelocity; /*const float flSpeed = */vecPlayerDir.NormalizeInPlace(); if( 150.0f * m_flWeatherValue > 0.0f ) { int iWindParticle = 0; Vector vecOrigin; Vector vecEndPos; Vector vecWindOrigin; pmtrace_t trace; for( size_t uiIndex = 0; static_cast<float>( uiIndex ) < 150.0f * m_flWeatherValue; ++uiIndex ) { vecOrigin = m_vecWeatherOrigin; vecOrigin.x += UTIL_RandomFloat( -400.0f, 400.0f ); vecOrigin.y += UTIL_RandomFloat( -400.0f, 400.0f ); vecOrigin.z += UTIL_RandomFloat( 100.0f, 300.0f ); vecEndPos.x = vecOrigin.x + ( ( UTIL_RandomLong( 0, 5 ) > 2 ) ? g_vPlayerVelocity.x : -g_vPlayerVelocity.x ); vecEndPos.y = vecOrigin.y + g_vPlayerVelocity.y; vecEndPos.z = 8000.0f; gEngfuncs.pEventAPI->EV_SetTraceHull( Hull::LARGE ); gEngfuncs.pEventAPI->EV_PlayerTrace( vecOrigin, vecEndPos, PM_WORLD_ONLY, -1, &trace ); const char* pszTexture = gEngfuncs.pEventAPI->EV_TraceTexture( trace.ent, vecOrigin, trace.endpos ); if( pszTexture && strncmp( pszTexture, "sky", 3 ) == 0 ) { CreateRaindrop( vecOrigin ); if( iWindParticle == 15 ) { iWindParticle = 1; vecWindOrigin.x = vecOrigin.x; vecWindOrigin.y = vecOrigin.y; vecWindOrigin.z = Hud().GetOrigin().z; if( gEngfuncs.pTriAPI->BoxInPVS( vecWindOrigin, vecWindOrigin ) ) { vecEndPos.z = 8000.0f; gEngfuncs.pEventAPI->EV_SetTraceHull( Hull::LARGE ); gEngfuncs.pEventAPI->EV_PlayerTrace( vecWindOrigin, vecEndPos, PM_WORLD_ONLY, -1, &trace ); pszTexture = gEngfuncs.pEventAPI->EV_TraceTexture( trace.ent, vecOrigin, trace.endpos ); if( pszTexture && strncmp( pszTexture, "sky", 3 ) == 0 ) { vecEndPos.z = -8000.0f; gEngfuncs.pEventAPI->EV_SetTraceHull( Hull::LARGE ); gEngfuncs.pEventAPI->EV_PlayerTrace( vecWindOrigin, vecEndPos, PM_WORLD_ONLY, -1, &trace ); CreateWindParticle( trace.endpos ); } } } else { ++iWindParticle; } } } } }
bool CHudAmmo::Draw(float flTime) { int a, x, y, r, g, b; int AmmoWidth; if (!( Hud().GetWeaponBits() & (1<<(WEAPON_SUIT)) )) return true; if ( GetHud().GetHideHudBits().Any( HIDEHUD_WEAPONS | HIDEHUD_ALL ) ) return true; // Draw Weapon Menu DrawWList(flTime); // Draw ammo pickup history gHR.DrawAmmoHistory( flTime ); if (!( GetFlags() & HUD_ACTIVE)) return false; if (!m_pWeapon) return false; if( m_pCrosshair->value != 0 && m_hCrosshair != INVALID_HSPRITE ) { float flScale; switch( static_cast<int>( m_pCrosshairMode->value ) ) { default: case CROSS_NATIVESCALE: flScale = 1; break; case CROSS_RESSCALE: flScale = max( ( ScreenWidth / 640.0 ) * 0.75, 1.0 ); break; case CROSS_USERSCALE: flScale = fabs( m_pCrosshairScale->value ); break; } class CCrosshairTriCallback : public ITriCoordFallback { public: void Calculate( HSPRITE hSprite, const int frame, const wrect_t& rect, const float flScale, int& x, int& y ) override { x = ( ScreenWidth - ( ( rect.right - rect.left ) ) ) / 2; y = ( ScreenHeight - ( ( rect.bottom - rect.top ) ) ) / 2; } }; CCrosshairTriCallback callback; Tri_DrawScaledSprite( m_hCrosshair, 0, m_iR, m_iG, m_iB, 255, kRenderTransTexture, flScale, callback, &m_CrosshairRC ); } CBasePlayerWeapon *pw = m_pWeapon; // shorthand // SPR_Draw Ammo if( !pw->GetWeaponInfo()->GetPrimaryAmmo() && !pw->GetWeaponInfo()->GetSecondaryAmmo() ) return false; int iFlags = DHN_DRAWZERO; // draw 0 values AmmoWidth = GetHud().GetSpriteRect( GetHud().GetHudNumber0Index() ).right - GetHud().GetSpriteRect( GetHud().GetHudNumber0Index() ).left; a = (int) max( static_cast<float>( MIN_ALPHA ), m_fFade ); if (m_fFade > 0) m_fFade -= ( Hud().GetTimeDelta() * 20 ); GetHud().GetPrimaryColor().UnpackRGB(r,g,b); ScaleColors(r, g, b, a ); // Does this weapon have a clip? y = ScreenHeight - GetHud().GetFontHeight() - GetHud().GetFontHeight() /2; CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer(); // Does weapon have any ammo at all? if ( auto pAmmo = pw->GetWeaponInfo()->GetPrimaryAmmo() ) { const auto& ammo = m_pWeapon->GetWeaponInfo()->GetHUDInfo()->GetPrimaryAmmo(); int iIconWidth = ammo.rect.right - ammo.rect.left; if (pw->m_iClientClip >= 0) { // room for the number and the '|' and the current ammo x = ScreenWidth - (8 * AmmoWidth) - iIconWidth; x = GetHud().DrawHudNumber(x, y, iFlags | DHN_3DIGITS, pw->m_iClientClip, r, g, b); int iBarWidth = AmmoWidth/10; x += AmmoWidth/2; GetHud().GetPrimaryColor().UnpackRGB(r,g,b); // draw the | bar FillRGBA(x, y, iBarWidth, GetHud().GetFontHeight(), r, g, b, a); x += iBarWidth + AmmoWidth/2; // GL Seems to need this ScaleColors(r, g, b, a ); x = GetHud().DrawHudNumber(x, y, iFlags | DHN_3DIGITS, pPlayer->CountAmmo( pAmmo->GetID() ), r, g, b); } else { // SPR_Draw a bullets only line x = ScreenWidth - 4 * AmmoWidth - iIconWidth; x = GetHud().DrawHudNumber(x, y, iFlags | DHN_3DIGITS, pPlayer->CountAmmo( pAmmo->GetID() ), r, g, b); } // Draw the ammo Icon int iOffset = ( ammo.rect.bottom - ammo.rect.top)/8; SPR_Set( ammo.hSprite, r, g, b); SPR_DrawAdditive(0, x, y - iOffset, &ammo.rect ); } // Does weapon have seconday ammo? if ( auto pAmmo = pw->GetWeaponInfo()->GetSecondaryAmmo() ) { const auto& ammo2 = m_pWeapon->GetWeaponInfo()->GetHUDInfo()->GetSecondaryAmmo(); int iIconWidth = ammo2.rect.right - ammo2.rect.left; // Do we have secondary ammo? if ( pPlayer->CountAmmo( pAmmo->GetID() ) > 0 ) { y -= GetHud().GetFontHeight() + GetHud().GetFontHeight() /4; x = ScreenWidth - 4 * AmmoWidth - iIconWidth; x = GetHud().DrawHudNumber(x, y, iFlags|DHN_3DIGITS, pPlayer->CountAmmo( pAmmo->GetID() ), r, g, b); // Draw the ammo Icon SPR_Set( ammo2.hSprite, r, g, b); int iOffset = ( ammo2.rect.bottom - ammo2.rect.top)/8; SPR_DrawAdditive(0, x, y - iOffset, &ammo2.rect ); } } return true; }
void CHudAmmo::SelectSlot( int iSlot, const bool fAdvance, int iDirection ) { if( auto pMenu = GETHUDCLASS( CHudMenu ) ) { if ( pMenu->m_fMenuDisplayed && !fAdvance && (iDirection == 1) ) { // menu is overriding slot use commands pMenu->SelectMenuItem( iSlot + 1 ); // slots are one off the key numbers return; } } if ( iSlot > MAX_WEAPON_SLOTS ) return; if ( m_bPlayerDead || GetHud().GetHideHudBits().Any( HIDEHUD_WEAPONS | HIDEHUD_ALL ) ) return; if (!( Hud().GetWeaponBits() & (1<<(WEAPON_SUIT)) )) return; if ( ! ( Hud().GetWeaponBits() & ~(1<<(WEAPON_SUIT)) )) return; CBasePlayerWeapon *p = NULL; bool fastSwitch = CVAR_GET_FLOAT( "hud_fastswitch" ) != 0; CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer(); if ( ( m_pActiveSel == NULL) || ( m_pActiveSel == ( CBasePlayerWeapon *)1) || (iSlot != m_pActiveSel->GetWeaponInfo()->GetBucket()) ) { PlaySound( "common/wpn_hudon.wav", 1 ); p = pPlayer->GetFirstPos( iSlot ); if ( p && fastSwitch ) // check for fast weapon switch mode { // if fast weapon switch is on, then weapons can be selected in a single keypress // but only if there is only one item in the bucket CBasePlayerWeapon *p2 = pPlayer->GetNextActivePos( p->GetWeaponInfo()->GetBucket(), p->GetWeaponInfo()->GetPosition() ); if ( !p2 ) { // only one active item in bucket, so change directly to weapon ServerCmd( p->GetWeaponInfo()->GetWeaponName() ); g_weaponselect = p->GetWeaponInfo()->GetID(); return; } } } else { PlaySound("common/wpn_moveselect.wav", 1); if ( m_pActiveSel ) p = pPlayer->GetNextActivePos( m_pActiveSel->GetWeaponInfo()->GetBucket(), m_pActiveSel->GetWeaponInfo()->GetPosition() ); if ( !p ) p = pPlayer->GetFirstPos( iSlot ); } if ( !p ) // no selection found { // just display the weapon list, unless fastswitch is on just ignore it if ( !fastSwitch ) m_pActiveSel = ( CBasePlayerWeapon *)1; else m_pActiveSel = nullptr; } else m_pActiveSel = p; }
bool CHudBattery::Draw(float flTime) { if ( GetHud().GetHideHudBits().Any( HIDEHUD_HEALTH ) ) return true; wrect_t rc; rc = *m_prc2; #if defined( _TFC ) float fScale = 0.0; if ( m_iBatMax > 0 ) fScale = 1.0 / (float)m_iBatMax; rc.top += m_iHeight * ((float)(m_iBatMax-(min(m_iBatMax,m_iBat))) * fScale); // battery can go from 0 to m_iBatMax so * fScale goes from 0 to 1 #else rc.top += m_iHeight * ((float)(100-(min(100,m_iBat))) * 0.01); // battery can go from 0 to 100 so * 0.01 goes from 0 to 1 #endif if (!( Hud().GetWeaponBits() & (1<<(WEAPON_SUIT)) )) return true; int r, g, b, x, y, a = MIN_ALPHA; GetHud().GetPrimaryColor().UnpackRGB( r, g, b ); // Has health changed? Flash the health # if (m_fFade) { if (m_fFade > FADE_TIME) m_fFade = FADE_TIME; m_fFade -= ( Hud().GetTimeDelta() * 20); if (m_fFade <= 0) { m_fFade = 0; } // Fade the health number back to dim a += ( m_fFade / FADE_TIME ) * 128; } ScaleColors(r, g, b, a ); int iOffset = (m_prc1->bottom - m_prc1->top)/6; y = ScreenHeight - GetHud().GetFontHeight() - GetHud().GetFontHeight() / 2; x = ScreenWidth/5; // make sure we have the right sprite handles if ( !m_hSprite1 ) m_hSprite1 = GetHud().GetSprite( GetHud().GetSpriteIndex( "suit_empty" ) ); if ( !m_hSprite2 ) m_hSprite2 = GetHud().GetSprite( GetHud().GetSpriteIndex( "suit_full" ) ); SPR_Set(m_hSprite1, r, g, b ); SPR_DrawAdditive( 0, x, y - iOffset, m_prc1); if (rc.bottom > rc.top) { SPR_Set(m_hSprite2, r, g, b ); SPR_DrawAdditive( 0, x, y - iOffset + (rc.top - m_prc2->top), &rc); } x += (m_prc1->right - m_prc1->left); x = GetHud().DrawHudNumber(x, y, DHN_3DIGITS | DHN_DRAWZERO, m_iBat, r, g, b); return true; }
int Graphic::AddRectangle( int _texture, float _scale, float _x, float _y, float _rotation, float _scale_x ) { return hud.insert( Hud( Rectangle( _x, _y, _scale, _rotation, _scale_x ), _texture ) ); }