diff --git a/Project Files/DLLSources/CvUnit.cpp b/Project Files/DLLSources/CvUnit.cpp index 589113d81..c9652bb87 100644 --- a/Project Files/DLLSources/CvUnit.cpp +++ b/Project Files/DLLSources/CvUnit.cpp @@ -10116,6 +10116,27 @@ int CvUnit::getArea() const return pPlot->getArea(); } +// get the areaID of a plot in the 3x3 area with the unit in the center +int CvUnit::getLandArea() const +{ + if (getX_INLINE() != INVALID_PLOT_COORD && getY_INLINE() != INVALID_PLOT_COORD) + { + // scanning the 3x3 area + // Use plotCity for order as this will start with the center plot + // This means unless the unit is on water (like large river), the result will be the same as getArea() + for (int i = 0; i < 9; ++i) + { + const CvPlot* pPlot = plotCity(getX_INLINE(), getY_INLINE(), i); + if (pPlot != NULL && !pPlot->isWater()) + { + return pPlot->getArea(); + } + } + } + + // failed to locate land. Rely on vanilla code for what to do now + return getArea(); +} CvArea* CvUnit::area() const { diff --git a/Project Files/DLLSources/CvUnit.h b/Project Files/DLLSources/CvUnit.h index a80ccaf02..4db16a7c2 100644 --- a/Project Files/DLLSources/CvUnit.h +++ b/Project Files/DLLSources/CvUnit.h @@ -424,6 +424,7 @@ class CvUnit : public CvDLLEntity DllExport CvPlot* plot() const; CvCity* getCity() const; int getArea() const; + int getLandArea() const; CvArea* area() const; int getLastMoveTurn() const; void setLastMoveTurn(int iNewValue); diff --git a/Project Files/DLLSources/CvUnitAI.cpp b/Project Files/DLLSources/CvUnitAI.cpp index 8cc5aa66d..5a23147cf 100644 --- a/Project Files/DLLSources/CvUnitAI.cpp +++ b/Project Files/DLLSources/CvUnitAI.cpp @@ -18131,7 +18131,7 @@ bool CvUnitAI::AI_plotValid(CvPlot* pPlot) case DOMAIN_LAND: //WTP, ray, Large Rivers - making sure that AI generally considers Large Rivers valid for Land Plots // if (pPlot->getArea() == getArea() || m_pUnitInfo->isCanMoveAllTerrain()) - if (pPlot->getArea() == getArea() || m_pUnitInfo->isCanMoveAllTerrain() || pPlot->getTerrainType() == TERRAIN_LARGE_RIVERS) + if (pPlot->getArea() == getLandArea() || m_pUnitInfo->isCanMoveAllTerrain() || pPlot->getTerrainType() == TERRAIN_LARGE_RIVERS) { return true; }