Move starting units configuration to rules.

This commit is contained in:
Paul Chote
2016-02-29 20:20:02 +00:00
parent e34864fe40
commit 3c779d4101
7 changed files with 27 additions and 11 deletions

View File

@@ -61,7 +61,6 @@ namespace OpenRA
public bool? Creeps;
public bool? AllyBuildRadius;
public string TechLevel;
public bool ConfigurableStartingUnits = true;
public string[] Difficulties = { };
public bool? ShortGame;
@@ -118,7 +117,6 @@ namespace OpenRA
public string Description;
public string Author;
public string Tileset;
public bool AllowStartUnitConfig = true;
public Bitmap CustomPreview;
public bool InvalidCustomRules { get; private set; }

View File

@@ -191,7 +191,7 @@ namespace OpenRA.Network
public bool AllyBuildRadius = true;
public int StartingCash = 5000;
public string TechLevel = "none";
public string StartingUnitsClass = "none";
public string StartingUnitsClass;
public string GameSpeedType = "default";
public bool ShortGame = true;
public bool AllowVersionMismatch;

View File

@@ -617,7 +617,8 @@ namespace OpenRA.Mods.Common.Server
return true;
}
if (!server.Map.Options.ConfigurableStartingUnits)
var startingUnits = server.Map.Rules.Actors["world"].TraitInfoOrDefault<SpawnMPUnitsInfo>();
if (startingUnits == null || startingUnits.Locked)
{
server.SendOrderTo(conn, "Message", "Map has disabled start unit configuration.");
return true;
@@ -1030,6 +1031,9 @@ namespace OpenRA.Mods.Common.Server
var resources = server.Map.Rules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
gs.StartingCash = resources.DefaultCash;
var startingUnits = server.Map.Rules.Actors["world"].TraitInfoOrDefault<SpawnMPUnitsInfo>();
gs.StartingUnitsClass = startingUnits == null ? "none" : startingUnits.StartingUnitsClass;
server.Map.Options.UpdateServerSettings(server.LobbyInfo.GlobalSettings);
}

View File

@@ -18,7 +18,13 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Spawn base actor at the spawnpoint and support units in an annulus around the base actor. Both are defined at MPStartUnits. Attach this to the world actor.")]
public class SpawnMPUnitsInfo : TraitInfo<SpawnMPUnits>, Requires<MPStartLocationsInfo>, Requires<MPStartUnitsInfo> { }
public class SpawnMPUnitsInfo : TraitInfo<SpawnMPUnits>, Requires<MPStartLocationsInfo>, Requires<MPStartUnitsInfo>
{
public readonly string StartingUnitsClass = "none";
[Desc("Prevent the starting units option from being changed in the lobby.")]
public bool Locked = false;
}
public class SpawnMPUnits : IWorldLoaded
{

View File

@@ -429,19 +429,27 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var startingUnits = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGUNITS_DROPDOWNBUTTON");
if (startingUnits != null)
{
var startUnitsInfo = modRules.Actors["world"].TraitInfos<MPStartUnitsInfo>();
var classes = startUnitsInfo.Select(a => a.Class).Distinct();
var startUnitsInfos = new CachedTransform<Map, IEnumerable<MPStartUnitsInfo>>(
map => map.Rules.Actors["world"].TraitInfos<MPStartUnitsInfo>());
var startUnitsLocked = new CachedTransform<Map, bool>(map =>
{
var spawnUnitsInfo = map.Rules.Actors["world"].TraitInfoOrDefault<SpawnMPUnitsInfo>();
return spawnUnitsInfo == null || spawnUnitsInfo.Locked;
});
Func<string, string> className = c =>
{
var selectedClass = startUnitsInfo.Where(s => s.Class == c).Select(u => u.ClassName).FirstOrDefault();
var selectedClass = startUnitsInfos.Update(Map).Where(s => s.Class == c).Select(u => u.ClassName).FirstOrDefault();
return selectedClass != null ? selectedClass : c;
};
startingUnits.IsDisabled = () => configurationDisabled() || !Map.Options.ConfigurableStartingUnits;
startingUnits.IsDisabled = () => configurationDisabled() || startUnitsLocked.Update(Map);
startingUnits.GetText = () => MapPreview.Status != MapStatus.Available ||
Map == null || !Map.Options.ConfigurableStartingUnits ? "Not Available" : className(orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass);
Map == null || startUnitsLocked.Update(Map) ? "Not Available" : className(orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass);
startingUnits.OnMouseDown = _ =>
{
var classes = startUnitsInfos.Update(Map).Select(a => a.Class).Distinct();
var options = classes.Select(c => new DropDownOption
{
Title = className(c),

View File

@@ -163,7 +163,6 @@ ServerTraits:
LobbySettingsNotification
LobbyDefaults:
StartingUnitsClass: light
TechLevel: Unrestricted
ChromeMetrics:

View File

@@ -135,6 +135,7 @@ World:
BaseActor: mcv
SupportActors: e1,e1,e1,e1,e1,e2,e2,e2,e3,e3,apc,mtnk
SpawnMPUnits:
StartingUnitsClass: light
CrateSpawner:
Minimum: 1
Maximum: 6