protected override void RegisterElements() { if (transform.Find("Background05a") != null) { background05a = transform.Find("Background05a").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background05b") != null) { background05b = transform.Find("Background05b").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background05c") != null) { background05c = transform.Find("Background05c").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background05d") != null) { background05d = transform.Find("Background05d").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background04a") != null) { background04a = transform.Find("Background04a").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background04b") != null) { background04b = transform.Find("Background04b").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background04c") != null) { background04c = transform.Find("Background04c").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background04d") != null) { background04d = transform.Find("Background04d").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background03a") != null) { background03a = transform.Find("Background03a").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background03b") != null) { background03b = transform.Find("Background03b").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background03c") != null) { background03c = transform.Find("Background03c").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background03d") != null) { background03d = transform.Find("Background03d").gameObject.AddComponent <MapElement>(); } // if (transform.Find("Background06a") != null) { background06a = transform.Find("Background06a").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background06b") != null) { background06b = transform.Find("Background06b").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background06c") != null) { background06c = transform.Find("Background06c").gameObject.AddComponent <MapElement>(); } if (transform.Find("Background06d") != null) { background06d = transform.Find("Background06d").gameObject.AddComponent <MapElement>(); } }
public void SaveMap(Map map, string path) { Debug.Log("Saving map at: " + path); var mapLines = new List <string>(); MapElement lastMapElem = null; var elems = new List <MapElement>(); //Config elems.AddRange(map.UnchangedElements); //Players foreach (var player in DomEdit.I.MapMan.Map.Players) { elems.Add(new AllowedPlayer { NationNum = player.Nation.id }); elems.Add(new StartLocation { NationNum = player.Nation.id, ProvinceNum = player.CapitalProvinceNum }); } //Provinces foreach (var province in map.ProvinceMap.Values) { bool isIndieProvince = province.Owner == Nation.Independents; bool hasIndieMonsters = isIndieProvince && province.Monsters.Any(); if (!isIndieProvince || hasIndieMonsters) { elems.Add(new Land { ProvinceNum = province.ProvinceNumber }); if (!isIndieProvince) { elems.Add(new ProvinceOwner { NationNum = province.Owner.id }); if (province.HasLab) { elems.Add(new Laboratory()); } if (province.HasTemple) { elems.Add(new Temple()); } if (province.HasFort) { elems.Add(new Fort { FortId = 1 }); } if (DomEdit.I.MapMan.Map.Players.Any(x => x.CapitalProvinceNum == province.ProvinceNumber)) { elems.Add(new KnownMagicSite { ProvinceNum = province.ProvinceNumber, SiteId = 1500 }); } } } } //Monsters foreach (var province in map.ProvinceMap.Values.Where(x => x.Monsters.Any())) { elems.Add(new SetLand { ProvinceNum = province.ProvinceNumber }); var nationalityMonsterGroups = province.Monsters.GroupBy(x => x.Nationality); foreach (var group in nationalityMonsterGroups) { var nation = group.Key; // if (nation != Nation.Independents) // { elems.Add(new ProvinceOwner { NationNum = nation.id }); // } foreach (var monster in group) { switch (monster) { case Commander commander: elems.Add(new CommanderElement { MonsterId = commander.MonsterId, ProvinceNum = province.ProvinceNumber }); foreach (var unit in commander.UnitsUnderCommand) { elems.Add(new UnitsElement { MonsterId = unit.MonsterId, Amount = unit.Amount, ProvinceNum = province.ProvinceNumber }); } foreach (var item in commander.Items) { elems.Add(new ItemElement { ItemName = item.ItemName }); } foreach (var magicOverride in commander.MagicOverrides) { Magic magic = magicOverride.Path switch { MagicPath.Fire => new FireMagic(), MagicPath.Air => new AirMagic(), MagicPath.Water => new WaterMagic(), MagicPath.Earth => new EarthMagic(), MagicPath.Astral => new AstralMagic(), MagicPath.Death => new DeathMagic(), MagicPath.Nature => new NatureMagic(), MagicPath.Blood => new BloodMagic(), MagicPath.Holy => new HolyMagic(), _ => throw new ArgumentOutOfRangeException() }; magic.MagicLevel = magicOverride.MagicValue; elems.Add(magic); } break; case Troops troops: elems.Add(new UnitsElement { MonsterId = troops.MonsterId, Amount = troops.Amount, ProvinceNum = province.ProvinceNumber }); break; default: throw new ArgumentOutOfRangeException(nameof(monster)); } } } if (province.Owner != Nation.Independents) { elems.Add(new ProvinceOwner { NationNum = province.Owner.id }); } } foreach (var mapElement in elems) { var key = GetMapElementKey(mapElement.GetType()); var mapLine = $"#{key} {string.Join(" ", mapElement.SaveArgs())}"; bool isDifferentTypeFromPrevious = lastMapElem != null && lastMapElem.GetType() != mapElement.GetType(); if (mapElement is IOwnedByProvince && lastMapElem is IOwnedByProvince) { isDifferentTypeFromPrevious = false; } if (isDifferentTypeFromPrevious) { mapLines.Add(""); } mapLines.Add(mapLine); lastMapElem = mapElement; } File.WriteAllLines(path, mapLines); }