Touch up Player.cs
This commit is contained in:
@@ -51,42 +51,42 @@ namespace OpenRA
|
|||||||
|
|
||||||
readonly IFogVisibilityModifier[] fogVisibilities;
|
readonly IFogVisibilityModifier[] fogVisibilities;
|
||||||
|
|
||||||
FactionInfo ChooseCountry(World world, string name, bool requireSelectable = true)
|
static FactionInfo ChooseFaction(World world, string name, bool requireSelectable = true)
|
||||||
{
|
{
|
||||||
var selectableCountries = world.Map.Rules.Actors["world"].Traits
|
var selectableFactions = world.Map.Rules.Actors["world"].Traits
|
||||||
.WithInterface<FactionInfo>().Where(f => !requireSelectable || f.Selectable)
|
.WithInterface<FactionInfo>().Where(f => !requireSelectable || f.Selectable)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var selected = selectableCountries.FirstOrDefault(f => f.InternalName == name)
|
var selected = selectableFactions.FirstOrDefault(f => f.InternalName == name)
|
||||||
?? selectableCountries.Random(world.SharedRandom);
|
?? selectableFactions.Random(world.SharedRandom);
|
||||||
|
|
||||||
// Don't loop infinite
|
// Don't loop infinite
|
||||||
for (var i = 0; i <= 10 && selected.RandomFactionMembers.Any(); i++)
|
for (var i = 0; i <= 10 && selected.RandomFactionMembers.Any(); i++)
|
||||||
{
|
{
|
||||||
var race = selected.RandomFactionMembers.Random(world.SharedRandom);
|
var faction = selected.RandomFactionMembers.Random(world.SharedRandom);
|
||||||
selected = selectableCountries.FirstOrDefault(f => f.InternalName == race);
|
selected = selectableFactions.FirstOrDefault(f => f.InternalName == faction);
|
||||||
|
|
||||||
if (selected == null)
|
if (selected == null)
|
||||||
throw new YamlException("Unknown race: {0}".F(race));
|
throw new YamlException("Unknown faction: {0}".F(faction));
|
||||||
}
|
}
|
||||||
|
|
||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
FactionInfo ChooseDisplayCountry(World world, string race)
|
static FactionInfo ChooseDisplayFaction(World world, string factionName)
|
||||||
{
|
{
|
||||||
var countries = world.Map.Rules.Actors["world"].Traits
|
var factions = world.Map.Rules.Actors["world"].Traits.WithInterface<FactionInfo>().ToArray();
|
||||||
.WithInterface<FactionInfo>().ToArray();
|
|
||||||
|
|
||||||
return countries.FirstOrDefault(f => f.InternalName == race) ?? countries.First();
|
return factions.FirstOrDefault(f => f.InternalName == factionName) ?? factions.First();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr)
|
public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr)
|
||||||
{
|
{
|
||||||
|
string botType;
|
||||||
|
|
||||||
World = world;
|
World = world;
|
||||||
InternalName = pr.Name;
|
InternalName = pr.Name;
|
||||||
PlayerReference = pr;
|
PlayerReference = pr;
|
||||||
string botType = null;
|
|
||||||
|
|
||||||
// Real player or host-created bot
|
// Real player or host-created bot
|
||||||
if (client != null)
|
if (client != null)
|
||||||
@@ -95,8 +95,8 @@ namespace OpenRA
|
|||||||
Color = client.Color;
|
Color = client.Color;
|
||||||
PlayerName = client.Name;
|
PlayerName = client.Name;
|
||||||
botType = client.Bot;
|
botType = client.Bot;
|
||||||
Faction = ChooseCountry(world, client.Race, !pr.LockFaction);
|
Faction = ChooseFaction(world, client.Race, !pr.LockFaction);
|
||||||
DisplayFaction = ChooseDisplayCountry(world, client.Race);
|
DisplayFaction = ChooseDisplayFaction(world, client.Race);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -108,22 +108,20 @@ namespace OpenRA
|
|||||||
Playable = pr.Playable;
|
Playable = pr.Playable;
|
||||||
Spectating = pr.Spectating;
|
Spectating = pr.Spectating;
|
||||||
botType = pr.Bot;
|
botType = pr.Bot;
|
||||||
Faction = ChooseCountry(world, pr.Faction, false);
|
Faction = ChooseFaction(world, pr.Faction, false);
|
||||||
DisplayFaction = ChooseDisplayCountry(world, pr.Faction);
|
DisplayFaction = ChooseDisplayFaction(world, pr.Faction);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
|
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
|
||||||
Shroud = PlayerActor.Trait<Shroud>();
|
Shroud = PlayerActor.Trait<Shroud>();
|
||||||
|
|
||||||
fogVisibilities = PlayerActor.TraitsImplementing<IFogVisibilityModifier>()
|
fogVisibilities = PlayerActor.TraitsImplementing<IFogVisibilityModifier>().ToArray();
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
// Enable the bot logic on the host
|
// Enable the bot logic on the host
|
||||||
IsBot = botType != null;
|
IsBot = botType != null;
|
||||||
if (IsBot && Game.IsHost)
|
if (IsBot && Game.IsHost)
|
||||||
{
|
{
|
||||||
var logic = PlayerActor.TraitsImplementing<IBot>()
|
var logic = PlayerActor.TraitsImplementing<IBot>().FirstOrDefault(b => b.Info.Name == botType);
|
||||||
.FirstOrDefault(b => b.Info.Name == botType);
|
|
||||||
if (logic == null)
|
if (logic == null)
|
||||||
Log.Write("debug", "Invalid bot type: {0}", botType);
|
Log.Write("debug", "Invalid bot type: {0}", botType);
|
||||||
else
|
else
|
||||||
@@ -193,7 +191,7 @@ namespace OpenRA
|
|||||||
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
Player a, b;
|
Player a, b;
|
||||||
if (!left.TryGetClrValue<Player>(out a) || !right.TryGetClrValue<Player>(out b))
|
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return a == b;
|
return a == b;
|
||||||
|
|||||||
Reference in New Issue
Block a user