diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 8df93965..fbd2dac9 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -398,7 +398,9 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const{ sprintf(szBuf,"In [%s::%s Line: %d] Can not find command type for network command = [%s]\n%s\n in unit = %d [%s][%s].\nGame out of synch.", __FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str(),unit->getType()->getCommandTypeListDesc().c_str(),unit->getId(), unit->getFullName().c_str(),unit->getDesc().c_str()); - throw runtime_error(szBuf); + std::string worldLog = world->DumpWorldToLog(); + std::string sError = "worldLog = " + worldLog + " " + string(szBuf); + throw runtime_error(sError); } CardinalDir facing; diff --git a/source/glest_game/game/game_constants.h b/source/glest_game/game/game_constants.h index eb05fdca..eae4d395 100644 --- a/source/glest_game/game/game_constants.h +++ b/source/glest_game/game/game_constants.h @@ -66,8 +66,8 @@ public: assertDirValid(v); value = static_cast(v); } - operator Enum() { return value; } - //int asInt() { return (int)value; } + operator Enum() const { return value; } + int asInt() const { return (int)value; } static void assertDirValid(int v) { assert(v >= 0 && v < 4); } void operator++() { diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 91a4040a..0998613f 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -342,6 +342,10 @@ void Gui::hotKey(char key){ else if(key=='?') { this->showDebugUI = !this->showDebugUI; } + else if(key=='|') { + std::string worldLog = world->DumpWorldToLog(); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] worldLog dumped to [%s]\n",__FILE__,__FUNCTION__,__LINE__,worldLog.c_str()); + } else if(key=='R'){ // Here the user triggers a unit rotation while placing a unit if(allowRotateUnits == true && isPlacingBuilding()) { diff --git a/source/glest_game/type_instances/command.cpp b/source/glest_game/type_instances/command.cpp index 69daa7a9..351fe335 100644 --- a/source/glest_game/type_instances/command.cpp +++ b/source/glest_game/type_instances/command.cpp @@ -12,8 +12,9 @@ #include "command.h" #include "command_type.h" -#include "leak_dumper.h" #include "util.h" +#include "conversion.h" +#include "leak_dumper.h" using namespace Shared::Util; @@ -63,4 +64,10 @@ void Command::setUnit(Unit *unit){ this->unitRef= unit; } +std::string Command::toString() const { + std::string result; + result = "commandType = " + commandType->toString() + " pos = " + pos.getString() + " facing = " + intToStr(facing.asInt()); + return result; +} + }}//end namespace diff --git a/source/glest_game/type_instances/command.h b/source/glest_game/type_instances/command.h index d06b6534..84521f69 100644 --- a/source/glest_game/type_instances/command.h +++ b/source/glest_game/type_instances/command.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -55,6 +55,8 @@ public: void setCommandType(const CommandType *commandType); void setPos(const Vec2i &pos); void setUnit(Unit *unit); + + std::string toString() const; }; }}//end namespace diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index c403fbbc..107efac2 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -478,4 +478,40 @@ void Faction::resetResourceAmount(const ResourceType *rt){ assert(false); } +std::string Faction::toString() const { + std::string result = ""; + + result = "FactionIndex = " + intToStr(this->index) + "\n"; + result += "teamIndex = " + intToStr(this->teamIndex) + "\n"; + result += "startLocationIndex = " + intToStr(this->startLocationIndex) + "\n"; + result += "thisFaction = " + intToStr(this->thisFaction) + "\n"; + result += "control = " + intToStr(this->control) + "\n"; + + result += this->factionType->toString() + "\n"; + + result += this->upgradeManager.toString() + "\n"; + + result += "ResourceCount = " + intToStr(resources.size()) + "\n"; + for(int idx = 0; idx < resources.size(); idx ++) { + result += "index = " + intToStr(idx) + " " + resources[idx].getDescription() + "\n"; + } + + result += "StoreCount = " + intToStr(store.size()) + "\n"; + for(int idx = 0; idx < store.size(); idx ++) { + result += "index = " + intToStr(idx) + " " + store[idx].getDescription() + "\n"; + } + + result += "Allies = " + intToStr(allies.size()) + "\n"; + for(int idx = 0; idx < allies.size(); idx ++) { + result += "index = " + intToStr(idx) + " name: " + allies[idx]->factionType->getName() + " factionindex = " + intToStr(allies[idx]->index) + "\n"; + } + + result += "Units = " + intToStr(units.size()) + "\n"; + for(int idx = 0; idx < units.size(); idx ++) { + result += units[idx]->toString() + "\n"; + } + + return result; +} + }}//end namespace diff --git a/source/glest_game/type_instances/faction.h b/source/glest_game/type_instances/faction.h index 1ec78257..e35292bb 100644 --- a/source/glest_game/type_instances/faction.h +++ b/source/glest_game/type_instances/faction.h @@ -133,6 +133,8 @@ public: void incResourceAmount(const ResourceType *rt, int amount); void setResourceBalance(const ResourceType *rt, int balance); + std::string toString() const; + private: void limitResourcesToStore(); void resetResourceAmount(const ResourceType *rt); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 0de01f99..d2be5cd3 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -73,6 +73,17 @@ Vec2i UnitPath::pop(){ return p; } +std::string UnitPath::toString() const { + std::string result = ""; + + result = "unit path blockCount = " + intToStr(blockCount) + " pathQueue size = " + intToStr(pathQueue.size()); + for(int idx = 0; idx < pathQueue.size(); idx++) { + result += " index = " + intToStr(idx) + " " + pathQueue[idx].getString(); + } + + return result; +} + // ===================================================== // class UnitReference // ===================================================== @@ -128,6 +139,7 @@ Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map this->faction=faction; this->map= map; level= NULL; + loadType= NULL; setModelFacing(placeFacing); @@ -1241,4 +1253,80 @@ void Unit::logSynchData(string source) { } } +std::string Unit::toString() const { + std::string result = ""; + +/* + result += "id = " + intToStr(this->id); + result += " name [" + this->getFullName() + "]"; + result += " desc: " + this->getDesc(); +*/ + result += "id = " + intToStr(this->id); + if(this->type != NULL) { + result += " name [" + this->type->getName() + "]"; + } + result += " hp = " + intToStr(this->hp); + result += " ep = " + intToStr(this->ep); + result += " loadCount = " + intToStr(this->loadCount); + result += " deadCount = " + intToStr(this->deadCount); + result += " progress = " + floatToStr(this->progress); + result += " lastAnimProgress = " + floatToStr(this->lastAnimProgress); + result += " animProgress = " + floatToStr(this->animProgress); + result += " highlight = " + floatToStr(this->highlight); + result += " progress2 = " + intToStr(this->progress2); + result += " kills = " + intToStr(this->kills); + + if(this->targetRef.getUnit() != NULL) { + result += " targetRef = " + this->targetRef.getUnit()->toString(); + } + result += " currField = " + intToStr(this->currField); + result += " targetField = " + intToStr(this->targetField); + if(level != NULL) { + result += " level = " + level->getName(); + } + + result += " pos = " + pos.getString(); + result += " lastPos = " + lastPos.getString(); + result += " targetPos = " + targetPos.getString(); + result += " targetVec = " + targetVec.getString(); + result += " meetingPos = " + meetingPos.getString(); + + result += " lastRotation = " + floatToStr(this->lastRotation); + result += " targetRotation = " + floatToStr(this->targetRotation); + result += " rotation = " + floatToStr(this->rotation); + + if(loadType != NULL) { + result += " loadType = " + loadType->getName(); + } + + if(currSkill != NULL) { + result += " currSkill = " + currSkill->getName(); + } + + result += " toBeUndertaken = " + intToStr(this->toBeUndertaken); + result += " alive = " + intToStr(this->alive); + result += " showUnitParticles = " + intToStr(this->showUnitParticles); + + result += " totalUpgrade = " + totalUpgrade.toString(); + + result += " " + unitPath.toString() + "\n"; + + result += "Command count = " + intToStr(commands.size()) + "\n"; + + int cmdIdx = 0; + for(Commands::const_iterator iterList = commands.begin(); iterList != commands.end(); ++iterList) { + result += " index = " + intToStr(cmdIdx) + " "; + const Command *cmd = *iterList; + if(cmd != NULL) { + result += cmd->toString() + "\n"; + } + cmdIdx++; + } + + result += "allowRotateUnits = " + intToStr(allowRotateUnits) + "\n"; + result += "modelFacing = " + intToStr(modelFacing.asInt()) + "\n"; + + return result; +} + }}//end namespace diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index e569b2f1..467c1e2a 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -114,6 +114,8 @@ public: void incBlockCount(); void push(const Vec2i &path); Vec2i pop(); + + std::string toString() const; }; // =============================== @@ -311,6 +313,8 @@ public: bool isMeetingPointSettable() const; + std::string toString() const; + private: float computeHeight(const Vec2i &pos) const; void updateTarget(); diff --git a/source/glest_game/type_instances/upgrade.cpp b/source/glest_game/type_instances/upgrade.cpp new file mode 100644 index 00000000..6afb89af --- /dev/null +++ b/source/glest_game/type_instances/upgrade.cpp @@ -0,0 +1,164 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2008 Martio Figueroa +// +// You can redistribute this code 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 +// ============================================================== + +#include "upgrade.h" + +#include + +#include "unit.h" +#include "util.h" +#include "upgrade_type.h" +#include "conversion.h" +#include "leak_dumper.h" + +using namespace std; +using namespace Shared::Util; + +namespace Glest{ namespace Game{ + +// ===================================================== +// class Upgrade +// ===================================================== + +Upgrade::Upgrade(const UpgradeType *type, int factionIndex){ + state= usUpgrading; + this->factionIndex= factionIndex; + this->type= type; +} + +// ============== get ============== + +UpgradeState Upgrade::getState() const{ + return state; +} + +int Upgrade::getFactionIndex() const{ + return factionIndex; +} + +const UpgradeType * Upgrade::getType() const{ + return type; +} + +// ============== set ============== + +void Upgrade::setState(UpgradeState state){ + this->state= state; +} + +std::string Upgrade::toString() const { + std::string result = ""; + + result += " state = " + intToStr(state) + " factionIndex = " + intToStr(factionIndex); + if(type != NULL) { + result += " type = " + type->getReqDesc(); + } + + return result; +} + + +// ===================================================== +// class UpgradeManager +// ===================================================== + +UpgradeManager::~UpgradeManager(){ + deleteValues(upgrades.begin(), upgrades.end()); +} + +void UpgradeManager::startUpgrade(const UpgradeType *upgradeType, int factionIndex){ + upgrades.push_back(new Upgrade(upgradeType, factionIndex)); +} + +void UpgradeManager::cancelUpgrade(const UpgradeType *upgradeType){ + Upgrades::iterator it; + + for(it=upgrades.begin(); it!=upgrades.end(); it++){ + if((*it)->getType()==upgradeType){ + break; + } + } + + if(it!=upgrades.end()){ + upgrades.erase(it); + } + else{ + throw runtime_error("Error canceling upgrade, upgrade not found in upgrade manager"); + } +} + +void UpgradeManager::finishUpgrade(const UpgradeType *upgradeType){ + Upgrades::iterator it; + + for(it=upgrades.begin(); it!=upgrades.end(); it++){ + if((*it)->getType()==upgradeType){ + break; + } + } + + if(it!=upgrades.end()){ + (*it)->setState(usUpgraded); + } + else{ + throw runtime_error("Error finishing upgrade, upgrade not found in upgrade manager"); + } +} + +bool UpgradeManager::isUpgradingOrUpgraded(const UpgradeType *upgradeType) const{ + Upgrades::const_iterator it; + + for(it= upgrades.begin(); it!=upgrades.end(); it++){ + if((*it)->getType()==upgradeType){ + return true; + } + } + + return false; +} + +bool UpgradeManager::isUpgraded(const UpgradeType *upgradeType) const{ + for(Upgrades::const_iterator it= upgrades.begin(); it!=upgrades.end(); it++){ + if((*it)->getType()==upgradeType && (*it)->getState()==usUpgraded){ + return true; + } + } + return false; +} + +bool UpgradeManager::isUpgrading(const UpgradeType *upgradeType) const{ + for(Upgrades::const_iterator it= upgrades.begin(); it!=upgrades.end(); it++){ + if((*it)->getType()==upgradeType && (*it)->getState()==usUpgrading){ + return true; + } + } + return false; +} + +void UpgradeManager::computeTotalUpgrade(const Unit *unit, TotalUpgrade *totalUpgrade) const{ + totalUpgrade->reset(); + for(Upgrades::const_iterator it= upgrades.begin(); it!=upgrades.end(); it++){ + if((*it)->getFactionIndex()==unit->getFactionIndex() + && (*it)->getType()->isAffected(unit->getType()) + && (*it)->getState()==usUpgraded) + totalUpgrade->sum((*it)->getType()); + } + +} + +std::string UpgradeManager::toString() const { + std::string result = "UpgradeCount: " + intToStr(this->getUpgradeCount()); + for(int idx = 0; idx < upgrades.size(); idx++) { + result += " index = " + intToStr(idx) + " " + upgrades[idx]->toString(); + } + return result; +} + +}}// end namespace diff --git a/source/glest_game/type_instances/upgrade.h b/source/glest_game/type_instances/upgrade.h new file mode 100644 index 00000000..c40755ad --- /dev/null +++ b/source/glest_game/type_instances/upgrade.h @@ -0,0 +1,92 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2008 Martio Figueroa +// +// You can redistribute this code 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 +// ============================================================== + +#ifndef _GLEST_GAME_UPGRADE_H_ +#define _GLEST_GAME_UPGRADE_H_ + +#include +#include + +using std::vector; + +namespace Glest{ namespace Game{ + +class Unit; +class UpgradeType; + +enum UpgradeState{ + usUpgrading, + usUpgraded, + + upgradeStateCount +}; + +class UpgradeManager; +class TotalUpgrade; + +// ===================================================== +// class Upgrade +// +/// A bonus to an UnitType +// ===================================================== + +class Upgrade{ +private: + UpgradeState state; + int factionIndex; + const UpgradeType *type; + + friend class UpgradeManager; + +public: + Upgrade(const UpgradeType *upgradeType, int factionIndex); + +private: + //get + UpgradeState getState() const; + int getFactionIndex() const; + const UpgradeType * getType() const; + + //set + void setState(UpgradeState state); + + std::string toString() const; +}; + + +// =============================== +// class UpgradeManager +// =============================== + +class UpgradeManager{ +private: + typedef vector Upgrades; + Upgrades upgrades; +public: + ~UpgradeManager(); + + int getUpgradeCount() const {return upgrades.size();} + + void startUpgrade(const UpgradeType *upgradeType, int factionIndex); + void cancelUpgrade(const UpgradeType *upgradeType); + void finishUpgrade(const UpgradeType *upgradeType); + + bool isUpgraded(const UpgradeType *upgradeType) const; + bool isUpgrading(const UpgradeType *upgradeType) const; + bool isUpgradingOrUpgraded(const UpgradeType *upgradeType) const; + void computeTotalUpgrade(const Unit *unit, TotalUpgrade *totalUpgrade) const; + + std::string toString() const; +}; + +}}//end namespace + +#endif diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp index 8c36a1f8..46ba6e4d 100644 --- a/source/glest_game/types/faction_type.cpp +++ b/source/glest_game/types/faction_type.cpp @@ -18,6 +18,7 @@ #include "resource.h" #include "platform_util.h" #include "game_util.h" +#include "conversion.h" #include "leak_dumper.h" using namespace Shared::Util; @@ -168,4 +169,22 @@ int FactionType::getStartingResourceAmount(const ResourceType *resourceType) con return 0; } +std::string FactionType::toString() const { + std::string result = ""; + + result = "Faction Name: " + name + "\n"; + + result += "Unit Type List count = " + intToStr(this->getUnitTypeCount()) + "\n"; + for(int i=0; igetUpgradeTypeCount()) + "\n"; + for(int i=0; i PairPUnitTypeInt; + typedef vector UnitTypes; + typedef vector UpgradeTypes; + typedef vector StartingUnits; + typedef vector Resources; + +private: + string name; + UnitTypes unitTypes; + UpgradeTypes upgradeTypes; + StartingUnits startingUnits; + Resources startingResources; + StrSound *music; + +public: + //init + FactionType(); + void load(const string &dir, const TechTree *techTree, Checksum* checksum); + ~FactionType(); + + //get + int getUnitTypeCount() const {return unitTypes.size();} + int getUpgradeTypeCount() const {return upgradeTypes.size();} + string getName() const {return name;} + const UnitType *getUnitType(int i) const {return &unitTypes[i];} + const UpgradeType *getUpgradeType(int i) const {return &upgradeTypes[i];} + StrSound *getMusic() const {return music;} + int getStartingUnitCount() const {return startingUnits.size();} + const UnitType *getStartingUnit(int i) const {return startingUnits[i].first;} + int getStartingUnitAmount(int i) const {return startingUnits[i].second;} + + const UnitType *getUnitType(const string &name) const; + const UpgradeType *getUpgradeType(const string &name) const; + int getStartingResourceAmount(const ResourceType *resourceType) const; + + std::string toString() const; +}; + +}}//end namespace + +#endif diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 83f09b23..a02b412e 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -604,4 +604,69 @@ string UnitType::getCommandTypeListDesc() const { } +std::string UnitType::toString() const { + std::string result = ""; + + result = "Unit Name: [" + name + "] id = " + intToStr(id); + result += " maxHp = " + intToStr(maxHp); + result += " hpRegeneration = " + intToStr(hpRegeneration); + result += " maxEp = " + intToStr(maxEp); + result += " epRegeneration = " + intToStr(epRegeneration); + + for(int i = 0; i < fieldCount; i++) { + result += " fields index = " + intToStr(i) + " value = " + intToStr(fields[i]); + } + for(int i = 0; i < pCount; i++) { + result += " properties index = " + intToStr(i) + " value = " + intToStr(properties[i]); + } + + result += " armor = " + intToStr(armor); + + if(armorType != NULL) { + result += " armorType Name: [" + armorType->getName() + " id = " + intToStr(armorType->getId()); + } + + result += " light = " + intToStr(light); + result += " lightColor = " + lightColor.getString(); + result += " multiSelect = " + intToStr(multiSelect); + result += " sight = " + intToStr(sight); + result += " size = " + intToStr(size); + result += " height = " + intToStr(height); + result += " rotatedBuildPos = " + floatToStr(rotatedBuildPos); + result += " rotationAllowed = " + intToStr(rotationAllowed); + + if(cellMap != NULL) { + result += " cellMap:"; + for(int i = 0; i < size; ++i) { + for(int j = 0; j < size; ++j){ + result += " i = " + intToStr(i) + " j = " + intToStr(j) + " value = " + intToStr(cellMap[i*size+j]); + } + } + } + + result += " skillTypes:"; + for(int i = 0; i < skillTypes.size(); ++i) { + result += " i = " + intToStr(i) + " " + skillTypes[i]->toString(); + } + + result += " commandTypes:"; + for(int i = 0; i < commandTypes.size(); ++i) { + result += " i = " + intToStr(i) + " " + commandTypes[i]->toString(); + } + + result += " storedResources:"; + for(int i = 0; i < storedResources.size(); ++i) { + result += " i = " + intToStr(i) + " " + storedResources[i].getDescription(); + } + + result += " levels:"; + for(int i = 0; i < levels.size(); ++i) { + result += " i = " + intToStr(i) + " " + levels[i].getName(); + } + + result += " meetingPoint = " + intToStr(meetingPoint); + + return result; +} + }}//end namespace diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index 6bc88715..db88c4ee 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -189,6 +189,8 @@ public: float getRotatedBuildPos() { return rotatedBuildPos; } void setRotatedBuildPos(float value) { rotatedBuildPos = value; } + std::string toString() const; + private: void computeFirstStOfClass(); void computeFirstCtOfClass(); diff --git a/source/glest_game/types/upgrade_type.h b/source/glest_game/types/upgrade_type.h new file mode 100644 index 00000000..60ff05fd --- /dev/null +++ b/source/glest_game/types/upgrade_type.h @@ -0,0 +1,105 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2008 Martio Figueroa +// +// You can redistribute this code 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 +// ============================================================== + +#ifndef _GLEST_GAME_UPGRADETYPE_H_ +#define _GLEST_GAME_UPGRADETYPE_H_ + +#include "element_type.h" +#include "checksum.h" +#include "conversion.h" + +using Shared::Util::Checksum; +using namespace Shared::Util; + +namespace Glest{ namespace Game{ + +class TechTree; +class FactionType; +class UnitType; + +// =============================== +// class UpgradeTypeBase +// =============================== + +class UpgradeTypeBase{ +protected: + int maxHp; + int sight; + int maxEp; + int armor; + int attackStrength; + int attackRange; + int moveSpeed; + int prodSpeed; + +public: + int getMaxHp() const {return maxHp;} + int getSight() const {return sight;} + int getMaxEp() const {return maxEp;} + int getArmor() const {return armor;} + int getAttackStrength() const {return attackStrength;} + int getAttackRange() const {return attackRange;} + int getMoveSpeed() const {return moveSpeed;} + int getProdSpeed() const {return prodSpeed;} + + std::string toString() const { + std::string result = ""; + + result += "maxHp = " + intToStr(maxHp); + result += " sight = " + intToStr(sight); + result += " maxEp = " + intToStr(maxEp); + result += " armor = " + intToStr(armor); + result += " attackStrength = " + intToStr(attackStrength); + result += " attackRange = " + intToStr(attackRange); + result += " moveSpeed = " + intToStr(moveSpeed); + result += " prodSpeed = " + intToStr(prodSpeed); + + return result; + } +}; + +// =============================== +// class UpgradeType +// =============================== + +class UpgradeType: public UpgradeTypeBase, public ProducibleType{ +private: + vector effects; + +public: + void preLoad(const string &dir); + void load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum); + + //get all + int getEffectCount() const {return effects.size();} + const UnitType * getEffect(int i) const {return effects[i];} + bool isAffected(const UnitType *unitType) const; + + //other methods + virtual string getReqDesc() const; +}; + +// =============================== +// class TotalUpgrade +// =============================== + +class TotalUpgrade: public UpgradeTypeBase{ +public: + TotalUpgrade(); + + void reset(); + void sum(const UpgradeType *ut); + void incLevel(const UnitType *ut); +}; + +}}//end namespace + +#endif diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index e9e74231..74dcc344 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -800,4 +800,41 @@ void World::computeFow(){ } } +std::string World::DumpWorldToLog() const { + string debugWorldLogFile = Config::getInstance().getString("DebugWorldLogFile","debugWorld.log"); + if(getGameReadWritePath() != "") { + debugWorldLogFile = getGameReadWritePath() + debugWorldLogFile; + } + + std::ofstream logFile; + logFile.open(debugWorldLogFile.c_str(), ios_base::out | ios_base::trunc); + + logFile << "World debug information:" << std::endl; + logFile << "========================" << std::endl; + + //factions (and their related info) + for(int i = 0; i < getFactionCount(); ++i) { + logFile << "Faction detail for index: " << i << std::endl; + logFile << "--------------------------" << std::endl; + logFile << getFaction(i)->toString() << std::endl; + } + + //undertake the dead + logFile << "Undertake stats:" << std::endl; + for(int i = 0; i < getFactionCount(); ++i){ + logFile << "Faction: " << getFaction(i)->getType()->getName() << std::endl; + int unitCount = getFaction(i)->getUnitCount(); + for(int j= unitCount - 1; j >= 0; j--){ + Unit *unit= getFaction(i)->getUnit(j); + if(unit->getToBeUndertaken()) { + logFile << "Undertake unit index = " << j << unit->getFullName() << std::endl; + } + } + } + + logFile.close(); + + return debugWorldLogFile; +} + }}//end namespace diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 138ec058..fef0a353 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -153,6 +153,7 @@ public: Game * getGame() { return game; } void setFogOfWar(bool value); + std::string DumpWorldToLog() const; private: