Exemple #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);
        }
Exemple #2
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);
        }