public static void DamageTest()
        {
            ThingDef    thingDef = ThingDef.Named("Bullet_BoltActionRifle");
            PawnKindDef slave    = PawnKindDefOf.Slave;
            Faction     faction  = FactionUtility.DefaultFactionFrom(slave.defaultFactionType);
            DamageInfo  dinfo    = new DamageInfo(thingDef.projectile.damageDef, thingDef.projectile.GetDamageAmount(null), thingDef.projectile.GetArmorPenetration(null));

            dinfo.SetIgnoreInstantKillProtection(ignore: true);
            int num  = 0;
            int num2 = 0;
            DefMap <BodyPartDef, int> defMap = new DefMap <BodyPartDef, int>();

            for (int i = 0; i < 500; i++)
            {
                Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(slave, faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: true));
                List <BodyPartDef> list = (from hd in pawn.health.hediffSet.GetMissingPartsCommonAncestors()
                                           select hd.Part.def).ToList();
                for (int j = 0; j < 2; j++)
                {
                    pawn.TakeDamage(dinfo);
                    if (pawn.Dead)
                    {
                        num++;
                        break;
                    }
                }
                List <BodyPartDef> list2 = (from hd in pawn.health.hediffSet.GetMissingPartsCommonAncestors()
                                            select hd.Part.def).ToList();
                if (list2.Count > list.Count)
                {
                    num2++;
                    foreach (BodyPartDef item in list2)
                    {
                        defMap[item]++;
                    }
                    foreach (BodyPartDef item2 in list)
                    {
                        defMap[item2]--;
                    }
                }
                Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Damage test");
            stringBuilder.AppendLine("Hit " + 500 + " " + slave.label + "s with " + 2 + "x " + thingDef.label + " (" + thingDef.projectile.GetDamageAmount(null) + " damage) each. Results:");
            stringBuilder.AppendLine("Killed: " + num + " / " + 500 + " (" + ((float)num / 500f).ToStringPercent() + ")");
            stringBuilder.AppendLine("Part losers: " + num2 + " / " + 500 + " (" + ((float)num2 / 500f).ToStringPercent() + ")");
            stringBuilder.AppendLine("Parts lost:");
            foreach (BodyPartDef allDef in DefDatabase <BodyPartDef> .AllDefs)
            {
                if (defMap[allDef] > 0)
                {
                    stringBuilder.AppendLine("   " + allDef.label + ": " + defMap[allDef]);
                }
            }
            Log.Message(stringBuilder.ToString());
        }
 public void Notify_CapacityLevelsDirty()
 {
     if (this.cachedCapacityLevels == null)
     {
         this.cachedCapacityLevels = new DefMap <PawnCapacityDef, CacheElement>();
     }
     for (int i = 0; i < this.cachedCapacityLevels.Count; i++)
     {
         this.cachedCapacityLevels[i].status = CacheStatus.Uncached;
     }
 }
Esempio n. 3
0
        public static void MakeTablePairsByThing(List <ThingStuffPair> pairList)
        {
            DefMap <ThingDef, float> totalCommMult = new DefMap <ThingDef, float>();
            DefMap <ThingDef, float> totalComm     = new DefMap <ThingDef, float>();
            DefMap <ThingDef, int>   pairCount     = new DefMap <ThingDef, int>();

            foreach (ThingStuffPair pair in pairList)
            {
                totalCommMult[pair.thing] += pair.commonalityMultiplier;
                totalComm[pair.thing]     += pair.Commonality;
                pairCount[pair.thing]++;
            }
            DebugTables.MakeTablesDialog(DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => pairList.Any((ThingStuffPair pa) => pa.thing == d)), new TableDataGetter <ThingDef>("thing", (ThingDef t) => t.defName), new TableDataGetter <ThingDef>("pair count", (ThingDef t) => pairCount[t].ToString()), new TableDataGetter <ThingDef>("total commonality multiplier ", (ThingDef t) => totalCommMult[t].ToString("F4")), new TableDataGetter <ThingDef>("total commonality", (ThingDef t) => totalComm[t].ToString("F4")), new TableDataGetter <ThingDef>("generateCommonality", (ThingDef t) => t.generateCommonality.ToString("F4")));
        }
