Exemple #1
0
        public void ProvinceTransferTo(int targetCountryIndex, int provinceIndex)
        {
            // Remove province form source country
            Province province      = map.provinces [provinceIndex];
            Country  sourceCountry = map.countries [countryIndex];

            if (map.countries [countryIndex].provinces != null)
            {
                List <Province> sourceProvinces = new List <Province> (sourceCountry.provinces);
                int             provIndex       = -1;
                for (int k = 0; k < sourceCountry.provinces.Length; k++)
                {
                    if (sourceCountry.provinces [k].name.Equals(province.name))
                    {
                        provIndex = k;
                    }
                }
                if (provIndex >= 0)
                {
                    sourceProvinces.RemoveAt(provIndex);
                    sourceCountry.provinces = sourceProvinces.ToArray();
                }
            }

            // Adds province to target country
            Country targetCountry = map.countries [targetCountryIndex];

            if (targetCountry.provinces == null)
            {
                targetCountry.provinces = new Province[0];
            }
            List <Province> destProvinces = new List <Province> (targetCountry.provinces);

            destProvinces.Add(province);
            targetCountry.provinces = destProvinces.ToArray();

            // Apply boolean operations on country polygons
            Region provinceRegion = province.regions [provinceRegionIndex];
            Region sourceRegion   = sourceCountry.regions [sourceCountry.mainRegionIndex];
            Region targetRegion   = targetCountry.regions [targetCountry.mainRegionIndex];

            // Extract from source country - only if province is in the frontier or is crossing the country
            for (int k = 0; k < sourceCountry.regions.Count; k++)
            {
                Region otherSourceRegion = sourceCountry.regions [k];
                otherSourceRegion.sanitized = true;
            }
            PolygonClipper pc = new PolygonClipper(sourceRegion, provinceRegion);

            if (pc.OverlapsSubjectAndClipping())
            {
                sourceRegion.sanitized = false;
                pc.Compute(PolygonOp.DIFFERENCE);
            }
            else
            {
                // Look for other regions to substract
                for (int k = 0; k < sourceCountry.regions.Count; k++)
                {
                    Region otherSourceRegion = sourceCountry.regions [k];
                    pc = new PolygonClipper(otherSourceRegion, provinceRegion);
                    if (pc.OverlapsSubjectAndClipping())
                    {
                        otherSourceRegion.sanitized = false;
                        pc.Compute(PolygonOp.DIFFERENCE);
                    }
                }
            }

            // Remove invalid regions from source country
            for (int k = 0; k < sourceCountry.regions.Count; k++)
            {
                Region otherSourceRegion = sourceCountry.regions [k];
                if (!otherSourceRegion.sanitized && otherSourceRegion.points.Length < 5)
                {
                    sourceCountry.regions.RemoveAt(k);
                    k--;
                }
            }

            // Add region to target country's polygon - only if the province is touching or crossing target country frontier
            pc = new PolygonClipper(targetRegion, provinceRegion);
            if (pc.OverlapsSubjectAndClipping())
            {
                pc.Compute(PolygonOp.UNION);
            }
            else
            {
                // Add new region to country
                Region newCountryRegion = new Region(targetCountry, targetCountry.regions.Count);
                newCountryRegion.points = new List <Vector3> (provinceRegion.points).ToArray();
                targetCountry.regions.Add(newCountryRegion);
            }

            //Max!
            if (!map.showCities && map.cities == null)
            {
                map.ReadCitiesPackedString();
            }

            // Transfer cities
            int cityCount = map.cities.Count;

            for (int k = 0; k < cityCount; k++)
            {
                City city = map.cities [k];
                if (city.countryIndex == countryIndex && city.province.Equals(province.name))
                {
                    city.countryIndex = targetCountryIndex;
                }
            }

            // Transfer mount points
            int mountPointCount = map.mountPoints.Count;

            for (int k = 0; k < mountPointCount; k++)
            {
                MountPoint mp = map.mountPoints [k];
                if (mp.countryIndex == countryIndex && mp.provinceIndex == provinceIndex)
                {
                    mp.countryIndex = targetCountryIndex;
                }
            }

            // Finish operation
            map.HideCountryRegionHighlights(true);
            map.HideProvinceRegionHighlights(true);
            map.RefreshCountryDefinition(province.countryIndex, null);
            province.countryIndex = targetCountryIndex;
            map.RefreshProvinceDefinition(provinceIndex);
            map.RefreshCountryDefinition(targetCountryIndex, null);
            countryChanges    = true;
            provinceChanges   = true;
            cityChanges       = true;
            mountPointChanges = true;
        }
