Merge pull request #7805 from penev92/bleed_prerequisites

Make buildings explicitly provide their names as prerequisites
This commit is contained in:
Paul Chote
2015-05-08 17:29:22 +01:00
20 changed files with 227 additions and 159 deletions

View File

@@ -19,14 +19,9 @@ namespace OpenRA.Mods.Common.Lint
{
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
// ProvidesPrerequisite allows arbitrary prereq definitions
var customPrereqs = map.Rules.Actors.SelectMany(a => a.Value.Traits
.WithInterface<ProvidesCustomPrerequisiteInfo>())
.Select(p => p.Prerequisite);
.WithInterface<ProvidesPrerequisiteInfo>().Select(p => p.Prerequisite ?? a.Value.Name));
// ProvidesTechPrerequisite allows arbitrary prereq definitions
// (but only one group at a time during gameplay)
@@ -34,7 +29,7 @@ namespace OpenRA.Mods.Common.Lint
.WithInterface<ProvidesTechPrerequisiteInfo>())
.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
foreach (var i in map.Rules.Actors)

View File

@@ -350,7 +350,7 @@
<Compile Include="Traits\Player\PlaceBuilding.cs" />
<Compile Include="Traits\Player\PlayerStatistics.cs" />
<Compile Include="Traits\Player\ProductionQueue.cs" />
<Compile Include="Traits\Player\ProvidesCustomPrerequisite.cs" />
<Compile Include="Traits\Player\ProvidesPrerequisite.cs" />
<Compile Include="Traits\Player\ProvidesTechPrerequisite.cs" />
<Compile Include="Traits\Player\StrategicVictoryConditions.cs" />
<Compile Include="Traits\Player\TechTree.cs" />

View File

@@ -17,8 +17,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The prerequisite names that must be available before this can be built.",
"This can be prefixed with ! to invert the prerequisite (disabling production if the prerequisite is available)",
"and/or ~ to hide the actor from the production palette if the prerequisite is not available.",
"Prerequisites are granted by actors with the Building trait (with a prerequisite string given by the lower case actor name)",
"and by the ProvidesCustomPrerequisite trait.")]
"Prerequisites are granted by actors with the ProvidesPrerequisite trait.")]
public readonly string[] Prerequisites = { };
[Desc("Production queue(s) that can produce this.")]

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 bool BuildComplete { get; private set; }
@@ -131,8 +131,6 @@ namespace OpenRA.Mods.Common.Traits
public CPos TopLeft { get { return topLeft; } }
public WPos CenterPosition { get; private set; }
public IEnumerable<string> ProvidesPrerequisites { get { yield return self.Info.Name; } }
public Building(ActorInitializer init, BuildingInfo info)
{
this.self = init.Self;

View File

@@ -10,36 +10,40 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
public class ProvidesCustomPrerequisiteInfo : ITraitInfo
public class ProvidesPrerequisiteInfo : 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;
[Desc("Only grant this prerequisite when you have these prerequisites")]
[Desc("Only grant this prerequisite when you have these prerequisites.")]
public readonly string[] RequiresPrerequisites = { };
[Desc("Only grant this prerequisite for certain factions")]
[Desc("Only grant this prerequisite for certain factions.")]
public readonly string[] Race = { };
[Desc("Should it recheck everything when it is captured?")]
public readonly bool ResetOnOwnerChange = false;
public object Create(ActorInitializer init) { return new ProvidesCustomPrerequisite(init, this); }
public object Create(ActorInitializer init) { return new ProvidesPrerequisite(init, this); }
}
public class ProvidesCustomPrerequisite : ITechTreePrerequisite, INotifyOwnerChanged
public class ProvidesPrerequisite : ITechTreePrerequisite, INotifyOwnerChanged
{
readonly ProvidesCustomPrerequisiteInfo info;
readonly ProvidesPrerequisiteInfo info;
readonly string prerequisite;
bool enabled = true;
public ProvidesCustomPrerequisite(ActorInitializer init, ProvidesCustomPrerequisiteInfo info)
public ProvidesPrerequisite(ActorInitializer init, ProvidesPrerequisiteInfo 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;
@@ -53,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
if (!enabled)
yield break;
yield return info.Prerequisite;
yield return prerequisite;
}
}

View File

@@ -931,6 +931,18 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
if (engineVersion < 20150504)
{
// Made buildings grant prerequisites explicitly.
if (depth == 0 && node.Value.Nodes.Exists(n => n.Key == "Inherits" &&
(n.Value.Value == "^Building" || n.Value.Value == "^BaseBuilding")))
node.Value.Nodes.Add(new MiniYamlNode("ProvidesCustomPrerequisite@buildingname", ""));
// Rename the ProvidesCustomPrerequisite trait.
if (node.Key.StartsWith("ProvidesCustomPrerequisite"))
node.Key = node.Key.Replace("ProvidesCustomPrerequisite", "ProvidesPrerequisite");
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}