Apply upgrades to units produced within range immediately.

This commit is contained in:
Paul Chote
2014-10-04 13:57:07 +13:00
parent bf2bc0c02e
commit 564a709a3a

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new UpgradeActorsNear(init.self, this); }
}
public class UpgradeActorsNear : ITick, INotifyAddedToWorld, INotifyRemovedFromWorld
public class UpgradeActorsNear : ITick, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOtherProduction
{
readonly UpgradeActorsNearInfo info;
readonly Actor self;
@@ -103,6 +103,22 @@ namespace OpenRA.Mods.RA
um.GrantUpgrade(a, u, this);
}
public void UnitProducedByOther(Actor self, Actor producer, Actor produced)
{
// Work around for actors produced within the region not triggering until the second tick
if ((produced.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= info.Range.Range * info.Range.Range)
{
var stance = self.Owner.Stances[produced.Owner];
if (!info.ValidStances.HasFlag(stance))
return;
var um = produced.TraitOrDefault<UpgradeManager>();
if (um != null)
foreach (var u in info.Upgrades)
um.GrantTimedUpgrade(produced, u, 1);
}
}
void ActorExited(Actor a)
{
if (a == self || a.Destroyed)