public void ConnectWorldAreaNodes(MultiLevelSector sector, WorldArea area) { foreach (AbstractNode node in sector.WorldAreaNodes.Keys) { ConnectNodeInSector(sector, node, area); } }
private void ReCalculateDistancesHigherSectorNodes(MultiLevelSector sector, WorldArea area) { List <AbstractNode> allNodesInSector = new List <AbstractNode>(); foreach (List <AbstractNode> list in sector.SectorNodesOnEdge) { allNodesInSector.AddRange(list); } allNodesInSector.AddRange(sector.WorldAreaNodes.Keys); List <AbstractNode> allNodesInSector2 = new List <AbstractNode>(allNodesInSector); foreach (AbstractNode node in allNodesInSector2) { foreach (AbstractNode nodeToFind in allNodesInSector) { Manager.WorldData.HierarchicalPathfinder.FindConnectionInsideSectorOnly(node, nodeToFind, sector, area); } } //foreach (List<AbstractNode> list in sector.sectorNodesOnEdge) //{ // foreach (AbstractNode node in list) // { // foreach (AbstractNode nodeToFind in allNodesInSector) // manager.worldData.hierarchicalPathfinder.FindConnectionInsideSectorOnly(node, nodeToFind, sector, area); // } //} }
private Vector2 DirectionBetweenSectorsVector2(MultiLevelSector a, MultiLevelSector b) { int deltaX = b.Left - a.Left; int deltaY = b.Top - a.Top; if (deltaX > 1) { deltaX = 1; } if (deltaX < -1) { deltaX = -1; } if (deltaY > 1) { deltaY = 1; } if (deltaY < -1) { deltaY = -1; } return(new Vector2(deltaX, deltaY)); }
public static void RemoveAllConnectionsWithinSector(MultiLevelSector sector) { foreach (List <AbstractNode> list in sector.SectorNodesOnEdge) { foreach (AbstractNode node in list) { node.Connections.Clear(); if (node.NodeConnectionToOtherSector != null) { node.Connections.Add(node.NodeConnectionToOtherSector, 1); } } } foreach (AbstractNode node in sector.WorldAreaNodes.Keys) { node.Connections.Clear(); if (node.NodeConnectionToOtherSector != null) { node.Connections.Add(node.NodeConnectionToOtherSector, 1); } } }
public void RemoveAllAbstractNodesOnSectorEdge(MultiLevelSector sector, int edgeIndex) { WorldArea area = WorldData.WorldAreas[sector.WorldAreaIndex]; // remove the connections from other sectorNodes to the sectorNodes we will remove now foreach (AbstractNode sectorNode in sector.SectorNodesOnEdge[edgeIndex]) { foreach (AbstractNode nodeConnected in sectorNode.Connections.Keys) { nodeConnected.Connections.Remove(sectorNode); } } // remove foreach (AbstractNode sectorNode in sector.SectorNodesOnEdge[edgeIndex]) { if (area.TileSectorNodeConnections[sector.Level][sectorNode.TileConnection].Count > 1) { area.TileSectorNodeConnections[sector.Level][sectorNode.TileConnection].Remove(sectorNode); } else { area.TileSectorNodeConnections[sector.Level].Remove(sectorNode.TileConnection); sectorNode.TileConnection.HasAbstractNodeConnection = false; } } // remove entire edge sector.SectorNodesOnEdge[edgeIndex].Clear(); }
public void FindConnectionInsideSectorOnly(AbstractNode start, AbstractNode destination, MultiLevelSector sector, WorldArea area) { // if we look for our self or already have a connection, we are done here if (start == destination || start.Connections.ContainsKey(destination)) { return; } int lowerLevel = sector.Level - 1; if (!area.TileSectorNodeConnections[lowerLevel].ContainsKey(start.TileConnection)) { Debug.Log("node index " + start.WorldAreaIndex + " actual world index " + area.Index + " start high " + start.TileConnection.GridPos.X + " y " + start.TileConnection.GridPos.Y); } int connectionDistance = FindConnectionThroughPathInsideSectorOnly( area.TileSectorNodeConnections[lowerLevel][start.TileConnection], area.TileSectorNodeConnections[lowerLevel][destination.TileConnection], WorldData.MultiLevelSectorManager.GetLowerSectorsFromHigher(sector.Level, sector.Id, area)); if (connectionDistance > -1) { WorldData.MultiLevelSectorManager.ConnectSectorNodes(start, destination, connectionDistance); } }
// get list of nodes that are on the border of start sector, with next sector public List <Tile> RowBetweenSectorsWithinWorldArea(MultiLevelSector sectorStart, MultiLevelSector sectorNext, WorldArea area) { Vector2 dir = DirectionBetweenSectorsVector2(sectorStart, sectorNext); if (dir == -Vector2.up) { return(GetNodesOnSectorRowNoBlocked(new Vector2(sectorStart.Left, sectorStart.Top), Vector2.right, area)); } if (dir == Vector2.up) { return(GetNodesOnSectorRowNoBlocked(new Vector2(sectorStart.Left, sectorStart.Bottom), Vector2.right, area)); } if (dir == -Vector2.right) { return(GetNodesOnSectorRowNoBlocked(new Vector2(sectorStart.Left, sectorStart.Top), Vector2.up, area)); } if (dir == Vector2.right) { return(GetNodesOnSectorRowNoBlocked(new Vector2(sectorStart.Right, sectorStart.Top), Vector2.up, area)); } return(null); }
public AbstractNode CreateAbstractNodeOnSectorEdge(MultiLevelSector sector, int edgeIndex, Tile tile, WorldArea area) { AbstractNode sectorNode = CreateAbstractNodeInSector(sector, tile, area); sector.sectorNodesOnEdge[edgeIndex].Add(sectorNode); return(sectorNode); }
public void RemoveAllAbstractNodesInSectorEdges(MultiLevelSector sector) { RemoveAllConnectionsWithinSector(sector); foreach (var t in sector.SectorNodesOnEdge) { t.Clear(); } }
public MultiLevelSector GetHigherSectorFromLower(int level, MultiLevelSector sector, WorldArea area) { int x = Mathf.FloorToInt(sector.Left / (float)GetSectorWidthAtLevel(area, level)); int y = Mathf.FloorToInt(sector.Top / (float)GetSectorHeightAtLevel(area, level)); int index = (y * GetSectorGridWidthAtLevel(area, level)) + x; return(area.SectorGrid[level][index]); }
public void RemoveAllAbstractNodesInSectorEdges(MultiLevelSector sector) { RemoveAllConnectionsWithinSector(sector); for (int i = 0; i < sector.sectorNodesOnEdge.Length; i++) { sector.sectorNodesOnEdge[i].Clear(); } }
// recalculate distances to other high level nodes public void ReCalculateDistancesSectorNodes(MultiLevelSector sector, WorldArea area) { foreach (List <AbstractNode> list in sector.SectorNodesOnEdge) { foreach (AbstractNode node in list) { ConnectNodeInSector(sector, node, area); } } }
public void CreateSectorNodes(MultiLevelSector sector, int neighbourID, int edgeIndex, int edgeIndexNeighbourSector, Tile inSectorNode, Tile inNeighbourSectorNode, WorldArea area) { AbstractNode node = CreateAbstractNodeOnSectorEdge(sector, edgeIndex, inSectorNode, area); AbstractNode neighbourNode = CreateAbstractNodeOnSectorEdge(area.sectorGrid[sector.level][neighbourID], edgeIndexNeighbourSector, inNeighbourSectorNode, area); node.nodeConnectionToOtherSector = neighbourNode; neighbourNode.nodeConnectionToOtherSector = node; ConnectSectorNodes(node, neighbourNode, 1); }
public void HighLevelSectorAdjustedRecalculate(MultiLevelSector sector) { WorldArea area = Manager.WorldData.WorldAreas[sector.WorldAreaIndex]; MultiLevelSectorManager.RemoveAllConnectionsWithinSector(sector); ReCalculateDistancesHigherSectorNodes(sector, area); // visual sector.SearchConnections(); }
public void DrawIntegrationField(IntergrationField integrationfield) { if (integrationFieldHolder != null) { Destroy(integrationFieldHolder); } GameObject integrationTile = Resources.Load("Prefab/IntegrationTile") as GameObject; if (worldData.pathfinder.showIntergrationField) { integrationFieldHolder = new GameObject(); for (int x = 0; x < worldData.worldAreas.Count; x++) { for (int i = 0; i < worldData.worldAreas[x].sectorGrid[0].Length; i++) { if (integrationfield.field.ContainsKey(new IntVector2(x, i))) { MultiLevelSector sector = worldData.worldAreas[x].sectorGrid[0][i]; Vector2 sectorPos = new Vector2(sector.left, sector.top); for (int j = 0; j < sector.tilesInWidth * sector.tilesInHeight; j++) { int y = Mathf.FloorToInt((float)j / sector.tilesInWidth); Vector2 node = sectorPos + new Vector2(j - (sector.tilesInWidth * y), y); if (worldData.worldAreas[x].tileGrid[(int)node.x][(int)node.y] != null) { GameObject b = Instantiate(integrationTile, worldData.tileManager.GetTileWorldPosition(worldData.worldAreas[x].tileGrid[(int)node.x][(int)node.y], worldData.worldAreas[x]), Quaternion.identity) as GameObject; int value = integrationfield.field[new IntVector2(x, i)][j]; if (value * 3 >= worldData.colorLists.pathCostColors.Length - 2) { b.transform.GetChild(0).gameObject.GetComponent <MeshRenderer>().material.color = worldData.colorLists.pathCostColors[worldData.colorLists.pathCostColors.Length - 2]; } else { if (value < worldData.colorLists.pathCostColors.Length - 2) { b.transform.GetChild(0).gameObject.GetComponent <MeshRenderer>().material.color = worldData.colorLists.pathCostColors[value * 3]; } } b.transform.position += Vector3.up * 0.15f; b.transform.parent = integrationFieldHolder.transform; b.transform.localScale = new Vector3(worldData.pathfinder.tileSize, worldData.pathfinder.tileSize, worldData.pathfinder.tileSize); } } } } } } }
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 ConnectWorldAreaNodesToSectorNodes(MultiLevelSector sector, WorldArea area, int level) { if (sector.level == 0) { lowLevel.ConnectWorldAreaNodes(sector, area); } else { highLevel.ConnectWorldAreaNodes(sector, area); } }
public List <int> GetNeighboursIndexes(MultiLevelSector sector, WorldArea area) { List <int> neighbours = new List <int>(); foreach (MultiLevelSector neighbourSector in GetNeighboursWithinWorldArea(sector, area)) { neighbours.Add(neighbourSector.Id); } return(neighbours); }
public void ConnectWorldAreaNodesToSectorNodes(MultiLevelSector sector, WorldArea area) { if (sector.Level == 0) { LowLevel.ConnectWorldAreaNodes(sector, area); } else { HighLevel.ConnectWorldAreaNodes(sector, area); } }
public void ConnectNodeInSector(MultiLevelSector sector, AbstractNode sectorNode, WorldArea area) { if (sector.Level == 0) { LowLevel.ConnectNodeInSector(sector, sectorNode, area); } else { HighLevel.ConnectNodeInSector(sector, sectorNode, area); } }
// set which slots/tiles we can expand on. public void SetSearchFields(List <int> sectors, WorldArea area, bool value) { foreach (var t in sectors) { MultiLevelSector sector = area.SectorGrid[0][t]; for (int x = 0; x < sector.TilesInWidth; x++) { for (int y = 0; y < sector.TilesInHeight; y++) { area.SearchField[sector.Left + x][sector.Top + y] = value; } } } }
// set which slots/tiles we can expand on. public void SetSearchFields(List <int> sectors, WorldArea area, bool value) { for (int i = 0; i < sectors.Count; i++) { MultiLevelSector sector = area.sectorGrid[0][sectors[i]]; for (int x = 0; x < sector.tilesInWidth; x++) { for (int y = 0; y < sector.tilesInHeight; y++) { area.searchField[sector.left + x][sector.top + y] = value; } } } }
public void FlatAreaCopyTiles(IntVector2 offset, Tile[][] tileGrid, int yLayer, WorldData worldData) { FlatArea = true; SetValues(offset, tileGrid.Length, tileGrid[0].Length, yLayer, worldData); _worldData.MultiLevelSectorManager.SetupSectorsWorldArea(this); bool firstTile = true; for (int x = 0; x < tileGrid.Length; x++) { for (int y = 0; y < tileGrid[0].Length; y++) { if (tileGrid[x][y] == null) { continue; } TileGrid[x][y] = tileGrid[x][y]; // manually TileGrid[x][y].YWorldPos = worldData.Pathfinder.worldStart.y; // 0f; // forced y = 0. 2D worldAreas _worldData.LayerWorldAreaIndexes[yLayer][x + LeftOffset][y + TopOffset] = Index; // set world Index TileGrid[x][y].GridPos = new IntVector2(x, y); TileGrid[x][y].IntegrationValue = TileManager.TileResetIntegrationValue; TileGrid[x][y].WorldAreaIndex = Index; int sectorX = Mathf.FloorToInt(x / (float)LevelDimensions[0][0]); // sectorWidth int sectorY = Mathf.FloorToInt(y / (float)LevelDimensions[0][1]); // sectorHeight if (_worldData.Pathfinder.maxLevelAmount == 0) { TileGrid[x][y].SectorIndex = 0; } else { TileGrid[x][y].SectorIndex = (sectorY * LevelDimensions[0][2]) + sectorX; } MultiLevelSector sector = SectorGrid[0][TileGrid[x][y].SectorIndex]; int deltaX = x - sector.Left; int deltaY = y - sector.Top; TileGrid[x][y].IndexWithinSector = (deltaY * sector.TilesInWidth) + deltaX; if (firstTile) { Origin.y = TileGrid[x][y].YWorldPos; firstTile = false; } } } }
private void DrawFlowField(FlowField flowField) { if (_flowFieldHolder != null) { Destroy(_flowFieldHolder); } GameObject arrow = Resources.Load("Prefab/FlowArrow") as GameObject; if (worldData.Pathfinder.showFlowField) { _flowFieldHolder = new GameObject(); for (int x = 0; x < worldData.WorldAreas.Count; x++) { for (int i = 0; i < worldData.WorldAreas[x].SectorGrid[0].Length; i++) { if (flowField.Field.ContainsKey(new IntVector2(x, i))) { MultiLevelSector sector = worldData.WorldAreas[x].SectorGrid[0][i]; Vector2 sectorPos = new Vector2(sector.Left, sector.Top); for (int j = 0; j < sector.TilesInWidth * sector.TilesInHeight; j++) { int y = Mathf.FloorToInt((float)j / sector.TilesInWidth); Vector2 node = sectorPos + new Vector2(j - (sector.TilesInWidth * y), y); if (worldData.WorldAreas[x].TileGrid[(int)node.x][(int)node.y] != null) { GameObject b = Instantiate(arrow, worldData.TileManager.GetTileWorldPosition( worldData.WorldAreas[x].TileGrid[(int)node.x][(int)node.y], worldData.WorldAreas[x]) + new Vector3(0, 0.2f, 0), Quaternion.identity); Vector2 flow = worldData.FlowFieldManager.DirToVector( flowField.Field[new IntVector2(x, i)][j]); b.transform.LookAt(b.transform.position + new Vector3(flow.x, 0, flow.y)); b.transform.parent = _flowFieldHolder.transform; b.transform.localScale = new Vector3(worldData.Pathfinder.tileSize, worldData.Pathfinder.tileSize, worldData.Pathfinder.tileSize); } } } } } } }
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), manager.FlipDirection(side)); // rebuild side RebuildNodesOnHighSectorEdge(1, higherSector, side, manager.EdgeIndexToVector(side), area); }
public static bool LowerSectorEdgeMatchesHigher(MultiLevelSector highSector, MultiLevelSector lowSector, int edgeIndex) { switch (edgeIndex) { case 0 when highSector.Top == lowSector.Top: case 1 when highSector.Bottom == lowSector.Bottom: case 2 when highSector.Left == lowSector.Left: case 3 when highSector.Right == lowSector.Right: return(true); default: return(false); } }
public void SetSearchFields(int areaIndex, List <int> sectors, bool value) { WorldArea worldArea = worldData.worldAreas[areaIndex]; for (int i = 0; i < sectors.Count; i++) { MultiLevelSector sector = worldArea.sectorGrid[0][sectors[i]]; for (int x = 0; x < sector.tilesInWidth; x++) { for (int y = 0; y < sector.tilesInHeight; y++) { worldArea.searchField[sector.left + x][sector.top + y] = value; } } } }
public void ConnectNodeInSector(MultiLevelSector sector, AbstractNode node, WorldArea area) { List <AbstractNode> allNodesInSector = new List <AbstractNode>(); foreach (List <AbstractNode> list in sector.SectorNodesOnEdge) { allNodesInSector.AddRange(list); } allNodesInSector.AddRange(sector.WorldAreaNodes.Keys); foreach (AbstractNode nodeToFind in allNodesInSector) { Manager.WorldData.HierarchicalPathfinder.FindConnectionInsideSectorOnly(node, nodeToFind, sector, area); } }
public void SetSearchFields(int areaIndex, List <int> sectors, bool value) { WorldArea worldArea = WorldData.WorldAreas[areaIndex]; foreach (var t in sectors) { MultiLevelSector sector = worldArea.SectorGrid[0][t]; for (int x = 0; x < sector.TilesInWidth; x++) { for (int y = 0; y < sector.TilesInHeight; y++) { worldArea.SearchField[sector.Left + x][sector.Top + y] = value; } } } }
public void FlatAreaCopyTiles(IntVector2 offset, Tile[][] _tileGrid, int yLayer, WorldData _worldData) { flatArea = true; SetValues(offset, _tileGrid.Length, _tileGrid[0].Length, yLayer, _worldData); worldData.multiLevelSectorManager.SetupSectorsWorldArea(this); bool firstTile = true; for (int x = 0; x < _tileGrid.Length; x++) { for (int y = 0; y < _tileGrid[0].Length; y++) { tileGrid[x][y] = _tileGrid[x][y]; // manually tileGrid[x][y].yWorldPos = _worldData.pathfinder.worldStart.y; // 0f; // forced y = 0. 2D worldAreas worldData.layerdWorldAreaIndexes[yLayer][x + leftOffset][y + topOffset] = index; // set world Index tileGrid[x][y].gridPos = new IntVector2(x, y); tileGrid[x][y].integrationValue = worldData.tileManager.tileResetIntegrationValue; tileGrid[x][y].worldAreaIndex = index; int SectorX = Mathf.FloorToInt(x / (float)levelDimensions[0][0]); // /sectorwidth int SectorY = Mathf.FloorToInt(y / (float)levelDimensions[0][1]); // /sectorheight if (worldData.pathfinder.maxLevelAmount == 0) { tileGrid[x][y].sectorIndex = 0; } else { tileGrid[x][y].sectorIndex = (SectorY * levelDimensions[0][2]) + SectorX; } MultiLevelSector sector = sectorGrid[0][tileGrid[x][y].sectorIndex]; int deltaX = x - sector.left; int deltaY = y - sector.top; tileGrid[x][y].indexWithinSector = (deltaY * sector.tilesInWidth) + deltaX; if (firstTile) { origin.y = tileGrid[x][y].yWorldPos; firstTile = false; } } } }