private float CheapestSapperCost(Faction faction, PawnGroupKindDef groupKind)
        {
            IEnumerable <PawnGroupMaker> enumerable = PawnGenOptionsWithSappers(faction, groupKind);

            if (!enumerable.Any())
            {
                Log.Error("Tried to get MinimumPoints for " + GetType().ToString() + " for faction " + faction.ToString() + " but the faction has no groups with sappers. groupKind=" + groupKind);
                return(99999f);
            }
            float num = 9999999f;

            foreach (PawnGroupMaker item in enumerable)
            {
                foreach (PawnGenOption item2 in from op in item.options
                         where op.kind.canBeSapper
                         select op)
                {
                    if (item2.Cost < num)
                    {
                        num = item2.Cost;
                    }
                }
            }
            return(num);
        }
Пример #2
0
 public override void ResolveRaidStrategy(IncidentParms parms, PawnGroupKindDef groupKind)
 {
     if (parms.raidStrategy == null)
     {
         parms.raidStrategy = RaidStrategyDefOf.ImmediateAttackFriendly;
     }
 }
        protected override void ResolveRaidStrategy(IncidentParms parms, PawnGroupKindDef groupKind)
        {
            if (parms.raidStrategy != null)
            {
                return;
            }
            Map map = (Map)parms.target;

            if (!(from d in DefDatabase <RaidStrategyDef> .AllDefs
                  where d.Worker.CanUseWith(parms, groupKind) && (parms.raidArrivalMode != null || (d.arriveModes != null && d.arriveModes.Any((PawnsArrivalModeDef x) => x.Worker.CanUseWith(parms))))
                  select d).TryRandomElementByWeight((RaidStrategyDef d) => d.Worker.SelectionWeight(map, parms.points), out parms.raidStrategy))
            {
                Log.Error(string.Concat(new object[]
                {
                    "No raid stategy for ",
                    parms.faction,
                    " with points ",
                    parms.points,
                    ", groupKind=",
                    groupKind,
                    "\nparms=",
                    parms
                }), false);
                if (!Prefs.DevMode)
                {
                    parms.raidStrategy = RaidStrategyDefOf.ImmediateAttack;
                }
            }
        }
Пример #4
0
        private float CheapestSapperCost(Faction faction, PawnGroupKindDef groupKind)
        {
            IEnumerable <PawnGroupMaker> enumerable = this.PawnGenOptionsWithSappers(faction, groupKind);

            if (!enumerable.Any <PawnGroupMaker>())
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to get MinimumPoints for ",
                    base.GetType().ToString(),
                    " for faction ",
                    faction.ToString(),
                    " but the faction has no groups with sappers. groupKind=",
                    groupKind
                }), false);
                return(99999f);
            }
            float num = 9999999f;

            foreach (PawnGroupMaker current in enumerable)
            {
                foreach (PawnGenOption current2 in from op in current.options
                         where op.kind.canBeSapper
                         select op)
                {
                    if (current2.Cost < num)
                    {
                        num = current2.Cost;
                    }
                }
            }
            return(num);
        }
Пример #5
0
 // Token: 0x06000EC0 RID: 3776 RVA: 0x0006EA07 File Offset: 0x0006CE07
 public override void ResolveRaidStrategy(IncidentParms parms, PawnGroupKindDef groupKind)
 {
     if (parms.raidStrategy != null)
     {
         return;
     }
     parms.raidStrategy = RaidStrategyDefOf.ImmediateAttack;
 }
 public override bool CanUseWith(IncidentParms parms, PawnGroupKindDef groupKind)
 {
     if (!base.CanUseWith(parms, groupKind))
     {
         return(false);
     }
     return(parms.faction.def.canStageAttacks);
 }
 public virtual bool CanUseWith(IncidentParms parms, PawnGroupKindDef groupKind)
 {
     if (parms.points < MinimumPoints(parms.faction, groupKind))
     {
         return(false);
     }
     return(true);
 }
 public override bool CanUseWith(IncidentParms parms, PawnGroupKindDef groupKind)
 {
     if (!PawnGenOptionsWithSappers(parms.faction, groupKind).Any())
     {
         return(false);
     }
     if (!base.CanUseWith(parms, groupKind))
     {
         return(false);
     }
     return(true);
 }
 public override bool CanUseWith(IncidentParms parms, PawnGroupKindDef groupKind)
 {
     if (!base.CanUseWith(parms, groupKind))
     {
         return(false);
     }
     if (!parms.faction.def.canUseAvoidGrid)
     {
         return(false);
     }
     return(true);
 }
