예제 #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))
            };

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

            return(false);
        }
예제 #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))
            };

            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);
        }
예제 #3
0
        public ArmyUnit(ActorInfo actorInfo, Player owner)
        {
            ActorInfo = actorInfo;

            var queues = owner.World.Map.Rules.Actors.Values
                         .SelectMany(a => a.TraitInfos <ProductionQueueInfo>());

            BuildableInfo = actorInfo.TraitInfoOrDefault <BuildableInfo>();
            TooltipInfo   = actorInfo.TraitInfos <TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);

            var rsi = actorInfo.TraitInfoOrDefault <RenderSpritesInfo>();

            if (BuildableInfo != null && rsi != null)
            {
                var image = rsi.GetImage(actorInfo, owner.World.Map.Rules.Sequences, owner.Faction.Name);
                Icon = new Animation(owner.World, image);
                Icon.Play(BuildableInfo.Icon);
                IconPalette = BuildableInfo.IconPalette;
                IconPaletteIsPlayerPalette = BuildableInfo.IconPaletteIsPlayerPalette;
                BuildPaletteOrder          = BuildableInfo.BuildPaletteOrder;
                ProductionQueueOrder       = queues.Where(q => BuildableInfo.Queue.Contains(q.Type))
                                             .Select(q => q.DisplayOrder)
                                             .MinByOrDefault(o => o);
            }
        }
예제 #4
0
 public ProductionItem(ProductionQueue queue, string item, int cost, PowerManager pm, Action onComplete)
 {
     Item          = item;
     RemainingTime = TotalTime = 1;
     RemainingCost = TotalCost = cost;
     OnComplete    = onComplete;
     Queue         = queue;
     this.pm       = pm;
     ai            = Queue.Actor.World.Map.Rules.Actors[Item];
     bi            = ai.TraitInfo <BuildableInfo>();
 }
예제 #5
0
        public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
        {
            if (developerMode.FastBuild)
            {
                return(0);
            }

            var time = unit.GetBuildTime() * Info.BuildSpeed / 100;

            return(time);
        }
예제 #6
0
        public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
        {
            if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait <DeveloperMode>().FastBuild)
            {
                return(0);
            }

            var time = unit.GetBuildTime() * Info.BuildSpeed / 100;

            return(time);
        }
예제 #7
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);
            }
        }
예제 #8
0
        public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi)
        {
            if (developerMode.FastBuild)
            {
                return(0);
            }

            var time = bi.BuildDuration;

            if (time == -1)
            {
                var valued = unit.TraitInfoOrDefault <ValuedInfo>();
                time = valued != null ? valued.Cost : 0;
            }

            time = time * bi.BuildDurationModifier * Info.BuildDurationModifier / 10000;
            return(time);
        }
예제 #9
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);
        }
예제 #10
0
        public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi)
        {
            if (developerMode.FastBuild)
            {
                return(0);
            }

            var time = bi.BuildDuration;

            if (time == -1)
            {
                time = GetProductionCost(unit);
            }

            var modifiers = unit.TraitInfos <IProductionTimeModifierInfo>()
                            .Select(t => t.GetProductionTimeModifier(techTree, Info.Type))
                            .Append(bi.BuildDurationModifier)
                            .Append(Info.BuildDurationModifier);

            return(Util.ApplyPercentageModifiers(time, modifiers));
        }
예제 #11
0
        public override int GetBuildTime(ActorInfo unit, BuildableInfo bi)
        {
            if (developerMode.FastBuild)
            {
                return(0);
            }

            var time = base.GetBuildTime(unit, bi);

            if (info.SpeedUp)
            {
                var type = bi.BuildAtProductionType ?? info.Type;

                var selfsameProductionsCount = self.World.ActorsWithTrait <Production>()
                                               .Count(p => !p.Trait.IsTraitDisabled && !p.Trait.IsTraitPaused && p.Actor.Owner == self.Owner && p.Trait.Info.Produces.Contains(type));

                var speedModifier = selfsameProductionsCount.Clamp(1, info.BuildTimeSpeedReduction.Length) - 1;
                time = (time * info.BuildTimeSpeedReduction[speedModifier]) / 100;
            }

            return(time);
        }
예제 #12
0
        public override int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
        {
            if (developerMode.FastBuild)
            {
                return(0);
            }

            var time = unit.GetBuildTime() * Info.BuildSpeed / 100;

            if (info.SpeedUp)
            {
                var type = (bi ?? unit.TraitInfo <BuildableInfo>()).BuildAtProductionType ?? info.Type;

                var selfsameProductionsCount = self.World.ActorsWithTrait <Production>()
                                               .Count(p => p.Actor.Owner == self.Owner && p.Trait.Info.Produces.Contains(type));

                var speedModifier = selfsameProductionsCount.Clamp(1, info.BuildTimeSpeedReduction.Length) - 1;
                time = (time * info.BuildTimeSpeedReduction[speedModifier]) / 100;
            }

            return(time);
        }
예제 #13
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);
            }
        }