Skip to content

Commit 7cb7edb

Browse files
committed
TODO WIP: Killer damage HUD
* fixes #667
1 parent f5cf0e8 commit 7cb7edb

19 files changed

+651
-283
lines changed

game/neo/scripts/HudLayout.res

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,4 +983,13 @@
983983
"wide" "300"
984984
"tall" "200"
985985
}
986+
987+
neo_killer_damage_info
988+
{
989+
"fieldName" "neo_killer_damage_info"
990+
"xpos" "0"
991+
"ypos" "0"
992+
"wide" "640"
993+
"tall" "480"
994+
}
986995
}

game/neo/scripts/kb_act.lst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
"timeleft" "Time Left in Round"
6666
"askconnect_accept" "#Valve_Accept_Redirect"
6767
"neo_mp3" "MP3 Player"
68+
"kdinfo_toggle" "Toggle killer damage info"
69+
"kdinfo_page_prev" "Killer damage info previous page"
70+
"kdinfo_page_next" "Killer damage info next page"
6871
"blank" "=========================="
6972
"blank" "#Valve_Miscellaneous_Keyboard_Keys_Title"
7073
"blank" "=========================="

game/neo/scripts/kb_def.lst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"w" "+forward"
3131
"y" "messagemode"
3232
"f" "+use"
33-
"p" "neo_mp3"
33+
"m" "neo_mp3"
3434
"ALT" "+walk"
3535
"CTRL" "+duck"
3636
"SHIFT" "+sprint"
@@ -44,6 +44,9 @@
4444
"F8" "joinstar 4"
4545
"F9" "joinstar 5"
4646
"F10" "joinstar 0"
47+
"F11" "kdinfo_toggle"
48+
"p" "kdinfo_page_prev"
49+
"n" "kdinfo_page_next"
4750
"MWHEELDOWN" "invprev"
4851
"MWHEELUP" "invnext"
4952
"MOUSE1" "+attack"

src/game/client/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,7 @@ target_sources_grouped(
15171517
neo/neo_fixup_glshaders.cpp
15181518
neo/neo_fixup_glshaders.h
15191519
neo/c_neo_bloom_controller.cpp
1520+
neo/c_neo_killer_damage_infos.h
15201521
)
15211522

