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; }
ICityUnitTacticsPtr makeCityUnitTactics(const Player& player, const City& city, const boost::shared_ptr<UnitInfo>& pUnitInfo) { const UnitTypes unitType = pUnitInfo->getUnitType(); const CvUnitInfo& unitInfo = gGlobals.getUnitInfo(pUnitInfo->getUnitType()); boost::shared_ptr<UnitAnalysis> pUnitAnalysis = player.getAnalysis()->getUnitAnalysis(); MakeUnitTacticsVisitor visitor(player, city, pUnitInfo->getUnitType()); boost::apply_visitor(visitor, pUnitInfo->getInfo()); ICityUnitTacticsPtr pCityUnitTactics = visitor.getTactic(); int maxPromotionLevel = 0; int freeExperience = ((CvCity*)city.getCvCity())->getProductionExperience(unitType); int requiredExperience = 2; while (freeExperience > requiredExperience) { // TODO - handle charismatic requiredExperience += 2 * ++maxPromotionLevel + 1; } if (unitInfo.getDomainType() == DOMAIN_LAND && unitInfo.getCombat() > 0) { if (!unitInfo.isOnlyDefensive()) { { UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCityAttackPromotions(unitType, maxPromotionLevel); if (levelsAndPromotions.second.empty()) { levelsAndPromotions = pUnitAnalysis->getCombatPromotions(unitType, maxPromotionLevel); } UnitData unitData(unitInfo, levelsAndPromotions.second); pCityUnitTactics->addTactic(ICityUnitTacticPtr(new CityAttackUnitTactic(levelsAndPromotions.second))); } if (unitInfo.getCombatLimit() == 100) { UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCombatPromotions(unitType, maxPromotionLevel); UnitData unitData(unitInfo, levelsAndPromotions.second); pCityUnitTactics->addTactic(ICityUnitTacticPtr(new FieldAttackUnitTactic(levelsAndPromotions.second))); } // todo - refine this check if (unitInfo.getCollateralDamage() > 0) { UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCityAttackPromotions(unitType, maxPromotionLevel); if (levelsAndPromotions.second.empty()) { levelsAndPromotions = pUnitAnalysis->getCollateralPromotions(unitType, maxPromotionLevel); } UnitData unitData(unitInfo, levelsAndPromotions.second); pCityUnitTactics->addTactic(ICityUnitTacticPtr(new CollateralUnitTactic(levelsAndPromotions.second))); } } { UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCityDefencePromotions(unitType, maxPromotionLevel); if (levelsAndPromotions.second.empty()) { levelsAndPromotions = pUnitAnalysis->getCombatPromotions(unitType, maxPromotionLevel); } UnitData unitData(unitInfo, levelsAndPromotions.second); pCityUnitTactics->addTactic(ICityUnitTacticPtr(new CityDefenceUnitTactic(levelsAndPromotions.second))); } { UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCombatPromotions(unitType, maxPromotionLevel); UnitData unitData(unitInfo, levelsAndPromotions.second); pCityUnitTactics->addTactic(ICityUnitTacticPtr(new FieldDefenceUnitTactic(levelsAndPromotions.second))); } } else if (unitInfo.getDomainType() == DOMAIN_SEA) { if (unitInfo.getCombat() > 0 && !unitInfo.isOnlyDefensive()) { UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCombatPromotions(unitType, maxPromotionLevel); UnitData unitData(unitInfo, levelsAndPromotions.second); if (unitData.combat > 0) { pCityUnitTactics->addTactic(ICityUnitTacticPtr(new SeaAttackUnitTactic(levelsAndPromotions.second))); } } if (unitInfo.getCargoSpace() > 0) { // todo } } return pCityUnitTactics; }