1 #include <battlefield.h>
5 #include <battlefield/gamestat.h>
7 #include <battlefield/playerstats.h>
9 std::unordered_map<std::string, Battlefield::PlayerStats::SetterFunc> Battlefield::PlayerStats::SetterMap = {
10 {
"pph", &Battlefield::PlayerStats::SetPPH },
11 {
"vehicles", &Battlefield::PlayerStats::SetVehiclesDestroyed },
12 {
"lavd", &Battlefield::PlayerStats::SetLAVsDestroyed },
13 {
"mavd", &Battlefield::PlayerStats::SetMAVsDestroyed },
14 {
"havd", &Battlefield::PlayerStats::SetHAVsDestroyed },
15 {
"hed", &Battlefield::PlayerStats::SetHelicoptersDestroyed },
16 {
"bod", &Battlefield::PlayerStats::SetBoatsDestroyed },
17 {
"kills", &Battlefield::PlayerStats::SetKills },
18 {
"deaths", &Battlefield::PlayerStats::SetDeaths },
19 {
"k1", &Battlefield::PlayerStats::SetKillsAssualtKit },
20 {
"s1", &Battlefield::PlayerStats::SetDeathsAssualtKit },
21 {
"k2", &Battlefield::PlayerStats::SetKillsSniperKit },
22 {
"s2", &Battlefield::PlayerStats::SetDeathsSniperKit },
23 {
"k3", &Battlefield::PlayerStats::SetKillsSpecialOpKit },
24 {
"s3", &Battlefield::PlayerStats::SetDeathsSpecialOpKit },
25 {
"k4", &Battlefield::PlayerStats::SetKillsCombatEngineerKit },
26 {
"s4", &Battlefield::PlayerStats::SetDeathsCombatEngineerKit },
27 {
"k5", &Battlefield::PlayerStats::SetKillsSupportKit },
28 {
"s5", &Battlefield::PlayerStats::SetDeathsSupportKit },
33 this->SetScore(41476);
34 this->SetRank(Ranks::Five_Star_General);
36 this->SetKills(31848);
37 this->SetDeaths(26394);
38 this->SetSuicides(41);
39 this->SetTime(3627752);
40 this->SetVehiclesDestroyed(818);
41 this->SetLAVsDestroyed(342);
42 this->SetMAVsDestroyed(182);
43 this->SetHAVsDestroyed(118);
44 this->SetHelicoptersDestroyed(173);
45 this->SetBoatsDestroyed(3);
46 this->SetKillsAssualtKit(20880);
47 this->SetDeathsAssualtKit(16556);
48 this->SetKillsSniperKit(7445);
49 this->SetDeathsSniperKit(4790);
50 this->SetKillsSpecialOpKit(2364);
51 this->SetDeathsSpecialOpKit(3286);
52 this->SetKillsCombatEngineerKit(730);
53 this->SetDeathsCombatEngineerKit(1411);
54 this->SetKillsSupportKit(414);
55 this->SetDeathsSupportKit(351);
56 this->SetMedals(Medals::All);
57 this->SetTotalTopPlayer(56);
58 this->SetTotalVictories(1202);
59 this->SetTotalGameSessions(3613);
62 double Battlefield::PlayerStats::GetRatio()
const
64 if(this->_kills == 0 or this->_deaths == 0)
69 return static_cast<double>(this->_kills * 100) / this->_deaths;
72 double Battlefield::PlayerStats::GetRatioAssualtKit()
const
74 if(this->_k1 == 0 or this->_s1 == 0)
79 return static_cast<double>(this->_k1 * 100) / this->_s1;
82 double Battlefield::PlayerStats::GetRatioSniperKit()
const
84 if(this->_k2 == 0 or this->_s2 == 0)
89 return static_cast<double>(this->_k2 * 100) / this->_s2;
92 double Battlefield::PlayerStats::GetRatioSpecialOpKit()
const
94 if(this->_k3 == 0 or this->_s3 == 0)
99 return static_cast<double>(this->_k3 * 100) / this->_s3;
102 double Battlefield::PlayerStats::GetRatioCombatEngineerKit()
const
104 if(this->_k4 == 0 or this->_s4 == 0)
109 return static_cast<double>(this->_k4 * 100) / this->_s4;
112 double Battlefield::PlayerStats::GetRatioSupportKit()
const
114 if(this->_k5 == 0 or this->_s5 == 0)
119 return static_cast<double>(this->_k5 * 100) / this->_s5;
122 bool Battlefield::PlayerStats::SetScore(int32_t score)
124 this->_score = score;
131 bool Battlefield::PlayerStats::SetRank(uint32_t ran)
133 if(ran >=
static_cast<uint8_t
>(Ranks::Private) && ran <=
static_cast<uint8_t
>(Ranks::Five_Star_General))
143 bool Battlefield::PlayerStats::SetRank(Ranks ran)
145 this->_ran =
static_cast<uint8_t
>(ran);
149 bool Battlefield::PlayerStats::SetPPH(uint32_t pph)
158 bool Battlefield::PlayerStats::SetKills(uint32_t kills)
160 this->_kills = kills;
164 bool Battlefield::PlayerStats::SetDeaths(uint32_t deaths)
166 this->_deaths = deaths;
170 bool Battlefield::PlayerStats::SetSuicides(uint32_t suicides)
172 this->_suicides = suicides;
176 bool Battlefield::PlayerStats::SetTime(uint32_t time)
182 bool Battlefield::PlayerStats::SetVehiclesDestroyed(uint32_t vehicles)
184 this->_vehicles = vehicles;
188 bool Battlefield::PlayerStats::SetLAVsDestroyed(uint32_t lavd)
194 bool Battlefield::PlayerStats::SetMAVsDestroyed(uint32_t mavd)
200 bool Battlefield::PlayerStats::SetHAVsDestroyed(uint32_t havd)
206 bool Battlefield::PlayerStats::SetHelicoptersDestroyed(uint32_t hed)
212 bool Battlefield::PlayerStats::SetBoatsDestroyed(uint32_t bod)
218 bool Battlefield::PlayerStats::SetKillsAssualtKit(uint32_t kills)
224 bool Battlefield::PlayerStats::SetDeathsAssualtKit(uint32_t deaths)
230 bool Battlefield::PlayerStats::SetKillsSniperKit(uint32_t kills)
236 bool Battlefield::PlayerStats::SetDeathsSniperKit(uint32_t deaths)
242 bool Battlefield::PlayerStats::SetKillsSpecialOpKit(uint32_t kills)
248 bool Battlefield::PlayerStats::SetDeathsSpecialOpKit(uint32_t deaths)
254 bool Battlefield::PlayerStats::SetKillsCombatEngineerKit(uint32_t kills)
260 bool Battlefield::PlayerStats::SetDeathsCombatEngineerKit(uint32_t deaths)
266 bool Battlefield::PlayerStats::SetKillsSupportKit(uint32_t kills)
272 bool Battlefield::PlayerStats::SetDeathsSupportKit(uint32_t deaths)
278 bool Battlefield::PlayerStats::SetMedals(uint32_t medals)
280 if(medals <=
static_cast<uint32_t
>(Medals::All) && Util::countSetBits(medals) > Util::countSetBits(this->_medals))
282 this->_medals = medals;
292 bool Battlefield::PlayerStats::SetMedals(Medals medals)
294 return this->SetMedals(
static_cast<uint32_t
>(medals));
297 bool Battlefield::PlayerStats::SetTotalTopPlayer(uint32_t total)
303 bool Battlefield::PlayerStats::SetTotalVictories(uint32_t total)
309 bool Battlefield::PlayerStats::SetTotalGameSessions(uint32_t total)
315 bool Battlefield::PlayerStats::SetCapturedFlags(uint32_t cflags)
317 this->_cflags = cflags;
321 bool Battlefield::PlayerStats::SetNeutralizedFlags(uint32_t nflags)
323 this->_nflags = nflags;
327 bool Battlefield::PlayerStats::SetSavedFlags(uint32_t sflags)
329 this->_sflags = sflags;
336 this->_calcNewPPH(gsplayer.GetTime(), gsplayer.GetScore());
338 this->SetBoatsDestroyed( this->_bod + gsplayer.GetBoatsDestroyed() );
339 this->SetHAVsDestroyed( this->_havd + gsplayer.GetHAVsDestroyed() );
340 this->SetHelicoptersDestroyed( this->_hed + gsplayer.GetHelicoptersDestroyed() );
341 this->SetKillsAssualtKit( this->_k1 + gsplayer.GetKillsAssualtKit() );
342 this->SetKillsSniperKit( this->_k2 + gsplayer.GetKillsSniperKit() );
343 this->SetKillsSpecialOpKit( this->_k3 + gsplayer.GetKillsSpecialOpKit() );
344 this->SetKillsCombatEngineerKit( this->_k4 + gsplayer.GetKillsCombatEngineerKit() );
345 this->SetKillsSupportKit( this->_k5 + gsplayer.GetKillsSupportKit() );
346 this->SetKills( this->_kills + gsplayer.GetKills() );
347 this->SetDeaths( this->_deaths + gsplayer.GetDeaths() );
348 this->SetLAVsDestroyed( this->_lavd + gsplayer.GetLAVsDestroyed() );
349 this->SetMAVsDestroyed( this->_mavd + gsplayer.GetMAVsDestroyed() );
350 this->SetTotalVictories( this->_mv + gsplayer.GetTotalVictories() );
351 this->SetTotalGameSessions( this->_ngp + gsplayer.GetTotalGameSessions() );
352 this->SetDeathsAssualtKit( this->_s1 + gsplayer.GetSpawnsAssualtKit() );
353 this->SetDeathsSniperKit( this->_s2 + gsplayer.GetSpawnsSniperKit() );
354 this->SetDeathsSpecialOpKit( this->_s3 + gsplayer.GetSpawnsSpecialOpKit() );
355 this->SetDeathsCombatEngineerKit( this->_s4 + gsplayer.GetSpawnsCombatEngineerKit() );
356 this->SetDeathsSupportKit( this->_s5 + gsplayer.GetSpawnsSupportKit() );
357 this->SetScore( this->_score + gsplayer.GetScore() );
358 this->SetSuicides( this->_suicides + gsplayer.GetSuicides() );
359 this->SetTime( this->_time + gsplayer.GetTime() );
360 this->SetTotalTopPlayer( this->_ttb + gsplayer.GetTotalTopPlayer() );
361 this->SetCapturedFlags( this->_cflags + gsplayer.GetCapturedFlags() );
362 this->SetNeutralizedFlags( this->_nflags + gsplayer.GetNeutralizedFlags() );
363 this->SetSavedFlags( this->_sflags + gsplayer.GetSavedFlags() );
365 this->SetVehiclesDestroyed(
373 this->SetMedals(gsplayer.GetMedals());
378 int pph = this->_pph / 100;
379 int total_medals = Util::countSetBits(this->_medals);
382 for(
int i = 1; i < RankScores.size(); i++)
384 if(this->_score >= RankScores[i] && pph >= RankPph[i] && total_medals >= RankMedals[i])
390 this->_ran = new_rank;
395 const int PPH_TIME_SPAN = 5;
396 const int PPH_FACTOR = 100;
397 const int SECONDS_PER_HOUR = 60 * 60;
399 double total_hours =
static_cast<double>(this->_time + time) / SECONDS_PER_HOUR;
400 int32_t total_score = this->_score + score;
402 uint32_t new_pph = 0;
405 if(total_hours < 1.0)
407 new_pph = total_score * 100;
410 else if(total_hours < PPH_TIME_SPAN)
413 double new_pph_double =
static_cast<double>(total_score) / total_hours;
416 new_pph =
static_cast<uint32_t
>(new_pph_double * 100.0);
422 double current_pph =
static_cast<double>(this->_pph) / 100.0;
425 double game_time_hours =
static_cast<double>(time) / SECONDS_PER_HOUR;
428 double gap_time_span =
static_cast<double>(PPH_TIME_SPAN) - game_time_hours;
431 double total_score = gap_time_span * current_pph;
432 total_score +=
static_cast<double>(score);
435 double new_pph_double = total_score / PPH_TIME_SPAN;
438 new_pph =
static_cast<uint32_t
>(new_pph_double * 100.0);
442 this->SetPPH(new_pph);
Represents a player's statistics in a game.
void useExample()
Performs an example operation using the PlayerStats class.
void _calcNewPPH(uint32_t time, int32_t score)
Calculates the pph based on game time, game score and current player stats.
void _calcRank()
Calculates the rank based on score, points per hour (pph), and medals.
void Update(const Battlefield::GameStatPlayer &gsplayer)
Update player stats based on played game.