Пример #1
0
        private void GenerateCarriers(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, Pawn trader, List <Thing> wares, List <Pawn> outPawns)
        {
            List <Thing> list = (from x in wares
                                 where !(x is Pawn)
                                 select x).ToList();
            int         i    = 0;
            int         num  = Mathf.CeilToInt((float)list.Count / 8f);
            PawnKindDef kind = (from x in groupMaker.carriers
                                where parms.tile == -1 || Find.WorldGrid[parms.tile].biome.IsPackAnimalAllowed(x.kind.race)
                                select x).RandomElementByWeight((PawnGenOption x) => x.selectionWeight).kind;
            List <Pawn> list2 = new List <Pawn>();

            for (int j = 0; j < num; j++)
            {
                PawnKindDef           kind2   = kind;
                Faction               faction = parms.faction;
                int                   tile    = parms.tile;
                PawnGenerationRequest request = new PawnGenerationRequest(kind2, faction, PawnGenerationContext.NonPlayer, tile, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, parms.inhabitants);
                Pawn                  pawn    = PawnGenerator.GeneratePawn(request);
                if (i < list.Count)
                {
                    pawn.inventory.innerContainer.TryAdd(list[i]);
                    i++;
                }
                list2.Add(pawn);
                outPawns.Add(pawn);
            }
            for (; i < list.Count; i++)
            {
                list2.RandomElement().inventory.innerContainer.TryAdd(list[i]);
            }
        }
 protected override void GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, List <Pawn> outPawns, bool errorOnZeroResults = true)
 {
     if (!this.CanGenerateFrom(parms, groupMaker))
     {
         if (errorOnZeroResults)
         {
             Log.Error("Cannot generate pawns for " + parms.faction + " with " + parms.points + ". Defaulting to a single random cheap group.");
         }
     }
     else
     {
         bool flag  = parms.raidStrategy == null || parms.raidStrategy.pawnsCanBringFood || (parms.faction != null && !parms.faction.HostileTo(Faction.OfPlayer));
         bool flag2 = false;
         foreach (PawnGenOption item in PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints(parms.points, groupMaker.options, parms))
         {
             PawnKindDef           kind        = item.kind;
             Faction               faction     = parms.faction;
             int                   tile        = parms.tile;
             bool                  allowFood   = flag;
             bool                  inhabitants = parms.inhabitants;
             PawnGenerationRequest request     = new PawnGenerationRequest(kind, faction, PawnGenerationContext.NonPlayer, tile, false, false, false, false, true, true, 1f, false, true, allowFood, inhabitants, false, false, false, null, null, null, null, null, null, null);
             Pawn                  pawn        = PawnGenerator.GeneratePawn(request);
             if (parms.forceOneIncap && !flag2)
             {
                 pawn.health.forceIncap           = true;
                 pawn.mindState.canFleeIndividual = false;
                 flag2 = true;
             }
             outPawns.Add(pawn);
         }
     }
 }
        private void GenerateCarriers(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, Pawn trader, List <Thing> wares, List <Pawn> outPawns)
        {
            List <Thing> list = (from x in wares
                                 where !(x is Pawn)
                                 select x).ToList <Thing>();
            int         i    = 0;
            int         num  = Mathf.CeilToInt((float)list.Count / 8f);
            PawnKindDef kind = (from x in groupMaker.carriers
                                where parms.tile == -1 || Find.WorldGrid[parms.tile].biome.IsPackAnimalAllowed(x.kind.race)
                                select x).RandomElementByWeight((PawnGenOption x) => x.selectionWeight).kind;
            List <Pawn> list2 = new List <Pawn>();

            for (int j = 0; j < num; j++)
            {
                PawnKindDef           kind2   = kind;
                Faction               faction = parms.faction;
                int                   tile    = parms.tile;
                PawnGenerationRequest request = new PawnGenerationRequest(kind2, faction, PawnGenerationContext.NonPlayer, tile, false, false, false, false, true, false, 1f, false, true, true, parms.inhabitants, false, false, false, null, null, null, null, null, null, null, null);
                Pawn                  pawn    = PawnGenerator.GeneratePawn(request);
                if (i < list.Count)
                {
                    pawn.inventory.innerContainer.TryAdd(list[i], true);
                    i++;
                }
                list2.Add(pawn);
                outPawns.Add(pawn);
            }
            while (i < list.Count)
            {
                list2.RandomElement <Pawn>().inventory.innerContainer.TryAdd(list[i], true);
                i++;
            }
        }
