From 3c6b9049d1406af3815331507261ae65d8d60bb1 Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Sun, 24 Nov 2024 17:40:03 +0300 Subject: [PATCH] CRoundStatistics::CPlayerStats: Turn per-class scores into array --- src/engine/server/roundstatistics.cpp | 164 ++++++++------------------ src/engine/server/roundstatistics.h | 25 +--- 2 files changed, 51 insertions(+), 138 deletions(-) diff --git a/src/engine/server/roundstatistics.cpp b/src/engine/server/roundstatistics.cpp index 413fbbb84..8a9f7627d 100644 --- a/src/engine/server/roundstatistics.cpp +++ b/src/engine/server/roundstatistics.cpp @@ -9,125 +9,59 @@ int CRoundStatistics::CPlayerStats::OnScoreEvent(int EventType, EPlayerClass Cla int Points = 0; switch(EventType) { - case SCOREEVENT_HUMAN_SURVIVE: - Points = 50; - break; - case SCOREEVENT_HUMAN_SUICIDE: - Points = -10; - break; - case SCOREEVENT_INFECTION: - Points = 30; - break; - case SCOREEVENT_KILL_INFECTED: - Points = 10; - break; - case SCOREEVENT_KILL_TARGET: - Points = 20; - break; - case SCOREEVENT_KILL_WITCH: - Points = 50; - break; - case SCOREEVENT_KILL_UNDEAD: - Points = 50; - break; - case SCOREEVENT_DESTROY_TURRET: - Points = 10; - break; - case SCOREEVENT_HELP_FREEZE: - Points = 10; - break; - case SCOREEVENT_HELP_HOOK_BARRIER: - Points = 10; - break; - case SCOREEVENT_HELP_HOOK_INFECTION: - Points = 10; - break; - case SCOREEVENT_HUMAN_HEALING: - Points = 10; - break; - case SCOREEVENT_HERO_FLAG: - Points = 10; - break; - case SCOREEVENT_BONUS: - Points = 50; - break; - case SCOREEVENT_MEDIC_REVIVE: - Points = 50; - break; + case SCOREEVENT_HUMAN_SURVIVE: + Points = 50; + break; + case SCOREEVENT_HUMAN_SUICIDE: + Points = -10; + break; + case SCOREEVENT_INFECTION: + Points = 30; + break; + case SCOREEVENT_KILL_INFECTED: + Points = 10; + break; + case SCOREEVENT_KILL_TARGET: + Points = 20; + break; + case SCOREEVENT_KILL_WITCH: + Points = 50; + break; + case SCOREEVENT_KILL_UNDEAD: + Points = 50; + break; + case SCOREEVENT_DESTROY_TURRET: + Points = 10; + break; + case SCOREEVENT_HELP_FREEZE: + Points = 10; + break; + case SCOREEVENT_HELP_HOOK_BARRIER: + Points = 10; + break; + case SCOREEVENT_HELP_HOOK_INFECTION: + Points = 10; + break; + case SCOREEVENT_HUMAN_HEALING: + Points = 10; + break; + case SCOREEVENT_HERO_FLAG: + Points = 10; + break; + case SCOREEVENT_BONUS: + Points = 50; + break; + case SCOREEVENT_MEDIC_REVIVE: + Points = 50; + break; } m_Score += Points; - - switch(Class) + + int ClassIndex = static_cast(Class); + if(ClassIndex > 0 && ClassIndex < NB_PLAYERCLASS) { - case EPlayerClass::Engineer: - m_EngineerScore += Points; - break; - case EPlayerClass::Soldier: - m_SoldierScore += Points; - break; - case EPlayerClass::Scientist: - m_ScientistScore += Points; - break; - case EPlayerClass::Biologist: - m_BiologistScore += Points; - break; - case EPlayerClass::Looper: - m_LooperScore += Points; - break; - case EPlayerClass::Medic: - m_MedicScore += Points; - break; - case EPlayerClass::Hero: - m_HeroScore += Points; - break; - case EPlayerClass::Ninja: - m_NinjaScore += Points; - break; - case EPlayerClass::Mercenary: - m_MercenaryScore += Points; - break; - case EPlayerClass::Sniper: - m_SniperScore += Points; - break; - case EPlayerClass::Smoker: - m_SmokerScore += Points; - break; - case EPlayerClass::Hunter: - m_HunterScore += Points; - break; - case EPlayerClass::Bat: - m_BatScore += Points; - break; - case EPlayerClass::Boomer: - m_BoomerScore += Points; - break; - case EPlayerClass::Ghost: - m_GhostScore += Points; - break; - case EPlayerClass::Spider: - m_SpiderScore += Points; - break; - case EPlayerClass::Ghoul: - m_GhoulScore += Points; - break; - case EPlayerClass::Slug: - m_SlugScore += Points; - break; - case EPlayerClass::Voodoo: - m_VoodooScore += Points; - break; - case EPlayerClass::Undead: - m_UndeadScore += Points; - break; - case EPlayerClass::Witch: - m_WitchScore += Points; - break; - - case EPlayerClass::Invalid: - case EPlayerClass::None: - case EPlayerClass::Count: - break; + m_ClassScore[ClassIndex] += Points; } return Points; diff --git a/src/engine/server/roundstatistics.h b/src/engine/server/roundstatistics.h index e53f80fc8..8b191a654 100644 --- a/src/engine/server/roundstatistics.h +++ b/src/engine/server/roundstatistics.h @@ -4,7 +4,7 @@ #include #include -enum class EPlayerClass; +#include enum { @@ -32,28 +32,7 @@ class CRoundStatistics { public: int m_Score{}; - int m_EngineerScore{}; - int m_SoldierScore{}; - int m_ScientistScore{}; - int m_BiologistScore{}; - int m_LooperScore{}; - int m_MedicScore{}; - int m_HeroScore{}; - int m_NinjaScore{}; - int m_MercenaryScore{}; - int m_SniperScore{}; - - int m_SmokerScore{}; - int m_HunterScore{}; - int m_BatScore{}; - int m_BoomerScore{}; - int m_GhostScore{}; - int m_SpiderScore{}; - int m_GhoulScore{}; - int m_SlugScore{}; - int m_VoodooScore{}; - int m_UndeadScore{}; - int m_WitchScore{}; + int m_ClassScore[NB_PLAYERCLASS]{}; bool m_WasSpectator{}; bool m_Won{};