std::list<TechTypes> pushTechAndPrereqs(TechTypes techType, const Player& player) { std::list<TechTypes> pushedTechs; if (techType != NO_TECH) { boost::shared_ptr<CivHelper> pCivHelper = player.getCivHelper(); PushTechResearchVisitor visitor(player.getPlayerID()); bool canResearch = boost::apply_visitor(visitor, player.getAnalysis()->getTechInfo(techType)->getInfo()); if (canResearch) { pushedTechs = pCivHelper->getResearchTechs(); pCivHelper->clearResearchTechs(); } } for (std::list<TechTypes>::const_iterator ci(pushedTechs.begin()), ciEnd(pushedTechs.end()); ci != ciEnd; ++ci) { player.getCivHelper()->addTech(*ci); } return pushedTechs; }
void UnitValueHelper::debug(const UnitValueHelper::MapT& unitCombatData, std::ostream& os) const { for (MapT::const_iterator ci(unitCombatData.begin()), ciEnd(unitCombatData.end()); ci != ciEnd; ++ci) { os << "\nUnit: " << gGlobals.getUnitInfo(ci->first).getType() << " (cost = " << ci->second.first << ")"; for (size_t i = 0, count = ci->second.second.size(); i < count; ++i) { os << "\n\t" << gGlobals.getUnitInfo(ci->second.second[i].first).getType() << " odds = " << ci->second.second[i].second; } os << "\n\t\tvalue = " << getValue(ci->second); } }
int calculateTechResearchCost(TechTypes techType, PlayerTypes playerType) { std::list<TechTypes> techs = calculateResearchTechs(techType, playerType); int cost = 0; for (std::list<TechTypes>::const_iterator ci(techs.begin()), ciEnd(techs.end()); ci != ciEnd; ++ci) { cost += CvTeamAI::getTeam(CvPlayerAI::getPlayer(playerType).getTeam()).getResearchLeft(*ci); } return cost; }
void NetServer::onDestroyUdpGroup( const NetGroupOp& op ) { NetGroupMap::iterator i = m_groups.find( op.groupId ); if ( i == m_groups.end() ) { LOG( FT_WARN, _T("NetServer::onDestroyUdpGroup> %d not found"), op.groupId ); return; } NetGroup* group = i->second; K_ASSERT( group != 0 ); // make TcpConnection to forget about group const std::vector<uint>& remotes = group->GetRemotes(); std::vector<uint>::const_iterator ci( remotes.begin() ); std::vector<uint>::const_iterator ciEnd( remotes.end() ); for ( ; ci != ciEnd; ++ci ) { TcpConnection* c = m_tcp.FindById( *ci ); if ( c != 0 ) { c->SetGroup( 0 ); } } group->Fini(); LOG( FT_DEBUG, _T("NetServer::onDestroyUdpGroup> %d destroyed"), group->GetId() ); delete group; m_groups.erase( i ); }
std::list<ICityImprovementTacticsPtr> makeCityBuildTactics(const Player& player, const City& city, const boost::shared_ptr<TechInfo>& pTechInfo) { #ifdef ALTAI_DEBUG //player.getAnalysis()->recalcTechDepths(); std::ostream& os = CivLog::getLog(*player.getCvPlayer())->getStream(); os << "\nmakeCityBuildTactics: checking tech: " << gGlobals.getTechInfo(pTechInfo->getTechType()).getType(); #endif std::list<ICityImprovementTacticsPtr> cityBuildTactics; CityImprovementManager improvementManager(city.getCvCity()->getIDInfo(), true); TotalOutputWeights outputWeights = city.getPlotAssignmentSettings().outputWeights; improvementManager.simulateImprovements(outputWeights, __FUNCTION__); std::vector<CityImprovementManager::PlotImprovementData> baseImprovements = improvementManager.getImprovements(); /*CityDataPtr pSimulationCityData(new CityData(city.getCvCity(), improvementManager.getImprovements(), improvementManager.getIncludeUnclaimedPlots())); std::vector<IProjectionEventPtr> events; events.push_back(IProjectionEventPtr(new ProjectionPopulationEvent())); ProjectionLadder base = getProjectedOutput(player, pSimulationCityData, 50, events);*/ std::list<TechTypes> prereqTechs = pushTechAndPrereqs(pTechInfo->getTechType(), player); #ifdef ALTAI_DEBUG os << " pushing techs: "; for (std::list<TechTypes>::const_iterator ci(prereqTechs.begin()), ciEnd(prereqTechs.end()); ci != ciEnd; ++ci) { os << gGlobals.getTechInfo(*ci).getType() << ", "; } #endif TotalOutput baseCityOutput = improvementManager.simulateImprovements(outputWeights, __FUNCTION__); std::vector<CityImprovementManager::PlotImprovementData> newImprovements = improvementManager.getImprovements(); MakeCityBuildTacticsVisitor visitor(player, city, newImprovements); boost::apply_visitor(visitor, pTechInfo->getInfo()); const ICityImprovementTacticsPtr& pTactic = visitor.getTactic(); if (pTactic) { pTactic->addDependency(ResearchTechDependencyPtr(new ResearchTechDependency(pTechInfo->getTechType()))); #ifdef ALTAI_DEBUG os << "\ncreated imp tactic: "; pTactic->debug(os); #endif cityBuildTactics.push_back(pTactic); } /*pSimulationCityData = CityDataPtr(new CityData(city.getCvCity(), improvementManager.getImprovements(), improvementManager.getIncludeUnclaimedPlots())); events.clear(); events.push_back(IProjectionEventPtr(new ProjectionPopulationEvent())); ProjectionLadder ladder = getProjectedOutput(player, pSimulationCityData, 50, events); #ifdef ALTAI_DEBUG base.debug(os); ladder.debug(os); os << "\nImprovement delta = " << ladder.getOutput() - base.getOutput(); #endif*/ for (std::list<TechTypes>::const_iterator ci(prereqTechs.begin()), ciEnd(prereqTechs.end()); ci != ciEnd; ++ci) { player.getCivHelper()->removeTech(*ci); } player.getCivHelper()->removeTech(pTechInfo->getTechType()); return cityBuildTactics; }
std::pair<std::vector<UnitTypes>, std::vector<UnitTypes> > getActualAndPossibleCombatUnits(const Player& player, const CvCity* pCity, DomainTypes domainType) { //#ifdef ALTAI_DEBUG // std::ostream& os = CivLog::getLog(*player.getCvPlayer())->getStream(); //#endif std::vector<UnitTypes> combatUnits, possibleCombatUnits; boost::shared_ptr<PlayerTactics> pTactics = player.getAnalysis()->getPlayerTactics(); for (PlayerTactics::UnitTacticsMap::const_iterator ci(pTactics->unitTacticsMap_.begin()), ciEnd(pTactics->unitTacticsMap_.end()); ci != ciEnd; ++ci) { if (ci->first != NO_UNIT) { //#ifdef ALTAI_DEBUG // os << "\nChecking unit: " << gGlobals.getUnitInfo(ci->first).getType(); //#endif const CvUnitInfo& unitInfo = gGlobals.getUnitInfo(ci->first); if (unitInfo.getDomainType() == domainType && unitInfo.getProductionCost() >= 0 && unitInfo.getCombat() > 0) { if (ci->second && !isUnitObsolete(player, player.getAnalysis()->getUnitInfo(ci->first))) { const boost::shared_ptr<UnitInfo> pUnitInfo = player.getAnalysis()->getUnitInfo(ci->first); bool depsSatisfied = false; if (pCity) { ICityUnitTacticsPtr pCityTactics = ci->second->getCityTactics(pCity->getIDInfo()); depsSatisfied = pCityTactics && pCityTactics->areDependenciesSatisfied(IDependentTactic::Ignore_None); } else { depsSatisfied = ci->second->areDependenciesSatisfied(player, IDependentTactic::Ignore_None); } bool couldConstruct = couldConstructUnit(player, 0, pUnitInfo, false); //#ifdef ALTAI_DEBUG // os << " deps = " << depsSatisfied << ", could construct = " << couldConstruct; //#endif if (depsSatisfied) { combatUnits.push_back(ci->first); possibleCombatUnits.push_back(ci->first); } else if (couldConstructUnit(player, 1, player.getAnalysis()->getUnitInfo(ci->first), true)) { possibleCombatUnits.push_back(ci->first); } } } } } return std::make_pair(combatUnits, possibleCombatUnits); }
ResearchTech getResearchTech(const PlayerTactics& playerTactics, TechTypes ignoreTechType) { TechSelectionData selectionData(playerTactics); // pure tech tactics ('first to tech' items, open borders, etc...) for (PlayerTactics::TechTacticsMap::const_iterator ci = playerTactics.techTacticsMap_.begin(), ciEnd = playerTactics.techTacticsMap_.end(); ci != ciEnd; ++ci) { if (ci->second) { ci->second->apply(selectionData.tacticSelectionDataMap[DependencyItem(ResearchTechDependency::ID, ci->first)]); } } // buildings for (PlayerTactics::CityBuildingTacticsMap::const_iterator ci = playerTactics.cityBuildingTacticsMap_.begin(), ciEnd = playerTactics.cityBuildingTacticsMap_.end(); ci != ciEnd; ++ci) { const CvCity* pCity = getCity(ci->first); const City& city = gGlobals.getGame().getAltAI()->getPlayer(pCity->getOwner())->getCity(pCity); for (PlayerTactics::CityBuildingTacticsList::const_iterator li(ci->second.begin()), liEnd(ci->second.end()); li != liEnd; ++li) { li->second->update(playerTactics.player, city.getCityData()); li->second->apply(selectionData.tacticSelectionDataMap, IDependentTactic::Ignore_Techs); } } // units for (PlayerTactics::UnitTacticsMap::const_iterator iter(playerTactics.unitTacticsMap_.begin()), endIter(playerTactics.unitTacticsMap_.end()); iter != endIter; ++iter) { if (iter->second) { iter->second->update(playerTactics.player); iter->second->apply(selectionData.tacticSelectionDataMap, IDependentTactic::Ignore_Techs); } } // city improvements for (PlayerTactics::CityImprovementTacticsMap::const_iterator ci(playerTactics.cityImprovementTacticsMap_.begin()), ciEnd(playerTactics.cityImprovementTacticsMap_.end()); ci != ciEnd; ++ci) { const CvCity* pCity = getCity(ci->first); if (pCity) { const City& city = playerTactics.player.getCity(pCity); TotalOutput base = city.getCurrentOutputProjection().getOutput(); for (PlayerTactics::CityImprovementTacticsList::const_iterator li(ci->second.begin()), liEnd(ci->second.end()); li != liEnd; ++li) { (*li)->update(playerTactics.player, city.getCityData()); const std::vector<ResearchTechDependencyPtr> techs = (*li)->getTechDependencies(); for (size_t i = 0, count = techs.size(); i < count; ++i) { selectionData.tacticSelectionDataMap[techs[i]->getDependencyItem()].cityImprovementsDelta += (*li)->getProjection().getOutput() - base; } } } } // processes for (PlayerTactics::ProcessTacticsMap::const_iterator ci(playerTactics.processTacticsMap_.begin()), ciEnd(playerTactics.processTacticsMap_.end()); ci != ciEnd; ++ci) { if (ci->second->areDependenciesSatisfied(playerTactics.player, IDependentTactic::Ignore_Techs)) { CityIter iter(*playerTactics.player.getCvPlayer()); TotalOutput processOutput; while (CvCity* pCity = iter()) { ProjectionLadder projection = ci->second->getProjection(pCity->getIDInfo()); processOutput += projection.getProcessOutput(); } const std::vector<ResearchTechDependencyPtr>& techs = ci->second->getTechDependencies(); for (size_t i = 0, count = techs.size(); i < count; ++i) { selectionData.tacticSelectionDataMap[techs[i]->getDependencyItem()]. processOutputsMap[ci->second->getProcessType()] += processOutput; } } } selectionData.processTechs(); if (ignoreTechType != NO_TECH) { //selectionData.removeTech(ignoreTechType); } selectionData.scoreTechs(); selectionData.debug(); return selectionData.getSelection(); }
// todo - get area counting code out of here; separate to logging void Game::logMap(const CvMap& map) const { #ifdef ALTAI_DEBUG std::ostream& os = CivLog::getLog(CvPlayerAI::getPlayer((PlayerTypes)0))->getStream(); #endif std::map<int, std::pair<int, int> > irrigatableAreaCounts; // TODO check that at least one plot in the area has fresh water if it is irrigatable for (int plotIndex = 0, plotCount = map.numPlots(); plotIndex < plotCount; ++plotIndex) { CvPlot* pPlot = map.plotByIndex(plotIndex); int irrigatableAreaID = pPlot->getIrrigatableArea(); if (irrigatableAreaID != FFreeList::INVALID_INDEX) { int subAreaID = pPlot->getSubArea(); std::map<int, std::pair<int, int> >::iterator iter = irrigatableAreaCounts.find(irrigatableAreaID); if (iter == irrigatableAreaCounts.end()) { irrigatableAreaCounts.insert(std::make_pair(irrigatableAreaID, std::make_pair(subAreaID, 1))); } else { FAssertMsg(iter->second.first == subAreaID, "Irrigatable Area has inconsistent SubArea IDs"); ++iter->second.second; } } } #ifdef ALTAI_DEBUG os << "\n"; #endif for (std::map<int, std::pair<int, int> >::const_iterator ci(irrigatableAreaCounts.begin()), ciEnd(irrigatableAreaCounts.end()); ci != ciEnd; ++ci) { boost::shared_ptr<AltAI::IrrigatableArea> pIrrigatableArea = map.getIrrigatableArea(ci->first); pIrrigatableArea->setNumTiles(ci->second.second); #ifdef ALTAI_DEBUG { os << "\nIrrigatable Area: " << ci->first << " irrigatable = " << pIrrigatableArea->isIrrigatable() << " wet = " << pIrrigatableArea->hasFreshWaterAccess() << " (Sub Area ID = " << pIrrigatableArea->getSubAreaID() << ") has: " << ci->second.second << " plots (out of " << map.getSubArea(ci->second.first)->getNumTiles() << ")\n"; } #endif if (pIrrigatableArea->isIrrigatable() && !pIrrigatableArea->hasFreshWaterAccess()) { #ifdef ALTAI_DEBUG os << "\n"; for (int plotIndex = 0, plotCount = map.numPlots(); plotIndex < plotCount; ++plotIndex) { CvPlot* pPlot = map.plotByIndex(plotIndex); int irrigatableAreaID = pPlot->getIrrigatableArea(); if (irrigatableAreaID == ci->first) { os << pPlot->getCoords() << ", "; } } os << "\n"; #endif } } #ifdef ALTAI_DEBUG os << "\n"; #endif }
void operator() (const UnitInfo::PromotionsNode& node) { for (std::set<UnitInfo::PromotionsNode::Promotion>::const_iterator ci(node.promotions.begin()), ciEnd(node.promotions.end()); ci != ciEnd; ++ci) { if (ci->level == 0) { freePromotions.insert(ci->promotionType); } } }