void Start() { errorHandler = interfaceFactory.ErrorHandler; gameManager = interfaceFactory.GameManager; globeManager = interfaceFactory.GlobeManager; uiManager = interfaceFactory.UIManager; if (errorHandler == null || gameManager == null || globeManager == null || uiManager == null) { gameObject.SetActive(false); } else { if (componentMissing == true) { errorHandler.ReportError("Pathfinder missing component", ErrorState.restart_scene); } globeParser = globeManager.GlobeParser; if (globeParser == null) { errorHandler.ReportError("Globe Parser missing", ErrorState.restart_scene); } worldMapGlobe = globeManager.WorldMapGlobe; if (worldMapGlobe == null) { errorHandler.ReportError("World Map Globe missing", ErrorState.restart_scene); } playerManager = gameManager.PlayerManager; if (playerManager == null) { errorHandler.ReportError("Player Manager missing", ErrorState.restart_scene); } CellsInRange = globeParser.GetCellsInRange(playerCharacter.CellLocation, TravelRange + 1); } }
public void FinishedPathFinding() { PathIndices.Clear(); worldMapGlobe.ClearCells(true, false, false); ClearCellCosts(); Array.Clear(CellsInRange, 0, CellsInRange.Length); CellsInRange = globeParser.GetCellsInRange(playerCharacter.CellLocation, TravelRange + 1); SetCellCosts(); if (playerCharacter.Selected) { if (playerCharacter.CellLocation == null) { errorHandler.ReportError("Player finished pathfinding in invalid location", ErrorState.restart_scene); return; } worldMapGlobe.SetCellColor(playerCharacter.CellLocation.index, Color.green, true); if (!uiManager.CursorOverUI && worldMapGlobe.lastHighlightedCellIndex >= 0) { playerCharacter.OnCellEnter(worldMapGlobe.lastHighlightedCellIndex); } } geoPosAnimator.Moving = false; geoPosAnimator.Stop = false; }
public List <Landmark>[] GetLandmarksInRange(Cell startCell, int range) { List <Cell>[] cellsInRange = globeParser.GetCellsInRange(startCell, range); if (range < 0 || startCell.index < 0 || worldMapGlobe.cells.Count() < startCell.index) { errorHandler.ReportError("Invalid input for GetLandmarksInCell", ErrorState.close_window); return(null); } List <Landmark> landmarksFound = new List <Landmark>(); List <Landmark> landmarksInCell; int distance = 0; //distance measures how many rings of hexes we've moved out List <Landmark>[] landmarks = new List <Landmark> [range + 1]; //landmarks is an array of lists with each list containing landmarks[0] = new List <Landmark>(); //the landmarks that can be reached at that distance. try { bool startHex = true; foreach (List <Cell> hexRing in cellsInRange) { if (startHex) { //Get landmarks at start hex landmarksInCell = GetLandmarksInCell(startCell); startHex = false; landmarks[0] = landmarksInCell; } else { distance++; landmarks[distance] = new List <Landmark>(); foreach (Cell cell in hexRing) { landmarksInCell = GetLandmarksInCell(cell); foreach (Landmark landmark in landmarksInCell) { if (!landmarksFound.Contains(landmark)) { landmarks[distance].Add(landmark); } } } } } } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.close_window); } return(landmarks); }
public List <Province>[] GetProvincesInRange(Cell startCell, int range) { if (range < 0 || startCell.index < 0 || worldMapGlobe.cells.Count() < startCell.index) { errorHandler.ReportError("Invalid input for GetProvincesInRange", ErrorState.close_window); return(null); } List <Cell>[] cellsInRange = globeParser.GetCellsInRange(startCell, range); int distance = 0; //distance measures how many rings of hexes we've moved out List <Province>[] provinces = new List <Province> [range + 1]; //provinces is an array of lists with each list containing List <Province> foundProvinces = new List <Province>(); //the provinces that can be reached at that distance. List <Province> provincesInHex = new List <Province>(); try { bool startHex = true; foreach (List <Cell> hexRing in cellsInRange) { if (startHex) { //Get provinces at start hex provinces[0] = new List <Province>(); provincesInHex = GetProvicesInCell(startCell); foreach (Province province in provincesInHex) { foundProvinces.Add(province); provinces[0].Add(province); } startHex = false; } else { distance++; provinces[distance] = new List <Province>(); foreach (Cell cell in hexRing) { //Check if there is a path from the start cell to this one if (worldMapGlobe.FindPath(startCell.index, cell.index) != null) { provincesInHex = GetProvicesInCell(cell); foreach (Province province in provincesInHex) { //Check that this province hasn't already been added if (!foundProvinces.Contains(province)) { foundProvinces.Add(province); provinces[distance].Add(province); } } } } } } } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.close_window); return(null); } return(provinces); }