public void Produce(string actorType, string factionVariant = null, string productionType = null) { ActorInfo actorInfo; if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out actorInfo)) { throw new LuaException("Unknown actor type '{0}'".F(actorType)); } Self.QueueActivity(new WaitFor(() => { // Go through all available traits and see which one successfully produces foreach (var p in productionTraits) { if (!string.IsNullOrEmpty(productionType) && !p.Info.Produces.Contains(productionType)) { continue; } var inits = new TypeDictionary { new OwnerInit(Self.Owner), new FactionInit(factionVariant ?? BuildableInfo.GetInitialFaction(actorInfo, p.Faction)) }; if (p.Produce(Self, actorInfo, productionType, inits)) { return(true); } } // We didn't produce anything, wait until we do return(false); })); }
public override void Activate(Actor self, Order order, SupportPowerManager manager) { base.Activate(self, order, manager); var info = Info as ProduceActorPowerCAInfo; var producers = self.World.ActorsWithTrait <Production>() .Where(x => x.Actor.Owner == self.Owner && !x.Trait.IsTraitDisabled && x.Trait.Info.Produces.Contains(info.Type)) .OrderByDescending(x => x.Actor.Exits()) .ThenByDescending(x => x.Actor.ActorID); // TODO: The power should not reset if the production fails. // Fixing this will require a larger rework of the support power code var activated = false; foreach (var p in producers) { foreach (var name in info.Actors) { var ai = self.World.Map.Rules.Actors[name]; var inits = new TypeDictionary { new OwnerInit(self.Owner), new FactionInit(BuildableInfo.GetInitialFaction(ai, faction)) }; activated |= p.Trait.Produce(p.Actor, ai, info.Type, inits); } if (activated) { break; } } if (activated) { Game.Sound.PlayNotification(self.World.Map.Rules, manager.Self.Owner, "Speech", info.ReadyAudio, self.Owner.Faction.InternalName); } else { Game.Sound.PlayNotification(self.World.Map.Rules, manager.Self.Owner, "Speech", info.BlockedAudio, self.Owner.Faction.InternalName); } }
public void Produce(string actorType, string factionVariant = null, string productionType = null) { ActorInfo actorInfo; if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out actorInfo)) { throw new LuaException("Unknown actor type '{0}'".F(actorType)); } var faction = factionVariant ?? BuildableInfo.GetInitialFaction(actorInfo, p.Faction); var inits = new TypeDictionary { new OwnerInit(Self.Owner), new FactionInit(faction) }; Self.QueueActivity(new WaitFor(() => p.Produce(Self, actorInfo, productionType, inits))); }
public void UnitProducedByOther(Actor self, Actor producer, Actor produced, string productionType, TypeDictionary init) { if (IsTraitDisabled) { return; } // No recursive cloning! if (producer.Owner != self.Owner || productionType == Info.ProductionType) { return; } var ci = produced.Info.TraitInfoOrDefault <CloneableInfo>(); if (ci == null || !Info.CloneableTypes.Overlaps(ci.Types)) { return; } var factionInit = init.GetOrDefault <FactionInit>(); // Stop as soon as one production trait successfully produced foreach (var p in productionTraits) { if (!string.IsNullOrEmpty(Info.ProductionType) && !p.Info.Produces.Contains(Info.ProductionType)) { continue; } var inits = new TypeDictionary { new OwnerInit(self.Owner), factionInit ?? new FactionInit(BuildableInfo.GetInitialFaction(produced.Info, p.Faction)) }; if (p.Produce(self, produced.Info, Info.ProductionType, inits, 0)) { return; } } }
public void UnitProducedByOther(Actor self, Actor producer, Actor produced, string productionType) { // No recursive cloning! if (producer.Owner != self.Owner || producer.Info.HasTraitInfo <ClonesProducedUnitsInfo>()) { return; } var ci = produced.Info.TraitInfoOrDefault <CloneableInfo>(); if (ci == null || !info.CloneableTypes.Overlaps(ci.Types)) { return; } var inits = new TypeDictionary { new OwnerInit(self.Owner), new FactionInit(BuildableInfo.GetInitialFaction(produced.Info, faction)) }; production.Produce(self, produced.Info, productionType, inits); }