From 00d367b725ac318fc405f71fdb69b30f7a2c1259 Mon Sep 17 00:00:00 2001 From: titison Date: Fri, 2 Jan 2015 02:45:44 +0100 Subject: [PATCH] Resource Storage calculated on team basis fixing a debt-bug with sharedResources: https://forum.megaglest.org/index.php?topic=9616.0 --- source/glest_game/type_instances/faction.cpp | 53 +++++++++++++++----- source/glest_game/world/world.cpp | 15 +++--- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index 7f95d31a..289a7561 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -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()); + } } } } diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 86521e8b..a6e7db50 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -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()); } } }