Make ProduceActorPower care for PrimaryBuilding

This commit is contained in:
Mustafa Alperen Seki
2018-01-04 12:31:12 +03:00
committed by reaperrr
parent 24b7f7a23f
commit c87aa62647

View File

@@ -57,14 +57,18 @@ namespace OpenRA.Mods.Common.Traits
base.Activate(self, order, manager); base.Activate(self, order, manager);
var info = Info as ProduceActorPowerInfo; var info = Info as ProduceActorPowerInfo;
var sp = self.TraitsImplementing<Production>() var producers = self.World.ActorsWithTrait<Production>()
.FirstOrDefault(p => p.Info.Produces.Contains(info.Type)); .Where(x => x.Actor.Owner == self.Owner
&& !x.Trait.IsTraitDisabled
&& x.Trait.Info.Produces.Contains(info.Type))
.OrderByDescending(x => x.Actor.IsPrimaryBuilding())
.ThenByDescending(x => x.Actor.ActorID);
// TODO: The power should not reset if the production fails. // TODO: The power should not reset if the production fails.
// Fixing this will require a larger rework of the support power code // Fixing this will require a larger rework of the support power code
var activated = false; var activated = false;
if (sp != null) foreach (var p in producers)
{ {
foreach (var name in info.Actors) foreach (var name in info.Actors)
{ {
@@ -75,8 +79,11 @@ namespace OpenRA.Mods.Common.Traits
new FactionInit(BuildableInfo.GetInitialFaction(ai, faction)) new FactionInit(BuildableInfo.GetInitialFaction(ai, faction))
}; };
activated |= sp.Produce(self, ai, info.Type, inits); activated |= p.Trait.Produce(p.Actor, ai, info.Type, inits);
} }
if (activated)
break;
} }
if (activated) if (activated)