-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathdeath.cpp
More file actions
291 lines (237 loc) * 7.14 KB
/
death.cpp
File metadata and controls
291 lines (237 loc) * 7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/***
*
* 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
//
#include "hud.h"
#include "utils.h"
#include "parsemsg.h"
struct DeathNoticeItem
{
char szKiller[MAX_PLAYER_NAME_LENGTH*2];
char szVictim[MAX_PLAYER_NAME_LENGTH*2];
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
#define DEATHNOTICE_TOP 32
static int DEATHNOTICE_DISPLAY_TIME = 6;
DeathNoticeItem rgDeathNoticeList[MAX_DEATHNOTICES+1];
float g_ColorBlue[3] = { 0.6, 0.8, 1.0 };
float g_ColorRed[3] = { 1.0, 0.25, 0.25 };
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 };
float *GetClientColor( int clientIndex )
{
switch( g_PlayerExtraInfo[clientIndex].teamnumber )
{
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;
default: return g_ColorGrey;
}
return NULL;
}
DECLARE_MESSAGE( m_DeathNotice, DeathMsg );
int CHudDeathNotice :: Init( void )
{
gHUD.AddHudElem( this );
HOOK_MESSAGE( DeathMsg );
CVAR_REGISTER( "hud_deathnotice_time", "6", 0 );
return 1;
}
void CHudDeathNotice :: InitHUDData( void )
{
memset( rgDeathNoticeList, 0, sizeof(rgDeathNoticeList) );
}
int CHudDeathNotice :: VidInit( void )
{
m_HUD_d_skull = gHUD.GetSpriteIndex( "d_skull" );
return 1;
}
int CHudDeathNotice :: Draw( float flTime )
{
int x, y, r, g, b;
for( int i = 0; i < MAX_DEATHNOTICES; i++ )
{
if( rgDeathNoticeList[i].iId == 0 )
break; // we've gone through them all
if( rgDeathNoticeList[i].flDisplayTime < flTime )
{
// display time has expired
// remove the current item from the list
memmove( &rgDeathNoticeList[i], &rgDeathNoticeList[i+1], sizeof( DeathNoticeItem ) * ( MAX_DEATHNOTICES - i ));
i--; // continue on the next item; stop the counter getting incremented
continue;
}
rgDeathNoticeList[i].flDisplayTime = Q_min( rgDeathNoticeList[i].flDisplayTime, gHUD.m_flTime + DEATHNOTICE_DISPLAY_TIME );
// Draw the death notice
y = DEATHNOTICE_TOP + (20 * i); //!!!
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 );
if( !rgDeathNoticeList[i].iSuicide )
{
x -= (5 + ConsoleStringLen( rgDeathNoticeList[i].szKiller ));
// Draw killers name
x = 5 + DrawConsoleString( x, y, rgDeathNoticeList[i].szKiller );
}
r = 255;
g = 80;
b = 0;
if( rgDeathNoticeList[i].iTeamKill )
{
// display it in sickly green
r = 10;
g = 240;
b = 10;
}
// Draw death weapon
SPR_Set( gHUD.GetSprite( id ), r, g, b );
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( id ));
x += (gHUD.GetSpriteRect( id ).right - gHUD.GetSpriteRect( id ).left );
// Draw victims name
x = DrawConsoleString( x, y, rgDeathNoticeList[i].szVictim );
}
return 1;
}
// This message handler may be better off elsewhere
int CHudDeathNotice :: MsgFunc_DeathMsg( const char *pszName, int iSize, void *pbuf )
{
int i;
m_iFlags |= HUD_ACTIVE;
BEGIN_READ( pszName, pbuf, iSize );
int killer = READ_BYTE();
int victim = READ_BYTE();
char killedwith[32];
Q_strcpy( killedwith, "d_" );
Q_strncat( killedwith, READ_STRING(), 32 );
gHUD.m_Scoreboard.DeathMsg( killer, victim );
for( i = 0; i < MAX_DEATHNOTICES; i++ )
{
if( rgDeathNoticeList[i].iId == 0 )
break;
}
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 );
i = MAX_DEATHNOTICES - 1;
}
gHUD.m_Scoreboard.GetAllPlayersInfo();
// Get the Killer's name
char *killer_name = g_PlayerInfoList[killer].name;
if( !killer_name )
{
killer_name = "";
rgDeathNoticeList[i].szKiller[0] = 0;
}
else
{
rgDeathNoticeList[i].KillerColor = GetClientColor( killer );
Q_strncpy( rgDeathNoticeList[i].szKiller, killer_name, MAX_PLAYER_NAME_LENGTH );
rgDeathNoticeList[i].szKiller[MAX_PLAYER_NAME_LENGTH-1] = 0;
}
// Get the Victim's name
char *victim_name = NULL;
// If victim is -1, the killer killed a specific, non-player object (like a sentrygun)
if((( char )victim) != -1 )
victim_name = g_PlayerInfoList[victim].name;
if( !victim_name )
{
victim_name = "";
rgDeathNoticeList[i].szVictim[0] = 0;
}
else
{
rgDeathNoticeList[i].VictimColor = GetClientColor( victim );
Q_strncpy( rgDeathNoticeList[i].szVictim, victim_name, MAX_PLAYER_NAME_LENGTH );
rgDeathNoticeList[i].szVictim[MAX_PLAYER_NAME_LENGTH-1] = 0;
}
// Is it a non-player object kill?
if( ((char)victim) == -1 )
{
rgDeathNoticeList[i].iNonPlayerKill = TRUE;
// Store the object's name in the Victim slot (skip the d_ bit)
Q_strcpy( rgDeathNoticeList[i].szVictim, killedwith+2 );
}
else
{
if( killer == victim || killer == 0 )
rgDeathNoticeList[i].iSuicide = TRUE;
if( !Q_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;
if( rgDeathNoticeList[i].iNonPlayerKill )
{
ConsolePrint( rgDeathNoticeList[i].szKiller );
ConsolePrint( " killed a " );
ConsolePrint( rgDeathNoticeList[i].szVictim );
ConsolePrint( "\n" );
}
else
{
// record the death notice in the console
if( rgDeathNoticeList[i].iSuicide )
{
ConsolePrint( rgDeathNoticeList[i].szVictim );
if( !Q_strcmp( killedwith, "d_world" ))
{
ConsolePrint( " died" );
}
else
{
ConsolePrint( " killed self" );
}
}
else if( rgDeathNoticeList[i].iTeamKill )
{
ConsolePrint( rgDeathNoticeList[i].szKiller );
ConsolePrint( " killed his teammate " );
ConsolePrint( rgDeathNoticeList[i].szVictim );
}
else
{
ConsolePrint( rgDeathNoticeList[i].szKiller );
ConsolePrint( " killed " );
ConsolePrint( rgDeathNoticeList[i].szVictim );
}
if( killedwith && *killedwith && (*killedwith > 13 ) && Q_strcmp( killedwith, "d_world" ) && !rgDeathNoticeList[i].iTeamKill )
{
ConsolePrint( " with " );
// replace the code names with the 'real' names
if( !Q_strcmp( killedwith+2, "egon" ))
Q_strcpy( killedwith, "d_gluon gun" );
if( !Q_strcmp( killedwith+2, "gauss" ))
Q_strcpy( killedwith, "d_tau cannon" );
ConsolePrint( killedwith+2 ); // skip over the "d_" part
}
ConsolePrint( "\n" );
}
END_READ();
return 1;
}