Resource Storage calculated on team basis

fixing a debt-bug with sharedResources:
https://forum.megaglest.org/index.php?topic=9616.0
This commit is contained in:
titison 2015-01-02 02:45:44 +01:00
parent f4529566fa
commit 00d367b725
2 changed files with 47 additions and 21 deletions

View File

@ -1278,14 +1278,29 @@ bool Faction::isAlly(const Faction *faction) {
// ================== misc ================== // ================== misc ==================
void Faction::incResourceAmount(const ResourceType *rt, int amount) { void Faction::incResourceAmount(const ResourceType *rt, int amount) {
for(int i=0; i < (int)resources.size(); ++i) { if (world != NULL && world->getGame() != NULL
Resource *r= &resources[i]; && world->getGame->isFlagType1BitEnabled(
if(r->getType()==rt) { ft1_allow_shared_team_resources) == true) {
r->setAmount(r->getAmount()+amount); for(int i=0; i < (int)resources.size(); ++i) {
if(r->getType()->getClass() != rcStatic && r->getAmount()>getStoreAmount(rt)) { Resource *r= &resources[i];
r->setAmount(getStoreAmount(rt)); if(r->getType()==rt) {
r->setAmount(r->getAmount()+amount);
if(r->getType()->getClass() != rcStatic && (getResource(rt,false)->getAmount()+amount)>getStoreAmount(rt,false)) {
r->setAmount(getStoreAmount(rt,false)-(getResource(rt,false)->getAmount()-r->getAmount()));
}
return;
}
}
} else {
for(int i=0; i < (int)resources.size(); ++i) {
Resource *r= &resources[i];
if(r->getType()==rt) {
r->setAmount(r->getAmount()+amount);
if(r->getType()->getClass() != rcStatic && r->getAmount()>getStoreAmount(rt)) {
r->setAmount(getStoreAmount(rt));
}
return;
} }
return;
} }
} }
assert(false); assert(false);
@ -1374,11 +1389,25 @@ void Faction::removeStore(const UnitType *unitType){
} }
void Faction::limitResourcesToStore() { void Faction::limitResourcesToStore() {
for(int i=0; i < (int)resources.size(); ++i) { if (world != NULL && world->getGame() != NULL
Resource *r= &resources[i]; && world->getGame->isFlagType1BitEnabled(
Resource *s= &store[i]; ft1_allow_shared_team_resources) == true) {
if(r->getType()->getClass() != rcStatic && r->getAmount()>s->getAmount()) { for(int i=0; i < (int)resources.size(); ++i) {
r->setAmount(s->getAmount()); Resource *r= &resources[i];
const ResourceType *rt= r->getType();
if(rt->getClass() != rcStatic && (getResource(rt,false)->getAmount())>getStoreAmount(rt,false)) {
printf("wopm\n");
r->setAmount(getStoreAmount(rt,false)-(getResource(rt,false)->getAmount()-r->getAmount()));
return;
}
}
} else {
for(int i=0; i < (int)resources.size(); ++i) {
Resource *r= &resources[i];
Resource *s= &store[i];
if(r->getType()->getClass() != rcStatic && r->getAmount()>s->getAmount()) {
r->setAmount(s->getAmount());
}
} }
} }
} }

View File

@ -2691,17 +2691,14 @@ const Resource *World::getResourceForTeam(const ResourceType *rt, int teamIndex)
Faction *faction = factions[index]; Faction *faction = factions[index];
if(faction != NULL && faction->getTeam() == teamIndex) { if(faction != NULL && faction->getTeam() == teamIndex) {
const Resource *factionResource = faction->getResource(rt,true);
if(factionResource != NULL && factionResource->getType() != NULL) {
if(faction->hasAliveUnits(true,true)) { int teamResourceAmount = teamResource.getAmount();
const Resource *factionResource = faction->getResource(rt,true); int teamResourceBalance = teamResource.getBalance();
if(factionResource != NULL && factionResource->getType() != NULL) {
int teamResourceAmount = teamResource.getAmount(); teamResource.setAmount(teamResourceAmount + factionResource->getAmount());
int teamResourceBalance = teamResource.getBalance(); teamResource.setBalance(teamResourceBalance + factionResource->getBalance());
teamResource.setAmount(teamResourceAmount + factionResource->getAmount());
teamResource.setBalance(teamResourceBalance + factionResource->getBalance());
}
} }
} }
} }