diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index dc560443..3af11949 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -665,12 +665,14 @@ bool Faction::applyCosts(const ProducibleType *p){ if(r == NULL) { char szBuf[1024]=""; sprintf(szBuf,"cannot apply costs for p [%s] %d of %d costs resource is null",p->getName().c_str(),i,p->getCostCount()); + throw runtime_error(szBuf); } const ResourceType *rt= r->getType(); if(rt == NULL) { char szBuf[1024]=""; sprintf(szBuf,"cannot apply costs for p [%s] %d of %d costs resourcetype [%s] is null",p->getName().c_str(),i,p->getCostCount(),r->getDescription().c_str()); + throw runtime_error(szBuf); } int cost= r->getAmount(); if((cost > 0 || (rt->getClass() != rcStatic)) && rt->getClass() != rcConsumable) diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 43cdac05..8659e800 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -347,31 +347,52 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, std::map sortedItems; //unit requirements + bool hasDup = false; const XmlNode *unitRequirementsNode= parametersNode->getChild("unit-requirements"); for(int i=0; igetChildCount(); ++i){ const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i); string name= unitNode->getAttribute("name")->getRestrictedValue(); + + if(sortedItems.find(name) != sortedItems.end()) { + hasDup = true; + } + sortedItems[name] = 0; } + if(hasDup) { + printf("WARNING, unit type [%s] has one or more duplicate unit requirements\n",this->getName().c_str()); + } + for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { unitReqs.push_back(factionType->getUnitType(iterMap->first)); } sortedItems.clear(); - + hasDup = false; //upgrade requirements const XmlNode *upgradeRequirementsNode= parametersNode->getChild("upgrade-requirements"); for(int i=0; igetChildCount(); ++i){ const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i); string name= upgradeReqNode->getAttribute("name")->getRestrictedValue(); + + if(sortedItems.find(name) != sortedItems.end()) { + hasDup = true; + } + sortedItems[name] = 0; } + + if(hasDup) { + printf("WARNING, unit type [%s] has one or more duplicate upgrade requirements\n",this->getName().c_str()); + } + for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { upgradeReqs.push_back(factionType->getUpgradeType(iterMap->first)); } sortedItems.clear(); + hasDup = false; //resource requirements const XmlNode *resourceRequirementsNode= parametersNode->getChild("resource-requirements"); @@ -380,8 +401,18 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const XmlNode *resourceNode= resourceRequirementsNode->getChild("resource", i); string name= resourceNode->getAttribute("name")->getRestrictedValue(); int amount= resourceNode->getAttribute("amount")->getIntValue(); + + if(sortedItems.find(name) != sortedItems.end()) { + hasDup = true; + } sortedItems[name] = amount; } + //if(hasDup || sortedItems.size() != costs.size()) printf("Found duplicate resource requirement, costs.size() = %d sortedItems.size() = %d\n",costs.size(),sortedItems.size()); + + if(hasDup) { + printf("WARNING, unit type [%s] has one or more duplicate resource requirements\n",this->getName().c_str()); + } + if(sortedItems.size() < costs.size()) { costs.resize(sortedItems.size()); } @@ -392,6 +423,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, index++; } sortedItems.clear(); + hasDup = false; //resources stored const XmlNode *resourcesStoredNode= parametersNode->getChild("resources-stored"); @@ -400,8 +432,18 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const XmlNode *resourceNode= resourcesStoredNode->getChild("resource", i); string name= resourceNode->getAttribute("name")->getRestrictedValue(); int amount= resourceNode->getAttribute("amount")->getIntValue(); + + if(sortedItems.find(name) != sortedItems.end()) { + hasDup = true; + } + sortedItems[name] = amount; } + + if(hasDup) { + printf("WARNING, unit type [%s] has one or more duplicate stored resources\n",this->getName().c_str()); + } + if(sortedItems.size() < storedResources.size()) { storedResources.resize(sortedItems.size()); } diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index 08dc0c6d..dd5f2f11 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -258,41 +258,81 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, std::map sortedItems; //unit requirements + bool hasDup = false; const XmlNode *unitRequirementsNode= upgradeNode->getChild("unit-requirements"); for(int i = 0; i < unitRequirementsNode->getChildCount(); ++i) { const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i); string name= unitNode->getAttribute("name")->getRestrictedValue(); + + if(sortedItems.find(name) != sortedItems.end()) { + hasDup = true; + } + sortedItems[name] = 0; } + + if(hasDup) { + printf("WARNING, upgrade type [%s] has one or more duplicate unit requirements\n",this->getName().c_str()); + } + for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { unitReqs.push_back(factionType->getUnitType(iterMap->first)); } sortedItems.clear(); + hasDup = false; //upgrade requirements const XmlNode *upgradeRequirementsNode= upgradeNode->getChild("upgrade-requirements"); for(int i = 0; i < upgradeRequirementsNode->getChildCount(); ++i) { const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i); string name= upgradeReqNode->getAttribute("name")->getRestrictedValue(); + + if(sortedItems.find(name) != sortedItems.end()) { + hasDup = true; + } + sortedItems[name] = 0; } + + if(hasDup) { + printf("WARNING, upgrade type [%s] has one or more duplicate upgrade requirements\n",this->getName().c_str()); + } + for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { upgradeReqs.push_back(factionType->getUpgradeType(iterMap->first)); } sortedItems.clear(); + hasDup = false; //resource requirements int index = 0; const XmlNode *resourceRequirementsNode= upgradeNode->getChild("resource-requirements"); + hasDup = false; costs.resize(resourceRequirementsNode->getChildCount()); for(int i = 0; i < costs.size(); ++i) { const XmlNode *resourceNode= resourceRequirementsNode->getChild("resource", i); string name= resourceNode->getAttribute("name")->getRestrictedValue(); int amount= resourceNode->getAttribute("amount")->getIntValue(); + + if(sortedItems.find(name) != sortedItems.end()) { + hasDup = true; + } + sortedItems[name] = amount; } + + //if(hasDup || sortedItems.size() != costs.size()) printf("Found duplicate resource requirement, costs.size() = %d sortedItems.size() = %d\n",costs.size(),sortedItems.size()); + + if(hasDup) { + printf("WARNING, upgrade type [%s] has one or more duplicate resource requirements\n",this->getName().c_str()); + } + + if(sortedItems.size() < costs.size()) { + costs.resize(sortedItems.size()); + } + index = 0; for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { @@ -300,14 +340,25 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, index++; } sortedItems.clear(); + hasDup = false; //effects const XmlNode *effectsNode= upgradeNode->getChild("effects"); for(int i = 0; i < effectsNode->getChildCount(); ++i) { const XmlNode *unitNode= effectsNode->getChild("unit", i); string name= unitNode->getAttribute("name")->getRestrictedValue(); + + if(sortedItems.find(name) != sortedItems.end()) { + hasDup = true; + } + sortedItems[name] = 0; } + + if(hasDup) { + printf("WARNING, upgrade type [%s] has one or more duplicate effects\n",this->getName().c_str()); + } + for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { effects.push_back(factionType->getUnitType(iterMap->first));