Advertisement
Shepard62700FR

TWHL - Abbadon - hud_overheat.cpp

Jan 31st, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. /***
  2. *
  3. *   Copyright (c) 1999, Valve LLC. All rights reserved.
  4. *  
  5. *   This product contains software technology licensed from Id
  6. *   Software, Inc. ("Id Technology").  Id Technology (c) 1996 Id Software, Inc.
  7. *   All Rights Reserved.
  8. *
  9. *   Use, distribution, and modification of this source code and/or resulting
  10. *   object code is restricted to non-commercial enhancements to products from
  11. *   Valve LLC.  All other use, distribution, or modification is prohibited
  12. *   without written permission from Valve LLC.
  13. *
  14. ****/
  15.  
  16. //
  17. // hud_overheat.cpp - Source of the CHudOverheat class.
  18. //
  19.  
  20. #include "hud.h"
  21. #include "cl_util.h"
  22. #include "parsemsg.h"
  23.  
  24. DECLARE_MESSAGE( m_Overheat, Overheat );
  25.  
  26. int CHudOverheat::Init( void )
  27. {
  28.     HOOK_MESSAGE( Overheat );
  29.     m_iHeat = 0;
  30.     m_iFlags |= HUD_ACTIVE;
  31.     gHUD.AddHudElem( this );
  32.     return 1;
  33. }
  34.  
  35. int CHudOverheat::Draw( float flTime )
  36. {
  37.     // Don't draw this HUD if the health is told to be hidden or we are in spectator mode
  38.     if ( (gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH) || gEngfuncs.IsSpectateOnly() )
  39.         return 1;
  40.  
  41.     // Don't draw this HUD if we don't have the HEV suit.
  42.     if ( !(gHUD.m_iWeaponBits & (1 << WEAPON_SUIT)) )
  43.         return 1;
  44.  
  45.     // Don't draw this HUD if we are using anything else than the MP5
  46.     if ( !gHUD.m_Ammo.GetCurrentWeapon() || gHUD.m_Ammo.GetCurrentWeapon()->iId != 4 ) // 4 = WEAPON_MP5 - Look at "weapons.h" for the proper value
  47.         return 1;
  48.  
  49.     if ( m_iHeat > 0 )
  50.     {
  51.         int iWidth = XRES( 340 );
  52.         int iHeight = YRES( 10 );
  53.         int iBarWidth = XRES( 1 );
  54.         int iBarHeight = XRES( 1 );
  55.         int iPosX = (ScreenWidth - iWidth) / 2;
  56.         int iPosY = (ScreenHeight - iHeight) / 2 + YRES( 50 );
  57.         int iRed = 0;
  58.         int iGreen = 0;
  59.         int iBlue = 0;
  60.  
  61.         PercentageToColor( m_iHeat, iRed, iGreen, iBlue );
  62.         FillRGBA( iPosX + iBarWidth * 2, iPosY + iBarHeight * 2, CalculatePercentage( iWidth, iBarWidth ), iHeight - 4 * iBarHeight, iRed, iGreen, iBlue, 255 );
  63.     }
  64.  
  65.     return 1;
  66. }
  67.  
  68. int CHudOverheat::MsgFunc_Overheat( const char *pszName, int iSize, void *pbuf )
  69. {
  70.     BEGIN_READ( pbuf, iSize );
  71.     m_iHeat = READ_BYTE();
  72.     return 1;
  73. }
  74.  
  75. int CHudOverheat::CalculatePercentage( const int _iWidth, const int _iBarWidth )
  76. {
  77.     return (int)((m_iHeat / 100.0f) * (_iWidth - 4 * _iBarWidth));
  78. }
  79.  
  80. void CHudOverheat::PercentageToColor( const int _iPercentage, int &_iRed, int &_iGreen, int &_iBlue )
  81. {
  82.     _iRed = (255 * _iPercentage) / 100;
  83.     _iGreen = (255 * (100 - _iPercentage)) / 100;
  84.     _iBlue = 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement