From: Côme Chilliet Date: Mon, 23 Jan 2017 16:28:46 +0000 (+0100) Subject: Fixes #40 Scores are now integers X-Git-Url: https://git.jsancho.org/?p=lugaru.git;a=commitdiff_plain;h=380d8141271d6fa12954f6fe46e736315cffd594 Fixes #40 Scores are now integers They are still stored as floats in save file to be backward compatible --- diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index a24df69..73e4dde 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -597,7 +597,7 @@ int Game::DrawGLScene(StereoSide side) } text->glPrintOutlined(1, 0, 0, 1 - bonustime, 1024 / 2 - 10 * strlen(bonus_name), 768 / 16 + 768 * 4 / 5, bonus_name, 1, 2, 1024, 768); - string = to_string((int)bonusvalue); + string = to_string(bonusvalue); text->glPrintOutlined(1, 0, 0, 1 - bonustime, 1024 / 2 - 10 * string.size(), 768 / 16 - 20 + 768 * 4 / 5, string, 1, 2 * .8, 1024, 768); glColor4f(.5, .5, .5, 1); diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 9844ff0..69f9d04 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -3209,7 +3209,12 @@ void Game::Tick() if (Tutorial::active) { bonusvalue = 0; } - bonusvalue /= bonusnum[bonus]; + if (bonusvalue > 0) { + bonusvalue /= bonusnum[bonus]; + if (bonusvalue <= 0) { + bonusvalue = 0; + } + } bonustotal += bonusvalue; } bonustime += multiplier; diff --git a/Source/Level/Awards.cpp b/Source/Level/Awards.cpp index 7fa37a8..1bb7622 100644 --- a/Source/Level/Awards.cpp +++ b/Source/Level/Awards.cpp @@ -23,9 +23,9 @@ along with Lugaru. If not, see . #include "Objects/Person.hpp" int bonus; -float bonusvalue; -float bonustotal; -float startbonustotal; +int bonusvalue; +int bonustotal; +int startbonustotal; float bonustime; float bonusnum[100]; diff --git a/Source/Level/Awards.hpp b/Source/Level/Awards.hpp index ba2bdf8..da0fb75 100644 --- a/Source/Level/Awards.hpp +++ b/Source/Level/Awards.hpp @@ -30,10 +30,10 @@ enum bonus_types { extern const char *bonus_names[bonus_count]; extern int bonus; -extern float bonusvalue; -extern float bonustotal; +extern int bonusvalue; +extern int bonustotal; extern float bonustime; -extern float startbonustotal; +extern int startbonustotal; extern float bonusnum[100]; extern void award_bonus(int playerid, int bonusid, int alt_value = 0); diff --git a/Source/User/Account.cpp b/Source/User/Account.cpp index 82072fc..50195f0 100644 --- a/Source/User/Account.cpp +++ b/Source/User/Account.cpp @@ -65,10 +65,13 @@ Account::Account(FILE* tfile) funpackf(tfile, "Bb", &c); campaignName.append(1, c); } + float fscore, fhighscore; funpackf(tfile, "Bf", &(campaignProgress[campaignName].time)); - funpackf(tfile, "Bf", &(campaignProgress[campaignName].score)); + funpackf(tfile, "Bf", &(fscore)); funpackf(tfile, "Bf", &(campaignProgress[campaignName].fasttime)); - funpackf(tfile, "Bf", &(campaignProgress[campaignName].highscore)); + funpackf(tfile, "Bf", &(fhighscore)); + campaignProgress[campaignName].score = fscore; + campaignProgress[campaignName].highscore = fhighscore; int campaignchoicesmade, campaignchoice; funpackf(tfile, "Bi", &campaignchoicesmade); for (int j = 0; j < campaignchoicesmade; j++) { @@ -91,8 +94,10 @@ Account::Account(FILE* tfile) funpackf(tfile, "Bf", &points); for (int i = 0; i < 50; i++) { - funpackf(tfile, "Bf", &(highscore[i])); + float fscore; + funpackf(tfile, "Bf", &(fscore)); funpackf(tfile, "Bf", &(fasttime[i])); + highscore[i] = fscore; } for (int i = 0; i < 60; i++) { funpackf(tfile, "Bb", &(unlocked[i])); @@ -122,9 +127,9 @@ void Account::save(FILE* tfile) fpackf(tfile, "Bb", it->first[j]); } fpackf(tfile, "Bf", it->second.time); - fpackf(tfile, "Bf", it->second.score); + fpackf(tfile, "Bf", float(it->second.score)); fpackf(tfile, "Bf", it->second.fasttime); - fpackf(tfile, "Bf", it->second.highscore); + fpackf(tfile, "Bf", float(it->second.highscore)); fpackf(tfile, "Bi", it->second.choices.size()); for (unsigned j = 0; j < it->second.choices.size(); j++) { fpackf(tfile, "Bi", it->second.choices[j]); @@ -138,7 +143,7 @@ void Account::save(FILE* tfile) fpackf(tfile, "Bf", points); for (unsigned j = 0; j < 50; j++) { - fpackf(tfile, "Bf", highscore[j]); + fpackf(tfile, "Bf", float(highscore[j])); fpackf(tfile, "Bf", fasttime[j]); } for (unsigned j = 0; j < 60; j++) { @@ -214,14 +219,14 @@ void Account::endGame() campaignProgress[currentCampaign].time = 0; } -void Account::winCampaignLevel(int choice, float score, float time) +void Account::winCampaignLevel(int choice, int score, float time) { campaignProgress[currentCampaign].choices.push_back(choice); setCampaignScore(campaignProgress[currentCampaign].score + score); campaignProgress[currentCampaign].time = time; } -void Account::winLevel(int level, float score, float time) +void Account::winLevel(int level, int score, float time) { if (!devtools) { if (score > highscore[level]) { diff --git a/Source/User/Account.hpp b/Source/User/Account.hpp index 3c9e2e2..f75a183 100644 --- a/Source/User/Account.hpp +++ b/Source/User/Account.hpp @@ -27,9 +27,9 @@ along with Lugaru. If not, see . #include struct CampaignProgress { - float highscore; + int highscore; float fasttime; - float score; + int score; float time; std::vector choices; CampaignProgress() { @@ -58,8 +58,8 @@ public: Account(FILE* tfile); void endGame(); - void winCampaignLevel(int choice, float score, float time); - void winLevel(int level, float score, float time); + void winCampaignLevel(int choice, int score, float time); + void winLevel(int level, int score, float time); // getter and setters int getDifficulty(); @@ -69,7 +69,7 @@ public: const std::string& getName() { return name; }; - float getCampaignScore() { + int getCampaignScore() { return campaignProgress[currentCampaign].score; }; int getCampaignChoicesMade() { @@ -80,13 +80,15 @@ public: }; void setCampaignScore(int s) { campaignProgress[currentCampaign].score = s; - if (s > campaignProgress[currentCampaign].highscore) + if (s > campaignProgress[currentCampaign].highscore) { campaignProgress[currentCampaign].highscore = s; + } }; void setCampaignFinalTime(float t) { campaignProgress[currentCampaign].time = t; - if ((t < campaignProgress[currentCampaign].fasttime) || ((campaignProgress[currentCampaign].fasttime == 0) && (t != 0))) + if ((t < campaignProgress[currentCampaign].fasttime) || ((campaignProgress[currentCampaign].fasttime == 0) && (t != 0))) { campaignProgress[currentCampaign].fasttime = t; + } }; float getCampaignFasttime() { return campaignProgress[currentCampaign].fasttime; @@ -94,10 +96,10 @@ public: void resetFasttime() { campaignProgress[currentCampaign].fasttime = 0; }; - float getCampaignHighScore() { + int getCampaignHighScore() { return campaignProgress[currentCampaign].highscore; }; - float getHighScore(int i) { + int getHighScore(int i) { return highscore[i]; }; float getFastTime(int i) { @@ -121,7 +123,7 @@ private: int difficulty; int progress; // progress in challenge levels float points; - float highscore[50]; + int highscore[50]; float fasttime[50]; bool unlocked[60]; std::string name;