protected virtual void SetMapPlayers(ScnFile file, List <string> players, MapPlayers mapPlayers) { int i = 0; foreach (var scnSection in file.Entries) { if (scnSection.Name != "SetStartLocation") { continue; } int x = Convert.ToInt32(scnSection.Values[0]); int y = Convert.ToInt32(scnSection.Values[1]); if (x != 0 && y != 0) { var multi = new PlayerReference { Name = "Multi" + i, Team = i + 2, Playable = true, Faction = "Random" }; mapPlayers.Players.Add(multi.Name, multi); i++; } } numMultiStarts = i; }
public virtual void Run(ModData modData, string[] args) { ModData = modData; // HACK: The engine code assumes that Game.modData is set. Game.ModData = modData; var filename = args[1]; using (var stream = modData.DefaultFileSystem.Open(filename)) { var file = new IniFile(stream); var basic = file.GetSection("Basic"); var mapSection = file.GetSection("Map"); var format = GetMapFormatVersion(basic); ValidateMapFormat(format); var tileset = GetTileset(mapSection); Map = new Map(modData, modData.DefaultTileSets[tileset], MapSize, MapSize) { Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)), Author = "Westwood Studios", }; Map.RequiresMod = modData.Manifest.Mod.Id; SetBounds(Map, mapSection); ReadPacks(file, filename); ReadTrees(file); LoadVideos(file, "BASIC"); LoadBriefing(file); ReadActors(file); LoadSmudges(file, "SMUDGE"); var waypoints = file.GetSection("Waypoints"); LoadWaypoints(waypoints); // Create default player definitions only if there are no players to import MapPlayers = new MapPlayers(Map.Rules, Players.Count == 0 ? spawnCount : 0); foreach (var p in Players) { LoadPlayer(file, p); } Map.PlayerDefinitions = MapPlayers.ToMiniYaml(); } Map.FixOpenAreas(); var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap"; var package = new ZipFile(modData.ModFiles, dest, true); Map.Save(package); Console.WriteLine(dest + " saved."); }
void Initialize(string mapFile) { mapSize = new Size(stream.ReadUInt16(), stream.ReadUInt16()); tileSet = Game.ModData.DefaultTileSets["ARRAKIS"]; map = new Map(Game.ModData, tileSet, mapSize.Width + 2 * MapCordonWidth, mapSize.Height + 2 * MapCordonWidth) { Title = Path.GetFileNameWithoutExtension(mapFile), Author = "Westwood Studios" }; var tl = new PPos(MapCordonWidth, MapCordonWidth); var br = new PPos(MapCordonWidth + mapSize.Width - 1, MapCordonWidth + mapSize.Height - 1); map.SetBounds(tl, br); // Get all templates from the tileset YAML file that have at least one frame and an Image property corresponding to the requested tileset // Each frame is a tile from the Dune 2000 tileset files, with the Frame ID being the index of the tile in the original file tileSetsFromYaml = tileSet.Templates.Where(t => t.Value.Frames != null && t.Value.Images[0].ToLower() == tilesetName.ToLower()).Select(ts => ts.Value).ToList(); var players = new MapPlayers(map.Rules, playerCount); map.PlayerDefinitions = players.ToMiniYaml(); }
public void CreatePlayers(World w) { if (w.Type != WorldType.Editor) return; Players = new MapPlayers(w.Map.PlayerDefinitions); }
void LoadMap(string mapname) { tilePalette.Controls.Clear(); actorPalette.Controls.Clear(); resourcePalette.Controls.Clear(); loadedMapName = mapname; // load the map var map = new Map(mapname); // upgrade maps that have no player definitions. editor doesnt care, // but this breaks the game pretty badly. if (map.PlayerDefinitions.Count == 0) { var players = new MapPlayers(map.Rules, map.SpawnPoints.Value.Length); map.PlayerDefinitions = players.ToMiniYaml(); } PrepareMapResources(Game.ModData, map); // Calculate total net worth of resources in cash cashToolStripStatusLabel.Text = CalculateTotalResource().ToString(); dirty = false; }
public static void SetMapPlayers(string section, string faction, string color, IniFile file, List<string> players, MapPlayers mapPlayers) { var pr = new PlayerReference { Name = section, OwnsWorld = section == "Neutral", NonCombatant = section == "Neutral", Faction = faction, Color = namedColorMapping[color] }; var neutral = new[] { "Neutral" }; foreach (var s in file.GetSection(section, true)) { switch (s.Key) { case "Allies": pr.Allies = s.Value.Split(',').Intersect(players).Except(neutral).ToArray(); pr.Enemies = s.Value.Split(',').SymmetricDifference(players).Except(neutral).ToArray(); break; default: Console.WriteLine("Ignoring unknown {0}={1} for player {2}", s.Key, s.Value, pr.Name); break; } } // Overwrite default player definitions if needed if (!mapPlayers.Players.ContainsKey(section)) mapPlayers.Players.Add(section, pr); else mapPlayers.Players[section] = pr; }
void NewClicked(object sender, EventArgs e) { using (var nmd = new NewMapDialog()) { nmd.TheaterBox.Items.Clear(); nmd.TheaterBox.Items.AddRange(Program.Rules.TileSets.Select(a => a.Value.Id).ToArray()); nmd.TheaterBox.SelectedIndex = 0; if (DialogResult.OK == nmd.ShowDialog()) { var tileset = Program.Rules.TileSets[nmd.TheaterBox.SelectedItem as string]; var map = Map.FromTileset(tileset); map.Resize((int)nmd.MapWidth.Value, (int)nmd.MapHeight.Value); map.ResizeCordon((int)nmd.CordonLeft.Value, (int)nmd.CordonTop.Value, (int)nmd.CordonRight.Value, (int)nmd.CordonBottom.Value); var players = new MapPlayers(map.Rules, map.SpawnPoints.Value.Length); map.PlayerDefinitions = players.ToMiniYaml(); map.FixOpenAreas(Program.Rules); NewMap(map); } } }
void Initialize(string mapFile) { stream.Seek(400, SeekOrigin.Begin); var x = stream.ReadInt32(); var y = stream.ReadInt32(); mapSize = new Size(x * 2, y * 2); tileSet = Game.ModData.DefaultTileSets[tilesetName]; map = new Map(Game.ModData, tileSet, mapSize.Width + 2 * MapCordonWidth, mapSize.Height + 2 * MapCordonWidth) { Title = Path.GetFileNameWithoutExtension(mapFile), Author = "Gate 5 Creations" }; var tl = new PPos(MapCordonWidth, MapCordonWidth); var br = new PPos(MapCordonWidth + mapSize.Width - 1, MapCordonWidth + mapSize.Height - 1); map.SetBounds(tl, br); stream.Seek(424, SeekOrigin.Begin); numberOfActors = stream.ReadInt32(); mapPlayers = new MapPlayers(map.Rules, 0); }
void Initialize(string mapFile) { stream.Seek(400, SeekOrigin.Begin); var x = stream.ReadInt32(); var y = stream.ReadInt32(); mapSize = new Size(x * 2, y * 2); if (!Game.ModData.DefaultTerrainInfo.TryGetValue(tileset, out var terrainInfo)) { throw new InvalidDataException("Unknown tileset {0}".F(tileset)); } this.terrainInfo = terrainInfo as CustomTerrain; map = new Map(Game.ModData, terrainInfo, mapSize.Width + 2 * MapCordonWidth, mapSize.Height + 2 * MapCordonWidth) { Title = Path.GetFileNameWithoutExtension(mapFile), Author = "Gate 5 Creations" }; var tl = new PPos(MapCordonWidth, MapCordonWidth); var br = new PPos(MapCordonWidth + mapSize.Width - 1, MapCordonWidth + mapSize.Height - 1); map.SetBounds(tl, br); stream.Seek(424, SeekOrigin.Begin); numberOfActors = stream.ReadInt32(); mapPlayers = new MapPlayers(map.Rules, 0); }
public void CreatePlayers(World w) { var players = new MapPlayers(w.Map.PlayerDefinitions).Players; var worldPlayers = new List <Player>(); // Create the unplayable map players -- neutral, shellmap, scripted, etc. foreach (var kv in players.Where(p => !p.Value.Playable)) { var player = new Player(w, null, kv.Value); worldPlayers.Add(player); if (kv.Value.OwnsWorld) { w.SetWorldOwner(player); } } Player localPlayer = null; // Create the regular playable players. foreach (var kv in w.LobbyInfo.Slots) { var client = w.LobbyInfo.ClientInSlot(kv.Key); if (client == null) { continue; } var player = new Player(w, client, players[kv.Value.PlayerReference]); worldPlayers.Add(player); if (client.Index == Game.LocalClientId) { localPlayer = player; } } // Create a player that is allied with everyone for shared observer shroud. worldPlayers.Add(new Player(w, null, new PlayerReference { Name = "Everyone", NonCombatant = true, Spectating = true, Faction = "Random", Allies = worldPlayers.Where(p => !p.NonCombatant && p.Playable).Select(p => p.InternalName).ToArray() })); w.SetPlayers(worldPlayers, localPlayer); foreach (var p in w.Players) { foreach (var q in w.Players) { if (!p.Stances.ContainsKey(q)) { p.Stances[q] = ChooseInitialStance(p, q); } } } }
ColorPalette GetPaletteForPlayerInner(string name) { var pr = new MapPlayers(Map.PlayerDefinitions).Players[name]; var pcpi = Program.Rules.Actors["world"].Traits.Get <PlayerColorPaletteInfo>(); var remap = new PlayerColorRemap(pcpi.RemapIndex, pr.Color, pcpi.Ramp); return(new ImmutablePalette(PlayerPalette, remap).AsSystemPalette()); }
public void Run(Action<string> emitError, Action<string> emitWarning, Map map) { var players = new MapPlayers(map.PlayerDefinitions).Players; var playerNames = players.Values.Select(p => p.Name).ToHashSet(); foreach (var player in players.Values) { foreach (var ally in player.Allies) if (!playerNames.Contains(ally)) emitError("Allies contains player {0} that is not in list.".F(ally)); foreach (var enemy in player.Enemies) if (!playerNames.Contains(enemy)) emitError("Enemies contains player {0} that is not in list.".F(enemy)); if (player.OwnsWorld && (player.Enemies.Any() || player.Allies.Any())) emitWarning("The player {0} owning the world should not have any allies or enemies.".F(player.Name)); } var worldActor = map.Rules.Actors["world"]; var factions = worldActor.TraitInfos<FactionInfo>().Select(f => f.InternalName).ToHashSet(); foreach (var player in players.Values) if (!string.IsNullOrWhiteSpace(player.Faction) && !factions.Contains(player.Faction)) emitError("Invalid faction {0} chosen for player {1}.".F(player.Faction, player.Name)); if (worldActor.HasTraitInfo<MPStartLocationsInfo>()) { var playerCount = players.Count(p => p.Value.Playable); var spawns = new List<CPos>(); foreach (var kv in map.ActorDefinitions.Where(d => d.Value.Value == "mpspawn")) { var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); spawns.Add(s.InitDict.Get<LocationInit>().Value(null)); } if (playerCount > spawns.Count) emitError("The map allows {0} possible players, but defines only {1} spawn points".F(playerCount, spawns.Count)); if (spawns.Distinct().Count() != spawns.Count) emitError("Duplicate spawn point locations detected."); } foreach (var kv in map.ActorDefinitions) { var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); var ownerInit = actorReference.InitDict.GetOrDefault<OwnerInit>(); if (ownerInit == null) emitError("Actor {0} is not owned by any player.".F(kv.Key)); else { var ownerName = ownerInit.PlayerName; if (!playerNames.Contains(ownerName)) emitError("Actor {0} is owned by unknown player {1}.".F(actorReference.Type, ownerName)); } } }
public void CreatePlayers(World w) { if (w.Type != WorldType.Editor) { return; } Players = new MapPlayers(w.Map.PlayerDefinitions); }
public void CreatePlayers(World w) { if (w.Type != WorldType.Editor) return; Players = new MapPlayers(w.Map.PlayerDefinitions); var worldOwner = Players.Players.Select(kvp => kvp.Value).First(p => !p.Playable && p.OwnsWorld); w.WorldActor.Owner = new Player(w, null, worldOwner); }
void SetupDefaultPlayers(object sender, EventArgs e) { dirty = true; var players = new MapPlayers(surface1.Map.Rules, surface1.Map.SpawnPoints.Value.Length); surface1.Map.PlayerDefinitions = players.ToMiniYaml(); surface1.Chunks.Clear(); surface1.Invalidate(); PopulateActorOwnerChooser(); }
void IUtilityCommand.Run(Utility utility, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = utility.ModData; var filename = args[1]; var file = new IniFile(File.Open(args[1], FileMode.Open)); var basic = file.GetSection("Basic"); var mapSection = file.GetSection("Map"); var tileset = mapSection.GetValue("Theater", ""); var iniSize = mapSection.GetValue("Size", "0, 0, 0, 0").Split(',').Select(int.Parse).ToArray(); var iniBounds = mapSection.GetValue("LocalSize", "0, 0, 0, 0").Split(',').Select(int.Parse).ToArray(); var size = new Size(iniSize[2], 2 * iniSize[3]); var author = args.Length > 2 ? args[2] : "Westwood Studios"; if (!utility.ModData.DefaultTerrainInfo.TryGetValue(tileset, out var terrainInfo)) { throw new InvalidDataException("Unknown tileset {0}".F(tileset)); } var map = new Map(Game.ModData, terrainInfo, size.Width, size.Height) { Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)), Author = author, Bounds = new Rectangle(iniBounds[0], iniBounds[1], iniBounds[2], 2 * iniBounds[3] + 2 * iniBounds[1]), RequiresMod = utility.ModData.Manifest.Id }; var fullSize = new int2(iniSize[2], iniSize[3]); ReadTiles(map, file, fullSize); ReadActors(map, file, "Structures", fullSize); ReadActors(map, file, "Units", fullSize); ReadActors(map, file, "Infantry", fullSize); ReadTerrainActors(map, file, fullSize); ReadWaypoints(map, file, fullSize); ReadOverlay(map, file, fullSize); ReadLighting(map, file); ReadLamps(map, file); var spawnCount = map.ActorDefinitions.Count(n => n.Value.Value == "mpspawn"); var mapPlayers = new MapPlayers(map.Rules, spawnCount); map.PlayerDefinitions = mapPlayers.ToMiniYaml(); var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap"; map.Save(ZipFileLoader.Create(dest)); Console.WriteLine(dest + " saved."); }
void ICreatePlayers.CreatePlayers(World w) { if (w.Type != WorldType.Editor) { return; } Players = new MapPlayers(w.Map.PlayerDefinitions); var worldOwner = Players.Players.Select(kvp => kvp.Value).First(p => !p.Playable && p.OwnsWorld); w.SetWorldOwner(new Player(w, null, worldOwner)); }
void ILintMapPass.Run(Action <string> emitError, Action <string> emitWarning, ModData modData, Map map) { var players = new MapPlayers(map.PlayerDefinitions); var spawns = new List <CPos>(); foreach (var kv in map.ActorDefinitions.Where(d => d.Value.Value == "mpspawn")) { var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); spawns.Add(s.Get <LocationInit>().Value); } Run(emitError, emitWarning, players, map.Visibility, map.Rules.Actors[SystemActors.World], spawns.ToArray()); }
public static Map Import(string filename, string mod, string tileset, Ruleset rules) { var map = new D2kMapImporter(filename, tileset, rules).map; if (map == null) { return(null); } map.RequiresMod = mod; var players = new MapPlayers(map.Rules, map.SpawnPoints.Value.Length); map.PlayerDefinitions = players.ToMiniYaml(); return(map); }
void IUtilityCommand.Run(ModData modData, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = modData; var filename = args[1]; var file = new IniFile(File.Open(args[1], FileMode.Open)); var basic = file.GetSection("Basic"); var mapSection = file.GetSection("Map"); var tileset = mapSection.GetValue("Theater", ""); var iniSize = mapSection.GetValue("Size", "0, 0, 0, 0").Split(',').Select(int.Parse).ToArray(); var iniBounds = mapSection.GetValue("LocalSize", "0, 0, 0, 0").Split(',').Select(int.Parse).ToArray(); var size = new Size(iniSize[2], 2 * iniSize[3]); var map = new Map(Game.ModData, modData.DefaultTileSets[tileset], size.Width, size.Height) { Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)), Author = "Westwood Studios", Bounds = new Rectangle(iniBounds[0], iniBounds[1], iniBounds[2], 2 * iniBounds[3] + 2 * iniBounds[1]), RequiresMod = modData.Manifest.Mod.Id }; var fullSize = new int2(iniSize[2], iniSize[3]); ReadTiles(map, file, fullSize); ReadActors(map, file, "Structures", fullSize); ReadActors(map, file, "Units", fullSize); ReadActors(map, file, "Infantry", fullSize); ReadTerrainActors(map, file, fullSize); ReadWaypoints(map, file, fullSize); ReadOverlay(map, file, fullSize); ReadLighting(map, file); var spawnCount = map.ActorDefinitions.Count(n => n.Value.Value == "mpspawn"); var mapPlayers = new MapPlayers(map.Rules, spawnCount); map.PlayerDefinitions = mapPlayers.ToMiniYaml(); var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap"; var package = new ZipFile(modData.DefaultFileSystem, dest, true); map.Save(package); Console.WriteLine(dest + " saved."); }
public void Run(Action<string> emitError, Action<string> emitWarning, Map map) { var players = new MapPlayers(map.PlayerDefinitions).Players; var playerNames = players.Values.Select(p => p.Name); foreach (var player in players) foreach (var ally in player.Value.Allies) if (!playerNames.Contains(ally)) emitError("Allies contains player {0} that is not in list.".F(ally)); foreach (var player in players) foreach (var enemy in player.Value.Enemies) if (!playerNames.Contains(enemy)) emitError("Enemies contains player {0} that is not in list.".F(enemy)); var races = map.Rules.Actors["world"].Traits.WithInterface<CountryInfo>().Select(c => c.Race); foreach (var player in players) if (!string.IsNullOrWhiteSpace(player.Value.Race) && player.Value.Race != "Random" && !races.Contains(player.Value.Race)) emitError("Invalid race {0} chosen for player {1}.".F(player.Value.Race, player.Value.Name)); }
protected void SetNeutralPlayer(MapPlayers mapPlayers) { var section = "Neutral"; var pr = new PlayerReference { Name = section, OwnsWorld = true, NonCombatant = true, Faction = "fguard", Color = Color.FromArgb(255, 255, 255) }; // Overwrite default player definitions if needed if (!mapPlayers.Players.ContainsKey(section)) { mapPlayers.Players.Add(section, pr); } else { mapPlayers.Players[section] = pr; } }
void CreateSaveMapButton() { if (world.Type != WorldType.Editor) { return; } var button = AddButton("SAVE_MAP", "Save Map"); button.OnClick = () => { hideMenu = true; var editorActorLayer = world.WorldActor.Trait <EditorActorLayer>(); var actionManager = world.WorldActor.Trait <EditorActionManager>(); var playerDefinitions = editorActorLayer.Players.ToMiniYaml(); var playerCount = new MapPlayers(playerDefinitions).Players.Count; if (playerCount > MapPlayers.MaximumPlayerCount) { ConfirmationDialogs.ButtonPrompt( title: "Error: Max player count exceeded", text: $"There are too many players defined ({playerCount}/{MapPlayers.MaximumPlayerCount}).", onConfirm: ShowMenu, confirmText: "Back"); return; } Ui.OpenWindow("SAVE_MAP_PANEL", new WidgetArgs() { { "onSave", (Action <string>)(_ => { hideMenu = false; actionManager.Modified = false; }) }, { "onExit", () => hideMenu = false }, { "map", world.Map }, { "playerDefinitions", playerDefinitions }, { "actorDefinitions", editorActorLayer.Save() } }); }; }
public void Run(Action <string> emitError, Action <string> emitWarning, Map map) { var players = new MapPlayers(map.PlayerDefinitions).Players; var playerNames = players.Values.Select(p => p.Name); foreach (var player in players) { foreach (var ally in player.Value.Allies) { if (!playerNames.Contains(ally)) { emitError("Allies contains player {0} that is not in list.".F(ally)); } } } foreach (var player in players) { foreach (var enemy in player.Value.Enemies) { if (!playerNames.Contains(enemy)) { emitError("Enemies contains player {0} that is not in list.".F(enemy)); } } } var races = map.Rules.Actors["world"].Traits.WithInterface <CountryInfo>().Select(c => c.Race); foreach (var player in players) { if (!string.IsNullOrWhiteSpace(player.Value.Race) && player.Value.Race != "Random" && !races.Contains(player.Value.Race)) { emitError("Invalid race {0} chosen for player {1}.".F(player.Value.Race, player.Value.Name)); } } }
public void Run(Action <string> emitError, Action <string> emitWarning, ModData modData, Map map) { var playerNames = new MapPlayers(map.PlayerDefinitions).Players.Values .Select(p => p.Name) .ToHashSet(); // Check for actors that require specific owners var actorsWithRequiredOwner = map.Rules.Actors .Where(a => a.Value.HasTraitInfo <RequiresSpecificOwnersInfo>()) .ToDictionary(a => a.Key, a => a.Value.TraitInfo <RequiresSpecificOwnersInfo>()); foreach (var kv in map.ActorDefinitions) { var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); var ownerInit = actorReference.GetOrDefault <OwnerInit>(); if (ownerInit == null) { emitError("Actor {0} is not owned by any player.".F(kv.Key)); } else { var ownerName = ownerInit.InternalName; if (!playerNames.Contains(ownerName)) { emitError("Actor {0} is owned by unknown player {1}.".F(kv.Key, ownerName)); } if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out var info)) { if (!info.ValidOwnerNames.Contains(ownerName)) { emitError("Actor {0} owner {1} is not one of ValidOwnerNames: {2}".F(kv.Key, ownerName, info.ValidOwnerNames.JoinWith(", "))); } } } } }
public void Run(Action <string> emitError, Action <string> emitWarning, ModData modData, Map map) { var players = new MapPlayers(map.PlayerDefinitions).Players; if (players.Count > 64) { emitError("Defining more than 64 players is not allowed."); } var worldOwnerFound = false; var playerNames = players.Values.Select(p => p.Name).ToHashSet(); foreach (var player in players.Values) { foreach (var ally in player.Allies) { if (!playerNames.Contains(ally)) { emitError("Allies contains player {0} that is not in list.".F(ally)); } } foreach (var enemy in player.Enemies) { if (!playerNames.Contains(enemy)) { emitError("Enemies contains player {0} that is not in list.".F(enemy)); } } if (player.OwnsWorld) { worldOwnerFound = true; if (player.Enemies.Any() || player.Allies.Any()) { emitWarning("The player {0} owning the world should not have any allies or enemies.".F(player.Name)); } if (player.Playable) { emitError("The player {0} owning the world can't be playable.".F(player.Name)); } } else if (map.Visibility == MapVisibility.MissionSelector && player.Playable && !player.LockFaction) { // Missions must lock the faction of the player to force the server to override the default Random faction emitError("The player {0} must specify LockFaction: True.".F(player.Name)); } } if (!worldOwnerFound) { emitError("Found no player owning the world."); } var worldActor = map.Rules.Actors[SystemActors.World]; var factions = worldActor.TraitInfos <FactionInfo>().Select(f => f.InternalName).ToHashSet(); foreach (var player in players.Values) { if (!string.IsNullOrWhiteSpace(player.Faction) && !factions.Contains(player.Faction)) { emitError("Invalid faction {0} chosen for player {1}.".F(player.Faction, player.Name)); } } if (worldActor.HasTraitInfo <MapStartingLocationsInfo>()) { var playerCount = players.Count(p => p.Value.Playable); var spawns = new List <CPos>(); foreach (var kv in map.ActorDefinitions.Where(d => d.Value.Value == "mpspawn")) { var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); spawns.Add(s.Get <LocationInit>().Value); } if (playerCount > spawns.Count) { emitError("The map allows {0} possible players, but defines only {1} spawn points".F(playerCount, spawns.Count)); } if (spawns.Distinct().Count() != spawns.Count) { emitError("Duplicate spawn point locations detected."); } } // Check for actors that require specific owners var actorsWithRequiredOwner = map.Rules.Actors .Where(a => a.Value.HasTraitInfo <RequiresSpecificOwnersInfo>()) .ToDictionary(a => a.Key, a => a.Value.TraitInfo <RequiresSpecificOwnersInfo>()); foreach (var kv in map.ActorDefinitions) { var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); var ownerInit = actorReference.GetOrDefault <OwnerInit>(); if (ownerInit == null) { emitError("Actor {0} is not owned by any player.".F(kv.Key)); } else { var ownerName = ownerInit.InternalName; if (!playerNames.Contains(ownerName)) { emitError("Actor {0} is owned by unknown player {1}.".F(kv.Key, ownerName)); } if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out var info)) { if (!info.ValidOwnerNames.Contains(ownerName)) { emitError("Actor {0} owner {1} is not one of ValidOwnerNames: {2}".F(kv.Key, ownerName, info.ValidOwnerNames.JoinWith(", "))); } } } } }
public static void SetMapPlayers(string section, string faction, string color, IniFile file, List <string> players, MapPlayers mapPlayers) { var pr = new PlayerReference { Name = section, OwnsWorld = section == "Neutral", NonCombatant = section == "Neutral", Faction = faction, Color = namedColorMapping[color] }; var neutral = new[] { "Neutral" }; foreach (var s in file.GetSection(section, true)) { switch (s.Key) { case "Allies": pr.Allies = s.Value.Split(',').Intersect(players).Except(neutral).ToArray(); pr.Enemies = s.Value.Split(',').SymmetricDifference(players).Except(neutral).ToArray(); break; default: Console.WriteLine("Ignoring unknown {0}={1} for player {2}", s.Key, s.Value, pr.Name); break; } } // Overwrite default player definitions if needed if (!mapPlayers.Players.ContainsKey(section)) { mapPlayers.Players.Add(section, pr); } else { mapPlayers.Players[section] = pr; } }
protected void Run(Utility utility, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = ModData = utility.ModData; var filename = args[1]; var flag = args[2]; if (string.IsNullOrWhiteSpace(flag)) { flag = "VH"; } bool flipHorizontal = flag.Contains("H"); bool flipVertical = flag.Contains("V"); MirrorType mirrorType = MirrorType.Horizontal; if (flipVertical) { mirrorType = MirrorType.Vertical; } if (flipHorizontal && flipVertical) { mirrorType = MirrorType.HorizontalAndVertical; } var targetPath = "..\\mods\\dr\\maps"; var package = new Folder(targetPath).OpenPackage(filename, ModData.ModFiles); if (package == null) { Console.WriteLine("Couldn't find map file: " + filename); return; } Map = new Map(ModData, package); var size = Map.MapSize; switch (mirrorType) { case MirrorType.Horizontal: size = size.WithX(size.X / 2); break; case MirrorType.Vertical: size = size.WithY(size.Y / 2); break; case MirrorType.HorizontalAndVertical: size = size / 2; break; } // Tiles for (int x = 0; x < size.X; x++) { for (int y = 0; y < size.Y; y++) { var pos = new CPos(x, y); var transformTile = new TileTransform() { Tile = Map.Tiles[pos], MirrorType = mirrorType, Position = pos }; foreach (var tt in transformTile.GetTransforms(Map)) { var newPos = tt.Position; Map.Tiles[newPos] = tt.Tile; } } } // Actors actorIndex = GetHighestActorIndex(); int multiCount = 0; var actorDefs = new List <ActorReference>(); var removeActors = new List <MiniYamlNode>(); foreach (var a in Map.ActorDefinitions) { var existing = new ActorReference(a.Value.Value, a.Value.ToDictionary()); var pos = existing.GetOrDefault <LocationInit>().Value; var owner = existing.Get <OwnerInit>(); if (pos.X < 0 || pos.X >= size.X || pos.Y < 0 || pos.Y >= size.Y) { removeActors.Add(a); continue; } var actor = new ActorTransform() { Actor = existing, Position = pos, MirrorType = mirrorType, }; if (actor.Actor.Type == "mpspawn") { multiCount++; } foreach (var at in actor.GetTransforms(Map)) { var ar = new ActorReference(actor.Actor.Type) { new LocationInit(at.Position), owner }; actorDefs.Add(ar); if (at.Actor.Type == "mpspawn") { multiCount++; } } } foreach (var a in actorDefs) { Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + ++actorIndex, a.Save())); } foreach (var a in removeActors) { Map.ActorDefinitions.Remove(a); } if (multiCount > 0) { var mapPlayers = new MapPlayers(Map.Rules, multiCount); Map.PlayerDefinitions = mapPlayers.ToMiniYaml(); } // Resources for (int x = 0; x < size.X; x++) { for (int y = 0; y < size.Y; y++) { var pos = new CPos(x, y); var resource = new ResourceTransform() { Tile = Map.Resources[pos], MirrorType = mirrorType, Position = pos }; foreach (var rt in resource.GetTransforms(Map)) { var newPos = rt.Position; Map.Resources[newPos] = rt.Tile; } } } var dest = Path.Combine(targetPath, Path.GetFileNameWithoutExtension(filename) + ".oramap"); Map.Save(ZipFileLoader.Create(dest)); Console.WriteLine(dest + " saved."); }
void IUtilityCommand.Run(Utility utility, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = utility.ModData; var filename = args[1]; var file = new IniFile(File.Open(args[1], FileMode.Open)); var basic = file.GetSection("Basic"); var mapSection = file.GetSection("Map"); var tileset = mapSection.GetValue("Theater", ""); var iniSize = mapSection.GetValue("Size", "0, 0, 0, 0").Split(',').Select(int.Parse).ToArray(); var iniBounds = mapSection.GetValue("LocalSize", "0, 0, 0, 0").Split(',').Select(int.Parse).ToArray(); var size = new Size(iniSize[2], 2 * iniSize[3]); var map = new Map(Game.ModData, utility.ModData.DefaultTileSets[tileset], size.Width, size.Height) { Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)), Author = "Westwood Studios", Bounds = new Rectangle(iniBounds[0], iniBounds[1], iniBounds[2], 2 * iniBounds[3] + 2 * iniBounds[1]), RequiresMod = utility.ModData.Manifest.Id }; var fullSize = new int2(iniSize[2], iniSize[3]); ReadTiles(map, file, fullSize); ReadActors(map, file, "Structures", fullSize); ReadActors(map, file, "Units", fullSize); ReadActors(map, file, "Infantry", fullSize); ReadTerrainActors(map, file, fullSize); ReadWaypoints(map, file, fullSize); ReadOverlay(map, file, fullSize); ReadLighting(map, file); var spawnCount = map.ActorDefinitions.Count(n => n.Value.Value == "mpspawn"); var mapPlayers = new MapPlayers(map.Rules, spawnCount); map.PlayerDefinitions = mapPlayers.ToMiniYaml(); var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap"; map.Save(ZipFile.Create(dest, new Folder("."))); Console.WriteLine(dest + " saved."); }
enum IniMapFormat { RedAlert = 3 } // otherwise, cnc (2 variants exist, we don't care to differentiate) public void ConvertIniMap(string iniFile) { using (var stream = GlobalFileSystem.Open(iniFile)) { var file = new IniFile(stream); var basic = file.GetSection("Basic"); var mapSection = file.GetSection("Map"); var legacyMapFormat = (IniMapFormat)Exts.ParseIntegerInvariant(basic.GetValue("NewINIFormat", "0")); var offsetX = Exts.ParseIntegerInvariant(mapSection.GetValue("X", "0")); var offsetY = Exts.ParseIntegerInvariant(mapSection.GetValue("Y", "0")); var width = Exts.ParseIntegerInvariant(mapSection.GetValue("Width", "0")); var height = Exts.ParseIntegerInvariant(mapSection.GetValue("Height", "0")); mapSize = (legacyMapFormat == IniMapFormat.RedAlert) ? 128 : 64; var tileset = Truncate(mapSection.GetValue("Theater", "TEMPERAT"), 8); map = new Map(rules.TileSets[tileset], mapSize, mapSize) { Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile)), Author = "Westwood Studios" }; var tl = new PPos(offsetX, offsetY); var br = new PPos(offsetX + width - 1, offsetY + height - 1); map.SetBounds(tl, br); if (legacyMapFormat == IniMapFormat.RedAlert) { UnpackRATileData(ReadPackedSection(file.GetSection("MapPack"))); UnpackRAOverlayData(ReadPackedSection(file.GetSection("OverlayPack"))); ReadRATrees(file); } else { // CnC using (var s = GlobalFileSystem.Open(iniFile.Substring(0, iniFile.Length - 4) + ".bin")) UnpackCncTileData(s); ReadCncOverlay(file); ReadCncTrees(file); } LoadVideos(file, "BASIC"); LoadActors(file, "STRUCTURES"); LoadActors(file, "UNITS"); LoadActors(file, "INFANTRY"); LoadActors(file, "SHIPS"); LoadSmudges(file, "SMUDGE"); var wps = file.GetSection("Waypoints") .Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0) .Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key), LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), mapSize))); // Add waypoint actors foreach (var kv in wps) { if (kv.First <= 7) { var ar = new ActorReference("mpspawn") { new LocationInit((CPos)kv.Second), new OwnerInit("Neutral") }; map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save())); } else { var ar = new ActorReference("waypoint") { new LocationInit((CPos)kv.Second), new OwnerInit("Neutral") }; map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save())); } } // Create default player definitions only if there are no players to import mapPlayers = new MapPlayers(map.Rules, (players.Count == 0) ? map.SpawnPoints.Value.Length : 0); foreach (var p in players) LoadPlayer(file, p, legacyMapFormat == IniMapFormat.RedAlert); map.PlayerDefinitions = mapPlayers.ToMiniYaml(); } }
enum IniMapFormat { RedAlert = 3 } // otherwise, cnc (2 variants exist, we don't care to differentiate) public void ConvertIniMap(string iniFile) { using (var stream = GlobalFileSystem.Open(iniFile)) { var file = new IniFile(stream); var basic = file.GetSection("Basic"); var mapSection = file.GetSection("Map"); var legacyMapFormat = (IniMapFormat)Exts.ParseIntegerInvariant(basic.GetValue("NewINIFormat", "0")); var offsetX = Exts.ParseIntegerInvariant(mapSection.GetValue("X", "0")); var offsetY = Exts.ParseIntegerInvariant(mapSection.GetValue("Y", "0")); var width = Exts.ParseIntegerInvariant(mapSection.GetValue("Width", "0")); var height = Exts.ParseIntegerInvariant(mapSection.GetValue("Height", "0")); mapSize = (legacyMapFormat == IniMapFormat.RedAlert) ? 128 : 64; var tileset = Truncate(mapSection.GetValue("Theater", "TEMPERAT"), 8); map = new Map(rules.TileSets[tileset], mapSize, mapSize) { Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile)), Author = "Westwood Studios" }; var tl = new PPos(offsetX, offsetY); var br = new PPos(offsetX + width - 1, offsetY + height - 1); map.SetBounds(tl, br); if (legacyMapFormat == IniMapFormat.RedAlert) { UnpackRATileData(ReadPackedSection(file.GetSection("MapPack"))); UnpackRAOverlayData(ReadPackedSection(file.GetSection("OverlayPack"))); ReadRATrees(file); } else { // CnC using (var s = GlobalFileSystem.Open(iniFile.Substring(0, iniFile.Length - 4) + ".bin")) UnpackCncTileData(s); ReadCncOverlay(file); ReadCncTrees(file); } LoadVideos(file, "BASIC"); LoadActors(file, "STRUCTURES"); LoadActors(file, "UNITS"); LoadActors(file, "INFANTRY"); LoadActors(file, "SHIPS"); LoadSmudges(file, "SMUDGE"); var wps = file.GetSection("Waypoints") .Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0) .Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key), LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), mapSize))); // Add waypoint actors foreach (var kv in wps) { if (kv.First <= 7) { var ar = new ActorReference("mpspawn") { new LocationInit((CPos)kv.Second), new OwnerInit("Neutral") }; map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save())); } else { var ar = new ActorReference("waypoint") { new LocationInit((CPos)kv.Second), new OwnerInit("Neutral") }; map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save())); } } // Create default player definitions only if there are no players to import mapPlayers = new MapPlayers(map.Rules, (players.Count == 0) ? map.SpawnPoints.Value.Length : 0); foreach (var p in players) { LoadPlayer(file, p, legacyMapFormat == IniMapFormat.RedAlert); } map.PlayerDefinitions = mapPlayers.ToMiniYaml(); } }
public void Run(Action <string> emitError, Action <string> emitWarning, Map map) { var players = new MapPlayers(map.PlayerDefinitions).Players; var playerNames = players.Values.Select(p => p.Name).ToHashSet(); foreach (var player in players.Values) { foreach (var ally in player.Allies) { if (!playerNames.Contains(ally)) { emitError("Allies contains player {0} that is not in list.".F(ally)); } } foreach (var enemy in player.Enemies) { if (!playerNames.Contains(enemy)) { emitError("Enemies contains player {0} that is not in list.".F(enemy)); } } if (player.OwnsWorld && (player.Enemies.Any() || player.Allies.Any())) { emitWarning("The player {0} owning the world should not have any allies or enemies.".F(player.Name)); } } var worldActor = map.Rules.Actors["world"]; var factions = worldActor.TraitInfos <FactionInfo>().Select(f => f.InternalName).ToHashSet(); foreach (var player in players.Values) { if (!string.IsNullOrWhiteSpace(player.Faction) && !factions.Contains(player.Faction)) { emitError("Invalid faction {0} chosen for player {1}.".F(player.Faction, player.Name)); } } if (worldActor.HasTraitInfo <MPStartLocationsInfo>()) { var playerCount = players.Count(p => p.Value.Playable); var spawns = new List <CPos>(); foreach (var kv in map.ActorDefinitions.Where(d => d.Value.Value == "mpspawn")) { var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); spawns.Add(s.InitDict.Get <LocationInit>().Value(null)); } if (playerCount > spawns.Count) { emitError("The map allows {0} possible players, but defines only {1} spawn points".F(playerCount, spawns.Count)); } if (spawns.Distinct().Count() != spawns.Count) { emitError("Duplicate spawn point locations detected."); } } foreach (var kv in map.ActorDefinitions) { var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); var ownerInit = actorReference.InitDict.GetOrDefault <OwnerInit>(); if (ownerInit == null) { emitError("Actor {0} is not owned by any player.".F(kv.Key)); } else { var ownerName = ownerInit.PlayerName; if (!playerNames.Contains(ownerName)) { emitError("Actor {0} is owned by unknown player {1}.".F(kv.Key, ownerName)); } else if (kv.Value.Value == "mpspawn" && !players[ownerName].OwnsWorld) { emitError("Actor {0} needs to be owned by the player that owns the world. ".F(kv.Key) + "Use the `Spawn` and `LockSpawn` player properties to force players onto a particular spawn instead."); } } } }
void CreateMapPlayers() { var players = new MapPlayers(map.Rules, playerCount); map.PlayerDefinitions = players.ToMiniYaml(); }
protected void Run(Utility utility, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = ModData = utility.ModData; var filename = args[1]; using (var stream = File.OpenRead(filename)) { var file = new IniFile(stream); var basic = file.GetSection("Basic"); var player = basic.GetValue("Player", string.Empty); if (!string.IsNullOrEmpty(player)) { singlePlayer = !player.StartsWith("Multi"); } var mapSection = file.GetSection("Map"); var format = GetMapFormatVersion(basic); ValidateMapFormat(format); // The original game isn't case sensitive, but we are. var tileset = GetTileset(mapSection).ToUpperInvariant(); if (!ModData.DefaultTileSets.ContainsKey(tileset)) { throw new InvalidDataException("Unknown tileset {0}".F(tileset)); } Map = new Map(ModData, ModData.DefaultTileSets[tileset], MapSize, MapSize) { Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)), Author = "Westwood Studios", }; Map.RequiresMod = ModData.Manifest.Id; SetBounds(Map, mapSection); ReadPacks(file, filename); ReadTrees(file); LoadVideos(file, "BASIC"); LoadBriefing(file); ReadActors(file); LoadSmudges(file, "SMUDGE"); var waypoints = file.GetSection("Waypoints"); LoadWaypoints(waypoints); // Create default player definitions only if there are no players to import MapPlayers = new MapPlayers(Map.Rules, Players.Count == 0 ? spawnCount : 0); foreach (var p in Players) { LoadPlayer(file, p); } Map.PlayerDefinitions = MapPlayers.ToMiniYaml(); } Map.FixOpenAreas(); var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap"; Map.Save(ZipFile.Create(dest, new Folder("."))); Console.WriteLine(dest + " saved."); }
public void Run(Action <string> emitError, Action <string> emitWarning, Map map) { var players = new MapPlayers(map.PlayerDefinitions).Players; var playerNames = players.Values.Select(p => p.Name).ToHashSet(); foreach (var player in players.Values) { foreach (var ally in player.Allies) { if (!playerNames.Contains(ally)) { emitError("Allies contains player {0} that is not in list.".F(ally)); } } foreach (var enemy in player.Enemies) { if (!playerNames.Contains(enemy)) { emitError("Enemies contains player {0} that is not in list.".F(enemy)); } } if (player.OwnsWorld && (player.Enemies.Any() || player.Allies.Any())) { emitWarning("The player {0} owning the world should not have any allies or enemies.".F(player.Name)); } } var worldActor = map.Rules.Actors["world"]; var races = worldActor.Traits.WithInterface <FactionInfo>().Select(f => f.InternalName).ToHashSet(); foreach (var player in players.Values) { if (!string.IsNullOrWhiteSpace(player.Faction) && !races.Contains(player.Faction)) { emitError("Invalid race {0} chosen for player {1}.".F(player.Faction, player.Name)); } } if (worldActor.Traits.Contains <MPStartLocationsInfo>()) { var multiPlayers = players.Count(p => p.Value.Playable); var spawns = map.ActorDefinitions.Where(a => a.Value.Value == "mpspawn"); var spawnCount = spawns.Count(); if (multiPlayers > spawnCount) { emitError("The map allows {0} possible players, but defines only {1} spawn points".F(multiPlayers, spawnCount)); } if (map.SpawnPoints.Value.Distinct().Count() != spawnCount) { emitError("Duplicate spawn point locations detected."); } } foreach (var kv in map.ActorDefinitions) { var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); var ownerName = actorReference.InitDict.Get <OwnerInit>().PlayerName; if (!playerNames.Contains(ownerName)) { emitError("Actor {0} is owned by unknown player {1}.".F(actorReference.Type, ownerName)); } } }
ColorPalette GetPaletteForPlayerInner(string name) { var pr = new MapPlayers(Map.PlayerDefinitions).Players[name]; var pcpi = Program.Rules.Actors["world"].Traits.Get<PlayerColorPaletteInfo>(); var remap = new PlayerColorRemap(pcpi.RemapIndex, pr.Color, pcpi.Ramp); return new ImmutablePalette(PlayerPalette, remap).AsSystemPalette(); }
void ICreatePlayers.CreatePlayers(World w, MersenneTwister playerRandom) { var players = new MapPlayers(w.Map.PlayerDefinitions).Players; var worldPlayers = new List <Player>(); var worldOwnerFound = false; // Create the unplayable map players -- neutral, shellmap, scripted, etc. foreach (var kv in players.Where(p => !p.Value.Playable)) { var player = new Player(w, null, kv.Value, playerRandom); worldPlayers.Add(player); if (kv.Value.OwnsWorld) { worldOwnerFound = true; w.SetWorldOwner(player); } } if (!worldOwnerFound) { throw new InvalidOperationException("Map {0} does not define a player actor owning the world.".F(w.Map.Title)); } Player localPlayer = null; // Create the regular playable players. foreach (var kv in w.LobbyInfo.Slots) { var client = w.LobbyInfo.ClientInSlot(kv.Key); if (client == null) { continue; } var player = new Player(w, client, players[kv.Value.PlayerReference], playerRandom); worldPlayers.Add(player); if (client.Index == Game.LocalClientId) { localPlayer = player; } } // Create a player that is allied with everyone for shared observer shroud. worldPlayers.Add(new Player(w, null, new PlayerReference { Name = "Everyone", NonCombatant = true, Spectating = true, Faction = "Random", Allies = worldPlayers.Where(p => !p.NonCombatant && p.Playable).Select(p => p.InternalName).ToArray() }, playerRandom)); w.SetPlayers(worldPlayers, localPlayer); foreach (var p in w.Players) { foreach (var q in w.Players) { SetupPlayerMasks(p, q); } } }
protected void Run(Utility utility, string[] args) { // HACK: The engine code assumes that Game.modData is set. Game.ModData = ModData = utility.ModData; var filename = args[1]; using (var stream = File.OpenRead(filename)) { var file = new IniFile(stream); var basic = file.GetSection("Basic"); var player = basic.GetValue("Player", string.Empty); if (!string.IsNullOrEmpty(player)) singlePlayer = !player.StartsWith("Multi"); var mapSection = file.GetSection("Map"); var format = GetMapFormatVersion(basic); ValidateMapFormat(format); // The original game isn't case sensitive, but we are. var tileset = GetTileset(mapSection).ToUpperInvariant(); if (!ModData.DefaultTileSets.ContainsKey(tileset)) throw new InvalidDataException("Unknown tileset {0}".F(tileset)); Map = new Map(ModData, ModData.DefaultTileSets[tileset], MapSize, MapSize) { Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)), Author = "Westwood Studios", }; Map.RequiresMod = ModData.Manifest.Id; SetBounds(Map, mapSection); ReadPacks(file, filename); ReadTrees(file); LoadVideos(file, "BASIC"); LoadBriefing(file); ReadActors(file); LoadSmudges(file, "SMUDGE"); var waypoints = file.GetSection("Waypoints"); LoadWaypoints(waypoints); // Create default player definitions only if there are no players to import MapPlayers = new MapPlayers(Map.Rules, Players.Count == 0 ? spawnCount : 0); foreach (var p in Players) LoadPlayer(file, p); Map.PlayerDefinitions = MapPlayers.ToMiniYaml(); } Map.FixOpenAreas(); var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap"; Map.Save(ZipFile.Create(dest, new Folder("."))); Console.WriteLine(dest + " saved."); }
void Run(Action <string> emitError, Action <string> emitWarning, MapPlayers players, MapVisibility visibility, ActorInfo worldActorInfo, CPos[] spawnPoints) { if (players.Players.Count > 64) { emitError("Defining more than 64 players is not allowed."); } var worldOwnerFound = false; var playerNames = players.Players.Values.Select(p => p.Name).ToHashSet(); foreach (var player in players.Players.Values) { foreach (var ally in player.Allies) { if (!playerNames.Contains(ally)) { emitError("Allies contains player {0} that is not in list.".F(ally)); } } foreach (var enemy in player.Enemies) { if (!playerNames.Contains(enemy)) { emitError("Enemies contains player {0} that is not in list.".F(enemy)); } } if (player.OwnsWorld) { worldOwnerFound = true; if (player.Enemies.Any() || player.Allies.Any()) { emitWarning("The player {0} owning the world should not have any allies or enemies.".F(player.Name)); } if (player.Playable) { emitError("The player {0} owning the world can't be playable.".F(player.Name)); } } else if (visibility == MapVisibility.MissionSelector && player.Playable && !player.LockFaction) { // Missions must lock the faction of the player to force the server to override the default Random faction emitError("The player {0} must specify LockFaction: True.".F(player.Name)); } } if (!worldOwnerFound) { emitError("Found no player owning the world."); } var factions = worldActorInfo.TraitInfos <FactionInfo>().Select(f => f.InternalName).ToHashSet(); foreach (var player in players.Players.Values) { if (!string.IsNullOrWhiteSpace(player.Faction) && !factions.Contains(player.Faction)) { emitError("Invalid faction {0} chosen for player {1}.".F(player.Faction, player.Name)); } } if (worldActorInfo.HasTraitInfo <MapStartingLocationsInfo>()) { var playerCount = players.Players.Count(p => p.Value.Playable); if (playerCount > spawnPoints.Length) { emitError("The map allows {0} possible players, but defines only {1} spawn points".F(playerCount, spawnPoints.Length)); } if (spawnPoints.Distinct().Count() != spawnPoints.Length) { emitError("Duplicate spawn point locations detected."); } } }
public static Map Import(string filename, string mod, string tileset, Ruleset rules) { var map = new D2kMapImporter(filename, tileset, rules).map; if (map == null) return null; map.RequiresMod = mod; var players = new MapPlayers(map.Rules, map.SpawnPoints.Value.Length); map.PlayerDefinitions = players.ToMiniYaml(); return map; }