Esempio n. 4
0
 private void UpdateRoomStatsAndRole()
 {
     statsAndRoleDirty = false;
     if (!TouchesMapEdge && RegionType == RegionType.Normal && regions.Count <= 36)
     {
         if (stats == null)
         {
             stats = new DefMap <RoomStatDef, float>();
         }
         foreach (RoomStatDef item in DefDatabase <RoomStatDef> .AllDefs.OrderByDescending((RoomStatDef x) => x.updatePriority))
         {
             stats[item] = item.Worker.GetScore(this);
         }
         role = DefDatabase <RoomRoleDef> .AllDefs.MaxBy((RoomRoleDef x) => x.Worker.GetScore(this));
     }
     else
     {
         stats = null;
         role  = RoomRoleDefOf.None;
     }
 }
Esempio n. 5
0
        public static void MakeTablePairsByThing(List <ThingStuffPair> pairList)
        {
            DefMap <ThingDef, float> totalCommMult = new DefMap <ThingDef, float>();
            DefMap <ThingDef, float> totalComm     = new DefMap <ThingDef, float>();
            DefMap <ThingDef, int>   pairCount     = new DefMap <ThingDef, int>();

            foreach (ThingStuffPair pair in pairList)
            {
                ThingStuffPair           current = pair;
                ThingDef                 thing;
                DefMap <ThingDef, float> defMap;
                (defMap = totalCommMult)[thing = current.thing] = defMap[thing] + current.commonalityMultiplier;
                ThingDef thing2;
                (defMap = totalComm)[thing2 = current.thing] = defMap[thing2] + current.Commonality;
                DefMap <ThingDef, int> defMap2;
                ThingDef thing3;
                (defMap2 = pairCount)[thing3 = current.thing] = defMap2[thing3] + 1;
            }
            DebugTables.MakeTablesDialog(from d in DefDatabase <ThingDef> .AllDefs
                                         where pairList.Any((ThingStuffPair pa) => pa.thing == d)
                                         select d, new TableDataGetter <ThingDef>("thing", (ThingDef t) => t.defName), new TableDataGetter <ThingDef>("pair count", (ThingDef t) => pairCount[t].ToString()), new TableDataGetter <ThingDef>("total commonality multiplier ", (ThingDef t) => totalCommMult[t].ToString("F4")), new TableDataGetter <ThingDef>("total commonality", (ThingDef t) => totalComm[t].ToString("F4")), new TableDataGetter <ThingDef>("generateCommonality", (ThingDef t) => t.generateCommonality.ToString("F4")));
        }
Esempio n. 6
0
 private void UpdateRoomStatsAndRole()
 {
     this.statsAndRoleDirty = false;
     if (!this.TouchesMapEdge && this.RegionType == RegionType.Normal && this.regions.Count <= 36)
     {
         if (this.stats == null)
         {
             this.stats = new DefMap <RoomStatDef, float>();
         }
         foreach (RoomStatDef current in from x in DefDatabase <RoomStatDef> .AllDefs
                  orderby x.updatePriority descending
                  select x)
         {
             this.stats[current] = current.Worker.GetScore(this);
         }
         this.role = DefDatabase <RoomRoleDef> .AllDefs.MaxBy((RoomRoleDef x) => x.Worker.GetScore(this));
     }
     else
     {
         this.stats = null;
         this.role  = RoomRoleDefOf.None;
     }
 }
