hlsdk-xash3d/cl_dll/overview.cpp

162 lines
4.5 KiB
C++
Raw Normal View History

2018-01-19 18:00:32 +01:00
//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ============
2016-06-04 15:24:23 +02:00
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "hud.h"
#include "cl_util.h"
#include "cl_entity.h"
#include "triangleapi.h"
2016-02-24 22:26:16 +01:00
#include "overview.h"
2016-06-04 15:24:23 +02:00
// these are included for the math functions
#include "com_model.h"
#include "studio_util.h"
#pragma warning(disable: 4244)
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CHudOverview::Init()
{
gHUD.AddHudElem(this);
m_iFlags |= HUD_ACTIVE;
return 1;
}
//-----------------------------------------------------------------------------
// Purpose: Loads new icons
//-----------------------------------------------------------------------------
int CHudOverview::VidInit()
{
2016-07-03 15:39:55 +02:00
m_hsprPlayer = gEngfuncs.pfnSPR_Load( "sprites/ring.spr" );
m_hsprViewcone = gEngfuncs.pfnSPR_Load( "sprites/camera.spr" );
2016-06-04 15:24:23 +02:00
return 1;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : flTime -
// intermission -
//-----------------------------------------------------------------------------
2016-07-03 15:39:55 +02:00
int CHudOverview::Draw( float flTime )
2016-06-04 15:24:23 +02:00
{
2016-02-24 22:26:16 +01:00
#if 0
2016-06-04 15:24:23 +02:00
// only draw in overview mode
2016-07-03 15:39:55 +02:00
if( !gEngfuncs.Overview_GetOverviewState() )
2016-06-04 15:24:23 +02:00
return 1;
// make sure we have player info
2016-07-03 15:39:55 +02:00
//gViewPort->GetAllPlayersInfo();
2016-02-24 22:26:16 +01:00
gHUD.m_Scoreboard.GetAllPlayersInfo();
2016-06-04 15:24:23 +02:00
// calculate player size on the overview
int x1, y1, x2, y2;
2016-07-03 15:39:55 +02:00
float v0[3] = { 0.0f }, v1[3] = { 64.0f, 64.0f };
gEngfuncs.Overview_WorldToScreen( v0, &x1, &y1 );
gEngfuncs.Overview_WorldToScreen( v1, &x2, &y2 );
float scale = abs( x2 - x1 );
2016-06-04 15:24:23 +02:00
// loop through all the players and draw them on the map
2016-07-03 15:39:55 +02:00
for( int i = 1; i < MAX_PLAYERS; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
cl_entity_t *pl = gEngfuncs.GetEntityByIndex( i );
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
if( pl && pl->player && pl->curstate.health > 0 && pl->curstate.solid != SOLID_NOT )
2016-06-04 15:24:23 +02:00
{
int x, y, z = 0;
2016-07-03 15:39:55 +02:00
float v[3] = { pl->origin[0], pl->origin[1], 0 };
gEngfuncs.Overview_WorldToScreen( v, &x, &y );
2016-06-04 15:24:23 +02:00
// hack in some team colors
float r, g, bc;
2016-07-03 15:39:55 +02:00
if( g_PlayerExtraInfo[i].teamnumber == 1 )
2016-06-04 15:24:23 +02:00
{
r = 0.0f; g = 0.0f; bc = 1.0f;
}
2016-07-03 15:39:55 +02:00
else if( g_PlayerExtraInfo[i].teamnumber == 2 )
2016-06-04 15:24:23 +02:00
{
r = 1.0f; g = 0.0f; bc = 0.0f;
}
else
{
// just use the default orange color if the team isn't set
r = 1.0f; g = 0.7f; bc = 0.0f;
}
// set the current texture
2016-07-03 15:39:55 +02:00
gEngfuncs.pTriAPI->SpriteTexture( (struct model_s *)gEngfuncs.GetSpritePointer( m_hsprPlayer ), 0 );
2016-06-04 15:24:23 +02:00
// additive render mode
2016-07-03 15:39:55 +02:00
gEngfuncs.pTriAPI->RenderMode( kRenderTransAdd );
2016-06-04 15:24:23 +02:00
// no culling
2016-07-03 15:39:55 +02:00
gEngfuncs.pTriAPI->CullFace( TRI_NONE );
2016-06-04 15:24:23 +02:00
// draw a square
2016-07-03 15:39:55 +02:00
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
2016-06-04 15:24:23 +02:00
// set the color to be that of the team
2016-07-03 15:39:55 +02:00
gEngfuncs.pTriAPI->Color4f( r, g, bc, 1.0f );
2016-06-04 15:24:23 +02:00
// calculate rotational matrix
vec3_t a, b, angles;
float rmatrix[3][4]; // transformation matrix
2016-07-03 15:39:55 +02:00
VectorCopy( pl->angles, angles );
2016-06-04 15:24:23 +02:00
angles[0] = 0.0f;
angles[1] += 90.f;
angles[1] = -angles[1];
angles[2] = 0.0f;
2016-07-03 15:39:55 +02:00
AngleMatrix( angles, rmatrix );
2016-06-04 15:24:23 +02:00
a[2] = 0;
a[0] = -scale; a[1] = -scale;
2016-07-03 15:39:55 +02:00
VectorTransform( a, rmatrix, b );
2016-06-04 15:24:23 +02:00
gEngfuncs.pTriAPI->TexCoord2f( 0, 0 );
2016-07-03 15:39:55 +02:00
gEngfuncs.pTriAPI->Vertex3f( x + b[0], y + b[1], z );
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
a[0] = -scale; a[1] = scale;
VectorTransform( a, rmatrix, b );
2016-06-04 15:24:23 +02:00
gEngfuncs.pTriAPI->TexCoord2f( 0, 1 );
2016-07-03 15:39:55 +02:00
gEngfuncs.pTriAPI->Vertex3f( x + b[0], y + b[1], z );
a[0] = scale; a[1] = scale;
VectorTransform( a, rmatrix, b );
2016-06-04 15:24:23 +02:00
gEngfuncs.pTriAPI->TexCoord2f( 1, 1 );
2016-07-03 15:39:55 +02:00
gEngfuncs.pTriAPI->Vertex3f( x + b[0], y + b[1], z );
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
a[0] = scale; a[1] = -scale;
VectorTransform( a, rmatrix, b );
2016-06-04 15:24:23 +02:00
gEngfuncs.pTriAPI->TexCoord2f( 1, 0 );
2016-07-03 15:39:55 +02:00
gEngfuncs.pTriAPI->Vertex3f( x + b[0], y + b[1], z );
2016-06-04 15:24:23 +02:00
// finish up
gEngfuncs.pTriAPI->End();
gEngfuncs.pTriAPI->RenderMode( kRenderNormal );
// draw the players name and health underneath
char string[256];
2016-07-03 15:39:55 +02:00
sprintf( string, "%s (%i%%)", g_PlayerInfoList[i].name, pl->curstate.health );
DrawConsoleString( x, y + ( 1.1 * scale ), string );
2016-06-04 15:24:23 +02:00
}
}
2016-02-24 22:26:16 +01:00
#endif
2016-06-04 15:24:23 +02:00
return 1;
}
//-----------------------------------------------------------------------------
// Purpose: called every time a server is connected to
//-----------------------------------------------------------------------------
void CHudOverview::InitHUDData()
{
2016-07-03 15:39:55 +02:00
//this block would force the spectator view to be on
//gEngfuncs.Overview_SetDrawOverview( 1 );
//gEngfuncs.Overview_SetDrawInset( 0 );
2016-06-04 15:24:23 +02:00
}