add CountryInfo.Selectable
This commit is contained in:
@@ -410,7 +410,7 @@ namespace OpenRA
|
|||||||
Players.Clear();
|
Players.Clear();
|
||||||
|
|
||||||
var firstRace = OpenRA.Rules.Info["world"].Traits
|
var firstRace = OpenRA.Rules.Info["world"].Traits
|
||||||
.WithInterface<CountryInfo>().First().Race;
|
.WithInterface<CountryInfo>().First(c => c.Selectable).Race;
|
||||||
|
|
||||||
Players.Add("Neutral", new PlayerReference
|
Players.Add("Neutral", new PlayerReference
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,6 +39,16 @@ namespace OpenRA
|
|||||||
public Shroud Shroud { get { return World.LocalShroud; }}
|
public Shroud Shroud { get { return World.LocalShroud; }}
|
||||||
public World World { get; private set; }
|
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)
|
public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr)
|
||||||
{
|
{
|
||||||
World = world;
|
World = world;
|
||||||
@@ -53,10 +63,7 @@ namespace OpenRA
|
|||||||
ColorRamp = client.ColorRamp;
|
ColorRamp = client.ColorRamp;
|
||||||
PlayerName = client.Name;
|
PlayerName = client.Name;
|
||||||
botType = client.Bot;
|
botType = client.Bot;
|
||||||
|
Country = ChooseCountry(world, client.Country);
|
||||||
Country = world.GetCountries()
|
|
||||||
.FirstOrDefault(c => client.Country == c.Race)
|
|
||||||
?? world.GetCountries().Random(world.SharedRandom);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -66,10 +73,7 @@ namespace OpenRA
|
|||||||
PlayerName = pr.Name;
|
PlayerName = pr.Name;
|
||||||
NonCombatant = pr.NonCombatant;
|
NonCombatant = pr.NonCombatant;
|
||||||
botType = pr.Bot;
|
botType = pr.Bot;
|
||||||
|
Country = ChooseCountry(world, pr.Race);
|
||||||
Country = world.GetCountries()
|
|
||||||
.FirstOrDefault(c => pr.Race == c.Race)
|
|
||||||
?? world.GetCountries().Random(world.SharedRandom);
|
|
||||||
}
|
}
|
||||||
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
|
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
public readonly string Name = null;
|
public readonly string Name = null;
|
||||||
public readonly string Race = null;
|
public readonly string Race = null;
|
||||||
|
public readonly bool Selectable = true;
|
||||||
/* todo: icon,... */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Country { /* we're only interested in the Info */ }
|
public class Country { /* we're only interested in the Info */ }
|
||||||
|
|||||||
@@ -102,11 +102,6 @@ namespace OpenRA
|
|||||||
r.Next(w.Map.Bounds.Top, w.Map.Bounds.Bottom));
|
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)
|
public static float Gauss1D(this Thirdparty.Random r, int samples)
|
||||||
{
|
{
|
||||||
return Graphics.Util.MakeArray(samples, _ => (float)r.NextDouble() * 2 - 1f)
|
return Graphics.Util.MakeArray(samples, _ => (float)r.NextDouble() * 2 - 1f)
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
};
|
};
|
||||||
|
|
||||||
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
|
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
|
||||||
|
.Where(c => c.Selectable)
|
||||||
.ToDictionary(a => a.Race, a => a.Name);
|
.ToDictionary(a => a.Race, a => a.Name);
|
||||||
CountryNames.Add("random", "Any");
|
CountryNames.Add("random", "Any");
|
||||||
|
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
};
|
};
|
||||||
|
|
||||||
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
|
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
|
||||||
|
.Where(c => c.Selectable)
|
||||||
.ToDictionary(a => a.Race, a => a.Name);
|
.ToDictionary(a => a.Race, a => a.Name);
|
||||||
CountryNames.Add("random", "Random");
|
CountryNames.Add("random", "Random");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user