]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Account.cpp
Add copyright notice and AUTHORS file for open source contributors
[lugaru.git] / Source / Account.cpp
index 09bf0d1ef3ac4f285f5f4c5c2e5b831a6a1ea146..1d7bbd1d4951c94692b4e5fe7771aabf47ad955e 100644 (file)
@@ -1,23 +1,21 @@
 /*
 Copyright (C) 2003, 2010 - Wolfire Games
-Copyright (C) 2010 - Côme <MCMic> BERNIGAUD
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
 
 This file is part of Lugaru.
 
-Lugaru is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
+Lugaru is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
+Lugaru is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-See the GNU General Public License for more details.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "Account.h"
@@ -32,9 +30,8 @@ extern bool debugmode;
 
 vector<Account*> Account::accounts = vector<Account*>();
 
-Account::Account(string n) : campaignProgress()
+Account::Account(const string& name) : name(name), campaignProgress()
 {
-    name = string(n);
     difficulty = 0;
     progress = 0;
     points = 0;
@@ -45,12 +42,12 @@ Account::Account(string n) : campaignProgress()
     setCurrentCampaign("main");
 }
 
-void Account::setCurrentCampaign(string name)
+void Account::setCurrentCampaign(const string& name)
 {
     currentCampaign = name;
 }
 
-Account* Account::add(string name)
+Account* Account::add(const string& name)
 {
     accounts.push_back(new Account(name));
     return accounts.back();
@@ -59,7 +56,7 @@ Account* Account::add(string name)
 Account* Account::get(int i)
 {
 
-    if ((i >= 0) && (i < accounts.size())) {
+    if ((i >= 0) && (i < int(accounts.size()))) {
         return accounts[i];
     } else
         return NULL;
@@ -71,7 +68,7 @@ void Account::destroy(int i)
 }
 Account* Account::destroy(Account* a)
 {
-    for (int i = 0; i < accounts.size(); i++) {
+    for (unsigned i = 0; i < accounts.size(); i++) {
         if (accounts[i] == a) {
             accounts.erase(accounts.begin() + i);
             return NULL;
@@ -198,7 +195,6 @@ Account* Account::loadFile(string filename)
 void Account::saveFile(string filename, Account* accountactive)
 {
     FILE *tfile;
-    int j;
 
     tfile = fopen(ConvertFileName(filename.c_str(), "wb"), "wb" );
     if (tfile) {
@@ -214,9 +210,9 @@ void Account::saveFile(string filename, Account* accountactive)
             fpackf(tfile, "Bi", a->campaignProgress.size());
 
             map<string, CampaignProgress>::const_iterator it;
-            for ( it = a->campaignProgress.begin(); it != a->campaignProgress.end(); ++it) {
+            for (it = a->campaignProgress.begin(); it != a->campaignProgress.end(); ++it) {
                 fpackf(tfile, "Bi",  it->first.size());
-                for (j = 0; j < it->first.size(); j++) {
+                for (unsigned j = 0; j < it->first.size(); j++) {
                     fpackf(tfile, "Bb",  it->first[j]);
                 }
                 fpackf(tfile, "Bf", it->second.time);
@@ -224,26 +220,26 @@ void Account::saveFile(string filename, Account* accountactive)
                 fpackf(tfile, "Bf", it->second.fasttime);
                 fpackf(tfile, "Bf", it->second.highscore);
                 fpackf(tfile, "Bi", it->second.choices.size());
-                for (j = 0; j < it->second.choices.size(); j++) {
+                for (unsigned j = 0; j < it->second.choices.size(); j++) {
                     fpackf(tfile, "Bi", it->second.choices[j]);
                 }
             }
 
             fpackf(tfile, "Bi", a->getCurrentCampaign().size());
-            for (j = 0; j < a->getCurrentCampaign().size(); j++) {
+            for (unsigned j = 0; j < a->getCurrentCampaign().size(); j++) {
                 fpackf(tfile, "Bb", a->getCurrentCampaign()[j]);
             }
 
             fpackf(tfile, "Bf", a->points);
-            for (j = 0; j < 50; j++) {
+            for (unsigned j = 0; j < 50; j++) {
                 fpackf(tfile, "Bf", a->highscore[j]);
                 fpackf(tfile, "Bf", a->fasttime[j]);
             }
-            for (j = 0; j < 60; j++) {
+            for (unsigned j = 0; j < 60; j++) {
                 fpackf(tfile, "Bb",  a->unlocked[j]);
             }
             fpackf(tfile, "Bi",  a->name.size());
-            for (j = 0; j < a->name.size(); j++) {
+            for (unsigned j = 0; j < a->name.size(); j++) {
                 fpackf(tfile, "Bb",  a->name[j]);
             }
         }
@@ -254,7 +250,7 @@ void Account::saveFile(string filename, Account* accountactive)
 
 int Account::indice(Account* a)
 {
-    for (int i = 0; i < accounts.size(); i++) {
+    for (unsigned i = 0; i < accounts.size(); i++) {
         if (accounts[i] == a)
             return i;
     }