mirror of
https://github.com/glest/glest-source.git
synced 2025-08-29 19:00:07 +02:00
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:
@@ -36,13 +36,62 @@ FactionType::FactionType() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//load a faction, given a directory
|
//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) {
|
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__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
string currentPath = dir;
|
bool realFactionPathFound=false;
|
||||||
endPathWithSlash(currentPath);
|
|
||||||
|
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);
|
name= lastDir(currentPath);
|
||||||
|
|
||||||
@@ -94,7 +143,7 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
|
|||||||
int progressBaseValue=logger.getProgress();
|
int progressBaseValue=logger.getProgress();
|
||||||
for(int i = 0; i < unitTypes.size(); ++i) {
|
for(int i = 0; i < unitTypes.size(); ++i) {
|
||||||
string str= currentPath + "units/" + unitTypes[i].getName();
|
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);
|
loadedFileList);
|
||||||
logger.setProgress(progressBaseValue+(int)((((double)i + 1.0) / (double)unitTypes.size()) * 100.0/techTree->getTypeCount()));
|
logger.setProgress(progressBaseValue+(int)((((double)i + 1.0) / (double)unitTypes.size()) * 100.0/techTree->getTypeCount()));
|
||||||
SDL_PumpEvents();
|
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());
|
throw runtime_error("Error loading upgrades: "+ currentPath + "\n" + e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
//open xml file
|
string tmppath= currentPath + factionName +".xml";
|
||||||
string path= currentPath + name + ".xml";
|
|
||||||
checksum->addFile(path);
|
|
||||||
techtreeChecksum->addFile(path);
|
|
||||||
|
|
||||||
XmlTree xmlTree;
|
|
||||||
std::map<string,string> mapExtraTagReplacementValues;
|
std::map<string,string> mapExtraTagReplacementValues;
|
||||||
mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTree->getPath() + "/commondata/";
|
mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTreePath + "/commondata/";
|
||||||
xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues));
|
//printf("current $COMMONDATAPATH = %s\n",mapExtraTagReplacementValues["$COMMONDATAPATH"].c_str());
|
||||||
loadedFileList[path].push_back(make_pair(currentPath,currentPath));
|
xmlTree.load(tmppath, Properties::getTagReplacementValues(&mapExtraTagReplacementValues));
|
||||||
|
|
||||||
const XmlNode *factionNode= xmlTree.getRootNode();
|
|
||||||
|
|
||||||
|
factionNode=xmlTree.getRootNode();
|
||||||
//read starting resources
|
//read starting resources
|
||||||
|
//printf("factionNode->getName()=%s",factionNode->getName().c_str());
|
||||||
const XmlNode *startingResourcesNode= factionNode->getChild("starting-resources");
|
const XmlNode *startingResourcesNode= factionNode->getChild("starting-resources");
|
||||||
|
|
||||||
startingResources.resize(startingResourcesNode->getChildCount());
|
startingResources.resize(startingResourcesNode->getChildCount());
|
||||||
|
@@ -58,7 +58,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
//init
|
//init
|
||||||
FactionType();
|
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);
|
Checksum *techtreeChecksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
|
||||||
~FactionType();
|
~FactionType();
|
||||||
|
|
||||||
|
@@ -32,11 +32,12 @@ namespace Glest{ namespace Game{
|
|||||||
// class TechTree
|
// class TechTree
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
TechTree::TechTree() {
|
TechTree::TechTree(const vector<string> pathList) {
|
||||||
SkillType::resetNextAttackBoostId();
|
SkillType::resetNextAttackBoostId();
|
||||||
|
|
||||||
name="";
|
name="";
|
||||||
treePath="";
|
treePath="";
|
||||||
|
this->pathList.assign(pathList.begin(), pathList.end());
|
||||||
|
|
||||||
resourceTypes.clear();
|
resourceTypes.clear();
|
||||||
factionTypes.clear();
|
factionTypes.clear();
|
||||||
@@ -44,23 +45,40 @@ TechTree::TechTree() {
|
|||||||
attackTypes.clear();
|
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) {
|
set<string> &factions, Checksum* checksum, std::map<string,vector<pair<string, string> > > &loadedFileList) {
|
||||||
name = "";
|
name = "";
|
||||||
Checksum techtreeChecksum;
|
Checksum techtreeChecksum;
|
||||||
for(int idx = 0; idx < pathList.size(); idx++) {
|
string path=findPath(techName);
|
||||||
string currentPath = pathList[idx];
|
if(path!=""){
|
||||||
endPathWithSlash(currentPath);
|
printf(">>> path=%s\n",path.c_str());
|
||||||
|
load(path, factions, checksum, &techtreeChecksum, loadedFileList);
|
||||||
string path = currentPath + techName;
|
}
|
||||||
if(isdir(path.c_str()) == true) {
|
else
|
||||||
load(path, factions, checksum, &techtreeChecksum, loadedFileList);
|
{
|
||||||
break;
|
printf(">>> schoen\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return techtreeChecksum;
|
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,
|
void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum,
|
||||||
Checksum *techtreeChecksum, std::map<string,vector<pair<string, string> > > &loadedFileList) {
|
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__);
|
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();
|
//SDL_PumpEvents();
|
||||||
|
|
||||||
//load factions
|
//load factions
|
||||||
str = currentPath + "factions/*.";
|
|
||||||
try{
|
try{
|
||||||
factionTypes.resize(factions.size());
|
factionTypes.resize(factions.size());
|
||||||
|
|
||||||
@@ -192,8 +209,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
|
|||||||
logger.setState(szBuf);
|
logger.setState(szBuf);
|
||||||
logger.setProgress((int)((((double)i) / (double)factions.size()) * 100.0));
|
logger.setProgress((int)((((double)i) / (double)factions.size()) * 100.0));
|
||||||
|
|
||||||
str = currentPath + "factions/" + factionName;
|
factionTypes[i++].load(factionName, this, checksum,&checksumValue,loadedFileList);
|
||||||
factionTypes[i++].load(str, this, checksum,&checksumValue,loadedFileList);
|
|
||||||
|
|
||||||
// give CPU time to update other things to avoid apperance of hanging
|
// give CPU time to update other things to avoid apperance of hanging
|
||||||
sleep(0);
|
sleep(0);
|
||||||
|
@@ -40,6 +40,7 @@ private:
|
|||||||
string name;
|
string name;
|
||||||
//string desc;
|
//string desc;
|
||||||
string treePath;
|
string treePath;
|
||||||
|
vector<string> pathList;
|
||||||
|
|
||||||
ResourceTypes resourceTypes;
|
ResourceTypes resourceTypes;
|
||||||
FactionTypes factionTypes;
|
FactionTypes factionTypes;
|
||||||
@@ -49,12 +50,13 @@ private:
|
|||||||
Checksum checksumValue;
|
Checksum checksumValue;
|
||||||
|
|
||||||
public:
|
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);
|
set<string> &factions, Checksum* checksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
|
||||||
void load(const string &dir, set<string> &factions, Checksum* checksum,
|
void load(const string &dir, set<string> &factions, Checksum* checksum,
|
||||||
Checksum *techtreeChecksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
|
Checksum *techtreeChecksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
|
||||||
|
string findPath(const string &techName) const;
|
||||||
|
|
||||||
TechTree();
|
TechTree(const vector<string> pathList);
|
||||||
~TechTree();
|
~TechTree();
|
||||||
Checksum * getChecksumValue() { return &checksumValue; }
|
Checksum * getChecksumValue() { return &checksumValue; }
|
||||||
|
|
||||||
@@ -64,6 +66,7 @@ public:
|
|||||||
const FactionType *getType(int i) const {return &factionTypes[i];}
|
const FactionType *getType(int i) const {return &factionTypes[i];}
|
||||||
const ResourceType *getResourceType(int i) const {return &resourceTypes[i];}
|
const ResourceType *getResourceType(int i) const {return &resourceTypes[i];}
|
||||||
const string getName() const {return name;}
|
const string getName() const {return name;}
|
||||||
|
vector<string> getPathList() const {return pathList;}
|
||||||
//const string &getDesc() const {return desc;}
|
//const string &getDesc() const {return desc;}
|
||||||
|
|
||||||
const string getPath() const {return treePath;}
|
const string getPath() const {return treePath;}
|
||||||
|
@@ -117,7 +117,7 @@ void UnitType::preLoad(const string &dir) {
|
|||||||
name= lastDir(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,
|
const FactionType *factionType, Checksum* checksum,
|
||||||
Checksum* techtreeChecksum, std::map<string,vector<pair<string, string> > > &loadedFileList) {
|
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;
|
XmlTree xmlTree;
|
||||||
std::map<string,string> mapExtraTagReplacementValues;
|
std::map<string,string> mapExtraTagReplacementValues;
|
||||||
mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTree->getPath() + "/commondata/";
|
mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTreePath + "/commondata/";
|
||||||
xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues));
|
xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues));
|
||||||
loadedFileList[path].push_back(make_pair(dir,dir));
|
loadedFileList[path].push_back(make_pair(dir,dir));
|
||||||
|
|
||||||
|
@@ -139,7 +139,7 @@ public:
|
|||||||
UnitType();
|
UnitType();
|
||||||
virtual ~UnitType();
|
virtual ~UnitType();
|
||||||
void preLoad(const string &dir);
|
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,
|
const FactionType *factionType, Checksum* checksum,
|
||||||
Checksum* techtreeChecksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
|
Checksum* techtreeChecksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
|
||||||
|
|
||||||
|
@@ -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__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
techTree = new TechTree();
|
techTree = new TechTree(pathList);
|
||||||
techtreeChecksum = techTree->loadTech(pathList, techName, factions,
|
techtreeChecksum = techTree->loadTech( techName, factions,
|
||||||
checksum,loadedFileList);
|
checksum,loadedFileList);
|
||||||
return techtreeChecksum;
|
return techtreeChecksum;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user