mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 10:37:02 +00:00
[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:
parent
8d7f6e5e0a
commit
3557b00a13
3 changed files with 26 additions and 25 deletions
|
|
@ -502,20 +502,16 @@ 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));
|
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
|
if (int32(stats.rating) + mod < 0)
|
||||||
//'chance' calculation - to beat the opponent
|
stats.rating = 0;
|
||||||
float chance = GetChanceAgainst(stats.rating,againstRating);
|
else
|
||||||
// calculate the rating modification (ELO system with k=32)
|
stats.rating += mod;
|
||||||
int32 mod = (int32)floor(32.0f * (1.0f - chance));
|
|
||||||
// modify the team stats accordingly
|
|
||||||
stats.rating += mod;
|
|
||||||
stats.games_week += 1;
|
stats.games_week += 1;
|
||||||
stats.wins_week += 1;
|
|
||||||
stats.games_season += 1;
|
stats.games_season += 1;
|
||||||
stats.wins_season += 1;
|
// update team's rank
|
||||||
//update team's rank
|
|
||||||
stats.rank = 1;
|
stats.rank = 1;
|
||||||
ObjectMgr::ArenaTeamMap::const_iterator i = objmgr.GetArenaTeamMapBegin();
|
ObjectMgr::ArenaTeamMap::const_iterator i = objmgr.GetArenaTeamMapBegin();
|
||||||
for ( ; i != objmgr.GetArenaTeamMapEnd(); ++i)
|
for ( ; i != objmgr.GetArenaTeamMapEnd(); ++i)
|
||||||
|
|
@ -524,6 +520,21 @@ int32 ArenaTeam::WonAgainst(uint32 againstRating)
|
||||||
++stats.rank;
|
++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 the rating change, used to display it on the results screen
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
@ -532,22 +543,11 @@ int32 ArenaTeam::LostAgainst(uint32 againstRating)
|
||||||
{
|
{
|
||||||
// called when the team has lost
|
// called when the team has lost
|
||||||
//'chance' calculation - to loose to the opponent
|
//'chance' calculation - to loose to the opponent
|
||||||
float chance = GetChanceAgainst(stats.rating,againstRating);
|
float chance = GetChanceAgainst(stats.rating, againstRating);
|
||||||
// calculate the rating modification (ELO system with k=32)
|
// calculate the rating modification (ELO system with k=32)
|
||||||
int32 mod = (int32)ceil(32.0f * (0.0f - chance));
|
int32 mod = (int32)ceil(32.0f * (0.0f - chance));
|
||||||
// modify the team stats accordingly
|
// modify the team stats accordingly
|
||||||
stats.rating += mod;
|
FinishGame(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the rating change, used to display it on the results screen
|
// return the rating change, used to display it on the results screen
|
||||||
return mod;
|
return mod;
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,7 @@ class ArenaTeam
|
||||||
void NotifyStatsChanged();
|
void NotifyStatsChanged();
|
||||||
|
|
||||||
void FinishWeek();
|
void FinishWeek();
|
||||||
|
void FinishGame(int32 mod);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "8266"
|
#define REVISION_NR "8267"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue