Added support for filtering exits by production type.

This commit is contained in:
GSonderling
2017-12-09 22:22:48 +00:00
committed by reaperrr
parent 1bf59e885d
commit 488cec64b8
16 changed files with 116 additions and 34 deletions

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
building = self.TraitOrDefault<Building>();
}
public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, TypeDictionary inits)
public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string productionType, TypeDictionary inits)
{
var exit = CPos.Zero;
var exitLocation = CPos.Zero;
@@ -113,25 +113,35 @@ namespace OpenRA.Mods.Common.Traits
var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>();
foreach (var notify in notifyOthers)
notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit);
notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType);
foreach (var t in newUnit.TraitsImplementing<INotifyBuildComplete>())
t.BuildingComplete(newUnit);
});
}
public virtual bool Produce(Actor self, ActorInfo producee, TypeDictionary inits)
protected virtual ExitInfo SelectExit(Actor self, ActorInfo producee, string productionType, Func<ExitInfo, bool> p)
{
return self.RandomExitOrDefault(productionType, p);
}
protected ExitInfo SelectExit(Actor self, ActorInfo producee, string productionType)
{
return SelectExit(self, producee, productionType, e => CanUseExit(self, producee, e));
}
public virtual bool Produce(Actor self, ActorInfo producee, string productionType, TypeDictionary inits)
{
if (Reservable.IsReserved(self) || (building != null && building.Locked))
return false;
// Pick a spawn/exit point pair
var exit = self.Info.TraitInfos<ExitInfo>().Shuffle(self.World.SharedRandom)
.FirstOrDefault(e => CanUseExit(self, producee, e));
var exit = SelectExit(self, producee, productionType);
if (exit != null || self.OccupiesSpace == null)
{
DoProduction(self, producee, exit, inits);
DoProduction(self, producee, exit, productionType, inits);
return true;
}