Esempio n. 7
0
        public static void PawnKindGearSampled()
        {
            IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs
                                                                 where k.RaceProps.ToolUser
                                                                 orderby k.combatPower
                                                                 select k;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (PawnKindDef item2 in orderedEnumerable)
            {
                Faction         fac  = FactionUtility.DefaultFactionFrom(item2.defaultFactionType);
                PawnKindDef     kind = item2;
                FloatMenuOption item = new FloatMenuOption(kind.defName + " (" + kind.combatPower + ")", delegate
                {
                    DefMap <ThingDef, int> weapons  = new DefMap <ThingDef, int>();
                    DefMap <ThingDef, int> apparel  = new DefMap <ThingDef, int>();
                    DefMap <HediffDef, int> hediffs = new DefMap <HediffDef, int>();
                    for (int i = 0; i < 400; i++)
                    {
                        Pawn pawn = PawnGenerator.GeneratePawn(kind, fac);
                        if (pawn.equipment.Primary != null)
                        {
                            DefMap <ThingDef, int> defMap;
                            ThingDef def;
                            (defMap = weapons)[def = pawn.equipment.Primary.def] = defMap[def] + 1;
                        }
                        foreach (Hediff hediff in pawn.health.hediffSet.hediffs)
                        {
                            DefMap <HediffDef, int> defMap2;
                            HediffDef def2;
                            (defMap2 = hediffs)[def2 = hediff.def] = defMap2[def2] + 1;
                        }
                        foreach (Apparel item3 in pawn.apparel.WornApparel)
                        {
                            DefMap <ThingDef, int> defMap;
                            ThingDef def3;
                            (defMap = apparel)[def3 = item3.def] = defMap[def3] + 1;
                        }
                        pawn.Destroy();
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("Sampled " + 400 + "x " + kind.defName + ":");
                    stringBuilder.AppendLine("Weapons");
                    foreach (ThingDef item4 in from t in DefDatabase <ThingDef> .AllDefs
                             orderby weapons[t] descending
                             select t)
                    {
                        int num = weapons[item4];
                        if (num > 0)
                        {
                            stringBuilder.AppendLine("  " + item4.defName + "    " + ((float)num / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Apparel");
                    foreach (ThingDef item5 in from t in DefDatabase <ThingDef> .AllDefs
                             orderby apparel[t] descending
                             select t)
                    {
                        int num2 = apparel[item5];
                        if (num2 > 0)
                        {
                            stringBuilder.AppendLine("  " + item5.defName + "    " + ((float)num2 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Tech hediffs");
                    foreach (HediffDef item6 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved != null
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num3 = hediffs[item6];
                        if (num3 > 0)
                        {
                            stringBuilder.AppendLine("  " + item6.defName + "    " + ((float)num3 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Addiction hediffs");
                    foreach (HediffDef item7 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num4 = hediffs[item7];
                        if (num4 > 0)
                        {
                            stringBuilder.AppendLine("  " + item7.defName + "    " + ((float)num4 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Other hediffs");
                    foreach (HediffDef item8 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved == null && !h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num5 = hediffs[item8];
                        if (num5 > 0)
                        {
                            stringBuilder.AppendLine("  " + item8.defName + "    " + ((float)num5 / 400f).ToStringPercent());
                        }
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines());
                });
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
 public void Clear()
 {
     this.cachedCapacityLevels = null;
 }
Esempio n. 9
0
 public static void PawnTrainingTrackerPostLoadInit(Pawn_TrainingTracker tracker, ref DefMap <TrainableDef, bool> wantedTrainables, ref DefMap <TrainableDef, int> steps, ref DefMap <TrainableDef, bool> learned)
 {
     if (wantedTrainables == null)
     {
         wantedTrainables = new DefMap <TrainableDef, bool>();
     }
     if (steps == null)
     {
         steps = new DefMap <TrainableDef, int>();
     }
     if (learned == null)
     {
         learned = new DefMap <TrainableDef, bool>();
     }
     if (tracker.GetSteps(TrainableDefOf.Tameness) == 0 && DefDatabase <TrainableDef> .AllDefsListForReading.Any((TrainableDef td) => tracker.GetSteps(td) != 0))
     {
         tracker.Train(TrainableDefOf.Tameness, null, complete: true);
     }
     foreach (TrainableDef item in DefDatabase <TrainableDef> .AllDefsListForReading)
     {
         if (tracker.GetSteps(item) == item.steps)
         {
             tracker.Train(item, null, complete: true);
         }
     }
 }
Esempio n. 10
0
        public static void PawnKindGearSampled()
        {
            IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs
                                                                 where k.RaceProps.ToolUser
                                                                 orderby k.combatPower
                                                                 select k;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (PawnKindDef current in orderedEnumerable)
            {
                Faction         fac  = FactionUtility.DefaultFactionFrom(current.defaultFactionType);
                PawnKindDef     kind = current;
                FloatMenuOption item = new FloatMenuOption(string.Concat(new object[]
                {
                    kind.defName,
                    " (",
                    kind.combatPower,
                    ")"
                }), delegate
                {
                    DefMap <ThingDef, int> weapons  = new DefMap <ThingDef, int>();
                    DefMap <ThingDef, int> apparel  = new DefMap <ThingDef, int>();
                    DefMap <HediffDef, int> hediffs = new DefMap <HediffDef, int>();
                    for (int i = 0; i < 400; i++)
                    {
                        Pawn pawn = PawnGenerator.GeneratePawn(kind, fac);
                        if (pawn.equipment.Primary != null)
                        {
                            DefMap <ThingDef, int> defMap;
                            ThingDef def;
                            (defMap = weapons)[def = pawn.equipment.Primary.def] = defMap[def] + 1;
                        }
                        foreach (Hediff current2 in pawn.health.hediffSet.hediffs)
                        {
                            DefMap <HediffDef, int> hediffs2;
                            HediffDef def2;
                            (hediffs2 = hediffs)[def2 = current2.def] = hediffs2[def2] + 1;
                        }
                        foreach (Apparel current3 in pawn.apparel.WornApparel)
                        {
                            DefMap <ThingDef, int> defMap;
                            ThingDef def3;
                            (defMap = apparel)[def3 = current3.def] = defMap[def3] + 1;
                        }
                        pawn.Destroy(DestroyMode.Vanish);
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(string.Concat(new object[]
                    {
                        "Sampled ",
                        400,
                        "x ",
                        kind.defName,
                        ":"
                    }));
                    stringBuilder.AppendLine("Weapons");
                    foreach (ThingDef current4 in from t in DefDatabase <ThingDef> .AllDefs
                             orderby weapons[t] descending
                             select t)
                    {
                        int num = weapons[current4];
                        if (num > 0)
                        {
                            stringBuilder.AppendLine("  " + current4.defName + "    " + ((float)num / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Apparel");
                    foreach (ThingDef current5 in from t in DefDatabase <ThingDef> .AllDefs
                             orderby apparel[t] descending
                             select t)
                    {
                        int num2 = apparel[current5];
                        if (num2 > 0)
                        {
                            stringBuilder.AppendLine("  " + current5.defName + "    " + ((float)num2 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Tech hediffs");
                    foreach (HediffDef current6 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved != null
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num3 = hediffs[current6];
                        if (num3 > 0)
                        {
                            stringBuilder.AppendLine("  " + current6.defName + "    " + ((float)num3 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Addiction hediffs");
                    foreach (HediffDef current7 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num4 = hediffs[current7];
                        if (num4 > 0)
                        {
                            stringBuilder.AppendLine("  " + current7.defName + "    " + ((float)num4 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Other hediffs");
                    foreach (HediffDef current8 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved == null && !h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num5 = hediffs[current8];
                        if (num5 > 0)
                        {
                            stringBuilder.AppendLine("  " + current8.defName + "    " + ((float)num5 / 400f).ToStringPercent());
                        }
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines(), false);
                }, MenuOptionPriority.Default, null, null, 0f, null, null);
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }