int CHudAmmo::MsgFunc_HideWeapon( const char *pszName, int iSize, void *pbuf ) { CBufferReader reader( pbuf, iSize ); gHUD.m_iHideHUDDisplay = reader.ReadByte(); if (gEngfuncs.IsSpectateOnly()) return 1; if ( gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL ) ) { wrect_t nullrc = {}; m_pActiveSel = nullptr; SetCrosshair( 0, nullrc, 0, 0, 0 ); } else { if ( m_pWeapon ) { const auto& crosshair = m_pWeapon->GetWeaponInfo()->GetHUDInfo()->GetCrosshair(); SetCrosshair( crosshair.hSprite, crosshair.rect, 255, 255, 255 ); } } return 1; }
// // CurWeapon: Update hud state with the current weapon and clip count. Ammo // counts are updated with AmmoX. Server assures that the Weapon ammo type // numbers match a real ammo type. // int CHudAmmo::MsgFunc_CurWeapon(const char *pszName, int iSize, void *pbuf ) { wrect_t nullrc = {}; CBufferReader reader( pbuf, iSize ); const WpnOnTargetState state = static_cast<WpnOnTargetState>( reader.ReadByte() ); int iId = reader.ReadChar(); int iClip = reader.ReadChar(); // detect if we're also on target bool fOnTarget = state == WpnOnTargetState::ACTIVE_IS_ONTARGET; if ( iId < 1 ) { SetCrosshair(0, nullrc, 0, 0, 0); //Clear out the weapon so we don't keep drawing the last active weapon's ammo. - Solokiller m_pWeapon = nullptr; return 0; } if ( g_iUser1 != OBS_IN_EYE ) { // Is player dead??? if ((iId == -1) && (iClip == -1)) { gHUD.m_bPlayerDead = true; m_pActiveSel = nullptr; return 1; } gHUD.m_bPlayerDead = false; } CBasePlayerWeapon *pWeapon = g_Prediction.GetWeapon( iId ); if( !pWeapon ) { m_bNeedsLocalUpdate = true; m_bOnTarget = fOnTarget; m_iFlags |= HUD_ACTIVE; return 1; } else if( m_bNeedsLocalUpdate ) m_bNeedsLocalUpdate = false; if ( iClip < -1 ) pWeapon->m_iClientClip = abs(iClip); else pWeapon->m_iClientClip = iClip; if ( state == WpnOnTargetState::NOT_ACTIVE_WEAPON ) // we're not the current weapon, so update no more return 1; m_pWeapon = pWeapon; UpdateWeaponHUD( m_pWeapon, fOnTarget ); return 1; }
void CHUDCrosshair::SelectCrosshair(IItem *pItem) { //set special crosshairs design comes up with ... bool bSpecialCrosshairSet = false; if(IActor *pActor = g_pGame->GetIGameFramework()->GetClientActor()) { if(g_pGameCVars->hud_crosshair != 0) { if(!pItem) pItem = pActor->GetCurrentItem(); if(!pItem || pItem->GetEntity()->GetClass() == CItem::sFistsClass || pItem->GetEntity()->GetClass() == CItem::sAlienCloak) { SetCrosshair(0); //was 10 bSpecialCrosshairSet = true; } else if(IWeapon *pWeapon = pItem->GetIWeapon()) //Laser attached { if((static_cast<CWeapon*>(pWeapon))->IsLamAttached()) { SetCrosshair(0); bSpecialCrosshairSet = true; } } // No current item or current item are fists or AlienCloak or LAW if(!bSpecialCrosshairSet) { if(pItem->GetEntity()->GetClass() == CItem::sRocketLauncherClass || pItem->GetEntity()->GetClass() == CItem::sTACGunFleetClass) { SetCrosshair(0); bSpecialCrosshairSet = true; } else if(pItem->GetEntity()->GetClass() == CItem::sTACGunClass) { SetCrosshair(11); bSpecialCrosshairSet = true; } else if(g_pHUD->GetSelectedFiremode() == 6) //sleep bullet { SetCrosshair(12); bSpecialCrosshairSet = true; } else if(g_pHUD->GetSelectedFiremode() == 4) //grenade launcher { SetCrosshair(13); bSpecialCrosshairSet = true; } } } } //now set normal crosshair if(!bSpecialCrosshairSet) SetCrosshair(g_pGameCVars->hud_crosshair); }
int CHudAmmo::MsgFunc_HideWeapon(const char *pszName, int iSize, void *pbuf) { BEGIN_READ(pbuf, iSize); gHUD.m_iHideHUDDisplay = READ_BYTE(); if(gHUD.m_iHideHUDDisplay & (HIDEHUD_WEAPONS | HIDEHUD_ALL)) { static wrect_t nullrc; gpActiveSel = NULL; SetCrosshair(0, nullrc, 0, 0, 0); } else { if(m_pWeapon) SetCrosshair(m_pWeapon->hCrosshair, m_pWeapon->rcCrosshair, 255, 255, 255); } return 1; }
int CHudAmmo::MsgFunc_HideWeapon( const char *pszName, int iSize, void *pbuf ) { BEGIN_READ( pszName, pbuf, iSize ); gHUD.m_iHideHUDDisplay = READ_BYTE(); if(( m_pWeapon == NULL ) || ( gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL ))) { gpActiveSel = NULL; SetCrosshair( 0, nullRc, 0, 0, 0 ); } else { SetCrosshair( m_pWeapon->hCrosshair, m_pWeapon->rcCrosshair, 255, 255, 255 ); } END_READ(); return 1; }
// // CurWeapon: Update hud state with the current weapon and clip count. Ammo // counts are updated with AmmoX. Server assures that the Weapon ammo type // numbers match a real ammo type. // int CHudAmmo::MsgFunc_CurWeapon(const char *pszName, int iSize, void *pbuf) { static wrect_t nullrc; int fOnTarget = FALSE; BEGIN_READ(pbuf, iSize); int iState = READ_BYTE(); int iId = READ_BYTE(); int iClip = READ_CHAR(); // detect if we're also on target if(iState > 1) { fOnTarget = TRUE; } if(iId < 1) { SetCrosshair(0, nullrc, 0, 0, 0); return 0; } // Is player dead??? if((iId == -1) && (iClip == -1)) { gHUD.m_fPlayerDead = TRUE; gpActiveSel = NULL; return 1; } gHUD.m_fPlayerDead = FALSE; WEAPON *pWeapon = gWR.GetWeapon(iId); if(!pWeapon) return 0; if(iClip < -1) pWeapon->iClip = abs(iClip); else pWeapon->iClip = iClip; if(iState == 0) // we're not the current weapon, so update no more return 1; m_pWeapon = pWeapon; m_fFade = 200.0f; //!!! m_iFlags |= HUD_ACTIVE; return 1; }
void CHudAmmo::UpdateWeaponHUD( CBasePlayerWeapon* pWeapon, bool bOnTarget ) { auto pHUDInfo = pWeapon->GetWeaponInfo()->GetHUDInfo(); if( gHUD.m_iFOV >= 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; //!!! m_iFlags |= HUD_ACTIVE; }
void CHudAmmo::Reset( void ) { m_fFade = 0; m_iFlags |= HUD_ACTIVE; //!!! gpActiveSel = NULL; gHUD.m_iHideHUDDisplay = 0; gWR.Reset(); gHR.Reset(); SetCrosshair( 0, nullRc, 0, 0, 0 ); // reset crosshair m_pWeapon = NULL; // reset last weapon }
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; }
// // CurWeapon: Update hud state with the current weapon and clip count. Ammo // counts are updated with AmmoX. Server assures that the Weapon ammo type // numbers match a real ammo type. // int CHudAmmo::MsgFunc_CurWeapon(const char *pszName, int iSize, void *pbuf) { static wrect_t nullrc; int fOnTarget = FALSE; BEGIN_READ(pbuf, iSize); int iState = READ_BYTE(); int iId = READ_CHAR(); int iClip = READ_CHAR(); // detect if we're also on target if(iState > 1) { fOnTarget = TRUE; } if(iId < 1) { SetCrosshair(0, nullrc, 0, 0, 0); return 0; } // Is player dead??? if((iId == -1) && (iClip == -1)) { gHUD.m_fPlayerDead = TRUE; gpActiveSel = NULL; return 1; } gHUD.m_fPlayerDead = FALSE; WEAPON *pWeapon = gWR.GetWeapon(iId); if(!pWeapon) return 0; if(iClip < -1) pWeapon->iClip = abs(iClip); else pWeapon->iClip = iClip; if(iState == 0) // we're not the current weapon, so update no more return 1; m_pWeapon = pWeapon; if(!(gHUD.m_iHideHUDDisplay & (HIDEHUD_WEAPONS | HIDEHUD_ALL))) { if(gHUD.m_iFOV >= 90) { // normal crosshairs if(fOnTarget && m_pWeapon->hAutoaim) SetCrosshair(m_pWeapon->hAutoaim, m_pWeapon->rcAutoaim, 255, 255, 255); else SetCrosshair(m_pWeapon->hCrosshair, m_pWeapon->rcCrosshair, 255, 255, 255); } else { // zoomed crosshairs if(fOnTarget && m_pWeapon->hZoomedAutoaim) SetCrosshair(m_pWeapon->hZoomedAutoaim, m_pWeapon->rcZoomedAutoaim, 255, 255, 255); else SetCrosshair(m_pWeapon->hZoomedCrosshair, m_pWeapon->rcZoomedCrosshair, 255, 255, 255); } } m_fFade = 200.0f; //!!! m_iFlags |= HUD_ACTIVE; return 1; }
// // CurWeapon: Update hud state with the current weapon and clip count. Ammo // counts are updated with AmmoX. Server assures that the Weapon ammo type // numbers match a real ammo type. // int CHudAmmo::MsgFunc_CurWeapon(const char *pszName, int iSize, void *pbuf ) { static wrect_t nullrc; BEGIN_READ( pbuf, iSize ); int iState = READ_BYTE(); int iId = READ_CHAR(); int iClip = READ_CHAR(); if ( iId < 1 ) { SetCrosshair(0, nullrc, 0, 0, 0); return 0; } if ( g_iUser1 != OBS_IN_EYE ) { // Is player dead??? if ((iId == -1) && (iClip == -1)) { gHUD.m_fPlayerDead = TRUE; gpActiveSel = NULL; return 1; } gHUD.m_fPlayerDead = FALSE; } WEAPON *pWeapon = gWR.GetWeapon( iId ); if ( !pWeapon ) return 0; if ( iClip < -1 ) pWeapon->iClip = abs(iClip); else pWeapon->iClip = iClip; if ( iState == 0 ) // we're not the current weapon, so update no more return 1; m_pWeapon = pWeapon; /*if( gHUD.m_iFOV <= 40 ) { // zoomed crosshairs if (fOnTarget && m_pWeapon->hZoomedAutoaim) SetCrosshair(m_pWeapon->hZoomedAutoaim, m_pWeapon->rcZoomedAutoaim, 255, 255, 255); else SetCrosshair(m_pWeapon->hZoomedCrosshair, m_pWeapon->rcZoomedCrosshair, 255, 255, 255); } else { SetCrosshair( 0, nullrc, 0, 0, 0); }*/ m_fFade = 200.0f; //!!! m_iFlags |= HUD_ACTIVE; return 1; }
int CHudAmmo::Draw(float flTime) { wrect_t nullrc; int a, x, y, r, g, b; int AmmoWidth; if (!(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)) )) return 1; if ( (gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL )) ) return 1; // Draw Weapon Menu DrawWList(flTime); // Draw ammo pickup history gHR.DrawAmmoHistory( flTime ); if (!(m_iFlags & HUD_ACTIVE)) return 0; if (!m_pWeapon) return 0; if( gHUD.m_iFOV > 40 ) { SetCrosshair( 0, nullrc, 0, 0, 0); DrawCrosshair(flTime, m_pWeapon->iId); // draw a dynamic crosshair } else { SetCrosshair(m_pWeapon->hZoomedCrosshair, m_pWeapon->rcZoomedCrosshair, 255, 255, 255); } WEAPON *pw = m_pWeapon; // shorthand // SPR_Draw Ammo if ((pw->iAmmoType < 0) && (pw->iAmmo2Type < 0)) return 0; int iFlags = DHN_DRAWZERO; // draw 0 values AmmoWidth = gHUD.GetSpriteRect(gHUD.m_HUD_number_0).right - gHUD.GetSpriteRect(gHUD.m_HUD_number_0).left; a = (int) max( MIN_ALPHA, m_fFade ); if (m_fFade > 0) m_fFade -= (gHUD.m_flTimeDelta * 20); DrawUtils::DrawUtils::UnpackRGB(r,g,b, RGB_YELLOWISH); DrawUtils::DrawUtils::ScaleColors(r, g, b, a ); // Does this weapon have a clip? y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight/2; // Does weapon have any ammo at all? if (m_pWeapon->iAmmoType > 0) { int iIconWidth = m_pWeapon->rcAmmo.right - m_pWeapon->rcAmmo.left; if (pw->iClip >= 0) { // room for the number and the '|' and the current ammo x = ScreenWidth - (8 * AmmoWidth) - iIconWidth; x = DrawUtils::DrawHudNumber(x, y, iFlags | DHN_3DIGITS, pw->iClip, r, g, b); int iBarWidth = AmmoWidth/10; x += AmmoWidth/2; DrawUtils::UnpackRGB(r,g,b, RGB_YELLOWISH); // draw the | bar FillRGBA(x, y, iBarWidth, gHUD.m_iFontHeight, r, g, b, a); x += iBarWidth + AmmoWidth/2;; // GL Seems to need this DrawUtils::ScaleColors(r, g, b, a ); x = DrawUtils::DrawHudNumber(x, y, iFlags | DHN_3DIGITS, gWR.CountAmmo(pw->iAmmoType), r, g, b); } else { // SPR_Draw a bullets only line x = ScreenWidth - 4 * AmmoWidth - iIconWidth; x = DrawUtils::DrawHudNumber(x, y, iFlags | DHN_3DIGITS, gWR.CountAmmo(pw->iAmmoType), r, g, b); } // Draw the ammo Icon int iOffset = (m_pWeapon->rcAmmo.bottom - m_pWeapon->rcAmmo.top)/8; SPR_Set(m_pWeapon->hAmmo, r, g, b); SPR_DrawAdditive(0, x, y - iOffset, &m_pWeapon->rcAmmo); } // Does weapon have seconday ammo? if (pw->iAmmo2Type > 0) { int iIconWidth = m_pWeapon->rcAmmo2.right - m_pWeapon->rcAmmo2.left; // Do we have secondary ammo? if ((pw->iAmmo2Type != 0) && (gWR.CountAmmo(pw->iAmmo2Type) > 0)) { y -= gHUD.m_iFontHeight + gHUD.m_iFontHeight/4; x = ScreenWidth - 4 * AmmoWidth - iIconWidth; x = DrawUtils::DrawHudNumber(x, y, iFlags|DHN_3DIGITS, gWR.CountAmmo(pw->iAmmo2Type), r, g, b); // Draw the ammo Icon SPR_Set(m_pWeapon->hAmmo2, r, g, b); int iOffset = (m_pWeapon->rcAmmo2.bottom - m_pWeapon->rcAmmo2.top)/8; SPR_DrawAdditive(0, x, y - iOffset, &m_pWeapon->rcAmmo2); } } return 1; }