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.

1531 lines
39 KiB

//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ============
9 years ago
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "hud.h"
#include "cl_util.h"
#include "cl_entity.h"
#include "triangleapi.h"
#include "hltv.h"
#include "pm_shared.h"
#include "pm_defs.h"
#include "pmtrace.h"
#include "parsemsg.h"
#include "entity_types.h"
// these are included for the math functions
#include "com_model.h"
#include "demo_api.h"
#include "event_api.h"
#include "studio_util.h"
#include "screenfade.h"
#pragma warning(disable: 4244)
extern "C" int iJumpSpectator;
extern "C" float vJumpOrigin[3];
extern "C" float vJumpAngles[3];
9 years ago
extern void V_GetInEyePos( int entity, float * origin, float * angles );
9 years ago
extern void V_ResetChaseCam();
9 years ago
extern void V_GetChasePos( int target, float * cl_angles, float * origin, float * angles );
9 years ago
extern void VectorAngles( const float *forward, float *angles );
extern "C" void NormalizeAngles( float *angles );
extern float * GetClientColor( int clientIndex );
extern vec3_t v_origin; // last view origin
extern vec3_t v_angles; // last view angle
extern vec3_t v_cl_angles; // last client/mouse angle
extern vec3_t v_sim_org; // last sim origin
9 years ago
void SpectatorMode( void )
9 years ago
{
9 years ago
if( gEngfuncs.Cmd_Argc() <= 1 )
9 years ago
{
gEngfuncs.Con_Printf( "usage: spec_mode <Main Mode> [<Inset Mode>]\n" );
return;
}
// SetModes() will decide if command is executed on server or local
9 years ago
if( gEngfuncs.Cmd_Argc() == 2 )
gHUD.m_Spectator.SetModes( atoi( gEngfuncs.Cmd_Argv( 1 ) ), -1 );
9 years ago
else if ( gEngfuncs.Cmd_Argc() == 3 )
9 years ago
gHUD.m_Spectator.SetModes( atoi( gEngfuncs.Cmd_Argv( 1 ) ), atoi( gEngfuncs.Cmd_Argv( 2 ) ) );
9 years ago
}
9 years ago
void SpectatorSpray( void )
9 years ago
{
vec3_t forward;
char string[128];
9 years ago
if( !gEngfuncs.IsSpectateOnly() )
9 years ago
return;
9 years ago
AngleVectors( v_angles, forward, NULL, NULL );
VectorScale( forward, 128, forward );
VectorAdd( forward, v_origin, forward );
9 years ago
pmtrace_t * trace = gEngfuncs.PM_TraceLine( v_origin, forward, PM_TRACELINE_PHYSENTSONLY, 2, -1 );
if( trace->fraction != 1.0f )
9 years ago
{
9 years ago
sprintf( string, "drc_spray %.2f %.2f %.2f %i",
(double)trace->endpos[0], (double)trace->endpos[1], (double)trace->endpos[2], trace->ent );
9 years ago
gEngfuncs.pfnServerCmd( string );
9 years ago
}
}
9 years ago
void SpectatorHelp( void )
9 years ago
{
{
char *text = CHudTextMessage::BufferedLocaliseTextString( "#Spec_Help_Text" );
9 years ago
if( text )
9 years ago
{
9 years ago
while( *text )
9 years ago
{
9 years ago
if( *text != 13 )
9 years ago
gEngfuncs.Con_Printf( "%c", *text );
text++;
}
}
}
}
void SpectatorMenu( void )
{
9 years ago
if( gEngfuncs.Cmd_Argc() <= 1 )
9 years ago
{
gEngfuncs.Con_Printf( "usage: spec_menu <0|1>\n" );
return;
}
}
void ToggleScores( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CHudSpectator::Init()
{
9 years ago
gHUD.AddHudElem( this );
9 years ago
m_iFlags |= HUD_ACTIVE;
m_flNextObserverInput = 0.0f;
9 years ago
m_zoomDelta = 0.0f;
9 years ago
m_moveDelta = 0.0f;
9 years ago
m_chatEnabled = ( gHUD.m_SayText.m_HUD_saytext->value != 0 );
iJumpSpectator = 0;
9 years ago
9 years ago
memset( &m_OverviewData, 0, sizeof(m_OverviewData) );
memset( &m_OverviewEntities, 0, sizeof(m_OverviewEntities) );
9 years ago
m_lastPrimaryObject = m_lastSecondaryObject = 0;
9 years ago
gEngfuncs.pfnAddCommand( "spec_mode", SpectatorMode );
gEngfuncs.pfnAddCommand( "spec_decal", SpectatorSpray );
gEngfuncs.pfnAddCommand( "spec_help", SpectatorHelp );
gEngfuncs.pfnAddCommand( "spec_menu", SpectatorMenu );
gEngfuncs.pfnAddCommand( "togglescores", ToggleScores );
m_drawnames = gEngfuncs.pfnRegisterVariable( "spec_drawnames", "1", 0 );
m_drawcone = gEngfuncs.pfnRegisterVariable( "spec_drawcone", "1", 0 );
m_drawstatus = gEngfuncs.pfnRegisterVariable( "spec_drawstatus", "1", 0 );
m_autoDirector = gEngfuncs.pfnRegisterVariable( "spec_autodirector", "1", 0 );
m_pip = gEngfuncs.pfnRegisterVariable( "spec_pip", "1", 0 );
9 years ago
9 years ago
if( !m_drawnames || !m_drawcone || !m_drawstatus || !m_autoDirector || !m_pip )
9 years ago
{
9 years ago
gEngfuncs.Con_Printf( "ERROR! Couldn't register all spectator variables.\n" );
9 years ago
return 0;
}
return 1;
}
//-----------------------------------------------------------------------------
// UTIL_StringToVector originally from ..\dlls\util.cpp, slightly changed
//-----------------------------------------------------------------------------
void UTIL_StringToVector( float * pVector, const char *pString )
{
char *pstr, *pfront, tempString[128];
int j;
strcpy( tempString, pString );
pstr = pfront = tempString;
9 years ago
for( j = 0; j < 3; j++ )
9 years ago
{
pVector[j] = atof( pfront );
9 years ago
while( *pstr && *pstr != ' ' )
9 years ago
pstr++;
9 years ago
if( !( *pstr ) )
9 years ago
break;
pstr++;
pfront = pstr;
}
9 years ago
if( j < 2 )
9 years ago
{
9 years ago
for( j = j + 1;j < 3; j++ )
9 years ago
pVector[j] = 0;
}
}
int UTIL_FindEntityInMap( const char *name, float *origin, float *angle )
9 years ago
{
9 years ago
int n, found = 0;
9 years ago
char keyname[256];
char token[2048];
cl_entity_t *pEnt = gEngfuncs.GetEntityByIndex( 0 ); // get world model
9 years ago
9 years ago
if( !pEnt )
return 0;
9 years ago
9 years ago
if( !pEnt->model )
return 0;
9 years ago
char *data = pEnt->model->entities;
9 years ago
9 years ago
while( data )
9 years ago
{
9 years ago
data = gEngfuncs.COM_ParseFile( data, token );
if( ( token[0] == '}' ) || ( token[0] == 0 ) )
9 years ago
break;
9 years ago
if( !data )
9 years ago
{
9 years ago
gEngfuncs.Con_DPrintf( "UTIL_FindEntityInMap: EOF without closing brace\n" );
9 years ago
return 0;
}
9 years ago
if( token[0] != '{' )
9 years ago
{
9 years ago
gEngfuncs.Con_DPrintf( "UTIL_FindEntityInMap: expected {\n" );
9 years ago
return 0;
}
9 years ago
// we parse the first { now parse entities properties
while( 1 )
9 years ago
{
// parse key
9 years ago
data = gEngfuncs.COM_ParseFile( data, token );
if( token[0] == '}' )
9 years ago
break; // finish parsing this entity
9 years ago
if( !data )
{
gEngfuncs.Con_DPrintf( "UTIL_FindEntityInMap: EOF without closing brace\n" );
9 years ago
return 0;
9 years ago
}
strcpy( keyname, token );
9 years ago
// another hack to fix keynames with trailing spaces
9 years ago
n = strlen( keyname );
while( n && keyname[n - 1] == ' ' )
9 years ago
{
9 years ago
keyname[n - 1] = 0;
9 years ago
n--;
}
9 years ago
9 years ago
// parse value
9 years ago
data = gEngfuncs.COM_ParseFile( data, token );
if( !data )
{
gEngfuncs.Con_DPrintf( "UTIL_FindEntityInMap: EOF without closing brace\n" );
9 years ago
return 0;
9 years ago
}
9 years ago
9 years ago
if( token[0] == '}' )
9 years ago
{
9 years ago
gEngfuncs.Con_DPrintf( "UTIL_FindEntityInMap: closing brace without data" );
9 years ago
return 0;
}
9 years ago
if( !strcmp( keyname, "classname" ) )
9 years ago
{
9 years ago
if( !strcmp( token, name ) )
9 years ago
{
found = 1; // thats our entity
}
9 years ago
}
9 years ago
if( !strcmp( keyname, "angle" ) )
{
float y = atof( token );
9 years ago
if( y >= 0 )
9 years ago
{
angle[0] = 0.0f;
angle[1] = y;
}
9 years ago
else if( (int)y == -1 )
9 years ago
{
angle[0] = -90.0f;
9 years ago
angle[1] = 0.0f;;
9 years ago
}
else
{
angle[0] = 90.0f;
9 years ago
angle[1] = 0.0f;
9 years ago
}
9 years ago
angle[2] = 0.0f;
9 years ago
}
if( !strcmp( keyname, "angles" ) )
{
9 years ago
UTIL_StringToVector( angle, token );
9 years ago
}
9 years ago
if( !strcmp( keyname, "origin" ) )
{
UTIL_StringToVector( origin, token );
}
9 years ago
} // while (1)
9 years ago
if( found )
9 years ago
return 1;
}
return 0; // we search all entities, but didn't found the correct
}
//-----------------------------------------------------------------------------
// SetSpectatorStartPosition():
// Get valid map position and 'beam' spectator to this position
//-----------------------------------------------------------------------------
void CHudSpectator::SetSpectatorStartPosition()
{
// search for info_player start
9 years ago
if( UTIL_FindEntityInMap( "trigger_camera", m_cameraOrigin, m_cameraAngles ) )
9 years ago
iJumpSpectator = 1;
9 years ago
else if( UTIL_FindEntityInMap( "info_player_start", m_cameraOrigin, m_cameraAngles ) )
9 years ago
iJumpSpectator = 1;
9 years ago
else if( UTIL_FindEntityInMap( "info_player_deathmatch", m_cameraOrigin, m_cameraAngles ) )
9 years ago
iJumpSpectator = 1;
9 years ago
else if( UTIL_FindEntityInMap( "info_player_coop", m_cameraOrigin, m_cameraAngles ) )
9 years ago
iJumpSpectator = 1;
else
{
// jump to 0,0,0 if no better position was found
9 years ago
VectorCopy( vec3_origin, m_cameraOrigin );
VectorCopy( vec3_origin, m_cameraAngles );
9 years ago
}
9 years ago
VectorCopy( m_cameraOrigin, vJumpOrigin );
VectorCopy( m_cameraAngles, vJumpAngles );
9 years ago
iJumpSpectator = 1; // jump anyway
}
//-----------------------------------------------------------------------------
// Purpose: Loads new icons
//-----------------------------------------------------------------------------
int CHudSpectator::VidInit()
{
9 years ago
m_hsprPlayer = SPR_Load( "sprites/iplayer.spr" );
m_hsprPlayerBlue = SPR_Load( "sprites/iplayerblue.spr" );
m_hsprPlayerRed = SPR_Load( "sprites/iplayerred.spr" );
m_hsprPlayerDead = SPR_Load( "sprites/iplayerdead.spr" );
m_hsprUnkownMap = SPR_Load( "sprites/tile.spr" );
m_hsprBeam = SPR_Load( "sprites/laserbeam.spr" );
m_hsprCamera = SPR_Load( "sprites/camera.spr" );
m_hCrosshair = SPR_Load( "sprites/crosshairs.spr" );
9 years ago
return 1;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : flTime -
// intermission -
//-----------------------------------------------------------------------------
9 years ago
int CHudSpectator::Draw( float flTime )
9 years ago
{
int lx;
char string[256];
float *color;
9 years ago
// draw only in spectator mode
9 years ago
if( !g_iUser1 )
9 years ago
return 0;
// if user pressed zoom, aplly changes
9 years ago
if( ( m_zoomDelta != 0.0f ) && ( g_iUser1 == OBS_MAP_FREE ) )
9 years ago
{
m_mapZoom += m_zoomDelta;
9 years ago
if( m_mapZoom > 3.0f )
9 years ago
m_mapZoom = 3.0f;
9 years ago
if( m_mapZoom < 0.5f )
9 years ago
m_mapZoom = 0.5f;
}
// if user moves in map mode, change map origin
9 years ago
if( ( m_moveDelta != 0.0f ) && ( g_iUser1 != OBS_ROAMING ) )
9 years ago
{
9 years ago
vec3_t right;
AngleVectors( v_angles, NULL, right, NULL );
VectorNormalize( right );
VectorScale( right, m_moveDelta, right );
9 years ago
VectorAdd( m_mapOrigin, right, m_mapOrigin )
}
9 years ago
9 years ago
// Only draw the icon names only if map mode is in Main Mode
9 years ago
if( g_iUser1 < OBS_MAP_FREE )
9 years ago
return 1;
9 years ago
if( !m_drawnames->value )
9 years ago
return 1;
9 years ago
9 years ago
// make sure we have player info
//gViewPort->GetAllPlayersInfo();
gHUD.m_Scoreboard.GetAllPlayersInfo();
// loop through all the players and draw additional infos to their sprites on the map
9 years ago
for( int i = 0; i < MAX_PLAYERS; i++ )
9 years ago
{
9 years ago
if( m_vPlayerPos[i][2] < 0 ) // marked as invisible ?
9 years ago
continue;
9 years ago
9 years ago
// check if name would be in inset window
9 years ago
if( m_pip->value != INSET_OFF )
9 years ago
{
9 years ago
if( m_vPlayerPos[i][0] > XRES( m_OverviewData.insetWindowX ) &&
9 years ago
m_vPlayerPos[i][1] > YRES( m_OverviewData.insetWindowY ) &&
m_vPlayerPos[i][0] < XRES( m_OverviewData.insetWindowX + m_OverviewData.insetWindowWidth ) &&
9 years ago
m_vPlayerPos[i][1] < YRES( m_OverviewData.insetWindowY + m_OverviewData.insetWindowHeight) )
continue;
9 years ago
}
9 years ago
color = GetClientColor( i + 1 );
9 years ago
// draw the players name and health underneath
9 years ago
sprintf( string, "%s", g_PlayerInfoList[i + 1].name );
lx = strlen( string ) * 3; // 3 is avg. character length :)
9 years ago
DrawSetTextColor( color[0], color[1], color[2] );
9 years ago
DrawConsoleString( m_vPlayerPos[i][0] - lx,m_vPlayerPos[i][1], string );
9 years ago
}
return 1;
}
void CHudSpectator::DirectorMessage( int iSize, void *pbuf )
{
9 years ago
float value;
char *string;
9 years ago
BEGIN_READ( pbuf, iSize );
int cmd = READ_BYTE();
9 years ago
switch( cmd ) // director command byte
{
case DRC_CMD_START:
// now we have to do some things clientside, since the proxy doesn't know our mod
g_iPlayerClass = 0;
g_iTeamNumber = 0;
// fake a InitHUD & ResetHUD message
gHUD.MsgFunc_InitHUD( NULL, 0, NULL );
gHUD.MsgFunc_ResetHUD( NULL, 0, NULL );
break;
case DRC_CMD_EVENT:
m_lastPrimaryObject = READ_WORD();
m_lastSecondaryObject = READ_WORD();
m_iObserverFlags = READ_LONG();
9 years ago
9 years ago
if( m_autoDirector->value )
{
if( ( g_iUser2 != m_lastPrimaryObject) || ( g_iUser3 != m_lastSecondaryObject ) )
V_ResetChaseCam();
9 years ago
9 years ago
g_iUser2 = m_lastPrimaryObject;
g_iUser3 = m_lastSecondaryObject;
}
9 years ago
9 years ago
// gEngfuncs.Con_Printf( "Director Camera: %i %i\n", firstObject, secondObject );
break;
case DRC_CMD_MODE:
if( m_autoDirector->value )
{
SetModes( READ_BYTE(), -1 );
}
break;
case DRC_CMD_CAMERA:
if( m_autoDirector->value )
{
vJumpOrigin[0] = READ_COORD(); // position
vJumpOrigin[1] = READ_COORD();
vJumpOrigin[2] = READ_COORD();
9 years ago
9 years ago
vJumpAngles[0] = READ_COORD(); // view angle
vJumpAngles[1] = READ_COORD();
vJumpAngles[2] = READ_COORD();
9 years ago
9 years ago
gEngfuncs.SetViewAngles( vJumpAngles );
9 years ago
9 years ago
iJumpSpectator = 1;
}
break;
case DRC_CMD_MESSAGE:
{
client_textmessage_t * msg = &m_HUDMessages[m_lastHudMessage];
9 years ago
9 years ago
msg->effect = READ_BYTE(); // effect
9 years ago
9 years ago
UnpackRGB( (int&)msg->r1, (int&)msg->g1, (int&)msg->b1, READ_LONG() ); // color
msg->r2 = msg->r1;
msg->g2 = msg->g1;
msg->b2 = msg->b1;
msg->a2 = msg->a1 = 0xFF; // not transparent
9 years ago
9 years ago
msg->x = READ_FLOAT(); // x pos
msg->y = READ_FLOAT(); // y pos
msg->fadein = READ_FLOAT(); // fadein
msg->fadeout = READ_FLOAT(); // fadeout
msg->holdtime = READ_FLOAT(); // holdtime
msg->fxtime = READ_FLOAT(); // fxtime;
9 years ago
9 years ago
strncpy( m_HUDMessageText[m_lastHudMessage], READ_STRING(), 128 );
m_HUDMessageText[m_lastHudMessage][127] = 0; // text
9 years ago
9 years ago
msg->pMessage = m_HUDMessageText[m_lastHudMessage];
msg->pName = "HUD_MESSAGE";
9 years ago
9 years ago
gHUD.m_Message.MessageAdd( msg );
9 years ago
9 years ago
m_lastHudMessage++;
m_lastHudMessage %= MAX_SPEC_HUD_MESSAGES;
}
break;
case DRC_CMD_SOUND:
string = READ_STRING();
value = READ_FLOAT();
9 years ago
9 years ago
// gEngfuncs.Con_Printf("DRC_CMD_FX_SOUND: %s %.2f\n", string, value );
gEngfuncs.pEventAPI->EV_PlaySound( 0, v_origin, CHAN_BODY, string, value, ATTN_NORM, 0, PITCH_NORM );
break;
case DRC_CMD_TIMESCALE:
value = READ_FLOAT();
break;
case DRC_CMD_STATUS:
READ_LONG(); // total number of spectator slots
m_iSpectatorNumber = READ_LONG(); // total number of spectator
READ_WORD(); // total number of relay proxies
break;
9 years ago
case DRC_CMD_BANNER:
9 years ago
// gEngfuncs.Con_DPrintf( "GUI: Banner %s\n",READ_STRING() ); // name of banner tga eg gfx/temp/7454562234563475.tga
break;
case DRC_CMD_FADE:
break;
9 years ago
case DRC_CMD_STUFFTEXT:
9 years ago
ClientCmd( READ_STRING() );
break;
default:
gEngfuncs.Con_DPrintf( "CHudSpectator::DirectorMessage: unknown command %i.\n", cmd );
9 years ago
}
}
9 years ago
void CHudSpectator::FindNextPlayer( bool bReverse )
9 years ago
{
// MOD AUTHORS: Modify the logic of this function if you want to restrict the observer to watching
// only a subset of the players. e.g. Make it check the target's team.
int iStart;
cl_entity_t * pEnt = NULL;
// if we are NOT in HLTV mode, spectator targets are set on server
9 years ago
if( !gEngfuncs.IsSpectateOnly() )
9 years ago
{
char cmdstring[32];
// forward command to server
9 years ago
sprintf( cmdstring, "follownext %i", bReverse ? 1 : 0 );
gEngfuncs.pfnServerCmd( cmdstring );
9 years ago
return;
}
9 years ago
if( g_iUser2 )
9 years ago
iStart = g_iUser2;
else
iStart = 1;
g_iUser2 = 0;
9 years ago
int iCurrent = iStart;
9 years ago
int iDir = bReverse ? -1 : 1;
// make sure we have player info
//gViewPort->GetAllPlayersInfo();
gHUD.m_Scoreboard.GetAllPlayersInfo();
do
{
iCurrent += iDir;
// Loop through the clients
9 years ago
if( iCurrent > MAX_PLAYERS )
9 years ago
iCurrent = 1;
9 years ago
if( iCurrent < 1 )
9 years ago
iCurrent = MAX_PLAYERS;
pEnt = gEngfuncs.GetEntityByIndex( iCurrent );
9 years ago
if( !IsActivePlayer( pEnt ) )
9 years ago
continue;
// MOD AUTHORS: Add checks on target here.
g_iUser2 = iCurrent;
break;
9 years ago
} while( iCurrent != iStart );
9 years ago
// Did we find a target?
9 years ago
if( !g_iUser2 )
9 years ago
{
gEngfuncs.Con_DPrintf( "No observer targets.\n" );
// take save camera position
9 years ago
VectorCopy( m_cameraOrigin, vJumpOrigin );
VectorCopy( m_cameraAngles, vJumpAngles );
9 years ago
}
else
{
// use new entity position for roaming
9 years ago
VectorCopy( pEnt->origin, vJumpOrigin );
VectorCopy( pEnt->angles, vJumpAngles );
9 years ago
}
iJumpSpectator = 1;
}
void CHudSpectator::HandleButtonsDown( int ButtonPressed )
{
double time = gEngfuncs.GetClientTime();
9 years ago
int newMainMode = g_iUser1;
int newInsetMode = m_pip->value;
9 years ago
9 years ago
// gEngfuncs.Con_Printf( " HandleButtons:%i\n", ButtonPressed );
9 years ago
//Not in intermission.
9 years ago
if( gHUD.m_iIntermission )
9 years ago
return;
9 years ago
if( !g_iUser1 )
9 years ago
return; // dont do anything if not in spectator mode
// don't handle buttons during normal demo playback
9 years ago
if( gEngfuncs.pDemoAPI->IsPlayingback() && !gEngfuncs.IsSpectateOnly() )
9 years ago
return;
// Slow down mouse clicks.
9 years ago
if( m_flNextObserverInput > time )
9 years ago
return;
// enable spectator screen
9 years ago
//if( ButtonPressed & IN_DUCK )
// gViewPort->m_pSpectatorPanel->ShowMenu( !gViewPort->m_pSpectatorPanel->m_menuVisible );
9 years ago
// 'Use' changes inset window mode
9 years ago
if( ButtonPressed & IN_USE )
9 years ago
{
9 years ago
newInsetMode = ToggleInset( true );
9 years ago
}
// if not in HLTV mode, buttons are handled server side
9 years ago
if( gEngfuncs.IsSpectateOnly() )
9 years ago
{
// changing target or chase mode not in overviewmode without inset window
// Jump changes main window modes
9 years ago
if( ButtonPressed & IN_JUMP )
9 years ago
{
9 years ago
if( g_iUser1 == OBS_CHASE_LOCKED )
9 years ago
newMainMode = OBS_CHASE_FREE;
9 years ago
else if( g_iUser1 == OBS_CHASE_FREE )
9 years ago
newMainMode = OBS_IN_EYE;
9 years ago
else if( g_iUser1 == OBS_IN_EYE )
9 years ago
newMainMode = OBS_ROAMING;
9 years ago
else if( g_iUser1 == OBS_ROAMING )
9 years ago
newMainMode = OBS_MAP_FREE;
9 years ago
else if( g_iUser1 == OBS_MAP_FREE )
9 years ago
newMainMode = OBS_MAP_CHASE;
else
newMainMode = OBS_CHASE_FREE; // don't use OBS_CHASE_LOCKED anymore
}
// Attack moves to the next player
9 years ago
if( ButtonPressed & ( IN_ATTACK | IN_ATTACK2 ) )
9 years ago
{
9 years ago
FindNextPlayer( ( ButtonPressed & IN_ATTACK2 ) ? true : false );
9 years ago
9 years ago
if( g_iUser1 == OBS_ROAMING )
9 years ago
{
gEngfuncs.SetViewAngles( vJumpAngles );
iJumpSpectator = 1;
}
// lease directed mode if player want to see another player
m_autoDirector->value = 0.0f;
}
}
9 years ago
SetModes( newMainMode, newInsetMode );
9 years ago
9 years ago
if( g_iUser1 == OBS_MAP_FREE )
9 years ago
{
9 years ago
if( ButtonPressed & IN_FORWARD )
m_zoomDelta = 0.01f;
9 years ago
9 years ago
if( ButtonPressed & IN_BACK )
9 years ago
m_zoomDelta = -0.01f;
9 years ago
if( ButtonPressed & IN_MOVELEFT )
9 years ago
m_moveDelta = -12.0f;
9 years ago
if( ButtonPressed & IN_MOVERIGHT )
m_moveDelta = 12.0f;
9 years ago
}
m_flNextObserverInput = time + 0.2;
}
void CHudSpectator::HandleButtonsUp( int ButtonPressed )
{
9 years ago
if( ButtonPressed & ( IN_FORWARD | IN_BACK ) )
9 years ago
m_zoomDelta = 0.0f;
9 years ago
if( ButtonPressed & ( IN_MOVELEFT | IN_MOVERIGHT ) )
9 years ago
m_moveDelta = 0.0f;
}
9 years ago
void CHudSpectator::SetModes( int iNewMainMode, int iNewInsetMode )
9 years ago
{
// if value == -1 keep old value
9 years ago
if( iNewMainMode == -1 )
9 years ago
iNewMainMode = g_iUser1;
9 years ago
if( iNewInsetMode == -1 )
9 years ago
iNewInsetMode = m_pip->value;
// inset mode is handled only clients side
m_pip->value = iNewInsetMode;
9 years ago
if( iNewMainMode < OBS_CHASE_LOCKED || iNewMainMode > OBS_MAP_CHASE )
9 years ago
{
9 years ago
gEngfuncs.Con_Printf( "Invalid spectator mode.\n" );
9 years ago
return;
}
9 years ago
9 years ago
// main modes ettings will override inset window settings
9 years ago
if( iNewMainMode != g_iUser1 )
9 years ago
{
// if we are NOT in HLTV mode, main spectator mode is set on server
9 years ago
if( !gEngfuncs.IsSpectateOnly() )
9 years ago
{
return;
}
9 years ago
if( !g_iUser2 && ( iNewMainMode != OBS_ROAMING ) ) // make sure we have a target
9 years ago
{
// choose last Director object if still available
9 years ago
if( IsActivePlayer( gEngfuncs.GetEntityByIndex( m_lastPrimaryObject ) ) )
9 years ago
{
g_iUser2 = m_lastPrimaryObject;
g_iUser3 = m_lastSecondaryObject;
}
else
9 years ago
FindNextPlayer( false ); // find any target
9 years ago
}
9 years ago
switch( iNewMainMode )
9 years ago
{
9 years ago
case OBS_CHASE_LOCKED:
g_iUser1 = OBS_CHASE_LOCKED;
break;
case OBS_CHASE_FREE:
g_iUser1 = OBS_CHASE_FREE;
break;
case OBS_ROAMING: // jump to current vJumpOrigin/angle
g_iUser1 = OBS_ROAMING;
if( g_iUser2 )
{
V_GetChasePos( g_iUser2, v_cl_angles, vJumpOrigin, vJumpAngles );
gEngfuncs.SetViewAngles( vJumpAngles );
iJumpSpectator = 1;
}
break;
case OBS_IN_EYE:
g_iUser1 = OBS_IN_EYE;
break;
case OBS_MAP_FREE:
g_iUser1 = OBS_MAP_FREE;
// reset user values
m_mapZoom = m_OverviewData.zoom;
m_mapOrigin = m_OverviewData.origin;
break;
case OBS_MAP_CHASE:
g_iUser1 = OBS_MAP_CHASE;
// reset user values
m_mapZoom = m_OverviewData.zoom;
m_mapOrigin = m_OverviewData.origin;
break;
9 years ago
}
9 years ago
if( ( g_iUser1 == OBS_IN_EYE ) || ( g_iUser1 == OBS_ROAMING ) )
9 years ago
{
9 years ago
m_crosshairRect.left = 24;
m_crosshairRect.top = 0;
m_crosshairRect.right = 48;
9 years ago
m_crosshairRect.bottom = 24;
9 years ago
9 years ago
SetCrosshair( m_hCrosshair, m_crosshairRect, 255, 255, 255 );
}
else
{
9 years ago
memset( &m_crosshairRect, 0, sizeof(m_crosshairRect) );
9 years ago
SetCrosshair( 0, m_crosshairRect, 0, 0, 0 );
9 years ago
}
9 years ago
char string[128];
9 years ago
sprintf( string, "#Spec_Mode%d", g_iUser1 );
sprintf( string, "%c%s", HUD_PRINTCENTER, CHudTextMessage::BufferedLocaliseTextString( string ) );
gHUD.m_TextMessage.MsgFunc_TextMsg( NULL, strlen( string ) + 1, string );
9 years ago
}
}
9 years ago
bool CHudSpectator::IsActivePlayer( cl_entity_t *ent )
9 years ago
{
9 years ago
return ( ent &&
ent->player &&
9 years ago
ent->curstate.solid != SOLID_NOT &&
ent != gEngfuncs.GetLocalPlayer() &&
g_PlayerInfoList[ent->index].name != NULL
);
}
9 years ago
bool CHudSpectator::ParseOverviewFile()
9 years ago
{
char filename[512] = { 0 };
char levelname[256] = { 0 };
9 years ago
char token[1024] = { 0 };
float height;
bool ret = false;
9 years ago
char *afile = NULL, *pfile = NULL;
9 years ago
9 years ago
memset( &m_OverviewData, 0, sizeof(m_OverviewData) );
9 years ago
// fill in standrd values
m_OverviewData.insetWindowX = 4; // upper left corner
m_OverviewData.insetWindowY = 4;
m_OverviewData.insetWindowHeight = 180;
m_OverviewData.insetWindowWidth = 240;
m_OverviewData.origin[0] = 0.0f;
m_OverviewData.origin[1] = 0.0f;
m_OverviewData.origin[2] = 0.0f;
9 years ago
m_OverviewData.zoom = 1.0f;
9 years ago
m_OverviewData.layers = 0;
m_OverviewData.layersHeights[0] = 0.0f;
strcpy( m_OverviewData.map, gEngfuncs.pfnGetLevelName() );
if( m_OverviewData.map[0] == '\0' )
return ret; // not active yet
9 years ago
9 years ago
strcpy( levelname, m_OverviewData.map + 5 );
levelname[strlen( levelname ) - 4] = 0;
9 years ago
9 years ago
sprintf( filename, "overviews/%s.txt", levelname );
9 years ago
afile = pfile = (char *)gEngfuncs.COM_LoadFile( filename, 5, NULL );
9 years ago
if( !pfile )
9 years ago
{
9 years ago
gEngfuncs.Con_DPrintf( "Couldn't open file %s. Using default values for overiew mode.\n", filename );
return ret;
9 years ago
}
9 years ago
while( true )
9 years ago
{
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
9 years ago
if( !pfile )
9 years ago
break;
9 years ago
if( !stricmp( token, "global" ) )
9 years ago
{
// parse the global data
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
if( stricmp( token, "{" ) )
9 years ago
{
9 years ago
gEngfuncs.Con_Printf( "Error parsing overview file %s. (expected { )\n", filename );
goto end;
9 years ago
}
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
9 years ago
while( stricmp( token, "}") )
9 years ago
{
9 years ago
if( !stricmp( token, "zoom" ) )
9 years ago
{
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
m_OverviewData.zoom = atof( token );
}
9 years ago
else if( !stricmp( token, "origin" ) )
9 years ago
{
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
m_OverviewData.origin[0] = atof( token );
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
m_OverviewData.origin[1] = atof( token );
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
m_OverviewData.origin[2] = atof( token );
}
9 years ago
else if( !stricmp( token, "rotated" ) )
9 years ago
{
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
m_OverviewData.rotated = atoi( token );
}
9 years ago
else if( !stricmp( token, "inset" ) )
9 years ago
{
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
m_OverviewData.insetWindowX = atof( token );
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
m_OverviewData.insetWindowY = atof( token );
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
m_OverviewData.insetWindowWidth = atof( token );
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
m_OverviewData.insetWindowHeight = atof( token );
}
else
{
9 years ago
gEngfuncs.Con_Printf( "Error parsing overview file %s. (%s unkown)\n", filename, token );
goto end;
9 years ago
}
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token ); // parse next token
9 years ago
}
}
9 years ago
else if( !stricmp( token, "layer" ) )
9 years ago
{
// parse a layer data
9 years ago
if( m_OverviewData.layers == OVERVIEW_MAX_LAYERS )
9 years ago
{
9 years ago
gEngfuncs.Con_Printf( "Error parsing overview file %s. ( too many layers )\n", filename );
goto end;
9 years ago
}
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
9 years ago
if( stricmp( token, "{" ) )
9 years ago
{
9 years ago
gEngfuncs.Con_Printf( "Error parsing overview file %s. (expected { )\n", filename );
goto end;
9 years ago
}
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
9 years ago
9 years ago
while( stricmp( token, "}") )
9 years ago
{
9 years ago
if( !stricmp( token, "image" ) )
9 years ago
{
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
strcpy( m_OverviewData.layersImages[m_OverviewData.layers], token );
9 years ago
}
else if ( !stricmp( token, "height" ) )
{
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token );
height = atof( token );
m_OverviewData.layersHeights[m_OverviewData.layers] = height;
9 years ago
}
else
{
9 years ago
gEngfuncs.Con_Printf( "Error parsing overview file %s. (%s unkown)\n", filename, token );
goto end;
9 years ago
}
9 years ago
pfile = gEngfuncs.COM_ParseFile( pfile, token ); // parse next token
9 years ago
}
m_OverviewData.layers++;
}
}
m_mapZoom = m_OverviewData.zoom;
m_mapOrigin = m_OverviewData.origin;
ret = true;
end:
gEngfuncs.COM_FreeFile( afile );
return ret;
9 years ago
}
void CHudSpectator::LoadMapSprites()
{
// right now only support for one map layer
9 years ago
if( m_OverviewData.layers > 0 )
9 years ago
{
m_MapSprite = gEngfuncs.LoadMapSprite( m_OverviewData.layersImages[0] );
}
else
m_MapSprite = NULL; // the standard "unkown map" sprite will be used instead
}
void CHudSpectator::DrawOverviewLayer()
{
9 years ago
float screenaspect, xs, ys, xStep, yStep, x, y, z;
int ix, iy, i, xTiles, yTiles, frame;
9 years ago
qboolean hasMapImage = m_MapSprite ? TRUE : FALSE;
model_t *dummySprite = (struct model_s *)gEngfuncs.GetSpritePointer( m_hsprUnkownMap );
9 years ago
if( hasMapImage )
9 years ago
{
i = m_MapSprite->numframes / ( 4 * 3 );
i = sqrt( float( i ) );
xTiles = i * 4;
yTiles = i * 3;
9 years ago
}
else
{
xTiles = 8;
yTiles = 6;
}
9 years ago
screenaspect = 4.0f / 3.0f;
9 years ago
xs = m_OverviewData.origin[0];
ys = m_OverviewData.origin[1];
z = ( 90.0f - v_angles[0] ) / 90.0f;
z *= m_OverviewData.layersHeights[0]; // gOverviewData.z_min - 32;
9 years ago
// i = r_overviewTexture + ( layer * OVERVIEW_X_TILES * OVERVIEW_Y_TILES );
9 years ago
gEngfuncs.pTriAPI->RenderMode( kRenderTransTexture );
gEngfuncs.pTriAPI->CullFace( TRI_NONE );
gEngfuncs.pTriAPI->Color4f( 1.0f, 1.0f, 1.0f, 1.0f );
9 years ago
frame = 0;
// rotated view ?
9 years ago
if( m_OverviewData.rotated )
9 years ago
{
9 years ago
xStep = ( 2 * 4096.0f / m_OverviewData.zoom ) / xTiles;
yStep = -( 2 * 4096.0f / ( m_OverviewData.zoom* screenaspect ) ) / yTiles;
9 years ago
9 years ago
y = ys + ( 4096.0f / ( m_OverviewData.zoom * screenaspect ) );
9 years ago
9 years ago
for( iy = 0; iy < yTiles; iy++ )
9 years ago
{
9 years ago
x = xs - ( 4096.0f / (m_OverviewData.zoom ) );
9 years ago
9 years ago
for( ix = 0; ix < xTiles; ix++ )
9 years ago
{
9 years ago
if( hasMapImage )
9 years ago
gEngfuncs.pTriAPI->SpriteTexture( m_MapSprite, frame );
else
gEngfuncs.pTriAPI->SpriteTexture( dummySprite, 0 );
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
gEngfuncs.pTriAPI->TexCoord2f( 0, 0 );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x, y, z );
9 years ago
gEngfuncs.pTriAPI->TexCoord2f( 1, 0 );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x + xStep, y, z);
9 years ago
gEngfuncs.pTriAPI->TexCoord2f( 1, 1 );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x + xStep, y + yStep, z );
9 years ago
gEngfuncs.pTriAPI->TexCoord2f( 0, 1 );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x, y + yStep, z);
9 years ago
gEngfuncs.pTriAPI->End();
frame++;
9 years ago
x += xStep;
9 years ago
}
9 years ago
y += yStep;
9 years ago
}
}
else
{
9 years ago
xStep = -( 2 * 4096.0f / m_OverviewData.zoom ) / xTiles;
yStep = -( 2 * 4096.0f / ( m_OverviewData.zoom* screenaspect ) ) / yTiles;
9 years ago
9 years ago
x = xs + ( 4096.0f / ( m_OverviewData.zoom * screenaspect ) );
9 years ago
9 years ago
for( ix = 0; ix < yTiles; ix++ )
9 years ago
{
9 years ago
y = ys + ( 4096.0f / ( m_OverviewData.zoom ) );
for( iy = 0; iy < xTiles; iy++ )
9 years ago
{
9 years ago
if( hasMapImage )
9 years ago
gEngfuncs.pTriAPI->SpriteTexture( m_MapSprite, frame );
else
gEngfuncs.pTriAPI->SpriteTexture( dummySprite, 0 );
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
gEngfuncs.pTriAPI->TexCoord2f( 0, 0 );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x, y, z );
9 years ago
gEngfuncs.pTriAPI->TexCoord2f( 0, 1 );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x + xStep, y, z);
9 years ago
gEngfuncs.pTriAPI->TexCoord2f( 1, 1 );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x + xStep, y + yStep, z );
9 years ago
gEngfuncs.pTriAPI->TexCoord2f( 1, 0 );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x, y + yStep, z );
9 years ago
gEngfuncs.pTriAPI->End();
frame++;
9 years ago
y += yStep;
9 years ago
}
9 years ago
x += xStep;
9 years ago
}
}
}
void CHudSpectator::DrawOverviewEntities()
{
9 years ago
int i, ir, ig, ib;
9 years ago
struct model_s *hSpriteModel;
vec3_t origin, angles, point, forward, right, left, up, world, screen, offset;
9 years ago
float x, y, z, r, g, b, sizeScale = 4.0f;
9 years ago
cl_entity_t * ent;
float rmatrix[3][4]; // transformation matrix
9 years ago
float zScale = ( 90.0f - v_angles[0] ) / 90.0f;
9 years ago
z = m_OverviewData.layersHeights[0] * zScale;
// get yellow/brown HUD color
UnpackRGB( ir, ig, ib, gHUD.m_iHUDColor );
9 years ago
r = (float)ir / 255.0f;
g = (float)ig / 255.0f;
b = (float)ib / 255.0f;
9 years ago
gEngfuncs.pTriAPI->CullFace( TRI_NONE );
9 years ago
for( i = 0; i < MAX_PLAYERS; i++ )
9 years ago
m_vPlayerPos[i][2] = -1; // mark as invisible
// draw all players
9 years ago
for( i = 0; i < MAX_OVERVIEW_ENTITIES; i++ )
9 years ago
{
9 years ago
if( !m_OverviewEntities[i].hSprite )
9 years ago
continue;
hSpriteModel = (struct model_s *)gEngfuncs.GetSpritePointer( m_OverviewEntities[i].hSprite );
ent = m_OverviewEntities[i].entity;
9 years ago
9 years ago
gEngfuncs.pTriAPI->SpriteTexture( hSpriteModel, 0 );
gEngfuncs.pTriAPI->RenderMode( kRenderTransTexture );
// see R_DrawSpriteModel
// draws players sprite
9 years ago
AngleVectors( ent->angles, right, up, NULL );
9 years ago
9 years ago
VectorCopy( ent->origin,origin );
9 years ago
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
gEngfuncs.pTriAPI->Color4f( 1.0f, 1.0f, 1.0f, 1.0f );
9 years ago
gEngfuncs.pTriAPI->TexCoord2f(1, 0);
VectorMA( origin, 16.0f * sizeScale, up, point );
VectorMA( point, 16.0f * sizeScale, right, point );
9 years ago
point[2] *= zScale;
9 years ago
gEngfuncs.pTriAPI->Vertex3fv( point );
gEngfuncs.pTriAPI->TexCoord2f( 0, 0 );
9 years ago
9 years ago
VectorMA( origin, 16.0f * sizeScale, up, point );
VectorMA( point, -16.0f * sizeScale, right, point );
9 years ago
point[2] *= zScale;
9 years ago
gEngfuncs.pTriAPI->Vertex3fv( point );
9 years ago
9 years ago
gEngfuncs.pTriAPI->TexCoord2f( 0, 1 );
VectorMA( origin, -16.0f * sizeScale, up, point );
VectorMA( point, -16.0f * sizeScale, right, point );
9 years ago
point[2] *= zScale;
9 years ago
gEngfuncs.pTriAPI->Vertex3fv( point );
9 years ago
9 years ago
gEngfuncs.pTriAPI->TexCoord2f( 1, 1 );
VectorMA( origin, -16.0f * sizeScale, up, point );
VectorMA( point, 16.0f * sizeScale, right, point );
9 years ago
point[2] *= zScale;
9 years ago
gEngfuncs.pTriAPI->Vertex3fv( point );
9 years ago
9 years ago
gEngfuncs.pTriAPI->End();
9 years ago
9 years ago
if( !ent->player )
9 years ago
continue;
9 years ago
9 years ago
// draw line under player icons
origin[2] *= zScale;
gEngfuncs.pTriAPI->RenderMode( kRenderTransAdd );
9 years ago
9 years ago
hSpriteModel = (struct model_s *)gEngfuncs.GetSpritePointer( m_hsprBeam );
gEngfuncs.pTriAPI->SpriteTexture( hSpriteModel, 0 );
9 years ago
gEngfuncs.pTriAPI->Color4f( r, g, b, 0.3f );
9 years ago
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 0.0f );
gEngfuncs.pTriAPI->Vertex3f( origin[0] + 4.0f, origin[1] + 4.0f, origin[2] - zScale );
gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
gEngfuncs.pTriAPI->Vertex3f( origin[0] - 4.0f, origin[1] - 4.0f, origin[2] - zScale );
gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
gEngfuncs.pTriAPI->Vertex3f( origin[0] - 4.0f, origin[1] - 4.0f, z );
gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 1.0f );
gEngfuncs.pTriAPI->Vertex3f( origin[0] + 4.0f, origin[1] + 4.0f, z );
9 years ago
gEngfuncs.pTriAPI->End();
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 0.0f );
gEngfuncs.pTriAPI->Vertex3f( origin[0] - 4.0f, origin[1] + 4.0f, origin[2] - zScale );
gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
gEngfuncs.pTriAPI->Vertex3f( origin[0] + 4.0f, origin[1] - 4.0f, origin[2] - zScale );
gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
gEngfuncs.pTriAPI->Vertex3f( origin[0] + 4.0f, origin[1] - 4.0f, z );
gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 1.0f );
gEngfuncs.pTriAPI->Vertex3f( origin[0] - 4.0f, origin[1] + 4.0f, z );
9 years ago
gEngfuncs.pTriAPI->End();
9 years ago
// calculate screen position for name and infromation in hud::draw()
9 years ago
if( gEngfuncs.pTriAPI->WorldToScreen( origin, screen ) )
9 years ago
continue; // object is behind viewer
9 years ago
screen[0] = XPROJECT( screen[0] );
screen[1] = YPROJECT( screen[1] );
9 years ago
screen[2] = 0.0f;
// calculate some offset under the icon
9 years ago
origin[0] += 32.0f;
origin[1] += 32.0f;
gEngfuncs.pTriAPI->WorldToScreen( origin, offset );
9 years ago
9 years ago
offset[0] = XPROJECT( offset[0] );
offset[1] = YPROJECT( offset[1] );
9 years ago
offset[2] = 0.0f;
9 years ago
VectorSubtract( offset, screen, offset );
9 years ago
int playerNum = ent->index - 1;
m_vPlayerPos[playerNum][0] = screen[0];
9 years ago
m_vPlayerPos[playerNum][1] = screen[1] + Length( offset );
9 years ago
m_vPlayerPos[playerNum][2] = 1; // mark player as visible
}
9 years ago
if( !m_pip->value || !m_drawcone->value )
9 years ago
return;
// get current camera position and angle
9 years ago
if( m_pip->value == INSET_IN_EYE || g_iUser1 == OBS_IN_EYE )
{
9 years ago
V_GetInEyePos( g_iUser2, origin, angles );
}
9 years ago
else if( m_pip->value == INSET_CHASE_FREE || g_iUser1 == OBS_CHASE_FREE )
9 years ago
{
V_GetChasePos( g_iUser2, v_cl_angles, origin, angles );
}
9 years ago
else if( g_iUser1 == OBS_ROAMING )
9 years ago
{
VectorCopy( v_sim_org, origin );
VectorCopy( v_cl_angles, angles );
}
else
V_GetChasePos( g_iUser2, NULL, origin, angles );
// draw camera sprite
x = origin[0];
y = origin[1];
z = origin[2];
angles[0] = 0; // always show horizontal camera sprite
hSpriteModel = (struct model_s *)gEngfuncs.GetSpritePointer( m_hsprCamera );
gEngfuncs.pTriAPI->RenderMode( kRenderTransAdd );
gEngfuncs.pTriAPI->SpriteTexture( hSpriteModel, 0 );
9 years ago
gEngfuncs.pTriAPI->Color4f( r, g, b, 1.0f );
9 years ago
9 years ago
AngleVectors( angles, forward, NULL, NULL );
VectorScale( forward, 512.0f, forward );
offset[0] = 0.0f;
9 years ago
offset[1] = 45.0f;
9 years ago
offset[2] = 0.0f;
9 years ago
9 years ago
AngleMatrix( offset, rmatrix );
VectorTransform( forward, rmatrix, right );
9 years ago
offset[1]= -45.0f;
9 years ago
AngleMatrix( offset, rmatrix );
VectorTransform( forward, rmatrix , left );
9 years ago
9 years ago
gEngfuncs.pTriAPI->Begin( TRI_TRIANGLES );
gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x + right[0], y + right[1], ( z + right[2] ) * zScale);
9 years ago
gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x, y, z * zScale );
gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 1.0f );
9 years ago
gEngfuncs.pTriAPI->Vertex3f( x + left[0], y + left[1], ( z + left[2] ) * zScale );
9 years ago
gEngfuncs.pTriAPI->End ();
}
void CHudSpectator::DrawOverview()
{
// draw only in sepctator mode
if ( !g_iUser1 )
return;
// Only draw the overview if Map Mode is selected for this view
9 years ago
if( m_iDrawCycle == 0 && ( ( g_iUser1 != OBS_MAP_FREE ) && ( g_iUser1 != OBS_MAP_CHASE ) ) )
9 years ago
return;
if ( m_iDrawCycle == 1 && m_pip->value < INSET_MAP_FREE )
return;
DrawOverviewLayer();
DrawOverviewEntities();
CheckOverviewEntities();
}
9 years ago
9 years ago
void CHudSpectator::CheckOverviewEntities()
{
double time = gEngfuncs.GetClientTime();
// removes old entities from list
9 years ago
for( int i = 0; i < MAX_OVERVIEW_ENTITIES; i++ )
9 years ago
{
// remove entity from list if it is too old
9 years ago
if( m_OverviewEntities[i].killTime < time )
9 years ago
{
9 years ago
memset( &m_OverviewEntities[i], 0, sizeof(overviewEntity_t) );
9 years ago
}
}
}
bool CHudSpectator::AddOverviewEntity( int type, struct cl_entity_s *ent, const char *modelname)
{
HSPRITE hSprite = 0;
double duration = -1.0; // duration -1 means show it only this frame;
9 years ago
9 years ago
if( !ent )
9 years ago
return false;
9 years ago
if( type == ET_PLAYER )
9 years ago
{
9 years ago
if( ent->curstate.solid != SOLID_NOT)
9 years ago
{
switch ( g_PlayerExtraInfo[ent->index].teamnumber )
{
// blue and red teams are swapped in CS and TFC
9 years ago
case 1:
hSprite = m_hsprPlayerBlue;
break;
case 2:
hSprite = m_hsprPlayerRed;
break;
default:
hSprite = m_hsprPlayer;
break;
9 years ago
}
}
else
return false; // it's an spectator
}
9 years ago
else if( type == ET_NORMAL )
9 years ago
{
return false;
}
else
9 years ago
return false;
9 years ago
9 years ago
return AddOverviewEntityToList( hSprite, ent, gEngfuncs.GetClientTime() + duration );
9 years ago
}
9 years ago
void CHudSpectator::DeathMessage( int victim )
9 years ago
{
// find out where the victim is
9 years ago
cl_entity_t *pl = gEngfuncs.GetEntityByIndex( victim );
9 years ago
9 years ago
if( pl && pl->player )
9 years ago
AddOverviewEntityToList(m_hsprPlayerDead, pl, gEngfuncs.GetClientTime() + 2.0f );
}
bool CHudSpectator::AddOverviewEntityToList( HSPRITE sprite, cl_entity_t *ent, double killTime )
9 years ago
{
9 years ago
for( int i = 0; i < MAX_OVERVIEW_ENTITIES; i++ )
9 years ago
{
// find empty entity slot
if( m_OverviewEntities[i].entity == NULL )
9 years ago
{
m_OverviewEntities[i].entity = ent;
m_OverviewEntities[i].hSprite = sprite;
m_OverviewEntities[i].killTime = killTime;
return true;
}
}
return false; // maximum overview entities reached
}
9 years ago
9 years ago
void CHudSpectator::CheckSettings()
{
// disallow same inset mode as main mode:
m_pip->value = (int)m_pip->value;
9 years ago
if( ( g_iUser1 < OBS_MAP_FREE ) && ( m_pip->value == INSET_CHASE_FREE || m_pip->value == INSET_IN_EYE ) )
9 years ago
{
// otherwise both would show in World picures
m_pip->value = INSET_MAP_FREE;
}
9 years ago
if( ( g_iUser1 >= OBS_MAP_FREE ) && ( m_pip->value >= INSET_MAP_FREE ) )
9 years ago
{
// both would show map views
m_pip->value = INSET_CHASE_FREE;
}
// disble in intermission screen
9 years ago
if( gHUD.m_iIntermission )
9 years ago
m_pip->value = INSET_OFF;
// check chat mode
9 years ago
if( m_chatEnabled != (gHUD.m_SayText.m_HUD_saytext->value != 0) )
9 years ago
{
// hud_saytext changed
9 years ago
m_chatEnabled = ( gHUD.m_SayText.m_HUD_saytext->value != 0 );
9 years ago
9 years ago
if( gEngfuncs.IsSpectateOnly() )
9 years ago
{
// tell proxy our new chat mode
char chatcmd[32];
9 years ago
sprintf( chatcmd, "ignoremsg %i", m_chatEnabled ? 0 : 1 );
gEngfuncs.pfnServerCmd( chatcmd );
9 years ago
}
}
// HL/TFC has no oberserver corsshair, so set it client side
9 years ago
if( ( g_iUser1 == OBS_IN_EYE ) || ( g_iUser1 == OBS_ROAMING ) )
9 years ago
{
9 years ago
m_crosshairRect.left = 24;
m_crosshairRect.top = 0;
m_crosshairRect.right = 48;
9 years ago
m_crosshairRect.bottom = 24;
SetCrosshair( m_hCrosshair, m_crosshairRect, 255, 255, 255 );
}
else
{
9 years ago
memset( &m_crosshairRect, 0, sizeof(m_crosshairRect) );
9 years ago
SetCrosshair( 0, m_crosshairRect, 0, 0, 0 );
9 years ago
}
9 years ago
// if we are a real player on server don't allow inset window
// in First Person mode since this is our resticted forcecamera mode 2
// team number 3 = SPECTATOR see player.h
9 years ago
if( ( ( g_iTeamNumber == 1 ) || ( g_iTeamNumber == 2 ) ) && ( g_iUser1 == OBS_IN_EYE ) )
9 years ago
m_pip->value = INSET_OFF;
// draw small border around inset view, adjust upper black bar
}
9 years ago
int CHudSpectator::ToggleInset( bool allowOff )
9 years ago
{
int newInsetMode = (int)m_pip->value + 1;
9 years ago
if( g_iUser1 < OBS_MAP_FREE )
9 years ago
{
9 years ago
if( newInsetMode > INSET_MAP_CHASE )
9 years ago
{
9 years ago
if( allowOff )
9 years ago
newInsetMode = INSET_OFF;
else
newInsetMode = INSET_MAP_FREE;
}
9 years ago
if( newInsetMode == INSET_CHASE_FREE )
9 years ago
newInsetMode = INSET_MAP_FREE;
}
else
{
9 years ago
if( newInsetMode > INSET_IN_EYE )
9 years ago
{
9 years ago
if( allowOff )
9 years ago
newInsetMode = INSET_OFF;
else
newInsetMode = INSET_CHASE_FREE;
}
}
return newInsetMode;
}
9 years ago
9 years ago
void CHudSpectator::Reset()
{
// Reset HUD
9 years ago
if( strcmp( m_OverviewData.map, gEngfuncs.pfnGetLevelName() ) )
9 years ago
{
// update level overview if level changed
ParseOverviewFile();
LoadMapSprites();
}
9 years ago
memset( &m_OverviewEntities, 0, sizeof(m_OverviewEntities) );
9 years ago
SetSpectatorStartPosition();
}
void CHudSpectator::InitHUDData()
{
m_lastPrimaryObject = m_lastSecondaryObject = 0;
m_flNextObserverInput = 0.0f;
m_lastHudMessage = 0;
m_iSpectatorNumber = 0;
9 years ago
iJumpSpectator = 0;
9 years ago
g_iUser1 = g_iUser2 = 0;
memset( &m_OverviewData, 0, sizeof(m_OverviewData));
memset( &m_OverviewEntities, 0, sizeof(m_OverviewEntities));
9 years ago
if( gEngfuncs.IsSpectateOnly() || gEngfuncs.pDemoAPI->IsPlayingback() )
9 years ago
m_autoDirector->value = 1.0f;
else
m_autoDirector->value = 0.0f;
Reset();
SetModes( OBS_CHASE_FREE, INSET_OFF );
g_iUser2 = 0; // fake not target until first camera command
// reset HUD FOV
9 years ago
gHUD.m_iFOV = CVAR_GET_FLOAT( "default_fov" );
9 years ago
}