1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

code review

This commit is contained in:
Laserlicht 2023-09-24 02:00:42 +02:00 committed by GitHub
parent 41b03e7c5b
commit 68e536c290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 35 deletions

View File

@ -34,46 +34,30 @@
auto HighScoreCalculation::calculate()
{
struct result
struct Result
{
int basic;
int total;
int sumDays;
bool cheater;
int basic = 0;
int total = 0;
int sumDays = 0;
bool cheater = false;
};
std::vector<int> scoresBasic;
std::vector<int> scoresTotal;
double sumBasic = 0;
double sumTotal = 0;
int sumDays = 0;
bool cheater = false;
Result firstResult, summary;
const std::array<double, 5> difficultyMultipliers{0.8, 1.0, 1.3, 1.6, 2.0};
for(auto & param : parameters)
{
double tmp = 200 - (param.day + 10) / (param.townAmount + 5) + (param.allDefeated ? 25 : 0) + (param.hasGrail ? 25 : 0);
scoresBasic.push_back(static_cast<int>(tmp));
sumBasic += tmp;
if(param.difficulty == 0)
tmp *= 0.8;
if(param.difficulty == 1)
tmp *= 1.0;
if(param.difficulty == 2)
tmp *= 1.3;
if(param.difficulty == 3)
tmp *= 1.6;
if(param.difficulty == 4)
tmp *= 2.0;
scoresTotal.push_back(static_cast<int>(tmp));
sumTotal += tmp;
sumDays += param.day;
if(param.usedCheat)
cheater = true;
firstResult = Result{static_cast<int>(tmp), static_cast<int>(tmp * difficultyMultipliers.at(param.difficulty)), param.day, param.usedCheat};
summary.basic += firstResult.basic * 5.0 / parameters.size();
summary.total += firstResult.total * 5.0 / parameters.size();
summary.sumDays += firstResult.sumDays;
summary.cheater |= firstResult.cheater;
}
if(scoresBasic.size() == 1)
return result { scoresBasic[0], scoresTotal[0], sumDays , cheater};
if(parameters.size() == 1)
return firstResult;
return result { static_cast<int>((sumBasic / parameters.size()) * 5.0), static_cast<int>((sumTotal / parameters.size()) * 5.0), sumDays, cheater };
return summary;
}
CreatureID HighScoreCalculation::getCreatureForPoints(int points, bool campaign)
@ -104,9 +88,9 @@ CHighScoreScreen::CHighScoreScreen(HighScorePage highscorepage, int highlighted)
void CHighScoreScreen::showPopupWindow(const Point & cursorPosition)
{
for (int i = 0; i < 11; i++)
for (int i = 0; i < screenRows; i++)
{
bool currentGameNotInListEntry = (i == 10 && highlighted > 10);
bool currentGameNotInListEntry = i == (screenRows - 1) && highlighted > (screenRows - 1);
Rect r = Rect(80, 40 + i * 50, 635, 50);
if(r.isInside(cursorPosition - pos))
@ -158,9 +142,9 @@ void CHighScoreScreen::addHighScores()
// Content
int y = 66;
auto & data = persistentStorage["highscore"][highscorepage == HighScorePage::SCENARIO ? "scenario" : "campaign"];
for (int i = 0; i < 11; i++)
for (int i = 0; i < screenRows; i++)
{
bool currentGameNotInListEntry = (i == 10 && highlighted > 10);
bool currentGameNotInListEntry = (i == (screenRows - 1) && highlighted > (screenRows - 1));
auto & curData = data[currentGameNotInListEntry ? highlighted : i];
ColorRGBA color = (i == highlighted || currentGameNotInListEntry) ? Colors::YELLOW : Colors::WHITE;

View File

@ -64,6 +64,8 @@ private:
std::vector<std::shared_ptr<CLabel>> texts;
std::vector<std::shared_ptr<CAnimImage>> images;
const int screenRows = 11;
int highlighted;
public:
CHighScoreScreen(HighScorePage highscorepage = HighScorePage::SCENARIO, int highlighted = -1);