/// <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); } } }
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); }