Пример #4
0
        public List <Pawn> GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, bool errorOnZeroResults = true)
        {
            List <Pawn> list = new List <Pawn>();

            PawnGroupKindWorker.pawnsBeingGeneratedNow.Add(list);
            try
            {
                this.GeneratePawns(parms, groupMaker, list, errorOnZeroResults);
                return(list);
            }
            catch (Exception arg)
            {
                Log.Error("Exception while generating pawn group: " + arg);
                for (int i = 0; i < list.Count; i++)
                {
                    list[i].Destroy(DestroyMode.Vanish);
                }
                list.Clear();
                return(list);
            }
            finally
            {
                PawnGroupKindWorker.pawnsBeingGeneratedNow.Remove(list);
            }
        }
 protected override void GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, List <Pawn> outPawns, bool errorOnZeroResults = true)
 {
     if (!CanGenerateFrom(parms, groupMaker))
     {
         if (errorOnZeroResults)
         {
             Log.Error("Cannot generate pawns for " + parms.faction + " with " + parms.points + ". Defaulting to a single random cheap group.");
         }
     }
     else
     {
         bool             allowFood         = parms.raidStrategy == null || parms.raidStrategy.pawnsCanBringFood || (parms.faction != null && !parms.faction.HostileTo(Faction.OfPlayer));
         Predicate <Pawn> validatorPostGear = (parms.raidStrategy != null) ? ((Predicate <Pawn>)((Pawn p) => parms.raidStrategy.Worker.CanUsePawn(p, outPawns))) : null;
         bool             flag = false;
         foreach (PawnGenOption item in PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints(parms.points, groupMaker.options, parms))
         {
             Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(item.kind, parms.faction, PawnGenerationContext.NonPlayer, parms.tile, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: true, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood, allowAddictions: true, parms.inhabitants, certainlyBeenInCryptosleep: false, forceRedressWorldPawnIfFormerColonist: false, worldPawnFactionDoesntMatter: false, 0f, null, 1f, null, validatorPostGear));
             if (parms.forceOneIncap && !flag)
             {
                 pawn.health.forceIncap           = true;
                 pawn.mindState.canFleeIndividual = false;
                 flag = true;
             }
             outPawns.Add(pawn);
         }
     }
 }
        public static bool CanGenerateAnyNormalGroup(Faction faction, float points)
        {
            bool result;

            if (faction.def.pawnGroupMakers == null)
            {
                result = false;
            }
            else
            {
                PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();
                pawnGroupMakerParms.faction = faction;
                pawnGroupMakerParms.points  = points;
                for (int i = 0; i < faction.def.pawnGroupMakers.Count; i++)
                {
                    PawnGroupMaker pawnGroupMaker = faction.def.pawnGroupMakers[i];
                    if (pawnGroupMaker.kindDef == PawnGroupKindDefOf.Combat)
                    {
                        if (pawnGroupMaker.CanGenerateFrom(pawnGroupMakerParms))
                        {
                            return(true);
                        }
                    }
                }
                result = false;
            }
            return(result);
        }
Пример #7
0
        private Pawn GenerateTrader(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, TraderKindDef traderKind)
        {
            Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(groupMaker.traders.RandomElementByWeight((PawnGenOption x) => x.selectionWeight).kind, parms.faction, PawnGenerationContext.NonPlayer, parms.tile, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, allowAddictions: true, parms.inhabitants));

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, actAsIfSpawned: true);
            pawn.trader.traderKind = traderKind;
            parms.points          -= pawn.kindDef.combatPower;
            return(pawn);
        }
 public override bool CanGenerateFrom(PawnGroupMakerParms parms, PawnGroupMaker groupMaker)
 {
     if (!base.CanGenerateFrom(parms, groupMaker))
     {
         return(false);
     }
     if (!PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints(parms.points, groupMaker.options, parms).Any())
     {
         return(false);
     }
     return(true);
 }
