start reworking player setup
This commit is contained in:
@@ -87,13 +87,7 @@ namespace OpenRA.Editor
|
|||||||
// upgrade maps that have no player definitions. editor doesnt care,
|
// upgrade maps that have no player definitions. editor doesnt care,
|
||||||
// but this breaks the game pretty badly.
|
// but this breaks the game pretty badly.
|
||||||
if (map.Players.Count == 0)
|
if (map.Players.Count == 0)
|
||||||
map.Players.Add("Neutral", new PlayerReference
|
map.MakeDefaultPlayers();
|
||||||
{
|
|
||||||
Name = "Neutral",
|
|
||||||
Race = Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race,
|
|
||||||
OwnsWorld = true,
|
|
||||||
NonCombatant = true
|
|
||||||
});
|
|
||||||
|
|
||||||
PrepareMapResources(Game.modData.Manifest, map);
|
PrepareMapResources(Game.modData.Manifest, map);
|
||||||
|
|
||||||
@@ -326,21 +320,8 @@ namespace OpenRA.Editor
|
|||||||
map.Resize((int)nmd.width.Value, (int)nmd.height.Value);
|
map.Resize((int)nmd.width.Value, (int)nmd.height.Value);
|
||||||
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
|
map.MakeDefaultPlayers();
|
||||||
{
|
|
||||||
Name = "Neutral",
|
|
||||||
Race = Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race,
|
|
||||||
OwnsWorld = true,
|
|
||||||
NonCombatant = true
|
|
||||||
});
|
|
||||||
|
|
||||||
map.Players.Add("Creeps", new PlayerReference
|
|
||||||
{
|
|
||||||
Name = "Creeps",
|
|
||||||
Race = Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race,
|
|
||||||
NonCombatant = true
|
|
||||||
});
|
|
||||||
|
|
||||||
NewMap(map);
|
NewMap(map);
|
||||||
}
|
}
|
||||||
@@ -395,22 +376,8 @@ namespace OpenRA.Editor
|
|||||||
if (errors.Count > 0)
|
if (errors.Count > 0)
|
||||||
using (var eld = new ErrorListDialog(errors))
|
using (var eld = new ErrorListDialog(errors))
|
||||||
eld.ShowDialog();
|
eld.ShowDialog();
|
||||||
|
|
||||||
if (!map.Players.ContainsKey("Neutral"))
|
map.MakeDefaultPlayers();
|
||||||
map.Players.Add("Neutral", new PlayerReference
|
|
||||||
{
|
|
||||||
Name = "Neutral",
|
|
||||||
Race = Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race,
|
|
||||||
OwnsWorld = true,
|
|
||||||
NonCombatant = true
|
|
||||||
});
|
|
||||||
|
|
||||||
map.Players.Add("Creeps", new PlayerReference
|
|
||||||
{
|
|
||||||
Name = "Creeps",
|
|
||||||
Race = Rules.Info["world"].Traits.WithInterface<CountryInfo>().First().Race,
|
|
||||||
NonCombatant = true
|
|
||||||
});
|
|
||||||
|
|
||||||
map.Save(savePath);
|
map.Save(savePath);
|
||||||
LoadMap(savePath);
|
LoadMap(savePath);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using System.Linq;
|
|||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
@@ -118,7 +119,8 @@ namespace OpenRA
|
|||||||
|
|
||||||
// Support for formats 1-3 dropped 2011-02-11.
|
// Support for formats 1-3 dropped 2011-02-11.
|
||||||
// Use release-20110207 to convert older maps to format 4
|
// Use release-20110207 to convert older maps to format 4
|
||||||
if (MapFormat < 4)
|
// Use release-20110511 to convert older maps to format 5
|
||||||
|
if (MapFormat < 5)
|
||||||
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));
|
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));
|
||||||
|
|
||||||
// Load players
|
// Load players
|
||||||
@@ -136,60 +138,8 @@ namespace OpenRA
|
|||||||
ret.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.NodesDict));
|
ret.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.NodesDict));
|
||||||
|
|
||||||
// Add waypoint actors
|
// Add waypoint actors
|
||||||
|
|
||||||
if (MapFormat < 5)
|
|
||||||
foreach( var wp in yaml.NodesDict[ "Waypoints" ].NodesDict )
|
|
||||||
{
|
|
||||||
string[] loc = wp.Value.Value.Split( ',' );
|
|
||||||
var a = new ActorReference("mpspawn");
|
|
||||||
a.Add(new LocationInit(new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) )));
|
|
||||||
a.Add(new OwnerInit(Players.First(p => p.Value.OwnsWorld).Key));
|
|
||||||
ret.Add(wp.Key, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* hack: make some slots. */
|
|
||||||
if (!Players.Any(p => p.Value.Playable))
|
|
||||||
{
|
|
||||||
for (int index = 0; index < SpawnPoints.Count(); index++)
|
|
||||||
{
|
|
||||||
var p = new PlayerReference
|
|
||||||
{
|
|
||||||
Name = "Multi{0}".F(index),
|
|
||||||
Race = "Random",
|
|
||||||
Playable = true,
|
|
||||||
DefaultStartingUnits = true,
|
|
||||||
Enemies = new[] { "Creeps" }
|
|
||||||
};
|
|
||||||
Players.Add(p.Name, p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upgrade map to format 5
|
|
||||||
if (MapFormat < 5)
|
|
||||||
{
|
|
||||||
// Define RequiresMod for map installer
|
|
||||||
RequiresMod = Game.CurrentMods.Keys.First();
|
|
||||||
|
|
||||||
var TopLeft = (int2)FieldLoader.GetValue( "", typeof(int2), yaml.NodesDict["TopLeft"].Value);
|
|
||||||
var BottomRight = (int2)FieldLoader.GetValue( "", typeof(int2), yaml.NodesDict["BottomRight"].Value);
|
|
||||||
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
|
|
||||||
|
|
||||||
// Creep player
|
|
||||||
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.Where(p => p.Value.Playable).Select(p => p.Key).ToArray()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Smudges
|
// Smudges
|
||||||
Smudges = Lazy.New(() =>
|
Smudges = Lazy.New(() =>
|
||||||
@@ -446,5 +396,42 @@ namespace OpenRA
|
|||||||
using (var csp = SHA1.Create())
|
using (var csp = SHA1.Create())
|
||||||
return new string(csp.ComputeHash(data).SelectMany(a => a.ToString("x2")).ToArray());
|
return new string(csp.ComputeHash(data).SelectMany(a => a.ToString("x2")).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void MakeDefaultPlayers()
|
||||||
|
{
|
||||||
|
Players.Clear();
|
||||||
|
|
||||||
|
var firstRace = OpenRA.Rules.Info["world"].Traits
|
||||||
|
.WithInterface<CountryInfo>().First().Race;
|
||||||
|
|
||||||
|
Players.Add("Neutral", new PlayerReference
|
||||||
|
{
|
||||||
|
Name = "Neutral",
|
||||||
|
Race = firstRace,
|
||||||
|
OwnsWorld = true,
|
||||||
|
NonCombatant = true
|
||||||
|
});
|
||||||
|
|
||||||
|
for (int index = 0; index < SpawnPoints.Count(); index++)
|
||||||
|
{
|
||||||
|
var p = new PlayerReference
|
||||||
|
{
|
||||||
|
Name = "Multi{0}".F(index),
|
||||||
|
Race = "Random",
|
||||||
|
Playable = true,
|
||||||
|
DefaultStartingUnits = true,
|
||||||
|
Enemies = new[] { "Creeps" }
|
||||||
|
};
|
||||||
|
Players.Add(p.Name, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
Players.Add("Creeps", new PlayerReference
|
||||||
|
{
|
||||||
|
Name = "Creeps",
|
||||||
|
Race = firstRace,
|
||||||
|
NonCombatant = true,
|
||||||
|
Enemies = Players.Where(p => p.Value.Playable).Select(p => p.Key).ToArray()
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user