Пример #10
0
 public override bool CanUseWith(IncidentParms parms, PawnGroupKindDef groupKind)
 {
     if (parms.points < MinimumPoints(parms.faction, groupKind))
     {
         return(false);
     }
     if (parms.faction == Faction.OfMechanoids)
     {
         return(ModsConfig.RoyaltyActive);
     }
     return(false);
 }
Пример #11
0
        public float MinPointsToGeneratePawnGroup(PawnGroupKindDef groupKind)
        {
            if (pawnGroupMakers == null)
            {
                return(0f);
            }
            IEnumerable <PawnGroupMaker> source = pawnGroupMakers.Where((PawnGroupMaker x) => x.kindDef == groupKind);

            if (!source.Any())
            {
                return(0f);
            }
            return(source.Min((PawnGroupMaker pgm) => pgm.MinPointsToGenerateAnything));
        }
Пример #12
0
        public override void ResolveRaidStrategy(IncidentParms parms, PawnGroupKindDef groupKind)
        {
            if (parms.raidStrategy == null)
            {
                Map map = (Map)parms.target;
                DefDatabase <RaidStrategyDef> .AllDefs.Where((RaidStrategyDef d) => d.Worker.CanUseWith(parms, groupKind) && (parms.raidArrivalMode != null || (d.arriveModes != null && d.arriveModes.Any((PawnsArrivalModeDef x) => x.Worker.CanUseWith(parms))))).TryRandomElementByWeight((RaidStrategyDef d) => d.Worker.SelectionWeight(map, parms.points), out RaidStrategyDef result);

                parms.raidStrategy = result;
                if (parms.raidStrategy == null)
                {
                    Log.Error("No raid stategy found, defaulting to ImmediateAttack. Faction=" + parms.faction.def.defName + ", points=" + parms.points + ", groupKind=" + groupKind + ", parms=" + parms);
                    parms.raidStrategy = RaidStrategyDefOf.ImmediateAttack;
                }
            }
        }
Пример #13
0
        public float MinPointsToGeneratePawnGroup(PawnGroupKindDef groupKind)
        {
            if (pawnGroupMakers == null)
            {
                return(0);
            }

            var groups = pawnGroupMakers.Where(x => x.kindDef == groupKind);

            if (!groups.Any())
            {
                return(0);
            }

            return(groups.Min(pgm => pgm.MinPointsToGenerateAnything));
        }
Пример #14
0
        public float MinPointsToGeneratePawnGroup(PawnGroupKindDef groupKind)
        {
            if (this.pawnGroupMakers == null)
            {
                return(0f);
            }
            IEnumerable <PawnGroupMaker> source = from x in this.pawnGroupMakers
                                                  where x.kindDef == groupKind
                                                  select x;

            if (!source.Any <PawnGroupMaker>())
            {
                return(0f);
            }
            return(source.Min((PawnGroupMaker pgm) => pgm.MinPointsToGenerateAnything));
        }
