public List <MovementAlgorithmTile> GetMVChoice(Squad ActiveSquad) { int StartingMV = GetSquadMaxMovement(ActiveSquad);//Maximum distance you can reach. StartingMV += ActiveSquad.CurrentLeader.Boosts.MovementModifier; //Init A star. List <MovementAlgorithmTile> ListAllNode = Pathfinder.FindPath(GetAllTerrain(ActiveSquad), ActiveSquad, ActiveSquad.CurrentLeader.UnitStat, StartingMV); List <MovementAlgorithmTile> MovementChoice = new List <MovementAlgorithmTile>(); for (int i = 0; i < ListAllNode.Count; i++) { ListAllNode[i].ParentTemp = null;//Unset parents ListAllNode[i].MovementCost = 0; bool UnitFound = false; for (int P = 0; P < ListPlayer.Count && !UnitFound; P++) { int SquadIndex = CheckForSquadAtPosition(P, new Vector3(ListAllNode[i].Position.X, ListAllNode[i].Position.Y, ListAllNode[i].LayerIndex), Vector3.Zero); if (SquadIndex >= 0) { UnitFound = true; } } //If there is no Unit. if (!UnitFound) { MovementChoice.Add(ListAllNode[i]); } } return(MovementChoice); }
public List <Vector3> GetMVChoice(Squad CurrentSquad) { int StartingMV = GetSquadMaxMovement(CurrentSquad);//Maximum distance you can reach. StartingMV += CurrentSquad.CurrentLeader.Boosts.MovementModifier; for (int X = -StartingMV; X <= StartingMV; X++) { for (int Y = -StartingMV; Y <= StartingMV; Y++) { if (CurrentSquad.X + X < 0 || CurrentSquad.X + X >= MapSize.X || CurrentSquad.Y + Y < 0 || CurrentSquad.Y + Y >= MapSize.Y) { continue; } GetTerrain(CurrentSquad.X + X, CurrentSquad.Y + Y, CurrentSquad.LayerIndex).Parent = null; bool UnitFound = false; for (int P = 0; P < ListPlayer.Count && !UnitFound; P++) {//Only check for enemies, can move through allies, can't move through ennemies. if (ListPlayer[P].Team == ListPlayer[ActivePlayerIndex].Team) { continue; } //Check if there's a Unit. //If a Unit was found. if (CheckForObstacleAtPosition(P, CurrentSquad.Position, new Vector3(X, Y, 0))) { UnitFound = true; } } //If there is an enemy Unit. if (UnitFound) { GetTerrain(CurrentSquad.X + X, CurrentSquad.Y + Y, CurrentSquad.LayerIndex).MovementCost = -1;//Make it impossible to go there. } else { GetTerrain(CurrentSquad.X + X, CurrentSquad.Y + Y, CurrentSquad.LayerIndex).MovementCost = 0; } } } //Init A star. List <MovementAlgorithmTile> ListAllNode = Pathfinder.FindPath(GetTerrain(CurrentSquad.X, CurrentSquad.Y, CurrentSquad.LayerIndex), CurrentSquad, CurrentSquad.CurrentLeader.UnitStat, StartingMV); List <Vector3> MovementChoice = new List <Vector3>(); for (int i = 0; i < ListAllNode.Count; i++) { bool UnitFound = false; for (int P = 0; P < ListPlayer.Count && !UnitFound; P++) { int SquadIndex = CheckForSquadAtPosition(P, ListAllNode[i].Position, Vector3.Zero); if (SquadIndex >= 0) { UnitFound = true; } } //If there is no Unit. if (!UnitFound) { MovementChoice.Add(ListAllNode[i].Position); } } return(MovementChoice); }