From 83968553aa87b485aaf0832c4ccda5a1649b2039 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 15 Oct 2010 19:02:15 +1300 Subject: [PATCH] Allow maps to override and enforce race/colour selection --- OpenRA.FileFormats/Map/PlayerReference.cs | 8 ++- OpenRA.Game/Server/Server.cs | 53 ++++++++++++++----- .../Widgets/Delegates/LobbyDelegate.cs | 10 +++- mods/cnc/maps/gdi01/map.yaml | 2 + 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/OpenRA.FileFormats/Map/PlayerReference.cs b/OpenRA.FileFormats/Map/PlayerReference.cs index 7f315e468f..b0bd9f3c26 100644 --- a/OpenRA.FileFormats/Map/PlayerReference.cs +++ b/OpenRA.FileFormats/Map/PlayerReference.cs @@ -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); diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 8a51d6badd..d265e4edde 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -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> @@ -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; } diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs index ab9469eb80..8263bb25d1 100755 --- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs @@ -291,6 +291,9 @@ namespace OpenRA.Widgets.Delegates var color = template.GetWidget("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("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("FACTION"); - faction.OnMouseUp = CycleRace; + faction.OnMouseUp = mi => CycleRace(mi, s); var factionname = faction.GetWidget("FACTIONNAME"); factionname.GetText = () => CountryNames[c.Country]; var factionflag = faction.GetWidget("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) diff --git a/mods/cnc/maps/gdi01/map.yaml b/mods/cnc/maps/gdi01/map.yaml index 38572e3302..87fde0a243 100644 --- a/mods/cnc/maps/gdi01/map.yaml +++ b/mods/cnc/maps/gdi01/map.yaml @@ -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