[8267] ArenaTeam: added check, that teamrating won't become negative

for this i added a FinishGame(mod) function
which also updates other stats, to avoid
redundant code

Signed-off-by: balrok <der-coole-carl@gmx.net>
This commit is contained in:
balrok 2009-07-28 16:49:42 +02:00
parent 8d7f6e5e0a
commit 3557b00a13
3 changed files with 26 additions and 25 deletions

View file

@ -502,19 +502,15 @@ float ArenaTeam::GetChanceAgainst(uint32 own_rating, uint32 enemy_rating)
return 1.0f/(1.0f+exp(log(10.0f)*(float)((float)enemy_rating - (float)own_rating)/400.0f));
}
int32 ArenaTeam::WonAgainst(uint32 againstRating)
void ArenaTeam::FinishGame(int32 mod)
{
// called when the team has won
//'chance' calculation - to beat the opponent
float chance = GetChanceAgainst(stats.rating,againstRating);
// calculate the rating modification (ELO system with k=32)
int32 mod = (int32)floor(32.0f * (1.0f - chance));
// modify the team stats accordingly
if (int32(stats.rating) + mod < 0)
stats.rating = 0;
else
stats.rating += mod;
stats.games_week += 1;
stats.wins_week += 1;
stats.games_season += 1;
stats.wins_season += 1;
// update team's rank
stats.rank = 1;
ObjectMgr::ArenaTeamMap::const_iterator i = objmgr.GetArenaTeamMapBegin();
@ -524,6 +520,21 @@ int32 ArenaTeam::WonAgainst(uint32 againstRating)
++stats.rank;
}
}
int32 ArenaTeam::WonAgainst(uint32 againstRating)
{
// called when the team has won
//'chance' calculation - to beat the opponent
float chance = GetChanceAgainst(stats.rating, againstRating);
// calculate the rating modification (ELO system with k=32)
int32 mod = (int32)floor(32.0f * (1.0f - chance));
// modify the team stats accordingly
FinishGame(mod);
stats.wins_week += 1;
stats.wins_season += 1;
// return the rating change, used to display it on the results screen
return mod;
}
@ -536,18 +547,7 @@ int32 ArenaTeam::LostAgainst(uint32 againstRating)
// calculate the rating modification (ELO system with k=32)
int32 mod = (int32)ceil(32.0f * (0.0f - chance));
// modify the team stats accordingly
stats.rating += mod;
stats.games_week += 1;
stats.games_season += 1;
//update team's rank
stats.rank = 1;
ObjectMgr::ArenaTeamMap::const_iterator i = objmgr.GetArenaTeamMapBegin();
for ( ; i != objmgr.GetArenaTeamMapEnd(); ++i)
{
if (i->second->GetType() == this->Type && i->second->GetStats().rating > stats.rating)
++stats.rank;
}
FinishGame(mod);
// return the rating change, used to display it on the results screen
return mod;

View file

@ -205,6 +205,7 @@ class ArenaTeam
void NotifyStatsChanged();
void FinishWeek();
void FinishGame(int32 mod);
protected:

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "8266"
#define REVISION_NR "8267"
#endif // __REVISION_NR_H__