public override bool ResolveLocation(MissionInProgress missionInProgress) { //if the mission structure is not set AND anyLocation is true if (!ValidMissionStructureEidSet && !deliverAtAnyLocation) { //pick a location => fieldTerminal or dockingBase var possibleLocations = missionDataCache.GetAllLocations .Where(l => l.ZoneConfig.Id == missionInProgress.myLocation.ZoneConfig.Id && missionInProgress.SearchOrigin.IsInRangeOf2D(l.MyPosition, TargetPositionRange) && l.LocationEid != missionInProgress.myLocation.LocationEid).ToArray(); if (possibleLocations.Length == 0) { Log("no possible delivery location was found for " + this + " " + missionInProgress); return(false); } Log("possible delivery locations: " + possibleLocations.Length); possibleLocations = possibleLocations.Except(missionInProgress.SelectedLocations).ToArray(); Log("except choosen: " + possibleLocations.Length); var minimumDistance = double.MaxValue; MissionLocation closestLocation = null; foreach (var missionLocation in possibleLocations) { var distance = missionLocation.MyPosition.TotalDistance2D(missionInProgress.myLocation.MyPosition); if (distance < minimumDistance) { closestLocation = missionLocation; minimumDistance = distance; } } //complier shutup if (closestLocation == null) { return(false); } Log("the closest location is " + closestLocation); //this is going to be saved to sql missionStructureEid = closestLocation.LocationEid; //other data to work with targetPositionX = (int)closestLocation.X; targetPositionY = (int)closestLocation.Y; targetPositionZone = closestLocation.ZoneConfig.Id; //comfy init SetTargetPosition_RandomTarget(); //pass the found position on missionInProgress.SearchOrigin = targetPosition; //and mark the choosen location used missionInProgress.AddToSelectedLocations(closestLocation); } return(base.ResolveLocation(missionInProgress)); }