/// <summary> /// Highlights all the hexagons in a distance of the designated type /// </summary> public void HighlightLOSNeighbors(Hexagon currentlyOccupiedHexagon, int distance, AbilityDescription.TargetType targetType, bool TemplateUse) { visited.Clear(); frontier.Clear(); distanceQueue.Clear(); frontier.Enqueue(currentlyOccupiedHexagon); //Starting hex visited.Add(currentlyOccupiedHexagon); TemplateManager.instance.TargetHexagons.Clear(); currentlyOccupiedHexagon.DisableLOSCollider(); Queue <Hexagon> activeQueue = frontier; Queue <Hexagon> inactiveQueue = distanceQueue; while (activeQueue.Count > 0 && distance > 0) //Breadth first search { Hexagon curr = activeQueue.Dequeue(); foreach (Hexagon h in GetNeighborsAbilityCast(curr)) { if (inLOS(currentlyOccupiedHexagon, h) && !visited.Contains(h)) { inactiveQueue.Enqueue(h); visited.Add(h); } } if (activeQueue.Count == 0) //Switching between active and inactive queues to track distance { Queue <Hexagon> t = activeQueue; activeQueue = inactiveQueue; inactiveQueue = t; distance--; } } foreach (Hexagon h in visited) //Highlight the hexagons we found { if (HexagonCastable(h, targetType)) { h.Highlight(); HighlightedHexagons.Add(h); if (TemplateUse) { TemplateManager.instance.TargetHexagons.Add(h); } } else { h.EnableLOSCollider(); //If we cant cast on this hex, reenable the collider so we know its not a valid target } } }
/// <summary> /// Highlights all the hexagons in a distance of the designated type /// </summary> public List <PlayerControlledBoardUnit> GetEnemiesInRange(Hexagon currentlyOccupiedHexagon, int distance, AbilityDescription.TargetType targetType) { visited.Clear(); frontier.Clear(); distanceQueue.Clear(); frontier.Enqueue(currentlyOccupiedHexagon); //Starting hex visited.Add(currentlyOccupiedHexagon); currentlyOccupiedHexagon.DisableLOSCollider(); Queue <Hexagon> activeQueue = frontier; Queue <Hexagon> inactiveQueue = distanceQueue; while (activeQueue.Count > 0 && distance > 0) //Breadth first search { Hexagon curr = activeQueue.Dequeue(); foreach (Hexagon h in GetNeighborsAbilityCast(curr)) { if (inLOS(currentlyOccupiedHexagon, h) && !visited.Contains(h)) { inactiveQueue.Enqueue(h); visited.Add(h); } } if (activeQueue.Count == 0) //Switching between active and inactive queues to track distance { Queue <Hexagon> t = activeQueue; activeQueue = inactiveQueue; inactiveQueue = t; distance--; } } List <PlayerControlledBoardUnit> targets = new List <PlayerControlledBoardUnit>(); foreach (Hexagon h in visited) //Highlight the hexagons we found { if (HexagonTargettable(h)) { targets.Add(h.OccupiedUnit as PlayerControlledBoardUnit); } h.EnableLOSCollider(); } return(targets); }
/// <summary> /// Checks if a destination hexagon is in LOS of the source, it checks for a collider, if it exists it disables the collider /// so that it doesnt block future raycasts, and also indicates that the box is in LOS /// </summary> protected bool inLOS(Hexagon source, Hexagon destination) { RaycastHit hit; if (Physics.Linecast(source.transform.position, destination.transform.position, out hit, 1 << 11)) { if (hit.transform.parent.GetComponent <Hexagon>() && Mathf.Abs(source.HexHeight - hit.transform.parent.GetComponent <Hexagon>().HexHeight) > 3) { return(false); } if (hit.transform.parent.GetComponent <Hexagon>() && LOSHexagon(hit.transform.parent.GetComponent <Hexagon>())) { destination.DisableLOSCollider(); return(true); } } return(false); }