bots choose random colors

This commit is contained in:
Chris Forbes
2010-10-07 07:41:14 +13:00
parent c85503811c
commit 5af8f5e2d9
3 changed files with 12 additions and 2 deletions

View File

@@ -49,6 +49,7 @@ namespace OpenRA
Index = index;
Palette = "player"+index;
Color = pr.Color;
Color2 = pr.Color2;
ClientIndex = 0; /* it's a map player, "owned" by host */

View File

@@ -174,7 +174,7 @@ namespace OpenRA.Widgets.Delegates
}
// hk is hue in the range [0,1] instead of [0,360]
Color ColorFromHSL(float hk, float s, float l)
public static Color ColorFromHSL(float hk, float s, float l)
{
// Convert from HSL to RGB
var q = (l < 0.5f) ? l * (1 + s) : l + s - (l * s);

View File

@@ -11,6 +11,7 @@
using System.Linq;
using OpenRA.Network;
using OpenRA.Traits;
using OpenRA.Widgets.Delegates;
namespace OpenRA.Mods.RA
{
@@ -47,6 +48,14 @@ namespace OpenRA.Mods.RA
else if (slot.Bot != null)
{
/* spawn a bot in this slot, "owned" by the host */
/* pick a random color for the bot */
var hue = (float)w.SharedRandom.NextDouble();
w.Map.Players[slot.MapPlayer].Color = LobbyDelegate.ColorFromHSL(hue, 1.0f, 0.7f);
w.Map.Players[slot.MapPlayer].Color2 = LobbyDelegate.ColorFromHSL(hue, 1.0f, 0.2f);
/* todo: pick a random name from the pool */
var player = new Player(w, w.Map.Players[slot.MapPlayer], playerIndex++);
w.AddPlayer(player);