Allow picking of a random subfaction

This commit is contained in:
abcdefg30
2015-03-06 16:02:40 +01:00
parent 687403ab89
commit 63fe578ba8
19 changed files with 65 additions and 19 deletions

View File

@@ -118,7 +118,7 @@ namespace OpenRA
Color = runtimePlayer.Color,
Team = client.Team,
SpawnPoint = runtimePlayer.SpawnPoint,
IsRandomFaction = runtimePlayer.Country.Race != client.Country,
IsRandomFaction = runtimePlayer.Country.Race != client.Race,
IsRandomSpawnPoint = runtimePlayer.SpawnPoint != client.SpawnPoint
};

View File

@@ -102,7 +102,7 @@ namespace OpenRA.Network
public int Index;
public HSLColor PreferredColor; // Color that the client normally uses from settings.yaml.
public HSLColor Color; // Actual color that the client is using. Usually the same as PreferredColor but can be different on maps with locked colors.
public string Country;
public string Race;
public int SpawnPoint;
public string Name;
public string IpAddress;

View File

@@ -154,7 +154,7 @@ namespace OpenRA.Network
Name = Game.Settings.Player.Name,
PreferredColor = Game.Settings.Player.Color,
Color = Game.Settings.Player.Color,
Country = "random",
Race = "Random",
SpawnPoint = 0,
Team = 0,
State = Session.ClientState.Invalid

View File

@@ -52,8 +52,20 @@ namespace OpenRA
.WithInterface<CountryInfo>().Where(c => !requireSelectable || c.Selectable)
.ToList();
return selectableCountries.FirstOrDefault(c => c.Race == name)
var selected = selectableCountries.FirstOrDefault(c => c.Race == name)
?? selectableCountries.Random(world.SharedRandom);
// Don't loop infinite
for (var i = 0; i <= 10 && selected.RandomRaceMembers.Any(); i++)
{
var race = selected.RandomRaceMembers.Random(world.SharedRandom);
selected = selectableCountries.FirstOrDefault(c => c.Race == race);
if (selected == null)
throw new YamlException("Unknown race: {0}".F(race));
}
return selected;
}
public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr)
@@ -70,7 +82,7 @@ namespace OpenRA
Color = client.Color;
PlayerName = client.Name;
botType = client.Bot;
Country = ChooseCountry(world, client.Country);
Country = ChooseCountry(world, client.Race);
}
else
{

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Server
else
c.Color = c.PreferredColor;
if (pr.LockRace)
c.Country = pr.Race;
c.Race = pr.Race;
if (pr.LockSpawn)
c.SpawnPoint = pr.Spawn;
if (pr.LockTeam)
@@ -289,7 +289,7 @@ namespace OpenRA.Server
Slot = LobbyInfo.FirstEmptySlot(),
PreferredColor = handshake.Client.Color,
Color = handshake.Client.Color,
Country = "random",
Race = "Random",
SpawnPoint = 0,
Team = 0,
State = Session.ClientState.Invalid,

View File

@@ -18,6 +18,9 @@ namespace OpenRA.Traits
[Desc("This is the internal name for owner checks.")]
public readonly string Race = null;
[Desc("Pick a random race as the player's race out of this list.")]
public readonly string[] RandomRaceMembers = { };
[Desc("The side that the country belongs to. For example, England belongs to the 'Allies' side.")]
public readonly string Side = null;

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Widgets
ClientIndex = client.Index;
PlayerName = client.Name;
Team = client.Team;
Country = client.Country;
Country = client.Race;
SpawnPoint = client.SpawnPoint;
}

View File

@@ -270,7 +270,7 @@ namespace OpenRA.Mods.Common.Server
Name = botType,
Bot = botType,
Slot = parts[0],
Country = "random",
Race = "Random",
SpawnPoint = 0,
Team = 0,
State = Session.ClientState.NotReady,
@@ -738,7 +738,7 @@ namespace OpenRA.Mods.Common.Server
if (server.LobbyInfo.Slots[targetClient.Slot].LockRace)
return true;
targetClient.Country = parts[1];
targetClient.Race = parts[1];
server.SyncLobbyClients();
return true;
}

View File

@@ -144,7 +144,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Color = Game.Settings.Player.Color;
countries.Add("random", new LobbyCountry { Name = "Any" });
foreach (var c in modRules.Actors["world"].Traits.WithInterface<CountryInfo>().Where(c => c.Selectable))
countries.Add(c.Race, new LobbyCountry { Name = c.Name, Side = c.Side, Description = c.Description });

