- added a few more things to end game stats as requested by ultifd

(now we can tell the difference between killed units and killed enemy units and final score is based on killed enemy units not all killed units)
This commit is contained in:
Mark Vejvoda 2011-04-05 06:32:23 +00:00
parent ebbdf2d2c2
commit 0fce64897e
6 changed files with 65 additions and 9 deletions

View File

@ -65,6 +65,7 @@ Game::Game(Program *program, const GameSettings *gameSettings):
captureAvgTestStatus = false;
lastRenderLog2d = 0;
totalRenderFps = 0;
lastMaxUnitCalcTime = 0;
mouseMoved= false;
quitTriggeredIndicator = false;
@ -1749,6 +1750,23 @@ void Game::render2d(){
string str="";
std::map<int,string> 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);
}
if( renderer.getShowDebugUI() == true ||
(perfLogging == true && difftime(time(NULL),lastRenderLog2d) >= 1)) {
str+= "MouseXY: " + intToStr(mouseX) + "," + intToStr(mouseY)+"\n";

View File

@ -114,6 +114,8 @@ private:
bool gameStarted;
time_t lastMaxUnitCalcTime;
public:
Game();
Game(Program *program, const GameSettings *gameSettings);

View File

@ -29,9 +29,12 @@ void Stats::setVictorious(int playerIndex){
playerStats[playerIndex].victory= true;
}
void Stats::kill(int killerFactionIndex, int killedFactionIndex){
void Stats::kill(int killerFactionIndex, int killedFactionIndex, bool isEnemy) {
playerStats[killerFactionIndex].kills++;
playerStats[killedFactionIndex].deaths++;
if(isEnemy == true) {
playerStats[killerFactionIndex].enemykills++;
}
}
void Stats::die(int diedFactionIndex){

View File

@ -35,6 +35,7 @@ public:
teamIndex = 0;
victory = false;
kills = 0;
enemykills = 0;
deaths = 0;
unitsProduced = 0;
resourcesHarvested = 0;
@ -49,6 +50,7 @@ public:
int teamIndex;
bool victory;
int kills;
int enemykills;
int deaths;
int unitsProduced;
int resourcesHarvested;
@ -70,25 +72,40 @@ private:
int factionCount;
int thisFactionIndex;
float worldTimeElapsed;
int maxConcurrentUnitCount;
int totalEndGameConcurrentUnitCount;
public:
Stats() {
description = "";
factionCount = 0;
thisFactionIndex = 0;
description = "";
factionCount = 0;
thisFactionIndex = 0;
worldTimeElapsed = 0.0;
maxConcurrentUnitCount = 0;
totalEndGameConcurrentUnitCount = 0;
}
void init(int factionCount, int thisFactionIndex, const string &description);
string getDescription() const {return description;}
int getThisFactionIndex() const {return thisFactionIndex;}
int getFactionCount() const {return factionCount;}
float getWorldTimeElapsed() const {return worldTimeElapsed;}
int getMaxConcurrentUnitCount() const {return maxConcurrentUnitCount; }
int getTotalEndGameConcurrentUnitCount() const {return totalEndGameConcurrentUnitCount; }
const string &getFactionTypeName(int factionIndex) const {return playerStats[factionIndex].factionTypeName;}
FactionPersonalityType getPersonalityType(int factionIndex) const { return playerStats[factionIndex].personalityType;}
ControlType getControl(int factionIndex) const {return playerStats[factionIndex].control;}
float getResourceMultiplier(int factionIndex) const {return playerStats[factionIndex].resourceMultiplier;}
float getResourceMultiplier(int factionIndex) const {return playerStats[factionIndex].resourceMultiplier;}
bool getVictory(int factionIndex) const {return playerStats[factionIndex].victory;}
int getTeam(int factionIndex) const {return playerStats[factionIndex].teamIndex;}
int getKills(int factionIndex) const {return playerStats[factionIndex].kills;}
int getEnemyKills(int factionIndex) const {return playerStats[factionIndex].enemykills;}
int getDeaths(int factionIndex) const {return playerStats[factionIndex].deaths;}
int getUnitsProduced(int factionIndex) const {return playerStats[factionIndex].unitsProduced;}
int getResourcesHarvested(int factionIndex) const {return playerStats[factionIndex].resourcesHarvested;}
@ -96,13 +113,17 @@ public:
Vec3f getPlayerColor(int factionIndex) const { return playerStats[factionIndex].playerColor;}
void setDescription(const string& description) {this->description = description;}
void setWorldTimeElapsed(float value) {this->worldTimeElapsed = value;}
void setMaxConcurrentUnitCount(int value) {this->maxConcurrentUnitCount = value; }
void setTotalEndGameConcurrentUnitCount(int value) {this->totalEndGameConcurrentUnitCount = value; }
void setFactionTypeName(int playerIndex, const string& factionTypeName) {playerStats[playerIndex].factionTypeName= factionTypeName;}
void setPersonalityType(int playerIndex, FactionPersonalityType value) { playerStats[playerIndex].personalityType = value;}
void setPersonalityType(int playerIndex, FactionPersonalityType value) {playerStats[playerIndex].personalityType = value;}
void setControl(int playerIndex, ControlType control) {playerStats[playerIndex].control= control;}
void setResourceMultiplier(int playerIndex, float resourceMultiplier) {playerStats[playerIndex].resourceMultiplier= resourceMultiplier;}
void setTeam(int playerIndex, int teamIndex) {playerStats[playerIndex].teamIndex= teamIndex;}
void setVictorious(int playerIndex);
void kill(int killerFactionIndex, int killedFactionIndex);
void kill(int killerFactionIndex, int killedFactionIndex, bool isEnemy);
void die(int diedFactionIndex);
void produce(int producerFactionIndex);
void harvest(int harvesterFactionIndex, int amount);

View File

@ -89,11 +89,12 @@ void BattleEnd::render(){
int textX= lm+160+i*100;
int team= stats.getTeam(i) + 1;
int kills= stats.getKills(i);
int enemykills= stats.getEnemyKills(i);
int deaths= stats.getDeaths(i);
int unitsProduced= stats.getUnitsProduced(i);
int resourcesHarvested= stats.getResourcesHarvested(i);
int score= kills*100 + unitsProduced*50 + resourcesHarvested/10;
int score= enemykills*100 + unitsProduced*50 + resourcesHarvested/10;
string controlString;
if(stats.getPersonalityType(i) == fpt_Observer) {
@ -161,6 +162,7 @@ void BattleEnd::render(){
textRenderer->render(stats.getFactionTypeName(i), textX, bm+280);
textRenderer->render(intToStr(team).c_str(), textX, bm+240);
textRenderer->render(intToStr(kills).c_str(), textX, bm+200);
textRenderer->render(intToStr(enemykills).c_str(), textX, bm+180);
textRenderer->render(intToStr(deaths).c_str(), textX, bm+160);
textRenderer->render(intToStr(unitsProduced).c_str(), textX, bm+120);
textRenderer->render(intToStr(resourcesHarvested).c_str(), textX, bm+80);
@ -172,6 +174,7 @@ void BattleEnd::render(){
textRenderer->render(lang.get("Faction"), lm, bm+280);
textRenderer->render(lang.get("Team"), lm, bm+240);
textRenderer->render(lang.get("Kills"), lm, bm+200);
textRenderer->render(lang.get("EnemyKills"), lm, bm+180);
textRenderer->render(lang.get("Deaths"), lm, bm+160);
textRenderer->render(lang.get("UnitsProduced"), lm, bm+120);
textRenderer->render(lang.get("ResourcesHarvested"), lm, bm+80);
@ -192,6 +195,15 @@ void BattleEnd::render(){
textRenderer->render(header, lm+250, bm+550);
string header2 = lang.get("GameDuration") + " " + floatToStr(stats.getWorldTimeElapsed() / 24.0,2);
textRenderer->render(header2, lm+250, bm+530);
header2 = lang.get("GameMaxConcurrentUnitCount") + " " + intToStr(stats.getMaxConcurrentUnitCount());
textRenderer->render(header2, lm+250, bm+510);
header2 = lang.get("GameTotalEndGameConcurrentUnitCount") + " " + intToStr(stats.getTotalEndGameConcurrentUnitCount());
textRenderer->render(header2, lm+250, bm+490);
textRenderer->end();
renderer.renderButton(&buttonExit);

View File

@ -1819,7 +1819,7 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
//damage the unit
if(attacked->decHp(static_cast<int>(damage))){
world->getStats()->kill(attacker->getFactionIndex(), attacked->getFactionIndex());
world->getStats()->kill(attacker->getFactionIndex(), attacked->getFactionIndex(), attacker->getTeam() != attacked->getTeam());
attacker->incKills();
switch(this->game->getGameSettings()->getPathFinderType()) {