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 int ClientIndex;
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>
public readonly FactionInfo DisplayFaction;
public WinState WinState = WinState.Undefined;
public bool IsBot;
public int SpawnPoint;
public bool HasObjectives = false;
public bool Spectating;
@@ -94,8 +95,6 @@ namespace OpenRA
public Player(World world, Session.Client client, PlayerReference pr)
{
string botType;
World = world;
InternalName = pr.Name;
PlayerReference = pr;
@@ -113,7 +112,7 @@ namespace OpenRA
else
PlayerName = client.Name;
botType = client.Bot;
BotType = client.Bot;
Faction = ChooseFaction(world, client.Faction, !pr.LockFaction);
DisplayFaction = ChooseDisplayFaction(world, client.Faction);
}
@@ -126,7 +125,7 @@ namespace OpenRA
NonCombatant = pr.NonCombatant;
Playable = pr.Playable;
Spectating = pr.Spectating;
botType = pr.Bot;
BotType = pr.Bot;
Faction = ChooseFaction(world, pr.Faction, false);
DisplayFaction = ChooseDisplayFaction(world, pr.Faction);
}
@@ -137,12 +136,12 @@ namespace OpenRA
fogVisibilities = PlayerActor.TraitsImplementing<IFogVisibilityModifier>().ToArray();
// Enable the bot logic on the host
IsBot = botType != null;
IsBot = BotType != null;
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)
Log.Write("debug", "Invalid bot type: {0}", botType);
Log.Write("debug", "Invalid bot type: {0}", BotType);
else
logic.Activate(this);
}