View File

@@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (race, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => client.Country == race,
() => client.Race == race,
() => orderManager.IssueOrder(Order.Command("race {0} {1}".F(client.Index, race))));
var country = countries[race];
item.Get<LabelWidget>("LABEL").GetText = () => country.Name;
@@ -398,7 +398,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var dropdown = parent.Get<DropDownButtonWidget>("FACTION");
dropdown.IsDisabled = () => s.LockRace || orderManager.LocalClient.IsReady;
dropdown.OnMouseDown = _ => ShowRaceDropDown(dropdown, c, orderManager, countries);
var factionDescription = countries[c.Country].Description;
var factionDescription = countries[c.Race].Description;
dropdown.GetTooltipText = () => factionDescription;
SetupFactionWidget(dropdown, s, c, countries);
}
@@ -407,9 +407,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Dictionary<string, LobbyCountry> countries)
{
var factionName = parent.Get<LabelWidget>("FACTIONNAME");
factionName.GetText = () => countries[c.Country].Name;
factionName.GetText = () => countries[c.Race].Name;
var factionFlag = parent.Get<ImageWidget>("FACTIONFLAG");
factionFlag.GetImageName = () => c.Country;
factionFlag.GetImageName = () => c.Race;
factionFlag.GetImageCollection = () => "flags";
}

View File

@@ -461,7 +461,7 @@ scrollbar: chrome.png
flags: chrome.png
nod: 352,0,32,16
gdi: 352,16,32,16
random: 352,32,32,16
Random: 352,32,32,16
strategic: strategic.png
unowned: 0,0,32,32

View File

@@ -81,6 +81,10 @@ World:
FogVariants: typea, typeb, typec, typed
OverrideFullShroud: full
OverrideFullFog: full
Country@Random:
Name: Any
Race: Random
RandomRaceMembers: gdi, nod
Country@gdi:
Name: GDI
Race: gdi

View File

@@ -91,7 +91,7 @@ flags: buttons.png
atreides: 0,114,22,21
harkonnen: 22,114,23,21
ordos: 45,114,22,21
random: 67,114,23,21
Random: 67,114,23,21
spectator: 67,114,23,21
# Used for the menu

View File

@@ -94,6 +94,10 @@ World:
OverrideFullShroud: full
OverrideFullFog: full
ShroudBlend: Multiply
Country@Random:
Name: Any
Race: Random
RandomRaceMembers: atreides, harkonnen, ordos
Country@Atreides:
Name: Atreides
Race: atreides

View File

@@ -471,7 +471,9 @@ strategic: strategic.png
flags: buttons.png
soviet: 0,112,30,15
allies: 30,112,30,15
random: 60,112,30,15
Random: 60,112,30,15
RandomAllies: 30,172,30,15
RandomSoviet: 0,172,30,15
spectator: 60,112,30,15
russia: 0,127,30,15

View File

@@ -126,6 +126,24 @@ World:
Race: ukraine
Side: Soviet
Description: Ukraine: Demolitions\nSpecial Ability: Parabombs\nSpecial Unit: Demolition Truck
Country@random:
Name: Any
Race: Random
RandomRaceMembers: RandomAllies, RandomSoviet
Side: Random
Description: A random country.
Country@randomallies:
Name: Allied
Race: RandomAllies
RandomRaceMembers: allies, england, france, germany
Side: Random
Description: A random Allied country.
Country@randomsoviet:
Name: Soviet
Race: RandomSoviet
RandomRaceMembers: soviet, russia, ukraine
Side: Random
Description: A random Soviet country.
DomainIndex:
SmudgeLayer@SCORCH:
Type: Scorch

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 257 KiB

View File

@@ -453,7 +453,7 @@ strategic: strategic.png
flags: buttons.png
gdi: 30,112,30,15
nod: 0,112,30,15
random: 60,112,30,15
Random: 60,112,30,15
spectator: 60,112,30,15
music: musicplayer.png

View File

@@ -79,6 +79,10 @@ World:
VoxelNormalsPalette@normals:
Name: normals
Type: TiberianSun
Country@Random:
Name: Any
Race: Random
RandomRaceMembers: gdi, nod
Country@0:
Name: GDI
Race: gdi