hlsdk-xash3d/cl_dll/geiger.cpp

184 lines
3.4 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.
*
****/
//
// 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"
2016-07-03 15:39:55 +02:00
DECLARE_MESSAGE( m_Geiger, Geiger )
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
int CHudGeiger::Init( void )
2016-06-04 15:24:23 +02:00
{
HOOK_MESSAGE( Geiger );
m_iGeigerRange = 0;
m_iFlags = 0;
2016-07-03 15:39:55 +02:00
gHUD.AddHudElem( this );
2016-06-04 15:24:23 +02:00
srand( (unsigned)time( NULL ) );
return 1;
}
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
int CHudGeiger::VidInit( void )
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 CHudGeiger::MsgFunc_Geiger( const char *pszName, int iSize, void *pbuf )
2016-06-04 15:24:23 +02:00
{
BEGIN_READ( pbuf, iSize );
// update geiger data
m_iGeigerRange = READ_BYTE();
m_iGeigerRange = m_iGeigerRange << 2;
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
m_iFlags |= HUD_ACTIVE;
return 1;
}
2016-07-03 15:39:55 +02:00
int CHudGeiger::Draw( float flTime )
2016-06-04 15:24:23 +02:00
{
int pct;
float flvol = 0.0f;
2017-06-29 15:56:03 +02:00
//int rg[3];
2016-06-04 15:24:23 +02:00
int i;
2016-07-03 15:39:55 +02:00
if( m_iGeigerRange < 1000 && m_iGeigerRange > 0 )
2016-06-04 15:24:23 +02:00
{
// peicewise linear is better than continuous formula for this
2016-07-03 15:39:55 +02:00
if( m_iGeigerRange > 800 )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
pct = 0; //Con_Printf( "range > 800\n" );
2016-06-04 15:24:23 +02:00
}
2016-07-03 15:39:55 +02:00
else if( m_iGeigerRange > 600 )
2016-06-04 15:24:23 +02:00
{
pct = 2;
2016-07-03 15:39:55 +02:00
flvol = 0.4; //Con_Printf( "range > 600\n" );
2017-06-29 15:56:03 +02:00
//rg[0] = 1;
//rg[1] = 1;
2016-06-04 15:24:23 +02:00
i = 2;
}
2016-07-03 15:39:55 +02:00
else if( m_iGeigerRange > 500 )
2016-06-04 15:24:23 +02:00
{
pct = 4;
2016-07-03 15:39:55 +02:00
flvol = 0.5; //Con_Printf( "range > 500\n" );
2017-06-29 15:56:03 +02:00
//rg[0] = 1;
//rg[1] = 2;
2016-06-04 15:24:23 +02:00
i = 2;
}
2016-07-03 15:39:55 +02:00
else if( m_iGeigerRange > 400 )
2016-06-04 15:24:23 +02:00
{
pct = 8;
2016-07-03 15:39:55 +02:00
flvol = 0.6; //Con_Printf( "range > 400\n" );
2017-06-29 15:56:03 +02:00
//rg[0] = 1;
//rg[1] = 2;
//rg[2] = 3;
2016-06-04 15:24:23 +02:00
i = 3;
}
2016-07-03 15:39:55 +02:00
else if( m_iGeigerRange > 300 )
2016-06-04 15:24:23 +02:00
{
pct = 8;
2016-07-03 15:39:55 +02:00
flvol = 0.7; //Con_Printf( "range > 300\n" );
2017-06-29 15:56:03 +02:00
//rg[0] = 2;
//rg[1] = 3;
//rg[2] = 4;
2016-06-04 15:24:23 +02:00
i = 3;
}
2016-07-03 15:39:55 +02:00
else if( m_iGeigerRange > 200 )
2016-06-04 15:24:23 +02:00
{
pct = 28;
2016-07-03 15:39:55 +02:00
flvol = 0.78; //Con_Printf( "range > 200\n" );
2017-06-29 15:56:03 +02:00
//rg[0] = 2;
//rg[1] = 3;
//rg[2] = 4;
2016-06-04 15:24:23 +02:00
i = 3;
}
2016-07-03 15:39:55 +02:00
else if( m_iGeigerRange > 150 )
2016-06-04 15:24:23 +02:00
{
pct = 40;
2016-07-03 15:39:55 +02:00
flvol = 0.80; //Con_Printf( "range > 150\n" );
2017-06-29 15:56:03 +02:00
//rg[0] = 3;
//rg[1] = 4;
//rg[2] = 5;
2016-06-04 15:24:23 +02:00
i = 3;
}
2016-07-03 15:39:55 +02:00
else if( m_iGeigerRange > 100 )
2016-06-04 15:24:23 +02:00
{
pct = 60;
2016-07-03 15:39:55 +02:00
flvol = 0.85; //Con_Printf( "range > 100\n" );
2017-06-29 15:56:03 +02:00
//rg[0] = 3;
//rg[1] = 4;
//rg[2] = 5;
2016-06-04 15:24:23 +02:00
i = 3;
}
2016-07-03 15:39:55 +02:00
else if( m_iGeigerRange > 75 )
2016-06-04 15:24:23 +02:00
{
pct = 80;
2016-07-03 15:39:55 +02:00
flvol = 0.9; //Con_Printf( "range > 75\n" );
2016-06-04 15:24:23 +02:00
//gflGeigerDelay = cl.time + GEIGERDELAY * 0.75;
2017-06-29 15:56:03 +02:00
//rg[0] = 4;
//rg[1] = 5;
//rg[2] = 6;
2016-06-04 15:24:23 +02:00
i = 3;
}
2016-07-03 15:39:55 +02:00
else if( m_iGeigerRange > 50 )
2016-06-04 15:24:23 +02:00
{
pct = 90;
2016-07-03 15:39:55 +02:00
flvol = 0.95; //Con_Printf( "range > 50\n" );
2017-06-29 15:56:03 +02:00
//rg[0] = 5;
//rg[1] = 6;
2016-06-04 15:24:23 +02:00
i = 2;
}
else
{
pct = 95;
2016-07-03 15:39:55 +02:00
flvol = 1.0; //Con_Printf( "range < 50\n" );
2017-06-29 15:56:03 +02:00
//rg[0] = 5;
//rg[1] = 6;
2016-06-04 15:24:23 +02:00
i = 2;
}
2017-06-29 15:56:03 +02:00
flvol = ( flvol * ( ( rand() & 127 ) ) / 255 ) + 0.25; // UTIL_RandomFloat( 0.25, 0.5 );
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
if( ( rand() & 127 ) < pct || ( rand() & 127 ) < pct )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
//S_StartDynamicSound( -1, 0, rgsfx[rand() % i], r_origin, flvol, 1.0, 0, 100 );
2016-06-04 15:24:23 +02:00
char sz[256];
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
int j = rand() & 1;
2016-07-03 15:39:55 +02:00
if( i > 2 )
2016-06-04 15:24:23 +02:00
j += rand() & 1;
2016-07-03 15:39:55 +02:00
sprintf( sz, "player/geiger%d.wav", j + 1 );
PlaySound( sz, flvol );
2016-06-04 15:24:23 +02:00
}
}
return 1;
}