- validation now works on techtree's with linked factions

This commit is contained in:
Mark Vejvoda 2012-10-14 21:40:35 +00:00
parent 23c313fe90
commit 68b1ae54b5
4 changed files with 193 additions and 26 deletions

View File

@ -20,10 +20,12 @@
//#include "util.h"
#include "platform_common.h"
#include "conversion.h"
#include "platform_util.h"
#include "leak_dumper.h"
using namespace Shared::Util;
using namespace Shared::PlatformCommon;
using namespace Shared::Platform;
using Shared::Xml::XmlNode;
namespace Glest{ namespace Game{
@ -151,18 +153,55 @@ public:
const string &getTech() const {return tech;}
const string &getScenario() const {return scenario;}
const string &getScenarioDir() const {return scenarioDir;}
const string &getFactionTypeName(int factionIndex) const {return factionTypeNames[factionIndex];}
const string &getFactionTypeName(int factionIndex) const {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
return factionTypeNames[factionIndex];
}
string getNetworkPlayerName(int factionIndex) const {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
string result = networkPlayerNames[factionIndex];
if(networkPlayerStatuses[factionIndex] == npst_Disconnected) {
result = playerDisconnectedText + result;
}
return result;
}
const int getNetworkPlayerStatuses(int factionIndex) const { return networkPlayerStatuses[factionIndex];}
const string getNetworkPlayerLanguages(int factionIndex) const { return networkPlayerLanguages[factionIndex];}
const int getNetworkPlayerStatuses(int factionIndex) const {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
const int getNetworkPlayerGameStatus(int factionIndex) const { return networkPlayerGameStatus[factionIndex];}
return networkPlayerStatuses[factionIndex];
}
const string getNetworkPlayerLanguages(int factionIndex) const {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
return networkPlayerLanguages[factionIndex];
}
const int getNetworkPlayerGameStatus(int factionIndex) const {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
return networkPlayerGameStatus[factionIndex];
}
const vector<string> getUniqueNetworkPlayerLanguages() const {
vector<string> languageList;
@ -189,8 +228,24 @@ public:
}
return result;
}
ControlType getFactionControl(int factionIndex) const {return factionControls[factionIndex];}
int getResourceMultiplierIndex(int factionIndex) const {return resourceMultiplierIndex[factionIndex];}
ControlType getFactionControl(int factionIndex) const {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
return factionControls[factionIndex];
}
int getResourceMultiplierIndex(int factionIndex) const {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
return resourceMultiplierIndex[factionIndex];
}
bool isNetworkGame() const {
bool result = false;
@ -205,8 +260,25 @@ public:
}
int getThisFactionIndex() const {return thisFactionIndex;}
int getFactionCount() const {return factionCount;}
int getTeam(int factionIndex) const {return teams[factionIndex];}
int getStartLocationIndex(int factionIndex) const {return startLocationIndex[factionIndex];}
int getTeam(int factionIndex) const {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
return teams[factionIndex];
}
int getStartLocationIndex(int factionIndex) const {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
return startLocationIndex[factionIndex];
}
int getMapFilterIndex() const {return mapFilterIndex;}
bool getDefaultUnits() const {return defaultUnits;}
@ -235,20 +307,94 @@ public:
void setScenario(const string& scenario) {this->scenario= scenario;}
void setScenarioDir(const string& scenarioDir) {this->scenarioDir= scenarioDir;}
void setFactionTypeName(int factionIndex, const string& factionTypeName) {this->factionTypeNames[factionIndex]= factionTypeName;}
void setNetworkPlayerName(int factionIndex,const string& playername) {this->networkPlayerNames[factionIndex]= playername;}
void setNetworkPlayerStatuses(int factionIndex,int status) {this->networkPlayerStatuses[factionIndex]= status;}
void setFactionTypeName(int factionIndex, const string& factionTypeName) {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
void setNetworkPlayerGameStatus(int factionIndex,int status) {this->networkPlayerGameStatus[factionIndex]= status;}
void setNetworkPlayerLanguages(int factionIndex, string language) {this->networkPlayerLanguages[factionIndex]=language;}
this->factionTypeNames[factionIndex]= factionTypeName;
}
void setNetworkPlayerName(int factionIndex,const string& playername) {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
void setFactionControl(int factionIndex, ControlType controller) {this->factionControls[factionIndex]= controller;}
void setResourceMultiplierIndex(int factionIndex, int multiplierIndex) {this->resourceMultiplierIndex[factionIndex]= multiplierIndex;}
this->networkPlayerNames[factionIndex]= playername;
}
void setNetworkPlayerStatuses(int factionIndex,int status) {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
void setThisFactionIndex(int thisFactionIndex) {this->thisFactionIndex= thisFactionIndex;}
this->networkPlayerStatuses[factionIndex]= status;
}
void setNetworkPlayerGameStatus(int factionIndex,int status) {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
this->networkPlayerGameStatus[factionIndex]= status;
}
void setNetworkPlayerLanguages(int factionIndex, string language) {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
this->networkPlayerLanguages[factionIndex]=language;
}
void setFactionControl(int factionIndex, ControlType controller) {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
this->factionControls[factionIndex]= controller;
}
void setResourceMultiplierIndex(int factionIndex, int multiplierIndex) {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
this->resourceMultiplierIndex[factionIndex]= multiplierIndex;
}
void setThisFactionIndex(int thisFactionIndex) {
this->thisFactionIndex= thisFactionIndex;
}
void setFactionCount(int factionCount) {this->factionCount= factionCount;}
void setTeam(int factionIndex, int team) {this->teams[factionIndex]= team;}
void setStartLocationIndex(int factionIndex, int startLocationIndex) {this->startLocationIndex[factionIndex]= startLocationIndex;}
void setTeam(int factionIndex, int team) {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
this->teams[factionIndex]= team;
}
void setStartLocationIndex(int factionIndex, int startLocationIndex) {
if(factionIndex < 0 || factionIndex >= GameConstants::maxPlayers) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s] Invalid factionIndex = %d\n",__FUNCTION__,factionIndex);
throw megaglest_runtime_error(szBuf);
}
this->startLocationIndex[factionIndex]= startLocationIndex;
}
void setMapFilterIndex(int mapFilterIndex) {this->mapFilterIndex=mapFilterIndex;}
void setDefaultUnits(bool defaultUnits) {this->defaultUnits= defaultUnits;}

