public HashSet <Vector3Int> GetViable(Vector3Int current, int team, int mobilityLeft, Dictionary <Territory.Type, int> mods, HashSet <Vector3Int> visitedBefore) { HashSet <Vector3Int> visited = visitedBefore; visited.Add(current); // TODO: check if unit is here if (CanMoveOver(team)) { for (int i = 0; i < 6; i++) { Vector3Int neighbour = GetNeighbour(current, i); Territory t = map.GetTerritoryAt(neighbour); if (t != null) { Territory.Type type = t.GetTerritoryType(); if (mods.ContainsKey(type)) { int cost = mods[type]; if (cost <= mobilityLeft) { // move there and recalculate visited = GetViable(neighbour, team, mobilityLeft - cost, mods, visited); } } } // else just skip } } return(visited); }
private static HashSet <Vector3Int> PathFromNeighbours(TerrainManager map, HashSet <Vector3Int> visitedBefore, Vector3Int current, ArmyUnit unit, int mobilityLeft) { HashSet <Vector3Int> visited = visitedBefore; for (int i = 0; i < 6; i++) { Vector3Int neighbour = GetNeighbour(current, i); Territory t = map.GetTerritoryAt(neighbour); if (t != null) { // t we can move Territory.Type type = t.GetTerritoryType(); int cost = unit.TerrainCost(type); if (cost >= 0 && cost <= mobilityLeft && CanMoveOver(map, unit, current)) { visited.Add(current); visited = NeighbourPath(map, visited, neighbour, unit, mobilityLeft - cost); } } } return(visited); }