Exemple #2
0
        /// <summary>
        /// Separates a province from its current country producing a new country
        /// </summary>
        public void ProvinceSeparate(string newCountryName)
        {
            if (provinceIndex < 0 || provinceIndex >= map.provinces.Length)
            {
                return;
            }

            // Remove province form source country
            Province province      = map.provinces [provinceIndex];
            Country  sourceCountry = map.countries [countryIndex];

            if (map.countries [countryIndex].provinces != null)
            {
                List <Province> sourceProvinces = new List <Province> (sourceCountry.provinces);
                int             provIndex       = -1;
                for (int k = 0; k < sourceCountry.provinces.Length; k++)
                {
                    if (sourceCountry.provinces [k].name.Equals(province.name))
                    {
                        provIndex = k;
                    }
                }
                if (provIndex >= 0)
                {
                    sourceProvinces.RemoveAt(provIndex);
                    sourceCountry.provinces = sourceProvinces.ToArray();
                }
            }

            // Adds province region to a new country
            Region  regionProvince = province.regions [provinceRegionIndex];
            Country targetCountry  = new Country(newCountryName, sourceCountry.continent);
            Region  region         = new Region(targetCountry, 0);

            region.points = new List <Vector3> (regionProvince.points).ToArray();
            targetCountry.regions.Add(region);
            map.CountryAdd(targetCountry);
            int targetCountryIndex = map.countries.Length - 1;

            map.RefreshCountryDefinition(targetCountryIndex, null);
            lastCountryCount = -1;

            // Add province to the new country
            if (targetCountry.provinces == null)
            {
                targetCountry.provinces = new Province[0];
            }
            List <Province> destProvinces = new List <Province> (targetCountry.provinces);

            destProvinces.Add(province);
            targetCountry.provinces = destProvinces.ToArray();

            // Apply boolean operations on country polygons
            Region provinceRegion = province.regions [provinceRegionIndex];
            Region sourceRegion   = sourceCountry.regions [sourceCountry.mainRegionIndex];

            // Extract from source country - only if province is in the frontier or is crossing the country
            for (int k = 0; k < sourceCountry.regions.Count; k++)
            {
                Region otherSourceRegion = sourceCountry.regions [k];
                otherSourceRegion.sanitized = true;
            }
            PolygonClipper pc = new PolygonClipper(sourceRegion, provinceRegion);

            if (pc.OverlapsSubjectAndClipping())
            {
                sourceRegion.sanitized = false;
                pc.Compute(PolygonOp.DIFFERENCE);
            }
            else
            {
                // Look for other regions to substract
                for (int k = 0; k < sourceCountry.regions.Count; k++)
                {
                    Region otherSourceRegion = sourceCountry.regions [k];
                    pc = new PolygonClipper(otherSourceRegion, provinceRegion);
                    if (pc.OverlapsSubjectAndClipping())
                    {
                        otherSourceRegion.sanitized = false;
                        pc.Compute(PolygonOp.DIFFERENCE);
                    }
                }
            }

            // Remove invalid regions from source country
            for (int k = 0; k < sourceCountry.regions.Count; k++)
            {
                Region otherSourceRegion = sourceCountry.regions [k];
                if (!otherSourceRegion.sanitized && otherSourceRegion.points.Length < 5)
                {
                    sourceCountry.regions.RemoveAt(k);
                    k--;
                }
            }

            // Transfer cities
            int cityCount = map.cities.Count;

            for (int k = 0; k < cityCount; k++)
            {
                City city = map.cities [k];
                if (city.countryIndex == countryIndex && city.province.Equals(province.name))
                {
                    city.countryIndex = targetCountryIndex;
                }
            }

            // Transfer mount points
            int mountPointCount = map.mountPoints.Count;

            for (int k = 0; k < mountPointCount; k++)
            {
                MountPoint mp = map.mountPoints [k];
                if (mp.countryIndex == countryIndex && mp.provinceIndex == provinceIndex)
                {
                    mp.countryIndex = targetCountryIndex;
                }
            }

            // Finish operation
            map.HideCountryRegionHighlights(true);
            map.HideProvinceRegionHighlights(true);
            map.RefreshCountryDefinition(province.countryIndex, null);
            province.countryIndex = targetCountryIndex;
            map.RefreshProvinceDefinition(provinceIndex);
            map.RefreshCountryDefinition(targetCountryIndex, null);
            countryChanges    = true;
            provinceChanges   = true;
            cityChanges       = true;
            mountPointChanges = true;
            ProvinceRegionSelect();
        }
