public override void UpdateTurn() { base.UpdateTurn(); TileProperties nextTile = tile.GetNeighbor(direction); // Remove last wind bool destroy = false; if (!previous && !previousAlreadyUpdated) { tile.wind = null; for (int i = 0; i < next.Count; i++) { next[i].previous = null; if (!next[i].updated) { next[i].previousAlreadyUpdated = true; } } RemoveFromTurnManager(); EndTurn(); destroy = true; } // Add wind at begin if (nextTile && !nextTile.wind && !nextTile.whirlwind && !TryCreateNewWind(direction)) { TryCreateNewWind(direction.Previous()); TryCreateNewWind(direction.Next()); } else if (nextTile && nextTile.wind && !next.Contains(nextTile.wind)) { nextTile.wind.DestroyWind(); Whirlwind newWhirlwind = WindManager.Instance.WhirldwindsPool.Pop(); newWhirlwind.transform.position = nextTile.transform.position; nextTile.whirlwind = newWhirlwind; nextTile.whirlwind.InitializeWhirlwind(nextTile); } if (destroy) { DestroyWind(); } previousAlreadyUpdated = false; EndTurn(); }
public void ExtendRiver(HexagonalGrid grid) { TileProperties tile = grid.GetTile(source); if (!tile) { return; } TileProperties neigh = tile.GetNeighbor(counterClockwise ? direction.Previous().Previous() : direction.Next().Next()); if (!neigh) { return; } if (state == 0) { force--; neigh.SetRiver(direction, this); state = 1; } else { force--; neigh.SetRiver(counterClockwise ? direction.Previous() : direction.Next(), this); source = neigh.Coordinates; state = 0; } }
public void PutLac(HexagonalGrid grid) { if (!doLake) { return; } TileProperties tile = grid.GetTile(source); if (!tile) { return; } TileProperties neigh = tile.GetNeighbor(counterClockwise ? direction.Previous().Previous() : direction.Next().Next()); if (!neigh) { return; } if (state == 0) { neigh.asLake = true; state = 1; } else { TileProperties lakePos = neigh.GetNeighbor(counterClockwise ? direction.Previous() : direction.Next()); lakePos.asLake = true; state = 0; } }
public override void UpdateTurn() { base.UpdateTurn(); if (turnCount == turnsBetweenSqualls && currentSquallLength < size) { Wind newWind = WindManager.Instance.WindsPool.Pop(); newWind.InitializeChildWind(tile.GetNeighbor(direction), null, direction); if (currentSquallLength > 0) { for (int i = 0; i < lastProduced.next.Count; i++) { lastProduced.next[i].previous = newWind; newWind.next.Add(lastProduced.next[i]); } lastProduced.previous = newWind; } lastProduced = newWind; currentSquallLength++; } else if (turnCount == turnsBetweenSqualls) { currentSquallLength = 0; turnCount = 1; } else { turnCount++; } EndTurn(); }
public void TryExpandCorridor(ref Stack <TileProperties> remainingTiles, TileProperties affectedTile, HexDirection previousDirection) { TileProperties nextTile = affectedTile.GetNeighbor(previousDirection); if (affectedTile.Tile && nextTile.Tile && !ExpandCorridor(ref remainingTiles, affectedTile, previousDirection)) { ExpandCorridor(ref remainingTiles, affectedTile, previousDirection.Previous()); ExpandCorridor(ref remainingTiles, affectedTile, previousDirection.Next()); } }
public bool ExpandCorridor(ref Stack <TileProperties> remainingTiles, TileProperties affectedTile, HexDirection nextDirection) { TileProperties nextTile = affectedTile.GetNeighbor(nextDirection); if (!nextTile.Tile) { return(false); } else if (CanCreateWindOnTile(nextTile)) { nextTile.nextTilesInCorridor.Add(nextDirection); nextTile.previousTileInCorridor = nextDirection; // nextTile.Tilemap.SetColor(nextTile.Position, Color.red); remainingTiles.Push(nextTile); nextTile.woOnTile.Add(this); corridor.Add(nextTile); for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { int z = -y - x; HexCoordinates coordinatesInRange = new HexCoordinates(x, y, z); HexCoordinates other = nextTile.Coordinates + coordinatesInRange; int distance = other.Distance(nextTile.Coordinates); if (distance <= radius) { TileProperties neighbor = nextTile.Grid.GetTile(other); if (!neighbor) { continue; } // neighbor.Tilemap.SetColor(neighbor.Position, Color.red); float newWindDryness = -(baseDryness - distance); if (newWindDryness < neighbor.windDryness) { neighbor.humidity -= neighbor.windDryness; neighbor.windDryness = newWindDryness; neighbor.humidity += neighbor.windDryness; } neighbor.woAffectingTile.Add(this); tilesAffected.Add(neighbor); } } } return(true); } return(false); }
public override void UpdateTurn() { bool destroy = true; int nbWinds = 0; for (int i = 0; i < 6; i++) { TileProperties neighbor = tile.GetNeighbor((HexDirection)i); if (neighbor.wind && neighbor.wind.direction.Opposite() == (HexDirection)i) { nbWinds++; if (nbWinds == 2) { destroy = false; break; } } } if (destroy) { tile.whirlwind = null; EndTurn(); RemoveFromTurnManager(); WindManager.Instance.WhirldwindsPool.Push(this); } else { if (tile.staticEntity) { tile.staticEntity.Kill(); } if (tile.movingEntity) { tile.movingEntity.Kill(); } EndTurn(); } }
// Get the next rechable tiles for a tile limit. Read tiles clockwise private int GetNextReachable(ref List <Vector3> vertices, ref TileProperties current, ref HexDirection begin, bool stopAtNW = false) { HexDirection currentDirection = begin.Next(); HexDirection end = begin; if (stopAtNW) { end = HexDirection.NE; } int rectangleCount = 0; // Iterate through neighbors clockwise while (currentDirection != end + 1 || begin.Next() == currentDirection) { TileProperties neighbor = current.GetNeighbor(currentDirection); // If neighbor is not reachable, add vertices if ((neighbor && !neighbor.IsInReachables) || !neighbor) { rectangleCount++; AddVertices(ref vertices, current, currentDirection, begin); currentDirection = currentDirection.Next(); } // else current is next neighbor else if (neighbor && neighbor.IsInReachables) { begin = (currentDirection).Opposite(); current = neighbor; return(rectangleCount); } } if (stopAtNW) { begin = HexDirection.NE; } return(rectangleCount); }