- a ton more load game state now working (including commands)

This commit is contained in:
Mark Vejvoda 2012-03-13 15:21:25 +00:00
parent e3fde99359
commit 5f95b08c17
37 changed files with 1324 additions and 325 deletions

View File

@ -22,30 +22,38 @@ using namespace Shared::Util;
namespace Glest { namespace Game {
void Task::saveGame(XmlNode *rootNode) const {
std::map<string,string> mapTagReplacements;
XmlNode *taskNode = rootNode->addChild("Task");
taskNode->addAttribute("taskClass",intToStr(taskClass), mapTagReplacements);
Task::Task() {
taskClass = tcProduce;
}
//void Task::saveGame(XmlNode *rootNode) const {
// std::map<string,string> mapTagReplacements;
// XmlNode *taskNode = rootNode->addChild("Task");
//}
// =====================================================
// class ProduceTask
// =====================================================
ProduceTask::ProduceTask(UnitClass unitClass){
ProduceTask::ProduceTask() : Task() {
taskClass= tcProduce;
unitType= NULL;
resourceType= NULL;
}
ProduceTask::ProduceTask(UnitClass unitClass) : Task() {
taskClass= tcProduce;
this->unitClass= unitClass;
unitType= NULL;
resourceType= NULL;
}
ProduceTask::ProduceTask(const UnitType *unitType){
ProduceTask::ProduceTask(const UnitType *unitType) : Task() {
taskClass= tcProduce;
this->unitType= unitType;
resourceType= NULL;
}
ProduceTask::ProduceTask(const ResourceType *resourceType){
ProduceTask::ProduceTask(const ResourceType *resourceType) : Task() {
taskClass= tcProduce;
unitType= NULL;
this->resourceType= resourceType;
@ -60,10 +68,10 @@ string ProduceTask::toString() const{
}
void ProduceTask::saveGame(XmlNode *rootNode) const {
Task::saveGame(rootNode);
std::map<string,string> mapTagReplacements;
XmlNode *produceTaskNode = rootNode->addChild("ProduceTask");
XmlNode *taskNode = rootNode->addChild("Task");
taskNode->addAttribute("taskClass",intToStr(taskClass), mapTagReplacements);
XmlNode *produceTaskNode = taskNode->addChild("ProduceTask");
// UnitClass unitClass;
produceTaskNode->addAttribute("unitClass",intToStr(unitClass), mapTagReplacements);
@ -77,9 +85,35 @@ void ProduceTask::saveGame(XmlNode *rootNode) const {
}
}
ProduceTask * ProduceTask::loadGame(const XmlNode *rootNode, Faction *faction) {
const XmlNode *produceTaskNode = rootNode->getChild("ProduceTask");
ProduceTask *newTask = new ProduceTask();
// UnitClass unitClass;
newTask->unitClass = static_cast<UnitClass>(produceTaskNode->getAttribute("unitClass")->getIntValue());
// const UnitType *unitType;
if(produceTaskNode->hasAttribute("unitType")) {
string unitTypeName = produceTaskNode->getAttribute("unitType")->getValue();
newTask->unitType = faction->getType()->getUnitType(unitTypeName);
}
// const ResourceType *resourceType;
if(produceTaskNode->hasAttribute("resourceType")) {
string resourceTypeName = produceTaskNode->getAttribute("resourceType")->getValue();
newTask->resourceType = faction->getTechTree()->getResourceType(resourceTypeName);
}
return newTask;
}
// =====================================================
// class BuildTask
// =====================================================
BuildTask::BuildTask() {
taskClass= tcBuild;
this->unitType= NULL;
resourceType= NULL;
forcePos= false;
}
BuildTask::BuildTask(const UnitType *unitType){
taskClass= tcBuild;
@ -112,10 +146,10 @@ string BuildTask::toString() const{
}
void BuildTask::saveGame(XmlNode *rootNode) const {
Task::saveGame(rootNode);
std::map<string,string> mapTagReplacements;
XmlNode *buildTaskNode = rootNode->addChild("BuildTask");
XmlNode *taskNode = rootNode->addChild("Task");
taskNode->addAttribute("taskClass",intToStr(taskClass), mapTagReplacements);
XmlNode *buildTaskNode = taskNode->addChild("BuildTask");
// const UnitType *unitType;
if(unitType != NULL) {
@ -131,9 +165,32 @@ void BuildTask::saveGame(XmlNode *rootNode) const {
buildTaskNode->addAttribute("pos",pos.getString(), mapTagReplacements);
}
BuildTask * BuildTask::loadGame(const XmlNode *rootNode, Faction *faction) {
const XmlNode *buildTaskNode = rootNode->getChild("BuildTask");
BuildTask *newTask = new BuildTask();
if(buildTaskNode->hasAttribute("unitType")) {
string unitTypeName = buildTaskNode->getAttribute("unitType")->getValue();
newTask->unitType = faction->getType()->getUnitType(unitTypeName);
}
if(buildTaskNode->hasAttribute("resourceType")) {
string resourceTypeName = buildTaskNode->getAttribute("resourceType")->getValue();
newTask->resourceType = faction->getTechTree()->getResourceType(resourceTypeName);
}
newTask->forcePos = buildTaskNode->getAttribute("forcePos")->getIntValue();
newTask->pos = Vec2i::strToVec2(buildTaskNode->getAttribute("pos")->getValue());
return newTask;
}
// =====================================================
// class UpgradeTask
// =====================================================
UpgradeTask::UpgradeTask() {
taskClass= tcUpgrade;
this->upgradeType= NULL;
}
UpgradeTask::UpgradeTask(const UpgradeType *upgradeType){
taskClass= tcUpgrade;
@ -149,16 +206,28 @@ string UpgradeTask::toString() const{
}
void UpgradeTask::saveGame(XmlNode *rootNode) const {
Task::saveGame(rootNode);
std::map<string,string> mapTagReplacements;
XmlNode *upgradeTaskNode = rootNode->addChild("UpgradeTask");
XmlNode *taskNode = rootNode->addChild("Task");
taskNode->addAttribute("taskClass",intToStr(taskClass), mapTagReplacements);
XmlNode *upgradeTaskNode = taskNode->addChild("UpgradeTask");
if(upgradeType != NULL) {
upgradeType->saveGame(upgradeTaskNode);
//upgradeType->saveGame(upgradeTaskNode);
upgradeTaskNode->addAttribute("upgradeType",upgradeType->getName(), mapTagReplacements);
}
}
UpgradeTask * UpgradeTask::loadGame(const XmlNode *rootNode, Faction *faction) {
const XmlNode *upgradeTaskNode = rootNode->getChild("UpgradeTask");
UpgradeTask *newTask = new UpgradeTask();
if(upgradeTaskNode->hasAttribute("upgradeType")) {
string upgradeTypeName = upgradeTaskNode->getAttribute("upgradeType")->getValue();
newTask->upgradeType = faction->getType()->getUpgradeType(upgradeTypeName);
}
return newTask;
}
// =====================================================
// class Ai
// =====================================================
@ -962,6 +1031,50 @@ void Ai::saveGame(XmlNode *rootNode) const {
// RandomGen random;
aiNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements);
// std::map<int,int> factionSwitchTeamRequestCount;
}
void Ai::loadGame(const XmlNode *rootNode, Faction *faction) {
const XmlNode *aiNode = rootNode->getChild("Ai");
startLoc = aiNode->getAttribute("startLoc")->getIntValue();
randomMinWarriorsReached = aiNode->getAttribute("randomMinWarriorsReached")->getIntValue();
vector<XmlNode *> taskNodeList = aiNode->getChildList("Task");
for(unsigned int i = 0; i < taskNodeList.size(); ++i) {
XmlNode *taskNode = taskNodeList[i];
TaskClass taskClass = static_cast<TaskClass>(taskNode->getAttribute("taskClass")->getIntValue());
switch(taskClass) {
case tcProduce:
{
ProduceTask *newTask = ProduceTask::loadGame(taskNode, faction);
tasks.push_back(newTask);
}
break;
case tcBuild:
{
BuildTask *newTask = BuildTask::loadGame(taskNode, faction);
tasks.push_back(newTask);
}
break;
case tcUpgrade:
{
UpgradeTask *newTask = UpgradeTask::loadGame(taskNode, faction);
tasks.push_back(newTask);
}
break;
}
}
vector<XmlNode *> expansionPositionsNodeList = aiNode->getChildList("expansionPositions");
for(unsigned int i = 0; i < expansionPositionsNodeList.size(); ++i) {
XmlNode *expansionPositionsNode = expansionPositionsNodeList[i];
Vec2i pos = Vec2i::strToVec2(expansionPositionsNode->getAttribute("pos")->getValue());
expansionPositions.push_back(pos);
}
// RandomGen random;
random.setLastNumber(aiNode->getAttribute("random")->getIntValue());
// std::map<int,int> factionSwitchTeamRequestCount;
}
}}//end namespace

View File

@ -48,11 +48,12 @@ protected:
TaskClass taskClass;
public:
Task();
virtual ~Task(){}
TaskClass getClass() const {return taskClass;}
virtual string toString() const= 0;
virtual void saveGame(XmlNode *rootNode) const;
virtual void saveGame(XmlNode *rootNode) const = 0;
};
// ==================== ProduceTask ====================
@ -63,6 +64,7 @@ private:
const UnitType *unitType;
const ResourceType *resourceType;
ProduceTask();
public:
ProduceTask(UnitClass unitClass);
ProduceTask(const UnitType *unitType);
@ -74,6 +76,7 @@ public:
virtual string toString() const;
virtual void saveGame(XmlNode *rootNode) const;
static ProduceTask * loadGame(const XmlNode *rootNode, Faction *faction);
};
// ==================== BuildTask ====================
@ -85,8 +88,10 @@ private:
bool forcePos;
Vec2i pos;
BuildTask();
public:
BuildTask(const UnitType *unitType= NULL);
BuildTask(const UnitType *unitType);
BuildTask(const ResourceType *resourceType);
BuildTask(const UnitType *unitType, const Vec2i &pos);
@ -97,6 +102,7 @@ public:
virtual string toString() const;
virtual void saveGame(XmlNode *rootNode) const;
static BuildTask * loadGame(const XmlNode *rootNode, Faction *faction);
};
// ==================== UpgradeTask ====================
@ -105,12 +111,14 @@ class UpgradeTask: public Task{
private:
const UpgradeType *upgradeType;
UpgradeTask();
public:
UpgradeTask(const UpgradeType *upgradeType= NULL);
UpgradeTask(const UpgradeType *upgradeType);
const UpgradeType *getUpgradeType() const {return upgradeType;}
virtual string toString() const;
virtual void saveGame(XmlNode *rootNode) const;
static UpgradeTask * loadGame(const XmlNode *rootNode, Faction *faction);
};
// ===============================
@ -207,6 +215,7 @@ public:
bool outputAIBehaviourToConsole() const;
void saveGame(XmlNode *rootNode) const;
void loadGame(const XmlNode *rootNode, Faction *faction);
};
}}//end namespace

View File

@ -699,4 +699,45 @@ void AiInterface::saveGame(XmlNode *rootNode) const {
}
}
// AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex, int useStartLocation) {
void AiInterface::loadGame(const XmlNode *rootNode, Faction *faction) {
XmlNode *aiInterfaceNode = NULL;
vector<XmlNode *> aiInterfaceNodeList = rootNode->getChildList("AiInterface");
for(unsigned int i = 0; i < aiInterfaceNodeList.size(); ++i) {
XmlNode *node = aiInterfaceNodeList[i];
if(node->getAttribute("factionIndex")->getIntValue() == faction->getIndex()) {
aiInterfaceNode = node;
break;
}
}
if(aiInterfaceNode != NULL) {
factionIndex = aiInterfaceNode->getAttribute("factionIndex")->getIntValue();
teamIndex = aiInterfaceNode->getAttribute("teamIndex")->getIntValue();
ai.loadGame(aiInterfaceNode, faction);
//firstTime = timeflowNode->getAttribute("firstTime")->getFloatValue();
timer = aiInterfaceNode->getAttribute("timer")->getIntValue();
// int factionIndex;
factionIndex = aiInterfaceNode->getAttribute("factionIndex")->getIntValue();
// int teamIndex;
teamIndex = aiInterfaceNode->getAttribute("teamIndex")->getIntValue();
// //config
// bool redir;
redir = aiInterfaceNode->getAttribute("redir")->getIntValue();
// int logLevel;
logLevel = aiInterfaceNode->getAttribute("logLevel")->getIntValue();
// std::map<const ResourceType *,int> cacheUnitHarvestResourceLookup;
// for(std::map<const ResourceType *,int>::const_iterator iterMap = cacheUnitHarvestResourceLookup.begin();
// iterMap != cacheUnitHarvestResourceLookup.end(); ++iterMap) {
// XmlNode *cacheUnitHarvestResourceLookupNode = aiInterfaceNode->addChild("cacheUnitHarvestResourceLookup");
//
// cacheUnitHarvestResourceLookupNode->addAttribute("key",iterMap->first->getName(), mapTagReplacements);
// cacheUnitHarvestResourceLookupNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
// }
}
}
}}//end namespace

View File

@ -104,6 +104,7 @@ public:
bool factionUsesResourceType(const FactionType *factionType, const ResourceType *rt);
void saveGame(XmlNode *rootNode) const;
void loadGame(const XmlNode *rootNode, Faction *faction);
private:
string getLogFilename() const {return "ai"+intToStr(factionIndex)+".log";}

View File

