public void MountPointSelect() { if (mountPointIndex < 0 || mountPointIndex > map.mountPoints.Count) { return; } // If no country is selected (the mount point could be at sea) select it MountPoint mp = map.mountPoints[mountPointIndex]; int mpCountryIndex = mp.countryIndex; if (mpCountryIndex < 0) { SetInfoMsg("Country not found in this country file."); } if (countryIndex != mpCountryIndex && mpCountryIndex >= 0) { ClearSelection(); countryIndex = mpCountryIndex; countryRegionIndex = map.countries[countryIndex].mainRegionIndex; CountryRegionSelect(); } // Just in case makes GUICountryIndex selects appropiate value in the combobox GUIMountPointName = mp.name; SyncGUIMountPointSelection(); if (mountPointIndex >= 0) { GUIMountPointNewName = mp.name; GUIMountPointNewType = mp.type.ToString(); MountPointHighlightSelection(); } }
/// <summary> /// Redraws the mounts points but only in editor time. This is automatically called by Redraw(). Used internally by the Map Editor. You should not need to call this method directly. /// </summary> public void DrawMountPoints() { // Create mount points layer Transform t = transform.Find("Mount Points"); if (t != null) { DestroyImmediate(t.gameObject); } if (Application.isPlaying || mountPoints == null) { return; } mountPointsLayer = new GameObject("Mount Points"); mountPointsLayer.transform.SetParent(transform, false); // Draw mount points marks for (int k = 0; k < mountPoints.Count; k++) { MountPoint mp = mountPoints [k]; GameObject mpObj = Instantiate(mountPointSpot); mpObj.name = k.ToString(); mpObj.transform.position = transform.TransformPoint(mp.unity2DLocation); mpObj.hideFlags = HideFlags.DontSave | HideFlags.HideInHierarchy; mpObj.transform.SetParent(mountPointsLayer.transform, true); } MountPointScaler mpScaler = mountPointsLayer.GetComponent <MountPointScaler>() ?? mountPointsLayer.AddComponent <MountPointScaler>(); mpScaler.map = this; mpScaler.ScaleMountPoints(); }
public void MountPointAdd(Vector2 location, string name, int countryIndex, int provinceIndex, int type) { MountPoint newMountPoint = new MountPoint(name, countryIndex, provinceIndex, location, type); if (mountPoints == null) { mountPoints = new List <MountPoint>(); } mountPoints.Add(newMountPoint); }
public MountPoint Clone() { // Clone dictionary Dictionary <string, string> tags = new Dictionary <string, string>(customTags.Count, customTags.Comparer); foreach (KeyValuePair <string, string> entry in customTags) { tags.Add(entry.Key, (string)entry.Value.Clone()); } MountPoint c = new MountPoint(name, countryIndex, provinceIndex, unity2DLocation, type, tags); return(c); }
void TransferRegionMountPoints(int countryIndex, Region countryRegion, int targetCountryIndex) { int mpCount = _map.mountPoints.Count; for (int k = 0; k < mpCount; k++) { MountPoint mp = _map.mountPoints[k]; if (mp.countryIndex == countryIndex && countryRegion.Contains(mp.unity2DLocation)) { mp.countryIndex = targetCountryIndex; mountPointChanges = true; } } }
public bool MountPointAddNewTag() { if (mountPointIndex < 0) { return(false); } MountPoint mp = map.mountPoints[mountPointIndex]; if (!mp.customTags.ContainsKey(GUIMountPointNewTagKey)) { mp.customTags.Add(GUIMountPointNewTagKey, GUIMountPointNewTagValue); GUIMountPointNewTagKey = ""; GUIMountPointNewTagValue = ""; mountPointChanges = true; return(true); } return(false); }
bool GetMountPointUnderMouse(int countryIndex, Vector2 localPoint, out int mountPointIndex) { float hitPrecission = MOUNT_POINT_HIT_PRECISION * _cityIconSize * 5.0f; for (int c = 0; c < mountPoints.Count; c++) { MountPoint mp = mountPoints[c]; if (mp.countryIndex == countryIndex) { if ((mp.unity2DLocation - localPoint).magnitude < hitPrecission) { mountPointIndex = c; return(true); } } } mountPointIndex = -1; return(false); }
/// <summary> /// Exports the geographic data in packed string format. /// </summary> public string GetMountPointsGeoData() { StringBuilder sb = new StringBuilder(); for (int k = 0; k < map.mountPoints.Count; k++) { MountPoint mp = map.mountPoints[k]; if (k > 0) { sb.Append("|"); } sb.Append(DataEscape(mp.name) + "$"); string province = ""; if (mp.provinceIndex >= 0 && mp.provinceIndex < map.provinces.Length) { province = map.provinces[mp.provinceIndex].name; } string country = ""; if (mp.countryIndex >= 0 && mp.countryIndex < map.countries.Length) { country = map.countries[mp.countryIndex].name; } sb.Append(province + "$"); sb.Append(country + "$"); sb.Append(mp.type + "$"); sb.Append(mp.unity2DLocation.x.ToString(CultureInfo.InvariantCulture) + "$"); sb.Append(mp.unity2DLocation.y.ToString(CultureInfo.InvariantCulture) + "$"); int tc = 0; foreach (string key in mp.customTags.Keys) { if (tc++ > 0) { sb.Append("$"); } sb.Append(key); sb.Append("&"); sb.Append(DataEscape(mp.customTags[key])); } } return(sb.ToString()); }
/// <summary> /// Reads the mount points data from a packed string. /// </summary> void ReadMountPointsPackedString(string s) { string[] mountPointsList = s.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); int mountPointsCount = mountPointsList.Length; mountPoints = new List <MountPoint> (mountPointsCount); for (int k = 0; k < mountPointsCount; k++) { string[] mountPointInfo = mountPointsList [k].Split(new char[] { '$' }); string name = mountPointInfo [0]; string country = mountPointInfo [2]; int countryIndex = GetCountryIndex(country); if (countryIndex >= 0) { string province = mountPointInfo [1]; int provinceIndex = GetProvinceIndex(countryIndex, province); int type = int.Parse(mountPointInfo [3], CultureInfo.InvariantCulture); float x = float.Parse(mountPointInfo [4], CultureInfo.InvariantCulture); float y = float.Parse(mountPointInfo [5], CultureInfo.InvariantCulture); Dictionary <string, string> tags = new Dictionary <string, string>(); for (int t = 6; t < mountPointInfo.Length; t++) { string tag = mountPointInfo[t]; string[] tagInfo = tag.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries); if (tagInfo != null && tagInfo.Length > 1) { string key = tagInfo[0]; string value = tagInfo[1]; if (!tags.ContainsKey(key)) { tags.Add(key, value); } } } MountPoint mountPoint = new MountPoint(name, countryIndex, provinceIndex, new Vector2(x, y), type, tags); mountPoints.Add(mountPoint); } } }
/// <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(); }
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; }