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.

314 lines
8.4 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.
*
****/
//
// death notice
//
9 years ago
9 years ago
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include <string.h>
#include <stdio.h>
DECLARE_MESSAGE( m_DeathNotice, DeathMsg )
9 years ago
struct DeathNoticeItem {
9 years ago
char szKiller[MAX_PLAYER_NAME_LENGTH * 2];
char szVictim[MAX_PLAYER_NAME_LENGTH * 2];
9 years ago
int iId; // the index number of the associated sprite
int iSuicide;
int iTeamKill;
int iNonPlayerKill;
float flDisplayTime;
float *KillerColor;
float *VictimColor;
};
#define MAX_DEATHNOTICES 4
static int DEATHNOTICE_DISPLAY_TIME = 6;
#define DEATHNOTICE_TOP 32
9 years ago
DeathNoticeItem rgDeathNoticeList[MAX_DEATHNOTICES + 1];
9 years ago
float g_ColorBlue[3] = { 0.6, 0.8, 1.0 };
9 years ago
float g_ColorRed[3] = { 1.0, 0.25, 0.25 };
9 years ago
float g_ColorGreen[3] = { 0.6, 1.0, 0.6 };
float g_ColorYellow[3] = { 1.0, 0.7, 0.0 };
float g_ColorGrey[3] = { 0.8, 0.8, 0.8 };
//++ BulliT
float g_ColorConsole[3] = { 1.0, 0.7, 0.0 };
//-- Martin Webrant
9 years ago
float *GetClientColor( int clientIndex )
{
9 years ago
switch( g_PlayerExtraInfo[clientIndex].teamnumber )
9 years ago
{
case 1: return g_ColorBlue;
case 2: return g_ColorRed;
case 3: return g_ColorYellow;
case 4: return g_ColorGreen;
//case 0: return g_ColorYellow;
//++ BulliT
case 0: return g_ColorConsole;
//-- Martin Webrant
9 years ago
default: return g_ColorGrey;
9 years ago
}
return NULL;
}
9 years ago
int CHudDeathNotice::Init( void )
9 years ago
{
gHUD.AddHudElem( this );
HOOK_MESSAGE( DeathMsg );
CVAR_CREATE( "hud_deathnotice_time", "6", 0 );
return 1;
}
9 years ago
void CHudDeathNotice::InitHUDData( void )
9 years ago
{
memset( rgDeathNoticeList, 0, sizeof(rgDeathNoticeList) );
}
9 years ago
int CHudDeathNotice::VidInit( void )
9 years ago
{
m_HUD_d_skull = gHUD.GetSpriteIndex( "d_skull" );
return 1;
}
9 years ago
int CHudDeathNotice::Draw( float flTime )
9 years ago
{
int x, y, r, g, b;
9 years ago
for( int i = 0; i < MAX_DEATHNOTICES; i++ )
9 years ago
{
9 years ago
if( rgDeathNoticeList[i].iId == 0 )
9 years ago
break; // we've gone through them all
9 years ago
if( rgDeathNoticeList[i].flDisplayTime < flTime )
{
// display time has expired
9 years ago
// remove the current item from the list
9 years ago
memmove( &rgDeathNoticeList[i], &rgDeathNoticeList[i + 1], sizeof(DeathNoticeItem) * ( MAX_DEATHNOTICES - i ) );
9 years ago
i--; // continue on the next item; stop the counter getting incremented
continue;
}
rgDeathNoticeList[i].flDisplayTime = min( rgDeathNoticeList[i].flDisplayTime, gHUD.m_flTime + DEATHNOTICE_DISPLAY_TIME );
// Only draw if the viewport will let me
// vgui dropped out
9 years ago
//if( gViewPort && gViewPort->AllowedToPrintText() )
9 years ago
{
// Draw the death notice
9 years ago
y = YRES( DEATHNOTICE_TOP ) + 2 + ( 20 * i ); //!!!
9 years ago
9 years ago
int id = ( rgDeathNoticeList[i].iId == -1 ) ? m_HUD_d_skull : rgDeathNoticeList[i].iId;
x = ScreenWidth - ConsoleStringLen( rgDeathNoticeList[i].szVictim ) - ( gHUD.GetSpriteRect(id).right - gHUD.GetSpriteRect(id).left );
9 years ago
9 years ago
if( !rgDeathNoticeList[i].iSuicide )
9 years ago
{
9 years ago
x -= ( 5 + ConsoleStringLen( rgDeathNoticeList[i].szKiller ) );
9 years ago
// Draw killers name
9 years ago
if( rgDeathNoticeList[i].KillerColor )
//++ BulliT
//gEngfuncs.pfnDrawSetTextColor( rgDeathNoticeList[i].KillerColor[0], rgDeathNoticeList[i].KillerColor[1], rgDeathNoticeList[i].KillerColor[2] );
x = 5 + DrawConsoleString( x, y, rgDeathNoticeList[i].szKiller, rgDeathNoticeList[i].KillerColor[0], rgDeathNoticeList[i].KillerColor[1], rgDeathNoticeList[i].KillerColor[2] );
else
//-- Martin Webrant
x = 5 + DrawConsoleString( x, y, rgDeathNoticeList[i].szKiller );
9 years ago
}
9 years ago
r = 255; g = 80; b = 0;
if( rgDeathNoticeList[i].iTeamKill )
9 years ago
{
r = 10; g = 240; b = 10; // display it in sickly green
}
// Draw death weapon
SPR_Set( gHUD.GetSprite(id), r, g, b );
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect(id) );
9 years ago
x += ( gHUD.GetSpriteRect(id).right - gHUD.GetSpriteRect(id).left );
9 years ago
// Draw victims name (if it was a player that was killed)
9 years ago
if( rgDeathNoticeList[i].iNonPlayerKill == FALSE )
9 years ago
{
9 years ago
if( rgDeathNoticeList[i].VictimColor )
//++ BulliT
//gEngfuncs.pfnDrawSetTextColor( rgDeathNoticeList[i].VictimColor[0], rgDeathNoticeList[i].VictimColor[1], rgDeathNoticeList[i].VictimColor[2] );
x = DrawConsoleString( x, y, rgDeathNoticeList[i].szVictim, rgDeathNoticeList[i].VictimColor[0], rgDeathNoticeList[i].VictimColor[1], rgDeathNoticeList[i].VictimColor[2] );
else
//-- Martin Webrant
x = DrawConsoleString( x, y, rgDeathNoticeList[i].szVictim );
9 years ago
}
}
}
return 1;
}
// This message handler may be better off elsewhere
9 years ago
int CHudDeathNotice::MsgFunc_DeathMsg( const char *pszName, int iSize, void *pbuf )
9 years ago
{
int i;
9 years ago
m_iFlags |= HUD_ACTIVE;
BEGIN_READ( pbuf, iSize );
int killer = READ_BYTE();
int victim = READ_BYTE();
char killedwith[32];
strcpy( killedwith, "d_" );
strncat( killedwith, READ_STRING(), sizeof(killedwith) - strlen(killedwith) - 1 );
9 years ago
9 years ago
gHUD.m_Spectator.DeathMessage( victim );
9 years ago
9 years ago
for( i = 0; i < MAX_DEATHNOTICES; i++ )
9 years ago
{
9 years ago
if( rgDeathNoticeList[i].iId == 0 )
9 years ago
break;
}
9 years ago
if( i == MAX_DEATHNOTICES )
{
// move the rest of the list forward to make room for this item
memmove( rgDeathNoticeList, rgDeathNoticeList + 1, sizeof(DeathNoticeItem) * MAX_DEATHNOTICES );
9 years ago
i = MAX_DEATHNOTICES - 1;
}
9 years ago
//if(gViewPort)
9 years ago
// gViewPort->GetAllPlayersInfo();
gHUD.m_Scoreboard.GetAllPlayersInfo();
// Get the Killer's name
9 years ago
char *killer_name = g_PlayerInfoList[killer].name;
if( !killer_name )
9 years ago
{
killer_name = "";
rgDeathNoticeList[i].szKiller[0] = 0;
}
else
{
rgDeathNoticeList[i].KillerColor = GetClientColor( killer );
strncpy( rgDeathNoticeList[i].szKiller, killer_name, MAX_PLAYER_NAME_LENGTH );
9 years ago
rgDeathNoticeList[i].szKiller[MAX_PLAYER_NAME_LENGTH - 1] = 0;
9 years ago
}
// Get the Victim's name
char *victim_name = NULL;
// If victim is -1, the killer killed a specific, non-player object (like a sentrygun)
9 years ago
if ( ( (char)victim ) != -1 )
victim_name = g_PlayerInfoList[victim].name;
9 years ago
if ( !victim_name )
{
victim_name = "";
rgDeathNoticeList[i].szVictim[0] = 0;
}
else
{
rgDeathNoticeList[i].VictimColor = GetClientColor( victim );
strncpy( rgDeathNoticeList[i].szVictim, victim_name, MAX_PLAYER_NAME_LENGTH );
9 years ago
rgDeathNoticeList[i].szVictim[MAX_PLAYER_NAME_LENGTH - 1] = 0;
9 years ago
}
// Is it a non-player object kill?
9 years ago
if ( ( (char)victim ) == -1 )
9 years ago
{
rgDeathNoticeList[i].iNonPlayerKill = TRUE;
// Store the object's name in the Victim slot (skip the d_ bit)
9 years ago
strcpy( rgDeathNoticeList[i].szVictim, killedwith + 2 );
9 years ago
}
else
{
if ( killer == victim || killer == 0 )
rgDeathNoticeList[i].iSuicide = TRUE;
if ( !strcmp( killedwith, "d_teammate" ) )
rgDeathNoticeList[i].iTeamKill = TRUE;
}
// Find the sprite in the list
int spr = gHUD.GetSpriteIndex( killedwith );
rgDeathNoticeList[i].iId = spr;
DEATHNOTICE_DISPLAY_TIME = CVAR_GET_FLOAT( "hud_deathnotice_time" );
rgDeathNoticeList[i].flDisplayTime = gHUD.m_flTime + DEATHNOTICE_DISPLAY_TIME;
9 years ago
if( rgDeathNoticeList[i].iNonPlayerKill )
9 years ago
{
ConsolePrint( rgDeathNoticeList[i].szKiller );
ConsolePrint( " killed a " );
ConsolePrint( rgDeathNoticeList[i].szVictim );
ConsolePrint( "\n" );
}
else
{
// record the death notice in the console
9 years ago
if( rgDeathNoticeList[i].iSuicide )
9 years ago
{
ConsolePrint( rgDeathNoticeList[i].szVictim );
9 years ago
if( !strcmp( killedwith, "d_world" ) )
9 years ago
{
ConsolePrint( " died" );
}
else
{
ConsolePrint( " killed self" );
}
}
9 years ago
else if( rgDeathNoticeList[i].iTeamKill )
9 years ago
{
ConsolePrint( rgDeathNoticeList[i].szKiller );
ConsolePrint( " killed his teammate " );
ConsolePrint( rgDeathNoticeList[i].szVictim );
}
else
{
ConsolePrint( rgDeathNoticeList[i].szKiller );
ConsolePrint( " killed " );
ConsolePrint( rgDeathNoticeList[i].szVictim );
}
9 years ago
if( *killedwith && (*killedwith > 13 ) && strcmp( killedwith, "d_world" ) && !rgDeathNoticeList[i].iTeamKill )
9 years ago
{
ConsolePrint( " with " );
// replace the code names with the 'real' names
9 years ago
if( !strcmp( killedwith + 2, "egon" ) )
9 years ago
strcpy( killedwith, "d_gluon gun" );
9 years ago
if ( !strcmp( killedwith + 2, "gauss" ) )
9 years ago
strcpy( killedwith, "d_tau cannon" );
9 years ago
ConsolePrint( killedwith + 2 ); // skip over the "d_" part
9 years ago
}
ConsolePrint( "\n" );
}
return 1;
}