commit c09d0e4f
Now adds defeat to the correct AI difficulty level. Cannot get endless highscore in Vs game anymore
git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@60 9d7177f8-192b-0410-8f35-a16a89829b06
Changed files
| M | Makefile before |
| M | source/code/BlockGame.hpp before |
| M | source/code/block.make before |
| M | source/code/common.cc before |
| M | source/code/common.h before |
| M | source/code/main.cpp before |
diff --git a/Makefile b/Makefile
index 56660a1..194f218 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@ standard:
@echo "Everything has been compiled!"
clean:
- rm -f ./source/code/*.o
+ rm -f ./source/code/build/*.o
rm -f ./source/code/blockattack #Build by scons
rm -f ./Game/blockattack #build by this
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp
index d9a5e73..600731b 100644
--- a/source/code/BlockGame.hpp
+++ b/source/code/BlockGame.hpp
@@ -424,16 +424,16 @@ public:
if(!AI_Enabled && !bReplaying)
{
Stats::getInstance()->addOne("totalWins");
- if(garbageTarget->AI_Enabled==true && garbageTarget->bReplaying==false)
+ if(garbageTarget->AI_Enabled && !(garbageTarget->bReplaying))
{
//We have defeated an AI
Stats::getInstance()->addOne("defeatedAI"+itoa(garbageTarget->getAIlevel()));
}
}
- if(AI_Enabled && garbageTarget->AI_Enabled==false && garbageTarget->bReplaying==false)
+ if(AI_Enabled && !(garbageTarget->AI_Enabled) && garbageTarget->bReplaying==false)
{
//The AI have defeated a human player
- Stats::getInstance()->addOne("defeatedByAI"+itoa(garbageTarget->getAIlevel()));
+ Stats::getInstance()->addOne("defeatedByAI"+itoa(getAIlevel()));
}
}
@@ -1322,7 +1322,7 @@ public:
}
if ((TowerHeight>12) && (!puzzleMode)&&(!bGameOver)&&(chain==0)) {
- if ((theTopScoresEndless.isHighScore(score))&&(!AI_Enabled)) {
+ if ((!vsMode)&&(theTopScoresEndless.isHighScore(score))&&(!AI_Enabled)) {
if (SoundEnabled)Mix_PlayChannel(1, applause, 0);
theTopScoresEndless.addScore(name, score);
cout << "New high score!" << endl;
diff --git a/source/code/block.make b/source/code/block.make
index 9d4d661..87112a2 100644
--- a/source/code/block.make
+++ b/source/code/block.make
@@ -13,7 +13,7 @@ BASE_LIBS=$(shell sdl-config --libs) -lSDL_image -lSDL_mixer -lSDL_ttf
#For developement only
ifndef DEBUG
-DEBUG=1
+DEBUG=0
endif
ifndef NETWORK
diff --git a/source/code/common.cc b/source/code/common.cc
index 7aee337..4d5a007 100644
--- a/source/code/common.cc
+++ b/source/code/common.cc
@@ -112,61 +112,65 @@ string getPathToSaveFiles()
#endif
}
-
+commonTime ms2ct(unsigned int milliseconds)
+{
+ commonTime ct;
+ ct.days = 0;
+ unsigned int time = milliseconds;
+ ct.hours = time/(1000*60*60);
+ time = time % (1000*60*60);
+ ct.minutes = time/(1000*60);
+ time = time % (1000*60);
+ ct.seconds = time/1000;
+}
commonTime getTotalTime()
{
commonTime ct;
- string filename = getPathToSaveFiles()+"/totalTime";
- ifstream inFile(filename.c_str());
- if(inFile)
- {
- inFile >> ct.days;
- inFile >> ct.hours;
- inFile >> ct.minutes;
- inFile >> ct.seconds;
- inFile.close();
- }
- else
- {
- ct.days = 0;
- ct.hours = 0;
- ct.minutes = 0;
- ct.seconds = 0;
- }
+ ct.days = Config::getInstance()->getInt("totalTimeDays");
+ ct.hours = Config::getInstance()->getInt("totalTimeHours");
+ ct.minutes = Config::getInstance()->getInt("totalTimeMinutes");
+ ct.seconds = Config::getInstance()->getInt("totalTimeSeconds");
return ct;
}
-commonTime addTotalTime(commonTime toAdd)
+/*
+ * peekTotalTime
+ * Returns the total runtime with toAdd added but without writing it to config file. Used for stats
+ */
+commonTime peekTotalTime(commonTime toAdd)
{
commonTime ct = getTotalTime();
-
+
ct.seconds +=toAdd.seconds;
ct.minutes +=ct.seconds/60;
ct.seconds = ct.seconds%60;
-
+
ct.minutes += toAdd.minutes;
ct.hours += ct.minutes/60;
ct.minutes = ct.minutes%60;
-
+
ct.hours += toAdd.hours;
ct.days += ct.hours/24;
ct.hours = ct.hours%24;
-
+
ct.days += toAdd.days;
+ return ct;
+}
+
+/*
+ * addTotalTime
+ * Same as peekTotalTime but writes the time to the config file.
+ * Should only be called once... when the program shuts down
+ */
+commonTime addTotalTime(commonTime toAdd)
+{
+ commonTime ct = peekTotalTime(toAdd);
- string filename = getPathToSaveFiles()+"/totalTime";
- ofstream outFile(filename.c_str(),ios::trunc);
- if(outFile)
- {
- outFile << ct.days << endl;
- outFile << ct.hours << endl;
- outFile << ct.minutes << endl;
- outFile << ct.seconds << endl;
- outFile.close();
- }
- else
- cout << "Error writing total time to: " << filename << endl;
+ Config::getInstance()->setInt("totalTimeDays",ct.days);
+ Config::getInstance()->setInt("totalTimeHours",ct.hours);
+ Config::getInstance()->setInt("totalTimeMinutes",ct.minutes);
+ Config::getInstance()->setInt("totalTimeSeconds",ct.seconds);
return ct;
}
@@ -229,6 +233,7 @@ void Config::save()
outFile << "\n"; //The last entry in the file will be read double if a linebreak is missing
//This is checked on load too in case a user changes it himself.
}
+ outFile.close();
}
bool Config::exists(string varName)
diff --git a/source/code/common.h b/source/code/common.h
index 82cd458..d7a498a 100644
--- a/source/code/common.h
+++ b/source/code/common.h
@@ -59,8 +59,12 @@ string itoa(int num);
string getPathToSaveFiles();
+commonTime ms2ct(unsigned int milliseconds);
+
commonTime getTotalTime();
+commonTime peekTotalTime(commonTime toAdd);
+
commonTime addTotalTime(commonTime toAdd);
#define MAX_VAR_LENGTH 1024
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 05a5538..6fcd877 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -4784,15 +4784,8 @@ int main(int argc, char *argv[])
configSettings->save();
}
- Stats::getInstance()->save();
-
- //Frees memory from music and fonts
- //This is done after writing of configurations and stats since it often crashes the program :(
- UnloadImages();
-
-
//calculate uptime:
- //int hours, mins, secs,
+ //int hours, mins, secs,
int time;
commonTime ct;
ct.days = 0;
@@ -4804,10 +4797,19 @@ int main(int argc, char *argv[])
ct.seconds = time/1000;
cout << "Block Attack - Rise of the Blocks ran for: " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl;
-
+
ct = addTotalTime(ct);
-
+
cout << "Total run time is now: " << ct.days << " days " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl;
+
+ Stats::getInstance()->save();
+
+ Config::getInstance()->save();
+
+ //Frees memory from music and fonts
+ //This is done after writing of configurations and stats since it often crashes the program :(
+ UnloadImages();
+
#if USE_ABSTRACT_FS
//Close file system Apstraction layer!
PHYSFS_deinit();