- fixed to handle duplicate resources in unit requirement costs without crashing
This commit is contained in:
parent
8d3a53235a
commit
89de9f4c8b
|
@ -468,11 +468,11 @@ void Faction::applyDiscount(const ProducibleType *p, int discount)
|
|||
void Faction::applyStaticCosts(const ProducibleType *p) {
|
||||
assert(p != NULL);
|
||||
//decrease static resources
|
||||
for(int i=0; i<p->getCostCount(); ++i) {
|
||||
for(int i=0; i < p->getCostCount(); ++i) {
|
||||
const ResourceType *rt= p->getCost(i)->getType();
|
||||
//assert(rt != NULL);
|
||||
if(rt == NULL) {
|
||||
throw runtime_error("rt == NULL - " + p->getName());
|
||||
throw runtime_error(string(__FUNCTION__) + " rt == NULL for ProducibleType [" + p->getName() + "] index: " + intToStr(i));
|
||||
}
|
||||
if(rt->getClass() == rcStatic) {
|
||||
int cost= p->getCost(i)->getAmount();
|
||||
|
|
|
@ -363,6 +363,9 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree,
|
|||
int amount= resourceNode->getAttribute("amount")->getIntValue();
|
||||
sortedItems[name] = amount;
|
||||
}
|
||||
if(sortedItems.size() < costs.size()) {
|
||||
costs.resize(sortedItems.size());
|
||||
}
|
||||
int index = 0;
|
||||
for(std::map<string,int>::iterator iterMap = sortedItems.begin();
|
||||
iterMap != sortedItems.end(); ++iterMap) {
|
||||
|
@ -380,6 +383,10 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree,
|
|||
int amount= resourceNode->getAttribute("amount")->getIntValue();
|
||||
sortedItems[name] = amount;
|
||||
}
|
||||
if(sortedItems.size() < storedResources.size()) {
|
||||
storedResources.resize(sortedItems.size());
|
||||
}
|
||||
|
||||
index = 0;
|
||||
for(std::map<string,int>::iterator iterMap = sortedItems.begin();
|
||||
iterMap != sortedItems.end(); ++iterMap) {
|
||||
|
|
Loading…
Reference in New Issue