CvCitySpecializationAI::WeightSpecializations()
- Defined in
- CvCitySpecializationAI.cpp, line 413
- Class
- CvCitySpecializationAI
- Hook name
CivHooks::CvCitySpecializationAI_WeightSpecializations
Hooks
static bool BeforeCvCitySpecializationAI_WeightSpecializations(CvCitySpecializationAI* self);static void AfterCvCitySpecializationAI_WeightSpecializations(CvCitySpecializationAI* self);static void ReplaceCvCitySpecializationAI_WeightSpecializations(void (*original)(CvCitySpecializationAI*), CvCitySpecializationAI* self);CivRegisterBefore<CivHooks::CvCitySpecializationAI_WeightSpecializations>(host, &BeforeCvCitySpecializationAI_WeightSpecializations);CivRegisterAfter<CivHooks::CvCitySpecializationAI_WeightSpecializations>(host, &AfterCvCitySpecializationAI_WeightSpecializations);CivRegisterReplace<CivHooks::CvCitySpecializationAI_WeightSpecializations>(host, &ReplaceCvCitySpecializationAI_WeightSpecializations);
Code
412/// Evaluate which specializations we need413void CvCitySpecializationAI::WeightSpecializations()414{415 int iFoodYieldWeight = 0;416 int iProductionYieldWeight = 0;417 int iGoldYieldWeight = 0;418 int iScienceYieldWeight = 0;419 int iGeneralEconomicWeight = 0;420421 // Clear old weights422 m_YieldWeights.clear();423 m_ProductionSubtypeWeights.clear();424425 // Must have a capital to do any specialization426 if(m_pPlayer->getCapitalCity() != NULL)427 {428 int iFlavorExpansion = 0;429 int iFlavorWonder = 0;430 int iFlavorGold = 0;431 int iFlavorScience = 0;432 int iFlavorSpaceship = 0;433434 iFlavorExpansion = m_pPlayer->GetFlavorManager()->GetIndividualFlavor((FlavorTypes)GC.getInfoTypeForString("FLAVOR_EXPANSION"));435 if(iFlavorExpansion < 0) iFlavorExpansion = 0;436 iFlavorWonder = m_pPlayer->GetFlavorManager()->GetIndividualFlavor((FlavorTypes)GC.getInfoTypeForString("FLAVOR_WONDER"));437 if(iFlavorWonder < 0) iFlavorWonder = 0;438 iFlavorGold = m_pPlayer->GetFlavorManager()->GetIndividualFlavor((FlavorTypes)GC.getInfoTypeForString("FLAVOR_GOLD"));439 if(iFlavorGold < 0) iFlavorGold = 0;440 iFlavorScience = m_pPlayer->GetFlavorManager()->GetIndividualFlavor((FlavorTypes)GC.getInfoTypeForString("FLAVOR_SCIENCE"));441 if(iFlavorScience < 0) iFlavorScience = 0;442 iFlavorSpaceship = m_pPlayer->GetFlavorManager()->GetIndividualFlavor((FlavorTypes)GC.getInfoTypeForString("FLAVOR_SPACESHIP"));443 if(iFlavorSpaceship < 0) iFlavorSpaceship = 0;444445 // COMPUTE NEW WEIGHTS446447 // Food448 CvArea* pArea = GC.getMap().getArea(m_pPlayer->getCapitalCity()->getArea());449 int iNumUnownedTiles = pArea->getNumUnownedTiles();450 int iNumCities = m_pPlayer->getNumCities();451 int iNumSettlers = m_pPlayer->GetNumUnitsWithUnitAI(UNITAI_SETTLE, true);452 EconomicAIStrategyTypes eStrategy = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_EARLY_EXPANSION");453 if(eStrategy != NO_ECONOMICAISTRATEGY && m_pPlayer->GetEconomicAI()->IsUsingStrategy(eStrategy))454 {455 iFoodYieldWeight += GC.getAI_CITY_SPECIALIZATION_FOOD_WEIGHT_EARLY_EXPANSION() /* 500 */;456 }457 iFoodYieldWeight += iFlavorExpansion * GC.getAI_CITY_SPECIALIZATION_FOOD_WEIGHT_FLAVOR_EXPANSION() /* 5 */;458 iFoodYieldWeight += (iNumUnownedTiles * 100) / pArea->getNumTiles() * GC.getAI_CITY_SPECIALIZATION_FOOD_WEIGHT_PERCENT_CONTINENT_UNOWNED() /* 5 */;;459 iFoodYieldWeight += iNumCities * GC.getAI_CITY_SPECIALIZATION_FOOD_WEIGHT_NUM_CITIES() /* -50 */;460 iFoodYieldWeight += iNumSettlers * GC.getAI_CITY_SPECIALIZATION_FOOD_WEIGHT_NUM_SETTLERS() /* -40 */;461 if((iNumCities + iNumSettlers) == 1)462 {463 iFoodYieldWeight *= 3; // Really want to get up over 1 city464 }465 if(iFoodYieldWeight < 0) iFoodYieldWeight = 0;466467 // Production468 iProductionYieldWeight = WeightProductionSubtypes(iFlavorWonder, iFlavorSpaceship);469470 // Trade471 int iLandDisputeLevel = m_pPlayer->GetDiplomacyAI()->GetTotalLandDisputeLevel();472 iGoldYieldWeight += iFlavorGold * GC.getAI_CITY_SPECIALIZATION_GOLD_WEIGHT_FLAVOR_GOLD() /* 20 */;473 iGoldYieldWeight += iLandDisputeLevel * GC.getAI_CITY_SPECIALIZATION_GOLD_WEIGHT_LAND_DISPUTE() /* 10 */;474475 // Science476 iScienceYieldWeight += iFlavorScience * GC.getAI_CITY_SPECIALIZATION_SCIENCE_WEIGHT_FLAVOR_SCIENCE() /* 20 */;477 iScienceYieldWeight += iFlavorSpaceship * GC.getAI_CITY_SPECIALIZATION_SCIENCE_WEIGHT_FLAVOR_SPACESHIP() /* 10 */;478479 // General Economics480 iGeneralEconomicWeight = GC.getAI_CITY_SPECIALIZATION_GENERAL_ECONOMIC_WEIGHT() /* 200 */;481482 // Add in any contribution from the current grand strategy483 for(int iGrandStrategyLoop = 0; iGrandStrategyLoop < GC.getNumAIGrandStrategyInfos(); iGrandStrategyLoop++)484 {485 CvAIGrandStrategyXMLEntry* grandStrategy = GC.getAIGrandStrategyInfo((AIGrandStrategyTypes)iGrandStrategyLoop);486 if(grandStrategy)487 {488 if(iGrandStrategyLoop == m_pPlayer->GetGrandStrategyAI()->GetActiveGrandStrategy())489 {490 iFoodYieldWeight += grandStrategy->GetSpecializationBoost(YIELD_FOOD);491 iGoldYieldWeight += grandStrategy->GetSpecializationBoost(YIELD_GOLD);492 iScienceYieldWeight += grandStrategy->GetSpecializationBoost(YIELD_SCIENCE);493 }494 }495 }496497 // Add weights to our weighted vector498 m_YieldWeights.push_back(YIELD_FOOD, iFoodYieldWeight);499 m_YieldWeights.push_back(YIELD_PRODUCTION, iProductionYieldWeight);500 m_YieldWeights.push_back(YIELD_GOLD, iGoldYieldWeight);501 m_YieldWeights.push_back(YIELD_SCIENCE, iScienceYieldWeight);502 m_YieldWeights.push_back(NO_YIELD, iGeneralEconomicWeight);503504 // Log results505 LogSpecializationWeights();506 }507508 return;509}
Calls
- CvAIGrandStrategyXMLEntry::GetSpecializationBoost(YieldTypes) const
- CvArea::getNumTiles() const
- CvArea::getNumUnownedTiles() const
- CvCity::getArea() const
- CvCitySpecializationAI::LogSpecializationWeights()
- CvCitySpecializationAI::WeightProductionSubtypes(int, int)
- CvDiplomacyAI::GetTotalLandDisputeLevel()
- CvEconomicAI::IsUsingStrategy(EconomicAIStrategyTypes)
- CvFlavorManager::GetIndividualFlavor(FlavorTypes)
- CvGlobals::getAI_CITY_SPECIALIZATION_FOOD_WEIGHT_EARLY_EXPANSION()
- CvGlobals::getAI_CITY_SPECIALIZATION_FOOD_WEIGHT_FLAVOR_EXPANSION()
- CvGlobals::getAI_CITY_SPECIALIZATION_FOOD_WEIGHT_NUM_CITIES()
- CvGlobals::getAI_CITY_SPECIALIZATION_FOOD_WEIGHT_NUM_SETTLERS()
- CvGlobals::getAI_CITY_SPECIALIZATION_FOOD_WEIGHT_PERCENT_CONTINENT_UNOWNED()
- CvGlobals::getAI_CITY_SPECIALIZATION_GENERAL_ECONOMIC_WEIGHT()
- CvGlobals::getAI_CITY_SPECIALIZATION_GOLD_WEIGHT_FLAVOR_GOLD()
- CvGlobals::getAI_CITY_SPECIALIZATION_GOLD_WEIGHT_LAND_DISPUTE()
- CvGlobals::getAI_CITY_SPECIALIZATION_SCIENCE_WEIGHT_FLAVOR_SCIENCE()
- CvGlobals::getAI_CITY_SPECIALIZATION_SCIENCE_WEIGHT_FLAVOR_SPACESHIP()
- CvGlobals::getAIGrandStrategyInfo(AIGrandStrategyTypes)
- CvGlobals::getInfoTypeForString(const char *, bool) const
- CvGlobals::getMap()
- CvGlobals::getNumAIGrandStrategyInfos()
- CvGrandStrategyAI::GetActiveGrandStrategy() const
- CvMap::getArea(int)
- CvPlayer::getCapitalCity()
- CvPlayer::GetDiplomacyAI() const
- CvPlayer::GetEconomicAI() const
- CvPlayer::GetFlavorManager() const
- CvPlayer::GetGrandStrategyAI() const
- CvPlayer::getNumCities() const
- CvPlayer::GetNumUnitsWithUnitAI(UnitAITypes, bool, bool)
CvWeightedVector::clearCvWeightedVector::clearCvWeightedVector::push_back