Пример #9
0
 public override bool CanGenerateFrom(PawnGroupMakerParms parms, PawnGroupMaker groupMaker)
 {
     if (base.CanGenerateFrom(parms, groupMaker) && groupMaker.traders.Any())
     {
         if (parms.tile != -1)
         {
             return(groupMaker.carriers.Any((PawnGenOption x) => Find.WorldGrid[parms.tile].biome.IsPackAnimalAllowed(x.kind.race)));
         }
         return(true);
     }
     return(false);
 }
Пример #10
0
        protected override void GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, List <Pawn> outPawns, bool errorOnZeroResults = true)
        {
            if (!CanGenerateFrom(parms, groupMaker))
            {
                if (errorOnZeroResults)
                {
                    Log.Error(string.Concat("Cannot generate trader caravan for ", parms.faction, "."));
                }
                return;
            }
            if (!parms.faction.def.caravanTraderKinds.Any())
            {
                Log.Error(string.Concat("Cannot generate trader caravan for ", parms.faction, " because it has no trader kinds."));
                return;
            }
            PawnGenOption pawnGenOption = groupMaker.traders.FirstOrDefault((PawnGenOption x) => !x.kind.trader);

            if (pawnGenOption != null)
            {
                Log.Error(string.Concat("Cannot generate arriving trader caravan for ", parms.faction, " because there is a pawn kind (") + pawnGenOption.kind.LabelCap + ") who is not a trader but is in a traders list.");
                return;
            }
            PawnGenOption pawnGenOption2 = groupMaker.carriers.FirstOrDefault((PawnGenOption x) => !x.kind.RaceProps.packAnimal);

            if (pawnGenOption2 != null)
            {
                Log.Error(string.Concat("Cannot generate arriving trader caravan for ", parms.faction, " because there is a pawn kind (") + pawnGenOption2.kind.LabelCap + ") who is not a carrier but is in a carriers list.");
                return;
            }
            if (parms.seed.HasValue)
            {
                Log.Warning("Deterministic seed not implemented for this pawn group kind worker. The result will be random anyway.");
            }
            TraderKindDef traderKindDef = ((parms.traderKind != null) ? parms.traderKind : parms.faction.def.caravanTraderKinds.RandomElementByWeight((TraderKindDef traderDef) => traderDef.CalculatedCommonality));
            Pawn          pawn          = GenerateTrader(parms, groupMaker, traderKindDef);

            outPawns.Add(pawn);
            ThingSetMakerParams parms2 = default(ThingSetMakerParams);

            parms2.traderDef     = traderKindDef;
            parms2.tile          = parms.tile;
            parms2.makingFaction = parms.faction;
            List <Thing> wares = ThingSetMakerDefOf.TraderStock.root.Generate(parms2).InRandomOrder().ToList();

            foreach (Pawn slavesAndAnimalsFromWare in GetSlavesAndAnimalsFromWares(parms, pawn, wares))
            {
                outPawns.Add(slavesAndAnimalsFromWare);
            }
            GenerateCarriers(parms, groupMaker, pawn, wares, outPawns);
            GenerateGuards(parms, groupMaker, pawn, wares, outPawns);
        }
        private Pawn GenerateTrader(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, TraderKindDef traderKind)
        {
            PawnKindDef           kind    = groupMaker.traders.RandomElementByWeight((PawnGenOption x) => x.selectionWeight).kind;
            Faction               faction = parms.faction;
            int                   tile    = parms.tile;
            PawnGenerationRequest request = new PawnGenerationRequest(kind, faction, PawnGenerationContext.NonPlayer, tile, false, false, false, false, true, false, 1f, false, true, true, parms.inhabitants, false, false, false, null, null, null, null, null, null, null, null);
            Pawn                  pawn    = PawnGenerator.GeneratePawn(request);

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
            pawn.trader.traderKind = traderKind;
            parms.points          -= pawn.kindDef.combatPower;
            return(pawn);
        }
            internal bool <> m__0(PawnGroupMaker gm)
            {
                bool result;

                if (gm.kindDef == this.groupKind && gm.options != null)
                {
                    result = gm.options.Any((PawnGenOption op) => op.kind.canBeSapper);
                }
                else
                {
                    result = false;
                }
                return(result);
            }
        private static bool TryGetRandomPawnGroupMaker(PawnGroupMakerParms parms, out PawnGroupMaker pawnGroupMaker)
        {
            if (parms.seed.HasValue)
            {
                Rand.PushState(parms.seed.Value);
            }
            bool result = parms.faction.def.pawnGroupMakers.Where((PawnGroupMaker gm) => gm.kindDef == parms.groupKind && gm.CanGenerateFrom(parms)).TryRandomElementByWeight((PawnGroupMaker gm) => gm.commonality, out pawnGroupMaker);

            if (parms.seed.HasValue)
            {
                Rand.PopState();
            }
            return(result);
        }
