private void RebuildNodesOnHighSectorEdge(int level, MultiLevelSector sector, int edgeNumber, Vector2 direction, WorldArea area) { // get all lower level sectors within foreach (int[] list in Manager.GetLowerSectorsFromHigher(level, sector.Id, area) ) // .lookUpLowerSectors[level - 1][sector.ID]) { // go through lowerLevel Sector (indexes), make copies of the abstract nodes on the correct edges foreach (int lowerLevelSectorIndex in list) { MultiLevelSector lowerSector = area.SectorGrid[level - 1][lowerLevelSectorIndex]; if (MultiLevelSectorManager.LowerSectorEdgeMatchesHigher(sector, lowerSector, edgeNumber)) // match edge { foreach (AbstractNode node in lowerSector.SectorNodesOnEdge[edgeNumber] ) // get nodes to copy from the edge { int neighbourId = 0; int neighbourEdgeNumber = 0; if (edgeNumber == 0) { neighbourId = sector.Id - Manager.GetSectorGridWidthAtLevel(area, level); // levelDimensions[level][2]; neighbourEdgeNumber = 1; } else if (edgeNumber == 1) { neighbourId = sector.Id + Manager.GetSectorGridWidthAtLevel(area, level); // levelDimensions[level][2]; neighbourEdgeNumber = 0; } else if (edgeNumber == 2) { neighbourId = sector.Id - 1; neighbourEdgeNumber = 3; } else if (edgeNumber == 3) { neighbourId = sector.Id + 1; neighbourEdgeNumber = 2; } Manager.CreateSectorNodes(sector, neighbourId, edgeNumber, neighbourEdgeNumber, node.TileConnection, Manager.WorldData.TileManager.GetTileInWorldArea(area, node.TileConnection.GridPos.X + (int)direction.x, node.TileConnection.GridPos.Y + (int)direction.y), area); } } } } }
private void RebuildNodesOnSectorEdge(MultiLevelSector sector, int edgeIndex, int edgeIndexNeighbourSector, Vector2 startInSector, Vector2 startInNeighbourSector, Vector2 direction, WorldArea area) { // remove connections to sector nodes on edge + remove them and those directly linked on neighbour sector Manager.RemoveAllAbstractNodesOnSectorEdge(sector, edgeIndex); var maxStep = direction == Vector2.right ? sector.TilesInWidth : sector.TilesInHeight; int sec = -1; for (int i = 0; i < maxStep; i++) { Tile neighbour = area.TileGrid[(int)startInNeighbourSector.x + (int)direction.x * i][ (int)startInNeighbourSector.y + (int)direction.y * i]; if (neighbour != null) { sec = neighbour.SectorIndex; Manager.RemoveAllAbstractNodesOnSectorEdge(area.SectorGrid[0][sec], edgeIndexNeighbourSector); break; } } if (sec != -1) // if we haven't found any tiles, no reason to try and build connections { // build nodes on edge bool sectorNodesOpen = false; int openLength = -1; int startNodeOfGroup = 0; for (int i = 0; i < maxStep; i++) { var tile1 = area.TileGrid[(int)startInSector.x + (int)direction.x * i][ (int)startInSector.y + (int)direction.y * i]; var tile2 = area.TileGrid[(int)startInNeighbourSector.x + (int)direction.x * i][ (int)startInNeighbourSector.y + (int)direction.y * i]; if (tile1 != null && tile2 != null && !tile1.Blocked && !tile2.Blocked && Manager.WorldData.TileManager.TilesWithinRangeGeneration(tile1, tile2)) { // starting point of a new connection/gate between sectors if (!sectorNodesOpen) { sectorNodesOpen = true; } openLength++; } else { if (sectorNodesOpen) // if we have had a couple of open nodes couples { // small enough to represent with 1 transition if (openLength < Manager.MaxGateSize) { int steps = Mathf.FloorToInt(openLength * 0.5f) + startNodeOfGroup; Tile neighbourTile = area.TileGrid[(int)startInNeighbourSector.x + (int)direction.x * steps][ (int)startInNeighbourSector.y + (int)direction.y * steps]; Manager.CreateSectorNodes(sector, neighbourTile.SectorIndex, edgeIndex, edgeIndexNeighbourSector, area.TileGrid[(int)startInSector.x + (int)direction.x * steps][ (int)startInSector.y + (int)direction.y * steps], neighbourTile, area); } else { // to large, 2 transitions. on on each end int multilayer = startNodeOfGroup; Tile neighbourTile = area.TileGrid[(int)startInNeighbourSector.x + (int)direction.x * multilayer][ (int)startInNeighbourSector.y + (int)direction.y * multilayer]; Manager.CreateSectorNodes(sector, neighbourTile.SectorIndex, edgeIndex, edgeIndexNeighbourSector, area.TileGrid[(int)startInSector.x + (int)direction.x * multilayer][ (int)startInSector.y + (int)direction.y * multilayer], neighbourTile, area); multilayer = (startNodeOfGroup + openLength); neighbourTile = area.TileGrid[(int)startInNeighbourSector.x + (int)direction.x * multilayer][ (int)startInNeighbourSector.y + (int)direction.y * multilayer]; Manager.CreateSectorNodes(sector, neighbourTile.SectorIndex, edgeIndex, edgeIndexNeighbourSector, area.TileGrid[(int)startInSector.x + (int)direction.x * multilayer][ (int)startInSector.y + (int)direction.y * multilayer], neighbourTile, area); } openLength = -1; sectorNodesOpen = false; } startNodeOfGroup = i + 1; } } if (sectorNodesOpen) // if we have had a couple of open nodes couples { if (openLength < Manager.MaxGateSize) { int steps = Mathf.FloorToInt(openLength * 0.5f) + startNodeOfGroup; Tile neighbourTile = area.TileGrid[(int)startInNeighbourSector.x + (int)direction.x * steps][ (int)startInNeighbourSector.y + (int)direction.y * steps]; Manager.CreateSectorNodes(sector, neighbourTile.SectorIndex, edgeIndex, edgeIndexNeighbourSector, area.TileGrid[(int)startInSector.x + (int)direction.x * steps][ (int)startInSector.y + (int)direction.y * steps], neighbourTile, area); } else { // to large, 2 transitions. on on each end int multilayer = startNodeOfGroup; Tile neighbourTile = area.TileGrid[(int)startInNeighbourSector.x + (int)direction.x * multilayer][ (int)startInNeighbourSector.y + (int)direction.y * multilayer]; Manager.CreateSectorNodes(sector, neighbourTile.SectorIndex, edgeIndex, edgeIndexNeighbourSector, area.TileGrid[(int)startInSector.x + (int)direction.x * multilayer][ (int)startInSector.y + (int)direction.y * multilayer], neighbourTile, area); multilayer = (startNodeOfGroup + openLength); neighbourTile = area.TileGrid[(int)startInNeighbourSector.x + (int)direction.x * multilayer][ (int)startInNeighbourSector.y + (int)direction.y * multilayer]; Manager.CreateSectorNodes(sector, neighbourTile.SectorIndex, edgeIndex, edgeIndexNeighbourSector, area.TileGrid[(int)startInSector.x + (int)direction.x * multilayer][ (int)startInSector.y + (int)direction.y * multilayer], neighbourTile, area); } } } }