Merge pull request #3687 from pchote/mapoptions

Lobby map option improvements.
This commit is contained in:
Matthias Mailänder
2013-08-17 02:42:23 -07:00
35 changed files with 749 additions and 162 deletions

View File

@@ -56,11 +56,17 @@ namespace OpenRA.Mods.RA.Buildings
return devMode.FastBuild || progress == 0;
}
bool ValidRenderPlayer()
{
var allyBuildRadius = self.World.LobbyInfo.GlobalSettings.AllyBuildRadius;
return self.Owner == self.World.RenderPlayer || (allyBuildRadius && self.Owner.IsAlliedWith(self.World.RenderPlayer));
}
// Range circle
public void RenderAfterWorld(WorldRenderer wr)
{
// Visible to player and allies
if (!self.Owner.IsAlliedWith(self.World.RenderPlayer))
if (!ValidRenderPlayer())
return;
wr.DrawRangeCircleWithContrast(
@@ -73,7 +79,7 @@ namespace OpenRA.Mods.RA.Buildings
public float GetValue()
{
// Visible to player and allies
if (!self.Owner.IsAlliedWith(self.World.RenderPlayer))
if (!ValidRenderPlayer())
return 0f;
// Ready or delay disabled

View File

@@ -43,7 +43,8 @@ namespace OpenRA.Mods.RA.Buildings
var center = topLeft.CenterPosition + FootprintUtils.CenterOffset(this);
foreach (var bp in world.ActorsWithTrait<BaseProvider>())
{
if (bp.Actor.Owner.Stances[p] != Stance.Ally || !bp.Trait.Ready())
var validOwner = bp.Actor.Owner == p || (world.LobbyInfo.GlobalSettings.AllyBuildRadius && bp.Actor.Owner.Stances[p] == Stance.Ally);
if (!validOwner || !bp.Trait.Ready())
continue;
// Range is counted from the center of the actor, not from each cell.
@@ -72,14 +73,21 @@ namespace OpenRA.Mods.RA.Buildings
var nearnessCandidates = new List<CPos>();
var bi = world.WorldActor.Trait<BuildingInfluence>();
var allyBuildRadius = world.LobbyInfo.GlobalSettings.AllyBuildRadius;
for (var y = scanStart.Y; y < scanEnd.Y; y++)
{
for (var x = scanStart.X; x < scanEnd.X; x++)
{
var at = bi.GetBuildingAt(new CPos(x, y));
if (at != null && at.Owner.Stances[p] == Stance.Ally && at.HasTrait<GivesBuildableArea>())
nearnessCandidates.Add(new CPos(x, y));
var pos = new CPos(x, y);
var at = bi.GetBuildingAt(pos);
if (at == null || !at.HasTrait<GivesBuildableArea>())
continue;
if (at.Owner == p || (allyBuildRadius && at.Owner.Stances[p] == Stance.Ally))
nearnessCandidates.Add(pos);
}
}
var buildingTiles = FootprintUtils.Tiles(buildingName, this, topLeft).ToList();
return nearnessCandidates

View File

@@ -309,6 +309,12 @@ namespace OpenRA.Mods.RA.Server
return true;
}
if (server.Map.Options.FragileAlliances.HasValue)
{
server.SendOrderTo(conn, "Message", "Map has disabled alliance configuration");
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.FragileAlliances);
server.SyncLobbyInfo();
return true;
@@ -322,6 +328,12 @@ namespace OpenRA.Mods.RA.Server
return true;
}
if (server.Map.Options.Cheats.HasValue)
{
server.SendOrderTo(conn, "Message", "Map has disabled cheat configuration");
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.AllowCheats);
server.SyncLobbyInfo();
return true;
@@ -335,6 +347,12 @@ namespace OpenRA.Mods.RA.Server
return true;
}
if (server.Map.Options.Shroud.HasValue)
{
server.SendOrderTo(conn, "Message", "Map has disabled shroud configuration");
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.Shroud);
server.SyncLobbyInfo();
return true;
@@ -348,6 +366,13 @@ namespace OpenRA.Mods.RA.Server
return true;
}
if (server.Map.Options.Fog.HasValue)
{
server.SendOrderTo(conn, "Message", "Map has disabled fog configuration");
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.Fog);
server.SyncLobbyInfo();
return true;
@@ -402,10 +427,35 @@ namespace OpenRA.Mods.RA.Server
return true;
}
if (server.Map.Options.Crates.HasValue)
{
server.SendOrderTo(conn, "Message", "Map has disabled crate configuration");
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.Crates);
server.SyncLobbyInfo();
return true;
}},
{ "allybuildradius",
s =>
{
if (!client.IsAdmin)
{
server.SendOrderTo(conn, "Message", "Only the host can set that option");
return true;
}
if (server.Map.Options.AllyBuildRadius.HasValue)
{
server.SendOrderTo(conn, "Message", "Map has disabled ally build radius configuration");
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.AllyBuildRadius);
server.SyncLobbyInfo();
return true;
}},
{ "difficulty",
s =>
{
@@ -414,10 +464,11 @@ namespace OpenRA.Mods.RA.Server
server.SendOrderTo(conn, "Message", "Only the host can set that option");
return true;
}
if ((server.Map.Difficulties == null && s != null) || (server.Map.Difficulties != null && !server.Map.Difficulties.Contains(s)))
if (s != null && !server.Map.Options.Difficulties.Contains(s))
{
server.SendOrderTo(conn, "Message", "Unsupported difficulty selected: {0}".F(s));
server.SendOrderTo(conn, "Message", "Supported difficulties: {0}".F(server.Map.Difficulties.JoinWith(",")));
server.SendOrderTo(conn, "Message", "Supported difficulties: {0}".F(server.Map.Options.Difficulties.JoinWith(",")));
return true;
}
@@ -434,7 +485,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
if (!server.Map.AllowStartUnitConfig)
if (!server.Map.Options.ConfigurableStartingUnits)
{
server.SendOrderTo(conn, "Message", "Map has disabled start unit configuration");
return true;
@@ -444,6 +495,25 @@ namespace OpenRA.Mods.RA.Server
server.SyncLobbyInfo();
return true;
}},
{ "startingcash",
s =>
{
if (!client.IsAdmin)
{
server.SendOrderTo(conn, "Message", "Only the host can set that option");
return true;
}
if (server.Map.Options.StartingCash.HasValue)
{
server.SendOrderTo(conn, "Message", "Map has disabled cash configuration");
return true;
}
server.lobbyInfo.GlobalSettings.StartingCash = int.Parse(s);
server.SyncLobbyInfo();
return true;
}},
{ "kick",
s =>
{
@@ -636,16 +706,20 @@ namespace OpenRA.Mods.RA.Server
.Select(p => MakeSlotFromPlayerReference(p.Value))
.Where(s => s != null)
.ToDictionary(s => s.PlayerReference, s => s);
server.Map.Options.UpdateServerSettings(server.lobbyInfo.GlobalSettings);
}
static void SetDefaultDifficulty(S server)
{
if (server.Map.Difficulties != null && server.Map.Difficulties.Any())
if (!server.Map.Options.Difficulties.Any())
{
if (!server.Map.Difficulties.Contains(server.lobbyInfo.GlobalSettings.Difficulty))
server.lobbyInfo.GlobalSettings.Difficulty = server.Map.Difficulties.First();
server.lobbyInfo.GlobalSettings.Difficulty = null;
return;
}
else server.lobbyInfo.GlobalSettings.Difficulty = null;
if (!server.Map.Options.Difficulties.Contains(server.lobbyInfo.GlobalSettings.Difficulty))
server.lobbyInfo.GlobalSettings.Difficulty = server.Map.Options.Difficulties.First();
}
}
}

