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 ==================
void Faction::incResourceAmount(const ResourceType *rt, int amount) {
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));
if (world != NULL && world->getGame() != NULL
&& world->getGame->isFlagType1BitEnabled(
ft1_allow_shared_team_resources) == true) {
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 && (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);
@ -1374,11 +1389,25 @@ void Faction::removeStore(const UnitType *unitType){
}
void Faction::limitResourcesToStore() {
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());
if (world != NULL && world->getGame() != NULL
&& world->getGame->isFlagType1BitEnabled(
ft1_allow_shared_team_resources) == true) {
for(int i=0; i < (int)resources.size(); ++i) {
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];
if(faction != NULL && faction->getTeam() == teamIndex) {
const Resource *factionResource = faction->getResource(rt,true);
if(factionResource != NULL && factionResource->getType() != NULL) {
if(faction->hasAliveUnits(true,true)) {
const Resource *factionResource = faction->getResource(rt,true);
if(factionResource != NULL && factionResource->getType() != NULL) {
int teamResourceAmount = teamResource.getAmount();
int teamResourceBalance = teamResource.getBalance();
int teamResourceAmount = teamResource.getAmount();
int teamResourceBalance = teamResource.getBalance();
teamResource.setAmount(teamResourceAmount + factionResource->getAmount());
teamResource.setBalance(teamResourceBalance + factionResource->getBalance());
}
teamResource.setAmount(teamResourceAmount + factionResource->getAmount());
teamResource.setBalance(teamResourceBalance + factionResource->getBalance());
}
}
}