@ -441,13 +441,13 @@ void AiRuleAddTasks::execute(){
}
//buildings
if(buildingCount<6 || buildingRatio<0.20) ai->addTask(new BuildTask());
if(buildingCount<10 && workerCount>12) ai->addTask(new BuildTask());
if(buildingCount<6 || buildingRatio<0.20) ai->addTask(new BuildTask((UnitType *)NULL));
if(buildingCount<10 && workerCount>12) ai->addTask(new BuildTask((UnitType *)NULL));
//upgrades
if(upgradeCount==0 && workerCount>5) ai->addTask(new UpgradeTask());
if(upgradeCount==1 && workerCount>10) ai->addTask(new UpgradeTask());
if(upgradeCount==2 && workerCount>15) ai->addTask(new UpgradeTask());
if(ai->isStableBase()) ai->addTask(new UpgradeTask());
if(upgradeCount==0 && workerCount>5) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
if(upgradeCount==1 && workerCount>10) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
if(upgradeCount==2 && workerCount>15) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
if(ai->isStableBase()) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
}
else if(ai->getAiInterface()->getControlType() == ctCpuEasy ||
ai->getAiInterface()->getControlType() == ctNetworkCpuEasy)
@ -468,13 +468,13 @@ void AiRuleAddTasks::execute(){
if(workerCount>=15) ai->addTask(new ProduceTask(ucWarrior));
//buildings
if(buildingCount<6 || buildingRatio<0.20) ai->addTask(new BuildTask());
if(buildingCount<10 && ai->isStableBase()) ai->addTask(new BuildTask());
if(buildingCount<6 || buildingRatio<0.20) ai->addTask(new BuildTask((UnitType *)NULL));
if(buildingCount<10 && ai->isStableBase()) ai->addTask(new BuildTask((UnitType *)NULL));
//upgrades
if(upgradeCount==0 && workerCount>6) ai->addTask(new UpgradeTask());
if(upgradeCount==1 && workerCount>7) ai->addTask(new UpgradeTask());
if(upgradeCount==2 && workerCount>9) ai->addTask(new UpgradeTask());
if(upgradeCount==0 && workerCount>6) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
if(upgradeCount==1 && workerCount>7) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
if(upgradeCount==2 && workerCount>9) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
//if(ai->isStableBase()) ai->addTask(new UpgradeTask());
}
else
@ -496,14 +496,14 @@ void AiRuleAddTasks::execute(){
if(workerCount>=15) ai->addTask(new ProduceTask(ucWarrior));
//buildings
if(buildingCount<6 || buildingRatio<0.20) ai->addTask(new BuildTask());
if(buildingCount<10 && workerCount>12) ai->addTask(new BuildTask());
if(buildingCount<6 || buildingRatio<0.20) ai->addTask(new BuildTask((UnitType *)NULL));
if(buildingCount<10 && workerCount>12) ai->addTask(new BuildTask((UnitType *)NULL));
//upgrades
if(upgradeCount==0 && workerCount>5) ai->addTask(new UpgradeTask());
if(upgradeCount==1 && workerCount>10) ai->addTask(new UpgradeTask());
if(upgradeCount==2 && workerCount>15) ai->addTask(new UpgradeTask());
if(ai->isStableBase()) ai->addTask(new UpgradeTask());
if(upgradeCount==0 && workerCount>5) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
if(upgradeCount==1 && workerCount>10) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
if(upgradeCount==2 && workerCount>15) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
if(ai->isStableBase()) ai->addTask(new UpgradeTask((const UpgradeType *)NULL));
}
}
}

View File

@ -1525,63 +1525,63 @@ void PathFinder::saveGame(XmlNode *rootNode) {
XmlNode *factionsNode = pathfinderNode->addChild("factions");
// std::map<Vec2i, bool> openPosList;
XmlNode *openPosListNode = factionsNode->addChild("openPosList");
for(std::map<Vec2i, bool>::iterator iterMap = factionState.openPosList.begin();
iterMap != factionState.openPosList.end(); ++iterMap) {
openPosListNode->addAttribute("key",iterMap->first.getString(), mapTagReplacements);
openPosListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
// std::map<float, Nodes> openNodesList;
XmlNode *openNodesListNode = factionsNode->addChild("openNodesList");
for(std::map<float, Nodes>::iterator iterMap = factionState.openNodesList.begin();
iterMap != factionState.openNodesList.end(); ++iterMap) {
Nodes &nodeList = iterMap->second;
for(unsigned int j = 0; j < nodeList.size(); ++j) {
Node *curNode = nodeList[j];
XmlNode *openNodesListNodeNode = factionsNode->addChild("openNodesListNode");
openNodesListNodeNode->addAttribute("key",floatToStr(iterMap->first), mapTagReplacements);
// Vec2i pos;
openNodesListNodeNode->addAttribute("pos",curNode->pos.getString(), mapTagReplacements);
// Node *next;
int nextIdx = findNodeIndex(curNode->next, nodeList);
openNodesListNodeNode->addAttribute("next",intToStr(nextIdx), mapTagReplacements);
// Node *prev;
int prevIdx = findNodeIndex(curNode->prev, nodeList);
openNodesListNodeNode->addAttribute("prev",intToStr(nextIdx), mapTagReplacements);
// float heuristic;
openNodesListNodeNode->addAttribute("heuristic",floatToStr(curNode->heuristic), mapTagReplacements);
// bool exploredCell;
openNodesListNodeNode->addAttribute("exploredCell",intToStr(curNode->exploredCell), mapTagReplacements);
}
}
// std::map<float, Nodes> closedNodesList;
XmlNode *closedNodesListNode = factionsNode->addChild("closedNodesList");
for(std::map<float, Nodes>::iterator iterMap = factionState.closedNodesList.begin();
iterMap != factionState.closedNodesList.end(); ++iterMap) {
Nodes &nodeList = iterMap->second;
for(unsigned int j = 0; j < nodeList.size(); ++j) {
Node *curNode = nodeList[j];
XmlNode *closedNodesListNodeNode = factionsNode->addChild("closedNodesListNode");
closedNodesListNodeNode->addAttribute("key",floatToStr(iterMap->first), mapTagReplacements);
// Vec2i pos;
closedNodesListNodeNode->addAttribute("pos",curNode->pos.getString(), mapTagReplacements);
// Node *next;
int nextIdx = findNodeIndex(curNode->next, nodeList);
closedNodesListNodeNode->addAttribute("next",intToStr(nextIdx), mapTagReplacements);
// Node *prev;
int prevIdx = findNodeIndex(curNode->prev, nodeList);
closedNodesListNodeNode->addAttribute("prev",intToStr(nextIdx), mapTagReplacements);
// float heuristic;
closedNodesListNodeNode->addAttribute("heuristic",floatToStr(curNode->heuristic), mapTagReplacements);
// bool exploredCell;
closedNodesListNodeNode->addAttribute("exploredCell",intToStr(curNode->exploredCell), mapTagReplacements);
}
}
// XmlNode *openPosListNode = factionsNode->addChild("openPosList");
// for(std::map<Vec2i, bool>::iterator iterMap = factionState.openPosList.begin();
// iterMap != factionState.openPosList.end(); ++iterMap) {
// openPosListNode->addAttribute("key",iterMap->first.getString(), mapTagReplacements);
// openPosListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
// }
//// std::map<float, Nodes> openNodesList;
// XmlNode *openNodesListNode = factionsNode->addChild("openNodesList");
// for(std::map<float, Nodes>::iterator iterMap = factionState.openNodesList.begin();
// iterMap != factionState.openNodesList.end(); ++iterMap) {
//
// Nodes &nodeList = iterMap->second;
// for(unsigned int j = 0; j < nodeList.size(); ++j) {
// Node *curNode = nodeList[j];
// XmlNode *openNodesListNodeNode = factionsNode->addChild("openNodesListNode");
// openNodesListNodeNode->addAttribute("key",floatToStr(iterMap->first), mapTagReplacements);
//
//// Vec2i pos;
// openNodesListNodeNode->addAttribute("pos",curNode->pos.getString(), mapTagReplacements);
//// Node *next;
// int nextIdx = findNodeIndex(curNode->next, nodeList);
// openNodesListNodeNode->addAttribute("next",intToStr(nextIdx), mapTagReplacements);
//// Node *prev;
// int prevIdx = findNodeIndex(curNode->prev, nodeList);
// openNodesListNodeNode->addAttribute("prev",intToStr(nextIdx), mapTagReplacements);
//// float heuristic;
// openNodesListNodeNode->addAttribute("heuristic",floatToStr(curNode->heuristic), mapTagReplacements);
//// bool exploredCell;
// openNodesListNodeNode->addAttribute("exploredCell",intToStr(curNode->exploredCell), mapTagReplacements);
// }
// }
//
//// std::map<float, Nodes> closedNodesList;
// XmlNode *closedNodesListNode = factionsNode->addChild("closedNodesList");
// for(std::map<float, Nodes>::iterator iterMap = factionState.closedNodesList.begin();
// iterMap != factionState.closedNodesList.end(); ++iterMap) {
//
// Nodes &nodeList = iterMap->second;
// for(unsigned int j = 0; j < nodeList.size(); ++j) {
// Node *curNode = nodeList[j];
// XmlNode *closedNodesListNodeNode = factionsNode->addChild("closedNodesListNode");
// closedNodesListNodeNode->addAttribute("key",floatToStr(iterMap->first), mapTagReplacements);
//
//// Vec2i pos;
// closedNodesListNodeNode->addAttribute("pos",curNode->pos.getString(), mapTagReplacements);
//// Node *next;
// int nextIdx = findNodeIndex(curNode->next, nodeList);
// closedNodesListNodeNode->addAttribute("next",intToStr(nextIdx), mapTagReplacements);
//// Node *prev;
// int prevIdx = findNodeIndex(curNode->prev, nodeList);
// closedNodesListNodeNode->addAttribute("prev",intToStr(nextIdx), mapTagReplacements);
//// float heuristic;
// closedNodesListNodeNode->addAttribute("heuristic",floatToStr(curNode->heuristic), mapTagReplacements);
//// bool exploredCell;
// closedNodesListNodeNode->addAttribute("exploredCell",intToStr(curNode->exploredCell), mapTagReplacements);
// }
// }
// std::vector<Node> nodePool;
for(unsigned int j = 0; j < factionState.nodePool.size(); ++j) {
@ -1604,8 +1604,11 @@ void PathFinder::saveGame(XmlNode *rootNode) {
}
// int nodePoolCount;
factionsNode->addAttribute("nodePoolCount",intToStr(factionState.nodePoolCount), mapTagReplacements);
// RandomGen random;
factionsNode->addAttribute("random",intToStr(factionState.random.getLastNumber()), mapTagReplacements);
// int useMaxNodeCount;
factionsNode->addAttribute("useMaxNodeCount",intToStr(factionState.useMaxNodeCount), mapTagReplacements);
//
// std::map<int,TravelState> precachedTravelState;
// std::map<int,std::vector<Vec2i> > precachedPath;
@ -1615,4 +1618,54 @@ void PathFinder::saveGame(XmlNode *rootNode) {
}
void PathFinder::loadGame(const XmlNode *rootNode) {
const XmlNode *pathfinderNode = rootNode->getChild("PathFinder");
//attackWarnRange = unitupdaterNode->getAttribute("attackWarnRange")->getFloatValue();
// static int pathFindNodesMax;
pathFindNodesMax = pathfinderNode->getAttribute("pathFindNodesMax")->getIntValue();
// static int pathFindNodesAbsoluteMax;
pathFindNodesAbsoluteMax = pathfinderNode->getAttribute("pathFindNodesAbsoluteMax")->getIntValue();
vector<XmlNode *> factionsNodeList = pathfinderNode->getChildList("factions");
for(unsigned int i = 0; i < factionsNodeList.size(); ++i) {
XmlNode *factionsNode = factionsNodeList[i];
FactionState &factionState = factions[i];
// std::vector<Node> nodePool;
vector<XmlNode *> nodePoolListNode = factionsNode->getChildList("nodePool");
for(unsigned int j = 0; j < nodePoolListNode.size(); ++j) {
XmlNode *nodePoolNode = nodePoolListNode[j];
Node *curNode = &factionState.nodePool[j];
//closedNodesListNodeNode->addAttribute("key",iterMap->first.getString(), mapTagReplacements);
// Vec2i pos;
curNode->pos = Vec2i::strToVec2(nodePoolNode->getAttribute("pos")->getValue());
// Node *next;
curNode->next = &factionState.nodePool[nodePoolNode->getAttribute("next")->getIntValue()];
// Node *prev;
curNode->prev = &factionState.nodePool[nodePoolNode->getAttribute("prev")->getIntValue()];
// float heuristic;
curNode->heuristic = nodePoolNode->getAttribute("heuristic")->getFloatValue();
// bool exploredCell;
curNode->exploredCell = nodePoolNode->getAttribute("exploredCell")->getIntValue();
}
// int nodePoolCount;
factionState.nodePoolCount = factionsNode->getAttribute("nodePoolCount")->getIntValue();
// RandomGen random;
factionState.random.setLastNumber(factionsNode->getAttribute("random")->getIntValue());
// int useMaxNodeCount;
factionState.useMaxNodeCount = factionsNode->getAttribute("useMaxNodeCount")->getIntValue();
//
// std::map<int,TravelState> precachedTravelState;
// std::map<int,std::vector<Vec2i> > precachedPath;
}
// const Map *map;
}
}} //end namespace

View File

@ -122,6 +122,7 @@ public:
int findNodeIndex(Node *node, std::vector<Node> &nodeList);
void saveGame(XmlNode *rootNode);
void loadGame(const XmlNode *rootNode);
private:
TravelState aStar(Unit *unit, const Vec2i &finalPos, bool inBailout, int frameIndex, int maxNodeCount=-1);

View File

@ -915,6 +915,9 @@ void Game::init(bool initForPreviewOnly) {
Faction *faction= world.getFaction(i);
if(faction->getCpuControl(enableServerControlledAI,isNetworkGame,role) == true) {
aiInterfaces[i]= new AiInterface(*this, i, faction->getTeam());
if(loadGameNode != NULL) {
aiInterfaces[i]->loadGame(loadGameNode,faction);
}
char szBuf[1024]="";
sprintf(szBuf,Lang::getInstance().get("LogScreenGameLoadingCreatingAIFaction","",true).c_str(),i);
logger.add(szBuf, true);

View File

@ -209,4 +209,63 @@ void Stats::saveGame(XmlNode *rootNode) {
// bool isMasterserverMode;
}
void Stats::loadGame(const XmlNode *rootNode) {
const XmlNode *statsNode = rootNode->getChild("Stats");
// PlayerStats playerStats[GameConstants::maxPlayers];
vector<XmlNode *> statsNodePlayerList = statsNode->getChildList("Player");
for(unsigned int i = 0; i < statsNodePlayerList.size(); ++i) {
XmlNode *statsNodePlayer = statsNodePlayerList[i];
PlayerStats &stat = playerStats[i];
// ControlType control;
stat.control = static_cast<ControlType>(statsNodePlayer->getAttribute("control")->getIntValue());
// float resourceMultiplier;
stat.resourceMultiplier = statsNodePlayer->getAttribute("resourceMultiplier")->getFloatValue();
// string factionTypeName;
stat.factionTypeName = statsNodePlayer->getAttribute("factionTypeName")->getValue();
// FactionPersonalityType personalityType;
stat.personalityType = static_cast<FactionPersonalityType>(statsNodePlayer->getAttribute("personalityType")->getIntValue());
// int teamIndex;
stat.teamIndex = statsNodePlayer->getAttribute("teamIndex")->getIntValue();
// bool victory;
stat.victory = statsNodePlayer->getAttribute("victory")->getIntValue();
// int kills;
stat.kills = statsNodePlayer->getAttribute("kills")->getIntValue();
// int enemykills;
stat.enemykills = statsNodePlayer->getAttribute("enemykills")->getIntValue();
// int deaths;
stat.deaths = statsNodePlayer->getAttribute("deaths")->getIntValue();
// int unitsProduced;
stat.unitsProduced = statsNodePlayer->getAttribute("unitsProduced")->getIntValue();
// int resourcesHarvested;
stat.resourcesHarvested = statsNodePlayer->getAttribute("resourcesHarvested")->getIntValue();
// string playerName;
stat.playerName = statsNodePlayer->getAttribute("playerName")->getValue();
// Vec3f playerColor;
stat.playerColor = Vec3f::strToVec3(statsNodePlayer->getAttribute("playerColor")->getValue());
}
// string description;
//statsNode->addAttribute("description",description, mapTagReplacements);
description = statsNode->getAttribute("description")->getValue();
// int factionCount;
factionCount = statsNode->getAttribute("factionCount")->getIntValue();
// int thisFactionIndex;
thisFactionIndex = statsNode->getAttribute("thisFactionIndex")->getIntValue();
//
// float worldTimeElapsed;
worldTimeElapsed = statsNode->getAttribute("worldTimeElapsed")->getFloatValue();
// int framesPlayed;
framesPlayed = statsNode->getAttribute("framesPlayed")->getIntValue();
// int framesToCalculatePlaytime;
framesToCalculatePlaytime = statsNode->getAttribute("framesToCalculatePlaytime")->getIntValue();
// time_t timePlayed;
timePlayed = statsNode->getAttribute("timePlayed")->getIntValue();
// int maxConcurrentUnitCount;
maxConcurrentUnitCount = statsNode->getAttribute("maxConcurrentUnitCount")->getIntValue();
// int totalEndGameConcurrentUnitCount;
totalEndGameConcurrentUnitCount = statsNode->getAttribute("totalEndGameConcurrentUnitCount")->getIntValue();
// bool isMasterserverMode;
}
}}//end namespace

View File

@ -136,6 +136,7 @@ public:
string getStats() const;
void saveGame(XmlNode *rootNode);
void loadGame(const XmlNode *rootNode);
};
}}//end namespace

