public static TileConnectionScoreInfo MapNeighbourObstaclesOfTile(Tile tile, ObstacleType obstacleType) { Logger.Log($"Map neighbours of {tile.GridLocation.X},{tile.GridLocation.Y}"); TileModifierConnectionInfo <TileObstacle> obstacleRight = new TileModifierConnectionInfo <TileObstacle>(Direction.Right); TileModifierConnectionInfo <TileObstacle> obstacleDown = new TileModifierConnectionInfo <TileObstacle>(Direction.Down); TileModifierConnectionInfo <TileObstacle> obstacleLeft = new TileModifierConnectionInfo <TileObstacle>(Direction.Left); TileModifierConnectionInfo <TileObstacle> obstacleUp = new TileModifierConnectionInfo <TileObstacle>(Direction.Up); if (!EditorManager.InEditor) { Logger.Error("MapNeighbourObstaclesOfTile was not called from the editor"); return(null); } foreach (KeyValuePair <ObjectDirection, Tile> neighbour in tile.Neighbours) { if (!neighbour.Value) { continue; } Logger.Warning($"Neighbour at {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y} is {neighbour.Key} of {tile.GridLocation.X},{tile.GridLocation.Y}"); TileObstacle tileObstacle = neighbour.Value.TryGetTileObstacle(); if (tileObstacle == null || tileObstacle.ObstacleType != obstacleType) { continue; } if (neighbour.Key == ObjectDirection.Right) { obstacleRight.HasConnection = true; obstacleRight.TileModifier = tileObstacle; } else if (neighbour.Key == ObjectDirection.Down) { obstacleDown.HasConnection = true; obstacleDown.TileModifier = tileObstacle; } else if (neighbour.Key == ObjectDirection.Left) { obstacleLeft.HasConnection = true; obstacleLeft.TileModifier = tileObstacle; } else if (neighbour.Key == ObjectDirection.Up) { obstacleUp.HasConnection = true; obstacleUp.TileModifier = tileObstacle; } } return(TileConnectionRegister.CalculateTileConnectionScore(obstacleRight, obstacleDown, obstacleLeft, obstacleUp)); }
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)); }
public static TileConnectionScoreInfo MapGroundConnectionsWithNeighbours(Tile tile, IBaseBackgroundType groundType) { Logger.Log($"---------Map neighbours of {tile.GridLocation.X},{tile.GridLocation.Y}--------"); TileModifierConnectionInfo <TileBaseGround> groundRight = new TileModifierConnectionInfo <TileBaseGround>(Direction.Right); TileModifierConnectionInfo <TileBaseGround> groundDown = new TileModifierConnectionInfo <TileBaseGround>(Direction.Down); TileModifierConnectionInfo <TileBaseGround> groundLeft = new TileModifierConnectionInfo <TileBaseGround>(Direction.Left); TileModifierConnectionInfo <TileBaseGround> groundUp = new TileModifierConnectionInfo <TileBaseGround>(Direction.Up); if (!EditorManager.InEditor) { Logger.Error("MapNeighbourGroundOfTile 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. // But only if the main tile itself is a land tile if (tile.TileMainMaterial.GetType() == typeof(GroundMainMaterial)) { if (neighbour.Key == ObjectDirection.Right) { groundRight.HasConnection = true; } else if (neighbour.Key == ObjectDirection.Down) { groundDown.HasConnection = true; } else if (neighbour.Key == ObjectDirection.Left) { groundLeft.HasConnection = true; } else if (neighbour.Key == ObjectDirection.Up) { groundUp.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}. Its main material is {neighbour.Value.TileMainMaterial.GetType()}"); TileBaseGround tileGround = neighbour.Value.TryGetTileGround(); //if (tileGround == null || tileGround.TileGroundType.GetType() != groundType.GetType()) //{ // continue; //} if (neighbour.Value.TileMainMaterial?.GetType() != typeof(GroundMainMaterial)) { continue; } if (neighbour.Key == ObjectDirection.Right) { groundRight.HasConnection = true; groundRight.TileModifier = tileGround; } else if (neighbour.Key == ObjectDirection.Down) { groundDown.HasConnection = true; groundDown.TileModifier = tileGround; } else if (neighbour.Key == ObjectDirection.Left) { groundLeft.HasConnection = true; groundLeft.TileModifier = tileGround; } else if (neighbour.Key == ObjectDirection.Up) { groundUp.HasConnection = true; groundUp.TileModifier = tileGround; } } return(TileConnectionRegister.CalculateInversedTileConnectionScore(groundRight, groundDown, groundLeft, groundUp)); }