Move starting units configuration to rules.
This commit is contained in:
@@ -61,7 +61,6 @@ namespace OpenRA
|
|||||||
public bool? Creeps;
|
public bool? Creeps;
|
||||||
public bool? AllyBuildRadius;
|
public bool? AllyBuildRadius;
|
||||||
public string TechLevel;
|
public string TechLevel;
|
||||||
public bool ConfigurableStartingUnits = true;
|
|
||||||
public string[] Difficulties = { };
|
public string[] Difficulties = { };
|
||||||
public bool? ShortGame;
|
public bool? ShortGame;
|
||||||
|
|
||||||
@@ -118,7 +117,6 @@ namespace OpenRA
|
|||||||
public string Description;
|
public string Description;
|
||||||
public string Author;
|
public string Author;
|
||||||
public string Tileset;
|
public string Tileset;
|
||||||
public bool AllowStartUnitConfig = true;
|
|
||||||
public Bitmap CustomPreview;
|
public Bitmap CustomPreview;
|
||||||
public bool InvalidCustomRules { get; private set; }
|
public bool InvalidCustomRules { get; private set; }
|
||||||
|
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ namespace OpenRA.Network
|
|||||||
public bool AllyBuildRadius = true;
|
public bool AllyBuildRadius = true;
|
||||||
public int StartingCash = 5000;
|
public int StartingCash = 5000;
|
||||||
public string TechLevel = "none";
|
public string TechLevel = "none";
|
||||||
public string StartingUnitsClass = "none";
|
public string StartingUnitsClass;
|
||||||
public string GameSpeedType = "default";
|
public string GameSpeedType = "default";
|
||||||
public bool ShortGame = true;
|
public bool ShortGame = true;
|
||||||
public bool AllowVersionMismatch;
|
public bool AllowVersionMismatch;
|
||||||
|
|||||||
@@ -617,7 +617,8 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
return true;
|
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.");
|
server.SendOrderTo(conn, "Message", "Map has disabled start unit configuration.");
|
||||||
return true;
|
return true;
|
||||||
@@ -1030,6 +1031,9 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
var resources = server.Map.Rules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
|
var resources = server.Map.Rules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
|
||||||
gs.StartingCash = resources.DefaultCash;
|
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);
|
server.Map.Options.UpdateServerSettings(server.LobbyInfo.GlobalSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,13 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.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.")]
|
[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
|
public class SpawnMPUnits : IWorldLoaded
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -429,19 +429,27 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var startingUnits = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGUNITS_DROPDOWNBUTTON");
|
var startingUnits = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGUNITS_DROPDOWNBUTTON");
|
||||||
if (startingUnits != null)
|
if (startingUnits != null)
|
||||||
{
|
{
|
||||||
var startUnitsInfo = modRules.Actors["world"].TraitInfos<MPStartUnitsInfo>();
|
var startUnitsInfos = new CachedTransform<Map, IEnumerable<MPStartUnitsInfo>>(
|
||||||
var classes = startUnitsInfo.Select(a => a.Class).Distinct();
|
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 =>
|
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;
|
return selectedClass != null ? selectedClass : c;
|
||||||
};
|
};
|
||||||
|
|
||||||
startingUnits.IsDisabled = () => configurationDisabled() || !Map.Options.ConfigurableStartingUnits;
|
startingUnits.IsDisabled = () => configurationDisabled() || startUnitsLocked.Update(Map);
|
||||||
startingUnits.GetText = () => MapPreview.Status != MapStatus.Available ||
|
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 = _ =>
|
startingUnits.OnMouseDown = _ =>
|
||||||
{
|
{
|
||||||
|
var classes = startUnitsInfos.Update(Map).Select(a => a.Class).Distinct();
|
||||||
var options = classes.Select(c => new DropDownOption
|
var options = classes.Select(c => new DropDownOption
|
||||||
{
|
{
|
||||||
Title = className(c),
|
Title = className(c),
|
||||||
|
|||||||
@@ -163,7 +163,6 @@ ServerTraits:
|
|||||||
LobbySettingsNotification
|
LobbySettingsNotification
|
||||||
|
|
||||||
LobbyDefaults:
|
LobbyDefaults:
|
||||||
StartingUnitsClass: light
|
|
||||||
TechLevel: Unrestricted
|
TechLevel: Unrestricted
|
||||||
|
|
||||||
ChromeMetrics:
|
ChromeMetrics:
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ World:
|
|||||||
BaseActor: mcv
|
BaseActor: mcv
|
||||||
SupportActors: e1,e1,e1,e1,e1,e2,e2,e2,e3,e3,apc,mtnk
|
SupportActors: e1,e1,e1,e1,e1,e2,e2,e2,e3,e3,apc,mtnk
|
||||||
SpawnMPUnits:
|
SpawnMPUnits:
|
||||||
|
StartingUnitsClass: light
|
||||||
CrateSpawner:
|
CrateSpawner:
|
||||||
Minimum: 1
|
Minimum: 1
|
||||||
Maximum: 6
|
Maximum: 6
|
||||||
|
|||||||
Reference in New Issue
Block a user