/*************************************************************************************************/
/** BETTER AI (UNITAI_SETTLE move) Sephi **/
/** **/
/** **/
/*************************************************************************************************/
//reset values after first city is build
if (GET_PLAYER(getOwnerINLINE()).getNumCities() == 1 && getGroup()->getNumUnits()==1)
{
GET_PLAYER(getOwnerINLINE()).AI_updateFoundValues(false);
}
if (GET_PLAYER(getOwnerINLINE()).getNumCities() == 0)
{
if (GC.getGameINLINE().getGameTurn()==0)
{
GET_PLAYER(getOwnerINLINE()).AI_updateFoundValues(false);
CvPlot* pLoopPlot;
CvPlot* pBestPlot;
int iSearchRange;
int iPathTurns;
int iValue;
int iBestValue;
int iDX, iDY;
iSearchRange = GC.getWorldInfo(GC.getMapINLINE().getWorldSize()).getAISettlerMove();
int iRange = 6;
iBestValue = 0;
pBestPlot = NULL;
for (iDX = -(iSearchRange); iDX <= iSearchRange; iDX++)
{
for (iDY = -(iSearchRange); iDY <= iSearchRange; iDY++)
{
pLoopPlot = plotXY(getX_INLINE(), getY_INLINE(), iDX, iDY);
if (pLoopPlot != NULL)
{
if ((AI_plotValid(pLoopPlot)) && canFound(pLoopPlot))
{
if (!pLoopPlot->isVisibleEnemyUnit(this))
{
if (generatePath(pLoopPlot, 0, true, &iPathTurns))
{
if (iPathTurns<3)
{
iValue = pLoopPlot->getFoundValue(getOwnerINLINE());
if (iValue > iBestValue)
{
iBestValue = iValue;
pBestPlot = pLoopPlot;
}
}
}
}
}
}
}
}
if (pBestPlot != NULL)
{
if(atPlot(pBestPlot))
{
getGroup()->pushMission(MISSION_FOUND);
return;
}
else
{
getGroup()->pushMission(MISSION_MOVE_TO, pBestPlot->getX_INLINE(), pBestPlot->getY_INLINE());
// Teleport other units to this plot
if (GC.getGameINLINE().getGameTurn()<4)
{
CvUnit* pLoopUnit;
int iLoop;
for(pLoopUnit = GET_PLAYER(getOwnerINLINE()).firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = GET_PLAYER(getOwnerINLINE()).nextUnit(&iLoop))
{
if (pLoopUnit)
{
if (pLoopUnit!=this)
{
if(!at(pBestPlot->getX_INLINE(),pBestPlot->getY_INLINE()))
{
pLoopUnit->setXY(pBestPlot->getX_INLINE(),pBestPlot->getY_INLINE());
}
}
}
}
}
return;
}
}
}
if (canFound(plot()))
{
getGroup()->pushMission(MISSION_FOUND);
return;
}
//haven't found a City after 3 turns?
if (GC.getGameINLINE().getGameTurn()>3)
{
CvPlot* pLoopPlot;
CvPlot* pBestPlot;
int iSearchRange;
int iPathTurns;
int iValue;
int iBestValue;
int iDX, iDY;
iSearchRange = 6;
int iRange = 6;
iBestValue = 0;
pBestPlot = NULL;
for (iDX = -(iSearchRange); iDX <= iSearchRange; iDX++)
{
for (iDY = -(iSearchRange); iDY <= iSearchRange; iDY++)
{
pLoopPlot = plotXY(getX_INLINE(), getY_INLINE(), iDX, iDY);
if (pLoopPlot != NULL)
{
if ((AI_plotValid(pLoopPlot)) && canFound(pLoopPlot))
{
if (!pLoopPlot->isVisibleEnemyUnit(this))
{
if (generatePath(pLoopPlot, 0, true, &iPathTurns))
{
if (iPathTurns<3)
{
iValue = pLoopPlot->getFoundValue(getOwnerINLINE());
if (iValue > iBestValue)
{
iBestValue = iValue;
pBestPlot = pLoopPlot;
FAssert(!atPlot(pBestPlot));
}
}
}
}
}
}
}
}
if (pBestPlot != NULL)
{
if(atPlot(pBestPlot))
{
getGroup()->pushMission(MISSION_FOUND);
return;
}
else
{
getGroup()->pushMission(MISSION_MOVE_TO, pBestPlot->getX_INLINE(), pBestPlot->getY_INLINE());
return;
}
}
}
}
int iNeededPatrol=4;
if (GET_TEAM(getTeam()).isBarbarianAlly())
{
iNeededPatrol=2;
}
if (plot()->isCity() && getGroup()->getNumUnits()<iNeededPatrol)
{
if (plot()->getOwnerINLINE()==getOwnerINLINE())
{
CLLNode<IDInfo>* pUnitNode;
CvUnit* pLoopUnit;
pUnitNode = plot()->headUnitNode();
while (pUnitNode != NULL)
{
pLoopUnit = ::getUnit(pUnitNode->m_data);
pUnitNode = plot()->nextUnitNode(pUnitNode);
if (pLoopUnit)
{
if (pLoopUnit->AI_getGroupflag()==GROUPFLAG_SETTLERGROUP)
{
joinGroup(pLoopUnit->getGroup());
getGroup()->pushMission(MISSION_SKIP);
return;
}
}
}
getGroup()->pushMission(MISSION_SKIP);
return;
}
}
if (getGroup()->getNumUnits()<iNeededPatrol)
{
if (plot()->isCity())
{
getGroup()->pushMission(MISSION_SKIP);
return;
}
}
/*************************************************************************************************/
/** END **/
/*************************************************************************************************/