here are two codes to help
sorry no time to explain
Code:
private void FindNearestMarker(out Point2d target, Point2d basePoint, int army) // piano, I find the nearest marker to the country
{
Point2d res = new Point2d(-1,-1);
double minDist = 9999999999.9 ;
foreach (MissionMarker mm in MissionMarkers)
{
if (mm.army == army)
{
double curDist = Math.Sqrt(Math.Pow((basePoint.x - mm.x),2 )+ Math.Pow((basePoint.y - mm.y),2));
if (curDist < minDist)
{
minDist = curDist;
res.x = mm.x; res.y = mm.y;
}
}
}
target = res;
}
Code:
private bool PointBetween(double intervalPoint1,double intervalPoint2,double point) // kh-n checks whether the point lies in the interval
{
return ((point > Math.Min(intervalPoint1, intervalPoint2)) && (point < Math.Max(intervalPoint1, intervalPoint2)));
}
private void FindFinishPoint(out Point2d target,Point2d startPoint, int army) // piano, I find the final destination
{
Point2d res = new Point2d(-1, -1);
int enemyArmy = (army == 1) ? 2 : 1;
Point2d nearestEnemyMarker;
Point3d startPos = new Point3d(startPoint.x, startPoint.y,0);
FindNearestMarker(out nearestEnemyMarker, startPoint, enemyArmy); // first find the closest enemy marker
AiActor nearestEnemyGG = FindGroundTarget(enemyArmy, startPos); // then the nearest group of enemy
if (nearestEnemyGG != null)
{
if ((PointBetween(startPoint.x, nearestEnemyMarker.x, nearestEnemyGG.Pos().x)) && (PointBetween(startPoint.y, nearestEnemyMarker.y, nearestEnemyGG.Pos().y)))
{
res.x = nearestEnemyGG.Pos().x;
res.y = nearestEnemyGG.Pos().y;
}
else res = nearestEnemyMarker; // and select one of them is closer
}
target = res;
}