Пример #14
0
 protected override void GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, List <Pawn> outPawns, bool errorOnZeroResults = true)
 {
     if (!this.CanGenerateFrom(parms, groupMaker))
     {
         if (errorOnZeroResults)
         {
             Log.Error("Cannot generate trader caravan for " + parms.faction + ".");
         }
     }
     else if (!parms.faction.def.caravanTraderKinds.Any())
     {
         Log.Error("Cannot generate trader caravan for " + parms.faction + " because it has no trader kinds.");
     }
     else
     {
         PawnGenOption pawnGenOption = groupMaker.traders.FirstOrDefault((PawnGenOption x) => !x.kind.trader);
         if (pawnGenOption != null)
         {
             Log.Error("Cannot generate arriving trader caravan for " + parms.faction + " because there is a pawn kind (" + pawnGenOption.kind.LabelCap + ") who is not a trader but is in a traders list.");
         }
         else
         {
             PawnGenOption pawnGenOption2 = groupMaker.carriers.FirstOrDefault((PawnGenOption x) => !x.kind.RaceProps.packAnimal);
             if (pawnGenOption2 != null)
             {
                 Log.Error("Cannot generate arriving trader caravan for " + parms.faction + " because there is a pawn kind (" + pawnGenOption2.kind.LabelCap + ") who is not a carrier but is in a carriers list.");
             }
             else
             {
                 TraderKindDef traderKindDef = (parms.traderKind == null) ? parms.faction.def.caravanTraderKinds.RandomElementByWeight((TraderKindDef traderDef) => traderDef.commonality) : parms.traderKind;
                 Pawn          pawn          = this.GenerateTrader(parms, groupMaker, traderKindDef);
                 outPawns.Add(pawn);
                 ItemCollectionGeneratorParams parms2 = default(ItemCollectionGeneratorParams);
                 parms2.traderDef     = traderKindDef;
                 parms2.tile          = parms.tile;
                 parms2.traderFaction = parms.faction;
                 List <Thing> wares = ItemCollectionGeneratorDefOf.TraderStock.Worker.Generate(parms2).InRandomOrder(null).ToList();
                 foreach (Pawn slavesAndAnimalsFromWare in this.GetSlavesAndAnimalsFromWares(parms, pawn, wares))
                 {
                     outPawns.Add(slavesAndAnimalsFromWare);
                 }
                 this.GenerateCarriers(parms, groupMaker, pawn, wares, outPawns);
                 this.GenerateGuards(parms, groupMaker, pawn, wares, outPawns);
             }
         }
     }
 }
 private void GenerateGuards(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, Pawn trader, List <Thing> wares, List <Pawn> outPawns)
 {
     if (groupMaker.guards.Any <PawnGenOption>())
     {
         float points = parms.points;
         foreach (PawnGenOption pawnGenOption in PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints(points, groupMaker.guards, parms))
         {
             PawnKindDef           kind        = pawnGenOption.kind;
             Faction               faction     = parms.faction;
             int                   tile        = parms.tile;
             bool                  inhabitants = parms.inhabitants;
             PawnGenerationRequest request     = new PawnGenerationRequest(kind, faction, PawnGenerationContext.NonPlayer, tile, false, false, false, false, true, true, 1f, false, true, true, inhabitants, false, false, false, null, null, null, null, null, null, null, null);
             Pawn                  item        = PawnGenerator.GeneratePawn(request);
             outPawns.Add(item);
         }
     }
 }
        private static bool TryGetRandomPawnGroupMaker(PawnGroupMakerParms parms, out PawnGroupMaker pawnGroupMaker)
        {
            if (parms.seed != null)
            {
                Rand.PushState(parms.seed.Value);
            }
            IEnumerable <PawnGroupMaker> source = from gm in parms.faction.def.pawnGroupMakers
                                                  where gm.kindDef == parms.groupKind && gm.CanGenerateFrom(parms)
                                                  select gm;
            bool result = source.TryRandomElementByWeight((PawnGroupMaker gm) => gm.commonality, out pawnGroupMaker);

            if (parms.seed != null)
            {
                Rand.PopState();
            }
            return(result);
        }
