Exemplo n.º 1
0
        public List <Province> MergeProvinceWithNeighbors(Province province, bool[] provinceSettings, bool mergeAcrossCountries)
        {
            if (!started)
            {
                Start();
            }

            int countryIndex = province.countryIndex;

            //Get all neighbors for province and loop through them
            int provinceIndex = worldMapGlobe.GetProvinceIndex(countryIndex, province.name);

            List <Province> neighbors = worldMapGlobe.ProvinceNeighboursOfMainRegion(provinceIndex);

            List <Province> removedProvinces = new List <Province>();

            bool mergeProvinces;

            foreach (Province neighbor in neighbors)
            {
                //This is a temp fix for provinces that haven't had their political name put in yet
                if (neighbor.attrib["PoliticalProvince"] == "")
                {
                    neighbor.attrib["PoliticalProvince"] = neighbor.name;
                }

                //Check that neighbor is in same country
                if (neighbor.countryIndex == countryIndex || mergeAcrossCountries)
                {
                    mergeProvinces = CheckIfProvincesShouldBeMerged(province, neighbor, provinceSettings);
                    if (mergeProvinces)
                    {
                        MergeProvinces(province, neighbor);
                        removedProvinces.Add(neighbor);
                    }
                }
            }
            return(removedProvinces);
        }
Exemplo n.º 2
0
        public void IntantiateMappables(Country country)
        {
            if (!started)
            {
                Start();
            }

            List <MountPoint> countryMountPoints = new List <MountPoint>();

            try
            {
                int countryIndex    = worldMapGlobe.GetCountryIndex(country.name);
                int mountPointCount = worldMapGlobe.GetMountPoints(countryIndex, countryMountPoints);
            }
            catch
            {
                errorHandler.ReportError("Failed to load country's mount points", ErrorState.restart_scene);
                return;
            }

            foreach (MountPoint mountPoint in countryMountPoints)
            {
                if (mountPoint.type == START_POINT && mountPoint.provinceIndex == worldMapGlobe.GetProvinceIndex(startingCountry, startingProvince))
                {
                    int startingCellIndex = worldMapGlobe.GetCellIndex(mountPoint.localPosition);
                    if (startingCellIndex < 0 || startingCellIndex > worldMapGlobe.cells.Length)
                    {
                        errorHandler.ReportError("Invalid starting mount point", ErrorState.restart_scene);
                    }
                    else
                    {
                        Cell startingCell       = worldMapGlobe.cells[startingCellIndex];
                        bool playerInstantiated = playerManager.IntantiatePlayer(startingCell);
                    }
                }
                if (mountPoint.type == CULTURAL_POINT) //&& loadedMapSettings.culturalLandmarks)
                {
                    LandmarkManager.InstantiateCulturalLandmark(mountPoint);
                }
            }
        }
Exemplo n.º 3
0
        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);
        }