public static List<int> GetAdjacentCells(Map Map, int Cell) { var Cells = new List<int>(); for (int i = 1; i < 8; i += 2) Cells.Add(Pathfinding.NextCell(Map, Cell, i)); return Cells; }
public Pathfinding(string path, Map map, int startCell, int startDir, bool trigger = false) { strPath = path; this.map = map; this.startCell = startCell; this.startDir = startDir; this.trigger = trigger; }
public static int GetCellYCoord(Map map, int cellID) { int width = map.Model.Width; int loc5 = (int)(cellID / ((width * 2) - 1)); int loc6 = cellID - loc5 * ((width * 2) - 1); int loc7 = loc6 % width; return (loc5 - loc7); }
public static List<int> GetCrossCells(Map Map, int CurrentCell, int Radius) { var Cells = new List<int>(); foreach (var Cell in GetCircleCells(Map, CurrentCell, Radius)) if (Pathfinding.InLine(Map, CurrentCell, Cell)) Cells.Add(Cell); return Cells; }
public static List<int> GetTLineCells(Map Map, int Cell, int Direction, int Length) { var LineDirection = Direction <= 5 ? Direction + 2 : Direction - 6; var Cells = new List<int>(); Cells.AddRange(GetLineCells(Map, Cell, LineDirection, Length)); Cells.AddRange(GetLineCells(Map, Cell, Pathfinding.OppositeDirection(LineDirection), Length)); return Cells; }
public static List<int> GetLineCells(Map Map, int Cell, int Direction, int Length) { var Cells = new List<int>(); var LastCell = Cell; for (int i = 0; i < Length; i++) { Cells.Add(Pathfinding.NextCell(Map, LastCell, Direction)); LastCell = Cells[i]; } return Cells; }
public static List<int> GetCircleCells(Map Map, int CurrentCell, int Radius) { var Cells = new List<int>() { CurrentCell }; for (int i = 0; i < Radius; i++) { var Copy = Cells.ToArray(); foreach (var Cell in Copy) Cells.AddRange(from Item in GetAdjacentCells(Map, Cell) where !Cells.Contains(Item) select Item); } return Cells; }
public static List<int> GetCells(Map Map, int Cell, int CurrentCell, string Range) { switch (Range[0]) { case 'C': return GetCircleCells(Map, Cell, Basic.HASH.IndexOf(Range[1])); case 'X': return GetCrossCells(Map, Cell, Basic.HASH.IndexOf(Range[1])); case 'T': var Cells1 = new List<int> { Cell }; Cells1.AddRange(GetTLineCells(Map, Cell, Pathfinding.GetDirection(Map, CurrentCell, Cell), Basic.HASH.IndexOf(Range[1]))); return Cells1; case 'L': var Cells2 = new List<int> { Cell }; Cells2.AddRange(GetLineCells(Map, Cell, Pathfinding.GetDirection(Map, CurrentCell, Cell), Basic.HASH.IndexOf(Range[1]))); return Cells2; } return new List<int>() { Cell }; }
public static int GetCellXCoord(Map map, int cellID) { int width = map.Model.Width; return ((cellID - (width - 1) * GetCellYCoord(map, cellID)) / width); }
public static int NextCell(Map map, int cell, int dir) { switch (dir) { case 0: return cell + 1; case 1: return cell + map.Model.Width; case 2: return cell + (map.Model.Width * 2) - 1; case 3: return cell + map.Model.Width - 1; case 4: return cell - 1; case 5: return cell - map.Model.Width; case 6: return cell - (map.Model.Width * 2) + 1; case 7: return cell - map.Model.Width + 1; } return -1; }
public static bool InLine(Map map, int cell1, int cell2) { bool isX = GetCellXCoord(map, cell1) == GetCellXCoord(map, cell2); bool isY = GetCellYCoord(map, cell1) == GetCellYCoord(map, cell2); return isX || isY; }
public static int GetDistanceBetween(Map map, int id1, int id2) { if (id1 == id2 || map == null) return 0; int diffX = Math.Abs(GetCellXCoord(map, id1) - GetCellXCoord(map, id2)); int diffY = Math.Abs(GetCellYCoord(map, id1) - GetCellYCoord(map, id2)); return (diffX + diffY); }
public static int GetDirection(Map map, int cell1, int cell2) { int[] ListChange = new int[] { 1, map.Model.Width, map.Model.Width * 2 - 1, map.Model.Width - 1, -1, -map.Model.Width, -map.Model.Width * 2 + 1, -(map.Model.Width - 1) }; int Result = cell2 - cell1; for (int i = 7; i > -1; i--) if (Result == ListChange[i]) return i; int ResultX = GetCellXCoord(map, cell2) - GetCellXCoord(map, cell1); int ResultY = GetCellYCoord(map, cell2) - GetCellYCoord(map, cell1); if (ResultX == 0) if (ResultY > 0) return 3; else return 7; else if (ResultX > 0) return 1; else return 5; }