public void HighLevelSectorAdjustedRecalculate(MultiLevelSector sector) { WorldArea area = Manager.WorldData.WorldAreas[sector.WorldAreaIndex]; MultiLevelSectorManager.RemoveAllConnectionsWithinSector(sector); ReCalculateDistancesHigherSectorNodes(sector, area); // visual sector.SearchConnections(); }
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); } } } } }
public void RebuildNodesOnHighSectorEdges(IntVector3 areaWithSectors, int side) { WorldArea area = Manager.WorldData.WorldAreas[areaWithSectors.X]; MultiLevelSector sector = area.SectorGrid[0][areaWithSectors.Y]; MultiLevelSector higherSector = Manager.GetHigherSectorFromLower(1, sector, area); Debug.Log("Lower level start " + areaWithSectors.Y + " end " + areaWithSectors.Z); // clear out both sides //area.sectorGrid[1][areaWithSectors.z] Manager.RemoveAllAbstractNodesOnSectorEdge(higherSector, side); Manager.RemoveAllAbstractNodesOnSectorEdge( Manager.GetHigherSectorFromLower(1, area.SectorGrid[0][areaWithSectors.Z], area), MultiLevelSectorManager.FlipDirection(side)); // rebuild side RebuildNodesOnHighSectorEdge(1, higherSector, side, MultiLevelSectorManager.EdgeIndexToVector(side), area); }
public void RebuildNodesOnSectorEdges(List <int> sides, int sectorIndex, WorldArea area) { Vector2 startInSector = Vector2.zero; Vector2 startInNeighbourSector = Vector2.zero; Vector2 direction = Vector2.zero; MultiLevelSector sector = area.SectorGrid[0][sectorIndex]; foreach (int side in sides) { if (side == 0) { startInSector = new Vector2(sector.Left, sector.Top); startInNeighbourSector = new Vector2(sector.Left, sector.Top - 1); direction = Vector2.right; } else if (side == 1) { startInSector = new Vector2(sector.Left, sector.Bottom); startInNeighbourSector = new Vector2(sector.Left, sector.Bottom + 1); direction = Vector2.right; } else if (side == 2) { startInSector = new Vector2(sector.Left, sector.Top); startInNeighbourSector = new Vector2(sector.Left - 1, sector.Top); direction = Vector2.up; } else if (side == 3) { startInSector = new Vector2(sector.Right, sector.Top); startInNeighbourSector = new Vector2(sector.Right + 1, sector.Top); direction = Vector2.up; } RebuildNodesOnSectorEdge(sector, side, MultiLevelSectorManager.FlipDirection(side), startInSector, startInNeighbourSector, direction, area); } }
private void AddChange(IntVector2 key, Tile tile, WorldArea area, int side) { IntVector2 otherSectorKey = new IntVector2(); int otherSector = -1; // if other side of the sector has already been added, we dont need to add this if (side == 0) { otherSector = tile.SectorIndex - WorldData.MultiLevelSectorManager.GetSectorGridWidthAtLevel(area, 0); } else if (side == 1) { otherSector = tile.SectorIndex + WorldData.MultiLevelSectorManager.GetSectorGridWidthAtLevel(area, 0); } else if (side == 2 && area.SectorGrid[0][tile.SectorIndex].GridX > 0) { otherSector = tile.SectorIndex - 1; } else if (side == 3 && area.SectorGrid[0][tile.SectorIndex].GridX < WorldData.MultiLevelSectorManager.GetSectorGridWidthAtLevel(area, 0) - 1) { otherSector = tile.SectorIndex + 1; } if (WorldData.Pathfinder.maxLevelAmount > 1) { // add high level sector changes if (WorldData.MultiLevelSectorManager.GetHigherSectorFromLower(1, area.SectorGrid[0][tile.SectorIndex], area) != WorldData.MultiLevelSectorManager.GetHigherSectorFromLower(1, area.SectorGrid[0][otherSector], area)) { IntVector3 highLevelEdgeKey = new IntVector3(area.Index, 0, 0); int sideValue; if (tile.SectorIndex < otherSector) { sideValue = side; highLevelEdgeKey.Y = tile.SectorIndex; highLevelEdgeKey.Z = otherSector; } else { sideValue = MultiLevelSectorManager.FlipDirection(side); highLevelEdgeKey.Y = otherSector; highLevelEdgeKey.Z = tile.SectorIndex; } if (!_sectorEdgeChangesHighLevel.ContainsKey(highLevelEdgeKey)) { _sectorEdgeChangesHighLevel.Add(highLevelEdgeKey, sideValue); } } } if (otherSector > 0 && otherSector < area.SectorGrid[0].Length) { otherSectorKey.X = tile.WorldAreaIndex; otherSectorKey.Y = otherSector; if (_sectorEdgeChangesLowLevel.ContainsKey(otherSectorKey)) { if (_sectorEdgeChangesLowLevel[otherSectorKey].Contains(MultiLevelSectorManager.FlipDirection(side)) ) // other side already filled in { if (!_sectorChanges.Contains(key) ) // other sector exist and the side. add our sector for general change { _sectorChanges.Add(key); } } else if (!_sectorEdgeChangesLowLevel[key].Contains(side) ) // other sector exist but not the side. add our sector for Edge change { _sectorEdgeChangesLowLevel[key].Add(side); } } else // other sector not (yet? )added. add ourselves and other sector for general change { if (!_sectorChanges.Contains(otherSectorKey)) { _sectorChanges.Add(otherSectorKey); } if (!_sectorEdgeChangesLowLevel[key].Contains(side)) { _sectorEdgeChangesLowLevel[key].Add(side); } } } else if (!_sectorEdgeChangesLowLevel[key].Contains(side)) // other sector does not exist, add ourselves { _sectorEdgeChangesLowLevel[key].Add(side); } }
public void InputChanges() { if (WorldData.Pathfinder.maxLevelAmount != 0) { _sectorChanges.Clear(); _sectorEdgeChangesLowLevel.Clear(); _sectorEdgeChangesHighLevel.Clear(); WorldArea area; IntVector2 key = new IntVector2(); IntVector3 sectorsAreaKey = new IntVector3(); List <IntVector3> sectorsAreaRedo = new List <IntVector3>(); foreach (var tile in TilesBlockedAdjusted) { var tileOnEdge = false; if (TilesCostAdjusted.Contains(tile)) { TilesCostAdjusted.Remove(tile); } var tilePosKey = tile.GridPos; key.X = tile.WorldAreaIndex; key.Y = tile.SectorIndex; if (!_sectorEdgeChangesLowLevel.ContainsKey(key)) { _sectorEdgeChangesLowLevel.Add(key, new List <int>()); } area = WorldData.WorldAreas[tile.WorldAreaIndex]; var sector = area.SectorGrid[0][tile.SectorIndex]; if (tile.GridPos.Y == sector.Top && sector.Top != 0) //top { tileOnEdge = true; if (!_sectorEdgeChangesLowLevel[key].Contains(0)) { AddChange(key, tile, area, 0); } } if (tile.GridPos.Y == sector.Bottom && sector.GridY < WorldData.MultiLevelSectorManager.GetSectorGridHeightAtLevel(area, 0) - 1 ) //sector.bottom != worldData.tileManager.gridHeight - 1) //bot { tileOnEdge = true; if (!_sectorEdgeChangesLowLevel[key].Contains(1)) { AddChange(key, tile, area, 1); } } if (tile.GridPos.X == sector.Left && sector.Left != 0) //left { tileOnEdge = true; if (!_sectorEdgeChangesLowLevel[key].Contains(2)) { AddChange(key, tile, area, 2); } } if (tile.GridPos.X == sector.Right && sector.GridX < WorldData.MultiLevelSectorManager.GetSectorGridWidthAtLevel(area, 0) - 1) //right { tileOnEdge = true; if (!_sectorEdgeChangesLowLevel[key].Contains(3)) { AddChange(key, tile, area, 3); } } if (!tileOnEdge) { if (!_sectorChanges.Contains(key)) { _sectorChanges.Add(key); } } // store tiles that will change how world areas connect if (area.WorldAreaTileConnections.ContainsKey(tilePosKey)) { sectorsAreaKey.Z = area.TileGrid[tilePosKey.X][tilePosKey.Y].SectorIndex; foreach (IntVector3 value in area.WorldAreaTileConnections[tilePosKey]) { sectorsAreaKey.Y = value.Z; WorldArea tempArea; if (area.Index < sectorsAreaKey.X) // change nothing { tempArea = area; } else // we only generate these connections from the world area with the lowest index { tempArea = WorldData.WorldAreas[value.Z]; sectorsAreaKey.Y = area.Index; sectorsAreaKey.Z = tempArea.TileGrid[value.X][value.Y].SectorIndex; } sectorsAreaKey.X = tempArea.Index; if (!sectorsAreaRedo.Contains(sectorsAreaKey)) { RemoveWorldAreaNodes(sectorsAreaKey); sectorsAreaRedo.Add(sectorsAreaKey); } } } } List <MultiLevelSector> higherSectors = new List <MultiLevelSector>(); // rebuild sector edges List <IntVector2> keys = new List <IntVector2>(_sectorEdgeChangesLowLevel.Keys); IntVector2 indexKey; foreach (var t in keys) { indexKey = t; area = WorldData.WorldAreas[indexKey.X]; WorldData.MultiLevelSectorManager.LowLevel.RebuildNodesOnSectorEdges( _sectorEdgeChangesLowLevel[indexKey], indexKey.Y, area); MultiLevelSectorManager.RemoveAllConnectionsWithinSector(area.SectorGrid[0][indexKey.Y]); // get all sectors that have to recalculate if (!_sectorChanges.Contains(indexKey)) { _sectorChanges.Add(indexKey); } } foreach (var t in TilesCostAdjusted) { key.X = t.WorldAreaIndex; key.Y = t.SectorIndex; if (!_sectorChanges.Contains(key)) { _sectorChanges.Add(key); } } // now we must recalculate connections on sector edges foreach (var t in _sectorChanges) { indexKey = t; area = WorldData.WorldAreas[indexKey.X]; WorldData.MultiLevelSectorManager.LowLevel.ReCalculateDistancesSectorNodes( area.SectorGrid[0][indexKey.Y], area); if (WorldData.Pathfinder.maxLevelAmount > 1) { MultiLevelSector highSector = WorldData.MultiLevelSectorManager.GetHigherSectorFromLower(1, area.SectorGrid[0][indexKey.Y], area); if (!higherSectors.Contains(highSector)) { higherSectors.Add(highSector); } } } List <IntVector3> sectorEdgeChangesHighLevel = new List <IntVector3>(_sectorEdgeChangesHighLevel.Keys); foreach (var t in sectorEdgeChangesHighLevel) { WorldData.MultiLevelSectorManager.HighLevel.RebuildNodesOnHighSectorEdges( t, _sectorEdgeChangesHighLevel[t]); } foreach (var t in higherSectors) { WorldData.MultiLevelSectorManager.HighLevel.HighLevelSectorAdjustedRecalculate(t); } //visual foreach (var t in _sectorChanges) { indexKey = t; WorldData.WorldAreas[indexKey.X].SectorGrid[0][indexKey.Y].SearchConnections(); } // all sector connections fixed & correct world area nodes removed // rebuild world area nodes were we removed them for (int i = 0; i < sectorsAreaRedo.Count; i++) { area = WorldData.WorldAreas[sectorsAreaRedo[i].X]; IntVector2 newKey = new IntVector2(sectorsAreaRedo[i].Y, sectorsAreaRedo[i].Z); foreach (List <IntVector2> group in area.GroupsInSectors[newKey]) { WorldData.WorldBuilder.GenerateWordConnectingNodesPerGroup(area, group, newKey); } } } TilesCostAdjusted.Clear(); TilesBlockedAdjusted.Clear(); //WorldData.Pathfinder.WorldHasBeenChanged(_sectorChanges); }