Пример #17
0
 private void GenerateGuards(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, Pawn trader, List <Thing> wares, List <Pawn> outPawns)
 {
     if (groupMaker.guards.Any())
     {
         float points = parms.points;
         foreach (PawnGenOption item2 in PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints(points, groupMaker.guards, parms))
         {
             PawnKindDef           kind        = item2.kind;
             Faction               faction     = parms.faction;
             int                   tile        = parms.tile;
             bool                  inhabitants = parms.inhabitants;
             PawnGenerationRequest request     = new PawnGenerationRequest(kind, faction, PawnGenerationContext.NonPlayer, tile, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: true, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, inhabitants);
             Pawn                  item        = PawnGenerator.GeneratePawn(request);
             outPawns.Add(item);
         }
     }
 }
Пример #18
0
 private void GenerateGuards(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, Pawn trader, List <Thing> wares, List <Pawn> outPawns)
 {
     if (groupMaker.guards.Any())
     {
         foreach (PawnGenOption item2 in PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints(parms.points, groupMaker.guards, parms))
         {
             PawnGenerationRequest request = PawnGenerationRequest.MakeDefault();
             request.KindDef = item2.kind;
             request.Faction = parms.faction;
             request.Tile    = parms.tile;
             request.MustBeCapableOfViolence = true;
             request.Inhabitant       = parms.inhabitants;
             request.RedressValidator = ((Pawn x) => x.royalty == null || !x.royalty.AllTitlesForReading.Any());
             Pawn item = PawnGenerator.GeneratePawn(request);
             outPawns.Add(item);
         }
     }
 }
Пример #19
0
        protected override void GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, List <Pawn> outPawns, bool errorOnZeroResults = true)
        {
            if (!this.CanGenerateFrom(parms, groupMaker))
            {
                if (errorOnZeroResults)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Cannot generate pawns for ",
                        parms.faction,
                        " with ",
                        parms.points,
                        ". Defaulting to a single random cheap group."
                    }), false);
                }
                return;
            }
            bool             flag      = parms.raidStrategy == null || parms.raidStrategy.pawnsCanBringFood || (parms.faction != null && !parms.faction.HostileTo(Faction.OfPlayer));
            Predicate <Pawn> predicate = (parms.raidStrategy == null) ? null : new Predicate <Pawn>((Pawn p) => parms.raidStrategy.Worker.CanUsePawn(p, outPawns));
            bool             flag2     = false;

            foreach (PawnGenOption pawnGenOption in PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints(parms.points, groupMaker.options, parms))
            {
                PawnKindDef           kind              = pawnGenOption.kind;
                Faction               faction           = parms.faction;
                int                   tile              = parms.tile;
                bool                  allowFood         = flag;
                bool                  inhabitants       = parms.inhabitants;
                Predicate <Pawn>      validatorPostGear = predicate;
                PawnGenerationRequest request           = new PawnGenerationRequest(kind, faction, PawnGenerationContext.NonPlayer, tile, false, false, false, false, true, true, 1f, false, true, allowFood, inhabitants, false, false, false, null, validatorPostGear, null, null, null, null, null, null);
                Pawn                  pawn              = PawnGenerator.GeneratePawn(request);
                if (parms.forceOneIncap && !flag2)
                {
                    pawn.health.forceIncap           = true;
                    pawn.mindState.canFleeIndividual = false;
                    flag2 = true;
                }
                outPawns.Add(pawn);
            }
        }
 public override IEnumerable <PawnKindDef> GeneratePawnKindsExample(PawnGroupMakerParms parms, PawnGroupMaker groupMaker)
 {
     throw new NotImplementedException();
 }
 public override float MinPointsToGenerateAnything(PawnGroupMaker groupMaker)
 {
     return(0f);
 }
 public override float MinPointsToGenerateAnything(PawnGroupMaker groupMaker)
 {
     return(groupMaker.options.Where((PawnGenOption x) => x.kind.isFighter).Min((PawnGenOption g) => g.Cost));
 }
 public override IEnumerable <PawnKindDef> GeneratePawnKindsExample(PawnGroupMakerParms parms, PawnGroupMaker groupMaker)
 {
     foreach (PawnGenOption item in PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints(parms.points, groupMaker.options, parms))
     {
         yield return(item.kind);
     }
 }
 public override bool CanGenerateFrom(PawnGroupMakerParms parms, PawnGroupMaker groupMaker)
 {
     return(base.CanGenerateFrom(parms, groupMaker) && groupMaker.traders.Any <PawnGenOption>() && (parms.tile == -1 || groupMaker.carriers.Any((PawnGenOption x) => Find.WorldGrid[parms.tile].biome.IsPackAnimalAllowed(x.kind.race))));
 }
