void CvGameObjectCity::foreachRelated(GameObjectTypes eType, RelationTypes eRelation, boost::function<void(CvGameObject *)> func, int iData) { if (eRelation == RELATION_TRADE) { if (eType == GAMEOBJECT_CITY) { int iRoutes = m_pCity->getTradeRoutes(); for (int i=0; i<iRoutes; i++) { CvCity* pTradeCity = m_pCity->getTradeCity(i); if (pTradeCity) { func(pTradeCity->getGameObject()); } } } } else if (eRelation == RELATION_WORKING) { if (eType == GAMEOBJECT_PLOT) { for (int iI = 0; iI < m_pCity->getNumCityPlots(); iI++) { CvPlot* pLoopPlot = plotCity(m_pCity->getX_INLINE(), m_pCity->getY_INLINE(), iI); if (pLoopPlot) { if (pLoopPlot->getWorkingCity() == m_pCity) { func(pLoopPlot->getGameObject()); } } } } } else { CvGameObject::foreachRelated(eType, eRelation, func, iData); } }
/// Value of this site for a civ starting location int CvSiteEvaluatorForStart::PlotFoundValue(CvPlot* pPlot, CvPlayer* pPlayer, YieldTypes, bool) { int rtnValue = 0; int iI; CvPlot* pLoopPlot(NULL); int iCelticForestCount = 0; CvAssert(pPlot); if(!pPlot) return rtnValue; if(!CanFound(pPlot, pPlayer, false)) { return rtnValue; } // Is there any reason this site doesn't work for a start location? // // Not on top of a goody hut if(pPlot->isGoody()) { return 0; } // We have our own special method of scoring, so don't call the base class for that (like settler version does) #if defined(MOD_GLOBAL_CITY_WORKING) int iLimit = (pPlayer != NULL) ? pPlayer->GetNumWorkablePlots() : AVG_CITY_PLOTS; for(iI = 0; iI < iLimit; iI++) #else for(iI = 0; iI < NUM_CITY_PLOTS; iI++) #endif { pLoopPlot = plotCity(pPlot->getX(), pPlot->getY(), iI); // Too close to map edge? if(pLoopPlot == NULL) { return 0; } else { int iDistance = plotDistance(pPlot->getX(), pPlot->getY(), pLoopPlot->getX(), pLoopPlot->getY()); #if defined(MOD_GLOBAL_CITY_WORKING) if (pPlayer != NULL) { CvAssert(iDistance <= pPlayer->getWorkPlotDistance()); if(iDistance > pPlayer->getWorkPlotDistance()) continue; } else { CvAssert(iDistance <= AVG_CITY_RADIUS); if(iDistance > AVG_CITY_RADIUS) continue; } #else CvAssert(iDistance <= NUM_CITY_RINGS); if(iDistance > NUM_CITY_RINGS) continue; #endif int iRingModifier = m_iRingModifier[iDistance]; // Skip the city plot itself for now if(iDistance != 0) { rtnValue += iRingModifier * ComputeFoodValue(pLoopPlot, pPlayer) * /*6*/ GC.getSTART_AREA_FOOD_MULTIPLIER(); rtnValue += iRingModifier * ComputeHappinessValue(pLoopPlot, pPlayer) * /*12*/ GC.getSTART_AREA_HAPPINESS_MULTIPLIER(); rtnValue += iRingModifier * ComputeProductionValue(pLoopPlot, pPlayer) * /*8*/ GC.getSTART_AREA_PRODUCTION_MULTIPLIER(); rtnValue += iRingModifier * ComputeGoldValue(pLoopPlot, pPlayer) * /*2*/ GC.getSTART_AREA_GOLD_MULTIPLIER(); rtnValue += iRingModifier * ComputeScienceValue(pLoopPlot, pPlayer) * /*1*/ GC.getSTART_AREA_SCIENCE_MULTIPLIER(); rtnValue += iRingModifier * ComputeFaithValue(pLoopPlot, pPlayer) * /*1*/ GC.getSTART_AREA_FAITH_MULTIPLIER(); rtnValue += iRingModifier * ComputeTradeableResourceValue(pLoopPlot, pPlayer) * /*1*/ GC.getSTART_AREA_RESOURCE_MULTIPLIER(); rtnValue += iRingModifier * ComputeStrategicValue(pLoopPlot, pPlayer, iDistance) * /*1*/ GC.getSTART_AREA_STRATEGIC_MULTIPLIER(); } if (pPlayer) { if (iDistance == 1 && pLoopPlot->getFeatureType() == FEATURE_FOREST) { if (pLoopPlot->getImprovementType() == NO_IMPROVEMENT && pPlayer->GetPlayerTraits()->IsFaithFromUnimprovedForest()) { iCelticForestCount += 1; } } } } } if (iCelticForestCount >= 3) { rtnValue += 2 * 1000 * m_iFlavorMultiplier[YIELD_FAITH]; } else if (iCelticForestCount >= 1) { rtnValue += 1 * 1000 * m_iFlavorMultiplier[YIELD_FAITH]; } if(rtnValue < 0) rtnValue = 0; // Finally, look at the city plot itself and use it as an overall multiplier if(pPlot->getResourceType() != NO_RESOURCE) { rtnValue += rtnValue * GC.getBUILD_ON_RESOURCE_PERCENT() / 100; } if(pPlot->isRiver()) { rtnValue += rtnValue * GC.getBUILD_ON_RIVER_PERCENT() / 100; } if(pPlot->isCoastalLand()) { rtnValue += rtnValue * GC.getSTART_AREA_BUILD_ON_COAST_PERCENT() / 100; } return rtnValue; }
CvPlot* CvPlayerAI::FindBestMusicianTargetPlot(CvUnit* pGreatMusician, bool bOnlySafePaths) { CvAssertMsg(pGreatMusician, "pGreatMusician is null"); if(!pGreatMusician) { return NULL; } int iBestTurnsToReach = MAX_INT; CvPlot* pBestTargetPlot = NULL; CvCity* pBestTargetCity = NULL; int iPathTurns; UnitHandle pMusician = UnitHandle(pGreatMusician); // Find target civ PlayerTypes eTargetPlayer = GetCulture()->GetCivLowestInfluence(true /*bCheckOpenBorders*/); if (eTargetPlayer == NO_PLAYER) { return NULL; } CvPlayer &kTargetPlayer = GET_PLAYER(eTargetPlayer); // Loop through each of that player's cities int iLoop; CvCity *pLoopCity; for(pLoopCity = kTargetPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kTargetPlayer.nextCity(&iLoop)) { // Search all the plots adjacent to this city for(int jJ = 0; jJ < NUM_DIRECTION_TYPES; jJ++) { CvPlot* pAdjacentPlot = plotDirection(pLoopCity->getX(), pLoopCity->getY(), ((DirectionTypes)jJ)); if(pAdjacentPlot != NULL) { // Make sure this is still owned by target and is revealed to us bool bRightOwner = (pAdjacentPlot->getOwner() == eTargetPlayer); bool bIsRevealed = pAdjacentPlot->isRevealed(getTeam()); if(bRightOwner && bIsRevealed) { iPathTurns = TurnsToReachTarget(pMusician, pAdjacentPlot, true /*bReusePaths*/, !bOnlySafePaths/*bIgnoreUnits*/); if(iPathTurns < iBestTurnsToReach) { iBestTurnsToReach = iPathTurns; pBestTargetCity = pLoopCity; } } } } } // Found a city now look at ALL the plots owned by that player near that city if (pBestTargetCity) { iBestTurnsToReach = MAX_INT; CvPlot *pLoopPlot; for(int iJ = 0; iJ < NUM_CITY_PLOTS; iJ++) { pLoopPlot = plotCity(pBestTargetCity->getX(), pBestTargetCity->getY(), iJ); if(pLoopPlot != NULL) { // Make sure this is still owned by target and is revealed to us bool bRightOwner = (pLoopPlot->getOwner() == eTargetPlayer); bool bIsRevealed = pLoopPlot->isRevealed(getTeam()); if(bRightOwner && bIsRevealed) { iPathTurns = TurnsToReachTarget(pMusician, pLoopPlot, true /*bReusePaths*/, !bOnlySafePaths/*bIgnoreUnits*/); if(iPathTurns < iBestTurnsToReach) { iBestTurnsToReach = iPathTurns; pBestTargetPlot = pLoopPlot; } } } } } return pBestTargetPlot; }
CyPlot* cyPlotCity(int iX, int iY, int iIndex) { return new CyPlot(plotCity(iX, iY, iIndex)); }