Пример #15
0
 public static IEnumerable <Pawn> GeneratePawns(PawnGroupKindDef groupKind, PawnGroupMakerParms parms, bool warnOnZeroResults = true)
 {
     if (groupKind == null)
     {
         Log.Error("Tried to generate pawns with null pawn group kind def. parms=" + parms);
     }
     else if (parms.faction.def.pawnGroupMakers.NullOrEmpty <PawnGroupMaker>())
     {
         Log.Error(string.Concat(new object[]
         {
             "Faction ",
             parms.faction,
             " of def ",
             parms.faction.def,
             " has no any PawnGroupMakers."
         }));
     }
     else
     {
         IEnumerable <PawnGroupMaker> usableGroupMakers = from gm in parms.faction.def.pawnGroupMakers
                                                          where gm.kindDef == groupKind && gm.CanGenerateFrom(parms)
                                                          select gm;
         PawnGroupMaker chosenGroupMaker;
         if (!usableGroupMakers.TryRandomElementByWeight((PawnGroupMaker gm) => gm.commonality, out chosenGroupMaker))
         {
             Log.Error(string.Concat(new object[]
             {
                 "Faction ",
                 parms.faction,
                 " of def ",
                 parms.faction.def,
                 " has no usable PawnGroupMakers for parms ",
                 parms,
                 ". groupKind=",
                 groupKind
             }));
         }
         else
         {
             foreach (Pawn p in chosenGroupMaker.GeneratePawns(parms, warnOnZeroResults))
             {
                 yield return(p);
             }
         }
     }
 }
Пример #16
0
        public static PawnGroupMakerParms GetDefaultPawnGroupMakerParms(PawnGroupKindDef groupKind, IncidentParms parms, bool ensureCanGenerateAtLeastOnePawn = false)
        {
            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();

            pawnGroupMakerParms.groupKind            = groupKind;
            pawnGroupMakerParms.tile                 = parms.target.Tile;
            pawnGroupMakerParms.points               = parms.points;
            pawnGroupMakerParms.faction              = parms.faction;
            pawnGroupMakerParms.traderKind           = parms.traderKind;
            pawnGroupMakerParms.generateFightersOnly = parms.generateFightersOnly;
            pawnGroupMakerParms.raidStrategy         = parms.raidStrategy;
            pawnGroupMakerParms.forceOneIncap        = parms.raidForceOneIncap;
            if (ensureCanGenerateAtLeastOnePawn && parms.faction != null)
            {
                pawnGroupMakerParms.points = Mathf.Max(pawnGroupMakerParms.points, parms.faction.def.MinPointsToGeneratePawnGroup(groupKind));
            }
            return(pawnGroupMakerParms);
        }
Пример #17
0
        public static IEnumerable <Pawn> GeneratePawns(PawnGroupKindDef groupKind, PawnGroupMakerParms parms, bool warnOnZeroResults = true)
        {
            _003CGeneratePawns_003Ec__Iterator0 _003CGeneratePawns_003Ec__Iterator = (_003CGeneratePawns_003Ec__Iterator0) /*Error near IL_0034: stateMachine*/;

            if (groupKind == null)
            {
                Log.Error("Tried to generate pawns with null pawn group kind def. parms=" + parms);
            }
            else if (parms.faction.def.pawnGroupMakers.NullOrEmpty())
            {
                Log.Error("Faction " + parms.faction + " of def " + parms.faction.def + " has no any PawnGroupMakers.");
            }
            else
            {
                IEnumerable <PawnGroupMaker> usableGroupMakers = from gm in parms.faction.def.pawnGroupMakers
                                                                 where gm.kindDef == groupKind && gm.CanGenerateFrom(parms)
                                                                 select gm;
                PawnGroupMaker chosenGroupMaker;
                if (!usableGroupMakers.TryRandomElementByWeight <PawnGroupMaker>((Func <PawnGroupMaker, float>)((PawnGroupMaker gm) => gm.commonality), out chosenGroupMaker))
                {
                    Log.Error("Faction " + parms.faction + " of def " + parms.faction.def + " has no usable PawnGroupMakers for parms " + parms + ". groupKind=" + groupKind);
                }
                else
                {
                    using (IEnumerator <Pawn> enumerator = chosenGroupMaker.GeneratePawns(parms, warnOnZeroResults).GetEnumerator())
                    {
                        if (enumerator.MoveNext())
                        {
                            Pawn p = enumerator.Current;
                            yield return(p);

                            /*Error: Unable to find new state assignment for yield return*/;
                        }
                    }
                }
            }
            yield break;
IL_0293:
            /*Error near IL_0294: Unexpected return in MoveNext()*/;
        }
