From fae355f5b646a56df09af116d6e3c7b8a222a313 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 10 Feb 2011 21:22:38 +1300 Subject: [PATCH] Add support for a "Creeps" faction that is hostile to all combatant players. Add a mod field to be used for map installation. --- OpenRA.Editor/Form1.cs | 6 +++++- OpenRA.FileFormats/Map/MapStub.cs | 3 ++- OpenRA.Game/Map.cs | 32 ++++++++++++++++++++++++------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/OpenRA.Editor/Form1.cs b/OpenRA.Editor/Form1.cs index 13faf0fce4..740c7e01fa 100755 --- a/OpenRA.Editor/Form1.cs +++ b/OpenRA.Editor/Form1.cs @@ -321,6 +321,7 @@ namespace OpenRA.Editor map.ResizeCordon((int)nmd.cordonLeft.Value, (int)nmd.cordonTop.Value, (int)nmd.cordonRight.Value, (int)nmd.cordonBottom.Value); map.Players.Add("Neutral", new PlayerReference("Neutral", Rules.Info["world"].Traits.WithInterface().First().Race, true, true)); + map.Players.Add("Creeps", new PlayerReference("Creeps", Rules.Info["world"].Traits.WithInterface().First().Race, true, true)); NewMap(map); } } @@ -372,7 +373,10 @@ namespace OpenRA.Editor var map = LegacyMapImporter.Import(ofd.FileName); map.Players.Add("Neutral", new PlayerReference("Neutral", Rules.Info["world"].Traits.WithInterface().First().Race, true, true)); - + + map.Players.Add("Creeps", new PlayerReference("Creeps", + Rules.Info["world"].Traits.WithInterface().First().Race, true, true)); + map.Save(savePath); LoadMap(savePath); loadedMapName = null; /* editor needs to think this hasnt been saved */ diff --git a/OpenRA.FileFormats/Map/MapStub.cs b/OpenRA.FileFormats/Map/MapStub.cs index 716b716ca7..b96d79c016 100644 --- a/OpenRA.FileFormats/Map/MapStub.cs +++ b/OpenRA.FileFormats/Map/MapStub.cs @@ -24,7 +24,8 @@ namespace OpenRA.FileFormats // Yaml map data public string Uid { get; protected set; } [FieldLoader.Load] public bool Selectable; - [FieldLoader.Load] public bool UseAsShellmap; + [FieldLoader.Load] public bool UseAsShellmap; + [FieldLoader.Load] public string RequiresMod; [FieldLoader.Load] public string Title; [FieldLoader.Load] public string Type = "Conquest"; diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index 16db93569f..f7be3e5a21 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -140,6 +140,7 @@ namespace OpenRA case 3: case 4: + case 5: { foreach (var kv in yaml.NodesDict["Players"].NodesDict) { @@ -165,21 +166,40 @@ namespace OpenRA Name = "Multi{0}".F(index), Race = "Random", Playable = true, - DefaultStartingUnits = true + DefaultStartingUnits = true, + Enemies = new[]{"Creeps"} }; Players.Add(p.Name, p); } } // Color1/Color2 -> ColorRamp - if (MapFormat == 3) + if (MapFormat < 4) foreach (var mp in Players) mp.Value.ColorRamp = new ColorRamp( (byte)((mp.Value.Color.GetHue() / 360.0f) * 255), (byte)(mp.Value.Color.GetSaturation() * 255), (byte)(mp.Value.Color.GetBrightness() * 255), (byte)(mp.Value.Color2.GetBrightness() * 255)); - + + + // Creep player / Required Mod + if (MapFormat < 5) + { + RequiresMod = Game.CurrentMods.Keys.First(); + + foreach (var mp in Players.Where(p => !p.Value.NonCombatant && !p.Value.Enemies.Contains("Creeps"))) + mp.Value.Enemies = mp.Value.Enemies.Concat(new[] {"Creeps"}).ToArray(); + + Players.Add("Creeps", new PlayerReference + { + Name = "Creeps", + Race = "Random", + NonCombatant = true, + Enemies = Players.Keys.Where(k => k != "Neutral").ToArray() + }); + } + // Smudges foreach (var kv in yaml.NodesDict["Smudges"].NodesDict) { @@ -206,12 +226,10 @@ namespace OpenRA public void Save(string toPath) { - Console.WriteLine("Saving map to path {0}",toPath); - // Todo: save to a zip file in the support dir by default - MapFormat = 4; + MapFormat = 5; var root = new List(); - foreach (var field in new string[] {"Selectable", "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight", "UseAsShellmap", "Type"}) + foreach (var field in new string[] {"Selectable", "MapFormat", "RequiresMod", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight", "UseAsShellmap", "Type"}) { var f = this.GetType().GetField(field); if (f.GetValue(this) == null) continue;