2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-22 01:47:45 +01:00
hlsdk-xash3d/cl_dll/battery.cpp

138 lines
3.1 KiB
C++
Raw Normal View History

2016-06-04 15:24:23 +02:00
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
//
// battery.cpp
//
// implementation of CHudBattery class
//
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include <string.h>
#include <stdio.h>
2016-07-03 15:39:55 +02:00
DECLARE_MESSAGE( m_Battery, Battery )
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
int CHudBattery::Init( void )
2016-06-04 15:24:23 +02:00
{
m_iBat = 0;
m_fFade = 0;
m_iFlags = 0;
2016-07-03 15:39:55 +02:00
HOOK_MESSAGE( Battery );
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
gHUD.AddHudElem( this );
2016-06-04 15:24:23 +02:00
return 1;
}
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
int CHudBattery::VidInit( void )
2016-06-04 15:24:23 +02:00
{
int HUD_suit_empty = gHUD.GetSpriteIndex( "suit_empty" );
int HUD_suit_full = gHUD.GetSpriteIndex( "suit_full" );
m_hSprite1 = m_hSprite2 = 0; // delaying get sprite handles until we know the sprites are loaded
m_prc1 = &gHUD.GetSpriteRect( HUD_suit_empty );
m_prc2 = &gHUD.GetSpriteRect( HUD_suit_full );
m_iHeight = m_prc2->bottom - m_prc1->top;
m_fFade = 0;
return 1;
}
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
int CHudBattery::MsgFunc_Battery( const char *pszName, int iSize, void *pbuf )
2016-06-04 15:24:23 +02:00
{
m_iFlags |= HUD_ACTIVE;
BEGIN_READ( pbuf, iSize );
int x = READ_SHORT();
2016-07-03 15:39:55 +02:00
if( x != m_iBat )
2016-06-04 15:24:23 +02:00
{
m_fFade = FADE_TIME;
m_iBat = x;
}
return 1;
}
2016-07-03 15:39:55 +02:00
int CHudBattery::Draw( float flTime )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
if( gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH )
2016-06-04 15:24:23 +02:00
return 1;
int r, g, b, x, y, a;
wrect_t rc;
rc = *m_prc2;
2019-10-13 13:49:25 +02:00
rc.top += m_iHeight * ( (float)( 100 - ( Q_min( 100, m_iBat ) ) ) * 0.01f ); // battery can go from 0 to 100 so * 0.01 goes from 0 to 1
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
UnpackRGB( r, g, b, RGB_YELLOWISH );
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
if( !( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_SUIT ) ) ) )
2016-06-04 15:24:23 +02:00
return 1;
// Has health changed? Flash the health #
2016-07-03 15:39:55 +02:00
if( m_fFade )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
if( m_fFade > FADE_TIME )
2016-06-04 15:24:23 +02:00
m_fFade = FADE_TIME;
2019-10-13 14:12:41 +02:00
m_fFade -= ( (float)gHUD.m_flTimeDelta * 20.0f );
2016-07-03 15:39:55 +02:00
if( m_fFade <= 0 )
2016-06-04 15:24:23 +02:00
{
a = 128;
m_fFade = 0;
}
// Fade the health number back to dim
2016-07-03 15:39:55 +02:00
a = MIN_ALPHA + ( m_fFade / FADE_TIME ) * 128;
2016-06-04 15:24:23 +02:00
}
else
a = MIN_ALPHA;
2016-07-03 15:39:55 +02:00
ScaleColors( r, g, b, a );
int iOffset = ( m_prc1->bottom - m_prc1->top ) / 6;
2016-06-04 15:24:23 +02:00
y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;
if( gHUD.IsHL25( )) // a1ba: HL25 style
x = ( m_prc1->right - m_prc1->left ) * 3;
else
x = ScreenWidth / 5;
2016-06-04 15:24:23 +02:00
// make sure we have the right sprite handles
2016-07-03 15:39:55 +02:00
if( !m_hSprite1 )
2016-06-04 15:24:23 +02:00
m_hSprite1 = gHUD.GetSprite( gHUD.GetSpriteIndex( "suit_empty" ) );
2016-07-03 15:39:55 +02:00
if( !m_hSprite2 )
2016-06-04 15:24:23 +02:00
m_hSprite2 = gHUD.GetSprite( gHUD.GetSpriteIndex( "suit_full" ) );
2016-07-03 15:39:55 +02:00
SPR_Set( m_hSprite1, r, g, b );
SPR_DrawAdditive( 0, x, y - iOffset, m_prc1 );
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
if( rc.bottom > rc.top )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
SPR_Set( m_hSprite2, r, g, b );
SPR_DrawAdditive( 0, x, y - iOffset + ( rc.top - m_prc2->top ), &rc );
2016-06-04 15:24:23 +02:00
}
2016-07-03 15:39:55 +02:00
x += ( m_prc1->right - m_prc1->left );
x = gHUD.DrawHudNumber( x, y + gHUD.m_iHudNumbersYOffset, DHN_3DIGITS | DHN_DRAWZERO, m_iBat, r, g, b );
2016-06-04 15:24:23 +02:00
return 1;
}