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)
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
|
||||
// create the unplayable map players -- neutral, shellmap, scripted, etc.
|
||||
foreach (var kv in w.Map.Players.Where(p => !p.Value.Playable))
|
||||
{
|
||||
var player = new Player(w, null, kv.Value);
|
||||
var player = new Player(w, null, null, kv.Value);
|
||||
w.AddPlayer(player);
|
||||
if (kv.Value.OwnsWorld)
|
||||
w.WorldActor.Owner = player;
|
||||
@@ -34,36 +34,14 @@ namespace OpenRA.Mods.RA
|
||||
foreach (var slot in w.LobbyInfo.Slots)
|
||||
{
|
||||
var client = w.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index && slot.MapPlayer != null);
|
||||
if (client != null)
|
||||
{
|
||||
/* spawn a real player in this slot. */
|
||||
var player = new Player(w, client, w.Map.Players[slot.MapPlayer]);
|
||||
w.AddPlayer(player);
|
||||
if (client.Index == Game.LocalClientId)
|
||||
w.SetLocalPlayer(player.InternalName); // bind this one to the local player.
|
||||
}
|
||||
// TODO: This is shit. Merge it up into Player ctor?
|
||||
else if (slot.Bot != null && slot.MapPlayer != null)
|
||||
{
|
||||
/* spawn a bot in this slot, "owned" by the host */
|
||||
if (client == null && slot.Bot == null)
|
||||
continue;
|
||||
|
||||
/* pick a random color for the bot */
|
||||
var hue = (byte)w.SharedRandom.Next(256);
|
||||
w.Map.Players[slot.MapPlayer].ColorRamp = new ColorRamp(hue, 255, 180, 25);
|
||||
|
||||
/* todo: pick a random name from the pool */
|
||||
var player = new Player(w, null, w.Map.Players[slot.MapPlayer]);
|
||||
var player = new Player(w, client, slot, w.Map.Players[slot.MapPlayer]);
|
||||
w.AddPlayer(player);
|
||||
|
||||
/* activate the bot option that's selected! */
|
||||
if (Game.IsHost)
|
||||
player.PlayerActor.TraitsImplementing<IBot>()
|
||||
.Single(b => b.Info.Name == slot.Bot)
|
||||
.Activate(player);
|
||||
|
||||
/* a bit of a hack */
|
||||
player.IsBot = true;
|
||||
}
|
||||
if (client != null && client.Index == Game.LocalClientId)
|
||||
w.SetLocalPlayer(player.InternalName);
|
||||
}
|
||||
|
||||
foreach (var p in w.Players)
|
||||
|
||||
Reference in New Issue
Block a user