Hooks
static bool BeforeCalculateDigSiteWeight(int iIndex, FFastVector<CvArchaeologyData, true, c_eCiv5GameplayDLL, 0>& inputData, FFastVector<CvArchaeologyData, true, c_eCiv5GameplayDLL, 0>& chosenDigSites, int& result);static void AfterCalculateDigSiteWeight(int iIndex, FFastVector<CvArchaeologyData, true, c_eCiv5GameplayDLL, 0>& inputData, FFastVector<CvArchaeologyData, true, c_eCiv5GameplayDLL, 0>& chosenDigSites, int& result);static int ReplaceCalculateDigSiteWeight(int (*original)(int, FFastVector<CvArchaeologyData, true, c_eCiv5GameplayDLL, 0>&, FFastVector<CvArchaeologyData, true, c_eCiv5GameplayDLL, 0>&), int iIndex, FFastVector<CvArchaeologyData, true, c_eCiv5GameplayDLL, 0>& inputData, FFastVector<CvArchaeologyData, true, c_eCiv5GameplayDLL, 0>& chosenDigSites);CivRegisterBefore<CivHooks::CalculateDigSiteWeight>(host, &BeforeCalculateDigSiteWeight);CivRegisterAfter<CivHooks::CalculateDigSiteWeight>(host, &AfterCalculateDigSiteWeight);CivRegisterReplace<CivHooks::CalculateDigSiteWeight>(host, &ReplaceCalculateDigSiteWeight);
Code
11362int CalculateDigSiteWeight(int iIndex, FFastVector<CvArchaeologyData, true, c_eCiv5GameplayDLL, 0>& inputData, FFastVector<CvArchaeologyData, true, c_eCiv5GameplayDLL, 0>& chosenDigSites)11363{11364 CvMap& theMap = GC.getMap();11365 int iGridWidth = theMap.getGridWidth();11366 int iBaseWeight = 0;11367 if (chosenDigSites[iIndex].m_eArtifactType == NO_GREAT_WORK_ARTIFACT_CLASS) // if we have not already chosen this spot for a dig site11368 {11369 iBaseWeight = inputData[iIndex].m_eArtifactType + 1;11370 iBaseWeight *= (10 - inputData[iIndex].m_eEra);1137111372 int iPlotX = iIndex % iGridWidth;11373 int iPlotY = iIndex / iGridWidth;1137411375 CvPlot* pPlot = theMap.plotByIndexUnchecked(iIndex);1137611377 // zero this value if this plot has a resource, water, ice, mountain, or natural wonder11378 if (pPlot->getResourceType() != NO_RESOURCE || pPlot->isWater() || pPlot->getFeatureType() == FEATURE_ICE || pPlot->isMountain() || pPlot->IsNaturalWonder())11379 iBaseWeight = 0;1138011381 // if this tile cannot be improved, zero it out11382 if (iBaseWeight && pPlot->getFeatureType() != NO_FEATURE)11383 {11384 if (GC.getFeatureInfo(pPlot->getFeatureType())->isNoImprovement())11385 {11386 iBaseWeight = 0;11387 }11388 }1138911390 // if this tile has a GP improvement, zero it out11391 if (iBaseWeight && pPlot->getImprovementType() != NO_IMPROVEMENT)11392 {11393 if (GC.getImprovementInfo(pPlot->getImprovementType())->IsCreatedByGreatPerson())11394 {11395 iBaseWeight = 0;11396 }11397 }1139811399 if (iBaseWeight > 0)11400 {11401 // add a small random factor11402 iBaseWeight += 10 + GC.getGame().getJonRandNum(10, "random factor on dig sites");1140311404 // increase the value if unowned11405 iBaseWeight *= (pPlot->getOwner() == NO_PLAYER) ? 9 : 8;11406 iBaseWeight /= 8;1140711408 // lower the value if owned by a major11409 iBaseWeight *= (pPlot->getOwner() > NO_PLAYER && pPlot->getOwner() < MAX_MAJOR_CIVS) ? 11 : 12;11410 iBaseWeight /= 12;1141111412 // lower the value if tile has been improved11413 iBaseWeight *= (pPlot->getImprovementType() != NO_IMPROVEMENT || pPlot->getRouteType() != NO_ROUTE) ? 7 : 8;11414 iBaseWeight /= 8;1141511416 // lower the value if tile has a city11417 iBaseWeight *= (pPlot->isCity()) ? 1 : 5;11418 iBaseWeight /= 5;1141911420 // increase the value if in thematic terrain (desert, jungle, or small island)11421 iBaseWeight *= (pPlot->getTerrainType() == TERRAIN_DESERT) ? 3 : 2;11422 iBaseWeight *= (pPlot->getFeatureType() == FEATURE_JUNGLE) ? 3 : 2;11423 CvArea* pArea = theMap.getArea(pPlot->getArea());11424 iBaseWeight *= (pArea->getNumTiles() <= 4) ? 3 : 2;1142511426 // lower the value by number of neighbors11427 int iDivisor = 1;11428 // lower the value if there is at least one nearby site (say, 3 tiles distance)11429 int iRange = 3;11430 for (int iDX = -iRange; iDX <= iRange; iDX++)11431 {11432 for (int iDY = -iRange; iDY <= iRange; iDY++)11433 {11434 CvPlot* pLoopPlot = plotXYWithRangeCheck(iPlotX, iPlotY, iDX, iDY, iRange);11435 if (pLoopPlot)11436 {11437 if (chosenDigSites[pLoopPlot->GetPlotIndex()].m_eArtifactType != NO_GREAT_WORK_ARTIFACT_CLASS)11438 {11439 iDivisor++;11440 }11441 }11442 }11443 }11444 iRange = 2;11445 for (int iDX = -iRange; iDX <= iRange; iDX++)11446 {11447 for (int iDY = -iRange; iDY <= iRange; iDY++)11448 {11449 CvPlot* pLoopPlot = plotXYWithRangeCheck(iPlotX, iPlotY, iDX, iDY, iRange);11450 if (pLoopPlot)11451 {11452 if (chosenDigSites[pLoopPlot->GetPlotIndex()].m_eArtifactType != NO_GREAT_WORK_ARTIFACT_CLASS)11453 {11454 iDivisor++;11455 }11456 }11457 }11458 }11459 iRange = 1;11460 for (int iDX = -iRange; iDX <= iRange; iDX++)11461 {11462 for (int iDY = -iRange; iDY <= iRange; iDY++)11463 {11464 CvPlot* pLoopPlot = plotXYWithRangeCheck(iPlotX, iPlotY, iDX, iDY, iRange);11465 if (pLoopPlot)11466 {11467 if (chosenDigSites[pLoopPlot->GetPlotIndex()].m_eArtifactType != NO_GREAT_WORK_ARTIFACT_CLASS)11468 {11469 iDivisor++;11470 }11471 }11472 }11473 }11474 iBaseWeight /= iDivisor;11475 }11476 }11477 return iBaseWeight;11478}