Пример #25
0
 public abstract IEnumerable <PawnKindDef> GeneratePawnKindsExample(PawnGroupMakerParms parms, PawnGroupMaker groupMaker);
Пример #26
0
 public virtual bool CanGenerateFrom(PawnGroupMakerParms parms, PawnGroupMaker groupMaker)
 {
     return(true);
 }
Пример #27
0
 protected abstract void GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, List <Pawn> outPawns, bool errorOnZeroResults = true);
Пример #28
0
 public abstract float MinPointsToGenerateAnything(PawnGroupMaker groupMaker);
 protected override void GeneratePawns(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, List <Pawn> outPawns, bool errorOnZeroResults = true)
 {
     if (!this.CanGenerateFrom(parms, groupMaker))
     {
         if (errorOnZeroResults)
         {
             Log.Error("Cannot generate trader caravan for " + parms.faction + ".", false);
         }
     }
     else if (!parms.faction.def.caravanTraderKinds.Any <TraderKindDef>())
     {
         Log.Error("Cannot generate trader caravan for " + parms.faction + " because it has no trader kinds.", false);
     }
     else
     {
         PawnGenOption pawnGenOption = groupMaker.traders.FirstOrDefault((PawnGenOption x) => !x.kind.trader);
         if (pawnGenOption != null)
         {
             Log.Error(string.Concat(new object[]
             {
                 "Cannot generate arriving trader caravan for ",
                 parms.faction,
                 " because there is a pawn kind (",
                 pawnGenOption.kind.LabelCap,
                 ") who is not a trader but is in a traders list."
             }), false);
         }
         else
         {
             PawnGenOption pawnGenOption2 = groupMaker.carriers.FirstOrDefault((PawnGenOption x) => !x.kind.RaceProps.packAnimal);
             if (pawnGenOption2 != null)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Cannot generate arriving trader caravan for ",
                     parms.faction,
                     " because there is a pawn kind (",
                     pawnGenOption2.kind.LabelCap,
                     ") who is not a carrier but is in a carriers list."
                 }), false);
             }
             else
             {
                 if (parms.seed != null)
                 {
                     Log.Warning("Deterministic seed not implemented for this pawn group kind worker. The result will be random anyway.", false);
                 }
                 TraderKindDef traderKindDef;
                 if (parms.traderKind != null)
                 {
                     traderKindDef = parms.traderKind;
                 }
                 else
                 {
                     traderKindDef = parms.faction.def.caravanTraderKinds.RandomElementByWeight((TraderKindDef traderDef) => traderDef.CalculatedCommonality);
                 }
                 TraderKindDef traderKindDef2 = traderKindDef;
                 Pawn          pawn           = this.GenerateTrader(parms, groupMaker, traderKindDef2);
                 outPawns.Add(pawn);
                 ThingSetMakerParams parms2 = default(ThingSetMakerParams);
                 parms2.traderDef     = traderKindDef2;
                 parms2.tile          = new int?(parms.tile);
                 parms2.traderFaction = parms.faction;
                 List <Thing> wares = ThingSetMakerDefOf.TraderStock.root.Generate(parms2).InRandomOrder(null).ToList <Thing>();
                 foreach (Pawn item in this.GetSlavesAndAnimalsFromWares(parms, pawn, wares))
                 {
                     outPawns.Add(item);
                 }
                 this.GenerateCarriers(parms, groupMaker, pawn, wares, outPawns);
                 this.GenerateGuards(parms, groupMaker, pawn, wares, outPawns);
             }
         }
     }
 }
 public override float MinPointsToGenerateAnything(PawnGroupMaker groupMaker)
 {
     return(groupMaker.options.Min((PawnGenOption g) => g.Cost));
 }