Add Buildable.BuildAtProduction.

This allows actors to be restricted to specific production structures.
This commit is contained in:
Paul Chote
2014-07-23 11:58:58 +12:00
parent 8837b3453c
commit c164ec8c8c
3 changed files with 12 additions and 3 deletions

View File

@@ -27,6 +27,9 @@ namespace OpenRA.Mods.RA
[Desc("Production queue(s) that can produce this.")]
public readonly string[] Queue = { };
[Desc("Override the production structure type (from the Production Produces list) that this unit should be built at.")]
public readonly string BuildAtProductionType = null;
[Desc("Disable production when there are more than this many of this actor on the battlefield. Set to 0 to disable.")]
public readonly int BuildLimit = 0;

View File

@@ -76,9 +76,15 @@ namespace OpenRA.Mods.RA
protected override bool BuildUnit(string name)
{
// Find a production structure to build this actor
var info = self.World.Map.Rules.Actors[name];
var bi = info.Traits.GetOrDefault<BuildableInfo>();
// Some units may request a specific production type, which is ignored if the AllTech cheat is enabled
var type = bi == null || developerMode.AllTech ? Info.Type : bi.BuildAtProductionType ?? Info.Type;
var producers = self.World.ActorsWithTrait<Production>()
.Where(x => x.Actor.Owner == self.Owner
&& x.Trait.Info.Produces.Contains(Info.Type))
&& x.Trait.Info.Produces.Contains(type))
.OrderByDescending(x => x.Actor.IsPrimaryBuilding())
.ThenByDescending(x => x.Actor.ActorID);
@@ -90,7 +96,7 @@ namespace OpenRA.Mods.RA
foreach (var p in producers.Where(p => !p.Actor.IsDisabled()))
{
if (p.Trait.Produce(p.Actor, self.World.Map.Rules.Actors[name], Race))
if (p.Trait.Produce(p.Actor, info, Race))
{
FinishProduction();
return true;

View File

@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA
// Will change if the owner changes
PowerManager playerPower;
PlayerResources playerResources;
DeveloperMode developerMode;
protected DeveloperMode developerMode;
// A list of things we could possibly build
Dictionary<ActorInfo, ProductionState> produceable;