Sort scoreboard

First, the team with more points, then which team scored points faster
1008-fix
tomangelo2 2018-03-07 15:46:30 +01:00
parent adda82819c
commit ff0f22ef44
3 changed files with 30 additions and 10 deletions

View File

@ -4963,7 +4963,7 @@ Error CRobotMain::ProcessEndMissionTake()
{ {
if (!details.empty()) if (!details.empty())
details += ", "; details += ", ";
details += StrUtils::Format(details_line.c_str(), GetTeamName(team).c_str(), m_scoreboard->GetScore(team)); details += StrUtils::Format(details_line.c_str(), GetTeamName(team).c_str(), m_scoreboard->GetScore(team).points);
} }
m_ui->GetDialog()->StartInformation( m_ui->GetDialog()->StartInformation(
title, title,
@ -5870,7 +5870,7 @@ void CRobotMain::CreateCodeBattleInterface()
: static_cast<Ui::CControl*>(pw->CreateEdit( pos, ddim, 0, static_cast<EventType>(EVENT_SCOREBOARD+2*(numTeams-i-1)+1))); : static_cast<Ui::CControl*>(pw->CreateEdit( pos, ddim, 0, static_cast<EventType>(EVENT_SCOREBOARD+2*(numTeams-i-1)+1)));
pl->SetTextAlign(Gfx::TEXT_ALIGN_RIGHT); pl->SetTextAlign(Gfx::TEXT_ALIGN_RIGHT);
pl->SetFontSize(m_codeBattleStarted ? Gfx::FONT_SIZE_SMALL : Gfx::FONT_SIZE_SMALL*0.75f); pl->SetFontSize(m_codeBattleStarted ? Gfx::FONT_SIZE_SMALL : Gfx::FONT_SIZE_SMALL*0.75f);
m_codeBattleStarted ? pl->SetName(StrUtils::ToString<int>(m_scoreboard->GetScore(team))) : static_cast<Ui::CEdit*>(pl)->SetText(StrUtils::ToString<int>(m_scoreboard->GetScore(team))); m_codeBattleStarted ? pl->SetName(StrUtils::ToString<int>(m_scoreboard->GetScore(team).points)) : static_cast<Ui::CEdit*>(pl)->SetText(StrUtils::ToString<int>(m_scoreboard->GetScore(team).points));
pos.x -= 57.5f/640.0f; pos.x -= 57.5f/640.0f;
pos.y += ddim.y; pos.y += ddim.y;
i++; i++;
@ -5910,9 +5910,18 @@ void CRobotMain::UpdateCodeBattleInterface()
Ui::CWindow* pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW6)); Ui::CWindow* pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW6));
assert(pw != nullptr); assert(pw != nullptr);
std::set<int> teams = GetAllTeams();
std::vector<int> sortedTeams(teams.begin(), teams.end());
std::sort(sortedTeams.begin(), sortedTeams.end(), [this](int teamA, int teamB)
{
if (m_scoreboard->GetScore(teamA).points > m_scoreboard->GetScore(teamB).points) return true; //Team A have more points than B?
if (m_scoreboard->GetScore(teamA).points < m_scoreboard->GetScore(teamB).points) return false; //Team A have less points than B?
if (m_scoreboard->GetScore(teamA).time < m_scoreboard->GetScore(teamB).time) return true; //Team A scored faster than B?
else return false; //Team A scored slower than B?
});
int i = 0; int i = 0;
for (int team : GetAllTeams()) for (int team : sortedTeams)
{ {
Ui::CControl* pl; Ui::CControl* pl;
@ -5922,7 +5931,7 @@ void CRobotMain::UpdateCodeBattleInterface()
pl = pw->SearchControl(static_cast<EventType>(EVENT_SCOREBOARD+2*i+1)); pl = pw->SearchControl(static_cast<EventType>(EVENT_SCOREBOARD+2*i+1));
assert(pl != nullptr); assert(pl != nullptr);
pl->SetName(StrUtils::ToString<int>(m_scoreboard->GetScore(team))); pl->SetName(StrUtils::ToString<int>(m_scoreboard->GetScore(team).points));
i++; i++;
} }

View File

@ -99,15 +99,16 @@ void CScoreboard::AddPoints(int team, int points)
text = StrUtils::Format(text.c_str(), main->GetTeamName(team).c_str(), points); text = StrUtils::Format(text.c_str(), main->GetTeamName(team).c_str(), points);
main->GetDisplayText()->DisplayText(text.c_str(), Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 10.0f, Ui::TT_WARNING); main->GetDisplayText()->DisplayText(text.c_str(), Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 10.0f, Ui::TT_WARNING);
m_score[team] += points; m_score[team].points += points;
m_score[team].time = main->GetGameTime();
} }
int CScoreboard::GetScore(int team) Score CScoreboard::GetScore(int team)
{ {
return m_score[team]; return m_score[team];
} }
void CScoreboard::SetScore(int team, int points) void CScoreboard::SetScore(int team, int points)
{ {
m_score[team] = points; m_score[team].points = points;
} }

View File

@ -32,6 +32,16 @@
class CObject; class CObject;
/**
* \struct Score
* \brief Struct containing score of individual team and additional variables to allow sorting teams through different criteria
*/
struct Score
{
int points = 0; //! Team score
float time = 0; //! Time when points were scored
};
/** /**
* \class CScoreboard * \class CScoreboard
* \brief Scoreboard used to score complex code battles * \brief Scoreboard used to score complex code battles
@ -114,12 +124,12 @@ public:
void ProcessEndTake(int team); void ProcessEndTake(int team);
void AddPoints(int team, int points); void AddPoints(int team, int points);
int GetScore(int team); Score GetScore(int team);
void SetScore(int team, int score); void SetScore(int team, int score);
private: private:
std::vector<std::unique_ptr<CScoreboardKillRule>> m_rulesKill = {}; std::vector<std::unique_ptr<CScoreboardKillRule>> m_rulesKill = {};
std::vector<std::unique_ptr<CScoreboardEndTakeRule>> m_rulesEndTake = {}; std::vector<std::unique_ptr<CScoreboardEndTakeRule>> m_rulesEndTake = {};
std::map<int, int> m_score; std::map<int, Score> m_score;
int m_finishCounter = 0; int m_finishCounter = 0;
}; };