View File

@ -1550,7 +1550,7 @@ void runTilesetValidationForPath(string tilesetPath, string tilesetName,
printf("foundText = %d\n",foundText);
if(foundText == false) {
char szBuf[4096]="";
sprintf(szBuf,"Error finding text [%s] in file [%s]",searchText.c_str(),parentFile.c_str());
sprintf(szBuf,"Line ref = %d, Error finding text [%s] in file [%s]",__LINE__,searchText.c_str(),parentFile.c_str());
throw megaglest_runtime_error(szBuf);
}
mapUniqueParentList[parentFile]++;
@ -1596,7 +1596,7 @@ void runTilesetValidationForPath(string tilesetPath, string tilesetName,
if(foundText == false) {
char szBuf[8096]="";
sprintf(szBuf,"Error finding text\n[%s]\nin file\n[%s]\nnew Common File [%s]\n",searchText.c_str(),parentFile.c_str(),newCommonFileName.c_str());
sprintf(szBuf,"Line ref = %d, Error finding text\n[%s]\nin file\n[%s]\nnew Common File [%s]\n",__LINE__,searchText.c_str(),parentFile.c_str(),newCommonFileName.c_str());
printf("\n\n=================================================\n%s",szBuf);
throw megaglest_runtime_error(szBuf);
@ -1659,6 +1659,9 @@ void runTechValidationForPath(string techPath, string techName,
//vector<string> pathList = config.getPathListForType(ptTechs,"");
vector<string> pathList;
pathList.push_back(techPath);
Config &config = Config::getInstance();
vector<string> otherTechPaths = config.getPathListForType(ptTechs,"");
pathList.insert(pathList.end(), otherTechPaths.begin(), otherTechPaths.end());
world.loadTech(pathList, techName, factions, &checksum, loadedFileList);
// Fixup paths with ..
@ -1878,7 +1881,7 @@ void runTechValidationForPath(string techPath, string techName,
printf("\nWarning, duplicate files were detected - START:\n=====================\n");
}
printf("----- START duplicate files for CRC [%d] count [%lu] first file is [%s]\n",iterMap->first,fileList.size(),fileList[0].c_str());
printf("----- START duplicate files for CRC [%u] count [%lu] first file is [%s]\n",iterMap->first,fileList.size(),fileList[0].c_str());
map<string,int> parentList;
for(unsigned int idx = 0; idx < fileList.size(); ++idx) {
@ -2048,7 +2051,7 @@ void runTechValidationForPath(string techPath, string techName,
//printf("Error finding text [%s] in file [%s]",searchText.c_str(),parentFile.c_str());
char szBuf[8096]="";
sprintf(szBuf,"Error finding text\n[%s]\nin file\n[%s]\nnew Common File [%s]\n",searchText.c_str(),parentFile.c_str(),newCommonFileName.c_str());
sprintf(szBuf,"Line ref = %d, Error finding text\n[%s]\nin file\n[%s]\nnew Common File [%s]\n",__LINE__,searchText.c_str(),parentFile.c_str(),newCommonFileName.c_str());
printf("\n\n=================================================\n%s",szBuf);
throw megaglest_runtime_error(szBuf);
@ -2115,11 +2118,15 @@ void runTechValidationForPath(string techPath, string techName,
if(foundText == false) {
//printf("Error finding text [%s] in file [%s]",searchText.c_str(),parentFile.c_str());
char szBuf[8096]="";
sprintf(szBuf,"Error finding text\n[%s]\nin file\n[%s]\nnew Common File [%s]\n",searchText.c_str(),parentFile.c_str(),newCommonFileName.c_str());
printf("\n\n=================================================\n%s",szBuf);
// Check if the sound file already references commandata
foundText = searchAndReplaceTextInFile(parentFile, newCommonFileName, newCommonFileName, true);
if(foundText == false) {
char szBuf[8096]="";
sprintf(szBuf,"Line ref = %d, Error finding text\n[%s]\nin file\n[%s]\nnew Common File [%s]\n",__LINE__,searchText.c_str(),parentFile.c_str(),newCommonFileName.c_str());
printf("\n\n=================================================\n%s",szBuf);
throw megaglest_runtime_error(szBuf);
throw megaglest_runtime_error(szBuf);
}
}
}
}

View File

@ -33,6 +33,7 @@ namespace Glest{ namespace Game{
FactionType::FactionType() {
music = NULL;
personalityType = fpt_Normal;
isLinked = false;
}
//load a faction, given a directory
@ -75,6 +76,9 @@ void FactionType::load(const string &factionName, const TechTree *techTree, Chec
const XmlNode *rootNode= xmlTree.getRootNode();
if(rootNode->getName()=="link") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"Faction [%s] is a linked faction\n",name.c_str());
isLinked = true;
const XmlNode *techTreeNode= rootNode->getChild("techtree");
const string linkedTechTreeName=techTreeNode->getAttribute("name")->getRestrictedValue();
// const XmlNode *factionLinkNode= rootNode->getChild("faction");
@ -83,6 +87,8 @@ void FactionType::load(const string &factionName, const TechTree *techTree, Chec
techTreePath=linkedTechTreePath;
endPathWithSlash(techTreePath);
techTreeName=linkedTechTreeName;
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"techTreePath [%s] techTreeName [%s]\n",techTreePath.c_str(),techTreeName.c_str());
}
else {
// stop looking for new path, no more links ...
@ -106,6 +112,8 @@ void FactionType::load(const string &factionName, const TechTree *techTree, Chec
Logger::getInstance().add(szBuf, true);
if(personalityType == fpt_Normal) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"Loading faction [%s] currentPath [%s]\n",path.c_str(),currentPath.c_str());
checksum->addFile(path);
techtreeChecksum->addFile(path);
@ -173,6 +181,9 @@ void FactionType::load(const string &factionName, const TechTree *techTree, Chec
}
string tmppath= currentPath + factionName +".xml";
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"Loading faction xml [%s]\n",tmppath.c_str());
std::map<string,string> mapExtraTagReplacementValues;
mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTreePath + "/commondata/";
//printf("current $COMMONDATAPATH = %s\n",mapExtraTagReplacementValues["$COMMONDATAPATH"].c_str());

View File

@ -94,6 +94,8 @@ private:
std::vector<const UpgradeType*> vctAIBehaviorUpgrades;
std::map<AIBehaviorStaticValueCategory, int > mapAIBehaviorStaticOverrideValues;
bool isLinked;
public:
//init
FactionType();
@ -106,6 +108,7 @@ public:
int getAIBehaviorStaticOverideValue(AIBehaviorStaticValueCategory type) const;
//get
bool getIsLinked() const { return isLinked; }
int getUnitTypeCount() const {return unitTypes.size();}
int getUpgradeTypeCount() const {return upgradeTypes.size();}
string getName() const {return name;}