Add support for a "Creeps" faction that is hostile to all combatant players. Add a mod field to be used for map installation.

This commit is contained in:
Paul Chote
2011-02-10 21:22:38 +13:00
parent 56952c1ab8
commit fae355f5b6
3 changed files with 32 additions and 9 deletions

View File

@@ -321,6 +321,7 @@ namespace OpenRA.Editor
map.ResizeCordon((int)nmd.cordonLeft.Value, (int)nmd.cordonTop.Value, map.ResizeCordon((int)nmd.cordonLeft.Value, (int)nmd.cordonTop.Value,
(int)nmd.cordonRight.Value, (int)nmd.cordonBottom.Value); (int)nmd.cordonRight.Value, (int)nmd.cordonBottom.Value);
map.Players.Add("Neutral", new PlayerReference("Neutral", Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race, true, true)); map.Players.Add("Neutral", new PlayerReference("Neutral", Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race, true, true));
map.Players.Add("Creeps", new PlayerReference("Creeps", Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race, true, true));
NewMap(map); NewMap(map);
} }
} }
@@ -373,6 +374,9 @@ namespace OpenRA.Editor
map.Players.Add("Neutral", new PlayerReference("Neutral", map.Players.Add("Neutral", new PlayerReference("Neutral",
Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race, true, true)); Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race, true, true));
map.Players.Add("Creeps", new PlayerReference("Creeps",
Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race, true, true));
map.Save(savePath); map.Save(savePath);
LoadMap(savePath); LoadMap(savePath);
loadedMapName = null; /* editor needs to think this hasnt been saved */ loadedMapName = null; /* editor needs to think this hasnt been saved */

View File

@@ -25,6 +25,7 @@ namespace OpenRA.FileFormats
public string Uid { get; protected set; } public string Uid { get; protected set; }
[FieldLoader.Load] public bool Selectable; [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 Title;
[FieldLoader.Load] public string Type = "Conquest"; [FieldLoader.Load] public string Type = "Conquest";

View File

@@ -140,6 +140,7 @@ namespace OpenRA
case 3: case 3:
case 4: case 4:
case 5:
{ {
foreach (var kv in yaml.NodesDict["Players"].NodesDict) foreach (var kv in yaml.NodesDict["Players"].NodesDict)
{ {
@@ -165,14 +166,15 @@ namespace OpenRA
Name = "Multi{0}".F(index), Name = "Multi{0}".F(index),
Race = "Random", Race = "Random",
Playable = true, Playable = true,
DefaultStartingUnits = true DefaultStartingUnits = true,
Enemies = new[]{"Creeps"}
}; };
Players.Add(p.Name, p); Players.Add(p.Name, p);
} }
} }
// Color1/Color2 -> ColorRamp // Color1/Color2 -> ColorRamp
if (MapFormat == 3) if (MapFormat < 4)
foreach (var mp in Players) foreach (var mp in Players)
mp.Value.ColorRamp = new ColorRamp( mp.Value.ColorRamp = new ColorRamp(
(byte)((mp.Value.Color.GetHue() / 360.0f) * 255), (byte)((mp.Value.Color.GetHue() / 360.0f) * 255),
@@ -180,6 +182,24 @@ namespace OpenRA
(byte)(mp.Value.Color.GetBrightness() * 255), (byte)(mp.Value.Color.GetBrightness() * 255),
(byte)(mp.Value.Color2.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 // Smudges
foreach (var kv in yaml.NodesDict["Smudges"].NodesDict) foreach (var kv in yaml.NodesDict["Smudges"].NodesDict)
{ {
@@ -206,12 +226,10 @@ namespace OpenRA
public void Save(string toPath) public void Save(string toPath)
{ {
Console.WriteLine("Saving map to path {0}",toPath); MapFormat = 5;
// Todo: save to a zip file in the support dir by default
MapFormat = 4;
var root = new List<MiniYamlNode>(); var root = new List<MiniYamlNode>();
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); var f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue; if (f.GetValue(this) == null) continue;