CvPlayerTechs::SetLocalePriorities()
- Defined in
- CvTechClasses.cpp, line 988
- Class
- CvPlayerTechs
- Hook name
CivHooks::CvPlayerTechs_SetLocalePriorities
Hooks
static bool BeforeCvPlayerTechs_SetLocalePriorities(CvPlayerTechs* self);static void AfterCvPlayerTechs_SetLocalePriorities(CvPlayerTechs* self);static void ReplaceCvPlayerTechs_SetLocalePriorities(void (*original)(CvPlayerTechs*), CvPlayerTechs* self);CivRegisterBefore<CivHooks::CvPlayerTechs_SetLocalePriorities>(host, &BeforeCvPlayerTechs_SetLocalePriorities);CivRegisterAfter<CivHooks::CvPlayerTechs_SetLocalePriorities>(host, &AfterCvPlayerTechs_SetLocalePriorities);CivRegisterReplace<CivHooks::CvPlayerTechs_SetLocalePriorities>(host, &ReplaceCvPlayerTechs_SetLocalePriorities);
Code
987/// Recompute weights taking into account tech cost988void CvPlayerTechs::SetLocalePriorities()989{990 int iLoop;991 CvCity* pCity;992 int iI;993994 for(iI = 0; iI < m_pTechs->GetNumTechs(); iI++)995 {996 m_piLocaleTechPriority[iI] = 1;997 m_peLocaleTechResources[iI] = NO_RESOURCE;998 }9991000 // Loop through all our cities1001 for(pCity = m_pPlayer->firstCity(&iLoop); pCity != NULL; pCity = m_pPlayer->nextCity(&iLoop))1002 {1003 // Look at all Tiles this City could potentially work to see if there are any non-water resources that could be improved1004#if defined(MOD_GLOBAL_CITY_WORKING)1005 for(int iPlotLoop = 0; iPlotLoop < pCity->GetNumWorkablePlots(); iPlotLoop++)1006#else1007 for(int iPlotLoop = 0; iPlotLoop < NUM_CITY_PLOTS; iPlotLoop++)1008#endif1009 {1010 CvPlot* pLoopPlot = plotCity(pCity->getX(), pCity->getY(), iPlotLoop);10111012 if(pLoopPlot != NULL)1013 {1014 int iDistance = plotDistance(pLoopPlot->getX(), pLoopPlot->getY(), pCity->getX(), pCity->getY());10151016 if(pLoopPlot->getOwner() == pCity->getOwner() || (iDistance <= 2 && pLoopPlot->getOwner() == NO_PLAYER))1017 {1018#if defined(MOD_AI_SMART_V3)1019 int multiplierValue = 1;1020#endif10211022#if defined(MOD_AI_SMART_V3)1023 if(MOD_AI_SMART_V3 || !pLoopPlot->isWater())1024#else1025 if(!pLoopPlot->isWater())1026#endif1027 {1028 ResourceTypes eResource = pLoopPlot->getResourceType(m_pPlayer->getTeam());1029 if(eResource == NO_RESOURCE)1030 {1031 continue;1032 }10331034 // Loop through the build types to find one that we can use1035 ImprovementTypes eCorrectImprovement = NO_IMPROVEMENT;1036 BuildTypes eCorrectBuild = NO_BUILD;1037 int iBuildIndex;1038 for(iBuildIndex = 0; iBuildIndex < GC.getNumBuildInfos(); iBuildIndex++)1039 {1040 const BuildTypes eBuild = static_cast<BuildTypes>(iBuildIndex);1041 CvBuildInfo* pkBuildInfo = GC.getBuildInfo(eBuild);1042 if(pkBuildInfo)1043 {1044 // If this is the improvement we're looking for1045 const ImprovementTypes eImprovement = (ImprovementTypes)pkBuildInfo->getImprovement();1046 if(eImprovement != NO_IMPROVEMENT)1047 {1048#if defined(MOD_AI_SMART_V3)1049 if (MOD_AI_SMART_V3)1050 {1051 if(pLoopPlot->canHaveImprovement(eImprovement))1052 {1053 CvImprovementEntry* pkImprovementInfo = GC.getImprovementInfo(eImprovement);1054 if (pkImprovementInfo && pkImprovementInfo->IsImprovementResourceTrade(eResource))1055 {1056 multiplierValue = 2;1057 }1058 1059 eCorrectBuild = eBuild;1060 eCorrectImprovement = eImprovement;1061 break;1062 }1063 }1064 else1065 {1066#endif1067 CvImprovementEntry* pkImprovementInfo = GC.getImprovementInfo(eImprovement);1068 if(pkImprovementInfo && pkImprovementInfo->IsImprovementResourceTrade(eResource))1069 {1070 eCorrectBuild = eBuild;1071 eCorrectImprovement = eImprovement;1072 break;1073 }1074#if defined(MOD_AI_SMART_V3)1075 }1076#endif1077 }1078 }1079 }10801081 // No valid build found1082 if(eCorrectBuild == NO_BUILD || eCorrectImprovement == NO_IMPROVEMENT)1083 {1084 continue;1085 }108610871088 // Looking for cases where we can't build the improvement for the resource1089 if(!m_pPlayer->canBuild(pLoopPlot, eCorrectBuild, false, false))1090 {1091 // Find the tech associated with this build and increment its multiplier1092 int iTech = GC.getBuildInfo(eCorrectBuild)->getTechPrereq();1093 CvAssert(iTech < m_pTechs->GetNumTechs()); // Just assert on a value off the top end, a -1 is ok to just skip silently1094 if (iTech >= 0 && iTech < m_pTechs->GetNumTechs())1095 {1096#if defined(MOD_AI_SMART_V3)1097 if (MOD_AI_SMART_V3)1098 {1099 m_piLocaleTechPriority[iTech] += multiplierValue;1100 if (multiplierValue == 2)1101 {1102 m_peLocaleTechResources[iTech] = eResource; 1103 }1104 }1105 else1106 {1107#endif1108 m_piLocaleTechPriority[iTech]++;1109 m_peLocaleTechResources[iTech] = eResource;1110#if defined(MOD_AI_SMART_V3)1111 }1112#endif1113 }1114 }1115 }1116 }1117 }1118 }1119 }1120}
Calls
- CustomMods::isAI_SMART_V3()
- CvBuildInfo::getImprovement() const
- CvBuildInfo::getTechPrereq() const
- CvCity::GetNumWorkablePlots(int) const
- CvCity::getOwner() const
- CvCity::getX() const
- CvCity::getY() const
- CvGlobals::getBuildInfo(BuildTypes)
- CvGlobals::getImprovementInfo(ImprovementTypes)
- CvGlobals::getNumBuildInfos()
- CvImprovementEntry::IsImprovementResourceTrade(int) const
- CvPlayer::canBuild(const CvPlot *, BuildTypes, bool, bool, bool, bool) const
- CvPlayer::firstCity(int *, bool)
- CvPlayer::getTeam() const
- CvPlayer::nextCity(int *, bool)
- CvPlot::canHaveImprovement(ImprovementTypes, TeamTypes, bool) const
- CvPlot::getOwner() const
- CvPlot::getResourceType(TeamTypes) const
- CvPlot::getX() const
- CvPlot::getY() const
- CvPlot::isWater() const
- CvTechXMLEntries::GetNumTechs()
- plotCity(int, int, int)
- plotDistance(int, int, int, int)