Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
5.4 KiB

9 years ago
/***
*
* 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.
*
****/
//
// ammohistory.cpp
//
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include <string.h>
#include <stdio.h>
#include "ammohistory.h"
HistoryResource gHR;
#define AMMO_PICKUP_GAP ( gHR.iHistoryGap + 5 )
9 years ago
#define AMMO_PICKUP_PICK_HEIGHT ( 32 + ( gHR.iHistoryGap * 2 ) )
#define AMMO_PICKUP_HEIGHT_MAX ( ScreenHeight - 100 )
9 years ago
#define MAX_ITEM_NAME 32
int HISTORY_DRAW_TIME = 5;
9 years ago
// keep a list of items
struct ITEM_INFO
{
char szName[MAX_ITEM_NAME];
HSPRITE spr;
wrect_t rect;
};
9 years ago
void HistoryResource::AddToHistory( int iType, int iId, int iCount )
9 years ago
{
9 years ago
if( iType == HISTSLOT_AMMO && !iCount )
9 years ago
return; // no amount, so don't add
9 years ago
if( ( ( ( AMMO_PICKUP_GAP * iCurrentHistorySlot ) + AMMO_PICKUP_PICK_HEIGHT ) > AMMO_PICKUP_HEIGHT_MAX ) || ( iCurrentHistorySlot >= MAX_HISTORY ) )
{
// the pic would have to be drawn too high
9 years ago
// so start from the bottom
iCurrentHistorySlot = 0;
}
HIST_ITEM *freeslot = &rgAmmoHistory[iCurrentHistorySlot++]; // default to just writing to the first slot
HISTORY_DRAW_TIME = CVAR_GET_FLOAT( "hud_drawhistory_time" );
freeslot->type = iType;
freeslot->iId = iId;
freeslot->iCount = iCount;
freeslot->DisplayTime = gHUD.m_flTime + HISTORY_DRAW_TIME;
}
9 years ago
void HistoryResource::AddToHistory( int iType, const char *szName, int iCount )
9 years ago
{
9 years ago
if( iType != HISTSLOT_ITEM )
9 years ago
return;
9 years ago
if( ( ( ( AMMO_PICKUP_GAP * iCurrentHistorySlot ) + AMMO_PICKUP_PICK_HEIGHT ) > AMMO_PICKUP_HEIGHT_MAX ) || ( iCurrentHistorySlot >= MAX_HISTORY ) )
{
// the pic would have to be drawn too high
9 years ago
// so start from the bottom
iCurrentHistorySlot = 0;
}
HIST_ITEM *freeslot = &rgAmmoHistory[iCurrentHistorySlot++]; // default to just writing to the first slot
// I am really unhappy with all the code in this file
int i = gHUD.GetSpriteIndex( szName );
9 years ago
if( i == -1 )
9 years ago
return; // unknown sprite name, don't add it to history
freeslot->iId = i;
freeslot->type = iType;
freeslot->iCount = iCount;
HISTORY_DRAW_TIME = CVAR_GET_FLOAT( "hud_drawhistory_time" );
freeslot->DisplayTime = gHUD.m_flTime + HISTORY_DRAW_TIME;
}
9 years ago
void HistoryResource::CheckClearHistory( void )
9 years ago
{
9 years ago
for( int i = 0; i < MAX_HISTORY; i++ )
9 years ago
{
9 years ago
if( rgAmmoHistory[i].type )
9 years ago
return;
}
iCurrentHistorySlot = 0;
}
//
// Draw Ammo pickup history
//
9 years ago
int HistoryResource::DrawAmmoHistory( float flTime )
9 years ago
{
for( int i = 0; i < MAX_HISTORY; i++ )
9 years ago
{
9 years ago
if( rgAmmoHistory[i].type )
9 years ago
{
rgAmmoHistory[i].DisplayTime = min( rgAmmoHistory[i].DisplayTime, gHUD.m_flTime + HISTORY_DRAW_TIME );
9 years ago
if( rgAmmoHistory[i].DisplayTime <= flTime )
{
// pic drawing time has expired
9 years ago
memset( &rgAmmoHistory[i], 0, sizeof(HIST_ITEM) );
CheckClearHistory();
}
9 years ago
else if( rgAmmoHistory[i].type == HISTSLOT_AMMO )
9 years ago
{
wrect_t rcPic;
HSPRITE *spr = gWR.GetAmmoPicFromWeapon( rgAmmoHistory[i].iId, rcPic );
int r, g, b;
9 years ago
UnpackRGB( r, g, b, RGB_YELLOWISH );
float scale = ( rgAmmoHistory[i].DisplayTime - flTime ) * 80;
ScaleColors( r, g, b, min( scale, 255 ) );
9 years ago
// Draw the pic
int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i));
int xpos = ScreenWidth - 24;
9 years ago
if( spr && *spr ) // weapon isn't loaded yet so just don't draw the pic
{
// the dll has to make sure it has sent info the weapons you need
9 years ago
SPR_Set( *spr, r, g, b );
SPR_DrawAdditive( 0, xpos, ypos, &rcPic );
}
// do not draw black console string
9 years ago
if( !( ( hud_textmode->value == 2 ) && ( scale < 200 ) ) )
// Draw the number
9 years ago
gHUD.DrawHudNumberString( xpos - 10, ypos, xpos - 100, rgAmmoHistory[i].iCount, r, g, b );
}
9 years ago
else if( rgAmmoHistory[i].type == HISTSLOT_WEAP )
9 years ago
{
WEAPON *weap = gWR.GetWeapon( rgAmmoHistory[i].iId );
9 years ago
if( !weap )
9 years ago
return 1; // we don't know about the weapon yet, so don't draw anything
int r, g, b;
9 years ago
UnpackRGB( r,g,b, RGB_YELLOWISH );
9 years ago
9 years ago
if( !gWR.HasAmmo( weap ) )
UnpackRGB( r, g, b, RGB_REDISH ); // if the weapon doesn't have ammo, display it as red
9 years ago
9 years ago
float scale = ( rgAmmoHistory[i].DisplayTime - flTime ) * 80;
ScaleColors( r, g, b, min( scale, 255 ) );
9 years ago
9 years ago
int ypos = ScreenHeight - ( AMMO_PICKUP_PICK_HEIGHT + ( AMMO_PICKUP_GAP * i ) );
int xpos = ScreenWidth - ( weap->rcInactive.right - weap->rcInactive.left );
9 years ago
SPR_Set( weap->hInactive, r, g, b );
SPR_DrawAdditive( 0, xpos, ypos, &weap->rcInactive );
}
9 years ago
else if( rgAmmoHistory[i].type == HISTSLOT_ITEM )
9 years ago
{
int r, g, b;
9 years ago
if( !rgAmmoHistory[i].iId )
9 years ago
continue; // sprite not loaded
wrect_t rect = gHUD.GetSpriteRect( rgAmmoHistory[i].iId );
9 years ago
UnpackRGB( r, g, b, RGB_YELLOWISH );
float scale = ( rgAmmoHistory[i].DisplayTime - flTime ) * 80;
ScaleColors( r, g, b, min( scale, 255 ) );
9 years ago
9 years ago
int ypos = ScreenHeight - ( AMMO_PICKUP_PICK_HEIGHT + ( AMMO_PICKUP_GAP * i ) );
int xpos = ScreenWidth - ( rect.right - rect.left ) - 10;
9 years ago
SPR_Set( gHUD.GetSprite( rgAmmoHistory[i].iId ), r, g, b );
SPR_DrawAdditive( 0, xpos, ypos, &rect );
}
}
}
9 years ago
return 1;
}