diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp index 0f4d21ccd..0eca3c5db 100644 --- a/source/glest_game/types/faction_type.cpp +++ b/source/glest_game/types/faction_type.cpp @@ -36,13 +36,62 @@ FactionType::FactionType() { } //load a faction, given a directory -void FactionType::load(const string &dir, const TechTree *techTree, Checksum* checksum, +void FactionType::load(const string &factionName, const TechTree *techTree, Checksum* checksum, Checksum *techtreeChecksum, std::map > > &loadedFileList) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - string currentPath = dir; - endPathWithSlash(currentPath); + bool realFactionPathFound=false; + + string techTreePath = techTree->getPath(); + string techTreeName=techTree->getName(); + string currentPath; + + //open xml file + string path=""; + XmlTree xmlTree; + const XmlNode *factionNode; + + //printf("\n>>> factionname=%s\n",factionName.c_str()); + while(!realFactionPathFound){ + XmlTree xmlTree; + currentPath = techTreePath + "factions/" + factionName; + endPathWithSlash(currentPath); + string tmppath= currentPath + factionName +".xml"; + std::map mapExtraTagReplacementValues; +// mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTreePath + "/commondata/"; + //printf("current $COMMONDATAPATH = %s\n",mapExtraTagReplacementValues["$COMMONDATAPATH"].c_str()); + xmlTree.load(tmppath, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); + + + const XmlNode *rootNode= xmlTree.getRootNode(); + + if(rootNode->getName()=="link") + { + const XmlNode *techTreeNode= rootNode->getChild("techtree"); + const string linkedTechTreeName=techTreeNode->getAttribute("name")->getRestrictedValue(); +// const XmlNode *factionLinkNode= rootNode->getChild("faction"); +// string linkedFactionName=factionLinkNode->getAttribute("name")->getRestrictedValue(); + string linkedTechTreePath=techTree->findPath(linkedTechTreeName); + techTreePath=linkedTechTreePath; + endPathWithSlash(techTreePath); + techTreeName=linkedTechTreeName; + } + else { + // stop looking for new path, no more links ... + //xmlTree.load(tmppath, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); + + loadedFileList[tmppath].push_back(make_pair(currentPath,currentPath)); + + realFactionPathFound=true; + //printf("techPath found! %s\n",tmppath.c_str()); + + path=tmppath; + } + } + + checksum->addFile(path); + techtreeChecksum->addFile(path); name= lastDir(currentPath); @@ -94,7 +143,7 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch int progressBaseValue=logger.getProgress(); for(int i = 0; i < unitTypes.size(); ++i) { string str= currentPath + "units/" + unitTypes[i].getName(); - unitTypes[i].load(i, str, techTree, this, checksum,techtreeChecksum, + unitTypes[i].loaddd(i, str, techTree,techTreePath, this, checksum,techtreeChecksum, loadedFileList); logger.setProgress(progressBaseValue+(int)((((double)i + 1.0) / (double)unitTypes.size()) * 100.0/techTree->getTypeCount())); SDL_PumpEvents(); @@ -120,20 +169,16 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch throw runtime_error("Error loading upgrades: "+ currentPath + "\n" + e.what()); } - //open xml file - string path= currentPath + name + ".xml"; - checksum->addFile(path); - techtreeChecksum->addFile(path); - - XmlTree xmlTree; + string tmppath= currentPath + factionName +".xml"; std::map mapExtraTagReplacementValues; - mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTree->getPath() + "/commondata/"; - xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); - loadedFileList[path].push_back(make_pair(currentPath,currentPath)); + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTreePath + "/commondata/"; + //printf("current $COMMONDATAPATH = %s\n",mapExtraTagReplacementValues["$COMMONDATAPATH"].c_str()); + xmlTree.load(tmppath, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); - const XmlNode *factionNode= xmlTree.getRootNode(); + factionNode=xmlTree.getRootNode(); //read starting resources + //printf("factionNode->getName()=%s",factionNode->getName().c_str()); const XmlNode *startingResourcesNode= factionNode->getChild("starting-resources"); startingResources.resize(startingResourcesNode->getChildCount()); diff --git a/source/glest_game/types/faction_type.h b/source/glest_game/types/faction_type.h index 97643ff36..f41ccd052 100644 --- a/source/glest_game/types/faction_type.h +++ b/source/glest_game/types/faction_type.h @@ -58,7 +58,7 @@ private: public: //init FactionType(); - void load(const string &dir, const TechTree *techTree, Checksum* checksum, + void load(const string &factionName, const TechTree *techTree, Checksum* checksum, Checksum *techtreeChecksum, std::map > > &loadedFileList); ~FactionType(); diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index 2e1207c92..1cb31a112 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -32,11 +32,12 @@ namespace Glest{ namespace Game{ // class TechTree // ===================================================== -TechTree::TechTree() { +TechTree::TechTree(const vector pathList) { SkillType::resetNextAttackBoostId(); name=""; treePath=""; + this->pathList.assign(pathList.begin(), pathList.end()); resourceTypes.clear(); factionTypes.clear(); @@ -44,23 +45,40 @@ TechTree::TechTree() { attackTypes.clear(); } -Checksum TechTree::loadTech(const vector pathList, const string &techName, +Checksum TechTree::loadTech(const string &techName, set &factions, Checksum* checksum, std::map > > &loadedFileList) { name = ""; Checksum techtreeChecksum; - for(int idx = 0; idx < pathList.size(); idx++) { - string currentPath = pathList[idx]; - endPathWithSlash(currentPath); - - string path = currentPath + techName; - if(isdir(path.c_str()) == true) { - load(path, factions, checksum, &techtreeChecksum, loadedFileList); - break; - } + string path=findPath(techName); + if(path!=""){ + printf(">>> path=%s\n",path.c_str()); + load(path, factions, checksum, &techtreeChecksum, loadedFileList); + } + else + { + printf(">>> schoen\n"); } return techtreeChecksum; } +string TechTree::findPath(const string &techName) const{ + for(int idx = 0; idx < pathList.size(); idx++) { + string currentPath = (pathList)[idx]; + endPathWithSlash(currentPath); + + string path = currentPath + techName; + + printf(">>> test path=%s\n",path.c_str()); + if(isdir(path.c_str()) == true) { + return path; + break; + } + } + //return "no path found for tech: \""+techname+"\""; + return ""; +} + + void TechTree::load(const string &dir, set &factions, Checksum* checksum, Checksum *techtreeChecksum, std::map > > &loadedFileList) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -174,7 +192,6 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum //SDL_PumpEvents(); //load factions - str = currentPath + "factions/*."; try{ factionTypes.resize(factions.size()); @@ -192,8 +209,7 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum logger.setState(szBuf); logger.setProgress((int)((((double)i) / (double)factions.size()) * 100.0)); - str = currentPath + "factions/" + factionName; - factionTypes[i++].load(str, this, checksum,&checksumValue,loadedFileList); + factionTypes[i++].load(factionName, this, checksum,&checksumValue,loadedFileList); // give CPU time to update other things to avoid apperance of hanging sleep(0); diff --git a/source/glest_game/types/tech_tree.h b/source/glest_game/types/tech_tree.h index d9e1ae14d..f4f9300b2 100644 --- a/source/glest_game/types/tech_tree.h +++ b/source/glest_game/types/tech_tree.h @@ -40,6 +40,7 @@ private: string name; //string desc; string treePath; + vector pathList; ResourceTypes resourceTypes; FactionTypes factionTypes; @@ -49,12 +50,13 @@ private: Checksum checksumValue; public: - Checksum loadTech(const vector pathList, const string &techName, + Checksum loadTech(const string &techName, set &factions, Checksum* checksum, std::map > > &loadedFileList); void load(const string &dir, set &factions, Checksum* checksum, Checksum *techtreeChecksum, std::map > > &loadedFileList); + string findPath(const string &techName) const; - TechTree(); + TechTree(const vector pathList); ~TechTree(); Checksum * getChecksumValue() { return &checksumValue; } @@ -64,6 +66,7 @@ public: const FactionType *getType(int i) const {return &factionTypes[i];} const ResourceType *getResourceType(int i) const {return &resourceTypes[i];} const string getName() const {return name;} + vector getPathList() const {return pathList;} //const string &getDesc() const {return desc;} const string getPath() const {return treePath;} diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 1f8fac3c7..bac4caab1 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -117,7 +117,7 @@ void UnitType::preLoad(const string &dir) { name= lastDir(dir); } -void UnitType::load(int id,const string &dir, const TechTree *techTree, +void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const string &techTreePath, const FactionType *factionType, Checksum* checksum, Checksum* techtreeChecksum, std::map > > &loadedFileList) { @@ -143,7 +143,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, XmlTree xmlTree; std::map mapExtraTagReplacementValues; - mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTree->getPath() + "/commondata/"; + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTreePath + "/commondata/"; xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); loadedFileList[path].push_back(make_pair(dir,dir)); diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index 2c88e4d3c..715eac71f 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -139,7 +139,7 @@ public: UnitType(); virtual ~UnitType(); void preLoad(const string &dir); - void load(int id, const string &dir, const TechTree *techTree, + void loaddd(int id, const string &dir, const TechTree *techTree,const string &techTreePath, const FactionType *factionType, Checksum* checksum, Checksum* techtreeChecksum, std::map > > &loadedFileList); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 810996613..74b9cc056 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -288,8 +288,8 @@ Checksum World::loadTech(const vector pathList, const string &techName, if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - techTree = new TechTree(); - techtreeChecksum = techTree->loadTech(pathList, techName, factions, + techTree = new TechTree(pathList); + techtreeChecksum = techTree->loadTech( techName, factions, checksum,loadedFileList); return techtreeChecksum; }