OrionVeteran
Deity
The calculatePathDistance function in CvPlot.cpp requires a starting (source) water plot to calculate distances to other water plots. Since city plots are considered land plots, the function will fail if the source plot is a city and your are trying to find a specific water plot. However, it will work just fine searching for a surrounding land plot. To search for land, the source plot must be land. To search for water, the source plot must be water. There have been many times when I needed to search for a water plot that is a few plots away from a city.
The work around is to loop through the adjacent plots around a coastal city and select the first water plot and then make the adjacent water plot the source plot in the calculatePathDistance function. I would much prefer to have the calculation be made from the city instead of an adjacent water plot. Reason: The adjacent water plot is not centered in the city and thus I could miss my target plot on the other side of the city.
My Goal: I want the calculation to search for water plots to work from a city (land) plot.
Question: Is there a way to modify the function below to eliminate the need for the source plot to be water, when searching for water plots?
The work around is to loop through the adjacent plots around a coastal city and select the first water plot and then make the adjacent water plot the source plot in the calculatePathDistance function. I would much prefer to have the calculation be made from the city instead of an adjacent water plot. Reason: The adjacent water plot is not centered in the city and thus I could miss my target plot on the other side of the city.
My Goal: I want the calculation to search for water plots to work from a city (land) plot.
Question: Is there a way to modify the function below to eliminate the need for the source plot to be water, when searching for water plots?
Spoiler :
Code:
int CvPlot::calculatePathDistanceToPlot( TeamTypes eTeam, CvPlot* pTargetPlot )
{
PROFILE_FUNC();
FAssert(eTeam != NO_TEAM);
if( pTargetPlot->area() != area() )
{
return false;
}
// Imitate instatiation of irrigated finder, pIrrigatedFinder
// Can't mimic step finder initialization because it requires creation from the exe
std::vector<TeamTypes> teamVec;
teamVec.push_back(eTeam);
teamVec.push_back(NO_TEAM);
FAStar* pTeamStepFinder = gDLL->getFAStarIFace()->create();
gDLL->getFAStarIFace()->Initialize(pTeamStepFinder, GC.getMapINLINE().getGridWidthINLINE(), GC.getMapINLINE().getGridHeightINLINE(), GC.getMapINLINE().isWrapXINLINE(), GC.getMapINLINE().isWrapYINLINE(), stepDestValid, stepHeuristic, stepCost, teamStepValid, stepAdd, NULL, NULL);
gDLL->getFAStarIFace()->SetData(pTeamStepFinder, &teamVec);
FAStarNode* pNode;
int iPathDistance = -1;
gDLL->getFAStarIFace()->GeneratePath(pTeamStepFinder, getX_INLINE(), getY_INLINE(), pTargetPlot->getX_INLINE(), pTargetPlot->getY_INLINE(), false, 0, true);
pNode = gDLL->getFAStarIFace()->GetLastNode(&GC.getStepFinder());
if (pNode != NULL)
{
iPathDistance = pNode->m_iData1;
}
gDLL->getFAStarIFace()->destroy(pTeamStepFinder);
return iPathDistance;
}