View File

@ -15,6 +15,8 @@
#include "util.h"
#include "conversion.h"
#include "unit_type.h"
#include "faction.h"
#include "world.h"
#include "leak_dumper.h"
using namespace Shared::Util;
@ -24,6 +26,14 @@ namespace Glest{ namespace Game{
// =====================================================
// class Command
// =====================================================
Command::Command() {
this->commandType= NULL;
this->unitRef= NULL;
unitType= NULL;
stateType = cst_None;
stateValue = -1;
unitCommandGroupId = -1;
}
Command::Command(const CommandType *ct, const Vec2i &pos){
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ct = [%p]\n",__FILE__,__FUNCTION__,__LINE__,ct);
@ -140,13 +150,13 @@ std::string Command::toString() const {
return result;
}
void Command::saveGame(XmlNode *rootNode) {
void Command::saveGame(XmlNode *rootNode, Faction *faction) {
std::map<string,string> mapTagReplacements;
XmlNode *commandNode = rootNode->addChild("Command");
// const CommandType *commandType;
if(commandType != NULL) {
commandNode->addAttribute("commandType",commandType->getName(), mapTagReplacements);
commandNode->addAttribute("commandType",intToStr(commandType->getId()), mapTagReplacements);
}
// Vec2i originalPos;
commandNode->addAttribute("originalPos",originalPos.getString(), mapTagReplacements);
@ -158,7 +168,8 @@ void Command::saveGame(XmlNode *rootNode) {
commandNode->addAttribute("facing",intToStr(facing), mapTagReplacements);
// const UnitType *unitType; //used for build
if(unitType != NULL) {
commandNode->addAttribute("unitType",unitType->getName(), mapTagReplacements);
commandNode->addAttribute("unitTypeId",intToStr(unitType->getId()), mapTagReplacements);
commandNode->addAttribute("unitTypeFactionIndex",intToStr(faction->getIndex()), mapTagReplacements);
}
// CommandStateType stateType;
commandNode->addAttribute("stateType",intToStr(stateType), mapTagReplacements);
@ -167,4 +178,42 @@ void Command::saveGame(XmlNode *rootNode) {
// int unitCommandGroupId;
commandNode->addAttribute("unitCommandGroupId",intToStr(unitCommandGroupId), mapTagReplacements);
}
Command * Command::loadGame(const XmlNode *rootNode,const UnitType *ut,World *world) {
Command *result = new Command();
const XmlNode *commandNode = rootNode;
//description = commandNode->getAttribute("description")->getValue();
// const CommandType *commandType;
if(commandNode->hasAttribute("commandType") == true) {
int cmdTypeId = commandNode->getAttribute("commandType")->getIntValue();
result->commandType = ut->findCommandTypeById(cmdTypeId);
}
// Vec2i originalPos;
result->originalPos = Vec2i::strToVec2(commandNode->getAttribute("originalPos")->getValue());
// Vec2i pos;
result->pos = Vec2i::strToVec2(commandNode->getAttribute("pos")->getValue());
// UnitReference unitRef; //target unit, used to move and attack optionally
result->unitRef.loadGame(commandNode,world);
// CardinalDir facing; // facing, for build command
result->facing = static_cast<CardinalDir>(commandNode->getAttribute("facing")->getIntValue());
// const UnitType *unitType; //used for build
if(commandNode->hasAttribute("unitTypeId") == true) {
//result->unitType = ut;
int unitTypeId = commandNode->getAttribute("unitTypeId")->getIntValue();
int unitTypeFactionIndex = commandNode->getAttribute("unitTypeFactionIndex")->getIntValue();
Faction *faction = world->getFaction(unitTypeFactionIndex);
result->unitType = world->findUnitTypeById(faction->getType(),unitTypeId);
}
// CommandStateType stateType;
result->stateType = static_cast<CommandStateType>(commandNode->getAttribute("stateType")->getIntValue());
// int stateValue;
result->stateValue = commandNode->getAttribute("stateValue")->getIntValue();
// int unitCommandGroupId;
result->unitCommandGroupId = commandNode->getAttribute("unitCommandGroupId")->getIntValue();
return result;
}
}}//end namespace

View File

@ -50,6 +50,7 @@ private:
int unitCommandGroupId;
Command();
public:
//constructor
Command(const CommandType *ct, const Vec2i &pos=Vec2i(0));
@ -87,7 +88,8 @@ public:
std::string toString() const;
void saveGame(XmlNode *rootNode);
void saveGame(XmlNode *rootNode, Faction *faction);
static Command * loadGame(const XmlNode *rootNode,const UnitType *ut,World *world);
};
}}//end namespace

View File

@ -505,7 +505,7 @@ void Faction::init(
}
if(loadWorldNode != NULL) {
loadGame(loadWorldNode, factionIndex,game->getGameSettings(),game->getWorld());
loadGame(loadWorldNode, this->index,game->getGameSettings(),game->getWorld());
}
if( game->getGameSettings()->getPathFinderType() == pfBasic &&
@ -1863,18 +1863,20 @@ void Faction::saveGame(XmlNode *rootNode) {
}
void Faction::loadGame(const XmlNode *rootNode, int index,GameSettings *settings,World *world) {
void Faction::loadGame(const XmlNode *rootNode, int factionIndex,GameSettings *settings,World *world) {
XmlNode *factionNode = NULL;
vector<XmlNode *> factionNodeList = rootNode->getChildList("Faction");
for(unsigned int i = 0; i < factionNodeList.size(); ++i) {
XmlNode *node = factionNodeList[i];
if(node->getAttribute("index")->getIntValue() == index) {
if(node->getAttribute("index")->getIntValue() == factionIndex) {
factionNode = node;
break;
}
}
if(factionNode != NULL) {
//printf("Loading faction index = %d [%s] [%s]\n",factionIndex,factionType->getName().c_str(),factionNode->getAttribute("factiontype")->getValue().c_str());
vector<XmlNode *> unitNodeList = factionNode->getChildList("Unit");
for(unsigned int i = 0; i < unitNodeList.size(); ++i) {
XmlNode *unitNode = unitNodeList[i];
@ -1904,6 +1906,8 @@ void Faction::loadGame(const XmlNode *rootNode, int index,GameSettings *settings
Resource &resource = store[i];
resource.loadGame(storeNode,i,techTree);
}
upgradeManager.loadGame(factionNode,this);
}
}}//end namespace

View File

@ -172,6 +172,7 @@ public:
int getTeam() const {return teamIndex;}
void setTeam(int team) {teamIndex=team;}
TechTree * getTechTree() const { return techTree; }
const SwitchTeamVote * getFirstSwitchTeamVote() const;
SwitchTeamVote * getSwitchTeamVote(int factionIndex);
void setSwitchTeamVote(SwitchTeamVote &vote);
@ -262,7 +263,7 @@ public:
std::string toString() const;
void saveGame(XmlNode *rootNode);
void loadGame(const XmlNode *rootNode, int index,GameSettings *settings,World *world);
void loadGame(const XmlNode *rootNode, int factionIndex,GameSettings *settings,World *world);
private:
void resetResourceAmount(const ResourceType *rt);

View File

@ -213,4 +213,39 @@ void Object::saveGame(XmlNode *rootNode) {
// bool visible;
objectNode->addAttribute("visible",intToStr(visible), mapTagReplacements);
}
void Object::loadGame(const XmlNode *rootNode,const TechTree *techTree) {
const XmlNode *objectNode = rootNode->getChild("Object");
//description = objectNode->getAttribute("description")->getValue();
// ObjectType *objectType;
// if(objectType != NULL) {
// objectNode->addAttribute("objectType",intToStr(objectType->getClass()), mapTagReplacements);
// }
// // vector<UnitParticleSystem*> unitParticleSystems;
// for(unsigned int i = 0; i < unitParticleSystems.size(); ++i) {
// UnitParticleSystem *ptr= unitParticleSystems[i];
// if(ptr != NULL) {
// ptr->saveGame(objectNode);
// }
// }
// Resource *resource;
if(resource != NULL) {
resource->loadGame(objectNode,0,techTree);
}
// Vec3f pos;
pos = Vec3f::strToVec3(objectNode->getAttribute("pos")->getValue());
// float rotation;
rotation = objectNode->getAttribute("rotation")->getFloatValue();
// int variation;
variation = objectNode->getAttribute("variation")->getIntValue();
// int lastRenderFrame;
lastRenderFrame = objectNode->getAttribute("lastRenderFrame")->getIntValue();
// Vec2i mapPos;
mapPos = Vec2i::strToVec2(objectNode->getAttribute("mapPos")->getValue());
// bool visible;
visible = objectNode->getAttribute("visible")->getIntValue();
}
}}//end namespace

View File

@ -23,6 +23,7 @@ namespace Glest{ namespace Game{
class ObjectType;
class ResourceType;
class Resource;
class TechTree;
using Shared::Graphics::Model;
using Shared::Graphics::Vec2i;
@ -89,6 +90,7 @@ public:
virtual string getUniquePickName() const;
void saveGame(XmlNode *rootNode);
void loadGame(const XmlNode *rootNode,const TechTree *techTree);
};
}}//end namespace

View File

@ -116,7 +116,7 @@ void Resource::saveGame(XmlNode *rootNode) const {
resourceNode->addAttribute("balance",intToStr(balance), mapTagReplacements);
}
void Resource::loadGame(const XmlNode *rootNode, int index,TechTree *techTree) {
void Resource::loadGame(const XmlNode *rootNode, int index,const TechTree *techTree) {
vector<XmlNode *> resourceNodeList = rootNode->getChildList("Resource");
if(index < resourceNodeList.size()) {

View File

@ -59,7 +59,7 @@ public:
bool decAmount(int i);
void saveGame(XmlNode *rootNode) const;
void loadGame(const XmlNode *rootNode, int index,TechTree *techTree);
void loadGame(const XmlNode *rootNode, int index,const TechTree *techTree);
};
}}// end namespace

View File

@ -3514,7 +3514,8 @@ void Unit::saveGame(XmlNode *rootNode) {
}
// const SkillType *currSkill;
if(currSkill != NULL) {
unitNode->addAttribute("currSkill",currSkill->getName(), mapTagReplacements);
unitNode->addAttribute("currSkillName",currSkill->getName(), mapTagReplacements);
unitNode->addAttribute("currSkillClass",intToStr(currSkill->getClass()), mapTagReplacements);
}
// int lastModelIndexForCurrSkillType;
unitNode->addAttribute("lastModelIndexForCurrSkillType",intToStr(lastModelIndexForCurrSkillType), mapTagReplacements);
@ -3542,7 +3543,7 @@ void Unit::saveGame(XmlNode *rootNode) {
//
// Commands commands;
for(Commands::iterator it = commands.begin(); it != commands.end(); ++it) {
(*it)->saveGame(unitNode);
(*it)->saveGame(unitNode,faction);
}
// Observers observers;
//for(Observers::iterator it = observers.begin(); it != observers.end(); ++it) {
@ -3738,6 +3739,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
// if(level != NULL) {
// level->saveGame(unitNode);
// }
result->level = Level::loadGame(unitNode,ut);
// Vec2i pos;
// unitNode->addAttribute("pos",pos.getString(), mapTagReplacements);
// Vec2i lastPos;
@ -3769,10 +3771,20 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
// if(loadType != NULL) {
// unitNode->addAttribute("loadType",loadType->getName(), mapTagReplacements);
// }
if(unitNode->hasAttribute("loadType") == true) {
string loadTypeName = unitNode->getAttribute("loadType")->getValue();
result->loadType = world->getTechTree()->getResourceType(loadTypeName);
}
// const SkillType *currSkill;
// if(currSkill != NULL) {
// unitNode->addAttribute("currSkill",currSkill->getName(), mapTagReplacements);
// }
if(unitNode->hasAttribute("currSkillName") == true) {
string skillTypeName = unitNode->getAttribute("currSkillName")->getValue();
SkillClass skillClass = static_cast<SkillClass>(unitNode->getAttribute("currSkillClass")->getIntValue());
result->currSkill = ut->getSkillType(skillTypeName,skillClass);
}
// int lastModelIndexForCurrSkillType;
result->lastModelIndexForCurrSkillType = unitNode->getAttribute("lastModelIndexForCurrSkillType")->getIntValue();
// int animationRandomCycleCount;
@ -3790,7 +3802,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
// fire->saveGame(unitNode);
// }
// TotalUpgrade totalUpgrade;
// totalUpgrade.saveGame(unitNode);
result->totalUpgrade.loadGame(unitNode);
// Map *map;
//
// UnitPathInterface *unitPath;
@ -3801,6 +3813,16 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
// for(Commands::iterator it = commands.begin(); it != commands.end(); ++it) {
// (*it)->saveGame(unitNode);
// }
vector<XmlNode *> commandNodeList = unitNode->getChildList("Command");
for(unsigned int i = 0; i < commandNodeList.size(); ++i) {
XmlNode *node = commandNodeList[i];
Command *command = Command::loadGame(node,ut,world);
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(result->mutexCommands,mutexOwnerId);
result->commands.push_back(command);
safeMutex.ReleaseLock();
}
// Observers observers;
//for(Observers::iterator it = observers.begin(); it != observers.end(); ++it) {
// (*it)->saveGame(unitNode);

View File

@ -17,6 +17,8 @@
#include "util.h"
#include "upgrade_type.h"
#include "conversion.h"
#include "faction.h"
#include "faction_type.h"
#include "leak_dumper.h"
using namespace std;
@ -27,6 +29,11 @@ namespace Glest{ namespace Game{
// =====================================================
// class Upgrade
// =====================================================
Upgrade::Upgrade() {
state= usUpgrading;
this->factionIndex= -1;
this->type= NULL;
}
Upgrade::Upgrade(const UpgradeType *type, int factionIndex) {
state= usUpgrading;
@ -74,6 +81,21 @@ void Upgrade::saveGame(XmlNode *rootNode) {
upgradeNode->addAttribute("type",type->getName(), mapTagReplacements);
}
Upgrade * Upgrade::loadGame(const XmlNode *rootNode,Faction *faction) {
Upgrade *newUpgrade = new Upgrade();
const XmlNode *upgradeNode = rootNode;
//description = upgrademanagerNode->getAttribute("description")->getValue();
newUpgrade->state = static_cast<UpgradeState>(upgradeNode->getAttribute("state")->getIntValue());
newUpgrade->factionIndex = upgradeNode->getAttribute("factionIndex")->getIntValue();
string unitTypeName = upgradeNode->getAttribute("type")->getValue();
newUpgrade->type = faction->getType()->getUpgradeType(unitTypeName);
return newUpgrade;
}
// =====================================================
// class UpgradeManager
// =====================================================
@ -244,8 +266,20 @@ void UpgradeManager::saveGame(XmlNode *rootNode) {
// Upgrades upgrades;
// UgradesLookup upgradesLookup;
}
void UpgradeManager::loadGame(const XmlNode *rootNode,Faction *faction) {
const XmlNode *upgrademanagerNode = rootNode->getChild("UpgradeManager");
//description = upgrademanagerNode->getAttribute("description")->getValue();
vector<XmlNode *> upgradeNodeList = upgrademanagerNode->getChildList("Upgrade");
for(unsigned int i = 0; i < upgradeNodeList.size(); ++i) {
XmlNode *node = upgradeNodeList[i];
Upgrade *newUpgrade = Upgrade::loadGame(node,faction);
upgrades.push_back(newUpgrade);
upgradesLookup[newUpgrade->getType()] = upgrades.size()-1;
}
}
}}// end namespace

View File

@ -26,6 +26,7 @@ namespace Glest { namespace Game {
class Unit;
class UpgradeType;
class Faction;
enum UpgradeState {
usUpgrading,
@ -51,6 +52,7 @@ private:
friend class UpgradeManager;
Upgrade();
public:
Upgrade(const UpgradeType *upgradeType, int factionIndex);
@ -66,6 +68,7 @@ private:
std::string toString() const;
void saveGame(XmlNode *rootNode);
static Upgrade * loadGame(const XmlNode *rootNode,Faction *faction);
};
@ -95,6 +98,7 @@ public:
std::string toString() const;
void saveGame(XmlNode *rootNode);
void loadGame(const XmlNode *rootNode,Faction *faction);
};
}}//end namespace

View File

@ -35,12 +35,12 @@ DisplayableType::DisplayableType(){
image= NULL;
}
void DisplayableType::saveGame(XmlNode *rootNode) const {
std::map<string,string> mapTagReplacements;
XmlNode *displayableTypeNode = rootNode->addChild("DisplayableType");
displayableTypeNode->addAttribute("name",name, mapTagReplacements);
}
//void DisplayableType::saveGame(XmlNode *rootNode) const {
// std::map<string,string> mapTagReplacements;
// XmlNode *displayableTypeNode = rootNode->addChild("DisplayableType");
//
// displayableTypeNode->addAttribute("name",name, mapTagReplacements);
//}
// =====================================================
// class RequirableType
@ -78,27 +78,27 @@ string RequirableType::getReqDesc() const{
}
}
void RequirableType::saveGame(XmlNode *rootNode) const {
DisplayableType::saveGame(rootNode);
std::map<string,string> mapTagReplacements;
XmlNode *requirableTypeNode = rootNode->addChild("RequirableType");
// UnitReqs unitReqs; //needed units
for(unsigned int i = 0; i < unitReqs.size(); ++i) {
const UnitType *ut = unitReqs[i];
XmlNode *unitReqsNode = requirableTypeNode->addChild("unitReqs");
unitReqsNode->addAttribute("name",ut->getName(), mapTagReplacements);
}
// UpgradeReqs upgradeReqs; //needed upgrades
for(unsigned int i = 0; i < upgradeReqs.size(); ++i) {
const UpgradeType* ut = upgradeReqs[i];
ut->saveGame(requirableTypeNode);
}
}
//void RequirableType::saveGame(XmlNode *rootNode) const {
// DisplayableType::saveGame(rootNode);
//
// std::map<string,string> mapTagReplacements;
// XmlNode *requirableTypeNode = rootNode->addChild("RequirableType");
//
//// UnitReqs unitReqs; //needed units
// for(unsigned int i = 0; i < unitReqs.size(); ++i) {
// const UnitType *ut = unitReqs[i];
//
// XmlNode *unitReqsNode = requirableTypeNode->addChild("unitReqs");
// unitReqsNode->addAttribute("name",ut->getName(), mapTagReplacements);
// }
//// UpgradeReqs upgradeReqs; //needed upgrades
// for(unsigned int i = 0; i < upgradeReqs.size(); ++i) {
// const UpgradeType* ut = upgradeReqs[i];
//
// ut->saveGame(requirableTypeNode);
// }
//
//}
// =====================================================
// class ProducibleType
@ -144,20 +144,26 @@ string ProducibleType::getReqDesc() const{
return str;
}
void ProducibleType::saveGame(XmlNode *rootNode) const {
RequirableType::saveGame(rootNode);
//void ProducibleType::saveGame(XmlNode *rootNode) const {
// RequirableType::saveGame(rootNode);
//
// std::map<string,string> mapTagReplacements;
// XmlNode *producibleTypeNode = rootNode->addChild("ProducibleType");
//
//// Costs costs;
// for(unsigned int i = 0; i < costs.size(); ++i) {
// const Resource &res = costs[i];
// res.saveGame(producibleTypeNode);
// }
//// Texture2D *cancelImage;
//// int productionTime;
// producibleTypeNode->addAttribute("productionTime",intToStr(productionTime), mapTagReplacements);
//}
std::map<string,string> mapTagReplacements;
XmlNode *producibleTypeNode = rootNode->addChild("ProducibleType");
// Costs costs;
for(unsigned int i = 0; i < costs.size(); ++i) {
const Resource &res = costs[i];
res.saveGame(producibleTypeNode);
}
// Texture2D *cancelImage;
// int productionTime;
producibleTypeNode->addAttribute("productionTime",intToStr(productionTime), mapTagReplacements);
}
//void ProducibleType::loadGame(const XmlNode *rootNode) {
// const XmlNode *producibleTypeNode = rootNode->getChild("ProducibleType");
//
// //int newUnitId = producibleTypeNode->getAttribute("id")->getIntValue();
//}
}}//end namespace

