diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index f382b4520..2545c1bde 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1457,6 +1457,8 @@ void Game::render() { renderFps++; totalRenderFps++; + updateWorldStats(); + //NetworkManager &networkManager= NetworkManager::getInstance(); if(this->masterserverMode == false) { renderWorker(); @@ -2601,6 +2603,16 @@ void Game::exitGameState(Program *program, Stats &endStats) { game->endGame(); } + if(game->isMasterserverMode() == true) { + printf("Game ending with stats:\n"); + printf("-----------------------\n"); + + string gameStats = endStats.getStats(); + printf("%s",gameStats.c_str()); + + printf("-----------------------\n"); + } + ProgramState *newState = new BattleEnd(program, &endStats, game); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -2701,7 +2713,27 @@ void Game::render3d(){ renderer.setLastRenderFps(lastRenderFps); } -void Game::render2d(){ +void Game::updateWorldStats() { + world.getStats()->setWorldTimeElapsed(world.getTimeFlow()->getTime()); + + if(difftime(time(NULL),lastMaxUnitCalcTime) >= 1) { + lastMaxUnitCalcTime = time(NULL); + + int totalUnitcount = 0; + for(int i = 0; i < world.getFactionCount(); ++i) { + Faction *faction= world.getFaction(i); + totalUnitcount += faction->getUnitCount(); + } + + if(world.getStats()->getMaxConcurrentUnitCount() < totalUnitcount) { + world.getStats()->setMaxConcurrentUnitCount(totalUnitcount); + } + world.getStats()->setTotalEndGameConcurrentUnitCount(totalUnitcount); + world.getStats()->setFramesPlayed(world.getFrameCount()); + } +} + +void Game::render2d() { Renderer &renderer= Renderer::getInstance(); //Config &config= Config::getInstance(); CoreData &coreData= CoreData::getInstance(); @@ -2776,24 +2808,6 @@ void Game::render2d(){ string str=""; std::map factionDebugInfo; - world.getStats()->setWorldTimeElapsed(world.getTimeFlow()->getTime()); - - if(difftime(time(NULL),lastMaxUnitCalcTime) >= 1) { - lastMaxUnitCalcTime = time(NULL); - - int totalUnitcount = 0; - for(int i = 0; i < world.getFactionCount(); ++i) { - Faction *faction= world.getFaction(i); - totalUnitcount += faction->getUnitCount(); - } - - if(world.getStats()->getMaxConcurrentUnitCount() < totalUnitcount) { - world.getStats()->setMaxConcurrentUnitCount(totalUnitcount); - } - world.getStats()->setTotalEndGameConcurrentUnitCount(totalUnitcount); - world.getStats()->setFramesPlayed(world.getFrameCount()); - } - if( renderer.getShowDebugUI() == true || (perfLogging == true && difftime(time(NULL),lastRenderLog2d) >= 1)) { str+= "MouseXY: " + intToStr(mouseX) + "," + intToStr(mouseY)+"\n"; diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index e7bb44cfc..ab8697803 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -252,6 +252,7 @@ private: void calcCameraMoveZ(); int getFirstUnusedTeamNumber(); + void updateWorldStats(); }; }}//end namespace diff --git a/source/glest_game/game/stats.cpp b/source/glest_game/game/stats.cpp index 0ccdadde2..4b63da2af 100644 --- a/source/glest_game/game/stats.cpp +++ b/source/glest_game/game/stats.cpp @@ -10,11 +10,93 @@ // ============================================================== #include "stats.h" - +#include "lang.h" #include "leak_dumper.h" namespace Glest{ namespace Game{ +PlayerStats::PlayerStats() { + control = ctClosed; + resourceMultiplier=1.0f; + factionTypeName = ""; + personalityType = fpt_Normal; + teamIndex = 0; + victory = false; + kills = 0; + enemykills = 0; + deaths = 0; + unitsProduced = 0; + resourcesHarvested = 0; + playerName = ""; + playerColor = Vec3f(0,0,0); +} + +string PlayerStats::getStats() const { + string result = ""; + + Lang &lang= Lang::getInstance(); + string controlString = ""; + + if(personalityType == fpt_Observer) { + controlString= GameConstants::OBSERVER_SLOTNAME; + } + else { + switch(control) { + case ctCpuEasy: + controlString= lang.get("CpuEasy"); + break; + case ctCpu: + controlString= lang.get("Cpu"); + break; + case ctCpuUltra: + controlString= lang.get("CpuUltra"); + break; + case ctCpuMega: + controlString= lang.get("CpuMega"); + break; + case ctNetwork: + controlString= lang.get("Network"); + break; + case ctHuman: + controlString= lang.get("Human"); + break; + + case ctNetworkCpuEasy: + controlString= lang.get("NetworkCpuEasy"); + break; + case ctNetworkCpu: + controlString= lang.get("NetworkCpu"); + break; + case ctNetworkCpuUltra: + controlString= lang.get("NetworkCpuUltra"); + break; + case ctNetworkCpuMega: + controlString= lang.get("NetworkCpuMega"); + break; + + default: + printf("Error control = %d\n",control); + assert(false); + }; + } + + if(control != ctHuman && control != ctNetwork ) { + controlString += " x " + floatToStr(resourceMultiplier,1); + } + + result += playerName + " (" + controlString + ") "; + result += "faction: " + factionTypeName + " "; + result += "Team: " + intToStr(teamIndex) + " "; + result += "victory: " + boolToStr(victory) + " "; + result += "# kills: " + intToStr(kills) + " "; + result += "# enemy kills: " + intToStr(enemykills) + " "; + result += "# deaths: " + intToStr(deaths) + "\n"; + result += "# units produced: " + intToStr(unitsProduced) + " "; + result += "# resources harvested: " + intToStr(resourcesHarvested); + + return result; +} + // ===================================================== // class Stats // ===================================================== @@ -49,4 +131,23 @@ void Stats::harvest(int harvesterFactionIndex, int amount){ playerStats[harvesterFactionIndex].resourcesHarvested+= amount; } +string Stats::getStats() const { + string result = ""; + + result += "Description: " + description + "\n"; + result += "Faction count: " + intToStr(factionCount) + "\n"; + + result += "Game duration (mins): " + intToStr(getFramesToCalculatePlaytime()/GameConstants::updateFps/60) + "\n"; + result += "Max Concurrent Units: " + intToStr(maxConcurrentUnitCount) + "\n"; + result += "Total EndGame Concurrent Unit Count: " + intToStr(totalEndGameConcurrentUnitCount) + "\n"; + + for(unsigned int i = 0; i < factionCount; ++i) { + const PlayerStats &player = playerStats[i]; + + result += "player #" + intToStr(i) + " " + player.getStats() + "\n"; + } + + return result; +} + }}//end namespace diff --git a/source/glest_game/game/stats.h b/source/glest_game/game/stats.h index 8099ee014..a65cc88df 100644 --- a/source/glest_game/game/stats.h +++ b/source/glest_game/game/stats.h @@ -27,21 +27,7 @@ namespace Glest{ namespace Game{ class PlayerStats { public: - PlayerStats() { - control = ctClosed; - resourceMultiplier=1.0f; - factionTypeName = ""; - personalityType = fpt_Normal; - teamIndex = 0; - victory = false; - kills = 0; - enemykills = 0; - deaths = 0; - unitsProduced = 0; - resourcesHarvested = 0; - playerName = ""; - playerColor = Vec3f(0,0,0); - } + PlayerStats(); ControlType control; float resourceMultiplier; @@ -56,6 +42,8 @@ public: int resourcesHarvested; string playerName; Vec3f playerColor; + + string getStats() const; }; // ===================================================== @@ -145,6 +133,7 @@ public: void addFramesToCalculatePlaytime() {this->framesToCalculatePlaytime++; } + string getStats() const; }; }}//end namespace diff --git a/source/glest_game/main/battle_end.cpp b/source/glest_game/main/battle_end.cpp index 4273642a7..c96a5ed26 100644 --- a/source/glest_game/main/battle_end.cpp +++ b/source/glest_game/main/battle_end.cpp @@ -284,6 +284,7 @@ void BattleEnd::render() { break; default: + printf("Error control = %d for i\n",stats.getControl(i),i); assert(false); }; }