Hooks
static bool BeforeCvUnit_GetMovablePlotListOpt(CvUnit* self, vector<CvPlot*>& plotData, CvPlot* plotTarget, bool exitOnFound, bool bIgnoreFriendlyUnits);static void AfterCvUnit_GetMovablePlotListOpt(CvUnit* self, vector<CvPlot*>& plotData, CvPlot* plotTarget, bool exitOnFound, bool bIgnoreFriendlyUnits);static void ReplaceCvUnit_GetMovablePlotListOpt(void (*original)(CvUnit*, vector<CvPlot*>&, CvPlot*, bool, bool), CvUnit* self, vector<CvPlot*>& plotData, CvPlot* plotTarget, bool exitOnFound, bool bIgnoreFriendlyUnits);CivRegisterBefore<CivHooks::CvUnit_GetMovablePlotListOpt>(host, &BeforeCvUnit_GetMovablePlotListOpt);CivRegisterAfter<CivHooks::CvUnit_GetMovablePlotListOpt>(host, &AfterCvUnit_GetMovablePlotListOpt);CivRegisterReplace<CivHooks::CvUnit_GetMovablePlotListOpt>(host, &ReplaceCvUnit_GetMovablePlotListOpt);
Code
21892#if defined(MOD_AI_SMART_V3)21893//AMS: Optimized function to retrieve free plots for move and fire.21894void CvUnit::GetMovablePlotListOpt(vector<CvPlot*>& plotData, CvPlot* plotTarget, bool exitOnFound, bool bIgnoreFriendlyUnits)21895{21896 VALIDATE_OBJECT21897 CvAStarNode* pNode;21898 int xVariance = max(abs((getX() - plotTarget->getX()) / 2), 1);21899 int yVariance = max(abs((getY() - plotTarget->getY()) / 2), 1);21900 int xMin = min(getX(), plotTarget->getX()) - yVariance;21901 int xMax = max(getX(), plotTarget->getX()) + yVariance;21902 int yMin = min(getY(), plotTarget->getY()) - xVariance;21903 int yMax = max(getY(), plotTarget->getY()) + xVariance;2190421905 for(int iDX = xMin; iDX <= xMax; iDX++)21906 {21907 for(int iDY = yMin; iDY <= yMax; iDY++)21908 {21909 if (GC.getMap().isPlot(iDX, iDY))21910 {21911 CvPlot* currentPlot = GC.getMap().plotCheckInvalid(iDX, iDY);2191221913 if (currentPlot->isUnit())21914 {21915 if (!bIgnoreFriendlyUnits)21916 {21917 continue;21918 }21919 UnitHandle pFriendlyUnit = currentPlot->getBestDefender(GET_PLAYER(getOwner()).GetID());21920 if (!pFriendlyUnit)21921 {21922 continue;21923 }21924 }2192521926 // Check is valid plot21927 if ((currentPlot != NULL) && !currentPlot->isImpassable() && !currentPlot->isCity())21928 {21929 //Check plot is in unit range21930 if (GetRange() >= plotDistance(currentPlot->getX(), currentPlot->getY(), plotTarget->getX(), plotTarget->getY()))21931 {21932 // Updated this part based on AUI that checks the movement left for siegue.21933 if(canEverRangeStrikeAt(plotTarget->getX(), plotTarget->getY(), currentPlot))21934 {21935 pNode = NULL;21936 GC.GetTacticalAnalysisMapFinder().SetData(this);21937 if (GC.GetTacticalAnalysisMapFinder().GeneratePath(getX(), getY(), currentPlot->getX(), currentPlot->getY(), MOVE_UNITS_IGNORE_DANGER | MOVE_IGNORE_STACKING, false))21938 {21939 pNode = GC.GetTacticalAnalysisMapFinder().GetLastNode();21940 }21941 if (pNode)21942 {21943 if (pNode->m_iData2 == 1 && pNode->m_iData1 > (isMustSetUpToRangedAttack() ? 1 : 0))21944 {21945 plotData.push_back(currentPlot);2194621947 if (exitOnFound)21948 {21949 return;21950 }21951 }21952 }21953 }21954 }21955 }21956 }21957 }21958 }21959}