diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 3df62fe5..a19879af 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -4963,7 +4963,7 @@ Error CRobotMain::ProcessEndMissionTake() { if (!details.empty()) 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( title, @@ -5870,7 +5870,7 @@ void CRobotMain::CreateCodeBattleInterface() : static_cast(pw->CreateEdit( pos, ddim, 0, static_cast(EVENT_SCOREBOARD+2*(numTeams-i-1)+1))); pl->SetTextAlign(Gfx::TEXT_ALIGN_RIGHT); pl->SetFontSize(m_codeBattleStarted ? Gfx::FONT_SIZE_SMALL : Gfx::FONT_SIZE_SMALL*0.75f); - m_codeBattleStarted ? pl->SetName(StrUtils::ToString(m_scoreboard->GetScore(team))) : static_cast(pl)->SetText(StrUtils::ToString(m_scoreboard->GetScore(team))); + m_codeBattleStarted ? pl->SetName(StrUtils::ToString(m_scoreboard->GetScore(team).points)) : static_cast(pl)->SetText(StrUtils::ToString(m_scoreboard->GetScore(team).points)); pos.x -= 57.5f/640.0f; pos.y += ddim.y; i++; @@ -5910,9 +5910,18 @@ void CRobotMain::UpdateCodeBattleInterface() Ui::CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); assert(pw != nullptr); - + std::set teams = GetAllTeams(); + std::vector 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; - for (int team : GetAllTeams()) + for (int team : sortedTeams) { Ui::CControl* pl; @@ -5922,7 +5931,7 @@ void CRobotMain::UpdateCodeBattleInterface() pl = pw->SearchControl(static_cast(EVENT_SCOREBOARD+2*i+1)); assert(pl != nullptr); - pl->SetName(StrUtils::ToString(m_scoreboard->GetScore(team))); + pl->SetName(StrUtils::ToString(m_scoreboard->GetScore(team).points)); i++; } diff --git a/src/level/scoreboard.cpp b/src/level/scoreboard.cpp index 7e4b5b04..83b74fe1 100644 --- a/src/level/scoreboard.cpp +++ b/src/level/scoreboard.cpp @@ -99,15 +99,16 @@ void CScoreboard::AddPoints(int team, int 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); - 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]; } void CScoreboard::SetScore(int team, int points) { - m_score[team] = points; + m_score[team].points = points; } diff --git a/src/level/scoreboard.h b/src/level/scoreboard.h index 58a5acb5..97477e8b 100644 --- a/src/level/scoreboard.h +++ b/src/level/scoreboard.h @@ -32,6 +32,16 @@ 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 * \brief Scoreboard used to score complex code battles @@ -114,12 +124,12 @@ public: void ProcessEndTake(int team); void AddPoints(int team, int points); - int GetScore(int team); + Score GetScore(int team); void SetScore(int team, int score); private: std::vector> m_rulesKill = {}; std::vector> m_rulesEndTake = {}; - std::map m_score; + std::map m_score; int m_finishCounter = 0; }; \ No newline at end of file