View File

@ -52,7 +52,7 @@ public:
string getName() const {return name;}
const Texture2D *getImage() const {return image;}
virtual void saveGame(XmlNode *rootNode) const;
//virtual void saveGame(XmlNode *rootNode) const;
};
@ -81,7 +81,7 @@ public:
//other
virtual string getReqDesc() const;
virtual void saveGame(XmlNode *rootNode) const;
//virtual void saveGame(XmlNode *rootNode) const;
};
@ -116,7 +116,8 @@ public:
virtual string getReqDesc() const;
virtual void saveGame(XmlNode *rootNode) const;
// virtual void saveGame(XmlNode *rootNode) const;
// void loadGame(const XmlNode *rootNode);
};
}}//end namespace

View File

@ -703,12 +703,17 @@ const UnitType *FactionType::getUnitType(const string &name) const{
}
}
printf("In [%s::%s Line: %d] scanning [%s] size = %lu\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),unitTypes.size());
for(int i=0; i<unitTypes.size();i++){
printf("In [%s::%s Line: %d] scanning [%s] idx = %d [%s]\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),i,unitTypes[i].getName().c_str());
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning [%s] size = %d\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),unitTypes.size());
for(int i=0; i<unitTypes.size();i++){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning [%s] idx = %d [%s]\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),i,unitTypes[i].getName().c_str());
}
throw runtime_error("Unit not found: [" + name + "]");
throw runtime_error("Unit type not found: [" + name + "] in faction type [" + this->name + "]");
}
const UpgradeType *FactionType::getUpgradeType(const string &name) const{
@ -718,12 +723,17 @@ const UpgradeType *FactionType::getUpgradeType(const string &name) const{
}
}
printf("In [%s::%s Line: %d] scanning [%s] size = %lu\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),unitTypes.size());
for(int i=0; i<upgradeTypes.size();i++){
printf("In [%s::%s Line: %d] scanning [%s] idx = %d [%s]\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),i,upgradeTypes[i].getName().c_str());
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning [%s] size = %d\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),unitTypes.size());
for(int i=0; i<upgradeTypes.size();i++){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning [%s] idx = %d [%s]\n",__FILE__,__FUNCTION__,__LINE__,name.c_str(),i,upgradeTypes[i].getName().c_str());
}
throw runtime_error("Upgrade not found: "+name);
throw runtime_error("Upgrade type not found: [" + name + "] in faction type [" + this->name + "]");
}
int FactionType::getStartingResourceAmount(const ResourceType *resourceType) const{
@ -846,9 +856,9 @@ void FactionType::saveGame(XmlNode *rootNode) {
}
}
// std::vector<const UpgradeType*> vctAIBehaviorUpgrades;
for(unsigned int i = 0; i < vctAIBehaviorUpgrades.size(); ++i) {
vctAIBehaviorUpgrades[i]->saveGame(factionTypeNode);
}
//for(unsigned int i = 0; i < vctAIBehaviorUpgrades.size(); ++i) {
// vctAIBehaviorUpgrades[i]->saveGame(factionTypeNode);
//}
}
}}//end namespace

View File

