Skip to content
9 changes: 2 additions & 7 deletions game/neo/scripts/HudLayout.res
Original file line number Diff line number Diff line change
Expand Up @@ -998,14 +998,9 @@
"tall" "200"
}

neo_killer_damage_info
neo_killer_info
{
"fieldName" "neo_killer_damage_info"
"xpos" "20"
"ypos" "150"
"wide" "640"
"tall" "480"
"box_color" "150 150 150 60"
"fieldName" "neo_killer_info"
}

neo_context_hint
Expand Down
5 changes: 2 additions & 3 deletions src/game/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1574,8 +1574,7 @@ set(UNITY_SOURCE_NEO_SRC_CLIENT
neo/c_neo_te_tocflash.cpp
neo/neo_fixup_glshaders.cpp
neo/c_neo_bloom_controller.cpp
neo/neo_killer_damage_info.cpp
neo/c_neo_killer_infos.cpp
neo/c_neo_killer_damage_infos.cpp
)

set_source_files_properties(
Expand All @@ -1592,7 +1591,7 @@ target_sources_grouped(
neo/c_neo_player.h
neo/c_neo_te_tocflash.h
neo/neo_fixup_glshaders.h
neo/c_neo_killer_infos.h
neo/c_neo_killer_damage_infos.h
${UNITY_SOURCE_NEO_SRC_CLIENT}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "c_neo_killer_damage_infos.h"

#include <cbase.h>
#include "strtools.h"

#include "c_neo_player.h"
#include "neo_gamerules.h"
Expand All @@ -8,6 +11,114 @@
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

static inline AttackersTotals gTotals;
static const char *BORDER = "==========================\n";

void NeoUserIDsLocalKilledClear()
{
g_neoUserIDsLocalKilledSize = 0;
V_memset(g_neoUserIDsLocalKilled, 0, sizeof(g_neoUserIDsLocalKilled));
}

void NeoDamageReportClear()
{
g_neoDamageReportSize = 0;
V_memset(g_neoDamageReport, 0, sizeof(g_neoDamageReport));
}

void NeoKillerInfoClear()
{
V_memset(&g_neoKillerInfos, 0, sizeof(CNEOKillerInfos));
}

void NeoAllKDReportsClear()
{
NeoDamageReportClear();
NeoUserIDsLocalKilledClear();
NeoKillerInfoClear();
}

static ENEOCompactMsgFlag ReadDamageReport(bf_read &msg)
{
// Read (server side) per-player damage stats
const int iAtkSize = Min(msg.ReadByte(), MAX_PLAYERS);
const ENEOCompactMsgFlag flags = static_cast<ENEOCompactMsgFlag>(msg.ReadByte());

for (int i = 0; i < iAtkSize; ++i)
{
AttackersTotals *pDmgReport = &g_neoDamageReport[g_neoDamageReportSize];
pDmgReport->iUserID = msg.ReadLong();

if (flags & NEO_COMPACT_MSG_FLAG_DMGS)
{
pDmgReport->iDealtDmgs = static_cast<unsigned char>(msg.ReadByte());
pDmgReport->iTakenDmgs = static_cast<unsigned char>(msg.ReadByte());
}
else
{
pDmgReport->iDealtDmgs = msg.ReadShort();
pDmgReport->iTakenDmgs = msg.ReadShort();
}

if (flags & NEO_COMPACT_MSG_FLAG_HITS)
{
pDmgReport->iDealtHits = static_cast<unsigned char>(msg.ReadByte());
pDmgReport->iTakenHits = static_cast<unsigned char>(msg.ReadByte());
}
else
{
pDmgReport->iDealtHits = msg.ReadShort();
pDmgReport->iTakenHits = msg.ReadShort();
}

auto *neoAttacker = USERID2NEOPLAYER(pDmgReport->iUserID);
if (!neoAttacker || neoAttacker->IsHLTV())
{
continue;
}

const char *dmgerName = neoAttacker->GetNeoPlayerName();
if (!dmgerName)
{
continue;
}

const char *dmgerClass = GetNeoClassName(neoAttacker->GetClass());

char infoLine[128] = {};
if (pDmgReport->iDealtDmgs > 0 && pDmgReport->iDealtHits > 0)
{
V_sprintf_safe(infoLine, "Damage dealt to %s [%s]: %d in %d hits\n",
dmgerName, dmgerClass,
pDmgReport->iDealtDmgs, pDmgReport->iDealtHits);
ConMsg("%s", infoLine);
gTotals.iDealtDmgs += pDmgReport->iDealtDmgs;
gTotals.iDealtHits += pDmgReport->iDealtHits;
}
if (pDmgReport->iTakenDmgs > 0 && pDmgReport->iTakenHits > 0)
{
V_sprintf_safe(infoLine, "Damage taken from %s [%s]: %d in %d hits\n",
dmgerName, dmgerClass,
pDmgReport->iTakenDmgs, pDmgReport->iTakenHits);
ConMsg("%s", infoLine);
gTotals.iTakenDmgs += pDmgReport->iTakenDmgs;
gTotals.iTakenHits += pDmgReport->iTakenHits;
}

++g_neoDamageReportSize;
}

return flags;
}

static void PrintTotalReport()
{
ConMsg("Total damage dealt: %d in %d hits\nTotal damage received from players: %d in %d hits\n%s\n",
gTotals.iDealtDmgs, gTotals.iDealtHits,
gTotals.iTakenDmgs, gTotals.iTakenHits,
BORDER);
}

// Console + activation of damage info
static void __MsgFunc_KillerDamageInfo(bf_read &msg)
{
Expand All @@ -23,17 +134,14 @@ static void __MsgFunc_KillerDamageInfo(bf_read &msg)

// Print damage stats into the console
// Print to console
AttackersTotals totals = {};

const int thisIdx = localPlayer->entindex();

// Can't rely on Msg as it can print out of order, so do it in chunks
static char killByLine[512];

static const char *BORDER = "==========================\n";
bool setKillByLine = false;

V_memset(&g_neoKillerInfos, 0, sizeof(CNEOKillerInfos));
NeoKillerInfoClear();
g_neoKillerInfos.bHasDmgInfos = true;

if (killerIdx > 0 && killerIdx <= gpGlobals->maxClients)
Expand Down Expand Up @@ -94,58 +202,22 @@ static void __MsgFunc_KillerDamageInfo(bf_read &msg)
}

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

for (int pIdx = 1; pIdx <= gpGlobals->maxClients; ++pIdx)
{
if (pIdx == thisIdx)
{
continue;
}

auto* neoAttacker = assert_cast<C_NEO_Player*>(UTIL_PlayerByIndex(pIdx));
if (!neoAttacker || neoAttacker->IsHLTV())
{
continue;
}

const char *dmgerName = neoAttacker->GetNeoPlayerName();
if (!dmgerName)
{
continue;
}

const AttackersTotals attackerInfo = {
.dealtDmgs = neoAttacker->GetAttackersScores(thisIdx),
.dealtHits = neoAttacker->GetAttackerHits(thisIdx),
.takenDmgs = localPlayer->GetAttackersScores(pIdx),
.takenHits = localPlayer->GetAttackerHits(pIdx),
};
if (attackerInfo.dealtDmgs > 0 || attackerInfo.takenDmgs > 0)
{
const char *dmgerClass = GetNeoClassName(neoAttacker->GetClass());

char infoLine[128] = {};
if (attackerInfo.dealtDmgs > 0)
{
V_sprintf_safe(infoLine, "Damage dealt to %s [%s]: %d in %d hits\n",
dmgerName, dmgerClass,
attackerInfo.dealtDmgs, attackerInfo.dealtHits);
}
if (attackerInfo.takenDmgs > 0)
{
V_sprintf_safe(infoLine, "Damage taken from %s [%s]: %d in %d hits\n",
dmgerName, dmgerClass,
attackerInfo.takenDmgs, attackerInfo.takenHits);
}
ConMsg("%s", infoLine);

totals += attackerInfo;
}
NeoDamageReportClear();
gTotals = {};
const ENEOCompactMsgFlag flags = ReadDamageReport(msg);
if (!(flags & NEO_COMPACT_MSG_FLAG_EXTRA))
{
PrintTotalReport();
}
}

ConMsg("Total damage dealt: %d in %d hits\nTotal damage received from players: %d in %d hits\n%s\n",
totals.dealtDmgs, totals.dealtHits,
totals.takenDmgs, totals.takenHits,
BORDER);
static void __MsgFunc_KillerDamageInfoExtra(bf_read &msg)
{
ReadDamageReport(msg);
PrintTotalReport();
}

USER_MESSAGE_REGISTER(KillerDamageInfo);
USER_MESSAGE_REGISTER(KillerDamageInfoExtra);

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "shareddefs.h"
#include "neo_player_shared.h"

static constexpr const int WEP_NAME_MAXSTRLEN = 32;

Expand All @@ -16,9 +17,16 @@ struct CNEOKillerInfos
};

void NeoUserIDsLocalKilledClear();
void NeoDamageReportClear();
void NeoKillerInfoClear();

void NeoAllKDReportsClear();

// Global instance of CNEOKillerInfos and local-player's kill record
inline CNEOKillerInfos g_neoKillerInfos;
inline int g_neoUserIDsLocalKilledSize;
inline int g_neoUserIDsLocalKilled[MAX_PLAYERS_ARRAY_SAFE];

inline int g_neoDamageReportSize;
inline AttackersTotals g_neoDamageReport[MAX_PLAYERS_ARRAY_SAFE];

10 changes: 0 additions & 10 deletions src/game/client/neo/c_neo_killer_infos.cpp

This file was deleted.

Loading