Allow maps to override and enforce race/colour selection

This commit is contained in:
Paul Chote
2010-10-15 19:02:15 +13:00
parent aa2aba1250
commit 83968553aa
4 changed files with 55 additions and 18 deletions

View File

@@ -16,12 +16,16 @@ namespace OpenRA.FileFormats
{
public string Name;
public string Palette;
public string Race;
public bool OwnsWorld = false;
public bool NonCombatant = false;
public bool Playable = false;
public bool DefaultStartingUnits = false;
public bool AllowBots = true;
public bool AllowBots = true;
public bool LockRace = false;
public string Race;
public bool LockColor = false;
public Color Color = Color.FromArgb(238,238,238);
public Color Color2 = Color.FromArgb(44,28,24);

View File

@@ -191,19 +191,25 @@ namespace OpenRA.Server
conns.Add(newConn);
var defaults = new GameRules.PlayerSettings();
lobbyInfo.Clients.Add(
new Session.Client()
{
Index = newConn.PlayerIndex,
Color1 = defaults.Color1,
Color2 = defaults.Color2,
Name = defaults.Name,
Country = "random",
State = Session.ClientState.NotReady,
SpawnPoint = 0,
Team = 0,
Slot = ChooseFreeSlot(),
});
var client = new Session.Client()
{
Index = newConn.PlayerIndex,
Color1 = defaults.Color1,
Color2 = defaults.Color2,
Name = defaults.Name,
Country = "random",
State = Session.ClientState.NotReady,
SpawnPoint = 0,
Team = 0,
Slot = ChooseFreeSlot(),
};
var slotData = lobbyInfo.Slots.FirstOrDefault( x => x.Index == client.Slot );
if (slotData != null)
SyncClientToPlayerReference(client, Map.Players[slotData.MapPlayer]);
lobbyInfo.Clients.Add(client);
Log.Write("server", "Client {0}: Accepted connection from {1}",
newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
@@ -275,6 +281,17 @@ namespace OpenRA.Server
catch (NotImplementedException) { }
}
static void SyncClientToPlayerReference(Session.Client c, PlayerReference pr)
{
if (pr.LockColor)
{
c.Color1 = pr.Color;
c.Color2 = pr.Color2;
}
if (pr.LockRace)
c.Country = pr.Race;
}
static bool InterpretCommand(Connection conn, string cmd)
{
var dict = new Dictionary<string, Func<string, bool>>
@@ -391,7 +408,11 @@ namespace OpenRA.Server
|| lobbyInfo.Clients.Any( c => c.Slot == slot ))
return false;
GetClient(conn).Slot = slot;
var cl = GetClient(conn);
cl.Slot = slot;
SyncClientToPlayerReference(cl, Map.Players[slotData.MapPlayer]);
SyncLobbyInfo();
return true;
}},
@@ -491,6 +512,10 @@ namespace OpenRA.Server
foreach(var client in lobbyInfo.Clients)
{
client.SpawnPoint = 0;
var slotData = lobbyInfo.Slots.FirstOrDefault( x => x.Index == client.Slot );
if (slotData != null)
SyncClientToPlayerReference(client, Map.Players[slotData.MapPlayer]);
client.State = Session.ClientState.NotReady;
}

View File

@@ -291,6 +291,9 @@ namespace OpenRA.Widgets.Delegates
var color = template.GetWidget<ButtonWidget>("COLOR");
color.OnMouseUp = mi =>
{
if (Map.Players[s.MapPlayer].LockColor)
return false;
var colorChooser = Widget.RootWidget.GetWidget("SERVER_LOBBY").GetWidget("COLOR_CHOOSER");
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
hueSlider.SetOffset(orderManager.LocalClient.Color1.GetHue()/360f);
@@ -313,7 +316,7 @@ namespace OpenRA.Widgets.Delegates
colorBlock.GetColor = () => c.Color1;
var faction = template.GetWidget<ButtonWidget>("FACTION");
faction.OnMouseUp = CycleRace;
faction.OnMouseUp = mi => CycleRace(mi, s);
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
factionname.GetText = () => CountryNames[c.Country];
var factionflag = faction.GetWidget<ImageWidget>("FACTIONFLAG");
@@ -362,8 +365,11 @@ namespace OpenRA.Widgets.Delegates
}
bool SpawnPointAvailable(int index) { return (index == 0) || orderManager.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
bool CycleRace(MouseInput mi)
bool CycleRace(MouseInput mi, Session.Slot s)
{
if (Map.Players[s.MapPlayer].LockColor)
return false;
var countries = CountryNames.Select(a => a.Key);
if (mi.Button == MouseButton.Right)

View File

@@ -34,8 +34,10 @@ Players:
Name: GoodGuy
Playable: yes
Race: gdi
LockRace: true
OwnsWorld: False
NonCombatant: False
LockColor: true
Color: 255,246,214,121
Color2: 255,40,32,8
InitialCash: 20