public override void RemovePath() { OverworldTilePath overworldTilePath = (OverworldTilePath)_tile.GetBackgrounds().FirstOrDefault(background => background is OverworldTilePath); if (overworldTilePath == null) { return; } Logger.Log(overworldTilePath.TilePathType); IPathType overworldTilePathType = overworldTilePath.TilePathType; int oldConnectionScore = overworldTilePath.ConnectionScore; // If needed, place a background in the gap that the removed path left if (oldConnectionScore == NeighbourTileCalculator.ConnectionOnAllSidesScore) { EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(_tile); tileBackgroundPlacer.PlaceBackground <OverworldTileBaseGround>(); } _tile.RemoveBackground(overworldTilePath); overworldTilePath.Remove(); //After removing tile, check with neighbour tiles if wall connections should be updated foreach (KeyValuePair <ObjectDirection, Tile> neighbour in _tile.Neighbours) { if (!neighbour.Value) { continue; } TilePath overworldTilePathOnNeighbour = neighbour.Value.TryGetTilePath(); if (overworldTilePathOnNeighbour == null) { continue; } int oldConnectionScoreOnNeighbour = overworldTilePathOnNeighbour.ConnectionScore; Logger.Warning($"We will now look for connections for neighbour {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y}, which is {neighbour.Key} of {_tile.GridLocation.X},{_tile.GridLocation.Y}"); TileConnectionScoreInfo overworldTilePathConnectionScoreOnNeighbourInfo = NeighbourTileCalculator.MapNeighbourPathsOfTile(neighbour.Value, overworldTilePathType); Logger.Log($"We calculated an path connection type score of {overworldTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore} for location {neighbour.Value.GridLocation.X}, {neighbour.Value.GridLocation.Y}"); //update connection score on neighbour overworldTilePathOnNeighbour.WithConnectionScoreInfo(overworldTilePathConnectionScoreOnNeighbourInfo); //Add background where needed if (oldConnectionScoreOnNeighbour == NeighbourTileCalculator.ConnectionOnAllSidesScore && overworldTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore != NeighbourTileCalculator.ConnectionOnAllSidesScore) { EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(neighbour.Value as EditorOverworldTile); tileBackgroundPlacer.PlaceBackground <OverworldTileBaseGround>(); } } }
// Called in game when we already have the connection score public override void PlacePath(IPathType tilePathType, TileConnectionScoreInfo pathConnectionScoreInfo) { GameObject overworldTilePathGO = GameObject.Instantiate(OverworldGameplayManager.Instance.GetTileBackgroundPrefab <OverworldTilePath>(), Tile.BackgroundsContainer); OverworldTilePath overworldTilePath = overworldTilePathGO.GetComponent <OverworldTilePath>(); overworldTilePath.WithType(tilePathType as IBackgroundType); overworldTilePath.WithConnectionScoreInfo(pathConnectionScoreInfo); overworldTilePath.SetTile(Tile); Tile.AddBackground(overworldTilePath); }
// Called in game when we already have the connection score public override void PlacePath(IPathType mazeTilePathType, TileConnectionScoreInfo pathConnectionScoreInfo) { GameObject mazeTilePathGO = GameObject.Instantiate(MazeLevelGameplayManager.Instance.GetTileBackgroundPrefab <MazeTilePath>(), Tile.BackgroundsContainer); MazeTilePath mazeTilePath = mazeTilePathGO.GetComponent <MazeTilePath>(); mazeTilePath.WithType(mazeTilePathType as IBackgroundType); mazeTilePath.WithConnectionScoreInfo(pathConnectionScoreInfo); mazeTilePath.SetTile(Tile); Tile.AddBackground(mazeTilePath); Tile.TryMakeMarkable(true); }
public abstract void PlacePath(IPathType tilePathType, TileConnectionScoreInfo pathConnectionScoreInfo);
public override void RemovePath() { MazeTilePath mazeTilePath = (MazeTilePath)_tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath); if (mazeTilePath == null) { return; } Logger.Log(mazeTilePath.TilePathType); IPathType mazeTilePathType = mazeTilePath.TilePathType; int oldConnectionScore = mazeTilePath.ConnectionScore; Logger.Log($"Old path score: {oldConnectionScore}"); // If needed, place a background in the gap that the removed path left if (oldConnectionScore == NeighbourTileCalculator.ConnectionOnAllSidesScore) { Logger.Log($"Place background in gap at {_tile.GridLocation.X},{_tile.GridLocation.Y}."); EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(_tile); tileBackgroundPlacer.PlaceCoveringBaseGround(); // place background with connections on all sides } _tile.RemoveBackground(mazeTilePath); mazeTilePath.Remove(); TrySetTileNotMarkable(); //After removing tile, check with neighbour tiles if wall connections should be updated foreach (KeyValuePair <ObjectDirection, Tile> neighbour in _tile.Neighbours) { if (!neighbour.Value) { continue; } TilePath mazeTilePathOnNeighbour = neighbour.Value.TryGetTilePath(); if (mazeTilePathOnNeighbour == null) { continue; } int oldConnectionScoreOnNeighbour = mazeTilePathOnNeighbour.ConnectionScore; Logger.Warning($"We will now look for connections for neighbour {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y}, which is {neighbour.Key} of {_tile.GridLocation.X},{_tile.GridLocation.Y}"); TileConnectionScoreInfo mazeTilePathConnectionScoreOnNeighbourInfo = NeighbourTileCalculator.MapNeighbourPathsOfTile(neighbour.Value, mazeTilePathType); Logger.Log($"We calculated an path connection type score of {mazeTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore} for location {neighbour.Value.GridLocation.X}, {neighbour.Value.GridLocation.Y}"); //update connection score on neighbour mazeTilePathOnNeighbour.WithConnectionScoreInfo(mazeTilePathConnectionScoreOnNeighbourInfo); //Add background where needed if (oldConnectionScoreOnNeighbour == NeighbourTileCalculator.ConnectionOnAllSidesScore && mazeTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore != NeighbourTileCalculator.ConnectionOnAllSidesScore) { EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(neighbour.Value as EditorMazeTile); tileBackgroundPlacer.PlaceCoveringBaseGround(); } } _tile.RemoveTileAsBeautificationTrigger(); }
public static TileConnectionScoreInfo MapNeighbourPathsOfTile(Tile tile, IPathType pathType) { Logger.Log($"---------Map neighbours of {tile.GridLocation.X},{tile.GridLocation.Y}--------"); TileModifierConnectionInfo <TilePath> pathRight = new TileModifierConnectionInfo <TilePath>(Direction.Right); TileModifierConnectionInfo <TilePath> pathDown = new TileModifierConnectionInfo <TilePath>(Direction.Down); TileModifierConnectionInfo <TilePath> pathLeft = new TileModifierConnectionInfo <TilePath>(Direction.Left); TileModifierConnectionInfo <TilePath> pathUp = new TileModifierConnectionInfo <TilePath>(Direction.Up); if (!EditorManager.InEditor) { Logger.Error("MapNeighbourPathsOfTile was not called from the editor"); return(null); } foreach (KeyValuePair <ObjectDirection, Tile> neighbour in tile.Neighbours) { if (!neighbour.Value) { // if there is no tile as neighbour, it must mean it as the level edge. This counts as a connection. if (neighbour.Key == ObjectDirection.Right) { pathRight.HasConnection = true; } else if (neighbour.Key == ObjectDirection.Down) { pathDown.HasConnection = true; } else if (neighbour.Key == ObjectDirection.Left) { pathLeft.HasConnection = true; } else if (neighbour.Key == ObjectDirection.Up) { pathUp.HasConnection = true; } continue; } Logger.Warning($"Neighbour at {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y} is {neighbour.Key} of {tile.GridLocation.X},{tile.GridLocation.Y}."); // Check if the neighbour has a connection which is a PATH or a BRIDGE TilePath tilePath = neighbour.Value.TryGetTilePath(); if (tilePath == null || tilePath.TilePathType?.GetType() != pathType.GetType()) { BridgePiece bridgePiece = neighbour.Value.TryGetBridgePiece(); if (bridgePiece == null) { continue; } bool hasBridgeConnection = false; if ((neighbour.Key == ObjectDirection.Right || neighbour.Key == ObjectDirection.Left) && bridgePiece.BridgePieceDirection == BridgePieceDirection.Horizontal) { hasBridgeConnection = true; } else if ((neighbour.Key == ObjectDirection.Down || neighbour.Key == ObjectDirection.Up) && bridgePiece.BridgePieceDirection == BridgePieceDirection.Vertical) { hasBridgeConnection = true; } if (hasBridgeConnection == false) { continue; } } if (neighbour.Key == ObjectDirection.Right) { pathRight.HasConnection = true; pathRight.TileModifier = tilePath; } else if (neighbour.Key == ObjectDirection.Down) { pathDown.HasConnection = true; pathDown.TileModifier = tilePath; } else if (neighbour.Key == ObjectDirection.Left) { pathLeft.HasConnection = true; pathLeft.TileModifier = tilePath; } else if (neighbour.Key == ObjectDirection.Up) { pathUp.HasConnection = true; pathUp.TileModifier = tilePath; } } return(TileConnectionRegister.CalculateTileConnectionScore(pathRight, pathDown, pathLeft, pathUp)); }