- added ability to share resources across same teams
This commit is contained in:
parent
e33024c102
commit
39696b6a65
|
@ -1594,10 +1594,10 @@ void Game::init(bool initForPreviewOnly) {
|
|||
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");
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -1735,8 +1735,8 @@ void Game::processNetworkSynchChecksIfRequired() {
|
|||
if(settings != NULL) {
|
||||
bool calculateNetworkCRC = false;
|
||||
|
||||
if(isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks) == true ||
|
||||
isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks_verbose) == true) {
|
||||
if(isFlagType1BitEnabled(ft1_network_synch_checks) == true ||
|
||||
isFlagType1BitEnabled(ft1_network_synch_checks_verbose) == true) {
|
||||
calculateNetworkCRC = true;
|
||||
}
|
||||
|
||||
|
@ -1751,10 +1751,10 @@ void Game::processNetworkSynchChecksIfRequired() {
|
|||
netIntf->setNetworkPlayerFactionCRC(index,faction->getCRC().getSum());
|
||||
|
||||
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);
|
||||
}
|
||||
else if(isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks) == true &&
|
||||
else if(isFlagType1BitEnabled(ft1_network_synch_checks) == true &&
|
||||
world.getFrameCount() % 20 == 0) {
|
||||
faction->addCRC_DetailsForWorldFrame(world.getFrameCount(),role == nrServer);
|
||||
}
|
||||
|
@ -5057,8 +5057,8 @@ void Game::DumpCRCWorldLogIfRequired(string fileSuffix) {
|
|||
|
||||
GameSettings *settings = world.getGameSettingsPtr();
|
||||
if(settings != NULL &&
|
||||
(isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks_verbose) == true ||
|
||||
isFlagType1BitEnabled(settings->getFlagTypes1(),ft1_network_synch_checks) == true)) {
|
||||
(isFlagType1BitEnabled(ft1_network_synch_checks_verbose) == true ||
|
||||
isFlagType1BitEnabled(ft1_network_synch_checks) == true)) {
|
||||
string debugCRCWorldLogFile = Config::getInstance().getString("DebugCRCWorldLogFile","debugCRCWorld.log");
|
||||
debugCRCWorldLogFile += fileSuffix;
|
||||
|
||||
|
@ -5796,7 +5796,7 @@ void Game::checkWinnerStandardPlayer() {
|
|||
|
||||
bool playerLostGame = true;
|
||||
// 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?
|
||||
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) {
|
||||
return factionLostGame(world.getFaction(factionIndex));
|
||||
}
|
||||
|
|
|
@ -224,6 +224,7 @@ public:
|
|||
~Game();
|
||||
|
||||
void reInitGUI();
|
||||
bool isFlagType1BitEnabled(FlagTypes1 type) const;
|
||||
|
||||
bool isMarkCellMode() const { return isMarkCellEnabled; }
|
||||
const Texture2D * getMarkCellTexture() const { return markCellTexture; }
|
||||
|
|
|
@ -2339,40 +2339,66 @@ void Renderer::renderResourceStatus() {
|
|||
return;
|
||||
}
|
||||
|
||||
const Metrics &metrics= Metrics::getInstance();
|
||||
const World *world= game->getWorld();
|
||||
const Metrics &metrics = Metrics::getInstance();
|
||||
const World *world = game->getWorld();
|
||||
|
||||
if(world->getThisFactionIndex() < 0 || world->getThisFactionIndex() >= world->getFactionCount()) {
|
||||
if(world->getThisFactionIndex() < 0 ||
|
||||
world->getThisFactionIndex() >= world->getFactionCount()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Faction *thisFaction= world->getFaction(world->getThisFactionIndex());
|
||||
const Faction *thisFaction = world->getFaction(world->getThisFactionIndex());
|
||||
const Vec4f fontColor = game->getGui()->getDisplay()->getColor();
|
||||
assertGl();
|
||||
|
||||
glPushAttrib(GL_ENABLE_BIT);
|
||||
|
||||
int resourceCountRendered = 0;
|
||||
for(int i= 0; i < world->getTechTree()->getResourceTypeCount(); ++i) {
|
||||
const ResourceType *rt = world->getTechTree()->getResourceType(i);
|
||||
const Resource *r = thisFaction->getResource(rt);
|
||||
for(int techTreeResourceTypeIndex = 0;
|
||||
techTreeResourceTypeIndex < world->getTechTree()->getResourceTypeCount();
|
||||
++techTreeResourceTypeIndex) {
|
||||
|
||||
if ( rt->getDisplayInHud() == false ){
|
||||
const ResourceType *rt = world->getTechTree()->getResourceType(techTreeResourceTypeIndex);
|
||||
|
||||
if ( rt->getDisplayInHud() == false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const Faction *factionForResourceView = thisFaction;
|
||||
bool localFactionResourcesOnly = false;
|
||||
|
||||
if(game != NULL && game->getGui() != NULL) {
|
||||
|
||||
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= false;
|
||||
for(int k=0; k < thisFaction->getType()->getUnitTypeCount(); ++k) {
|
||||
const UnitType *ut = thisFaction->getType()->getUnitType(k);
|
||||
if(ut->getCost(rt) != NULL) {
|
||||
showResource = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool showResource = world->showResourceTypeForFaction(rt, factionForResourceView, localFactionResourcesOnly);
|
||||
|
||||
//draw resource status
|
||||
if(showResource) {
|
||||
string str= intToStr(r->getAmount());
|
||||
if(showResource == true) {
|
||||
const Resource *r = factionForResourceView->getResource(rt,localFactionResourcesOnly);
|
||||
string str = intToStr(r->getAmount());
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
|
@ -2381,18 +2407,22 @@ void Renderer::renderResourceStatus() {
|
|||
bool isNegativeConsumableDisplayCycle = false;
|
||||
if(rt->getClass() == rcConsumable) {
|
||||
// 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) {
|
||||
|
||||
isNegativeConsumableDisplayCycle = true;
|
||||
if(r->getBalance()*1+r->getAmount()<0){
|
||||
if(r->getBalance() * 1 + r->getAmount() < 0) {
|
||||
|
||||
glColor3f(RED.x,RED.y,RED.z);
|
||||
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);
|
||||
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);
|
||||
resourceFontColor = YELLOW;
|
||||
}
|
||||
|
@ -2406,11 +2436,11 @@ void Renderer::renderResourceStatus() {
|
|||
const int MAX_RESOURCES_PER_ROW = 6;
|
||||
int resourceRow = (resourceCountRendered > 0 ? resourceCountRendered / MAX_RESOURCES_PER_ROW : 0);
|
||||
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());
|
||||
|
||||
if(rt->getClass() != rcStatic) {
|
||||
str+= "/" + intToStr(thisFaction->getStoreAmount(rt));
|
||||
str+= "/" + intToStr(factionForResourceView->getStoreAmount(rt,localFactionResourcesOnly));
|
||||
}
|
||||
if(rt->getClass() == rcConsumable) {
|
||||
str+= "(";
|
||||
|
|
|
@ -135,7 +135,7 @@ void Gui::init(Game *game) {
|
|||
selection.init(this,
|
||||
world->getThisFactionIndex(),
|
||||
world->getThisTeamIndex(),
|
||||
isFlagType1BitEnabled(game->getGameSettings()->getFlagTypes1(),ft1_allow_shared_team_units));
|
||||
game->isFlagType1BitEnabled(ft1_allow_shared_team_units));
|
||||
}
|
||||
|
||||
void Gui::end(){
|
||||
|
|
|
@ -329,7 +329,7 @@ void Selection::loadGame(const XmlNode *rootNode, World *world) {
|
|||
factionIndex = selectionNode->getAttribute("factionIndex")->getIntValue();
|
||||
teamIndex = selectionNode->getAttribute("teamIndex")->getIntValue();
|
||||
if(selectionNode->hasAttribute("allowSharedTeamUnits") == true) {
|
||||
allowSharedTeamUnits = selectionNode->getAttribute("allowSharedTeamUnits")->getIntValue();
|
||||
allowSharedTeamUnits = (selectionNode->getAttribute("allowSharedTeamUnits")->getIntValue() != 0);
|
||||
}
|
||||
|
||||
vector<XmlNode *> selectedUnitsNodeList = selectionNode->getChildList("selectedUnits");
|
||||
|
|
|
@ -1702,21 +1702,6 @@ void ServerInterface::updateKeyframe(int frameCount) {
|
|||
// We always need to broadcast when not pause as clients
|
||||
// look for broadcasts every network frame.
|
||||
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
|
||||
// broadcasts every MAX_EMPTY_NETWORK_COMMAND_LIST_BROADCAST_INTERVAL_MILLISECONDS
|
||||
|
|
|
@ -710,11 +710,14 @@ void Faction::init(
|
|||
store.resize(techTree->getResourceTypeCount());
|
||||
|
||||
if(loadWorldNode == NULL) {
|
||||
for(int i=0; i<techTree->getResourceTypeCount(); ++i){
|
||||
const ResourceType *rt= techTree->getResourceType(i);
|
||||
int resourceAmount= giveResources? factionType->getStartingResourceAmount(rt): 0;
|
||||
resources[i].init(rt, resourceAmount);
|
||||
store[i].init(rt, 0);
|
||||
for(int index = 0; index < techTree->getResourceTypeCount(); ++index) {
|
||||
const ResourceType *rt = techTree->getResourceType(index);
|
||||
int resourceAmount = giveResources ? factionType->getStartingResourceAmount(rt): 0;
|
||||
resources[index].init(rt, resourceAmount);
|
||||
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 &&
|
||||
// Config::getInstance().getBool("EnableFactionWorkerThreads","true") == true) {
|
||||
if(workerThread != NULL) {
|
||||
workerThread->signalQuit();
|
||||
if(workerThread->shutdownAndWait() == true) {
|
||||
|
@ -750,12 +751,54 @@ void Faction::init(
|
|||
|
||||
// ================== get ==================
|
||||
|
||||
const Resource *Faction::getResource(const ResourceType *rt) const{
|
||||
for(int i = 0; i < (int)resources.size(); ++i){
|
||||
if(rt==resources[i].getType()){
|
||||
return &resources[i];
|
||||
bool Faction::hasUnitTypeWithResourceCostInCache(const ResourceType *rt) const {
|
||||
std::string resourceTypeName = rt->getName(false);
|
||||
std::map<std::string, bool>::const_iterator iterFind = resourceTypeCostCache.find(resourceTypeName);
|
||||
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"));
|
||||
for(int i=0; i < (int)resources.size(); ++i){
|
||||
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;
|
||||
}
|
||||
|
||||
int Faction::getStoreAmount(const ResourceType *rt) const{
|
||||
for(int i=0; i < (int)store.size(); ++i){
|
||||
if(rt==store[i].getType()){
|
||||
return store[i].getAmount();
|
||||
int Faction::getStoreAmount(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->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"));
|
||||
|
|
|
@ -167,6 +167,7 @@ private:
|
|||
std::map<int,SwitchTeamVote> switchTeamVotes;
|
||||
int currentSwitchTeamVoteFactionIndex;
|
||||
|
||||
bool allowSharedTeamUnits;
|
||||
set<int> livingUnits;
|
||||
set<Unit*> livingUnitsp;
|
||||
|
||||
|
@ -184,6 +185,8 @@ private:
|
|||
std::map<int,const Unit *> mobileUnitListCache;
|
||||
std::map<int,const Unit *> beingBuiltUnitListCache;
|
||||
|
||||
std::map<std::string, bool> resourceTypeCostCache;
|
||||
|
||||
public:
|
||||
Faction();
|
||||
~Faction();
|
||||
|
@ -251,9 +254,9 @@ public:
|
|||
void setFactionDisconnectHandled(bool value) { factionDisconnectHandled=value;}
|
||||
|
||||
//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];}
|
||||
int getStoreAmount(const ResourceType *rt) const;
|
||||
int getStoreAmount(const ResourceType *rt,bool localFactionOnly=false) const;
|
||||
inline const FactionType *getType() const {return factionType;}
|
||||
inline int getIndex() const {return index;}
|
||||
|
||||
|
@ -375,9 +378,13 @@ public:
|
|||
string getCRC_DetailsForWorldFrames() const;
|
||||
uint64 getCRC_DetailsForWorldFrameCount() const;
|
||||
|
||||
void updateUnitTypeWithResourceCostCache(const ResourceType *rt);
|
||||
bool hasUnitTypeWithResourceCostInCache(const ResourceType *rt) const;
|
||||
|
||||
private:
|
||||
void init();
|
||||
void resetResourceAmount(const ResourceType *rt);
|
||||
bool hasUnitTypeWithResouceCost(const ResourceType *rt);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -753,11 +753,11 @@ void Unit::dumpMemoryList() {
|
|||
bool Unit::isNetworkCRCEnabled() {
|
||||
bool isNetworkCRCEnabled = false;
|
||||
|
||||
if(game != NULL && game->getGameSettings() != NULL) {
|
||||
if(isFlagType1BitEnabled(game->getGameSettings()->getFlagTypes1(),ft1_network_synch_checks_verbose) == true) {
|
||||
if(game != NULL) {
|
||||
if(game->isFlagType1BitEnabled(ft1_network_synch_checks_verbose) == 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1033,6 +1033,7 @@ void World::tick() {
|
|||
|
||||
//if consumable
|
||||
if(rt != NULL && rt->getClass() == rcConsumable) {
|
||||
|
||||
int balance= 0;
|
||||
for(int unitIndex = 0;
|
||||
unitIndex < faction->getUnitCount(); ++unitIndex) {
|
||||
|
@ -1040,11 +1041,13 @@ void World::tick() {
|
|||
//if unit operative and has this cost
|
||||
const Unit *unit = faction->getUnit(unitIndex);
|
||||
if(unit != NULL && unit->isOperative()) {
|
||||
|
||||
const UnitType *ut = unit->getType();
|
||||
const Resource *resource = NULL;
|
||||
std::map<const UnitType *, std::map<const ResourceType *, const Resource *> >::iterator iterFind = resourceCostCache.find(ut);
|
||||
if(iterFind != resourceCostCache.end() &&
|
||||
iterFind->second.find(rt) != iterFind->second.end()) {
|
||||
|
||||
resource = iterFind->second.find(rt)->second;
|
||||
}
|
||||
else {
|
||||
|
@ -2656,6 +2659,87 @@ void World::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) {
|
||||
for(int i= 0; i < (int)factions.size(); ++i) {
|
||||
factions[i]->removeResourceTargetFromCache(pos);
|
||||
|
|
|
@ -142,6 +142,8 @@ private:
|
|||
bool cacheFowAlphaTexture;
|
||||
bool cacheFowAlphaTextureFogOfWarValue;
|
||||
|
||||
std::map<int, std::map<std::string, Resource > > TeamResources;
|
||||
|
||||
public:
|
||||
World();
|
||||
~World();
|
||||
|
@ -317,6 +319,12 @@ public:
|
|||
void refreshAllUnitExplorations();
|
||||
|
||||
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:
|
||||
|
||||
void initCells(bool fogOfWar);
|
||||
|
|
Loading…
Reference in New Issue