Esempio n. 1
0
        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);

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

            return(false);
        }
Esempio n. 2
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>();
 }
Esempio n. 3
0
        public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi)
        {
            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);
        }
Esempio 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))
                };

                if (p.Trait.Produce(p.Actor, unit, type, inits))
                {
                    FinishProduction();
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 5
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);
        }