Skip to content

Commit

Permalink
Fix #449: AI Settlers getting stuck on river fords
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightinggale committed May 5, 2021
1 parent 09c5c4f commit 44a1410
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Project Files/DLLSources/CvUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions Project Files/DLLSources/CvUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Project Files/DLLSources/CvUnitAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 44a1410

Please sign in to comment.