]> git.jsancho.org Git - lugaru.git/commitdiff
Moved Account::active in Account class. Maybe it should be changed for a method and...
authorCôme Chilliet <come@chilliet.eu>
Sun, 11 Dec 2016 07:34:52 +0000 (14:34 +0700)
committerCôme Chilliet <come@chilliet.eu>
Sun, 11 Dec 2016 07:34:52 +0000 (14:34 +0700)
Source/Account.cpp
Source/Account.h
Source/Campaign.cpp
Source/Game.cpp
Source/Game.h
Source/GameDraw.cpp
Source/GameInitDispose.cpp
Source/GameTick.cpp
Source/Menu.cpp

index bfaa3d4ba2aa520782726fc2b1340c1343c79676..d132c2123d602945454e79d7f87e7d96c3315e9e 100644 (file)
@@ -30,6 +30,7 @@ using namespace std;
 extern bool devtools;
 
 vector<Account*> Account::accounts = vector<Account*>();
+Account* Account::active = nullptr;
 
 Account::Account(const string& name) : name(name), campaignProgress()
 {
@@ -114,14 +115,14 @@ Account* Account::loadFile(string filename)
 {
     FILE *tfile;
     int numaccounts;
-    int accountactive;
+    int iactive;
     errno = 0;
 
     tfile = fopen(filename.c_str(), "rb" );
 
     if (tfile) {
         funpackf(tfile, "Bi", &numaccounts);
-        funpackf(tfile, "Bi", &accountactive);
+        funpackf(tfile, "Bi", &iactive);
         printf("number of accounts %d\n", numaccounts);
         for (int i = 0; i < numaccounts; i++) {
             printf("loading account %d/%d\n", i, numaccounts);
@@ -185,14 +186,14 @@ Account* Account::loadFile(string filename)
         }
 
         fclose(tfile);
-        return get(accountactive);
+        return get(iactive);
     } else {
         perror(("Couldn't load users from " + filename).c_str());
         return NULL;
     }
 }
 
-void Account::saveFile(string filename, Account* accountactive)
+void Account::saveFile(string filename)
 {
     FILE *tfile;
     errno = 0;
@@ -200,7 +201,7 @@ void Account::saveFile(string filename, Account* accountactive)
     tfile = fopen(filename.c_str(), "wb" );
     if (tfile) {
         fpackf(tfile, "Bi", getNbAccounts());
-        fpackf(tfile, "Bi", indice(accountactive));
+        fpackf(tfile, "Bi", indice(Account::active));
 
         for (int i = 0; i < getNbAccounts(); i++) {
             Account* a = Account::get(i);
index f5b91f1e869cbc2d43566b4d5e7f30c21d6ca54c..f68c52b484e1663437e4e8f0daf1ab32f7b81b73 100644 (file)
@@ -48,9 +48,11 @@ public:
     static Account* add(const std::string& name);
     static Account* get(int i);
     static Account* loadFile(std::string filename);
-    static void saveFile(std::string filename, Account* accountactive);
+    static void saveFile(std::string filename);
     static int indice(Account* a);
 
+    static Account* active;
+
     void endGame();
     void winCampaignLevel(int choice, float score, float time);
     void winLevel(int level, float score, float time);
index f46b7d299b4c7a90e7cf92a77f3ad4a9662e27ab..b02dd7bf58a66542ee193a5c16cc14fbfd7dfb76 100644 (file)
@@ -55,16 +55,16 @@ std::vector<std::string> ListCampaigns()
 
 void LoadCampaign()
 {
-    if (!accountactive)
+    if (!Account::active)
         return;
-    std::ifstream ipstream(Folders::getResourcePath("Campaigns/" + accountactive->getCurrentCampaign() + ".txt"));
+    std::ifstream ipstream(Folders::getResourcePath("Campaigns/" + Account::active->getCurrentCampaign() + ".txt"));
     if (!ipstream.good()) {
-        if (accountactive->getCurrentCampaign() == "main") {
+        if (Account::active->getCurrentCampaign() == "main") {
             cerr << "Could not found main campaign!" << endl;
             return;
         }
-        cerr << "Could not found campaign \"" << accountactive->getCurrentCampaign() << "\", falling back to main." << endl;
-        accountactive->setCurrentCampaign("main");
+        cerr << "Could not found campaign \"" << Account::active->getCurrentCampaign() << "\", falling back to main." << endl;
+        Account::active->setCurrentCampaign("main");
         return LoadCampaign();
     }
     ipstream.ignore(256, ':');
@@ -78,16 +78,16 @@ void LoadCampaign()
     }
     ipstream.close();
 
-    std::ifstream test(Folders::getResourcePath("Textures/" + accountactive->getCurrentCampaign() + "/World.png"));
+    std::ifstream test(Folders::getResourcePath("Textures/" + Account::active->getCurrentCampaign() + "/World.png"));
     if (test.good()) {
-        Mainmenuitems[7].load("Textures/" + accountactive->getCurrentCampaign() + "/World.png", 0);
+        Mainmenuitems[7].load("Textures/" + Account::active->getCurrentCampaign() + "/World.png", 0);
     } else {
         Mainmenuitems[7].load("Textures/World.png", 0);
     }
 
-    if (accountactive->getCampaignChoicesMade() == 0) {
-        accountactive->setCampaignScore(0);
-        accountactive->resetFasttime();
+    if (Account::active->getCampaignChoicesMade() == 0) {
+        Account::active->setCampaignScore(0);
+        Account::active->resetFasttime();
     }
 }
 
index 39b7df764627e1cb9ed0258acad3a9806afbf1ce..d05bb44a9d223fb2aff7deae0ba4b46cc671d29d 100644 (file)
@@ -129,7 +129,6 @@ int targetlevel = 0;
 float changedelay = 0;
 
 bool waiting = false;
-Account* accountactive = NULL;
 }
 
 void Game::fireSound(int sound)
index 96ec8154f262794154749a78cef3bd82dfcfb3a0..2dbc9af532a7d7646b82916f0065a2ced39684dd 100644 (file)
@@ -135,7 +135,6 @@ extern int targetlevel;
 extern float changedelay;
 
 extern bool waiting;
-extern Account* accountactive;
 
 extern unsigned short crouchkey, jumpkey, forwardkey, backkey, leftkey, rightkey, drawkey, throwkey, attackkey;
 extern unsigned short consolekey;
index 87a982be56e7111cb528c1f4758cb8786ef3f38e..76318a4775c4536f1ebba824e8825c73572e1f93 100644 (file)
@@ -1051,9 +1051,9 @@ int Game::DrawGLScene(StereoSide side)
             if (!tutoriallevel && !winfreeze && !Dialog::inDialog() && !mainmenu) {
                 if (campaign) {
                     if (scoreadded)
-                        sprintf (string, "Score: %d", (int)accountactive->getCampaignScore());
+                        sprintf (string, "Score: %d", (int)Account::active->getCampaignScore());
                     else
-                        sprintf (string, "Score: %d", (int)accountactive->getCampaignScore() + (int)bonustotal);
+                        sprintf (string, "Score: %d", (int)Account::active->getCampaignScore() + (int)bonustotal);
                 }
                 if (!campaign)
                     sprintf (string, "Score: %d", (int)bonustotal);
index 2103c2184cb570d54dd3fe00c09498ca071e3c47..e08ff8efc712823c24902ddff34dba64fb44f09b 100644 (file)
@@ -79,11 +79,11 @@ void Dispose()
     LOGFUNC;
 
     if (Game::endgame == 2) {
-        Game::accountactive->endGame();
+        Account::active->endGame();
         Game::endgame = 0;
     }
 
-    Account::saveFile(Folders::getUserDataPath()+"/users", Game::accountactive);
+    Account::saveFile(Folders::getUserDataPath()+"/users");
 
     //textures.clear();
 
@@ -458,7 +458,7 @@ void Game::InitGame()
 
     numchallengelevels = 14;
 
-    accountactive = Account::loadFile(Folders::getUserDataPath()+"/users");
+    Account::active = Account::loadFile(Folders::getUserDataPath()+"/users");
 
     whichjointstartarray[0] = righthip;
     whichjointendarray[0] = rightfoot;
index e738a420552cbc58067ce48f98f1a32bda426ba4..fab80e9e5ac4c29b7c07fc9422e0e27236ae2d80 100644 (file)
@@ -692,8 +692,8 @@ void Game::Loadlevel(const std::string& name)
     damagedealt = 0;
     damagetaken = 0;
 
-    if (accountactive)
-        difficulty = accountactive->getDifficulty();
+    if (Account::active)
+        difficulty = Account::active->getDifficulty();
 
     Hotspot::hotspots.clear();
     Hotspot::current = -1;
@@ -6217,11 +6217,11 @@ void Game::TickOnceAfter()
             if (changedelay > 0 && !Person::players[0]->dead && !won) {
                 //high scores, awards, win
                 if (campaign) {
-                    accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
+                    Account::active->winCampaignLevel(whichchoice, bonustotal, leveltime);
                     scoreadded = 1;
                 } else {
                     wonleveltime = leveltime;
-                    accountactive->winLevel(whichlevel, bonustotal - startbonustotal, leveltime);
+                    Account::active->winLevel(whichlevel, bonustotal - startbonustotal, leveltime);
                 }
                 won = 1;
             }
@@ -6264,7 +6264,7 @@ void Game::TickOnceAfter()
 
                     fireSound(firestartsound);
 
-                    Loadlevel(campaignlevels[accountactive->getCampaignChoicesMade()].mapname.c_str());
+                    Loadlevel(campaignlevels[Account::active->getCampaignChoicesMade()].mapname.c_str());
 
                     fireSound();
 
index af6fe29889f71cc158ac6257b4b890c68d06df39..d3c9b0d35c3d1dbb2b02c98e027c7e4dca84d507 100644 (file)
@@ -397,24 +397,24 @@ void Menu::Load()
         break;
     case 5: {
         LoadCampaign();
-        addLabel(-1, accountactive->getName(), 5, 400);
+        addLabel(-1, Account::active->getName(), 5, 400);
         addButton(1, "Tutorial", 5, 300);
         addButton(2, "Challenge", 5, 240);
         addButton(3, "Delete User", 400, 10);
         addButton(4, "Main Menu", 5, 10);
         addButton(5, "Change User", 5, 180);
-        addButton(6, "Campaign : " + accountactive->getCurrentCampaign(), 200, 420);
+        addButton(6, "Campaign : " + Account::active->getCurrentCampaign(), 200, 420);
 
         //show campaign map
         //with (2,-5) offset from old code
         addImage(-1, Mainmenuitems[7], 150 + 2, 60 - 5, 400, 400);
         //show levels
-        int numlevels = accountactive->getCampaignChoicesMade();
+        int numlevels = Account::active->getCampaignChoicesMade();
         numlevels += numlevels > 0 ? campaignlevels[numlevels - 1].nextlevel.size() : 1;
         for (int i = 0; i < numlevels; i++) {
             XYZ midpoint = campaignlevels[i].getCenter();
             float itemsize = campaignlevels[i].getWidth();
-            const bool active = i >= accountactive->getCampaignChoicesMade();
+            const bool active = i >= Account::active->getCampaignChoicesMade();
             if (!active)
                 itemsize /= 2;
 
@@ -460,18 +460,18 @@ void Menu::Load()
             if (name.size() < 17) {
                 name.append((17 - name.size()), ' ');
             }
-            name += to_string(int(accountactive->getHighScore(i)));
+            name += to_string(int(Account::active->getHighScore(i)));
             if (name.size() < 32) {
                 name.append((32 - name.size()), ' ');
             }
-            int fasttime = (int)round(accountactive->getFastTime(i));
+            int fasttime = (int)round(Account::active->getFastTime(i));
             name += to_string(int((fasttime - fasttime % 60) / 60));
             name += ":";
             if (fasttime % 60 < 10)
                 name += "0";
             name += to_string(fasttime % 60);
 
-            addButton(i, name, 10, 400 - i * 25, i > accountactive->getProgress() ? 0.5 : 1, 0, 0);
+            addButton(i, name, 10, 400 - i * 25, i > Account::active->getProgress() ? 0.5 : 1, 0, 0);
         }
 
         addButton(-1, "             High Score      Best Time", 10, 440);
@@ -482,8 +482,8 @@ void Menu::Load()
         addLabel(1, "You have avenged your family and", 140, 300);
         addLabel(2, "restored peace to the island of Lugaru.", 110, 270);
         addButton(3, "Back", 10, 10);
-        addLabel(4, string("Your score:         ") + to_string((int)accountactive->getCampaignScore()), 190, 200);
-        addLabel(5, string("Highest score:      ") + to_string((int)accountactive->getCampaignHighScore()), 190, 180);
+        addLabel(4, string("Your score:         ") + to_string((int)Account::active->getCampaignScore()), 190, 200);
+        addLabel(5, string("Highest score:      ") + to_string((int)Account::active->getCampaignHighScore()), 190, 180);
     }
     break;
     case 18:
@@ -535,7 +535,7 @@ void Menu::Tick()
 
     // some specific case where we do something even if the left mouse button is not pressed.
     if ((mainmenu == 5) && (endgame == 2)) {
-        accountactive->endGame();
+        Account::active->endGame();
         endgame = 0;
     }
     if (mainmenu == 10)
@@ -561,7 +561,7 @@ void Menu::Tick()
                 } else { //new game
                     fireSound(firestartsound);
                     flash();
-                    mainmenu = (accountactive ? 5 : 7);
+                    mainmenu = (Account::active ? 5 : 7);
                     selected = -1;
                 }
                 break;
@@ -702,7 +702,7 @@ void Menu::Tick()
         case 5:
             fireSound();
             flash();
-            if ((selected - NB_CAMPAIGN_MENU_ITEM >= accountactive->getCampaignChoicesMade())) {
+            if ((selected - NB_CAMPAIGN_MENU_ITEM >= Account::active->getCampaignChoicesMade())) {
                 startbonustotal = 0;
 
                 loading = 2;
@@ -712,8 +712,8 @@ void Menu::Tick()
                     TickOnceAfter();
                 else
                     LoadStuff();
-                whichchoice = selected - NB_CAMPAIGN_MENU_ITEM - accountactive->getCampaignChoicesMade();
-                actuallevel = (accountactive->getCampaignChoicesMade() > 0 ? campaignlevels[accountactive->getCampaignChoicesMade() - 1].nextlevel[whichchoice] : 0);
+                whichchoice = selected - NB_CAMPAIGN_MENU_ITEM - Account::active->getCampaignChoicesMade();
+                actuallevel = (Account::active->getCampaignChoicesMade() > 0 ? campaignlevels[Account::active->getCampaignChoicesMade() - 1].nextlevel[whichchoice] : 0);
                 visibleloading = 1;
                 stillloading = 1;
                 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
@@ -754,14 +754,14 @@ void Menu::Tick()
             case 6:
                 vector<string> campaigns = ListCampaigns();
                 vector<string>::iterator c;
-                if ((c = find(campaigns.begin(), campaigns.end(), accountactive->getCurrentCampaign())) == campaigns.end()) {
+                if ((c = find(campaigns.begin(), campaigns.end(), Account::active->getCurrentCampaign())) == campaigns.end()) {
                     if (!campaigns.empty())
-                        accountactive->setCurrentCampaign(campaigns.front());
+                        Account::active->setCurrentCampaign(campaigns.front());
                 } else {
                     c++;
                     if (c == campaigns.end())
                         c = campaigns.begin();
-                    accountactive->setCurrentCampaign(*c);
+                    Account::active->setCurrentCampaign(*c);
                 }
                 Load();
                 break;
@@ -771,7 +771,7 @@ void Menu::Tick()
             fireSound();
             if (selected == 1) {
                 flash();
-                accountactive = Account::destroy(accountactive);
+                Account::active = Account::destroy(Account::active);
                 mainmenu = 7;
             } else if (selected == 2) {
                 flash();
@@ -785,10 +785,10 @@ void Menu::Tick()
             } else if (selected < Account::getNbAccounts() + 1) {
                 flash();
                 mainmenu = 5;
-                accountactive = Account::get(selected - 1);
+                Account::active = Account::get(selected - 1);
             } else if (selected == Account::getNbAccounts() + 1) {
                 flash();
-                if (accountactive)
+                if (Account::active)
                     mainmenu = 5;
                 else
                     mainmenu = 1;
@@ -801,11 +801,11 @@ void Menu::Tick()
             fireSound();
             flash();
             if (selected <= 2)
-                accountactive->setDifficulty(selected);
+                Account::active->setDifficulty(selected);
             mainmenu = 5;
             break;
         case 9:
-            if (selected < numchallengelevels && selected <= accountactive->getProgress()) {
+            if (selected < numchallengelevels && selected <= Account::active->getProgress()) {
                 fireSound();
                 flash();
 
@@ -872,7 +872,7 @@ void Menu::Tick()
         inputText(displaytext[0], &displayselected);
         if (!waiting) { // the input as finished
             if (!displaytext[0].empty()) { // with enter
-                accountactive = Account::add(string(displaytext[0]));
+                Account::active = Account::add(string(displaytext[0]));
 
                 mainmenu = 8;