Added in code for Tech Levels using prereqs
and fixed up some kinks of the old system
This commit is contained in:
@@ -31,6 +31,7 @@ namespace OpenRA
|
|||||||
public bool? AllyBuildRadius;
|
public bool? AllyBuildRadius;
|
||||||
public bool? FragileAlliances;
|
public bool? FragileAlliances;
|
||||||
public int? StartingCash;
|
public int? StartingCash;
|
||||||
|
public string TechLevel;
|
||||||
public bool ConfigurableStartingUnits = true;
|
public bool ConfigurableStartingUnits = true;
|
||||||
public string[] Difficulties = { };
|
public string[] Difficulties = { };
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ namespace OpenRA.Network
|
|||||||
public bool Fog = true;
|
public bool Fog = true;
|
||||||
public bool AllyBuildRadius = true;
|
public bool AllyBuildRadius = true;
|
||||||
public int StartingCash = 5000;
|
public int StartingCash = 5000;
|
||||||
|
public String TechLevel = "none";
|
||||||
public string StartingUnitsClass = "none";
|
public string StartingUnitsClass = "none";
|
||||||
public bool AllowVersionMismatch;
|
public bool AllowVersionMismatch;
|
||||||
public string GameUid;
|
public string GameUid;
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ namespace OpenRA.Mods.RA
|
|||||||
public readonly string[] Owner = { };
|
public readonly string[] Owner = { };
|
||||||
|
|
||||||
public readonly string Queue;
|
public readonly string Queue;
|
||||||
public readonly bool Hidden = false;
|
|
||||||
public readonly int BuildLimit = 0;
|
public readonly int BuildLimit = 0;
|
||||||
|
|
||||||
// TODO: UI fluff; doesn't belong here
|
// TODO: UI fluff; doesn't belong here
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Mods.RA.Buildings;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
@@ -18,10 +19,22 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||||
{
|
{
|
||||||
var providedPrereqs = map.Rules.Actors.Keys.Concat(
|
// Buildings provide their actor names as a prerequisite
|
||||||
map.Rules.Actors.SelectMany(a => a.Value.Traits
|
var buildingPrereqs = map.Rules.Actors.Where(a => a.Value.Traits.Contains<BuildingInfo>())
|
||||||
.WithInterface<ProvidesCustomPrerequisiteInfo>()
|
.Select(a => a.Key);
|
||||||
.Select(p => p.Prerequisite))).ToArray();
|
|
||||||
|
// ProvidesCustomPrerequisite allows arbitrary prereq definitions
|
||||||
|
var customPrereqs = map.Rules.Actors.SelectMany(a => a.Value.Traits
|
||||||
|
.WithInterface<ProvidesCustomPrerequisiteInfo>())
|
||||||
|
.Select(p => p.Prerequisite);
|
||||||
|
|
||||||
|
// ProvidesTechPrerequisite allows arbitrary prereq definitions
|
||||||
|
// (but only one group at a time during gameplay)
|
||||||
|
var techPrereqs = map.Rules.Actors.SelectMany(a => a.Value.Traits
|
||||||
|
.WithInterface<ProvidesTechPrerequisiteInfo>())
|
||||||
|
.SelectMany(p => p.Prerequisites);
|
||||||
|
|
||||||
|
var providedPrereqs = buildingPrereqs.Concat(customPrereqs).Concat(techPrereqs);
|
||||||
|
|
||||||
// TODO: this check is case insensitive while the real check in-game is not
|
// TODO: this check is case insensitive while the real check in-game is not
|
||||||
foreach (var i in map.Rules.Actors)
|
foreach (var i in map.Rules.Actors)
|
||||||
@@ -29,7 +42,7 @@ namespace OpenRA.Mods.RA
|
|||||||
var bi = i.Value.Traits.GetOrDefault<BuildableInfo>();
|
var bi = i.Value.Traits.GetOrDefault<BuildableInfo>();
|
||||||
if (bi != null)
|
if (bi != null)
|
||||||
foreach (var prereq in bi.Prerequisites)
|
foreach (var prereq in bi.Prerequisites)
|
||||||
if (!providedPrereqs.Contains(prereq.Replace("!", "")))
|
if (!providedPrereqs.Contains(prereq.Replace("!", "").Replace("~", "")))
|
||||||
emitError("Buildable actor {0} has prereq {1} not provided by anything.".F(i.Key, prereq));
|
emitError("Buildable actor {0} has prereq {1} not provided by anything.".F(i.Key, prereq));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -300,6 +300,7 @@
|
|||||||
<Compile Include="Player\ClassicProductionQueue.cs" />
|
<Compile Include="Player\ClassicProductionQueue.cs" />
|
||||||
<Compile Include="Player\PlaceBuilding.cs" />
|
<Compile Include="Player\PlaceBuilding.cs" />
|
||||||
<Compile Include="Player\ProductionQueue.cs" />
|
<Compile Include="Player\ProductionQueue.cs" />
|
||||||
|
<Compile Include="Player\ProvidesTechPrerequisite.cs" />
|
||||||
<Compile Include="PortableChrono.cs" />
|
<Compile Include="PortableChrono.cs" />
|
||||||
<Compile Include="World\RadarPings.cs" />
|
<Compile Include="World\RadarPings.cs" />
|
||||||
<Compile Include="Player\TechTree.cs" />
|
<Compile Include="Player\TechTree.cs" />
|
||||||
|
|||||||
@@ -123,11 +123,12 @@ namespace OpenRA.Mods.RA
|
|||||||
foreach (var a in AllBuildables(Info.Type))
|
foreach (var a in AllBuildables(Info.Type))
|
||||||
{
|
{
|
||||||
var bi = a.Traits.Get<BuildableInfo>();
|
var bi = a.Traits.Get<BuildableInfo>();
|
||||||
// Can our race build this by satisfying normal prereqs?
|
// Can our race build this by satisfying normal prerequisites?
|
||||||
var buildable = bi.Owner.Contains(Race.Race);
|
var buildable = bi.Owner.Contains(Race.Race);
|
||||||
tech.Add(a, new ProductionState { Visible = buildable && !bi.Hidden });
|
// Checks if Prerequisites want to hide the Actor from buildQueue if they are false
|
||||||
|
tech.Add(a, new ProductionState { Visible = buildable });
|
||||||
if (buildable)
|
if (buildable)
|
||||||
ttc.Add(a.Name, bi, this);
|
ttc.Add(a.Name, bi.Prerequisites, bi.BuildLimit, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tech;
|
return tech;
|
||||||
@@ -161,6 +162,18 @@ namespace OpenRA.Mods.RA
|
|||||||
ps.Buildable = false;
|
ps.Buildable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void PrerequisitesItemHidden(string key)
|
||||||
|
{
|
||||||
|
var ps = Produceable[self.World.Map.Rules.Actors[key]];
|
||||||
|
ps.Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PrerequisitesItemVisable(string key)
|
||||||
|
{
|
||||||
|
var ps = Produceable[self.World.Map.Rules.Actors[key]];
|
||||||
|
ps.Visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
public ProductionItem CurrentItem()
|
public ProductionItem CurrentItem()
|
||||||
{
|
{
|
||||||
return Queue.ElementAtOrDefault(0);
|
return Queue.ElementAtOrDefault(0);
|
||||||
|
|||||||
51
OpenRA.Mods.RA/Player/ProvidesTechPrerequisite.cs
Normal file
51
OpenRA.Mods.RA/Player/ProvidesTechPrerequisite.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRA.Primitives;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
public class ProvidesTechPrerequisiteInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public readonly string Name;
|
||||||
|
public readonly string[] Prerequisites = {};
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new ProvidesTechPrerequisite(this, init); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ProvidesTechPrerequisite : ITechTreePrerequisite
|
||||||
|
{
|
||||||
|
ProvidesTechPrerequisiteInfo info;
|
||||||
|
bool enabled;
|
||||||
|
static readonly string[] NoPrerequisites = new string[0];
|
||||||
|
|
||||||
|
public string Name { get { return info.Name; } }
|
||||||
|
|
||||||
|
public IEnumerable<string> ProvidesPrerequisites
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return enabled ? info.Prerequisites : NoPrerequisites;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProvidesTechPrerequisite(ProvidesTechPrerequisiteInfo info, ActorInitializer init)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
this.enabled = info.Name == init.world.LobbyInfo.GlobalSettings.TechLevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,14 +41,14 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
var buildables = GatherBuildables(player);
|
var ownedPrerequisites = GatherOwnedPrerequisites(player);
|
||||||
foreach (var w in watchers)
|
foreach (var w in watchers)
|
||||||
w.Update(buildables);
|
w.Update(ownedPrerequisites);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(string key, BuildableInfo info, ITechTreeElement tte)
|
public void Add(string key, string[] prerequisites, int limit, ITechTreeElement tte)
|
||||||
{
|
{
|
||||||
watchers.Add(new Watcher(key, info, tte));
|
watchers.Add(new Watcher(key, prerequisites, limit, tte));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(string key)
|
public void Remove(string key)
|
||||||
@@ -56,17 +56,17 @@ namespace OpenRA.Mods.RA
|
|||||||
watchers.RemoveAll(x => x.Key == key);
|
watchers.RemoveAll(x => x.Key == key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Cache<string, List<Actor>> GatherBuildables(Player player)
|
static Cache<string, List<Actor>> GatherOwnedPrerequisites(Player player)
|
||||||
{
|
{
|
||||||
var ret = new Cache<string, List<Actor>>(x => new List<Actor>());
|
var ret = new Cache<string, List<Actor>>(x => new List<Actor>());
|
||||||
if (player == null)
|
if (player == null)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
// Add buildables that provide prerequisites
|
// Add all actors that provide prerequisites
|
||||||
var prereqs = player.World.ActorsWithTrait<ITechTreePrerequisite>()
|
var prerequisites = player.World.ActorsWithTrait<ITechTreePrerequisite>()
|
||||||
.Where(a => a.Actor.Owner == player && !a.Actor.IsDead() && a.Actor.IsInWorld);
|
.Where(a => a.Actor.Owner == player && !a.Actor.IsDead() && a.Actor.IsInWorld);
|
||||||
|
|
||||||
foreach (var b in prereqs)
|
foreach (var b in prerequisites)
|
||||||
{
|
{
|
||||||
foreach (var p in b.Trait.ProvidesPrerequisites)
|
foreach (var p in b.Trait.ProvidesPrerequisites)
|
||||||
{
|
{
|
||||||
@@ -91,30 +91,54 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
public readonly string Key;
|
public readonly string Key;
|
||||||
|
|
||||||
// strings may be either actor type, or "alternate name" key
|
// Strings may be either actor type, or "alternate name" key
|
||||||
readonly string[] prerequisites;
|
readonly string[] prerequisites;
|
||||||
readonly ITechTreeElement watcher;
|
readonly ITechTreeElement watcher;
|
||||||
bool hasPrerequisites;
|
bool hasPrerequisites;
|
||||||
int buildLimit;
|
int limit;
|
||||||
|
bool hidden;
|
||||||
|
bool initialized = false;
|
||||||
|
|
||||||
public Watcher(string key, BuildableInfo info, ITechTreeElement watcher)
|
public Watcher(string key, string[] prerequisites, int limit, ITechTreeElement watcher)
|
||||||
{
|
{
|
||||||
this.Key = key;
|
this.Key = key;
|
||||||
this.prerequisites = info.Prerequisites;
|
this.prerequisites = prerequisites;
|
||||||
this.watcher = watcher;
|
this.watcher = watcher;
|
||||||
this.hasPrerequisites = false;
|
this.hasPrerequisites = false;
|
||||||
this.buildLimit = info.BuildLimit;
|
this.limit = limit;
|
||||||
|
this.hidden = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasPrerequisites(Cache<string, List<Actor>> buildables)
|
bool HasPrerequisites(Cache<string, List<Actor>> ownedPrerequisites)
|
||||||
{
|
{
|
||||||
return prerequisites.All(p => !(p.StartsWith("!") ^ !buildables.Keys.Contains(p.Replace("!", ""))));
|
return prerequisites.All(p => !(p.Replace("~", "").StartsWith("!") ^ !ownedPrerequisites.Keys.Contains(p.Replace("!", "").Replace("~", ""))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(Cache<string, List<Actor>> buildables)
|
bool IsHidden(Cache<string, List<Actor>> ownedPrerequisites)
|
||||||
{
|
{
|
||||||
var hasReachedBuildLimit = buildLimit > 0 && buildables.Keys.Contains(Key) && buildables[Key].Count >= buildLimit;
|
return prerequisites.Any(prereq => prereq.StartsWith("~") && (prereq.Replace("~", "").StartsWith("!") ^ !ownedPrerequisites.Keys.Contains(prereq.Replace("~", "").Replace("!", ""))));
|
||||||
var nowHasPrerequisites = HasPrerequisites(buildables) && !hasReachedBuildLimit;
|
}
|
||||||
|
|
||||||
|
public void Update(Cache<string, List<Actor>> ownedPrerequisites)
|
||||||
|
{
|
||||||
|
var hasReachedLimit = limit > 0 && ownedPrerequisites.Keys.Contains(Key) && ownedPrerequisites[Key].Count >= limit;
|
||||||
|
// The '!' annotation inverts prerequisites: "I'm buildable if this prerequisite *isn't* met"
|
||||||
|
var nowHasPrerequisites = HasPrerequisites(ownedPrerequisites) && !hasReachedLimit;
|
||||||
|
var nowHidden = IsHidden(ownedPrerequisites);
|
||||||
|
|
||||||
|
if (initialized == false)
|
||||||
|
{
|
||||||
|
initialized = true;
|
||||||
|
hasPrerequisites = !nowHasPrerequisites;
|
||||||
|
hidden = !nowHidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide the item from the UI if a prereq annotated with '~' is not met.
|
||||||
|
if (nowHidden && !hidden)
|
||||||
|
watcher.PrerequisitesItemHidden(Key);
|
||||||
|
|
||||||
|
if (!nowHidden && hidden)
|
||||||
|
watcher.PrerequisitesItemVisable(Key);
|
||||||
|
|
||||||
if (nowHasPrerequisites && !hasPrerequisites)
|
if (nowHasPrerequisites && !hasPrerequisites)
|
||||||
watcher.PrerequisitesAvailable(Key);
|
watcher.PrerequisitesAvailable(Key);
|
||||||
@@ -122,6 +146,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (!nowHasPrerequisites && hasPrerequisites)
|
if (!nowHasPrerequisites && hasPrerequisites)
|
||||||
watcher.PrerequisitesUnavailable(Key);
|
watcher.PrerequisitesUnavailable(Key);
|
||||||
|
|
||||||
|
hidden = nowHidden;
|
||||||
hasPrerequisites = nowHasPrerequisites;
|
hasPrerequisites = nowHasPrerequisites;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -551,6 +551,25 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
server.LobbyInfo.GlobalSettings.StartingCash = Exts.ParseIntegerInvariant(s);
|
server.LobbyInfo.GlobalSettings.StartingCash = Exts.ParseIntegerInvariant(s);
|
||||||
server.SyncLobbyGlobalSettings();
|
server.SyncLobbyGlobalSettings();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}},
|
||||||
|
{ "techlevel",
|
||||||
|
s =>
|
||||||
|
{
|
||||||
|
if (!client.IsAdmin)
|
||||||
|
{
|
||||||
|
server.SendOrderTo(conn, "Message", "Only the host can set that option");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server.Map.Options.TechLevel != null)
|
||||||
|
{
|
||||||
|
server.SendOrderTo(conn, "Message", "Map has disabled Tech configuration");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
server.LobbyInfo.GlobalSettings.TechLevel = s;
|
||||||
|
server.SyncLobbyInfo();
|
||||||
return true;
|
return true;
|
||||||
}},
|
}},
|
||||||
{ "kick",
|
{ "kick",
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
void PrerequisitesAvailable(string key);
|
void PrerequisitesAvailable(string key);
|
||||||
void PrerequisitesUnavailable(string key);
|
void PrerequisitesUnavailable(string key);
|
||||||
|
void PrerequisitesItemHidden(string key);
|
||||||
|
void PrerequisitesItemVisable(string key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ITechTreePrerequisite
|
public interface ITechTreePrerequisite
|
||||||
|
|||||||
@@ -500,7 +500,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
var prereqs = buildable.Prerequisites.Select(s => Description(world.Map.Rules, s));
|
var prereqs = buildable.Prerequisites.Select(s => Description(world.Map.Rules, s));
|
||||||
if (prereqs.Any())
|
if (prereqs.Any())
|
||||||
{
|
{
|
||||||
Game.Renderer.Fonts["Regular"].DrawText(RequiresText.F(prereqs.JoinWith(", ")), p.ToInt2(), Color.White);
|
Game.Renderer.Fonts["Regular"].DrawText(RequiresText.F(prereqs.Where(s => !s.StartsWith("~")).JoinWith(", ")), p.ToInt2(), Color.White);
|
||||||
|
|
||||||
p += new int2(0, 8);
|
p += new int2(0, 8);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -429,6 +429,34 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var techLevel = optionsBin.GetOrNull<DropDownButtonWidget>("TECHLEVEL_DROPDOWNBUTTON");
|
||||||
|
if (techLevel != null)
|
||||||
|
{
|
||||||
|
var techTraits = modRules.Actors["player"].Traits.WithInterface<ProvidesTechPrerequisiteInfo>().ToArray();
|
||||||
|
techLevel.IsVisible = () => techTraits.Length > 0;
|
||||||
|
optionsBin.GetOrNull<LabelWidget>("TECHLEVEL_DESC").IsVisible = () => techTraits.Length > 0;
|
||||||
|
techLevel.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.TechLevel != null || configurationDisabled() || techTraits.Length <= 1;
|
||||||
|
techLevel.GetText = () => Map.Status != MapStatus.Available || Map.Map.Options.TechLevel != null ? "Not Available" : "{0}".F(orderManager.LobbyInfo.GlobalSettings.TechLevel);
|
||||||
|
techLevel.OnMouseDown = _ =>
|
||||||
|
{
|
||||||
|
var options = techTraits.Select(c => new DropDownOption
|
||||||
|
{
|
||||||
|
Title = "{0}".F(c.Name),
|
||||||
|
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.TechLevel == c.Name,
|
||||||
|
OnClick = () => orderManager.IssueOrder(Order.Command("techlevel {0}".F(c.Name)))
|
||||||
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
techLevel.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var enableShroud = optionsBin.GetOrNull<CheckboxWidget>("SHROUD_CHECKBOX");
|
var enableShroud = optionsBin.GetOrNull<CheckboxWidget>("SHROUD_CHECKBOX");
|
||||||
if (enableShroud != null)
|
if (enableShroud != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user