Пример #18
0
        public float MinPointsToGeneratePawnGroup(PawnGroupKindDef groupKind)
        {
            float result;

            if (this.pawnGroupMakers == null)
            {
                result = 0f;
            }
            else
            {
                IEnumerable <PawnGroupMaker> source = from x in this.pawnGroupMakers
                                                      where x.kindDef == groupKind
                                                      select x;
                if (!source.Any <PawnGroupMaker>())
                {
                    result = 0f;
                }
                else
                {
                    result = source.Min((PawnGroupMaker pgm) => pgm.MinPointsToGenerateAnything);
                }
            }
            return(result);
        }
Пример #19
0
 private IEnumerable <PawnGroupMaker> PawnGenOptionsWithSappers(Faction faction, PawnGroupKindDef groupKind)
 {
     if (faction.def.pawnGroupMakers == null)
     {
         return(Enumerable.Empty <PawnGroupMaker>());
     }
     return(faction.def.pawnGroupMakers.Where(delegate(PawnGroupMaker gm)
     {
         bool arg_47_0;
         if (gm.kindDef == groupKind && gm.options != null)
         {
             arg_47_0 = gm.options.Any((PawnGenOption op) => op.kind.canBeSapper);
         }
         else
         {
             arg_47_0 = false;
         }
         return arg_47_0;
     }));
 }
Пример #20
0
 public abstract void ResolveRaidStrategy(IncidentParms parms, PawnGroupKindDef groupKind);
Пример #21
0
 public static float AdjustedRaidPoints(float points, PawnsArrivalModeDef raidArrivalMode, RaidStrategyDef raidStrategy, Faction faction, PawnGroupKindDef groupKind)
 {
     if (raidArrivalMode.pointsFactorCurve != null)
     {
         points *= raidArrivalMode.pointsFactorCurve.Evaluate(points);
     }
     if (raidStrategy.pointsFactorCurve != null)
     {
         points *= raidStrategy.pointsFactorCurve.Evaluate(points);
     }
     points = Mathf.Max(points, raidStrategy.Worker.MinimumPoints(faction, groupKind) * 1.05f);
     return(points);
 }
 private IEnumerable <PawnGroupMaker> PawnGenOptionsWithSappers(Faction faction, PawnGroupKindDef groupKind)
 {
     if (faction.def.pawnGroupMakers == null)
     {
         return(Enumerable.Empty <PawnGroupMaker>());
     }
     return(faction.def.pawnGroupMakers.Where((PawnGroupMaker gm) => gm.kindDef == groupKind && gm.options != null && gm.options.Any((PawnGenOption op) => op.kind.canBeSapper)));
 }
 public override float MinMaxAllowedPawnGenOptionCost(Faction faction, PawnGroupKindDef groupKind)
 {
     return(CheapestSapperCost(faction, groupKind));
 }
 public override float MinimumPoints(Faction faction, PawnGroupKindDef groupKind)
 {
     return(Mathf.Max(base.MinimumPoints(faction, groupKind), CheapestSapperCost(faction, groupKind)));
 }
