Skip to content

Commit

Permalink
Apply upgrades to units produced within range immediately.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Oct 4, 2014
1 parent 7970c55 commit 9990c53
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion OpenRA.Mods.RA/UpgradeActorsNear.cs
Expand Up @@ -36,7 +36,7 @@ public class UpgradeActorsNearInfo : ITraitInfo
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;
Expand Down Expand Up @@ -103,6 +103,22 @@ void ActorEntered(Actor a)
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)
Expand Down

0 comments on commit 9990c53

Please sign in to comment.