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.

188 lines
3.7 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.
*
****/
//
// Geiger.cpp
//
// implementation of CHudAmmo class
//
#include "hud.h"
#include "cl_util.h"
#include <string.h>
#include <time.h>
#include <stdio.h>
#include "parsemsg.h"
#include "event_api.h"
9 years ago
9 years ago
DECLARE_MESSAGE( m_Geiger, Geiger )
9 years ago
9 years ago
int CHudGeiger::Init( void )
9 years ago
{
HOOK_MESSAGE( Geiger );
m_iGeigerRange = 0;
m_iFlags = 0;
9 years ago
gHUD.AddHudElem( this );
9 years ago
srand( (unsigned)time( NULL ) );
return 1;
}
9 years ago
9 years ago
int CHudGeiger::VidInit( void )
9 years ago
{
return 1;
}
9 years ago
9 years ago
int CHudGeiger::MsgFunc_Geiger( const char *pszName, int iSize, void *pbuf )
9 years ago
{
BEGIN_READ( pbuf, iSize );
// update geiger data
m_iGeigerRange = READ_BYTE();
m_iGeigerRange = m_iGeigerRange << 2;
9 years ago
9 years ago
m_iFlags |= HUD_ACTIVE;
return 1;
}
9 years ago
int CHudGeiger::Draw( float flTime )
9 years ago
{
int pct;
float flvol = 0.0f;
//int rg[3];
int i = 0;
9 years ago
if( m_iGeigerRange < 1000 && m_iGeigerRange > 0 )
9 years ago
{
// peicewise linear is better than continuous formula for this
9 years ago
if( m_iGeigerRange > 800 )
9 years ago
{
9 years ago
pct = 0; //Con_Printf( "range > 800\n" );
9 years ago
}
9 years ago
else if( m_iGeigerRange > 600 )
9 years ago
{
pct = 2;
flvol = 0.4f; //Con_Printf( "range > 600\n" );
//rg[0] = 1;
//rg[1] = 1;
9 years ago
i = 2;
}
9 years ago
else if( m_iGeigerRange > 500 )
9 years ago
{
pct = 4;
flvol = 0.5f; //Con_Printf( "range > 500\n" );
//rg[0] = 1;
//rg[1] = 2;
9 years ago
i = 2;
}
9 years ago
else if( m_iGeigerRange > 400 )
9 years ago
{
pct = 8;
flvol = 0.6f; //Con_Printf( "range > 400\n" );
//rg[0] = 1;
//rg[1] = 2;
//rg[2] = 3;
9 years ago
i = 3;
}
9 years ago
else if( m_iGeigerRange > 300 )
9 years ago
{
pct = 8;
flvol = 0.7f; //Con_Printf( "range > 300\n" );
//rg[0] = 2;
//rg[1] = 3;
//rg[2] = 4;
9 years ago
i = 3;
}
9 years ago
else if( m_iGeigerRange > 200 )
9 years ago
{
pct = 28;
flvol = 0.78f; //Con_Printf( "range > 200\n" );
//rg[0] = 2;
//rg[1] = 3;
//rg[2] = 4;
9 years ago
i = 3;
}
9 years ago
else if( m_iGeigerRange > 150 )
9 years ago
{
pct = 40;
flvol = 0.80f; //Con_Printf( "range > 150\n" );
//rg[0] = 3;
//rg[1] = 4;
//rg[2] = 5;
9 years ago
i = 3;
}
9 years ago
else if( m_iGeigerRange > 100 )
9 years ago
{
pct = 60;
9 years ago
flvol = 0.85; //Con_Printf( "range > 100\n" );
//rg[0] = 3;
//rg[1] = 4;
//rg[2] = 5;
9 years ago
i = 3;
}
9 years ago
else if( m_iGeigerRange > 75 )
9 years ago
{
pct = 80;
flvol = 0.9f; //Con_Printf( "range > 75\n" );
9 years ago
//gflGeigerDelay = cl.time + GEIGERDELAY * 0.75;
//rg[0] = 4;
//rg[1] = 5;
//rg[2] = 6;
9 years ago
i = 3;
}
9 years ago
else if( m_iGeigerRange > 50 )
9 years ago
{
pct = 90;
flvol = 0.95f; //Con_Printf( "range > 50\n" );
//rg[0] = 5;
//rg[1] = 6;
9 years ago
i = 2;
}
else
{
pct = 95;
flvol = 1.0f; //Con_Printf( "range < 50\n" );
//rg[0] = 5;
//rg[1] = 6;
9 years ago
i = 2;
}
flvol = ( flvol * ( ( rand() & 127 ) ) / 255 ) + 0.25f; // UTIL_RandomFloat( 0.25f, 0.5f );
9 years ago
9 years ago
if( ( rand() & 127 ) < pct || ( rand() & 127 ) < pct )
9 years ago
{
//S_StartDynamicSound( -1, 0, rgsfx[rand() % i], r_origin, flvol, 1.0f, 0, 100 );
9 years ago
char sz[256];
9 years ago
9 years ago
int j = rand() & 1;
9 years ago
if( i > 2 )
9 years ago
j += rand() & 1;
9 years ago
sprintf( sz, "player/geiger%d.wav", j + 1 );
vec3_t view_ofs;
cl_entity_t *pthisplayer = gEngfuncs.GetLocalPlayer();
gEngfuncs.pEventAPI->EV_LocalPlayerViewheight( view_ofs );
gEngfuncs.pEventAPI->EV_PlaySound( pthisplayer->index, pthisplayer->origin + view_ofs, CHAN_STATIC, sz, flvol, ATTN_NORM, 0, PITCH_NORM );
9 years ago
}
}
return 1;
}