faction links, modders can include factions from other techtrees if techtree.xmls are compatible.

( Still problems with CRC-calculation and download in Multiplayer for those linked factions )
This commit is contained in:
Titus Tscharntke
2012-01-17 01:34:50 +00:00
parent 3049c5e376
commit 9f703f2303
7 changed files with 100 additions and 36 deletions

View File

@@ -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<string,vector<pair<string, string> > > &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<string,string> 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<string,string> 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());

View File

@@ -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<string,vector<pair<string, string> > > &loadedFileList);
~FactionType();

View File

@@ -32,11 +32,12 @@ namespace Glest{ namespace Game{
// class TechTree
// =====================================================
TechTree::TechTree() {
TechTree::TechTree(const vector<string> 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<string> pathList, const string &techName,
Checksum TechTree::loadTech(const string &techName,
set<string> &factions, Checksum* checksum, std::map<string,vector<pair<string, string> > > &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<string> &factions, Checksum* checksum,
Checksum *techtreeChecksum, std::map<string,vector<pair<string, string> > > &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<string> &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<string> &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);

View File

@@ -40,6 +40,7 @@ private:
string name;
//string desc;
string treePath;
vector<string> pathList;
ResourceTypes resourceTypes;
FactionTypes factionTypes;
@@ -49,12 +50,13 @@ private:
Checksum checksumValue;
public:
Checksum loadTech(const vector<string> pathList, const string &techName,
Checksum loadTech(const string &techName,
set<string> &factions, Checksum* checksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
void load(const string &dir, set<string> &factions, Checksum* checksum,
Checksum *techtreeChecksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
string findPath(const string &techName) const;
TechTree();
TechTree(const vector<string> 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<string> getPathList() const {return pathList;}
//const string &getDesc() const {return desc;}
const string getPath() const {return treePath;}

View File

@@ -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<string,vector<pair<string, string> > > &loadedFileList) {
@@ -143,7 +143,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree,
XmlTree xmlTree;
std::map<string,string> mapExtraTagReplacementValues;
mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTree->getPath() + "/commondata/";
mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTreePath + "/commondata/";
xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues));
loadedFileList[path].push_back(make_pair(dir,dir));

View File

@@ -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<string,vector<pair<string, string> > > &loadedFileList);

View File

@@ -288,8 +288,8 @@ Checksum World::loadTech(const vector<string> 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;
}