- added ability to share resources across same teams

This commit is contained in:
SoftCoder 2014-01-27 18:55:08 -08:00
parent e33024c102
commit 39696b6a65
11 changed files with 243 additions and 70 deletions

View File

@ -1594,10 +1594,10 @@ void Game::init(bool initForPreviewOnly) {
printf("New game has started...\n"); printf("New game has started...\n");
} }
if(isFlagType1BitEnabled(gameSettings.getFlagTypes1(),ft1_network_synch_checks_verbose) == true) { if(isFlagType1BitEnabled(ft1_network_synch_checks_verbose) == true) {
printf("*Note: Monitoring Network CRC VERBOSE synchronization...\n"); printf("*Note: Monitoring Network CRC VERBOSE synchronization...\n");
} }
else if(isFlagType1BitEnabled(gameSettings.getFlagTypes1(),ft1_network_synch_checks) == true) { else if(isFlagType1BitEnabled(ft1_network_synch_checks) == true) {
printf("*Note: Monitoring Network CRC NORMAL synchronization...\n"); printf("*Note: Monitoring Network CRC NORMAL synchronization...\n");
} }
@ -1735,8 +1735,8 @@ void Game::processNetworkSynchChecksIfRequired() {
if(settings != NULL) { if(settings != NULL) {
bool calculateNetworkCRC = false; bool calculateNetworkCRC = false;
if(isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks) == true || if(isFlagType1BitEnabled(ft1_network_synch_checks) == true ||
isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks_verbose) == true) { isFlagType1BitEnabled(ft1_network_synch_checks_verbose) == true) {
calculateNetworkCRC = true; calculateNetworkCRC = true;
} }
@ -1751,10 +1751,10 @@ void Game::processNetworkSynchChecksIfRequired() {
netIntf->setNetworkPlayerFactionCRC(index,faction->getCRC().getSum()); netIntf->setNetworkPlayerFactionCRC(index,faction->getCRC().getSum());
if(settings != NULL) { if(settings != NULL) {
if(isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks_verbose) == true) { if(isFlagType1BitEnabled(ft1_network_synch_checks_verbose) == true) {
faction->addCRC_DetailsForWorldFrame(world.getFrameCount(),role == nrServer); faction->addCRC_DetailsForWorldFrame(world.getFrameCount(),role == nrServer);
} }
else if(isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks) == true && else if(isFlagType1BitEnabled(ft1_network_synch_checks) == true &&
world.getFrameCount() % 20 == 0) { world.getFrameCount() % 20 == 0) {
faction->addCRC_DetailsForWorldFrame(world.getFrameCount(),role == nrServer); faction->addCRC_DetailsForWorldFrame(world.getFrameCount(),role == nrServer);
} }
@ -5057,8 +5057,8 @@ void Game::DumpCRCWorldLogIfRequired(string fileSuffix) {
GameSettings *settings = world.getGameSettingsPtr(); GameSettings *settings = world.getGameSettingsPtr();
if(settings != NULL && if(settings != NULL &&
(isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks_verbose) == true || (isFlagType1BitEnabled(ft1_network_synch_checks_verbose) == true ||
isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks) == true)) { isFlagType1BitEnabled(ft1_network_synch_checks) == true)) {
string debugCRCWorldLogFile = Config::getInstance().getString("DebugCRCWorldLogFile","debugCRCWorld.log"); string debugCRCWorldLogFile = Config::getInstance().getString("DebugCRCWorldLogFile","debugCRCWorld.log");
debugCRCWorldLogFile += fileSuffix; debugCRCWorldLogFile += fileSuffix;
@ -5796,7 +5796,7 @@ void Game::checkWinnerStandardPlayer() {
bool playerLostGame = true; bool playerLostGame = true;
// Team Shared units enabled? // Team Shared units enabled?
if(isFlagType1BitEnabled(this->gameSettings.getFlagTypes1(),ft1_allow_shared_team_units) == true) { if(isFlagType1BitEnabled(ft1_allow_shared_team_units) == true) {
// Check if all team members have lost? // Check if all team members have lost?
for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) { for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) {
@ -5956,6 +5956,10 @@ void Game::checkWinnerScripted() {
} }
} }
bool Game::isFlagType1BitEnabled(FlagTypes1 type) const {
return ((gameSettings.getFlagTypes1() & (uint32)type) == (uint32)type);
}
bool Game::factionLostGame(int factionIndex) { bool Game::factionLostGame(int factionIndex) {
return factionLostGame(world.getFaction(factionIndex)); return factionLostGame(world.getFaction(factionIndex));
} }

View File

@ -224,6 +224,7 @@ public:
~Game(); ~Game();
void reInitGUI(); void reInitGUI();
bool isFlagType1BitEnabled(FlagTypes1 type) const;
bool isMarkCellMode() const { return isMarkCellEnabled; } bool isMarkCellMode() const { return isMarkCellEnabled; }
const Texture2D * getMarkCellTexture() const { return markCellTexture; } const Texture2D * getMarkCellTexture() const { return markCellTexture; }

View File

@ -2339,40 +2339,66 @@ void Renderer::renderResourceStatus() {
return; return;
} }
const Metrics &metrics= Metrics::getInstance(); const Metrics &metrics = Metrics::getInstance();
const World *world= game->getWorld(); const World *world = game->getWorld();
if(world->getThisFactionIndex() < 0 || world->getThisFactionIndex() >= world->getFactionCount()) { if(world->getThisFactionIndex() < 0 ||
world->getThisFactionIndex() >= world->getFactionCount()) {
return; return;
} }
const Faction *thisFaction= world->getFaction(world->getThisFactionIndex()); const Faction *thisFaction = world->getFaction(world->getThisFactionIndex());
const Vec4f fontColor = game->getGui()->getDisplay()->getColor(); const Vec4f fontColor = game->getGui()->getDisplay()->getColor();
assertGl(); assertGl();
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
int resourceCountRendered = 0; int resourceCountRendered = 0;
for(int i= 0; i < world->getTechTree()->getResourceTypeCount(); ++i) { for(int techTreeResourceTypeIndex = 0;
const ResourceType *rt = world->getTechTree()->getResourceType(i); techTreeResourceTypeIndex < world->getTechTree()->getResourceTypeCount();
const Resource *r = thisFaction->getResource(rt); ++techTreeResourceTypeIndex) {
if ( rt->getDisplayInHud() == false ){ const ResourceType *rt = world->getTechTree()->getResourceType(techTreeResourceTypeIndex);
if ( rt->getDisplayInHud() == false ) {
continue; continue;
} }
//if any unit produces the resource
bool showResource= false; const Faction *factionForResourceView = thisFaction;
for(int k=0; k < thisFaction->getType()->getUnitTypeCount(); ++k) { bool localFactionResourcesOnly = false;
const UnitType *ut = thisFaction->getType()->getUnitType(k);
if(ut->getCost(rt) != NULL) { if(game != NULL && game->getGui() != NULL) {
showResource = true;
break; if(game->isFlagType1BitEnabled(ft1_allow_shared_team_units) == true ||
game->isFlagType1BitEnabled(ft1_allow_shared_team_resources) == true) {
const Gui *gui = game->getGui();
if(gui != NULL) {
const Selection *selection = gui->getSelection();
if(selection != NULL && selection->getCount() > 0 && selection->getFrontUnit() != NULL) {
const Unit *selectedUnit = selection->getFrontUnit();
if(selectedUnit != NULL && selectedUnit->getType()->hasSkillClass(scBeBuilt) == true) {
if(selectedUnit->getFactionIndex() == thisFaction->getIndex() ||
selectedUnit->getFaction()->isAlly(thisFaction) == true) {
factionForResourceView = selectedUnit->getFaction();
localFactionResourcesOnly = true;
}
}
}
}
} }
} }
//if any unit produces the resource
bool showResource = world->showResourceTypeForFaction(rt, factionForResourceView, localFactionResourcesOnly);
//draw resource status //draw resource status
if(showResource) { if(showResource == true) {
string str= intToStr(r->getAmount()); const Resource *r = factionForResourceView->getResource(rt,localFactionResourcesOnly);
string str = intToStr(r->getAmount());
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
@ -2381,18 +2407,22 @@ void Renderer::renderResourceStatus() {
bool isNegativeConsumableDisplayCycle = false; bool isNegativeConsumableDisplayCycle = false;
if(rt->getClass() == rcConsumable) { if(rt->getClass() == rcConsumable) {
// Show in yellow/orange/red font if negative // Show in yellow/orange/red font if negative
if(r->getBalance()*5+r->getAmount()<0){ if(r->getBalance() * 5 + r->getAmount() < 0) {
if(time(NULL) % 2 == 0) { if(time(NULL) % 2 == 0) {
isNegativeConsumableDisplayCycle = true; isNegativeConsumableDisplayCycle = true;
if(r->getBalance()*1+r->getAmount()<0){ if(r->getBalance() * 1 + r->getAmount() < 0) {
glColor3f(RED.x,RED.y,RED.z); glColor3f(RED.x,RED.y,RED.z);
resourceFontColor = RED; resourceFontColor = RED;
} }
else if(r->getBalance()*3+r->getAmount()<0){ else if(r->getBalance() * 3 + r->getAmount() < 0) {
glColor3f(ORANGE.x,ORANGE.y,ORANGE.z); glColor3f(ORANGE.x,ORANGE.y,ORANGE.z);
resourceFontColor = ORANGE; resourceFontColor = ORANGE;
} }
else if(r->getBalance()*5+r->getAmount()<0){ else if(r->getBalance() * 5 + r->getAmount() < 0) {
glColor3f(YELLOW.x,YELLOW.y,YELLOW.z); glColor3f(YELLOW.x,YELLOW.y,YELLOW.z);
resourceFontColor = YELLOW; resourceFontColor = YELLOW;
} }
@ -2406,11 +2436,11 @@ void Renderer::renderResourceStatus() {
const int MAX_RESOURCES_PER_ROW = 6; const int MAX_RESOURCES_PER_ROW = 6;
int resourceRow = (resourceCountRendered > 0 ? resourceCountRendered / MAX_RESOURCES_PER_ROW : 0); int resourceRow = (resourceCountRendered > 0 ? resourceCountRendered / MAX_RESOURCES_PER_ROW : 0);
int resourceCol = resourceCountRendered % MAX_RESOURCES_PER_ROW; int resourceCol = resourceCountRendered % MAX_RESOURCES_PER_ROW;
//renderQuad(resourceCountRendered*100+200, metrics.getVirtualH()-30 - (30 * resourceRows), 16, 16, rt->getImage());
renderQuad(resourceCol * 100 + 200, metrics.getVirtualH()-30 - (30 * resourceRow), 16, 16, rt->getImage()); renderQuad(resourceCol * 100 + 200, metrics.getVirtualH()-30 - (30 * resourceRow), 16, 16, rt->getImage());
if(rt->getClass() != rcStatic) { if(rt->getClass() != rcStatic) {
str+= "/" + intToStr(thisFaction->getStoreAmount(rt)); str+= "/" + intToStr(factionForResourceView->getStoreAmount(rt,localFactionResourcesOnly));
} }
if(rt->getClass() == rcConsumable) { if(rt->getClass() == rcConsumable) {
str+= "("; str+= "(";

View File

@ -135,7 +135,7 @@ void Gui::init(Game *game) {
selection.init(this, selection.init(this,
world->getThisFactionIndex(), world->getThisFactionIndex(),
world->getThisTeamIndex(), world->getThisTeamIndex(),
isFlagType1BitEnabled(game->getGameSettings()->getFlagTypes1(),ft1_allow_shared_team_units)); game->isFlagType1BitEnabled(ft1_allow_shared_team_units));
} }
void Gui::end(){ void Gui::end(){

View File

@ -329,7 +329,7 @@ void Selection::loadGame(const XmlNode *rootNode, World *world) {
factionIndex = selectionNode->getAttribute("factionIndex")->getIntValue(); factionIndex = selectionNode->getAttribute("factionIndex")->getIntValue();
teamIndex = selectionNode->getAttribute("teamIndex")->getIntValue(); teamIndex = selectionNode->getAttribute("teamIndex")->getIntValue();
if(selectionNode->hasAttribute("allowSharedTeamUnits") == true) { if(selectionNode->hasAttribute("allowSharedTeamUnits") == true) {
allowSharedTeamUnits = selectionNode->getAttribute("allowSharedTeamUnits")->getIntValue(); allowSharedTeamUnits = (selectionNode->getAttribute("allowSharedTeamUnits")->getIntValue() != 0);
} }
vector<XmlNode *> selectedUnitsNodeList = selectionNode->getChildList("selectedUnits"); vector<XmlNode *> selectedUnitsNodeList = selectionNode->getChildList("selectedUnits");

View File

@ -1702,21 +1702,6 @@ void ServerInterface::updateKeyframe(int frameCount) {
// We always need to broadcast when not pause as clients // We always need to broadcast when not pause as clients
// look for broadcasts every network frame. // look for broadcasts every network frame.
sendBroadcastMessage = true; sendBroadcastMessage = true;
// If network CRC checking enabled we turn on broadcasting always
// bool calculateNetworkCRC = false;
// if(isFlagType1BitEnabled(this->gameSettings.getFlagTypes1(),ft1_network_synch_checks) == true ||
// isFlagType1BitEnabled(this->gameSettings.getFlagTypes1(),ft1_network_synch_checks_verbose) == true) {
//
// calculateNetworkCRC = true;
// }
//
// if(calculateNetworkCRC == true ||
// (lastBroadcastCommandsTimer.isStarted() == false ||
// lastBroadcastCommandsTimer.getMillis() >= MAX_EMPTY_NETWORK_COMMAND_LIST_BROADCAST_INTERVAL_MILLISECONDS)) {
//
// sendBroadcastMessage = true;
// }
} }
// Auto pause is enabled due to client lagging, only send empty command // Auto pause is enabled due to client lagging, only send empty command
// broadcasts every MAX_EMPTY_NETWORK_COMMAND_LIST_BROADCAST_INTERVAL_MILLISECONDS // broadcasts every MAX_EMPTY_NETWORK_COMMAND_LIST_BROADCAST_INTERVAL_MILLISECONDS

View File

@ -710,11 +710,14 @@ void Faction::init(
store.resize(techTree->getResourceTypeCount()); store.resize(techTree->getResourceTypeCount());
if(loadWorldNode == NULL) { if(loadWorldNode == NULL) {
for(int i=0; i<techTree->getResourceTypeCount(); ++i){ for(int index = 0; index < techTree->getResourceTypeCount(); ++index) {
const ResourceType *rt= techTree->getResourceType(i); const ResourceType *rt = techTree->getResourceType(index);
int resourceAmount= giveResources? factionType->getStartingResourceAmount(rt): 0; int resourceAmount = giveResources ? factionType->getStartingResourceAmount(rt): 0;
resources[i].init(rt, resourceAmount); resources[index].init(rt, resourceAmount);
store[i].init(rt, 0); store[index].init(rt, 0);
this->world->initTeamResource(rt,this->teamIndex,0);
this->updateUnitTypeWithResourceCostCache(rt);
} }
} }
@ -730,8 +733,6 @@ void Faction::init(
} }
if( game->getGameSettings()->getPathFinderType() == pfBasic) { if( game->getGameSettings()->getPathFinderType() == pfBasic) {
// if( game->getGameSettings()->getPathFinderType() == pfBasic &&
// Config::getInstance().getBool("EnableFactionWorkerThreads","true") == true) {
if(workerThread != NULL) { if(workerThread != NULL) {
workerThread->signalQuit(); workerThread->signalQuit();
if(workerThread->shutdownAndWait() == true) { if(workerThread->shutdownAndWait() == true) {
@ -750,12 +751,54 @@ void Faction::init(
// ================== get ================== // ================== get ==================
const Resource *Faction::getResource(const ResourceType *rt) const{ bool Faction::hasUnitTypeWithResourceCostInCache(const ResourceType *rt) const {
for(int i = 0; i < (int)resources.size(); ++i){ std::string resourceTypeName = rt->getName(false);
if(rt==resources[i].getType()){ std::map<std::string, bool>::const_iterator iterFind = resourceTypeCostCache.find(resourceTypeName);
return &resources[i]; if(iterFind != resourceTypeCostCache.end()) {
return iterFind->second;
}
return false;
}
void Faction::updateUnitTypeWithResourceCostCache(const ResourceType *rt) {
std::string resourceTypeName = rt->getName(false);
if(resourceTypeCostCache.find(resourceTypeName) == resourceTypeCostCache.end()) {
resourceTypeCostCache[resourceTypeName] = hasUnitTypeWithResouceCost(rt);
}
}
bool Faction::hasUnitTypeWithResouceCost(const ResourceType *rt) {
for(int factionUnitTypeIndex = 0;
factionUnitTypeIndex < getType()->getUnitTypeCount();
++factionUnitTypeIndex) {
const UnitType *ut = getType()->getUnitType(factionUnitTypeIndex);
if(ut->getCost(rt) != NULL) {
return true;
break;
} }
} }
return false;
}
const Resource *Faction::getResource(const ResourceType *rt,bool localFactionOnly) const {
if(localFactionOnly == false &&
world != NULL &&
world->getGame() != NULL) {
Game *game = world->getGame();
if(game->isFlagType1BitEnabled(ft1_allow_shared_team_resources) == true) {
return world->getResourceForTeam(rt, this->getTeam());
}
}
for(int index = 0; index < (int)resources.size(); ++index) {
if(rt == resources[index].getType()) {
return &resources[index];
}
}
printf("ERROR cannot find resource type [%s] in list:\n",(rt != NULL ? rt->getName().c_str() : "null")); printf("ERROR cannot find resource type [%s] in list:\n",(rt != NULL ? rt->getName().c_str() : "null"));
for(int i=0; i < (int)resources.size(); ++i){ for(int i=0; i < (int)resources.size(); ++i){
printf("Index %d [%s]",i,resources[i].getType()->getName().c_str()); printf("Index %d [%s]",i,resources[i].getType()->getName().c_str());
@ -765,10 +808,21 @@ const Resource *Faction::getResource(const ResourceType *rt) const{
return NULL; return NULL;
} }
int Faction::getStoreAmount(const ResourceType *rt) const{ int Faction::getStoreAmount(const ResourceType *rt,bool localFactionOnly) const {
for(int i=0; i < (int)store.size(); ++i){
if(rt==store[i].getType()){ if(localFactionOnly == false &&
return store[i].getAmount(); world != NULL &&
world->getGame() != NULL) {
Game *game = world->getGame();
if(game->isFlagType1BitEnabled(ft1_allow_shared_team_resources) == true) {
return world->getStoreAmountForTeam(rt, this->getTeam());
}
}
for(int index =0 ; index < (int)store.size(); ++index) {
if(rt == store[index].getType()) {
return store[index].getAmount();
} }
} }
printf("ERROR cannot find store type [%s] in list:\n",(rt != NULL ? rt->getName().c_str() : "null")); printf("ERROR cannot find store type [%s] in list:\n",(rt != NULL ? rt->getName().c_str() : "null"));

View File

@ -167,6 +167,7 @@ private:
std::map<int,SwitchTeamVote> switchTeamVotes; std::map<int,SwitchTeamVote> switchTeamVotes;
int currentSwitchTeamVoteFactionIndex; int currentSwitchTeamVoteFactionIndex;
bool allowSharedTeamUnits;
set<int> livingUnits; set<int> livingUnits;
set<Unit*> livingUnitsp; set<Unit*> livingUnitsp;
@ -184,6 +185,8 @@ private:
std::map<int,const Unit *> mobileUnitListCache; std::map<int,const Unit *> mobileUnitListCache;
std::map<int,const Unit *> beingBuiltUnitListCache; std::map<int,const Unit *> beingBuiltUnitListCache;
std::map<std::string, bool> resourceTypeCostCache;
public: public:
Faction(); Faction();
~Faction(); ~Faction();
@ -251,9 +254,9 @@ public:
void setFactionDisconnectHandled(bool value) { factionDisconnectHandled=value;} void setFactionDisconnectHandled(bool value) { factionDisconnectHandled=value;}
//get //get
const Resource *getResource(const ResourceType *rt) const; const Resource *getResource(const ResourceType *rt,bool localFactionOnly=false) const;
inline const Resource *getResource(int i) const {return &resources[i];} inline const Resource *getResource(int i) const {return &resources[i];}
int getStoreAmount(const ResourceType *rt) const; int getStoreAmount(const ResourceType *rt,bool localFactionOnly=false) const;
inline const FactionType *getType() const {return factionType;} inline const FactionType *getType() const {return factionType;}
inline int getIndex() const {return index;} inline int getIndex() const {return index;}
@ -375,9 +378,13 @@ public:
string getCRC_DetailsForWorldFrames() const; string getCRC_DetailsForWorldFrames() const;
uint64 getCRC_DetailsForWorldFrameCount() const; uint64 getCRC_DetailsForWorldFrameCount() const;
void updateUnitTypeWithResourceCostCache(const ResourceType *rt);
bool hasUnitTypeWithResourceCostInCache(const ResourceType *rt) const;
private: private:
void init(); void init();
void resetResourceAmount(const ResourceType *rt); void resetResourceAmount(const ResourceType *rt);
bool hasUnitTypeWithResouceCost(const ResourceType *rt);
}; };
}}//end namespace }}//end namespace

View File

@ -753,11 +753,11 @@ void Unit::dumpMemoryList() {
bool Unit::isNetworkCRCEnabled() { bool Unit::isNetworkCRCEnabled() {
bool isNetworkCRCEnabled = false; bool isNetworkCRCEnabled = false;
if(game != NULL && game->getGameSettings() != NULL) { if(game != NULL) {
if(isFlagType1BitEnabled(game->getGameSettings()->getFlagTypes1(),ft1_network_synch_checks_verbose) == true) { if(game->isFlagType1BitEnabled(ft1_network_synch_checks_verbose) == true) {
isNetworkCRCEnabled = true; isNetworkCRCEnabled = true;
} }
else if(isFlagType1BitEnabled(game->getGameSettings()->getFlagTypes1(),ft1_network_synch_checks) == true) { else if(game->isFlagType1BitEnabled(ft1_network_synch_checks) == true) {
isNetworkCRCEnabled = true; isNetworkCRCEnabled = true;
} }
} }

View File

@ -1033,6 +1033,7 @@ void World::tick() {
//if consumable //if consumable
if(rt != NULL && rt->getClass() == rcConsumable) { if(rt != NULL && rt->getClass() == rcConsumable) {
int balance= 0; int balance= 0;
for(int unitIndex = 0; for(int unitIndex = 0;
unitIndex < faction->getUnitCount(); ++unitIndex) { unitIndex < faction->getUnitCount(); ++unitIndex) {
@ -1040,11 +1041,13 @@ void World::tick() {
//if unit operative and has this cost //if unit operative and has this cost
const Unit *unit = faction->getUnit(unitIndex); const Unit *unit = faction->getUnit(unitIndex);
if(unit != NULL && unit->isOperative()) { if(unit != NULL && unit->isOperative()) {
const UnitType *ut = unit->getType(); const UnitType *ut = unit->getType();
const Resource *resource = NULL; const Resource *resource = NULL;
std::map<const UnitType *, std::map<const ResourceType *, const Resource *> >::iterator iterFind = resourceCostCache.find(ut); std::map<const UnitType *, std::map<const ResourceType *, const Resource *> >::iterator iterFind = resourceCostCache.find(ut);
if(iterFind != resourceCostCache.end() && if(iterFind != resourceCostCache.end() &&
iterFind->second.find(rt) != iterFind->second.end()) { iterFind->second.find(rt) != iterFind->second.end()) {
resource = iterFind->second.find(rt)->second; resource = iterFind->second.find(rt)->second;
} }
else { else {
@ -2656,6 +2659,87 @@ void World::stopAllVideo() {
this->game->stopAllVideo(); this->game->stopAllVideo();
} }
void World::initTeamResource(const ResourceType *rt,int teamIndex, int value) {
std::string resourceTypeName = rt->getName(false);
TeamResources[teamIndex][resourceTypeName].init(rt,value);
}
const Resource *World::getResourceForTeam(const ResourceType *rt, int teamIndex) {
if(rt == NULL) {
return NULL;
}
std::map<std::string, Resource> &resourceList = TeamResources[teamIndex];
std::string resourceTypeName = rt->getName(false);
resourceList[resourceTypeName].init(rt,0);
Resource &teamResource = resourceList[resourceTypeName];
for(int index = 0; index < (int)factions.size(); ++index) {
Faction *faction = factions[index];
if(faction != NULL && faction->getTeam() == teamIndex) {
const Resource *factionResource = faction->getResource(rt,true);
if(factionResource != NULL && factionResource->getType() != NULL) {
int teamResourceAmount = teamResource.getAmount();
int teamResourceBalance = teamResource.getBalance();
teamResource.setAmount(teamResourceAmount + factionResource->getAmount());
teamResource.setBalance(teamResourceBalance + factionResource->getBalance());
}
}
}
return &teamResource;
}
int World::getStoreAmountForTeam(const ResourceType *rt, int teamIndex) const {
int teamStoreAmount = 0;
for(int index = 0; index < (int)factions.size(); ++index) {
Faction *faction = factions[index];
if(faction != NULL && faction->getTeam() == teamIndex) {
teamStoreAmount += faction->getStoreAmount(rt,true);
}
}
return teamStoreAmount;
}
bool World::showResourceTypeForFaction(const ResourceType *rt, const Faction *faction,bool localFactionOnly) const {
//if any unit produces the resource
bool showResource = false;
for(int factionUnitTypeIndex = 0;
factionUnitTypeIndex < faction->getType()->getUnitTypeCount();
++factionUnitTypeIndex) {
const UnitType *ut = faction->getType()->getUnitType(factionUnitTypeIndex);
if(ut->getCost(rt) != NULL) {
showResource = true;
break;
}
}
if(localFactionOnly == false && showResource == false &&
(game->isFlagType1BitEnabled(ft1_allow_shared_team_units) == true ||
game->isFlagType1BitEnabled(ft1_allow_shared_team_resources) == true)) {
for(int index = 0; showResource == false && index < (int)factions.size(); ++index) {
const Faction *teamFaction = factions[index];
if(teamFaction != NULL && teamFaction->getTeam() == faction->getTeam()) {
if(teamFaction->hasUnitTypeWithResourceCostInCache(rt) == true) {
showResource = true;
}
}
}
}
return showResource;
}
void World::removeResourceTargetFromCache(const Vec2i &pos) { void World::removeResourceTargetFromCache(const Vec2i &pos) {
for(int i= 0; i < (int)factions.size(); ++i) { for(int i= 0; i < (int)factions.size(); ++i) {
factions[i]->removeResourceTargetFromCache(pos); factions[i]->removeResourceTargetFromCache(pos);

View File

@ -142,6 +142,8 @@ private:
bool cacheFowAlphaTexture; bool cacheFowAlphaTexture;
bool cacheFowAlphaTextureFogOfWarValue; bool cacheFowAlphaTextureFogOfWarValue;
std::map<int, std::map<std::string, Resource > > TeamResources;
public: public:
World(); World();
~World(); ~World();
@ -317,6 +319,12 @@ public:
void refreshAllUnitExplorations(); void refreshAllUnitExplorations();
bool factionLostGame(int factionIndex); bool factionLostGame(int factionIndex);
void initTeamResource(const ResourceType *rt,int teamIndex, int value);
const Resource * getResourceForTeam(const ResourceType *rt, int teamIndex);
int getStoreAmountForTeam(const ResourceType *rt, int teamIndex) const;
bool showResourceTypeForFaction(const ResourceType *rt, const Faction *faction,bool localFactionOnly) const;
private: private:
void initCells(bool fogOfWar); void initCells(bool fogOfWar);