Make buildings grant prerequisites explicitly

This commit is contained in:
penev92
2015-03-30 21:08:43 +03:00
parent a310411bcc
commit 50fb6f1d25
3 changed files with 12 additions and 14 deletions

View File

@@ -19,14 +19,9 @@ namespace OpenRA.Mods.Common.Lint
{ {
public void Run(Action<string> emitError, Action<string> emitWarning, Map map) public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
{ {
// Buildings provide their actor names as a prerequisite
var buildingPrereqs = map.Rules.Actors.Where(a => a.Value.Traits.Contains<BuildingInfo>())
.Select(a => a.Key);
// ProvidesCustomPrerequisite allows arbitrary prereq definitions // ProvidesCustomPrerequisite allows arbitrary prereq definitions
var customPrereqs = map.Rules.Actors.SelectMany(a => a.Value.Traits var customPrereqs = map.Rules.Actors.SelectMany(a => a.Value.Traits
.WithInterface<ProvidesCustomPrerequisiteInfo>()) .WithInterface<ProvidesCustomPrerequisiteInfo>().Select(p => p.Prerequisite ?? a.Value.Name));
.Select(p => p.Prerequisite);
// ProvidesTechPrerequisite allows arbitrary prereq definitions // ProvidesTechPrerequisite allows arbitrary prereq definitions
// (but only one group at a time during gameplay) // (but only one group at a time during gameplay)
@@ -34,7 +29,7 @@ namespace OpenRA.Mods.Common.Lint
.WithInterface<ProvidesTechPrerequisiteInfo>()) .WithInterface<ProvidesTechPrerequisiteInfo>())
.SelectMany(p => p.Prerequisites); .SelectMany(p => p.Prerequisites);
var providedPrereqs = buildingPrereqs.Concat(customPrereqs).Concat(techPrereqs); var providedPrereqs = 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)

View File

@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public class Building : IOccupySpace, INotifySold, INotifyTransform, ISync, ITechTreePrerequisite, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld public class Building : IOccupySpace, INotifySold, INotifyTransform, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld
{ {
public readonly BuildingInfo Info; public readonly BuildingInfo Info;
public bool BuildComplete { get; private set; } public bool BuildComplete { get; private set; }
@@ -131,8 +131,6 @@ namespace OpenRA.Mods.Common.Traits
public CPos TopLeft { get { return topLeft; } } public CPos TopLeft { get { return topLeft; } }
public WPos CenterPosition { get; private set; } public WPos CenterPosition { get; private set; }
public IEnumerable<string> ProvidesPrerequisites { get { yield return self.Info.Name; } }
public Building(ActorInitializer init, BuildingInfo info) public Building(ActorInitializer init, BuildingInfo info)
{ {
this.self = init.Self; this.self = init.Self;

View File

@@ -17,13 +17,13 @@ namespace OpenRA.Mods.Common.Traits
{ {
public class ProvidesCustomPrerequisiteInfo : ITraitInfo public class ProvidesCustomPrerequisiteInfo : ITraitInfo
{ {
[Desc("The prerequisite type that this provides")] [Desc("The prerequisite type that this provides. If left empty it defaults to the actor's name.")]
public readonly string Prerequisite = null; public readonly string Prerequisite = null;
[Desc("Only grant this prerequisite when you have these prerequisites")] [Desc("Only grant this prerequisite when you have these prerequisites.")]
public readonly string[] RequiresPrerequisites = { }; public readonly string[] RequiresPrerequisites = { };
[Desc("Only grant this prerequisite for certain factions")] [Desc("Only grant this prerequisite for certain factions.")]
public readonly string[] Race = { }; public readonly string[] Race = { };
[Desc("Should it recheck everything when it is captured?")] [Desc("Should it recheck everything when it is captured?")]
@@ -34,12 +34,17 @@ namespace OpenRA.Mods.Common.Traits
public class ProvidesCustomPrerequisite : ITechTreePrerequisite, INotifyOwnerChanged public class ProvidesCustomPrerequisite : ITechTreePrerequisite, INotifyOwnerChanged
{ {
readonly ProvidesCustomPrerequisiteInfo info; readonly ProvidesCustomPrerequisiteInfo info;
readonly string prerequisite;
bool enabled = true; bool enabled = true;
public ProvidesCustomPrerequisite(ActorInitializer init, ProvidesCustomPrerequisiteInfo info) public ProvidesCustomPrerequisite(ActorInitializer init, ProvidesCustomPrerequisiteInfo info)
{ {
this.info = info; this.info = info;
prerequisite = info.Prerequisite;
if (string.IsNullOrEmpty(prerequisite))
prerequisite = init.Self.Info.Name;
var race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : init.Self.Owner.Country.Race; var race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : init.Self.Owner.Country.Race;
@@ -53,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
if (!enabled) if (!enabled)
yield break; yield break;
yield return info.Prerequisite; yield return prerequisite;
} }
} }