15221523
target_sources_grouped(
@@ -1590,6 +1591,8 @@ target_sources_grouped(
15901591
neo/ui/neo_hud_ghost_cap_point.h
15911592
neo/ui/neo_hud_ghost_marker.cpp
15921593
neo/ui/neo_hud_ghost_marker.h
1594+
neo/ui/neo_hud_killer_damage_info.cpp
1595+
neo/ui/neo_hud_killer_damage_info.h
15931596
neo/ui/neo_hud_ghost_uplink_state.cpp
15941597
neo/ui/neo_hud_ghost_uplink_state.h
15951598
neo/ui/neo_hud_health_thermoptic_aux.cpp
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
static constexpr const int WEP_NAME_MAXSTRLEN = 32;
4+
5+
struct CNEOKillerInfo
6+
{
7+
int iEntIndex;
8+
int iClass;
9+
int iHP;
10+
float flDistance;
11+
wchar_t wszKilledWith[WEP_NAME_MAXSTRLEN];
12+
};
13+
14+
struct CNEOKillerDamageInfos
15+
{
16+
bool bHasDmgInfos = false;
17+
CNEOKillerInfo killerInfo;
18+
wchar_t wszKillerName[MAX_PLAYER_NAME_LENGTH + 1];
19+
size_t iKillerNameSize = 0;
20+
};
21+
22+
// Global instance of CNEOKillerDamageInfos
23+
inline CNEOKillerDamageInfos g_neoKDmgInfos;

src/game/client/neo/c_neo_player.cpp

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#include <materialsystem/itexture.h>
4747
#include "rendertexture.h"
4848
#include "ivieweffects.h"
49+
#include "c_neo_killer_damage_infos.h"
50+
#include <vgui/ILocalize.h>
51+
#include <tier3.h>
4952

5053
#include "model_types.h"
5154

@@ -142,18 +145,52 @@ static void __MsgFunc_DamageInfo(bf_read& msg)
142145

143146
static const char* BORDER = "==========================\n";
144147
bool setKillByLine = false;
148+
149+
V_memset(&g_neoKDmgInfos, 0, sizeof(CNEOKillerDamageInfos));
150+
g_neoKDmgInfos.bHasDmgInfos = true;
151+
145152
if (killerIdx > 0 && killerIdx <= gpGlobals->maxClients)
146153
{
147154
auto *neoAttacker = assert_cast<C_NEO_Player*>(UTIL_PlayerByIndex(killerIdx));
148155
if (neoAttacker && neoAttacker->entindex() != thisIdx)
149156
{
150-
KillerLineStr(killByLine, sizeof(killByLine), neoAttacker, localPlayer, foundKilledBy ? killedBy : NULL);
157+
g_pVGuiLocalize->ConvertANSIToUnicode(neoAttacker->GetNeoPlayerName(),
158+
g_neoKDmgInfos.wszKillerName,
159+
sizeof(g_neoKDmgInfos.wszKillerName));
160+
g_neoKDmgInfos.iKillerNameSize = V_wcslen(g_neoKDmgInfos.wszKillerName);
161+
}
162+
// If not neoAttacker, already cleared out by memset earlier
163+
164+
if (neoAttacker && neoAttacker->entindex() != thisIdx)
165+
{
166+
CNEOKillerInfo killerInfo = {
167+
.iEntIndex = killerIdx,
168+
.iClass = neoAttacker->GetClass(),
169+
.iHP = neoAttacker->GetHealth(),
170+
.flDistance = METERS_PER_INCH * neoAttacker->GetAbsOrigin().DistTo(localPlayer->GetAbsOrigin()),
171+
};
172+
g_neoKDmgInfos.killerInfo = killerInfo;
173+
if (foundKilledBy)
174+
{
175+
g_pVGuiLocalize->ConvertANSIToUnicode(killedBy,
176+
g_neoKDmgInfos.killerInfo.wszKilledWith,
177+
sizeof(g_neoKDmgInfos.killerInfo.wszKilledWith));
178+
}
179+
else
180+
{
181+
g_neoKDmgInfos.killerInfo.wszKilledWith[0] = L'\0';
182+
}
183+
184+
V_sprintf_safe(killByLine, "Killed by: %s [%s | %d hp] with %s at %.0f m\n",
185+
neoAttacker->GetNeoPlayerName(), GetNeoClassName(killerInfo.iClass),
186+
killerInfo.iHP, foundKilledBy ? killedBy : "", killerInfo.flDistance);
151187
setKillByLine = true;
152188
}
153189
}
154190

155191
ConMsg("%sDamage infos (Round %d):\n%s\n", BORDER, NEORules()->roundNumber(), setKillByLine ? killByLine : "");
156192

193+
// NEO TODO (nullsystem): Fill pHudKillerDmgInfo CNEOHud_KillerDamageInfo infos
157194
for (int pIdx = 1; pIdx <= gpGlobals->maxClients; ++pIdx)
158195
{
159196
if (pIdx == thisIdx)
@@ -183,8 +220,25 @@ static void __MsgFunc_DamageInfo(bf_read& msg)
183220
{
184221
const char *dmgerClass = GetNeoClassName(neoAttacker->GetClass());
185222

186-
static char infoLine[128];
187-
DmgLineStr(infoLine, sizeof(infoLine), dmgerName, dmgerClass, attackerInfo);
223+
char infoLine[128];
224+
if (totals.dealtDmgs > 0 && totals.takenDmgs > 0)
225+
{
226+
V_sprintf_safe(infoLine, "%s [%s]: Dealt: %d in %d hits | Taken: %d in %d hits\n",
227+
dmgerName, dmgerClass,
228+
totals.dealtDmgs, totals.dealtHits, totals.takenDmgs, totals.takenHits);
229+
}
230+
else if (totals.dealtDmgs > 0)
231+
{
232+
V_sprintf_safe(infoLine, "%s [%s]: Dealt: %d in %d hits\n",
233+
dmgerName, dmgerClass,
234+
totals.dealtDmgs, totals.dealtHits);
235+
}
236+
else if (totals.takenDmgs > 0)
237+
{
238+
V_sprintf_safe(infoLine, "%s [%s]: Taken: %d in %d hits\n",
239+
dmgerName, dmgerClass,
240+
totals.takenDmgs, totals.takenHits);
241+
}
188242
ConMsg("%s", infoLine);
189243

190244
totals += attackerInfo;
@@ -1524,6 +1578,8 @@ void C_NEO_Player::Spawn( void )
15241578
{
15251579
BaseClass::Spawn();
15261580

1581+
g_neoKDmgInfos.bHasDmgInfos = false;
1582+
15271583
m_bLastTickInThermOpticCamo = m_bInThermOpticCamo = false;
15281584
m_flCamoAuxLastTime = 0;
15291585

@@ -1543,6 +1599,7 @@ void C_NEO_Player::Spawn( void )
15431599
{
15441600
m_rfAttackersHits.Set(i, 0);
15451601
}
1602+
V_memset(m_rfNeoPlayerIdxsKilledByLocal, 0, sizeof(m_rfNeoPlayerIdxsKilledByLocal));
15461603

15471604
Weapon_SetZoom(false);
15481605

src/game/client/neo/c_neo_player.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ class C_NEO_Player : public C_HL2MP_Player
233233
mutable char m_szNeoNameWDupeIdx[MAX_PLAYER_NAME_LENGTH + 10];
234234
mutable int m_szNeoNameLocalDupeIdx;
235235

236+
public:
237+
bool m_rfNeoPlayerIdxsKilledByLocal[MAX_PLAYERS + 1];
238+
236239
private:
237240
C_NEO_Player(const C_NEO_Player &);
238241
};

src/game/client/neo/ui/neo_hud_deathnotice.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "neo_hud_childelement.h"
2323
#include "spectatorgui.h"
2424
#include "takedamageinfo.h"
25+
#include "c_neo_killer_damage_infos.h"
2526

2627
// memdbgon must be the last include file in a .cpp file!!!
2728
#include "tier0/memdbgon.h"
@@ -797,6 +798,12 @@ void CNEOHud_DeathNotice::AddPlayerDeath(IGameEvent* event)
797798
const char* deathIcon = event->GetString("deathIcon");
798799
g_pVGuiLocalize->ConvertANSIToUnicode(deathIcon, deathMsg.szDeathIcon, sizeof(deathMsg.szDeathIcon));
799800
deathMsg.bInvolved = killer == GetLocalPlayerIndex() || victim == GetLocalPlayerIndex() || assist == GetLocalPlayerIndex();
801+
Assert(victim >= 0 && victim < (MAX_PLAYERS + 1));
802+
C_NEO_Player *localPlayer = C_NEO_Player::GetLocalNEOPlayer();
803+
if (localPlayer)
804+
{
805+
localPlayer->m_rfNeoPlayerIdxsKilledByLocal[victim] = (killer == localPlayer->entindex());
806+
}
800807

801808
SetDeathNoticeItemDimensions(&deathMsg);
802809

@@ -977,4 +984,4 @@ void CNEOHud_DeathNotice::Paint()
977984
{
978985
BaseClass::Paint();
979986
PaintNeoElement();
980-
}
987+
}

0 commit comments

Comments
 (0)