Hooks
static bool BeforeCvCityCitizens_IsPlotBlockaded(const CvCityCitizens* self, CvPlot* pPlot, bool& result);static void AfterCvCityCitizens_IsPlotBlockaded(const CvCityCitizens* self, CvPlot* pPlot, bool& result);static bool ReplaceCvCityCitizens_IsPlotBlockaded(bool (*original)(const CvCityCitizens*, CvPlot*), const CvCityCitizens* self, CvPlot* pPlot);CivRegisterBefore<CivHooks::CvCityCitizens_IsPlotBlockaded>(host, &BeforeCvCityCitizens_IsPlotBlockaded);CivRegisterAfter<CivHooks::CvCityCitizens_IsPlotBlockaded>(host, &AfterCvCityCitizens_IsPlotBlockaded);CivRegisterReplace<CivHooks::CvCityCitizens_IsPlotBlockaded>(host, &ReplaceCvCityCitizens_IsPlotBlockaded);
Code
2003// Is there a naval blockade on this water tile?2004bool CvCityCitizens::IsPlotBlockaded(CvPlot* pPlot) const2005{2006 // See if there are any enemy boats near us that are blockading this plot2007 int iBlockadeDistance = /*2*/ GC.getNAVAL_PLOT_BLOCKADE_RANGE();2008 int iDX, iDY;2009 CvPlot* pNearbyPlot;20102011 PlayerTypes ePlayer = m_pCity->getOwner();20122013 // Might be a better way to do this that'd be slightly less CPU-intensive2014 for(iDX = -(iBlockadeDistance); iDX <= iBlockadeDistance; iDX++)2015 {2016 for(iDY = -(iBlockadeDistance); iDY <= iBlockadeDistance; iDY++)2017 {2018 pNearbyPlot = plotXY(pPlot->getX(), pPlot->getY(), iDX, iDY);20192020 if(pNearbyPlot != NULL)2021 {2022 // Must be water in the same Area2023 if(pNearbyPlot->isWater() && pNearbyPlot->getArea() == pPlot->getArea())2024 {2025#if defined(MOD_GLOBAL_ALLIES_BLOCK_BLOCKADES)2026 int iPlotDistance = plotDistance(pNearbyPlot->getX(), pNearbyPlot->getY(), pPlot->getX(), pPlot->getY());2027 if(iPlotDistance <= iBlockadeDistance)2028#else2029 if(plotDistance(pNearbyPlot->getX(), pNearbyPlot->getY(), pPlot->getX(), pPlot->getY()) <= iBlockadeDistance)2030#endif2031 {2032 // Enemy boat within range to blockade our plot?2033#if defined(MOD_GLOBAL_SHORT_EMBARKED_BLOCKADES)2034 if(pNearbyPlot->IsActualEnemyUnit(ePlayer, true, true))2035#else2036 if(pNearbyPlot->IsActualEnemyUnit(ePlayer))2037#endif2038 {2039#if defined(MOD_GLOBAL_ALLIES_BLOCK_BLOCKADES)2040 if (MOD_GLOBAL_ALLIES_BLOCK_BLOCKADES && iPlotDistance > 1) {2041 // Is there an allied ship in the plot?2042 if (pPlot->IsActualAlliedUnit(ePlayer)) {2043 return false;2044 }20452046 // We have an enemy ship 2 (or more) plots away,2047 // so check if we have an immediately adjacent allied ship to keep this plot open (ships in port do not count!)2048 for (int iI = 0; iI < NUM_DIRECTION_TYPES; iI++) {2049 CvPlot* pAdjacentPlot = plotDirection(pPlot->getX(), pPlot->getY(), ((DirectionTypes)iI));20502051 if (pAdjacentPlot != NULL) {2052 // Must be water in the same Area2053 if (pAdjacentPlot->isWater() && pAdjacentPlot->getArea() == pPlot->getArea()) {2054 // If there is an allied ship here the blockade from 2 (or more) tiles away is itself blocked!2055 if (pAdjacentPlot->IsActualAlliedUnit(ePlayer)) {2056 return false;2057 }2058 }2059 }2060 }2061 }2062#endif2063 return true;2064 }2065 }2066 }2067 }2068 }2069 }20702071 return false;2072}