Ejemplo n.º 1
0
        // 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(ActorInfo unit)
        {
            var mostLikelyProducerTrait = MostLikelyProducer().Trait;

            // Cannot produce if I'm dead or trait is disabled
            if (!self.IsInWorld || self.IsDead || mostLikelyProducerTrait == null)
            {
                CancelProduction(unit.Name, 1);
                return(false);
            }

            var inits = new TypeDictionary
            {
                new OwnerInit(self.Owner),
                new FactionInit(BuildableInfo.GetInitialFaction(unit, Faction))
            };

            var bi   = unit.TraitInfo <BuildableInfo>();
            var type = developerMode.AllTech ? Info.Type : (bi.BuildAtProductionType ?? Info.Type);
            var item = Queue.First(i => i.Done && i.Item == unit.Name);

            if (!mostLikelyProducerTrait.IsTraitPaused && mostLikelyProducerTrait.Produce(self, unit, type, inits, item.TotalCost))
            {
                EndProduction(item);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        // 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(ActorInfo unit)
        {
            var mostLikelyProducerTrait = MostLikelyProducer().Trait;

            // Cannot produce if I'm dead or trait is disabled
            if (!self.IsInWorld || self.IsDead || mostLikelyProducerTrait == null)
            {
                CancelProduction(unit.Name, 1);
                return(false);
            }

            var inits = new TypeDictionary
            {
                new OwnerInit(self.Owner),
                new FactionInit(BuildableInfo.GetInitialFaction(unit, Faction))
            };

            if (!mostLikelyProducerTrait.IsTraitPaused && mostLikelyProducerTrait.Produce(self, unit, developerMode.AllTech ? null : Info.Type, inits))
            {
                FinishProduction();
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public override void Activate(Actor self, Order order, SupportPowerManager manager)
        {
            base.Activate(self, order, manager);
            PlayLaunchSounds();

            var info      = Info as ProduceActorPowerInfo;
            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.IsPrimaryBuilding())
                            .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, 0);
                }

                if (activated)
                {
                    break;
                }
            }

            if (activated)
            {
                Game.Sound.PlayNotification(self.World.Map.Rules, manager.Self.Owner, "Speech", info.ReadyAudio, self.Owner.Faction.InternalName);
                TextNotificationsManager.AddTransientLine(info.ReadyTextNotification, manager.Self.Owner);
            }
            else
            {
                Game.Sound.PlayNotification(self.World.Map.Rules, manager.Self.Owner, "Speech", info.BlockedAudio, self.Owner.Faction.InternalName);
                TextNotificationsManager.AddTransientLine(info.BlockedTextNotification, manager.Self.Owner);
            }
        }
Ejemplo n.º 4
0
        protected override bool BuildUnit(ActorInfo unit)
        {
            // Find a production structure to build this actor
            var bi = unit.TraitInfo <BuildableInfo>();

            // Some units may request a specific production type, which is ignored if the AllTech cheat is enabled
            var type = developerMode.AllTech ? Info.Type : (bi.BuildAtProductionType ?? Info.Type);

            var producers = self.World.ActorsWithTrait <Production>()
                            .Where(x => x.Actor.Owner == self.Owner &&
                                   !x.Trait.IsTraitDisabled &&
                                   x.Trait.Info.Produces.Contains(type))
                            .OrderByDescending(x => x.Actor.IsPrimaryBuilding())
                            .ThenByDescending(x => x.Actor.ActorID);

            if (!producers.Any())
            {
                CancelProduction(unit.Name, 1);
                return(false);
            }

            foreach (var p in producers)
            {
                if (p.Trait.IsTraitPaused)
                {
                    continue;
                }

                var inits = new TypeDictionary
                {
                    new OwnerInit(self.Owner),
                    new FactionInit(BuildableInfo.GetInitialFaction(unit, p.Trait.Faction))
                };

                var item = Queue.First(i => i.Done && i.Item == unit.Name);
                if (p.Trait.Produce(p.Actor, unit, type, inits, item.TotalCost))
                {
                    EndProduction(item);
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        public override void Activate(Actor self, Order order, SupportPowerManager manager)
        {
            base.Activate(self, order, manager);

            var info = Info as ProduceActorPowerInfo;
            var sp   = self.TraitsImplementing <Production>()
                       .FirstOrDefault(p => p.Info.Produces.Contains(info.Type));

            // 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;

            if (sp != null)
            {
                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 |= sp.Produce(self, ai, info.Type, inits);
                }
            }

            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);
            }
        }