public MarkersSet GetFireZoneForMoveZone(Unit unit, MarkersSet moveZone = null) { if (moveZone == null) { moveZone = GetMoveZone(unit); } MarkersSet fullFireZone = new MarkersSet(); fullFireZone.Add(GetFireZoneFromCoord(unit.Coordinate, unit)); var moveCoords = moveZone.GetCoordList(); int availableActionPoints; foreach (var coord in moveCoords) { if (this[coord].Unit != null) { continue; } availableActionPoints = moveZone[coord]; if (availableActionPoints > 0) { fullFireZone.Add(GetFireZoneFromCoord(coord, unit)); } } return(fullFireZone); }
internal void Add(MarkersSet markers) { foreach (var marker in markers.elements) { if (marker.Value > Empty) { if (!elements.ContainsKey(marker.Key)) { elements.Add(marker.Key, marker.Value); } } } }
private MarkersSet GetFireZoneFromCoord(Coord coord, Unit unit) { MarkersSet fireMarkers = new MarkersSet(); for (int i = -unit.MaxFireRange; i <= unit.MaxFireRange; i++) { for (int j = -unit.MaxFireRange; j <= unit.MaxFireRange; j++) { var distance = CubeDistance(i, j); var distanceIsActual = unit.MinFireRange <= distance && distance <= unit.MaxFireRange; var currentCoord = new Coord(i, j) + coord; var hasEnemyUnit = this[currentCoord].HasEnemyUnit(unit.Faction); var hasEnemyCity = this[currentCoord].HasEnemyCity(unit.Faction); var hasEnemyForAttack = hasEnemyCity || hasEnemyUnit; if (distanceIsActual && hasEnemyForAttack) { fireMarkers[currentCoord] = 1; } } } return(fireMarkers); }
public void MoveUnit(Coord from, Coord to, MarkersSet moveMarkers) { if (from == to) { return; } if (this[from].Unit != null && this[to].Unit == null) { var path = TryFindPath(from, to, moveMarkers); // TODO find separately for unit var actionPoints = this[from].Unit.ActionPoints - moveMarkers[to]; this[to].Unit = this[from].Unit; this[from].Unit = null; this[to].Unit.SetPositionTo(to, actionPoints); AddAction(new MoveAction(this[to].Unit, from, to, actionPoints, path)); } #if UNITY_EDITOR else { Debug.LogError("move unit error - unit not found or place is not empty"); } #endif }
public Coord FindOptimalMovePoint(Unit unit, MarkersSet moveMarkers, Coord fireCoord) { var moveCoords = moveMarkers.GetCoordList(); int bestMarker = 0; Coord nearestCoord = Coord.Zero; foreach (var moveCoord in moveCoords) { if (moveMarkers[moveCoord] > bestMarker && (this[moveCoord].Unit == unit || this[moveCoord].Unit == null)) { if (IsCanFireFromCoord(unit, moveCoord, fireCoord)) { nearestCoord = moveCoord; bestMarker = moveMarkers[moveCoord]; } } } if (nearestCoord == Coord.Zero) { Debug.LogError("Can't find nearest fire point"); } return(nearestCoord); }
public List <Coord> TryFindPath(Coord from, Coord to, MarkersSet moveMarkers) { return(Navigation.TryFindPath(from, to, moveMarkers)); }