/// <summary> /// Creates a country with a name and list of points. /// </summary> /// <returns>The country index.</returns> int CreateCountry(string name, Vector2[] points) { // 1) Initialize a new country Country country = new Country(name, "Continent", 1); // 2) Define the land region for this country with a list of points with coordinates from -0.5, -0.5 (bottom/left edge of map) to 0.5, 0.5 (top/right edge of map) // Note: the list of points should be expressed in clock-wise order Region region = new Region(country, 0); region.UpdatePointsAndRect(points); // 3) Add the region to the country (a country can have multiple regions, like islands) country.regions.Add(region); // 4) Add the new country to the map int countryIndex = map.CountryAdd(country); return(countryIndex); }
void UpdateCountries() { WMSK map = WMSK.instance; if (committingProgress < 0.1f) { committingStatus = "Refreshing country frontiers..."; committingProgress = 0.25f; } else if (committingProgress < 0.3f) { newCountries = ti.GetCountries(); if (additive) { for (int k = 0; k < newCountries.Length; k++) { map.CountryAdd(newCountries [k]); } } else { map.countries = newCountries; } map.editor.countryChanges = true; for (int k = 0; k < map.countries.Length; k++) { map.CountrySanitize(k, 5); } committingProgress = 0.4f; } else if (committingProgress < 0.5f) { committingStatus = "Refreshing provinces..."; committingProgress = 0.6f; } else if (committingProgress < 0.7f) { // Update provinces references List <Province> newProvinces = new List <Province> (map.provinces.Length); for (int k = 0; k < map.provinces.Length; k++) { Province prov = map.provinces [k]; if (prov.regions == null) { map.ReadProvincePackedString(prov); if (prov.regions == null) { prov.center = new Vector2(-1000, -1000); } } int countryIndex = map.GetCountryIndex(prov.center); if (countryIndex < 0) { // Province deleted/ignored map.editor.provinceChanges = true; } else if (prov.countryIndex != countryIndex) { prov.countryIndex = countryIndex; map.editor.provinceChanges = true; newProvinces.Add(prov); } } map.provinces = newProvinces.ToArray(); // Update country provinces newProvinces.Clear(); for (int k = 0; k < map.countries.Length; k++) { newProvinces.Clear(); for (int p = 0; p < map.provinces.Length; p++) { if (map.provinces [p].countryIndex == k) { newProvinces.Add(map.provinces [p]); } } map.countries [k].provinces = newProvinces.ToArray(); } committingProgress = 0.8f; } else if (committingProgress < 0.9f) { committingStatus = "Refreshing other dependencies..."; committingProgress = 0.95f; } else { // Update city references int citiesCount = map.cities.Length; List <City> cities = new List <City>(map.cities); for (int k = 0; k < citiesCount; k++) { City city = cities [k]; int countryIndex = map.GetCountryIndex(city.unity2DLocation); if (countryIndex >= 0) { if (city.countryIndex != countryIndex) { city.countryIndex = countryIndex; map.editor.cityChanges = true; } } else { cities.RemoveAt(k); map.editor.cityChanges = true; k--; citiesCount--; } } map.cities = cities.ToArray(); // Update mount points references if (map.mountPoints != null) { int mpCount = map.mountPoints.Count; for (int k = 0; k < mpCount; k++) { MountPoint mp = map.mountPoints [k]; int countryIndex = map.GetCountryIndex(mp.unity2DLocation); if (countryIndex >= 0) { if (mp.countryIndex != countryIndex) { mp.countryIndex = countryIndex; map.editor.mountPointChanges = true; } } else { map.mountPoints.RemoveAt(k); map.editor.mountPointChanges = true; k--; mpCount--; } } } committingProgress = 1f; } }