View File

@@ -272,7 +272,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (allowCheats != null)
{
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
allowCheats.IsDisabled = configurationDisabled;
allowCheats.IsDisabled = () => Map.Options.Cheats.HasValue || configurationDisabled();
allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command(
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));
}
@@ -281,16 +281,25 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (crates != null)
{
crates.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Crates;
crates.IsDisabled = configurationDisabled;
crates.IsDisabled = () => Map.Options.Crates.HasValue || configurationDisabled();
crates.OnClick = () => orderManager.IssueOrder(Order.Command(
"crates {0}".F(!orderManager.LobbyInfo.GlobalSettings.Crates)));
}
var allybuildradius = optionsBin.GetOrNull<CheckboxWidget>("ALLYBUILDRADIUS_CHECKBOX");
if (allybuildradius != null)
{
allybuildradius.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllyBuildRadius;
allybuildradius.IsDisabled = () => Map.Options.AllyBuildRadius.HasValue || configurationDisabled();
allybuildradius.OnClick = () => orderManager.IssueOrder(Order.Command(
"allybuildradius {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllyBuildRadius)));
}
var fragileAlliance = optionsBin.GetOrNull<CheckboxWidget>("FRAGILEALLIANCES_CHECKBOX");
if (fragileAlliance != null)
{
fragileAlliance.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.FragileAlliances;
fragileAlliance.IsDisabled = configurationDisabled;
fragileAlliance.IsDisabled = () => Map.Options.FragileAlliances.HasValue || configurationDisabled();
fragileAlliance.OnClick = () => orderManager.IssueOrder(Order.Command(
"fragilealliance {0}".F(!orderManager.LobbyInfo.GlobalSettings.FragileAlliances)));
};
@@ -298,12 +307,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var difficulty = optionsBin.GetOrNull<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON");
if (difficulty != null)
{
difficulty.IsVisible = () => Map != null && Map.Difficulties != null && Map.Difficulties.Any();
difficulty.IsVisible = () => Map.Options.Difficulties.Any();
difficulty.IsDisabled = configurationDisabled;
difficulty.GetText = () => orderManager.LobbyInfo.GlobalSettings.Difficulty;
difficulty.OnMouseDown = _ =>
{
var options = Map.Difficulties.Select(d => new DropDownOption
var options = Map.Options.Difficulties.Select(d => new DropDownOption
{
Title = d,
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.Difficulty == d,
@@ -335,9 +344,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var classes = Rules.Info["world"].Traits.WithInterface<MPStartUnitsInfo>()
.Select(a => a.Class).Distinct();
startingUnits.IsDisabled = configurationDisabled;
startingUnits.IsVisible = () => Map.AllowStartUnitConfig;
startingUnits.GetText = () => className(orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass);
startingUnits.IsDisabled = () => !Map.Options.ConfigurableStartingUnits || configurationDisabled();
startingUnits.GetText = () => !Map.Options.ConfigurableStartingUnits ? "Not Available" : className(orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass);
startingUnits.OnMouseDown = _ =>
{
var options = classes.Select(c => new DropDownOption
@@ -360,11 +368,36 @@ namespace OpenRA.Mods.RA.Widgets.Logic
optionsBin.Get<LabelWidget>("STARTINGUNITS_DESC").IsVisible = startingUnits.IsVisible;
}
var startingCash = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGCASH_DROPDOWNBUTTON");
if (startingCash != null)
{
startingCash.IsDisabled = () => Map.Options.StartingCash.HasValue || configurationDisabled();
startingCash.GetText = () => Map.Options.StartingCash.HasValue ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash);
startingCash.OnMouseDown = _ =>
{
var options = Rules.Info["player"].Traits.Get<PlayerResourcesInfo>().SelectableCash.Select(c => new DropDownOption
{
Title = "${0}".F(c),
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingCash == c,
OnClick = () => orderManager.IssueOrder(Order.Command("startingcash {0}".F(c)))
});
Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
return item;
};
startingCash.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
};
}
var enableShroud = optionsBin.GetOrNull<CheckboxWidget>("SHROUD_CHECKBOX");
if (enableShroud != null)
{
enableShroud.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Shroud;
enableShroud.IsDisabled = configurationDisabled;
enableShroud.IsDisabled = () => Map.Options.Shroud.HasValue || configurationDisabled();
enableShroud.OnClick = () => orderManager.IssueOrder(Order.Command(
"shroud {0}".F(!orderManager.LobbyInfo.GlobalSettings.Shroud)));
};
@@ -373,7 +406,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (enableFog != null)
{
enableFog.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Fog;
enableFog.IsDisabled = configurationDisabled;
enableFog.IsDisabled = () => Map.Options.Fog.HasValue || configurationDisabled();
enableFog.OnClick = () => orderManager.IssueOrder(Order.Command(
"fog {0}".F(!orderManager.LobbyInfo.GlobalSettings.Fog)));
};
@@ -473,6 +506,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
else
throw new InvalidOperationException("Server's new map doesn't exist on your system and Downloading turned off");
Map = new Map(Game.modData.AvailableMaps[MapUid].Path);
// Restore default starting cash if the last map set it to something invalid
var pri = Rules.Info["player"].Traits.Get<PlayerResourcesInfo>();
if (!Map.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash))
orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash)));
}
void UpdatePlayerList()