Пример #25
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            ResolveRaidPoints(parms);
            if (!TryResolveRaidFaction(parms))
            {
                return(false);
            }
            PawnGroupKindDef combat = PawnGroupKindDefOf.Combat;

            ResolveRaidStrategy(parms, combat);
            ResolveRaidArriveMode(parms);
            parms.raidStrategy.Worker.TryGenerateThreats(parms);
            if (!parms.raidArrivalMode.Worker.TryResolveRaidSpawnCenter(parms))
            {
                return(false);
            }
            float points = parms.points;

            parms.points = AdjustedRaidPoints(parms.points, parms.raidArrivalMode, parms.raidStrategy, parms.faction, combat);
            List <Pawn> list = parms.raidStrategy.Worker.SpawnThreats(parms);

            if (list == null)
            {
                list = PawnGroupMakerUtility.GeneratePawns(IncidentParmsUtility.GetDefaultPawnGroupMakerParms(combat, parms)).ToList();
                if (list.Count == 0)
                {
                    Log.Error("Got no pawns spawning raid from parms " + parms);
                    return(false);
                }
                parms.raidArrivalMode.Worker.Arrive(list, parms);
            }
            GenerateRaidLoot(parms, points, list);
            TaggedString letterLabel = GetLetterLabel(parms);
            TaggedString letterText  = GetLetterText(parms, list);

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref letterLabel, ref letterText, GetRelatedPawnsInfoLetterText(parms), informEvenIfSeenBefore: true);
            List <TargetInfo> list2 = new List <TargetInfo>();

            if (parms.pawnGroups != null)
            {
                List <List <Pawn> > list3 = IncidentParmsUtility.SplitIntoGroups(list, parms.pawnGroups);
                List <Pawn>         list4 = list3.MaxBy((List <Pawn> x) => x.Count);
                if (list4.Any())
                {
                    list2.Add(list4[0]);
                }
                for (int i = 0; i < list3.Count; i++)
                {
                    if (list3[i] != list4 && list3[i].Any())
                    {
                        list2.Add(list3[i][0]);
                    }
                }
            }
            else if (list.Any())
            {
                foreach (Pawn item in list)
                {
                    list2.Add(item);
                }
            }
            SendStandardLetter(letterLabel, letterText, GetLetterDef(), parms, list2);
            parms.raidStrategy.Worker.MakeLords(parms, list);
            LessonAutoActivator.TeachOpportunity(ConceptDefOf.EquippingWeapons, OpportunityType.Critical);
            if (!PlayerKnowledgeDatabase.IsComplete(ConceptDefOf.ShieldBelts))
            {
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j].apparel.WornApparel.Any((Apparel ap) => ap is ShieldBelt))
                    {
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.ShieldBelts, OpportunityType.Critical);
                        break;
                    }
                }
            }
            return(true);
        }
        public static float MaxPawnCost(Faction faction, float totalPoints, RaidStrategyDef raidStrategy, PawnGroupKindDef groupKind)
        {
            float num = faction.def.maxPawnCostPerTotalPointsCurve.Evaluate(totalPoints);

            if (raidStrategy != null)
            {
                num = Mathf.Min(num, totalPoints / raidStrategy.minPawns);
            }
            num = Mathf.Max(num, faction.def.MinPointsToGeneratePawnGroup(groupKind) * 1.2f);
            if (raidStrategy != null)
            {
                num = Mathf.Max(num, raidStrategy.Worker.MinMaxAllowedPawnGenOptionCost(faction, groupKind) * 1.2f);
            }
            return(num);
        }
 public virtual float MinMaxAllowedPawnGenOptionCost(Faction faction, PawnGroupKindDef groupKind)
 {
     return(0f);
 }
 public virtual float MinimumPoints(Faction faction, PawnGroupKindDef groupKind)
 {
     return(faction.def.MinPointsToGeneratePawnGroup(groupKind));
 }
 public virtual bool CanUseWith(IncidentParms parms, PawnGroupKindDef groupKind)
 {
     return(parms.points >= this.MinimumPoints(parms.faction, groupKind));
 }
Пример #30
0
 public override bool CanUseWith(IncidentParms parms, PawnGroupKindDef groupKind)
 {
     return(this.PawnGenOptionsWithSappers(parms.faction, groupKind).Any <PawnGroupMaker>() && base.CanUseWith(parms, groupKind));
 }