@ -200,11 +200,12 @@ void ResourceType::deletePixels() {
}
void ResourceType::saveGame(XmlNode *rootNode) {
DisplayableType::saveGame(rootNode);
//DisplayableType::saveGame(rootNode);
std::map<string,string> mapTagReplacements;
XmlNode *resourceTypeNode = rootNode->addChild("ResourceType");
resourceTypeNode->addAttribute("name",this->getName(), mapTagReplacements);
// ResourceClass resourceClass;
resourceTypeNode->addAttribute("resourceClass",intToStr(resourceClass), mapTagReplacements);
// int tilesetObject; //used only if class==rcTileset

View File

@ -336,7 +336,7 @@ void SkillType::loadAttackBoost(const XmlNode *attackBoostsNode, const XmlNode *
throw runtime_error(szBuf);
}
attackBoost.boostUpgrade.load(attackBoostNode);
attackBoost.boostUpgrade.load(attackBoostNode,attackBoost.name);
if(attackBoostNode->hasChild("particles") == true) {
const XmlNode *particleNode = attackBoostNode->getChild("particles");
bool particleEnabled = particleNode->getAttribute("value")->getBoolValue();

View File

@ -49,6 +49,18 @@ void Level::saveGame(XmlNode *rootNode) const {
levelNode->addAttribute("name",name, mapTagReplacements);
levelNode->addAttribute("kills",intToStr(kills), mapTagReplacements);
}
const Level * Level::loadGame(const XmlNode *rootNode,const UnitType *ut) {
const Level *result = NULL;
if(rootNode->hasChild("Level") == true) {
const XmlNode *levelNode = rootNode->getChild("Level");
result = ut->getLevel(levelNode->getAttribute("name")->getValue());
}
return result;
}
// =====================================================
// class UnitType
// =====================================================
@ -572,6 +584,19 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const
// ==================== get ====================
const Level *UnitType::getLevel(string name) const {
const Level *result = NULL;
for(unsigned int i = 0; i < levels.size(); ++i) {
const Level &level = levels[i];
if(level.getName() == name) {
result = &level;
break;
}
}
return result;
}
const CommandType *UnitType::getFirstCtOfClass(CommandClass commandClass) const{
if(firstCommandTypeOfClass[commandClass] == NULL) {
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] commandClass = %d\n",__FILE__,__FUNCTION__,__LINE__,commandClass);

View File

@ -55,6 +55,7 @@ public:
int getKills() const {return kills;}
void saveGame(XmlNode *rootNode) const ;
static const Level * loadGame(const XmlNode *rootNode, const UnitType *ut);
};
// ===============================
@ -160,6 +161,7 @@ public:
const SkillType *getSkillType(int i) const {return skillTypes[i];}
const CommandType *getCommandType(int i) const;
const Level *getLevel(int i) const {return &levels[i];}
const Level *getLevel(string name) const;
int getSkillTypeCount() const {return skillTypes.size();}
int getCommandTypeCount() const {return commandTypes.size();}
int getLevelCount() const {return levels.size();}

View File

@ -24,6 +24,7 @@
#include "resource.h"
#include "renderer.h"
#include "game_util.h"
#include "faction.h"
#include "leak_dumper.h"
using namespace Shared::Util;
@ -40,8 +41,8 @@ namespace Glest{ namespace Game{
const string VALUE_PERCENT_MULTIPLIER_KEY_NAME = "value-percent-multiplier";
const string VALUE_REGEN_KEY_NAME = "regeneration";
void UpgradeTypeBase::load(const XmlNode *upgradeNode) {
void UpgradeTypeBase::load(const XmlNode *upgradeNode, string upgradename) {
this->upgradename = upgradename;
//values
maxHpIsMultiplier = false;
maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue();
@ -278,97 +279,199 @@ void UpgradeTypeBase::saveGame(XmlNode *rootNode) const {
std::map<string,string> mapTagReplacements;
XmlNode *upgradeTypeBaseNode = rootNode->addChild("UpgradeTypeBase");
// int maxHp;
upgradeTypeBaseNode->addAttribute("maxHp",intToStr(maxHp), mapTagReplacements);
// bool maxHpIsMultiplier;
upgradeTypeBaseNode->addAttribute("maxHpIsMultiplier",intToStr(maxHpIsMultiplier), mapTagReplacements);
// int maxHpRegeneration;
upgradeTypeBaseNode->addAttribute("maxHpRegeneration",intToStr(maxHpRegeneration), mapTagReplacements);
// //bool maxHpRegenerationIsMultiplier;
upgradeTypeBaseNode->addAttribute("upgradename",upgradename, mapTagReplacements);
//// int maxHp;
// upgradeTypeBaseNode->addAttribute("maxHp",intToStr(maxHp), mapTagReplacements);
//// bool maxHpIsMultiplier;
// upgradeTypeBaseNode->addAttribute("maxHpIsMultiplier",intToStr(maxHpIsMultiplier), mapTagReplacements);
//// int maxHpRegeneration;
// upgradeTypeBaseNode->addAttribute("maxHpRegeneration",intToStr(maxHpRegeneration), mapTagReplacements);
//// //bool maxHpRegenerationIsMultiplier;
////
//// int sight;
// upgradeTypeBaseNode->addAttribute("sight",intToStr(sight), mapTagReplacements);
//// bool sightIsMultiplier;
// upgradeTypeBaseNode->addAttribute("sightIsMultiplier",intToStr(sightIsMultiplier), mapTagReplacements);
//// int maxEp;
// upgradeTypeBaseNode->addAttribute("maxEp",intToStr(maxEp), mapTagReplacements);
//// bool maxEpIsMultiplier;
// upgradeTypeBaseNode->addAttribute("maxEpIsMultiplier",intToStr(maxEpIsMultiplier), mapTagReplacements);
//// int maxEpRegeneration;
// upgradeTypeBaseNode->addAttribute("maxEpRegeneration",intToStr(maxEpRegeneration), mapTagReplacements);
//// //bool maxEpRegenerationIsMultiplier;
//// int armor;
// upgradeTypeBaseNode->addAttribute("armor",intToStr(armor), mapTagReplacements);
//// bool armorIsMultiplier;
// upgradeTypeBaseNode->addAttribute("armorIsMultiplier",intToStr(armorIsMultiplier), mapTagReplacements);
//// int attackStrength;
// upgradeTypeBaseNode->addAttribute("attackStrength",intToStr(attackStrength), mapTagReplacements);
//// bool attackStrengthIsMultiplier;
// upgradeTypeBaseNode->addAttribute("attackStrengthIsMultiplier",intToStr(attackStrengthIsMultiplier), mapTagReplacements);
//// std::map<string,int> attackStrengthMultiplierValueList;
// for(std::map<string,int>::const_iterator iterMap = attackStrengthMultiplierValueList.begin();
// iterMap != attackStrengthMultiplierValueList.end(); ++iterMap) {
// XmlNode *attackStrengthMultiplierValueListNode = upgradeTypeBaseNode->addChild("attackStrengthMultiplierValueList");
//
// int sight;
upgradeTypeBaseNode->addAttribute("sight",intToStr(sight), mapTagReplacements);
// bool sightIsMultiplier;
upgradeTypeBaseNode->addAttribute("sightIsMultiplier",intToStr(sightIsMultiplier), mapTagReplacements);
// int maxEp;
upgradeTypeBaseNode->addAttribute("maxEp",intToStr(maxEp), mapTagReplacements);
// bool maxEpIsMultiplier;
upgradeTypeBaseNode->addAttribute("maxEpIsMultiplier",intToStr(maxEpIsMultiplier), mapTagReplacements);
// int maxEpRegeneration;
upgradeTypeBaseNode->addAttribute("maxEpRegeneration",intToStr(maxEpRegeneration), mapTagReplacements);
// //bool maxEpRegenerationIsMultiplier;
// int armor;
upgradeTypeBaseNode->addAttribute("armor",intToStr(armor), mapTagReplacements);
// bool armorIsMultiplier;
upgradeTypeBaseNode->addAttribute("armorIsMultiplier",intToStr(armorIsMultiplier), mapTagReplacements);
// int attackStrength;
upgradeTypeBaseNode->addAttribute("attackStrength",intToStr(attackStrength), mapTagReplacements);
// bool attackStrengthIsMultiplier;
upgradeTypeBaseNode->addAttribute("attackStrengthIsMultiplier",intToStr(attackStrengthIsMultiplier), mapTagReplacements);
// std::map<string,int> attackStrengthMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = attackStrengthMultiplierValueList.begin();
iterMap != attackStrengthMultiplierValueList.end(); ++iterMap) {
XmlNode *attackStrengthMultiplierValueListNode = upgradeTypeBaseNode->addChild("attackStrengthMultiplierValueList");
// attackStrengthMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
// attackStrengthMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
// }
//// int attackRange;
// upgradeTypeBaseNode->addAttribute("attackRange",intToStr(attackRange), mapTagReplacements);
//// bool attackRangeIsMultiplier;
// upgradeTypeBaseNode->addAttribute("attackRangeIsMultiplier",intToStr(attackRangeIsMultiplier), mapTagReplacements);
//// std::map<string,int> attackRangeMultiplierValueList;
// for(std::map<string,int>::const_iterator iterMap = attackRangeMultiplierValueList.begin();
// iterMap != attackRangeMultiplierValueList.end(); ++iterMap) {
// XmlNode *attackRangeMultiplierValueListNode = upgradeTypeBaseNode->addChild("attackRangeMultiplierValueList");
//
// attackRangeMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
// attackRangeMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
// }
//
//// int moveSpeed;
// upgradeTypeBaseNode->addAttribute("moveSpeed",intToStr(moveSpeed), mapTagReplacements);
//// bool moveSpeedIsMultiplier;
// upgradeTypeBaseNode->addAttribute("moveSpeedIsMultiplier",intToStr(moveSpeedIsMultiplier), mapTagReplacements);
//// std::map<string,int> moveSpeedIsMultiplierValueList;
// for(std::map<string,int>::const_iterator iterMap = moveSpeedIsMultiplierValueList.begin();
// iterMap != moveSpeedIsMultiplierValueList.end(); ++iterMap) {
// XmlNode *moveSpeedIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("moveSpeedIsMultiplierValueList");
//
// moveSpeedIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
// moveSpeedIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
// }
//
//// int prodSpeed;
// upgradeTypeBaseNode->addAttribute("prodSpeed",intToStr(prodSpeed), mapTagReplacements);
//// bool prodSpeedIsMultiplier;
// upgradeTypeBaseNode->addAttribute("prodSpeedIsMultiplier",intToStr(prodSpeedIsMultiplier), mapTagReplacements);
//// std::map<string,int> prodSpeedProduceIsMultiplierValueList;
// for(std::map<string,int>::const_iterator iterMap = prodSpeedProduceIsMultiplierValueList.begin();
// iterMap != prodSpeedProduceIsMultiplierValueList.end(); ++iterMap) {
// XmlNode *prodSpeedProduceIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("prodSpeedProduceIsMultiplierValueList");
//
// prodSpeedProduceIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
// prodSpeedProduceIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
// }
//
//// std::map<string,int> prodSpeedUpgradeIsMultiplierValueList;
// for(std::map<string,int>::const_iterator iterMap = prodSpeedUpgradeIsMultiplierValueList.begin();
// iterMap != prodSpeedUpgradeIsMultiplierValueList.end(); ++iterMap) {
// XmlNode *prodSpeedUpgradeIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("prodSpeedUpgradeIsMultiplierValueList");
//
// prodSpeedUpgradeIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
// prodSpeedUpgradeIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
// }
//
//// std::map<string,int> prodSpeedMorphIsMultiplierValueList;
// for(std::map<string,int>::const_iterator iterMap = prodSpeedMorphIsMultiplierValueList.begin();
// iterMap != prodSpeedMorphIsMultiplierValueList.end(); ++iterMap) {
// XmlNode *prodSpeedMorphIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("prodSpeedMorphIsMultiplierValueList");
//
// prodSpeedMorphIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
// prodSpeedMorphIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
// }
}
attackStrengthMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
attackStrengthMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
// int attackRange;
upgradeTypeBaseNode->addAttribute("attackRange",intToStr(attackRange), mapTagReplacements);
// bool attackRangeIsMultiplier;
upgradeTypeBaseNode->addAttribute("attackRangeIsMultiplier",intToStr(attackRangeIsMultiplier), mapTagReplacements);
// std::map<string,int> attackRangeMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = attackRangeMultiplierValueList.begin();
iterMap != attackRangeMultiplierValueList.end(); ++iterMap) {
XmlNode *attackRangeMultiplierValueListNode = upgradeTypeBaseNode->addChild("attackRangeMultiplierValueList");
const UpgradeType * UpgradeTypeBase::loadGame(const XmlNode *rootNode, Faction *faction) {
const XmlNode *upgradeTypeBaseNode = rootNode->getChild("UpgradeTypeBase");
attackRangeMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
attackRangeMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
//description = upgradeTypeBaseNode->getAttribute("description")->getValue();
// int moveSpeed;
upgradeTypeBaseNode->addAttribute("moveSpeed",intToStr(moveSpeed), mapTagReplacements);
// bool moveSpeedIsMultiplier;
upgradeTypeBaseNode->addAttribute("moveSpeedIsMultiplier",intToStr(moveSpeedIsMultiplier), mapTagReplacements);
// std::map<string,int> moveSpeedIsMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = moveSpeedIsMultiplierValueList.begin();
iterMap != moveSpeedIsMultiplierValueList.end(); ++iterMap) {
XmlNode *moveSpeedIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("moveSpeedIsMultiplierValueList");
moveSpeedIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
moveSpeedIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
// int prodSpeed;
upgradeTypeBaseNode->addAttribute("prodSpeed",intToStr(prodSpeed), mapTagReplacements);
// bool prodSpeedIsMultiplier;
upgradeTypeBaseNode->addAttribute("prodSpeedIsMultiplier",intToStr(prodSpeedIsMultiplier), mapTagReplacements);
// std::map<string,int> prodSpeedProduceIsMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = prodSpeedProduceIsMultiplierValueList.begin();
iterMap != prodSpeedProduceIsMultiplierValueList.end(); ++iterMap) {
XmlNode *prodSpeedProduceIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("prodSpeedProduceIsMultiplierValueList");
prodSpeedProduceIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
prodSpeedProduceIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
// std::map<string,int> prodSpeedUpgradeIsMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = prodSpeedUpgradeIsMultiplierValueList.begin();
iterMap != prodSpeedUpgradeIsMultiplierValueList.end(); ++iterMap) {
XmlNode *prodSpeedUpgradeIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("prodSpeedUpgradeIsMultiplierValueList");
prodSpeedUpgradeIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
prodSpeedUpgradeIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
// std::map<string,int> prodSpeedMorphIsMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = prodSpeedMorphIsMultiplierValueList.begin();
iterMap != prodSpeedMorphIsMultiplierValueList.end(); ++iterMap) {
XmlNode *prodSpeedMorphIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("prodSpeedMorphIsMultiplierValueList");
prodSpeedMorphIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
prodSpeedMorphIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
string upgradename = upgradeTypeBaseNode->getAttribute("upgradename")->getValue();
return faction->getType()->getUpgradeType(upgradename);
// int maxHp;
// maxHp = upgradeTypeBaseNode->getAttribute("maxHp")->getIntValue();
// // bool maxHpIsMultiplier;
// maxHpIsMultiplier = upgradeTypeBaseNode->getAttribute("maxHpIsMultiplier")->getIntValue();
// // int maxHpRegeneration;
// maxHpRegeneration = upgradeTypeBaseNode->getAttribute("maxHpRegeneration")->getIntValue();
// // //bool maxHpRegenerationIsMultiplier;
// //
// // int sight;
// sight = upgradeTypeBaseNode->getAttribute("sight")->getIntValue();
// // bool sightIsMultiplier;
// sightIsMultiplier = upgradeTypeBaseNode->getAttribute("sightIsMultiplier")->getIntValue();
// // int maxEp;
// maxEp = upgradeTypeBaseNode->getAttribute("maxEp")->getIntValue();
// // bool maxEpIsMultiplier;
// maxEpIsMultiplier = upgradeTypeBaseNode->getAttribute("maxEpIsMultiplier")->getIntValue();
// // int maxEpRegeneration;
// maxEpRegeneration = upgradeTypeBaseNode->getAttribute("maxEpRegeneration")->getIntValue();
// // //bool maxEpRegenerationIsMultiplier;
// // int armor;
// armor = upgradeTypeBaseNode->getAttribute("armor")->getIntValue();
// // bool armorIsMultiplier;
// armorIsMultiplier = upgradeTypeBaseNode->getAttribute("armorIsMultiplier")->getIntValue();
// // int attackStrength;
// attackStrength = upgradeTypeBaseNode->getAttribute("attackStrength")->getIntValue();
// // bool attackStrengthIsMultiplier;
// attackStrengthIsMultiplier = upgradeTypeBaseNode->getAttribute("attackStrengthIsMultiplier")->getIntValue();
// // std::map<string,int> attackStrengthMultiplierValueList;
// vector<XmlNode *> attackStrengthMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("attackStrengthMultiplierValueList");
// for(unsigned int i = 0; i < attackStrengthMultiplierValueNodeList.size(); ++i) {
// XmlNode *node = attackStrengthMultiplierValueNodeList[i];
//
// attackStrengthMultiplierValueList[node->getAttribute("key")->getValue()] =
// node->getAttribute("value")->getIntValue();
// }
// // int attackRange;
// attackRange = upgradeTypeBaseNode->getAttribute("attackRange")->getIntValue();
// // bool attackRangeIsMultiplier;
// attackRangeIsMultiplier = upgradeTypeBaseNode->getAttribute("attackRangeIsMultiplier")->getIntValue();
// // std::map<string,int> attackRangeMultiplierValueList;
// vector<XmlNode *> attackRangeMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("attackRangeMultiplierValueList");
// for(unsigned int i = 0; i < attackRangeMultiplierValueNodeList.size(); ++i) {
// XmlNode *node = attackRangeMultiplierValueNodeList[i];
//
// attackRangeMultiplierValueList[node->getAttribute("key")->getValue()] =
// node->getAttribute("value")->getIntValue();
// }
//
// // int moveSpeed;
// moveSpeed = upgradeTypeBaseNode->getAttribute("moveSpeed")->getIntValue();
// // bool moveSpeedIsMultiplier;
// moveSpeedIsMultiplier = upgradeTypeBaseNode->getAttribute("moveSpeedIsMultiplier")->getIntValue();
// // std::map<string,int> moveSpeedIsMultiplierValueList;
// vector<XmlNode *> moveSpeedIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("moveSpeedIsMultiplierValueList");
// for(unsigned int i = 0; i < moveSpeedIsMultiplierValueNodeList.size(); ++i) {
// XmlNode *node = moveSpeedIsMultiplierValueNodeList[i];
//
// moveSpeedIsMultiplierValueList[node->getAttribute("key")->getValue()] =
// node->getAttribute("value")->getIntValue();
// }
//
// // int prodSpeed;
// prodSpeed = upgradeTypeBaseNode->getAttribute("prodSpeed")->getIntValue();
// // bool prodSpeedIsMultiplier;
// prodSpeedIsMultiplier = upgradeTypeBaseNode->getAttribute("prodSpeedIsMultiplier")->getIntValue();
// // std::map<string,int> prodSpeedProduceIsMultiplierValueList;
// vector<XmlNode *> prodSpeedProduceIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("prodSpeedProduceIsMultiplierValueList");
// for(unsigned int i = 0; i < prodSpeedProduceIsMultiplierValueNodeList.size(); ++i) {
// XmlNode *node = prodSpeedProduceIsMultiplierValueNodeList[i];
//
// prodSpeedProduceIsMultiplierValueList[node->getAttribute("key")->getValue()] =
// node->getAttribute("value")->getIntValue();
// }
//
// // std::map<string,int> prodSpeedUpgradeIsMultiplierValueList;
// vector<XmlNode *> prodSpeedUpgradeIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("prodSpeedUpgradeIsMultiplierValueList");
// for(unsigned int i = 0; i < prodSpeedUpgradeIsMultiplierValueNodeList.size(); ++i) {
// XmlNode *node = prodSpeedUpgradeIsMultiplierValueNodeList[i];
//
// prodSpeedUpgradeIsMultiplierValueList[node->getAttribute("key")->getValue()] =
// node->getAttribute("value")->getIntValue();
// }
//
// // std::map<string,int> prodSpeedMorphIsMultiplierValueList;
// vector<XmlNode *> prodSpeedMorphIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("prodSpeedMorphIsMultiplierValueList");
// for(unsigned int i = 0; i < prodSpeedMorphIsMultiplierValueNodeList.size(); ++i) {
// XmlNode *node = prodSpeedMorphIsMultiplierValueNodeList[i];
//
// prodSpeedMorphIsMultiplierValueList[node->getAttribute("key")->getValue()] =
// node->getAttribute("value")->getIntValue();
// }
}
// ==================== misc ====================
@ -558,7 +661,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree,
sortedItems.clear();
//values
UpgradeTypeBase::load(upgradeNode);
UpgradeTypeBase::load(upgradeNode,name);
}
catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
@ -572,22 +675,36 @@ bool UpgradeType::isAffected(const UnitType *unitType) const{
return find(effects.begin(), effects.end(), unitType)!=effects.end();
}
void UpgradeType::saveGame(XmlNode *rootNode) const {
UpgradeTypeBase::saveGame(rootNode);
ProducibleType::saveGame(rootNode);
std::map<string,string> mapTagReplacements;
XmlNode *upgradeTypeNode = rootNode->addChild("UpgradeType");
//upgradeTypeNode->addAttribute("maxHp",intToStr(maxHp), mapTagReplacements);
//vector<const UnitType*> effects;
for(unsigned int i = 0; i < effects.size(); ++i) {
XmlNode *unitTypeNode = rootNode->addChild("UnitType");
const UnitType *ut = effects[i];
unitTypeNode->addAttribute("name",ut->getName(), mapTagReplacements);
}
}
//void UpgradeType::saveGame(XmlNode *rootNode) const {
// UpgradeTypeBase::saveGame(rootNode);
// ProducibleType::saveGame(rootNode);
//
// std::map<string,string> mapTagReplacements;
// XmlNode *upgradeTypeNode = rootNode->addChild("UpgradeType");
//
// //upgradeTypeNode->addAttribute("maxHp",intToStr(maxHp), mapTagReplacements);
// //vector<const UnitType*> effects;
// for(unsigned int i = 0; i < effects.size(); ++i) {
// XmlNode *unitTypeNode = rootNode->addChild("UnitType");
//
// const UnitType *ut = effects[i];
// unitTypeNode->addAttribute("name",ut->getName(), mapTagReplacements);
// }
//}
//
//void UpgradeType::loadGame(const XmlNode *rootNode, Faction *faction) {
// //UpgradeTypeBase::loadGame(rootNode);
// //ProducibleType::loadGame(rootNode);
//
// //const XmlNode *upgradeTypeNode = rootNode->getChild("UpgradeType");
//
// //maxHp = upgradeTypeNode->getAttribute("maxHp")->getIntValue();
//
//// vector<XmlNode *> unitTypeNodeList = upgradeTypeNode->getChildList("UnitType");
//// for(unsigned int i = 0; i < unitTypeNodeList.size(); ++i) {
//// XmlNode *node = unitTypeNodeList[i];
//// }
//}
// ===============================
// class TotalUpgrade
@ -871,5 +988,200 @@ void TotalUpgrade::incLevel(const UnitType *ut) {
armor += ut->getArmor()*50/100;
}
void TotalUpgrade::saveGame(XmlNode *rootNode) const {
std::map<string,string> mapTagReplacements;
XmlNode *upgradeTypeBaseNode = rootNode->addChild("TotalUpgrade");
// int maxHp;
upgradeTypeBaseNode->addAttribute("maxHp",intToStr(maxHp), mapTagReplacements);
// bool maxHpIsMultiplier;
upgradeTypeBaseNode->addAttribute("maxHpIsMultiplier",intToStr(maxHpIsMultiplier), mapTagReplacements);
// int maxHpRegeneration;
upgradeTypeBaseNode->addAttribute("maxHpRegeneration",intToStr(maxHpRegeneration), mapTagReplacements);
// //bool maxHpRegenerationIsMultiplier;
//
// int sight;
upgradeTypeBaseNode->addAttribute("sight",intToStr(sight), mapTagReplacements);
// bool sightIsMultiplier;
upgradeTypeBaseNode->addAttribute("sightIsMultiplier",intToStr(sightIsMultiplier), mapTagReplacements);
// int maxEp;
upgradeTypeBaseNode->addAttribute("maxEp",intToStr(maxEp), mapTagReplacements);
// bool maxEpIsMultiplier;
upgradeTypeBaseNode->addAttribute("maxEpIsMultiplier",intToStr(maxEpIsMultiplier), mapTagReplacements);
// int maxEpRegeneration;
upgradeTypeBaseNode->addAttribute("maxEpRegeneration",intToStr(maxEpRegeneration), mapTagReplacements);
// //bool maxEpRegenerationIsMultiplier;
// int armor;
upgradeTypeBaseNode->addAttribute("armor",intToStr(armor), mapTagReplacements);
// bool armorIsMultiplier;
upgradeTypeBaseNode->addAttribute("armorIsMultiplier",intToStr(armorIsMultiplier), mapTagReplacements);
// int attackStrength;
upgradeTypeBaseNode->addAttribute("attackStrength",intToStr(attackStrength), mapTagReplacements);
// bool attackStrengthIsMultiplier;
upgradeTypeBaseNode->addAttribute("attackStrengthIsMultiplier",intToStr(attackStrengthIsMultiplier), mapTagReplacements);
// std::map<string,int> attackStrengthMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = attackStrengthMultiplierValueList.begin();
iterMap != attackStrengthMultiplierValueList.end(); ++iterMap) {
XmlNode *attackStrengthMultiplierValueListNode = upgradeTypeBaseNode->addChild("attackStrengthMultiplierValueList");
attackStrengthMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
attackStrengthMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
// int attackRange;
upgradeTypeBaseNode->addAttribute("attackRange",intToStr(attackRange), mapTagReplacements);
// bool attackRangeIsMultiplier;
upgradeTypeBaseNode->addAttribute("attackRangeIsMultiplier",intToStr(attackRangeIsMultiplier), mapTagReplacements);
// std::map<string,int> attackRangeMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = attackRangeMultiplierValueList.begin();
iterMap != attackRangeMultiplierValueList.end(); ++iterMap) {
XmlNode *attackRangeMultiplierValueListNode = upgradeTypeBaseNode->addChild("attackRangeMultiplierValueList");
attackRangeMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
attackRangeMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
// int moveSpeed;
upgradeTypeBaseNode->addAttribute("moveSpeed",intToStr(moveSpeed), mapTagReplacements);
// bool moveSpeedIsMultiplier;
upgradeTypeBaseNode->addAttribute("moveSpeedIsMultiplier",intToStr(moveSpeedIsMultiplier), mapTagReplacements);
// std::map<string,int> moveSpeedIsMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = moveSpeedIsMultiplierValueList.begin();
iterMap != moveSpeedIsMultiplierValueList.end(); ++iterMap) {
XmlNode *moveSpeedIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("moveSpeedIsMultiplierValueList");
moveSpeedIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
moveSpeedIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
// int prodSpeed;
upgradeTypeBaseNode->addAttribute("prodSpeed",intToStr(prodSpeed), mapTagReplacements);
// bool prodSpeedIsMultiplier;
upgradeTypeBaseNode->addAttribute("prodSpeedIsMultiplier",intToStr(prodSpeedIsMultiplier), mapTagReplacements);
// std::map<string,int> prodSpeedProduceIsMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = prodSpeedProduceIsMultiplierValueList.begin();
iterMap != prodSpeedProduceIsMultiplierValueList.end(); ++iterMap) {
XmlNode *prodSpeedProduceIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("prodSpeedProduceIsMultiplierValueList");
prodSpeedProduceIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
prodSpeedProduceIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
// std::map<string,int> prodSpeedUpgradeIsMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = prodSpeedUpgradeIsMultiplierValueList.begin();
iterMap != prodSpeedUpgradeIsMultiplierValueList.end(); ++iterMap) {
XmlNode *prodSpeedUpgradeIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("prodSpeedUpgradeIsMultiplierValueList");
prodSpeedUpgradeIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
prodSpeedUpgradeIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
// std::map<string,int> prodSpeedMorphIsMultiplierValueList;
for(std::map<string,int>::const_iterator iterMap = prodSpeedMorphIsMultiplierValueList.begin();
iterMap != prodSpeedMorphIsMultiplierValueList.end(); ++iterMap) {
XmlNode *prodSpeedMorphIsMultiplierValueListNode = upgradeTypeBaseNode->addChild("prodSpeedMorphIsMultiplierValueList");
prodSpeedMorphIsMultiplierValueListNode->addAttribute("key",iterMap->first, mapTagReplacements);
prodSpeedMorphIsMultiplierValueListNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
}
void TotalUpgrade::loadGame(const XmlNode *rootNode) {
const XmlNode *upgradeTypeBaseNode = rootNode->getChild("TotalUpgrade");
//description = upgradeTypeBaseNode->getAttribute("description")->getValue();
// int maxHp;
maxHp = upgradeTypeBaseNode->getAttribute("maxHp")->getIntValue();
// bool maxHpIsMultiplier;
maxHpIsMultiplier = upgradeTypeBaseNode->getAttribute("maxHpIsMultiplier")->getIntValue();
// int maxHpRegeneration;
maxHpRegeneration = upgradeTypeBaseNode->getAttribute("maxHpRegeneration")->getIntValue();
// //bool maxHpRegenerationIsMultiplier;
//
// int sight;
sight = upgradeTypeBaseNode->getAttribute("sight")->getIntValue();
// bool sightIsMultiplier;
sightIsMultiplier = upgradeTypeBaseNode->getAttribute("sightIsMultiplier")->getIntValue();
// int maxEp;
maxEp = upgradeTypeBaseNode->getAttribute("maxEp")->getIntValue();
// bool maxEpIsMultiplier;
maxEpIsMultiplier = upgradeTypeBaseNode->getAttribute("maxEpIsMultiplier")->getIntValue();
// int maxEpRegeneration;
maxEpRegeneration = upgradeTypeBaseNode->getAttribute("maxEpRegeneration")->getIntValue();
// //bool maxEpRegenerationIsMultiplier;
// int armor;
armor = upgradeTypeBaseNode->getAttribute("armor")->getIntValue();
// bool armorIsMultiplier;
armorIsMultiplier = upgradeTypeBaseNode->getAttribute("armorIsMultiplier")->getIntValue();
// int attackStrength;
attackStrength = upgradeTypeBaseNode->getAttribute("attackStrength")->getIntValue();
// bool attackStrengthIsMultiplier;
attackStrengthIsMultiplier = upgradeTypeBaseNode->getAttribute("attackStrengthIsMultiplier")->getIntValue();
// std::map<string,int> attackStrengthMultiplierValueList;
vector<XmlNode *> attackStrengthMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("attackStrengthMultiplierValueList");
for(unsigned int i = 0; i < attackStrengthMultiplierValueNodeList.size(); ++i) {
XmlNode *node = attackStrengthMultiplierValueNodeList[i];
attackStrengthMultiplierValueList[node->getAttribute("key")->getValue()] =
node->getAttribute("value")->getIntValue();
}
// int attackRange;
attackRange = upgradeTypeBaseNode->getAttribute("attackRange")->getIntValue();
// bool attackRangeIsMultiplier;
attackRangeIsMultiplier = upgradeTypeBaseNode->getAttribute("attackRangeIsMultiplier")->getIntValue();
// std::map<string,int> attackRangeMultiplierValueList;
vector<XmlNode *> attackRangeMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("attackRangeMultiplierValueList");
for(unsigned int i = 0; i < attackRangeMultiplierValueNodeList.size(); ++i) {
XmlNode *node = attackRangeMultiplierValueNodeList[i];
attackRangeMultiplierValueList[node->getAttribute("key")->getValue()] =
node->getAttribute("value")->getIntValue();
}
// int moveSpeed;
moveSpeed = upgradeTypeBaseNode->getAttribute("moveSpeed")->getIntValue();
// bool moveSpeedIsMultiplier;
moveSpeedIsMultiplier = upgradeTypeBaseNode->getAttribute("moveSpeedIsMultiplier")->getIntValue();
// std::map<string,int> moveSpeedIsMultiplierValueList;
vector<XmlNode *> moveSpeedIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("moveSpeedIsMultiplierValueList");
for(unsigned int i = 0; i < moveSpeedIsMultiplierValueNodeList.size(); ++i) {
XmlNode *node = moveSpeedIsMultiplierValueNodeList[i];
moveSpeedIsMultiplierValueList[node->getAttribute("key")->getValue()] =
node->getAttribute("value")->getIntValue();
}
// int prodSpeed;
prodSpeed = upgradeTypeBaseNode->getAttribute("prodSpeed")->getIntValue();
// bool prodSpeedIsMultiplier;
prodSpeedIsMultiplier = upgradeTypeBaseNode->getAttribute("prodSpeedIsMultiplier")->getIntValue();
// std::map<string,int> prodSpeedProduceIsMultiplierValueList;
vector<XmlNode *> prodSpeedProduceIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("prodSpeedProduceIsMultiplierValueList");
for(unsigned int i = 0; i < prodSpeedProduceIsMultiplierValueNodeList.size(); ++i) {
XmlNode *node = prodSpeedProduceIsMultiplierValueNodeList[i];
prodSpeedProduceIsMultiplierValueList[node->getAttribute("key")->getValue()] =
node->getAttribute("value")->getIntValue();
}
// std::map<string,int> prodSpeedUpgradeIsMultiplierValueList;
vector<XmlNode *> prodSpeedUpgradeIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("prodSpeedUpgradeIsMultiplierValueList");
for(unsigned int i = 0; i < prodSpeedUpgradeIsMultiplierValueNodeList.size(); ++i) {
XmlNode *node = prodSpeedUpgradeIsMultiplierValueNodeList[i];
prodSpeedUpgradeIsMultiplierValueList[node->getAttribute("key")->getValue()] =
node->getAttribute("value")->getIntValue();
}
// std::map<string,int> prodSpeedMorphIsMultiplierValueList;
vector<XmlNode *> prodSpeedMorphIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("prodSpeedMorphIsMultiplierValueList");
for(unsigned int i = 0; i < prodSpeedMorphIsMultiplierValueNodeList.size(); ++i) {
XmlNode *node = prodSpeedMorphIsMultiplierValueNodeList[i];
prodSpeedMorphIsMultiplierValueList[node->getAttribute("key")->getValue()] =
node->getAttribute("value")->getIntValue();
}
}
}}//end namespace

View File

@ -32,6 +32,7 @@ class SkillType;
class AttackSkillType;
class MoveSkillType;
class ProduceSkillType;
class Faction;
// ===============================
// class UpgradeTypeBase
@ -39,6 +40,7 @@ class ProduceSkillType;
class UpgradeTypeBase {
protected:
string upgradename;
int maxHp;
bool maxHpIsMultiplier;
int maxHpRegeneration;
@ -99,12 +101,13 @@ public:
int getProdSpeed(const SkillType *st) const;
bool getProdSpeedIsMultiplier() const {return prodSpeedIsMultiplier;}
void load(const XmlNode *upgradeNode);
void load(const XmlNode *upgradeNode, string upgradename);
virtual string getDesc() const;
std::string toString() const {
std::string result = "";
result += "upgradename =" + upgradename;
result += "maxHp = " + intToStr(maxHp);
result += "maxHpIsMultiplier = " + intToStr(maxHpIsMultiplier);
result += "maxHpRegeneration = " + intToStr(maxHpRegeneration);
@ -133,6 +136,7 @@ public:
}
virtual void saveGame(XmlNode *rootNode) const;
static const UpgradeType * loadGame(const XmlNode *rootNode, Faction *faction);
};
// ===============================
@ -157,7 +161,8 @@ public:
//other methods
virtual string getReqDesc() const;
virtual void saveGame(XmlNode *rootNode) const;
//virtual void saveGame(XmlNode *rootNode) const;
//virtual void loadGame(const XmlNode *rootNode);
};
// ===============================
@ -174,6 +179,9 @@ public:
void apply(const UpgradeTypeBase *ut, const Unit *unit);
void deapply(const UpgradeTypeBase *ut, const Unit *unit);
void saveGame(XmlNode *rootNode) const;
void loadGame(const XmlNode *rootNode);
};
}}//end namespace

