diff --git a/source/glest_game/game/stats.cpp b/source/glest_game/game/stats.cpp index 41260b6a..a0902dfb 100644 --- a/source/glest_game/game/stats.cpp +++ b/source/glest_game/game/stats.cpp @@ -111,20 +111,28 @@ void Stats::setVictorious(int playerIndex){ playerStats[playerIndex].victory= true; } -void Stats::kill(int killerFactionIndex, int killedFactionIndex, bool isEnemy) { - playerStats[killerFactionIndex].kills++; - playerStats[killedFactionIndex].deaths++; - if(isEnemy == true) { +void Stats::kill(int killerFactionIndex, int killedFactionIndex, bool isEnemy, bool isDeathCounted, bool isKillCounted) { + if(isKillCounted == true){ + playerStats[killerFactionIndex].kills++; + } + if(isDeathCounted == true){ + playerStats[killedFactionIndex].deaths++; + } + if(isEnemy == true && isKillCounted == true) { playerStats[killerFactionIndex].enemykills++; } } -void Stats::die(int diedFactionIndex){ - playerStats[diedFactionIndex].deaths++; +void Stats::die(int diedFactionIndex, bool isDeathCounted){ + if(isDeathCounted == true){ + playerStats[diedFactionIndex].deaths++; + } } -void Stats::produce(int producerFactionIndex){ - playerStats[producerFactionIndex].unitsProduced++; +void Stats::produce(int producerFactionIndex, bool isProductionCounted){ + if(isProductionCounted == true){ + playerStats[producerFactionIndex].unitsProduced++; + } } void Stats::harvest(int harvesterFactionIndex, int amount){ diff --git a/source/glest_game/game/stats.h b/source/glest_game/game/stats.h index 493aae16..0c5b9629 100644 --- a/source/glest_game/game/stats.h +++ b/source/glest_game/game/stats.h @@ -124,9 +124,9 @@ public: 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, bool isEnemy); - void die(int diedFactionIndex); - void produce(int producerFactionIndex); + void kill(int killerFactionIndex, int killedFactionIndex, bool isEnemy, bool isDeathCounted, bool isKillCounted); + void die(int diedFactionIndex, bool isDeathCounted); + void produce(int producerFactionIndex, bool isProductionCounted); void harvest(int harvesterFactionIndex, int amount); void setPlayerName(int playerIndex, string value) {playerStats[playerIndex].playerName = value; } void setPlayerColor(int playerIndex, Vec3f value) {playerStats[playerIndex].playerColor = value; } diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index e648fb5a..b5e52439 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -928,7 +928,7 @@ void Faction::applyCostsOnInterval(const ResourceType *rtApply) { bool decHpResult = unit->decHp(unit->getType()->getMaxHp() / 3); if(decHpResult) { unit->setCauseOfDeath(ucodStarvedResource); - world->getStats()->die(unit->getFactionIndex()); + world->getStats()->die(unit->getFactionIndex(),unit->getType()->getCountUnitDeathInStats()); scriptManager->onUnitDied(unit); } StaticSound *sound= unit->getType()->getFirstStOfClass(scDie)->getSound(); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 71b5f793..a33866e5 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -2145,7 +2145,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) { this->setLastAttackerUnitId(source->getId()); this->setCauseOfDeath(ucodAttackBoost); - Unit::game->getWorld()->getStats()->die(getFactionIndex()); + Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); game->getScriptManager()->onUnitDied(this); StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); @@ -2224,7 +2224,7 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) { this->setLastAttackerUnitId(source->getId()); this->setCauseOfDeath(ucodAttackBoost); - Unit::game->getWorld()->getStats()->die(getFactionIndex()); + Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); game->getScriptManager()->onUnitDied(this); StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); @@ -2288,7 +2288,7 @@ void Unit::tick() { if(decHpResult) { this->setCauseOfDeath(ucodStarvedRegeneration); - Unit::game->getWorld()->getStats()->die(getFactionIndex()); + Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); game->getScriptManager()->onUnitDied(this); } StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); @@ -2322,7 +2322,7 @@ void Unit::tick() { if(decHpResult) { this->setCauseOfDeath(ucodStarvedRegeneration); - Unit::game->getWorld()->getStats()->die(getFactionIndex()); + Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); game->getScriptManager()->onUnitDied(this); } StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index df6ae703..e2e24916 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -502,6 +502,28 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const loadedFileList[meetingPointNode->getAttribute("image-path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,meetingPointNode->getAttribute("image-path")->getRestrictedValue())); } + //countUnitDeathInStats + if(parametersNode->hasChild("count-unit-death-in-stats")){ + const XmlNode *countUnitDeathInStatsNode= parametersNode->getChild("count-unit-death-in-stats"); + countUnitDeathInStats= countUnitDeathInStatsNode->getAttribute("value")->getBoolValue(); + } else { + countUnitDeathInStats=true; + } + //countUnitProductionInStats + if(parametersNode->hasChild("count-unit-production-in-stats")){ + const XmlNode *countUnitProductionInStatsNode= parametersNode->getChild("count-unit-production-in-stats"); + countUnitProductionInStats= countUnitProductionInStatsNode->getAttribute("value")->getBoolValue(); + } else { + countUnitProductionInStats=true; + } + //countUnitKillInStats + if(parametersNode->hasChild("count-unit-kill-in-stats")){ + const XmlNode *countUnitKillInStatsNode= parametersNode->getChild("count-unit-kill-in-stats"); + countUnitKillInStats= countUnitKillInStatsNode->getAttribute("value")->getBoolValue(); + } else { + countUnitKillInStats=true; + } + //selection sounds const XmlNode *selectionSoundNode= parametersNode->getChild("selection-sounds"); if(selectionSoundNode->getAttribute("enabled")->getBoolValue()){ diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index 60598510..54b9ef1c 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -133,6 +133,11 @@ private: bool meetingPoint; Texture2D *meetingPointImage; + // for dummy units and units used as shots and so on .... + bool countUnitDeathInStats; + bool countUnitProductionInStats; + bool countUnitKillInStats; + //OPTIMIZATION: store first command type and skill type of each class const CommandType *firstCommandTypeOfClass[ccCount]; const SkillType *firstSkillTypeOfClass[scCount]; @@ -176,6 +181,10 @@ public: const Resource *getStoredResource(int i) const {return &storedResources[i];} bool getCellMapCell(int x, int y, CardinalDir facing) const; bool getMeetingPoint() const {return meetingPoint;} + bool getCountUnitDeathInStats() const {return countUnitDeathInStats;} + bool getCountUnitProductionInStats() const {return countUnitProductionInStats;} + bool getCountUnitKillInStats() const {return countUnitKillInStats;} + bool isMobile() const {return (firstSkillTypeOfClass[scMove] != NULL);} Texture2D *getMeetingPointImage() const {return meetingPointImage;} StaticSound *getSelectionSound() const {return selectionSounds.getRandSound();} diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index eea581d1..44b23cb9 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -247,7 +247,7 @@ void UnitUpdater::updateUnit(Unit *unit) { else { spawned->create(); spawned->born(ct); - world->getStats()->produce(unit->getFactionIndex()); + world->getStats()->produce(unit->getFactionIndex(),spawned->getType()->getCountUnitProductionInStats()); const CommandType *ct= spawned->computeCommandType(command->getPos(),command->getUnit()); if(ct != NULL){ if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -1813,7 +1813,7 @@ void UnitUpdater::updateProduce(Unit *unit, int frameIndex) { else{ produced->create(); produced->born(ct); - world->getStats()->produce(unit->getFactionIndex()); + world->getStats()->produce(unit->getFactionIndex(),produced->getType()->getCountUnitProductionInStats()); const CommandType *ct= produced->computeCommandType(unit->getMeetingPos()); if(ct!=NULL){ if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -2062,7 +2062,7 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac //damage the unit if(attacked->decHp(static_cast(damage))) { - world->getStats()->kill(attacker->getFactionIndex(), attacked->getFactionIndex(), attacker->getTeam() != attacked->getTeam()); + world->getStats()->kill(attacker->getFactionIndex(), attacked->getFactionIndex(), attacker->getTeam() != attacked->getTeam(),attacked->getType()->getCountUnitDeathInStats(),attacked->getType()->getCountUnitKillInStats()); attacker->incKills(attacked->getTeam()); switch(this->game->getGameSettings()->getPathFinderType()) {