Allow maps to override and enforce race/colour selection
This commit is contained in:
@@ -16,12 +16,16 @@ namespace OpenRA.FileFormats
|
|||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
public string Palette;
|
public string Palette;
|
||||||
public string Race;
|
|
||||||
public bool OwnsWorld = false;
|
public bool OwnsWorld = false;
|
||||||
public bool NonCombatant = false;
|
public bool NonCombatant = false;
|
||||||
public bool Playable = false;
|
public bool Playable = false;
|
||||||
public bool DefaultStartingUnits = 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 Color = Color.FromArgb(238,238,238);
|
||||||
public Color Color2 = Color.FromArgb(44,28,24);
|
public Color Color2 = Color.FromArgb(44,28,24);
|
||||||
|
|
||||||
|
|||||||
@@ -191,19 +191,25 @@ namespace OpenRA.Server
|
|||||||
conns.Add(newConn);
|
conns.Add(newConn);
|
||||||
|
|
||||||
var defaults = new GameRules.PlayerSettings();
|
var defaults = new GameRules.PlayerSettings();
|
||||||
lobbyInfo.Clients.Add(
|
|
||||||
new Session.Client()
|
var client = new Session.Client()
|
||||||
{
|
{
|
||||||
Index = newConn.PlayerIndex,
|
Index = newConn.PlayerIndex,
|
||||||
Color1 = defaults.Color1,
|
Color1 = defaults.Color1,
|
||||||
Color2 = defaults.Color2,
|
Color2 = defaults.Color2,
|
||||||
Name = defaults.Name,
|
Name = defaults.Name,
|
||||||
Country = "random",
|
Country = "random",
|
||||||
State = Session.ClientState.NotReady,
|
State = Session.ClientState.NotReady,
|
||||||
SpawnPoint = 0,
|
SpawnPoint = 0,
|
||||||
Team = 0,
|
Team = 0,
|
||||||
Slot = ChooseFreeSlot(),
|
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}",
|
Log.Write("server", "Client {0}: Accepted connection from {1}",
|
||||||
newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
|
newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
|
||||||
@@ -275,6 +281,17 @@ namespace OpenRA.Server
|
|||||||
catch (NotImplementedException) { }
|
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)
|
static bool InterpretCommand(Connection conn, string cmd)
|
||||||
{
|
{
|
||||||
var dict = new Dictionary<string, Func<string, bool>>
|
var dict = new Dictionary<string, Func<string, bool>>
|
||||||
@@ -391,7 +408,11 @@ namespace OpenRA.Server
|
|||||||
|| lobbyInfo.Clients.Any( c => c.Slot == slot ))
|
|| lobbyInfo.Clients.Any( c => c.Slot == slot ))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
GetClient(conn).Slot = slot;
|
var cl = GetClient(conn);
|
||||||
|
cl.Slot = slot;
|
||||||
|
|
||||||
|
SyncClientToPlayerReference(cl, Map.Players[slotData.MapPlayer]);
|
||||||
|
|
||||||
SyncLobbyInfo();
|
SyncLobbyInfo();
|
||||||
return true;
|
return true;
|
||||||
}},
|
}},
|
||||||
@@ -491,6 +512,10 @@ namespace OpenRA.Server
|
|||||||
foreach(var client in lobbyInfo.Clients)
|
foreach(var client in lobbyInfo.Clients)
|
||||||
{
|
{
|
||||||
client.SpawnPoint = 0;
|
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;
|
client.State = Session.ClientState.NotReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -291,6 +291,9 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
var color = template.GetWidget<ButtonWidget>("COLOR");
|
var color = template.GetWidget<ButtonWidget>("COLOR");
|
||||||
color.OnMouseUp = mi =>
|
color.OnMouseUp = mi =>
|
||||||
{
|
{
|
||||||
|
if (Map.Players[s.MapPlayer].LockColor)
|
||||||
|
return false;
|
||||||
|
|
||||||
var colorChooser = Widget.RootWidget.GetWidget("SERVER_LOBBY").GetWidget("COLOR_CHOOSER");
|
var colorChooser = Widget.RootWidget.GetWidget("SERVER_LOBBY").GetWidget("COLOR_CHOOSER");
|
||||||
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
|
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
|
||||||
hueSlider.SetOffset(orderManager.LocalClient.Color1.GetHue()/360f);
|
hueSlider.SetOffset(orderManager.LocalClient.Color1.GetHue()/360f);
|
||||||
@@ -313,7 +316,7 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
colorBlock.GetColor = () => c.Color1;
|
colorBlock.GetColor = () => c.Color1;
|
||||||
|
|
||||||
var faction = template.GetWidget<ButtonWidget>("FACTION");
|
var faction = template.GetWidget<ButtonWidget>("FACTION");
|
||||||
faction.OnMouseUp = CycleRace;
|
faction.OnMouseUp = mi => CycleRace(mi, s);
|
||||||
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
||||||
factionname.GetText = () => CountryNames[c.Country];
|
factionname.GetText = () => CountryNames[c.Country];
|
||||||
var factionflag = faction.GetWidget<ImageWidget>("FACTIONFLAG");
|
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 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);
|
var countries = CountryNames.Select(a => a.Key);
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
|
|||||||
@@ -34,8 +34,10 @@ Players:
|
|||||||
Name: GoodGuy
|
Name: GoodGuy
|
||||||
Playable: yes
|
Playable: yes
|
||||||
Race: gdi
|
Race: gdi
|
||||||
|
LockRace: true
|
||||||
OwnsWorld: False
|
OwnsWorld: False
|
||||||
NonCombatant: False
|
NonCombatant: False
|
||||||
|
LockColor: true
|
||||||
Color: 255,246,214,121
|
Color: 255,246,214,121
|
||||||
Color2: 255,40,32,8
|
Color2: 255,40,32,8
|
||||||
InitialCash: 20
|
InitialCash: 20
|
||||||
|
|||||||
Reference in New Issue
Block a user