Make PrimaryBuilding conditional.
This commit is contained in:
committed by
abcdefg30
parent
491f808b75
commit
ce63dd33db
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
[Desc("Used together with ClassicProductionQueue.")]
|
||||
public class PrimaryBuildingInfo : ITraitInfo
|
||||
public class PrimaryBuildingInfo : ConditionalTraitInfo
|
||||
{
|
||||
[GrantedConditionReference]
|
||||
[Desc("The condition to grant to self while this is the primary building.")]
|
||||
@@ -39,23 +39,20 @@ namespace OpenRA.Mods.Common.Traits
|
||||
"If empty, the list given in the `Produces` property of the `Production` trait will be used.")]
|
||||
public readonly string[] ProductionQueues = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new PrimaryBuilding(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new PrimaryBuilding(init.Self, this); }
|
||||
}
|
||||
|
||||
public class PrimaryBuilding : INotifyCreated, IIssueOrder, IResolveOrder
|
||||
public class PrimaryBuilding : ConditionalTrait<PrimaryBuildingInfo>, INotifyCreated, IIssueOrder, IResolveOrder
|
||||
{
|
||||
const string OrderID = "PrimaryProducer";
|
||||
|
||||
readonly PrimaryBuildingInfo info;
|
||||
ConditionManager conditionManager;
|
||||
int primaryToken = ConditionManager.InvalidConditionToken;
|
||||
|
||||
public bool IsPrimary { get; private set; }
|
||||
|
||||
public PrimaryBuilding(Actor self, PrimaryBuildingInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
: base(info) { }
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
@@ -64,7 +61,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
IEnumerable<IOrderTargeter> IIssueOrder.Orders
|
||||
{
|
||||
get { yield return new DeployOrderTargeter(OrderID, 1); }
|
||||
get
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
yield break;
|
||||
|
||||
yield return new DeployOrderTargeter(OrderID, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
@@ -90,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
// Cancel existing primaries
|
||||
// TODO: THIS IS SHIT
|
||||
var queues = info.ProductionQueues.Length == 0 ? self.Info.TraitInfo<ProductionInfo>().Produces : info.ProductionQueues;
|
||||
var queues = Info.ProductionQueues.Length == 0 ? self.Info.TraitInfos<ProductionInfo>().SelectMany(pi => pi.Produces) : Info.ProductionQueues;
|
||||
foreach (var q in queues)
|
||||
{
|
||||
foreach (var b in self.World
|
||||
@@ -99,17 +102,25 @@ namespace OpenRA.Mods.Common.Traits
|
||||
a.Actor != self &&
|
||||
a.Actor.Owner == self.Owner &&
|
||||
a.Trait.IsPrimary &&
|
||||
a.Actor.Info.TraitInfo<ProductionInfo>().Produces.Contains(q)))
|
||||
a.Actor.Info.TraitInfos<ProductionInfo>().Any(pi => pi.Produces.Contains(q))))
|
||||
b.Trait.SetPrimaryProducer(b.Actor, false);
|
||||
}
|
||||
|
||||
if (conditionManager != null && primaryToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.PrimaryCondition))
|
||||
primaryToken = conditionManager.GrantCondition(self, info.PrimaryCondition);
|
||||
if (conditionManager != null && primaryToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.PrimaryCondition))
|
||||
primaryToken = conditionManager.GrantCondition(self, Info.PrimaryCondition);
|
||||
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.SelectionNotification, self.Owner.Faction.InternalName);
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Info.SelectionNotification, self.Owner.Faction.InternalName);
|
||||
}
|
||||
else if (primaryToken != ConditionManager.InvalidConditionToken)
|
||||
primaryToken = conditionManager.RevokeCondition(self, primaryToken);
|
||||
}
|
||||
|
||||
protected override void TraitEnabled(Actor self) { }
|
||||
|
||||
protected override void TraitDisabled(Actor self)
|
||||
{
|
||||
if (IsPrimary)
|
||||
SetPrimaryProducer(self, !IsPrimary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user