Expose Player.BotType and make fields readonly.

This commit is contained in:
Paul Chote
2017-05-28 20:40:44 +00:00
parent 3a6796ac9d
commit e88754cd4a

View File

@@ -47,12 +47,13 @@ namespace OpenRA
public readonly bool Playable = true; public readonly bool Playable = true;
public readonly int ClientIndex; public readonly int ClientIndex;
public readonly PlayerReference PlayerReference; public readonly PlayerReference PlayerReference;
public readonly bool IsBot;
public readonly string BotType;
/// <summary>The faction (including Random, etc) that was selected in the lobby.</summary> /// <summary>The faction (including Random, etc) that was selected in the lobby.</summary>
public readonly FactionInfo DisplayFaction; public readonly FactionInfo DisplayFaction;
public WinState WinState = WinState.Undefined; public WinState WinState = WinState.Undefined;
public bool IsBot;
public int SpawnPoint; public int SpawnPoint;
public bool HasObjectives = false; public bool HasObjectives = false;
public bool Spectating; public bool Spectating;
@@ -94,8 +95,6 @@ namespace OpenRA
public Player(World world, Session.Client client, PlayerReference pr) public Player(World world, Session.Client client, PlayerReference pr)
{ {
string botType;
World = world; World = world;
InternalName = pr.Name; InternalName = pr.Name;
PlayerReference = pr; PlayerReference = pr;
@@ -113,7 +112,7 @@ namespace OpenRA
else else
PlayerName = client.Name; PlayerName = client.Name;
botType = client.Bot; BotType = client.Bot;
Faction = ChooseFaction(world, client.Faction, !pr.LockFaction); Faction = ChooseFaction(world, client.Faction, !pr.LockFaction);
DisplayFaction = ChooseDisplayFaction(world, client.Faction); DisplayFaction = ChooseDisplayFaction(world, client.Faction);
} }
@@ -126,7 +125,7 @@ namespace OpenRA
NonCombatant = pr.NonCombatant; NonCombatant = pr.NonCombatant;
Playable = pr.Playable; Playable = pr.Playable;
Spectating = pr.Spectating; Spectating = pr.Spectating;
botType = pr.Bot; BotType = pr.Bot;
Faction = ChooseFaction(world, pr.Faction, false); Faction = ChooseFaction(world, pr.Faction, false);
DisplayFaction = ChooseDisplayFaction(world, pr.Faction); DisplayFaction = ChooseDisplayFaction(world, pr.Faction);
} }
@@ -137,12 +136,12 @@ namespace OpenRA
fogVisibilities = PlayerActor.TraitsImplementing<IFogVisibilityModifier>().ToArray(); fogVisibilities = PlayerActor.TraitsImplementing<IFogVisibilityModifier>().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>().FirstOrDefault(b => b.Info.Name == botType); var logic = PlayerActor.TraitsImplementing<IBot>().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
logic.Activate(this); logic.Activate(this);
} }