View File

@ -153,6 +153,7 @@ SurfaceCell::SurfaceCell() {
surfaceType= -1;
surfaceTexture= NULL;
nearSubmerged = false;
cellChangedFromOriginalMapLoad = false;
for(int i = 0; i < GameConstants::maxPlayers + GameConstants::specialFactions; ++i) {
visible[i] = false;
@ -181,12 +182,20 @@ bool SurfaceCell::isFree() const {
}
void SurfaceCell::deleteResource() {
cellChangedFromOriginalMapLoad = true;
delete object;
object= NULL;
}
bool SurfaceCell::decAmount(int value) {
cellChangedFromOriginalMapLoad = true;
return object->getResource()->decAmount(value);
}
void SurfaceCell::setExplored(int teamIndex, bool explored) {
this->explored[teamIndex]= explored;
//printf("Setting explored to %d for teamIndex %d\n",explored,teamIndex);
}
void SurfaceCell::setVisible(int teamIndex, bool visible) {
@ -194,14 +203,15 @@ void SurfaceCell::setVisible(int teamIndex, bool visible) {
}
void SurfaceCell::saveGame(XmlNode *rootNode,int index) const {
bool saveCell = (object != NULL);
if(saveCell == false) {
for(unsigned int i = 0; i < GameConstants::maxPlayers; ++i) {
if(visible[i] == true || explored[i] == true) {
saveCell = true;
}
}
}
bool saveCell = (this->getCellChangedFromOriginalMapLoad() == true);
// if(saveCell == false) {
// for(unsigned int i = 0; i < GameConstants::maxPlayers; ++i) {
// if(visible[i] == true || explored[i] == true) {
// saveCell = true;
// break;
// }
// }
// }
if(saveCell == true) {
std::map<string,string> mapTagReplacements;
@ -231,23 +241,27 @@ void SurfaceCell::saveGame(XmlNode *rootNode,int index) const {
if(object != NULL) {
object->saveGame(surfaceCellNode);
}
else {
XmlNode *objectNode = surfaceCellNode->addChild("Object");
objectNode->addAttribute("isDeleted",intToStr(true), mapTagReplacements);
}
// //visibility
// bool visible[GameConstants::maxPlayers + GameConstants::specialFactions];
for(unsigned int i = 0; i < GameConstants::maxPlayers; ++i) {
if(visible[i] == true) {
XmlNode *visibleNode = surfaceCellNode->addChild("visible");
visibleNode->addAttribute("index",intToStr(i), mapTagReplacements);
visibleNode->addAttribute("value",intToStr(visible[i]), mapTagReplacements);
}
}
// bool explored[GameConstants::maxPlayers + GameConstants::specialFactions];
for(unsigned int i = 0; i < GameConstants::maxPlayers; ++i) {
if(explored[i] == true) {
XmlNode *exploredNode = surfaceCellNode->addChild("explored");
exploredNode->addAttribute("index",intToStr(i), mapTagReplacements);
exploredNode->addAttribute("value",intToStr(explored[i]), mapTagReplacements);
}
}
// for(unsigned int i = 0; i < GameConstants::maxPlayers; ++i) {
// if(visible[i] == true) {
// XmlNode *visibleNode = surfaceCellNode->addChild("visible");
// visibleNode->addAttribute("index",intToStr(i), mapTagReplacements);
// visibleNode->addAttribute("value",intToStr(visible[i]), mapTagReplacements);
// }
// }
// // bool explored[GameConstants::maxPlayers + GameConstants::specialFactions];
// for(unsigned int i = 0; i < GameConstants::maxPlayers; ++i) {
// if(explored[i] == true) {
// XmlNode *exploredNode = surfaceCellNode->addChild("explored");
// exploredNode->addAttribute("index",intToStr(i), mapTagReplacements);
// exploredNode->addAttribute("value",intToStr(explored[i]), mapTagReplacements);
// }
// }
// //cache
// bool nearSubmerged;
@ -257,29 +271,36 @@ void SurfaceCell::saveGame(XmlNode *rootNode,int index) const {
void SurfaceCell::loadGame(const XmlNode *rootNode, int index, World *world) {
if(rootNode->hasChild("SurfaceCell" + intToStr(index)) == true) {
const XmlNode *cellNode = rootNode->getChild("SurfaceCell" + intToStr(index));
int visibleCount = cellNode->getChildCount();
const XmlNode *surfaceCellNode = rootNode->getChild("SurfaceCell" + intToStr(index));
//int visibleCount = cellNode->getChildCount();
XmlNode *objectNode = surfaceCellNode->getChild("Object");
if(objectNode->hasAttribute("isDeleted") == true) {
this->deleteResource();
}
else {
object->loadGame(surfaceCellNode,world->getTechTree());
}
//printf("Loading game, sc index [%d][%d]\n",index,visibleCount);
for(unsigned int i = 0; i < visibleCount; ++i) {
if(cellNode->hasChildAtIndex("visible",i) == true) {
const XmlNode *visibleNode = cellNode->getChild("visible",i);
int indexCell = visibleNode->getAttribute("index")->getIntValue();
bool value = visibleNode->getAttribute("value")->getIntValue();
visible[indexCell] = value;
//printf("Loading game, sc visible index [%d][%d][%d]\n",index,indexCell,value);
}
if(cellNode->hasChildAtIndex("explored",i) == true) {
const XmlNode *exploredNode = cellNode->getChild("explored",i);
int indexCell = exploredNode->getAttribute("index")->getIntValue();
bool value = exploredNode->getAttribute("value")->getIntValue();
explored[indexCell] = value;
//printf("Loading game, sc explored index [%d][%d][%d]\n",index,indexCell,value);
}
}
// for(unsigned int i = 0; i < visibleCount; ++i) {
// if(cellNode->hasChildAtIndex("visible",i) == true) {
// const XmlNode *visibleNode = cellNode->getChild("visible",i);
// int indexCell = visibleNode->getAttribute("index")->getIntValue();
// bool value = visibleNode->getAttribute("value")->getIntValue();
// visible[indexCell] = value;
//
// //printf("Loading game, sc visible index [%d][%d][%d]\n",index,indexCell,value);
// }
// if(cellNode->hasChildAtIndex("explored",i) == true) {
// const XmlNode *exploredNode = cellNode->getChild("explored",i);
// int indexCell = exploredNode->getAttribute("index")->getIntValue();
// bool value = exploredNode->getAttribute("value")->getIntValue();
// explored[indexCell] = value;
//
// //printf("Loading game, sc explored cell index [%d] exploredIndex [%d] value [%d]\n",index,indexCell,value);
// }
// }
}
}
// =====================================================
@ -1830,17 +1851,43 @@ void Map::saveGame(XmlNode *rootNode) const {
mapNode->addAttribute("maxPlayers",intToStr(maxPlayers), mapTagReplacements);
// Cell *cells;
//printf("getCellArraySize() = %d\n",getCellArraySize());
for(unsigned int i = 0; i < getCellArraySize(); ++i) {
Cell &cell = cells[i];
cell.saveGame(mapNode,i);
}
// for(unsigned int i = 0; i < getCellArraySize(); ++i) {
// Cell &cell = cells[i];
// cell.saveGame(mapNode,i);
// }
// SurfaceCell *surfaceCells;
//printf("getSurfaceCellArraySize() = %d\n",getSurfaceCellArraySize());
string exploredList = "";
string visibleList = "";
for(unsigned int i = 0; i < getSurfaceCellArraySize(); ++i) {
SurfaceCell &surfaceCell = surfaceCells[i];
for(unsigned int j = 0; j < GameConstants::maxPlayers; ++j) {
if(exploredList != "") {
exploredList += "|";
}
exploredList += intToStr(surfaceCell.isExplored(j));
}
exploredList += ",";
for(unsigned int j = 0; j < GameConstants::maxPlayers; ++j) {
if(visibleList != "") {
visibleList += "|";
}
visibleList += intToStr(surfaceCell.isVisible(j));
}
visibleList += ",";
surfaceCell.saveGame(mapNode,i);
}
XmlNode *surfaceCellNode = mapNode->addChild("SurfaceCell");
surfaceCellNode->addAttribute("exploredList",exploredList, mapTagReplacements);
surfaceCellNode->addAttribute("visibleList",visibleList, mapTagReplacements);
// Vec2i *startLocations;
for(unsigned int i = 0; i < maxPlayers; ++i) {
XmlNode *startLocationsNode = mapNode->addChild("startLocations");
@ -1855,7 +1902,7 @@ void Map::saveGame(XmlNode *rootNode) const {
}
void Map::loadGame(const XmlNode *rootNode, World *world) {
const XmlNode *mapNode = rootNode->getChild("World")->getChild("Map");
const XmlNode *mapNode = rootNode->getChild("Map");
//description = gameSettingsNode->getAttribute("description")->getValue();
@ -1868,18 +1915,52 @@ void Map::loadGame(const XmlNode *rootNode, World *world) {
// surfaceCell.saveGame(mapNode,i);
// }
printf("getCellArraySize() = %d\n",getCellArraySize());
for(unsigned int i = 0; i < getCellArraySize(); ++i) {
Cell &cell = cells[i];
cell.loadGame(mapNode,i,world);
}
// printf("getCellArraySize() = %d\n",getCellArraySize());
// for(unsigned int i = 0; i < getCellArraySize(); ++i) {
// Cell &cell = cells[i];
// cell.loadGame(mapNode,i,world);
// }
printf("getSurfaceCellArraySize() = %d\n",getSurfaceCellArraySize());
// printf("getSurfaceCellArraySize() = %d\n",getSurfaceCellArraySize());
for(unsigned int i = 0; i < getSurfaceCellArraySize(); ++i) {
SurfaceCell &surfaceCell = surfaceCells[i];
surfaceCell.loadGame(mapNode,i,world);
}
XmlNode *surfaceCellNode = mapNode->getChild("SurfaceCell");
string exploredList = surfaceCellNode->getAttribute("exploredList")->getValue();
string visibleList = surfaceCellNode->getAttribute("visibleList")->getValue();
vector<string> tokensExplored;
Tokenize(exploredList,tokensExplored,",");
for(unsigned int i = 0; i < tokensExplored.size(); ++i) {
string valueList = tokensExplored[i];
vector<string> tokensExploredValue;
Tokenize(valueList,tokensExploredValue,"|");
for(unsigned int j = 0; j < tokensExploredValue.size(); ++j) {
string value = tokensExploredValue[j];
SurfaceCell &surfaceCell = surfaceCells[i];
surfaceCell.setExplored(j,strToInt(value));
}
}
vector<string> tokensVisible;
Tokenize(visibleList,tokensVisible,",");
for(unsigned int i = 0; i < tokensVisible.size(); ++i) {
string valueList = tokensVisible[i];
vector<string> tokensVisibleValue;
Tokenize(valueList,tokensVisibleValue,"|");
for(unsigned int j = 0; j < tokensVisibleValue.size(); ++j) {
string value = tokensVisibleValue[j];
SurfaceCell &surfaceCell = surfaceCells[i];
surfaceCell.setVisible(j,strToInt(value));
}
}
}
// =====================================================

View File

@ -105,6 +105,7 @@ private:
//cache
bool nearSubmerged;
bool cellChangedFromOriginalMapLoad;
public:
SurfaceCell();
@ -143,7 +144,9 @@ public:
//misc
void deleteResource();
bool decAmount(int value);
bool isFree() const;
bool getCellChangedFromOriginalMapLoad() const { return cellChangedFromOriginalMapLoad; }
void saveGame(XmlNode *rootNode,int index) const;
void loadGame(const XmlNode *rootNode, int index, World *world);

View File

@ -220,4 +220,36 @@ void Minimap::computeTexture(const World *world) {
}
}
void Minimap::saveGame(XmlNode *rootNode) {
std::map<string,string> mapTagReplacements;
XmlNode *minimapNode = rootNode->addChild("Minimap");
// Pixmap2D *fowPixmap0;
// Pixmap2D *fowPixmap1;
for(unsigned int i = 0; i < fowPixmap1->getPixelByteCount(); ++i) {
if(fowPixmap1->getPixels()[i] != 0) {
XmlNode *fowPixmap1Node = minimapNode->addChild("fowPixmap1");
fowPixmap1Node->addAttribute("index",intToStr(i), mapTagReplacements);
fowPixmap1Node->addAttribute("pixel",intToStr(fowPixmap1->getPixels()[i]), mapTagReplacements);
}
}
// Texture2D *tex;
// Texture2D *fowTex; //Fog Of War Texture2D
// bool fogOfWar;
// const GameSettings *gameSettings;
}
void Minimap::loadGame(const XmlNode *rootNode) {
const XmlNode *minimapNode = rootNode->getChild("Minimap");
vector<XmlNode *> fowPixmap1NodeList = minimapNode->getChildList("fowPixmap1");
for(unsigned int i = 0; i < fowPixmap1NodeList.size(); ++i) {
XmlNode *fowPixmap1Node = fowPixmap1NodeList[i];
int pixelIndex = fowPixmap1Node->getAttribute("index")->getIntValue();
fowPixmap1->getPixels()[pixelIndex] = fowPixmap1Node->getAttribute("pixel")->getIntValue();
}
}
}}//end namespace

View File

@ -14,6 +14,7 @@
#include "pixmap.h"
#include "texture.h"
#include "xml_parser.h"
#include "leak_dumper.h"
namespace Glest{ namespace Game{
@ -23,6 +24,7 @@ using Shared::Graphics::Vec3f;
using Shared::Graphics::Vec2i;
using Shared::Graphics::Pixmap2D;
using Shared::Graphics::Texture2D;
using Shared::Xml::XmlNode;
class World;
class GameSettings;
@ -64,6 +66,9 @@ public:
void updateFowTex(float t);
void setFogOfWar(bool value) { fogOfWar = value; resetFowTex(); }
void saveGame(XmlNode *rootNode);
void loadGame(const XmlNode *rootNode);
private:
void computeTexture(const World *world);
};

View File

@ -1274,7 +1274,7 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) {
unit->setLoadCount(unit->getLoadCount() + 1);
//if resource exausted, then delete it and stop
if (r->decAmount(1)) {
if (sc->decAmount(1)) {
const ResourceType *rt = r->getType();
sc->deleteResource();
world->removeResourceTargetFromCache(unitTargetPos);
@ -2600,6 +2600,14 @@ void UnitUpdater::saveGame(XmlNode *rootNode) {
// std::map<Vec2i, std::map<int, std::map<int, UnitRangeCellsLookupItem > > > UnitRangeCellsLookupItemCache;
}
void UnitUpdater::loadGame(const XmlNode *rootNode) {
const XmlNode *unitupdaterNode = rootNode->getChild("UnitUpdater");
pathFinder->loadGame(unitupdaterNode);
random.setLastNumber(unitupdaterNode->getAttribute("random")->getIntValue());
// float attackWarnRange;
attackWarnRange = unitupdaterNode->getAttribute("attackWarnRange")->getFloatValue();
}
// =====================================================
// class ParticleDamager
// =====================================================

View File

@ -129,6 +129,7 @@ public:
string getUnitRangeCellsLookupItemCacheStats();
void saveGame(XmlNode *rootNode);
void loadGame(const XmlNode *rootNode);
private:
//attack

View File

@ -248,12 +248,21 @@ void World::init(Game *game, bool createUnits, bool initFactions){
}
unitUpdater.init(game);
if(loadWorldNode != NULL) {
unitUpdater.loadGame(loadWorldNode);
}
//minimap must be init after sum computation
initMinimap();
if(createUnits){
initUnits();
}
if(loadWorldNode != NULL) {
map.loadGame(loadWorldNode,this);
minimap.loadGame(loadWorldNode);
}
//initExplorationState(); ... was only for !fog-of-war, now handled in initCells()
computeFow();
@ -1331,6 +1340,64 @@ void World::initFactionTypes(GameSettings *gs) {
}
}
if(loadWorldNode != NULL) {
stats.loadGame(loadWorldNode);
random.setLastNumber(loadWorldNode->getAttribute("random")->getIntValue());
thisFactionIndex = loadWorldNode->getAttribute("thisFactionIndex")->getIntValue();
// int thisTeamIndex;
thisTeamIndex = loadWorldNode->getAttribute("thisTeamIndex")->getIntValue();
// int frameCount;
frameCount = loadWorldNode->getAttribute("frameCount")->getIntValue();
MutexSafeWrapper safeMutex(&mutexFactionNextUnitId,string(__FILE__) + "_" + intToStr(__LINE__));
// std::map<int,int> mapFactionNextUnitId;
// for(std::map<int,int>::iterator iterMap = mapFactionNextUnitId.begin();
// iterMap != mapFactionNextUnitId.end(); ++iterMap) {
// XmlNode *factionNextUnitIdNode = worldNode->addChild("FactionNextUnitId");
//
// factionNextUnitIdNode->addAttribute("key",intToStr(iterMap->first), mapTagReplacements);
// factionNextUnitIdNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
// }
//!!!
vector<XmlNode *> factionNextUnitIdNodeList = loadWorldNode->getChildList("FactionNextUnitId");
for(unsigned int i = 0; i < factionNextUnitIdNodeList.size(); ++i) {
XmlNode *factionNextUnitIdNode = factionNextUnitIdNodeList[i];
int key = factionNextUnitIdNode->getAttribute("key")->getIntValue();
int value = factionNextUnitIdNode->getAttribute("value")->getIntValue();
mapFactionNextUnitId[key] = value;
}
safeMutex.ReleaseLock();
// //config
// bool fogOfWarOverride;
fogOfWarOverride = loadWorldNode->getAttribute("fogOfWarOverride")->getIntValue();
// bool fogOfWar;
fogOfWar = loadWorldNode->getAttribute("fogOfWar")->getIntValue();
// int fogOfWarSmoothingFrameSkip;
fogOfWarSmoothingFrameSkip = loadWorldNode->getAttribute("fogOfWarSmoothingFrameSkip")->getIntValue();
// bool fogOfWarSmoothing;
fogOfWarSmoothing = loadWorldNode->getAttribute("fogOfWarSmoothing")->getIntValue();
// Game *game;
// Chrono chronoPerfTimer;
// bool perfTimerEnabled;
//
// bool unitParticlesEnabled;
unitParticlesEnabled = loadWorldNode->getAttribute("unitParticlesEnabled")->getIntValue();
// bool staggeredFactionUpdates;
staggeredFactionUpdates = loadWorldNode->getAttribute("staggeredFactionUpdates")->getIntValue();
// std::map<string,StaticSound *> staticSoundList;
// std::map<string,StrSound *> streamSoundList;
//
// uint32 nextCommandGroupId;
nextCommandGroupId = loadWorldNode->getAttribute("nextCommandGroupId")->getIntValue();
// string queuedScenarioName;
queuedScenarioName = loadWorldNode->getAttribute("queuedScenarioName")->getValue();
// bool queuedScenarioKeepFactions;
queuedScenarioKeepFactions = loadWorldNode->getAttribute("queuedScenarioKeepFactions")->getIntValue();
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(factions.empty() == false) {
@ -2033,7 +2100,7 @@ void World::saveGame(XmlNode *rootNode) {
XmlNode *worldNode = rootNode->addChild("World");
// Map map;
//map.saveGame(worldNode);
map.saveGame(worldNode);
// Tileset tileset;
worldNode->addAttribute("tileset",tileset.getName(), mapTagReplacements);
// //TechTree techTree;
@ -2051,6 +2118,7 @@ void World::saveGame(XmlNode *rootNode) {
// WaterEffects waterEffects;
// WaterEffects attackEffects; // onMiniMap
// Minimap minimap;
minimap.saveGame(worldNode);
// Stats stats; //BattleEnd will delete this object
stats.saveGame(worldNode);
//
@ -2072,6 +2140,7 @@ void World::saveGame(XmlNode *rootNode) {
worldNode->addAttribute("frameCount",intToStr(frameCount), mapTagReplacements);
// //int nextUnitId;
// Mutex mutexFactionNextUnitId;
MutexSafeWrapper safeMutex(&mutexFactionNextUnitId,string(__FILE__) + "_" + intToStr(__LINE__));
// std::map<int,int> mapFactionNextUnitId;
for(std::map<int,int>::iterator iterMap = mapFactionNextUnitId.begin();
iterMap != mapFactionNextUnitId.end(); ++iterMap) {
@ -2080,6 +2149,7 @@ void World::saveGame(XmlNode *rootNode) {
factionNextUnitIdNode->addAttribute("key",intToStr(iterMap->first), mapTagReplacements);
factionNextUnitIdNode->addAttribute("value",intToStr(iterMap->second), mapTagReplacements);
}
safeMutex.ReleaseLock();
// //config
// bool fogOfWarOverride;
worldNode->addAttribute("fogOfWarOverride",intToStr(fogOfWarOverride), mapTagReplacements);