Add switch to determine sort type
You can set it in scene file with ScoreboardSortType SortBy="Name" or "Points"1008-fix
parent
ff0f22ef44
commit
1b79e8409f
|
@ -3563,6 +3563,22 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
|||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line->GetCommand() == "ScoreboardSortType" && !resetObject)
|
||||
{
|
||||
if (line->GetParam("SortBy")->AsString() == "Points")
|
||||
{
|
||||
// Sort teams by points
|
||||
m_scoreboard->SetSortType(SORT_POINTS);
|
||||
}
|
||||
else if (line->GetParam("SortBy")->AsString() == "Name")
|
||||
{
|
||||
// Sort teams alphabetically
|
||||
m_scoreboard->SetSortType(SORT_ID);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line->GetCommand() == "ScoreboardKillRule" && !resetObject)
|
||||
{
|
||||
if (!m_scoreboard)
|
||||
|
@ -5912,14 +5928,18 @@ void CRobotMain::UpdateCodeBattleInterface()
|
|||
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?
|
||||
});
|
||||
if(m_scoreboard->GetSortType() == SORT_POINTS)
|
||||
{
|
||||
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 : sortedTeams)
|
||||
{
|
||||
|
|
|
@ -112,3 +112,13 @@ void CScoreboard::SetScore(int team, int points)
|
|||
{
|
||||
m_score[team].points = points;
|
||||
}
|
||||
|
||||
SortType CScoreboard::GetSortType()
|
||||
{
|
||||
return m_sorttype;
|
||||
}
|
||||
|
||||
void CScoreboard::SetSortType(SortType type)
|
||||
{
|
||||
m_sorttype = type;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,12 @@ struct Score
|
|||
float time = 0; //! Time when points were scored
|
||||
};
|
||||
|
||||
enum SortType
|
||||
{
|
||||
SORT_ID, //Sort by team ID
|
||||
SORT_POINTS, //Sort by points
|
||||
};
|
||||
|
||||
/**
|
||||
* \class CScoreboard
|
||||
* \brief Scoreboard used to score complex code battles
|
||||
|
@ -55,6 +61,7 @@ struct Score
|
|||
* \section example Usage example
|
||||
* \code{.scene}
|
||||
* Scoreboard enable=true // enable the scoreboard
|
||||
* ScoreboardSortType SortBy="Name" // sort teams alphabetically, another option is SortBy="Points", sorting teams in order of points
|
||||
* ScoreboardKillRule type=WheeledShooter team=1 score=500 // destruction of team 1's WheeledShooter gives 100 points to the team that destroyed it
|
||||
* ScoreboardKillRule type=TargetBot score=100 // destruction of TargetBot (any team) gives 100 points
|
||||
* ScoreboardEndTakeRule score=1000 // completion of EndMissionTake objectives for any team results in 1000 points for that team
|
||||
|
@ -127,9 +134,13 @@ public:
|
|||
Score GetScore(int team);
|
||||
void SetScore(int team, int score);
|
||||
|
||||
SortType GetSortType();
|
||||
void SetSortType(SortType type);
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<CScoreboardKillRule>> m_rulesKill = {};
|
||||
std::vector<std::unique_ptr<CScoreboardEndTakeRule>> m_rulesEndTake = {};
|
||||
std::map<int, Score> m_score;
|
||||
int m_finishCounter = 0;
|
||||
};
|
||||
SortType m_sorttype = SORT_ID;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue