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.

152 lines
3.9 KiB

//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ============
9 years ago
//
// Purpose: New version of the slider bar
//
// $NoKeywords: $
//=============================================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "player.h"
#include "trains.h"
#include "nodes.h"
#include "weapons.h"
#include "soundent.h"
#include "monsters.h"
#include "../engine/shake.h"
9 years ago
#include "decals.h"
#include "gamerules.h"
float AmmoDamage( const char *pName )
{
8 years ago
if( !pName )
9 years ago
return 0;
8 years ago
if( !strcmp( pName, "9mm" ) )
9 years ago
return gSkillData.plrDmg9MM;
8 years ago
if( !strcmp( pName, "357" ) )
9 years ago
return gSkillData.plrDmg357;
8 years ago
if( !strcmp( pName, "ARgrenades" ) )
9 years ago
return gSkillData.plrDmgM203Grenade;
8 years ago
if( !strcmp( pName, "buckshot" ) )
9 years ago
return gSkillData.plrDmgBuckshot;
8 years ago
if( !strcmp( pName, "bolts") )
9 years ago
return gSkillData.plrDmgCrossbowMonster;
8 years ago
if( !strcmp( pName, "rockets") )
9 years ago
return gSkillData.plrDmgRPG;
8 years ago
if( !strcmp( pName, "uranium") )
9 years ago
return gSkillData.plrDmgGauss;
8 years ago
if( !strcmp( pName, "Hand Grenade") )
9 years ago
return gSkillData.plrDmgHandGrenade;
8 years ago
if( !strcmp( pName, "Satchel Charge") )
9 years ago
return gSkillData.plrDmgSatchel;
8 years ago
if( !strcmp( pName, "Trip Mine") )
9 years ago
return gSkillData.plrDmgTripmine;
return 0;
}
void UpdateStatsFile( float dataTime, const char *pMapname, float health, float ammo, int skillLevel )
9 years ago
{
FILE *fp;
fp = fopen( "stats.txt", "a" );
8 years ago
if( !fp )
9 years ago
return;
fprintf( fp, "%6.2f, %6.2f, %6.2f, %s, %2d\n", dataTime, health, ammo, pMapname, skillLevel );
fclose( fp );
}
#define AMMO_THRESHOLD 10 // This much ammo goes by before it is "interesting"
#define HEALTH_THRESHOLD 10 // Same for health
#define OUTPUT_LATENCY 3 // This many seconds for ammo/health to settle
typedef struct
{
8 years ago
int lastAmmo;
float lastHealth;
float lastOutputTime; // NOTE: These times are in "game" time -- a running total of elapsed time since the game started
float nextOutputTime;
float dataTime;
float gameTime;
float lastGameTime;
9 years ago
} TESTSTATS;
8 years ago
TESTSTATS gStats = { 0, 0, 0, 0, 0, 0, 0 };
9 years ago
void UpdateStats( CBasePlayer *pPlayer )
{
int i;
8 years ago
int ammoCount[MAX_AMMO_SLOTS];
9 years ago
memcpy( ammoCount, pPlayer->m_rgAmmo, MAX_AMMO_SLOTS * sizeof(int) );
// Keep a running time, so the graph doesn't overlap
8 years ago
if( gpGlobals->time < gStats.lastGameTime ) // Changed level or died, don't b0rk
9 years ago
{
gStats.lastGameTime = gpGlobals->time;
gStats.dataTime = gStats.gameTime;
}
gStats.gameTime += gpGlobals->time - gStats.lastGameTime;
gStats.lastGameTime = gpGlobals->time;
8 years ago
for( i = 0; i < MAX_ITEM_TYPES; i++ )
9 years ago
{
CBasePlayerItem *p = pPlayer->m_rgpPlayerItems[i];
8 years ago
while( p )
9 years ago
{
ItemInfo II = {0};
8 years ago
p->GetItemInfo( &II );
int index = pPlayer->GetAmmoIndex( II.pszAmmo1 );
if( index >= 0 )
ammoCount[index] += ( (CBasePlayerWeapon *)p )->m_iClip;
9 years ago
p = p->m_pNext;
}
}
float ammo = 0;
8 years ago
for( i = 1; i < MAX_AMMO_SLOTS; i++ )
9 years ago
{
ammo += ammoCount[i] * AmmoDamage( CBasePlayerItem::AmmoInfoArray[i].pszName );
}
float health = pPlayer->pev->health + pPlayer->pev->armorvalue * 2; // Armor is 2X health
float ammoDelta = fabs( ammo - gStats.lastAmmo );
float healthDelta = fabs( health - gStats.lastHealth );
int forceWrite = 0;
8 years ago
if( health <= 0 && gStats.lastHealth > 0 )
9 years ago
forceWrite = 1;
8 years ago
if( ( ammoDelta > AMMO_THRESHOLD || healthDelta > HEALTH_THRESHOLD ) && !forceWrite )
9 years ago
{
8 years ago
if( gStats.nextOutputTime == 0 )
9 years ago
gStats.dataTime = gStats.gameTime;
gStats.lastAmmo = ammo;
gStats.lastHealth = health;
gStats.nextOutputTime = gStats.gameTime + OUTPUT_LATENCY;
}
8 years ago
else if( ( gStats.nextOutputTime != 0 && gStats.nextOutputTime < gStats.gameTime ) || forceWrite )
9 years ago
{
UpdateStatsFile( gStats.dataTime, STRING( gpGlobals->mapname ), health, ammo, (int)CVAR_GET_FLOAT( "skill" ) );
9 years ago
gStats.lastAmmo = ammo;
gStats.lastHealth = health;
gStats.lastOutputTime = gStats.gameTime;
gStats.nextOutputTime = 0;
}
}
void InitStats( CBasePlayer *pPlayer )
{
gStats.lastGameTime = gpGlobals->time; // Fixup stats time
}