Set actor race (and icons) based on active producer.
This commit is contained in:
@@ -74,6 +74,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return isActive ? base.BuildableItems() : NoItems;
|
||||
}
|
||||
|
||||
public override TraitPair<Production> MostLikelyProducer()
|
||||
{
|
||||
return self.World.ActorsWithTrait<Production>()
|
||||
.Where(x => x.Actor.Owner == self.Owner
|
||||
&& x.Trait.Info.Produces.Contains(Info.Type))
|
||||
.OrderByDescending(x => x.Actor.IsPrimaryBuilding())
|
||||
.ThenByDescending(x => x.Actor.ActorID)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
protected override bool BuildUnit(string name)
|
||||
{
|
||||
// Find a production structure to build this actor
|
||||
@@ -97,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var p in producers.Where(p => !p.Actor.IsDisabled()))
|
||||
{
|
||||
if (p.Trait.Produce(p.Actor, ai, Race))
|
||||
if (p.Trait.Produce(p.Actor, ai, p.Trait.Race))
|
||||
{
|
||||
FinishProduction();
|
||||
return true;
|
||||
|
||||
@@ -38,6 +38,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (queue == null)
|
||||
return;
|
||||
|
||||
var producer = queue.MostLikelyProducer();
|
||||
var race = producer.Trait != null ? producer.Trait.Race : self.Owner.Country.Race;
|
||||
var buildingInfo = unit.Traits.Get<BuildingInfo>();
|
||||
|
||||
if (order.OrderString == "LineBuild")
|
||||
@@ -49,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
new LocationInit(t),
|
||||
new OwnerInit(order.Player),
|
||||
new RaceInit(queue.Race)
|
||||
new RaceInit(race)
|
||||
});
|
||||
|
||||
if (playSounds)
|
||||
@@ -69,14 +71,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
new LocationInit(order.TargetLocation),
|
||||
new OwnerInit(order.Player),
|
||||
new RaceInit(queue.Race),
|
||||
new RaceInit(race),
|
||||
});
|
||||
|
||||
foreach (var s in buildingInfo.BuildSounds)
|
||||
Sound.PlayToPlayer(order.Player, s, building.CenterPosition);
|
||||
}
|
||||
|
||||
PlayBuildAnim(self, unit);
|
||||
if (producer.Actor != null)
|
||||
foreach (var nbp in producer.Actor.TraitsImplementing<INotifyBuildingPlaced>())
|
||||
nbp.BuildingPlaced(producer.Actor);
|
||||
|
||||
queue.FinishProduction();
|
||||
|
||||
@@ -84,9 +88,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
// May be null if the build anywhere cheat is active
|
||||
// BuildingInfo.IsCloseEnoughToBase has already verified that this is a valid build location
|
||||
var producer = buildingInfo.FindBaseProvider(w, self.Owner, order.TargetLocation);
|
||||
if (producer != null)
|
||||
producer.Trait<BaseProvider>().BeginCooldown();
|
||||
var provider = buildingInfo.FindBaseProvider(w, self.Owner, order.TargetLocation);
|
||||
if (provider != null)
|
||||
provider.Trait<BaseProvider>().BeginCooldown();
|
||||
}
|
||||
|
||||
if (GetNumBuildables(self.Owner) > prevItems)
|
||||
@@ -96,30 +100,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
// finds a construction yard (or equivalent) and runs its "build" animation.
|
||||
static void PlayBuildAnim(Actor self, ActorInfo unit)
|
||||
{
|
||||
var bi = unit.Traits.GetOrDefault<BuildableInfo>();
|
||||
if (bi == null)
|
||||
return;
|
||||
|
||||
var producers = self.World.ActorsWithTrait<Production>()
|
||||
.Where(x => x.Actor.Owner == self.Owner
|
||||
&& x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Intersect(bi.Queue).Any())
|
||||
.ToList();
|
||||
var producer = producers.Where(x => x.Actor.IsPrimaryBuilding()).Concat(producers)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (producer.Actor == null)
|
||||
return;
|
||||
|
||||
foreach (var nbp in producer.Actor.TraitsImplementing<INotifyBuildingPlaced>())
|
||||
nbp.BuildingPlaced(producer.Actor);
|
||||
}
|
||||
|
||||
static int GetNumBuildables(Player p)
|
||||
{
|
||||
if (p != p.World.LocalPlayer) return 0; // this only matters for local players.
|
||||
// This only matters for local players.
|
||||
if (p != p.World.LocalPlayer)
|
||||
return 0;
|
||||
|
||||
return p.World.ActorsWithTrait<ProductionQueue>()
|
||||
.Where(a => a.Actor.Owner == p)
|
||||
|
||||
@@ -79,7 +79,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Dictionary<ActorInfo, ProductionState> produceable;
|
||||
List<ProductionItem> queue = new List<ProductionItem>();
|
||||
|
||||
// A list of things we are currently building
|
||||
public Actor Actor { get { return self; } }
|
||||
|
||||
[Sync] public int QueueLength { get { return queue.Count; } }
|
||||
@@ -361,6 +360,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
queue.Add(item);
|
||||
}
|
||||
|
||||
// Returns the actor/trait that is most likely (but not necessarily guaranteed) to produce something in this queue
|
||||
public virtual TraitPair<Production> MostLikelyProducer()
|
||||
{
|
||||
var trait = self.TraitsImplementing<Production>().FirstOrDefault(p => p.Info.Produces.Contains(Info.Type));
|
||||
return new TraitPair<Production> { Actor = self, Trait = trait };
|
||||
}
|
||||
|
||||
// Builds a unit from the actor that holds this queue (1 queue per building)
|
||||
// Returns false if the unit can't be built
|
||||
protected virtual bool BuildUnit(string name)
|
||||
|
||||
Reference in New Issue
Block a user