add CountryInfo.Selectable

This commit is contained in:
Chris Forbes
2011-10-15 13:00:19 +13:00
parent d9d0e74d74
commit 1e32014190
6 changed files with 16 additions and 16 deletions

View File

@@ -410,7 +410,7 @@ namespace OpenRA
Players.Clear();
var firstRace = OpenRA.Rules.Info["world"].Traits
.WithInterface<CountryInfo>().First().Race;
.WithInterface<CountryInfo>().First(c => c.Selectable).Race;
Players.Add("Neutral", new PlayerReference
{

View File

@@ -39,6 +39,16 @@ namespace OpenRA
public Shroud Shroud { get { return World.LocalShroud; }}
public World World { get; private set; }
static CountryInfo ChooseCountry(World world, string name)
{
var selectableCountries = Rules.Info["world"].Traits
.WithInterface<CountryInfo>().Where( c => c.Selectable )
.ToArray();
return selectableCountries.FirstOrDefault(c => c.Race == name)
?? selectableCountries.Random(world.SharedRandom);
}
public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr)
{
World = world;
@@ -53,10 +63,7 @@ namespace OpenRA
ColorRamp = client.ColorRamp;
PlayerName = client.Name;
botType = client.Bot;
Country = world.GetCountries()
.FirstOrDefault(c => client.Country == c.Race)
?? world.GetCountries().Random(world.SharedRandom);
Country = ChooseCountry(world, client.Country);
}
else
{
@@ -66,10 +73,7 @@ namespace OpenRA
PlayerName = pr.Name;
NonCombatant = pr.NonCombatant;
botType = pr.Bot;
Country = world.GetCountries()
.FirstOrDefault(c => pr.Race == c.Race)
?? world.GetCountries().Random(world.SharedRandom);
Country = ChooseCountry(world, pr.Race);
}
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });

View File

@@ -14,8 +14,7 @@ namespace OpenRA.Traits
{
public readonly string Name = null;
public readonly string Race = null;
/* todo: icon,... */
public readonly bool Selectable = true;
}
public class Country { /* we're only interested in the Info */ }

View File

@@ -102,11 +102,6 @@ namespace OpenRA
r.Next(w.Map.Bounds.Top, w.Map.Bounds.Bottom));
}
public static IEnumerable<CountryInfo> GetCountries(this World w)
{
return w.WorldActor.Info.Traits.WithInterface<CountryInfo>();
}
public static float Gauss1D(this Thirdparty.Random r, int samples)
{
return Graphics.Util.MakeArray(samples, _ => (float)r.NextDouble() * 2 - 1f)

View File

@@ -153,6 +153,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
};
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
.Where(c => c.Selectable)
.ToDictionary(a => a.Race, a => a.Name);
CountryNames.Add("random", "Any");

View File

@@ -104,6 +104,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
};
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
.Where(c => c.Selectable)
.ToDictionary(a => a.Race, a => a.Name);
CountryNames.Add("random", "Random");