public void ComputePath() { if (latLon == null) { errorHandler.ReportError("Latlon missing", ErrorState.close_window); return; } try { // Compute path length int steps = latLon.Count; stepLengths = new float[steps]; // Calculate total travel length totalLength = 0; for (int k = 0; k < steps - 1; k++) { stepLengths[k] = worldMapGlobe.calc.Distance(latLon[k], latLon[k + 1]); totalLength += stepLengths[k]; } Debug.Log("Total path length = " + totalLength / 1000 + " km."); } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.close_window); } }
void Start() { gameManager = interfaceFactory.GameManager; globeManager = interfaceFactory.GlobeManager; uiManager = interfaceFactory.UIManager; errorHandler = interfaceFactory.ErrorHandler; if (gameManager == null || globeManager == null || uiManager == null || errorHandler == null) { gameObject.SetActive(false); } else { if (componentMissing) { errorHandler.ReportError("Mouse Cell Enterer missing component", ErrorState.restart_scene); } worldMapGlobe = globeManager.WorldMapGlobe; if (worldMapGlobe == null) { errorHandler.ReportError("World Map Globe missing", ErrorState.restart_scene); } try { globeManager.WorldMapGlobe.OnCellEnter += HandleOnCellEnter; } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.restart_scene); } } }
public List <Country>[] GetCountriesInRange(Cell startCell, int range) { if (range < 0 || startCell.index < 0 || worldMapGlobe.cells.Count() < startCell.index) { errorHandler.ReportError("Invalid input for GetCountriesInRange", ErrorState.close_window); return(null); } List <Country>[] countries = new List <Country> [range + 1]; //provinces is an array of lists with each list containing List <Country> foundCountries = new List <Country>(); //the provinces that can be reached at that distance. List <Province>[] provinces = provinceParser.GetProvincesInRange(startCell, range); if (provinces == null) { errorHandler.ReportError("Failed to parse provinces", ErrorState.close_window); return(null); } try { //Create lists of the countries within range based off of the provinces in range int i = 0; //Province province; foreach (List <Country> countryList in countries) { foreach (Province province in provinces[i]) { Country country = worldMapGlobe.countries[province.countryIndex]; if (!foundCountries.Contains(country)) { foundCountries.Add(country); countries[i].Add(country); } } i++; } } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.close_window); } return(countries); }
public List <Landmark> GetLandmarksInCell(Cell cell) { List <Landmark> landmarks = new List <Landmark>(); try { foreach (MappableObject mappableObject in cell.occupants) { if (mappableObject is Landmark) { Landmark castedLandmark = mappableObject as Landmark; landmarks.Add(castedLandmark); } } } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.close_window); return(null); } return(landmarks); }
/// <summary> /// Check if a given location is a correct drop off location given a desired province /// </summary> /// <param name="dropOffCell"> The cell drop off cell </param> /// <param name="provinceDestination"> The desired province destination </param> private bool AttemptProvinceDropOff(Cell dropOffCell, Province provinceDestination) { bool dropOffSuccess = false; if (provinceDestination == null) { errorHandler.ReportError("Drop Off Failed: Province destination not set", ErrorState.close_window); return(false); } List <Province> selectedProvinces = provinceParser.GetProvicesInCell(dropOffCell); if (selectedProvinces == null) { errorHandler.ReportError("Drop Off Failed: No provinces in cell", ErrorState.close_window); return(false); } foreach (Province province in selectedProvinces) { try { if (province == provinceDestination) { dropOffSuccess = true; break; } } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.close_window); return(false); } } return(dropOffSuccess); }
/// <summary> /// Called when a tourist needs to be generated and added to the palyer's inventory /// </summary> public void GenerateTourist() { //Get Player Character IPlayerCharacter playerCharacter = playerManager.PlayerCharacter; if (playerCharacter == null) { errorHandler.ReportError("Player character missing", ErrorState.restart_scene); return; } //Intantiate tourist GameObject touristObject = Instantiate(touristPrefab, new Vector3(0, 0, 0), Quaternion.identity); touristObject.transform.parent = inventoryUI.UIObject.transform; IInventoryTourist tourist = touristObject.GetComponent(typeof(IInventoryTourist)) as IInventoryTourist; if (tourist == null) { errorHandler.ReportError("Tourist component of tourist prefab missing", ErrorState.restart_scene); return; } //Give tourist its image tourist.InventoryIcon = Resources.Load <Sprite>(touristImageFiles[touristImageIndex]); touristImageIndex++; if (touristImageIndex >= NUMBER_OF_TOURIST_IMAGES) { touristImageIndex = 0; } //Add tourist to player's inventory playerCharacter.Inventory.AddItem(tourist, 0); //Check if a region switch is needed touristsInCurrentRegion++; int rand = Random.Range(MIN_TIME_IN_REGION, MAX_TIME_IN_REGION); if (touristsInCurrentRegion >= rand) { //Switch regions try { int newRegionNeighbourIndex = Random.Range(0, CurrentRegion.neighbouringRegions.Count - 1); CurrentRegion = CurrentRegion.neighbouringRegions[newRegionNeighbourIndex]; touristsInCurrentRegion = 0; } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.restart_scene); } } }
/// <summary> /// Set the terrain costs of all the cells that are reachable by the player /// </summary> public void SetCellCosts() { if (CellsInRange == null) { errorHandler.ReportError("Cells in range empty", ErrorState.restart_scene); return; } foreach (Cell cell in CellsInRange[0]) { try { //Get Climate From Cell int provinceIndex = worldMapGlobe.GetProvinceNearPoint(cell.sphereCenter); Province province = worldMapGlobe.provinces[provinceIndex]; string climateAttribute = province.attrib["ClimateGroup"]; //Loop Through Each Neighbor and Set the Cost from the Neighbor to the Cell if (climateAttribute != "") { bool cellOccupied = false; //Check if cell is occupied by something other than the player if (cell.occupants.Any() && !cell.occupants.Contains(playerCharacter)) { cellOccupied = true; } int cost = playerCharacter.ClimateCosts[climateAttribute]; if (cost == IMPASSABLE || cellOccupied) { worldMapGlobe.SetCellCanCross(cell.index, false); } else { worldMapGlobe.SetCellCanCross(cell.index, true); foreach (Cell neighbour in worldMapGlobe.GetCellNeighbours(cell.index)) { worldMapGlobe.SetCellNeighbourCost(neighbour.index, cell.index, cost, false); } } } } catch (Exception ex) { errorHandler.CatchException(ex, ErrorState.close_window); } } }
/// <summary> /// Merge a neighboring province into a given province /// </summary> /// <param name="mainProvince"> The province absorbing its neighbor </param> /// <param name="neighbor"> The province being absorbed </param> private void MergeProvinces(Province mainProvince, Province neighbor) { try { int provinceIndex = worldMapGlobe.GetProvinceIndex(mainProvince.countryIndex, mainProvince.name); //Merge provinces worldMapGlobe.ProvinceTransferProvinceRegion(provinceIndex, neighbor.mainRegion, true); //Clear unused attributes //if (!loadedMapSettings.provinces) // neighbor.attrib["PoliticalProvince"] = ""; //if (!loadedMapSettings.terrain) neighbor.attrib["Terrain"] = ""; //if (!loadedMapSettings.climate) neighbor.attrib["Climate"] = ""; } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.close_window); } }
void Start() { gameManager = interfaceFactory.GameManager; globeManager = interfaceFactory.GlobeManager; uiManager = interfaceFactory.UIManager; errorHandler = interfaceFactory.ErrorHandler; if (gameManager == null || globeManager == null || uiManager == null || errorHandler == null) { gameObject.SetActive(false); } else { try { globeManager.WorldMapGlobe.OnCellClick += HandleOnCellClick; } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.restart_scene); } } }
public List <Province> GetProvicesInCell(Cell cell) { List <Province> foundProvinces = new List <Province>(); List <Province> checkedProvinces = new List <Province>(); int provinceIndex; try { //Create a list of points including each vertex of the cell and its center point List <Vector3> cellPoints = cell.vertices.ToList(); cellPoints.Add(cell.sphereCenter); foreach (Vector3 cellPoint in cellPoints) { provinceIndex = worldMapGlobe.GetProvinceIndex(cellPoint); //Check if cell point is on a province if (provinceIndex == -1) { //Get closest province to point if it is not centered on one provinceIndex = worldMapGlobe.GetProvinceNearPoint(cellPoint); } //Add the province, if it is not already in the province list Province province = worldMapGlobe.provinces[provinceIndex]; if (!foundProvinces.Contains(province)) { foundProvinces.Add(province); } //Check to see if neighbours of province overlap with cell List <Province> provinceNeighbours = worldMapGlobe.ProvinceNeighbours(provinceIndex); bool provinceOverlaps; foreach (Province neighbor in provinceNeighbours) { //countryIndex = neighbor.countryIndex; //neighborIndex = worldMapGlobe.GetProvinceIndex(countryIndex, neighbor.name); //Make sure you haven't already checked the province, this saves time if (!checkedProvinces.Contains(neighbor)) { checkedProvinces.Add(neighbor); provinceOverlaps = false; foreach (Region region in neighbor.regions) { foreach (Vector3 spherePoint in region.spherePoints) { if (worldMapGlobe.GetCellIndex(spherePoint) == cell.index) { provinceOverlaps = true; break; } } if (provinceOverlaps) { break; } } if (provinceOverlaps && !foundProvinces.Contains(province)) { foundProvinces.Add(neighbor); } } } } } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.close_window); return(null); } return(foundProvinces); }