Exemple #3
0
        /// <summary>
        /// Deletes current region or province if this was the last region
        /// </summary>
        public void ProvinceDelete()
        {
            if (provinceIndex < 0 || provinceIndex >= map.provinces.Length)
            {
                return;
            }

            // Apply boolean operations on country polygons
            Province province       = map.provinces [provinceIndex];
            Region   provinceRegion = province.regions [provinceRegionIndex];
            Country  sourceCountry  = map.countries [countryIndex];

            // Extract from source country - only if province is in the frontier or is crossing the country
            for (int k = 0; k < sourceCountry.regions.Count; k++)
            {
                Region otherSourceRegion = sourceCountry.regions [k];
                otherSourceRegion.sanitized = true;
            }
            for (int k = 0; k < sourceCountry.regions.Count; k++)
            {
                Region         otherSourceRegion = sourceCountry.regions [k];
                PolygonClipper pc = new PolygonClipper(otherSourceRegion, provinceRegion);
                if (pc.OverlapsSubjectAndClipping())
                {
                    otherSourceRegion.sanitized = false;
                    pc.Compute(PolygonOp.DIFFERENCE);
                }
            }

            // Remove invalid regions from source country
            for (int k = 0; k < sourceCountry.regions.Count; k++)
            {
                Region otherSourceRegion = sourceCountry.regions [k];
                if (!otherSourceRegion.sanitized && otherSourceRegion.points.Length < 5)
                {
                    sourceCountry.regions.RemoveAt(k);
                    k--;
                }
            }

            // Remove it from the country array
            List <Province> newProvinces = new List <Province> (map.countries [countryIndex].provinces.Length - 1);

            for (int k = 0; k < map.countries [countryIndex].provinces.Length; k++)
            {
                if (!map.countries [countryIndex].provinces [k].name.Equals(GUIProvinceName))
                {
                    newProvinces.Add(map.countries [countryIndex].provinces [k]);
                }
            }
            map.countries [countryIndex].provinces = newProvinces.ToArray();
            // Remove from the global array
            newProvinces = new List <Province> (map.provinces.Length - 1);
            for (int k = 0; k < map.provinces.Length; k++)
            {
                if (k != provinceIndex)
                {
                    newProvinces.Add(map.provinces [k]);
                }
            }
            map.provinces = newProvinces.ToArray();

            // Finish operation
            map.HideCountryRegionHighlights(true);
            map.HideProvinceRegionHighlights(true);
            map.RefreshCountryDefinition(countryIndex, null);
            ClearProvinceSelection();
            map.OptimizeFrontiers();
            map.Redraw();
            countryChanges  = true;
            provinceChanges = true;
            CountryRegionSelect();
        }