Hooks
static bool BeforeCvPlayerAI_FindBestArtistTargetPlot(CvPlayerAI* self, CvUnit* pGreatArtist, int& iResultScore, CvPlot*& result);static void AfterCvPlayerAI_FindBestArtistTargetPlot(CvPlayerAI* self, CvUnit* pGreatArtist, int& iResultScore, CvPlot*& result);static CvPlot* ReplaceCvPlayerAI_FindBestArtistTargetPlot(CvPlot* (*original)(CvPlayerAI*, CvUnit*, int&), CvPlayerAI* self, CvUnit* pGreatArtist, int& iResultScore);CivRegisterBefore<CivHooks::CvPlayerAI_FindBestArtistTargetPlot>(host, &BeforeCvPlayerAI_FindBestArtistTargetPlot);CivRegisterAfter<CivHooks::CvPlayerAI_FindBestArtistTargetPlot>(host, &AfterCvPlayerAI_FindBestArtistTargetPlot);CivRegisterReplace<CivHooks::CvPlayerAI_FindBestArtistTargetPlot>(host, &ReplaceCvPlayerAI_FindBestArtistTargetPlot);
Code
1627CvPlot* CvPlayerAI::FindBestArtistTargetPlot(CvUnit* pGreatArtist, int& iResultScore)1628{1629 CvAssertMsg(pGreatArtist, "pGreatArtist is null");1630 if(!pGreatArtist)1631 {1632 return NULL;1633 }16341635 iResultScore = 0;16361637 CvPlotsVector& m_aiPlots = GetPlots();16381639 CvPlot* pBestPlot = NULL;1640 int iBestScore = 0;16411642 // loop through plots and wipe out ones that are invalid1643 const uint nPlots = m_aiPlots.size();1644 for(uint ui = 0; ui < nPlots; ui++)1645 {1646 if(m_aiPlots[ui] == -1)1647 {1648 continue;1649 }16501651 CvPlot* pPlot = GC.getMap().plotByIndex(m_aiPlots[ui]);16521653 if(pPlot->isWater())1654 {1655 continue;1656 }16571658 if(!pPlot->IsAdjacentOwnedByOtherTeam(getTeam()))1659 {1660 continue;1661 }16621663 // don't build over luxury resources1664 ResourceTypes eResource = pPlot->getResourceType();1665 if(eResource != NO_RESOURCE)1666 {1667 CvResourceInfo* pkResource = GC.getResourceInfo(eResource);1668 if(pkResource != NULL)1669 {1670 if (pkResource->getResourceUsage() == RESOURCEUSAGE_LUXURY)1671 {1672 continue;1673 }1674 }1675 }16761677 // if no improvement can be built on this plot, then don't consider it1678 FeatureTypes eFeature = pPlot->getFeatureType();1679 if (eFeature != NO_FEATURE && GC.getFeatureInfo(eFeature)->isNoImprovement())1680 {1681 continue;1682 }16831684 // Improvement already here?1685 ImprovementTypes eImprovement = (ImprovementTypes)pPlot->getImprovementType();1686 if (eImprovement != NO_IMPROVEMENT)1687 {1688 CvImprovementEntry* pkImprovementInfo = GC.getImprovementInfo(eImprovement);1689 if(pkImprovementInfo)1690 {1691 if (pkImprovementInfo->GetCultureBombRadius() > 0)1692 {1693 continue;1694 }1695 }1696 }16971698 int iScore = 0;16991700 for(int iI = 0; iI < NUM_DIRECTION_TYPES; ++iI)1701 {1702 CvPlot* pAdjacentPlot = plotDirection(pPlot->getX(), pPlot->getY(), ((DirectionTypes)iI));1703 // if there's no plot, bail1704 if(pAdjacentPlot == NULL)1705 {1706 continue;1707 }17081709 // if the plot is ours or no one's, bail1710 if(pAdjacentPlot->getTeam() == NO_TEAM || pAdjacentPlot->getTeam() == getTeam())1711 {1712 continue;1713 }17141715 // don't evaluate city plots since we don't get ownership of them with the bomb1716 if(pAdjacentPlot->getPlotCity())1717 {1718 continue;1719 }17201721 const PlayerTypes eOtherPlayer = pAdjacentPlot->getOwner();1722 if(GET_PLAYER(eOtherPlayer).isMinorCiv())1723 {1724 MinorCivApproachTypes eMinorApproach = GetDiplomacyAI()->GetMinorCivApproach(eOtherPlayer);1725 // if we're friendly or protective, don't be a jerk. Bail out.1726 if(eMinorApproach != MINOR_CIV_APPROACH_CONQUEST && eMinorApproach != MINOR_CIV_APPROACH_IGNORE)1727 {1728 iScore = 0;1729 break;1730 }1731 }1732 else1733 {1734 MajorCivApproachTypes eMajorApproach = GetDiplomacyAI()->GetMajorCivApproach(eOtherPlayer, true);1735 DisputeLevelTypes eLandDisputeLevel = GetDiplomacyAI()->GetLandDisputeLevel(eOtherPlayer);17361737 bool bTicked = eMajorApproach == MAJOR_CIV_APPROACH_HOSTILE;1738 bool bTickedAboutLand = eMajorApproach == MAJOR_CIV_APPROACH_NEUTRAL && (eLandDisputeLevel == DISPUTE_LEVEL_STRONG || eLandDisputeLevel == DISPUTE_LEVEL_FIERCE);17391740 // only bomb if we're hostile1741 if(!bTicked && !bTickedAboutLand)1742 {1743 iScore = 0;1744 break;1745 }1746 }17471748 eResource = pAdjacentPlot->getResourceType();1749 if(eResource != NO_RESOURCE)1750 {1751 iScore += GetBuilderTaskingAI()->GetResourceWeight(eResource, NO_IMPROVEMENT, pAdjacentPlot->getNumResource()) * 10;1752 }1753 else1754 {1755 for(int iYield = 0; iYield < NUM_YIELD_TYPES; iYield++)1756 {1757 iScore += pAdjacentPlot->getYield((YieldTypes)iYield);1758 }1759 }1760 }17611762 if(iScore > iBestScore)1763 {1764 iBestScore = iScore;1765 pBestPlot = pPlot;1766 }1767 }17681769 iResultScore = iBestScore;1770 return pBestPlot;1771}