Use DefaultCash for the default cash.
This commit is contained in:
@@ -60,7 +60,6 @@ namespace OpenRA
|
||||
{
|
||||
public bool? Creeps;
|
||||
public bool? AllyBuildRadius;
|
||||
public int? StartingCash;
|
||||
public string TechLevel;
|
||||
public bool ConfigurableStartingUnits = true;
|
||||
public string[] Difficulties = { };
|
||||
@@ -72,8 +71,6 @@ namespace OpenRA
|
||||
settings.Creeps = Creeps.Value;
|
||||
if (AllyBuildRadius.HasValue)
|
||||
settings.AllyBuildRadius = AllyBuildRadius.Value;
|
||||
if (StartingCash.HasValue)
|
||||
settings.StartingCash = StartingCash.Value;
|
||||
if (ShortGame.HasValue)
|
||||
settings.ShortGame = ShortGame.Value;
|
||||
}
|
||||
|
||||
@@ -16,9 +16,15 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public class PlayerResourcesInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Starting cash options that are available in the lobby options.")]
|
||||
public readonly int[] SelectableCash = { 2500, 5000, 10000, 20000 };
|
||||
|
||||
[Desc("Default starting cash option: should be one of the SelectableCash options.")]
|
||||
public readonly int DefaultCash = 5000;
|
||||
|
||||
[Desc("Force the DefaultCash option by disabling changes in the lobby.")]
|
||||
public readonly bool DefaultCashLocked = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new PlayerResources(init.Self, this); }
|
||||
}
|
||||
|
||||
|
||||
@@ -648,13 +648,14 @@ namespace OpenRA.Mods.Common.Server
|
||||
return true;
|
||||
}
|
||||
|
||||
if (server.Map.Options.StartingCash.HasValue)
|
||||
var playerResources = server.Map.Rules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
|
||||
if (playerResources.DefaultCashLocked)
|
||||
{
|
||||
server.SendOrderTo(conn, "Message", "Map has disabled cash configuration.");
|
||||
return true;
|
||||
}
|
||||
|
||||
var startingCashOptions = server.Map.Rules.Actors["player"].TraitInfo<PlayerResourcesInfo>().SelectableCash;
|
||||
var startingCashOptions = playerResources.SelectableCash;
|
||||
var requestedCash = Exts.ParseIntegerInvariant(s);
|
||||
if (!startingCashOptions.Contains(requestedCash))
|
||||
{
|
||||
@@ -1026,6 +1027,9 @@ namespace OpenRA.Mods.Common.Server
|
||||
gs.Fog = shroud.FogEnabled;
|
||||
gs.Shroud = !shroud.ExploredMapEnabled;
|
||||
|
||||
var resources = server.Map.Rules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
|
||||
gs.StartingCash = resources.DefaultCash;
|
||||
|
||||
server.Map.Options.UpdateServerSettings(server.LobbyInfo.GlobalSettings);
|
||||
}
|
||||
|
||||
|
||||
@@ -465,12 +465,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var startingCash = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGCASH_DROPDOWNBUTTON");
|
||||
if (startingCash != null)
|
||||
{
|
||||
startingCash.IsDisabled = () => configurationDisabled() || Map.Options.StartingCash.HasValue;
|
||||
var playerResources = new CachedTransform<Map, PlayerResourcesInfo>(
|
||||
map => map.Rules.Actors["player"].TraitInfo<PlayerResourcesInfo>());
|
||||
|
||||
startingCash.IsDisabled = () => configurationDisabled() || playerResources.Update(Map).DefaultCashLocked;
|
||||
startingCash.GetText = () => MapPreview.Status != MapStatus.Available ||
|
||||
Map == null || Map.Options.StartingCash.HasValue ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash);
|
||||
Map == null || playerResources.Update(Map).DefaultCashLocked ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash);
|
||||
startingCash.OnMouseDown = _ =>
|
||||
{
|
||||
var options = modRules.Actors["player"].TraitInfo<PlayerResourcesInfo>().SelectableCash.Select(c => new DropDownOption
|
||||
var options = playerResources.Update(Map).SelectableCash.Select(c => new DropDownOption
|
||||
{
|
||||
Title = "${0}".F(c),
|
||||
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingCash == c,
|
||||
@@ -776,11 +779,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
// Tell the server that we have the map
|
||||
orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady)));
|
||||
|
||||
// Restore default starting cash if the last map set it to something invalid
|
||||
var pri = modRules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
|
||||
if (!currentMap.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash))
|
||||
orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash)));
|
||||
}
|
||||
});
|
||||
}).Start();
|
||||
|
||||
Reference in New Issue
Block a user