Add plumbing for short game option
This commit is contained in:
@@ -68,6 +68,7 @@ namespace OpenRA
|
|||||||
public string TechLevel;
|
public string TechLevel;
|
||||||
public bool ConfigurableStartingUnits = true;
|
public bool ConfigurableStartingUnits = true;
|
||||||
public string[] Difficulties = { };
|
public string[] Difficulties = { };
|
||||||
|
public bool? ShortGame;
|
||||||
|
|
||||||
public void UpdateServerSettings(Session.Global settings)
|
public void UpdateServerSettings(Session.Global settings)
|
||||||
{
|
{
|
||||||
@@ -85,6 +86,8 @@ namespace OpenRA
|
|||||||
settings.StartingCash = StartingCash.Value;
|
settings.StartingCash = StartingCash.Value;
|
||||||
if (FragileAlliances.HasValue)
|
if (FragileAlliances.HasValue)
|
||||||
settings.FragileAlliances = FragileAlliances.Value;
|
settings.FragileAlliances = FragileAlliances.Value;
|
||||||
|
if (ShortGame.HasValue)
|
||||||
|
settings.ShortGame = ShortGame.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ namespace OpenRA.Network
|
|||||||
public int StartingCash = 5000;
|
public int StartingCash = 5000;
|
||||||
public string TechLevel = "none";
|
public string TechLevel = "none";
|
||||||
public string StartingUnitsClass = "none";
|
public string StartingUnitsClass = "none";
|
||||||
|
public bool ShortGame = true;
|
||||||
public bool AllowVersionMismatch;
|
public bool AllowVersionMismatch;
|
||||||
public string GameUid;
|
public string GameUid;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,11 @@ namespace OpenRA.Mods.Common
|
|||||||
{
|
{
|
||||||
public static bool HasNoRequiredUnits(this Player player)
|
public static bool HasNoRequiredUnits(this Player player)
|
||||||
{
|
{
|
||||||
return player.World.ActorsWithTrait<MustBeDestroyed>().All(p => p.Actor.Owner != player);
|
return !player.World.ActorsWithTrait<MustBeDestroyed>().Any(p =>
|
||||||
|
{
|
||||||
|
return p.Actor.Owner == player &&
|
||||||
|
(player.World.LobbyInfo.GlobalSettings.ShortGame ? p.Trait.Info.RequiredForShortGame : p.Actor.IsInWorld);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -809,6 +809,29 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
server.SyncLobbyClients();
|
server.SyncLobbyClients();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{ "shortgame",
|
||||||
|
s =>
|
||||||
|
{
|
||||||
|
if (!client.IsAdmin)
|
||||||
|
{
|
||||||
|
server.SendOrderTo(conn, "Message", "Only the host can set that option");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server.Map.Options.ShortGame.HasValue)
|
||||||
|
{
|
||||||
|
server.SendOrderTo(conn, "Message", "Map has disabled short game configuration");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.ShortGame);
|
||||||
|
server.SyncLobbyGlobalSettings();
|
||||||
|
server.SendMessage("{0} {1} Short Game."
|
||||||
|
.F(client.Name, server.LobbyInfo.GlobalSettings.ShortGame ? "enabled" : "disabled"));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,22 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Tag trait for things that must be destroyed for a short game to end.")]
|
[Desc("Actors with this trait must be destroyed for a game to end.")]
|
||||||
public class MustBeDestroyedInfo : TraitInfo<MustBeDestroyed> { }
|
public class MustBeDestroyedInfo : ITraitInfo
|
||||||
public class MustBeDestroyed { }
|
{
|
||||||
|
[Desc("In a short game only actors that have this value set to true need to be destroyed.")]
|
||||||
|
public bool RequiredForShortGame = false;
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new MustBeDestroyed(this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MustBeDestroyed
|
||||||
|
{
|
||||||
|
public readonly MustBeDestroyedInfo Info;
|
||||||
|
|
||||||
|
public MustBeDestroyed(MustBeDestroyedInfo info)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -690,6 +690,11 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adjust MustBeDestroyed for short games
|
||||||
|
if (engineVersion < 20141218)
|
||||||
|
if (depth == 1 && node.Key == "MustBeDestroyed")
|
||||||
|
node.Value.Nodes.Add(new MiniYamlNode("RequiredForShortGame", "true"));
|
||||||
|
|
||||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,8 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ScriptActorPropertyActivity]
|
[ScriptActorPropertyActivity]
|
||||||
[Desc("Returns true if this player has lost all units/actors that have the MustBeDestroyed trait.")]
|
[Desc("Returns true if this player has lost all units/actors that have" +
|
||||||
|
"the MustBeDestroyed trait (according to the short game option).")]
|
||||||
public bool HasNoRequiredUnits()
|
public bool HasNoRequiredUnits()
|
||||||
{
|
{
|
||||||
return player.HasNoRequiredUnits();
|
return player.HasNoRequiredUnits();
|
||||||
|
|||||||
Reference in New Issue
Block a user