Better bot spawning code; better random color and proper player names.
This commit is contained in:
@@ -39,11 +39,12 @@ namespace OpenRA
|
||||
public Shroud Shroud { get { return World.LocalShroud; }}
|
||||
public World World { get; private set; }
|
||||
|
||||
public Player(World world, Session.Client client, PlayerReference pr)
|
||||
public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr)
|
||||
{
|
||||
World = world;
|
||||
InternalName = pr.Name;
|
||||
PlayerRef = pr;
|
||||
string botType = null;
|
||||
|
||||
if (client != null)
|
||||
{
|
||||
@@ -57,23 +58,45 @@ namespace OpenRA
|
||||
}
|
||||
else
|
||||
{
|
||||
// Map player or bot
|
||||
ClientIndex = 0; /* it's a map player, "owned" by host */
|
||||
ColorRamp = pr.ColorRamp;
|
||||
PlayerName = pr.Name;
|
||||
NonCombatant = pr.NonCombatant;
|
||||
IsBot = pr.Bot != null;
|
||||
botType = pr.Bot;
|
||||
|
||||
Country = world.GetCountries()
|
||||
.FirstOrDefault(c => pr.Race == c.Race)
|
||||
?? world.GetCountries().Random(world.SharedRandom);
|
||||
|
||||
// Multiplayer bot
|
||||
if (slot != null && slot.Bot != null)
|
||||
{
|
||||
IsBot = true;
|
||||
botType = pr.Bot;
|
||||
PlayerName = slot.Bot;
|
||||
|
||||
// pick a random color for the bot
|
||||
var hue = (byte)world.SharedRandom.Next(255);
|
||||
var sat = (byte)world.SharedRandom.Next(255);
|
||||
var lum = (byte)world.SharedRandom.Next(51,255);
|
||||
ColorRamp = new ColorRamp(hue, sat, lum, 10);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
|
||||
|
||||
if (IsBot)
|
||||
PlayerActor.TraitsImplementing<IBot>()
|
||||
.Single(b => b.Info.Name == pr.Bot)
|
||||
.Activate(this);
|
||||
// Enable the bot logic
|
||||
if (IsBot && Game.IsHost)
|
||||
{
|
||||
var logic = PlayerActor.TraitsImplementing<IBot>()
|
||||
.FirstOrDefault(b => b.Info.Name == botType);
|
||||
if (logic == null)
|
||||
Log.Write("debug", "Invalid bot type: {0}", botType);
|
||||
else
|
||||
logic.Activate(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void GiveAdvice(string advice)
|
||||
|
||||
Reference in New Issue
Block a user