示例#1
0
        public static List <Hediff> HediffsToTend(Pawn patient)
        {
            List <Hediff> toTend = new List <Hediff>();

            TendUtility.GetOptimalHediffsToTendWithSingleTreatment(patient, true, toTend);
            return(toTend);
        }
示例#2
0
 //candidate for reverse patch
 public static void WorldPawnsListTick()
 {
     while (true)
     {
         int index = Interlocked.Decrement(ref worldPawnsTicks);
         if (index < 0)
         {
             return;
         }
         Pawn pawn = worldPawnsAlive[index];
         try
         {
             pawn.Tick();
         }
         catch (Exception ex)
         {
             Log.ErrorOnce("Exception ticking world pawn " + pawn.ToStringSafe() + ". Suppressing further errors. " + ex, pawn.thingIDNumber ^ 1148571423);
         }
         try
         {
             if (!pawn.Dead && !pawn.Destroyed && (pawn.IsHashIntervalTick(7500) && !pawn.IsCaravanMember()) && !PawnUtility.IsTravelingInTransportPodWorldObject(pawn))
             {
                 TendUtility.DoTend(null, pawn, null);
             }
         }
         catch (Exception ex)
         {
             Log.ErrorOnce("Exception tending to a world pawn " + pawn.ToStringSafe() + ". Suppressing further errors. " + ex, pawn.thingIDNumber ^ 8765780);
         }
     }
 }
        public static void TryTendToRandomPawn(Caravan caravan)
        {
            CaravanTendUtility.FindPawnsNeedingTend(caravan, CaravanTendUtility.tmpPawnsNeedingTreatment);
            if (!CaravanTendUtility.tmpPawnsNeedingTreatment.Any <Pawn>())
            {
                return;
            }
            Pawn patient = CaravanTendUtility.tmpPawnsNeedingTreatment.RandomElement <Pawn>();
            Pawn pawn    = CaravanTendUtility.FindBestDoctor(caravan, patient);

            if (pawn == null)
            {
                return;
            }
            Medicine medicine = null;
            Pawn     pawn2    = null;

            CaravanInventoryUtility.TryGetBestMedicine(caravan, patient, out medicine, out pawn2);
            TendUtility.DoTend(pawn, patient, medicine);
            if (medicine != null && medicine.Destroyed && pawn2 != null)
            {
                pawn2.inventory.innerContainer.Remove(medicine);
            }
            CaravanTendUtility.tmpPawnsNeedingTreatment.Clear();
        }
示例#4
0
 public static bool AddPawn(WorldPawns __instance, Pawn p)
 {
     lock (__instance)
     {
         __instance.gc.CancelGCPass();
         if (p.Dead || p.Destroyed)
         {
             __instance.pawnsDead.Add(p);
         }
         else
         {
             try
             {
                 int num = 0;
                 while (__instance.ShouldAutoTendTo(p) && num < 30)
                 {
                     TendUtility.DoTend(null, p, null);
                     num++;
                 }
             }
             catch (Exception ex)
             {
                 Log.ErrorOnce("Exception tending to a world pawn " + p.ToStringSafe() + ". Suppressing further errors. " + ex, p.thingIDNumber ^ 0x85C154);
             }
             __instance.pawnsAlive.Add(p);
         }
         p.Notify_PassedToWorld();
     }
     return(false);
 }
        public static void TryTendToAnyPawn(Caravan caravan)
        {
            CaravanTendUtility.FindPawnsNeedingTend(caravan, CaravanTendUtility.tmpPawnsNeedingTreatment);
            if (!CaravanTendUtility.tmpPawnsNeedingTreatment.Any <Pawn>())
            {
                return;
            }
            CaravanTendUtility.tmpPawnsNeedingTreatment.SortByDescending(new Func <Pawn, float>(CaravanTendUtility.GetTendPriority));
            Pawn patient = null;
            Pawn pawn    = null;

            for (int i = 0; i < CaravanTendUtility.tmpPawnsNeedingTreatment.Count; i++)
            {
                patient = CaravanTendUtility.tmpPawnsNeedingTreatment[i];
                pawn    = CaravanTendUtility.FindBestDoctorFor(caravan, patient);
                if (pawn != null)
                {
                    break;
                }
            }
            if (pawn == null)
            {
                return;
            }
            Medicine medicine = null;
            Pawn     pawn2    = null;

            CaravanInventoryUtility.TryGetBestMedicine(caravan, patient, out medicine, out pawn2);
            TendUtility.DoTend(pawn, patient, medicine);
            if (medicine != null && medicine.Destroyed && pawn2 != null)
            {
                pawn2.inventory.innerContainer.Remove(medicine);
            }
            CaravanTendUtility.tmpPawnsNeedingTreatment.Clear();
        }
示例#6
0
 public static void TryTendToAnyPawn(Caravan caravan)
 {
     FindPawnsNeedingTend(caravan, tmpPawnsNeedingTreatment);
     if (tmpPawnsNeedingTreatment.Any())
     {
         tmpPawnsNeedingTreatment.SortByDescending(GetTendPriority);
         Pawn patient = null;
         Pawn pawn    = null;
         for (int i = 0; i < tmpPawnsNeedingTreatment.Count; i++)
         {
             patient = tmpPawnsNeedingTreatment[i];
             pawn    = FindBestDoctorFor(caravan, patient);
             if (pawn != null)
             {
                 break;
             }
         }
         if (pawn != null)
         {
             Medicine medicine = null;
             Pawn     owner    = null;
             CaravanInventoryUtility.TryGetBestMedicine(caravan, patient, out medicine, out owner);
             TendUtility.DoTend(pawn, patient, medicine);
             if (medicine != null && medicine.Destroyed)
             {
                 owner?.inventory.innerContainer.Remove(medicine);
             }
             tmpPawnsNeedingTreatment.Clear();
         }
     }
 }
示例#7
0
 private void AddPawn(Pawn p)
 {
     gc.CancelGCPass();
     if (p.Dead || p.Destroyed)
     {
         pawnsDead.Add(p);
     }
     else
     {
         try
         {
             int num = 0;
             while (ShouldAutoTendTo(p) && num < 30)
             {
                 TendUtility.DoTend(null, p, null);
                 num++;
             }
         }
         catch (Exception ex)
         {
             Log.ErrorOnce("Exception tending to a world pawn " + p.ToStringSafe() + ". Suppressing further errors. " + ex, p.thingIDNumber ^ 0x85C154);
         }
         pawnsAlive.Add(p);
     }
     p.Notify_PassedToWorld();
 }
示例#8
0
 public void WorldPawnsTick()
 {
     tmpPawnsToTick.Clear();
     tmpPawnsToTick.AddRange(pawnsAlive);
     for (int i = 0; i < tmpPawnsToTick.Count; i++)
     {
         try
         {
             tmpPawnsToTick[i].Tick();
         }
         catch (Exception ex)
         {
             Log.ErrorOnce("Exception ticking world pawn " + tmpPawnsToTick[i].ToStringSafe() + ". Suppressing further errors. " + ex, tmpPawnsToTick[i].thingIDNumber ^ 0x4475CF1F);
         }
         try
         {
             if (ShouldAutoTendTo(tmpPawnsToTick[i]))
             {
                 TendUtility.DoTend(null, tmpPawnsToTick[i], null);
             }
         }
         catch (Exception ex2)
         {
             Log.ErrorOnce("Exception tending to a world pawn " + tmpPawnsToTick[i].ToStringSafe() + ". Suppressing further errors. " + ex2, tmpPawnsToTick[i].thingIDNumber ^ 0x85C154);
         }
     }
     tmpPawnsToTick.Clear();
     if (Find.TickManager.TicksGame % 15000 == 0)
     {
         DoMothballProcessing();
     }
     tmpPawnsToRemove.Clear();
     foreach (Pawn item in pawnsDead)
     {
         if (item == null)
         {
             Log.ErrorOnce("Dead null world pawn detected, discarding.", 94424128);
             tmpPawnsToRemove.Add(item);
         }
         else if (item.Discarded)
         {
             Log.Error(string.Concat("World pawn ", item, " has been discarded while still being a world pawn. This should never happen, because discard destroy mode means that the pawn is no longer managed by anything. Pawn should have been removed from the world first."));
             tmpPawnsToRemove.Add(item);
         }
     }
     for (int j = 0; j < tmpPawnsToRemove.Count; j++)
     {
         pawnsDead.Remove(tmpPawnsToRemove[j]);
     }
     tmpPawnsToRemove.Clear();
     try
     {
         gc.WorldPawnGCTick();
     }
     catch (Exception arg)
     {
         Log.Error("Error in WorldPawnGCTick(): " + arg);
     }
 }
示例#9
0
 public static void GetOptimalHediffsToTendWithSingleTreatment(Pawn patient, bool usingMedicine, List <Hediff> outHediffsToTend, List <Hediff> tendableHediffsInTendPriorityOrder = null)
 {
     outHediffsToTend.Clear();
     tmpHediffs.Clear();
     if (tendableHediffsInTendPriorityOrder != null)
     {
         tmpHediffs.AddRange(tendableHediffsInTendPriorityOrder);
     }
     else
     {
         List <Hediff> hediffs = patient.health.hediffSet.hediffs;
         for (int i = 0; i < hediffs.Count; i++)
         {
             if (hediffs[i].TendableNow(false))
             {
                 tmpHediffs.Add(hediffs[i]);
             }
         }
         TendUtility.SortByTendPriority(tmpHediffs);
     }
     if (tmpHediffs.Any <Hediff>())
     {
         Hediff hediff = tmpHediffs[0];
         outHediffsToTend.Add(hediff);
         HediffCompProperties_TendDuration hediffCompProperties_TendDuration = hediff.def.CompProps <HediffCompProperties_TendDuration>();
         if (hediffCompProperties_TendDuration != null && hediffCompProperties_TendDuration.tendAllAtOnce)
         {
             for (int j = 0; j < tmpHediffs.Count; j++)
             {
                 if (tmpHediffs[j] != hediff && tmpHediffs[j].def == hediff.def)
                 {
                     outHediffsToTend.Add(tmpHediffs[j]);
                 }
             }
         }
         else if (hediff is Hediff_Injury && usingMedicine)
         {
             float num = hediff.Severity;
             for (int k = 0; k < tmpHediffs.Count; k++)
             {
                 if (tmpHediffs[k] != hediff)
                 {
                     Hediff_Injury hediff_Injury = tmpHediffs[k] as Hediff_Injury;
                     if (hediff_Injury != null)
                     {
                         float severity = hediff_Injury.Severity;
                         if (num + severity <= 20f)
                         {
                             num += severity;
                             outHediffsToTend.Add(hediff_Injury);
                         }
                     }
                 }
             }
         }
         tmpHediffs.Clear();
     }
 }
示例#10
0
 public void WorldPawnsTick()
 {
     WorldPawns.tmpPawnsToTick.Clear();
     WorldPawns.tmpPawnsToTick.AddRange(this.pawnsAlive);
     for (int i = 0; i < WorldPawns.tmpPawnsToTick.Count; i++)
     {
         try
         {
             WorldPawns.tmpPawnsToTick[i].Tick();
         }
         catch (Exception arg)
         {
             Log.ErrorOnce("Exception ticking world pawn: " + arg, WorldPawns.tmpPawnsToTick[i].thingIDNumber ^ 1148571423, false);
         }
         if (this.ShouldAutoTendTo(WorldPawns.tmpPawnsToTick[i]))
         {
             TendUtility.DoTend(null, WorldPawns.tmpPawnsToTick[i], null);
         }
     }
     WorldPawns.tmpPawnsToTick.Clear();
     if (Find.TickManager.TicksGame % 15000 == 0)
     {
         this.DoMothballProcessing();
     }
     WorldPawns.tmpPawnsToRemove.Clear();
     foreach (Pawn pawn in this.pawnsDead)
     {
         if (pawn == null)
         {
             Log.ErrorOnce("Dead null world pawn detected, discarding.", 94424128, false);
             WorldPawns.tmpPawnsToRemove.Add(pawn);
         }
         else if (pawn.Discarded)
         {
             Log.Error("World pawn " + pawn + " has been discarded while still being a world pawn. This should never happen, because discard destroy mode means that the pawn is no longer managed by anything. Pawn should have been removed from the world first.", false);
             WorldPawns.tmpPawnsToRemove.Add(pawn);
         }
     }
     for (int j = 0; j < WorldPawns.tmpPawnsToRemove.Count; j++)
     {
         this.pawnsDead.Remove(WorldPawns.tmpPawnsToRemove[j]);
     }
     WorldPawns.tmpPawnsToRemove.Clear();
     Profiler.BeginSample("WorldPawnGCTick");
     try
     {
         this.gc.WorldPawnGCTick();
     }
     catch (Exception arg2)
     {
         Log.Error("Error in WorldPawnGCTick(): " + arg2, false);
     }
     Profiler.EndSample();
 }
示例#11
0
        private static void GenerateInitialHediffs(Pawn pawn, PawnGenerationRequest request)
        {
            int num = 0;

            while (true)
            {
                AgeInjuryUtility.GenerateRandomOldAgeInjuries(pawn, !request.AllowDead);
                PawnTechHediffsGenerator.GenerateTechHediffsFor(pawn);
                PawnAddictionHediffsGenerator.GenerateAddictionsAndTolerancesFor(pawn);
                if (request.AllowDead && pawn.Dead)
                {
                    break;
                }
                if (request.AllowDowned || !pawn.Downed)
                {
                    break;
                }
                pawn.health.Reset();
                num++;
                if (num > 80)
                {
                    goto Block_4;
                }
            }
            goto IL_D7;
Block_4:
            Log.Warning(string.Concat(new object[]
            {
                "Could not generate old age injuries for ",
                pawn.ThingID,
                " of age ",
                pawn.ageTracker.AgeBiologicalYears,
                " that allow pawn to move after ",
                80,
                " tries. request=",
                request
            }), false);
IL_D7:
            if (!pawn.Dead && (request.Faction == null || !request.Faction.IsPlayer))
            {
                int num2 = 0;
                while (pawn.health.HasHediffsNeedingTend(false))
                {
                    num2++;
                    if (num2 > 10000)
                    {
                        Log.Error("Too many iterations.", false);
                        break;
                    }
                    TendUtility.DoTend(null, pawn, null);
                }
            }
        }
示例#12
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            Hediff hediff = pawn.health.hediffSet.hediffs.Find(x => x is Cancer && x.Part == part && x.Visible);
            Cancer cancer = hediff as Cancer;

            if (cancer == null)
            {
                return;
            }

            Thing medicine = ingredients.FirstOrDefault();
            float quality  = TendUtility.CalculateBaseTendQuality(billDoer, pawn, (medicine == null) ? null : medicine.def);

            cancer.Tended(quality, 0);
        }
示例#13
0
        private static void DoTendPrefix(Pawn doctor, Pawn patient, ref Medicine medicine, Medicine __state)
        {
            if (QOLTweaksPack.BruiseWalkingOff.Value == false)
            {
                return;
            }

            //Log.Message("tending prefix");
            if (medicine == null || doctor == null || patient == null || doctor.Faction.IsPlayer == false)
            {
                return;
            }



            List <Hediff> tmpHediffsToTend = new List <Hediff>();

            TendUtility.GetOptimalHediffsToTendWithSingleTreatment(patient, true, tmpHediffsToTend, null);

            foreach (Hediff tendable in tmpHediffsToTend)
            {
                //Log.Message("tending " + tendable.GetType().ToString());
                if (!(tendable is Hediff_Injury))
                {
                    return;
                }
                Hediff_Injury injury = (tendable as Hediff_Injury);
                if (injury.Bleeding)
                {
                    //Log.Message("is bleeding");
                    return;
                }
                if (injury.TryGetComp <HediffComp_Infecter>() != null)
                {
                    //Log.Message("has infecter");
                    return;
                }
                if (injury.TryGetComp <HediffComp_GetsOld>() != null)
                {
                    //Log.Message("has scarring");
                    return;
                }
                //Log.Message("match");
            }

            __state  = medicine;
            medicine = null;
        }
示例#14
0
 public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients)
 {
     if (billDoer != null)
     {
         if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part))
         {
             return;
         }
         TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
         {
             billDoer,
             pawn
         });
     }
     TendUtility.DoTend(billDoer, pawn, ingredients[0] as Medicine);
 }
示例#15
0
        public static bool GetMedicineCountToFullyHeal(ref int __result, Pawn pawn)
        {
            int           num  = 0;
            int           num2 = pawn.health.hediffSet.hediffs.Count + 1;
            List <Hediff> tendableHediffsInTendPriorityOrder = new List <Hediff>();
            List <Hediff> tmpHediffs = new List <Hediff>();
            //tendableHediffsInTendPriorityOrder.Clear();
            List <Hediff> hediffs = pawn.health.hediffSet.hediffs;

            for (int i = 0; i < hediffs.Count; i++)
            {
                if (hediffs[i].TendableNow())
                {
                    tendableHediffsInTendPriorityOrder.Add(hediffs[i]);
                }
            }

            TendUtility.SortByTendPriority(tendableHediffsInTendPriorityOrder);
            int num3 = 0;

            while (true)
            {
                num++;
                if (num > num2)
                {
                    Log.Error("Too many iterations.");
                    break;
                }

                TendUtility.GetOptimalHediffsToTendWithSingleTreatment(pawn, usingMedicine: true, tmpHediffs, tendableHediffsInTendPriorityOrder);
                if (!tmpHediffs.Any())
                {
                    break;
                }

                num3++;
                for (int j = 0; j < tmpHediffs.Count; j++)
                {
                    tendableHediffsInTendPriorityOrder.Remove(tmpHediffs[j]);
                }
            }

            //tmpHediffs.Clear();
            //tendableHediffsInTendPriorityOrder.Clear();
            __result = num3;
            return(false);
        }
示例#16
0
        private static void GenerateInitialHediffs(Pawn pawn, PawnGenerationRequest request)
        {
            int num = 0;

            while (true)
            {
                AgeInjuryUtility.GenerateRandomOldAgeInjuries(pawn, !request.AllowDead);
                PawnTechHediffsGenerator.GenerateTechHediffsFor(pawn);
                if (request.AllowAddictions)
                {
                    PawnAddictionHediffsGenerator.GenerateAddictionsAndTolerancesFor(pawn);
                }
                if ((request.AllowDead && pawn.Dead) || request.AllowDowned || !pawn.Downed)
                {
                    break;
                }
                pawn.health.Reset();
                num++;
                if (num > 80)
                {
                    Log.Warning("Could not generate old age injuries for " + pawn.ThingID + " of age " + pawn.ageTracker.AgeBiologicalYears + " that allow pawn to move after " + 80 + " tries. request=" + request);
                    break;
                }
            }
            if (pawn.Dead || (request.Faction != null && request.Faction.IsPlayer))
            {
                return;
            }
            int num2 = 0;

            while (true)
            {
                if (pawn.health.HasHediffsNeedingTend())
                {
                    num2++;
                    if (num2 > 10000)
                    {
                        break;
                    }
                    TendUtility.DoTend(null, pawn, null);
                    continue;
                }
                return;
            }
            Log.Error("Too many iterations.");
        }
示例#17
0
 public void WorldPawnsTick()
 {
     WorldPawns.tmpPawnsToTick.Clear();
     WorldPawns.tmpPawnsToTick.AddRange(this.pawnsAlive);
     for (int i = 0; i < WorldPawns.tmpPawnsToTick.Count; i++)
     {
         WorldPawns.tmpPawnsToTick[i].Tick();
         if (this.ShouldAutoTendTo(WorldPawns.tmpPawnsToTick[i]))
         {
             TendUtility.DoTend(null, WorldPawns.tmpPawnsToTick[i], null);
         }
     }
     WorldPawns.tmpPawnsToTick.Clear();
     if (Find.TickManager.TicksGame % 15000 == 0)
     {
         this.DoMothballProcessing();
     }
     WorldPawns.tmpPawnsToRemove.Clear();
     foreach (Pawn current in this.pawnsDead)
     {
         if (current.Discarded)
         {
             Log.Error("World pawn " + current + " has been discarded while still being a world pawn. This should never happen, because discard destroy mode means that the pawn is no longer managed by anything. Pawn should have been removed from the world first.");
             WorldPawns.tmpPawnsToRemove.Add(current);
         }
     }
     for (int j = 0; j < WorldPawns.tmpPawnsToRemove.Count; j++)
     {
         this.pawnsDead.Remove(WorldPawns.tmpPawnsToRemove[j]);
     }
     WorldPawns.tmpPawnsToRemove.Clear();
     try
     {
         this.gc.WorldPawnGCTick();
     }
     catch (Exception arg)
     {
         Log.Error("Error in WorldPawnGCTick(): " + arg);
     }
 }
            public static bool Listener(Pawn patient, ref Toil __result)
            {
                try
                {
                    if (!Settings.androidsCanOnlyBeHealedByCrafter || !patient.IsAndroidTier() && !patient.IsCyberAnimal())
                    {
                        return(true);
                    }

                    var toil = new Toil();
                    toil.initAction = delegate
                    {
                        var actor    = toil.actor;
                        var medicine = (Medicine)actor.CurJob.targetB.Thing;
                        var num      = !patient.RaceProps.Animal ? 500f : 175f;
                        var num2     = medicine?.def.MedicineTendXpGainFactor ?? 0.5f;
                        actor.skills.Learn(SkillDefOf.Crafting, num * num2);
                        TendUtility.DoTend(actor, patient, medicine);
                        if (medicine != null && medicine.Destroyed)
                        {
                            actor.CurJob.SetTarget(TargetIndex.B, LocalTargetInfo.Invalid);
                        }
                        if (toil.actor.CurJob.endAfterTendedOnce)
                        {
                            actor.jobs.EndCurrentJob(JobCondition.Succeeded);
                        }
                    };
                    toil.defaultCompleteMode = ToilCompleteMode.Instant;
                    __result = toil;

                    return(false);
                }
                catch (Exception e)
                {
                    Log.Message("[ATPP] Toils_Tend.FinalizeTend " + e.Message + " " + e.StackTrace);
                    return(true);
                }
            }
        public static void Infections()
        {
            Func <InfectionLuck, float> ilc = delegate(InfectionLuck il)
            {
                float result = 1f;
                if (il == InfectionLuck.Bad)
                {
                    result = 0.8f;
                }
                if (il == InfectionLuck.Good)
                {
                    result = 1.2f;
                }
                return(result);
            };
            Func <Func <InfectionLuck, float>, string>   stringizeWithLuck      = (Func <InfectionLuck, float> func) => $"{func(InfectionLuck.Bad):F2} / {func(InfectionLuck.Good):F2}";
            Func <HediffDef, InfectionLuck, float>       baseImmunityIncrease   = (HediffDef d, InfectionLuck il) => d.CompProps <HediffCompProperties_Immunizable>().immunityPerDaySick *ilc(il);
            Func <HediffDef, float, float>               tendedSeverityIncrease = (HediffDef d, float tend) => baseSeverityIncrease(d) + d.CompProps <HediffCompProperties_TendDuration>().severityPerDayTended *tend;
            Func <HediffDef, InfectionLuck, bool, float> immunityIncrease       = delegate(HediffDef d, InfectionLuck il, bool bedridden)
            {
                float b    = (isAnimal(d) ? 1f : ThingDefOf.Bed.GetStatValueAbstract(StatDefOf.ImmunityGainSpeedFactor));
                float num3 = Mathf.Lerp(1f, b, bedridden ? 1f : 0.3f) * StatDefOf.ImmunityGainSpeed.GetStatPart <StatPart_Resting>().factor;
                return(baseImmunityIncrease(d, il) * num3);
            };
            Func <HediffDef, InfectionLuck, float, float> immunityOnLethality = (HediffDef d, InfectionLuck il, float tend) => (tendedSeverityIncrease(d, tend) <= 0f) ? float.PositiveInfinity : (d.lethalSeverity / tendedSeverityIncrease(d, tend) * immunityIncrease(d, il, arg3: true));
            List <TableDataGetter <HediffDef> >           list = new List <TableDataGetter <HediffDef> >();

            list.Add(new TableDataGetter <HediffDef>("defName", (HediffDef d) => d.defName + (d.stages.Any((HediffStage stage) => stage.capMods.Any((PawnCapacityModifier cap) => cap.capacity == PawnCapacityDefOf.BloodFiltration)) ? " (inaccurate)" : "")));
            list.Add(new TableDataGetter <HediffDef>("lethal\nseverity", (HediffDef d) => d.lethalSeverity.ToString("F2")));
            list.Add(new TableDataGetter <HediffDef>("base\nseverity\nincrease", (HediffDef d) => baseSeverityIncrease(d).ToString("F2")));
            list.Add(new TableDataGetter <HediffDef>("base\nimmunity\nincrease", (HediffDef d) => stringizeWithLuck((InfectionLuck il) => baseImmunityIncrease(d, il))));
            List <Pawn> source = GenerateDoctorArray();

            for (float tendquality = 0f; tendquality <= 1.01f; tendquality += 0.1f)
            {
                tendquality = Mathf.Clamp01(tendquality);
                Pawn arg   = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, null) >= Mathf.Clamp01(tendquality - 0.25f));
                Pawn arg2  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineHerbal) >= Mathf.Clamp01(tendquality - 0.25f));
                Pawn arg3  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineIndustrial) >= Mathf.Clamp01(tendquality - 0.25f));
                Pawn arg4  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineUltratech) >= Mathf.Clamp01(tendquality - 0.25f));
                Pawn arg5  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, null) >= tendquality);
                Pawn arg6  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineHerbal) >= tendquality);
                Pawn arg7  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineIndustrial) >= tendquality);
                Pawn arg8  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineUltratech) >= tendquality);
                Pawn arg9  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, null) >= Mathf.Clamp01(tendquality + 0.25f));
                Pawn arg10 = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineHerbal) >= Mathf.Clamp01(tendquality + 0.25f));
                Pawn arg11 = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineIndustrial) >= Mathf.Clamp01(tendquality + 0.25f));
                Pawn arg12 = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineUltratech) >= Mathf.Clamp01(tendquality + 0.25f));
                Func <Pawn, Pawn, Pawn, string> obj = delegate(Pawn low, Pawn exp, Pawn high)
                {
                    string arg13 = ((low != null) ? low.skills.GetSkill(SkillDefOf.Medicine).Level.ToString() : "X");
                    string arg14 = ((exp != null) ? exp.skills.GetSkill(SkillDefOf.Medicine).Level.ToString() : "X");
                    string arg15 = ((high != null) ? high.skills.GetSkill(SkillDefOf.Medicine).Level.ToString() : "X");
                    return($"{arg13}-{arg14}-{arg15}");
                };
                string text  = obj(arg, arg5, arg9);
                string text2 = obj(arg2, arg6, arg10);
                string text3 = obj(arg3, arg7, arg11);
                string text4 = obj(arg4, arg8, arg12);
                float  tq    = tendquality;
                list.Add(new TableDataGetter <HediffDef>($"survival chance at\ntend quality {tq.ToStringPercent()}\n\ndoc skill needed:\nno meds:  {text}\nherbal:  {text2}\nnormal:  {text3}\nglitter:  {text4}", delegate(HediffDef d)
                {
                    float num  = immunityOnLethality(d, InfectionLuck.Bad, tq);
                    float num2 = immunityOnLethality(d, InfectionLuck.Good, tq);
                    return((num == float.PositiveInfinity) ? float.PositiveInfinity.ToString() : Mathf.Clamp01((num2 - 1f) / (num2 - num)).ToStringPercent());
                }));
            }
            DebugTables.MakeTablesDialog(InfectionList(), list.ToArray());
示例#20
0
        public static void Infections()
        {
            Func <DebugOutputsInfection.InfectionLuck, float> ilc = delegate(DebugOutputsInfection.InfectionLuck il)
            {
                float result = 1f;
                if (il == DebugOutputsInfection.InfectionLuck.Bad)
                {
                    result = 0.8f;
                }
                if (il == DebugOutputsInfection.InfectionLuck.Good)
                {
                    result = 1.2f;
                }
                return(result);
            };
            Func <Func <DebugOutputsInfection.InfectionLuck, float>, string> stringizeWithLuck = (Func <DebugOutputsInfection.InfectionLuck, float> func) => string.Format("{0:F2} / {1:F2}", func(DebugOutputsInfection.InfectionLuck.Bad), func(DebugOutputsInfection.InfectionLuck.Good));
            Func <HediffDef, bool>  isAnimal             = (HediffDef d) => d.defName.Contains("Animal");
            Func <HediffDef, float> revealSeverity       = (HediffDef d) => d.stages.First((HediffStage s) => s.becomeVisible).minSeverity;
            Func <HediffDef, float> baseSeverityIncrease = (HediffDef d) => d.CompProps <HediffCompProperties_Immunizable>().severityPerDayNotImmune;
            Func <HediffDef, DebugOutputsInfection.InfectionLuck, float> baseImmunityIncrease = (HediffDef d, DebugOutputsInfection.InfectionLuck il) => d.CompProps <HediffCompProperties_Immunizable>().immunityPerDaySick *ilc(il);
            Func <HediffDef, float, float> tendedSeverityIncrease = (HediffDef d, float tend) => baseSeverityIncrease(d) + d.CompProps <HediffCompProperties_TendDuration>().severityPerDayTended *tend;
            Func <HediffDef, DebugOutputsInfection.InfectionLuck, bool, float> immunityIncrease = delegate(HediffDef d, DebugOutputsInfection.InfectionLuck il, bool bedridden)
            {
                float b    = (!isAnimal(d)) ? ThingDefOf.Bed.GetStatValueAbstract(StatDefOf.ImmunityGainSpeedFactor, null) : 1f;
                float num  = Mathf.Lerp(1f, b, (!bedridden) ? 0.3f : 1f);
                float num2 = num * StatDefOf.ImmunityGainSpeed.GetStatPart <StatPart_Resting>().factor;
                return(baseImmunityIncrease(d, il) * num2);
            };
            Func <HediffDef, DebugOutputsInfection.InfectionLuck, float>        immunityOnReveal    = (HediffDef d, DebugOutputsInfection.InfectionLuck il) => revealSeverity(d) / baseSeverityIncrease(d) * immunityIncrease(d, il, false);
            Func <HediffDef, DebugOutputsInfection.InfectionLuck, float, float> immunityOnLethality = delegate(HediffDef d, DebugOutputsInfection.InfectionLuck il, float tend)
            {
                float result;
                if (tendedSeverityIncrease(d, tend) <= 0f)
                {
                    result = float.PositiveInfinity;
                }
                else
                {
                    result = immunityOnReveal(d, il) + (d.lethalSeverity - revealSeverity(d)) / tendedSeverityIncrease(d, tend) * immunityIncrease(d, il, true);
                }
                return(result);
            };
            List <TableDataGetter <HediffDef> > list = new List <TableDataGetter <HediffDef> >();

            list.Add(new TableDataGetter <HediffDef>("defName", (HediffDef d) => d.defName + ((!d.stages.Any((HediffStage stage) => stage.capMods.Any((PawnCapacityModifier cap) => cap.capacity == PawnCapacityDefOf.BloodFiltration))) ? "" : " (inaccurate)")));
            list.Add(new TableDataGetter <HediffDef>("lethal\nseverity", (HediffDef d) => d.lethalSeverity.ToString("F2")));
            list.Add(new TableDataGetter <HediffDef>("base\nseverity\nincrease", (HediffDef d) => baseSeverityIncrease(d).ToString("F2")));
            list.Add(new TableDataGetter <HediffDef>("base\nimmunity\nincrease", (HediffDef d) => stringizeWithLuck((DebugOutputsInfection.InfectionLuck il) => baseImmunityIncrease(d, il))));
            list.Add(new TableDataGetter <HediffDef>("immunity\non reveal", (HediffDef d) => stringizeWithLuck((DebugOutputsInfection.InfectionLuck il) => immunityOnReveal(d, il))));
            List <Pawn> source = DebugOutputsInfection.GenerateDoctorArray();
            float       tendquality;

            for (tendquality = 0f; tendquality <= 1.01f; tendquality += 0.1f)
            {
                tendquality = Mathf.Clamp01(tendquality);
                Pawn arg   = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, null) >= Mathf.Clamp01(tendquality - 0.25f), null);
                Pawn arg2  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineHerbal) >= Mathf.Clamp01(tendquality - 0.25f), null);
                Pawn arg3  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineIndustrial) >= Mathf.Clamp01(tendquality - 0.25f), null);
                Pawn arg4  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineUltratech) >= Mathf.Clamp01(tendquality - 0.25f), null);
                Pawn arg5  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, null) >= tendquality, null);
                Pawn arg6  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineHerbal) >= tendquality, null);
                Pawn arg7  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineIndustrial) >= tendquality, null);
                Pawn arg8  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineUltratech) >= tendquality, null);
                Pawn arg9  = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, null) >= Mathf.Clamp01(tendquality + 0.25f), null);
                Pawn arg10 = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineHerbal) >= Mathf.Clamp01(tendquality + 0.25f), null);
                Pawn arg11 = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineIndustrial) >= Mathf.Clamp01(tendquality + 0.25f), null);
                Pawn arg12 = source.FirstOrFallback((Pawn doc) => TendUtility.CalculateBaseTendQuality(doc, null, ThingDefOf.MedicineUltratech) >= Mathf.Clamp01(tendquality + 0.25f), null);
                Func <Pawn, Pawn, Pawn, string> func2 = delegate(Pawn low, Pawn exp, Pawn high)
                {
                    string arg13 = (low == null) ? "X" : low.skills.GetSkill(SkillDefOf.Medicine).Level.ToString();
                    string arg14 = (exp == null) ? "X" : exp.skills.GetSkill(SkillDefOf.Medicine).Level.ToString();
                    string arg15 = (high == null) ? "X" : high.skills.GetSkill(SkillDefOf.Medicine).Level.ToString();
                    return(string.Format("{0}-{1}-{2}", arg13, arg14, arg15));
                };
                string text  = func2(arg, arg5, arg9);
                string text2 = func2(arg2, arg6, arg10);
                string text3 = func2(arg3, arg7, arg11);
                string text4 = func2(arg4, arg8, arg12);
                float  tq    = tendquality;
                list.Add(new TableDataGetter <HediffDef>(string.Format("survival chance at\ntend quality {0}\n\ndoc skill needed:\nno meds:  {1}\nherbal:  {2}\nnormal:  {3}\nglitter:  {4}", new object[]
                {
                    tq.ToStringPercent(),
                    text,
                    text2,
                    text3,
                    text4
                }), delegate(HediffDef d)
                {
                    float num  = immunityOnLethality(d, DebugOutputsInfection.InfectionLuck.Bad, tq);
                    float num2 = immunityOnLethality(d, DebugOutputsInfection.InfectionLuck.Good, tq);
                    string result;
                    if (num == float.PositiveInfinity)
                    {
                        result = float.PositiveInfinity.ToString();
                    }
                    else
                    {
                        result = Mathf.Clamp01((num2 - 1f) / (num2 - num)).ToStringPercent();
                    }
                    return(result);
                }));
            }
            DebugTables.MakeTablesDialog <HediffDef>(DebugOutputsInfection.InfectionList(), list.ToArray());
        }
示例#21
0
        private static IEnumerable InfectionSimulatorWorker()
        {
            int         trials    = 2;
            List <Pawn> doctors   = DebugOutputsInfection.GenerateDoctorArray();
            List <int>  testSkill = new List <int>
            {
                4,
                10,
                16
            };
            List <ThingDef> testMedicine = new List <ThingDef>
            {
                null,
                ThingDefOf.MedicineHerbal,
                ThingDefOf.MedicineIndustrial,
                ThingDefOf.MedicineUltratech
            };
            PawnGenerationRequest pawngen = new PawnGenerationRequest(PawnKindDefOf.Colonist, Faction.OfPlayer, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
            int originalTicks             = Find.TickManager.TicksGame;
            List <DebugOutputsInfection.InfectionSimRow> results = new List <DebugOutputsInfection.InfectionSimRow>();
            int totalTests  = DebugOutputsInfection.InfectionList().Count <HediffDef>() * testMedicine.Count <ThingDef>() * testSkill.Count <int>() * trials;
            int currentTest = 0;

            foreach (HediffDef hediff in DebugOutputsInfection.InfectionList())
            {
                foreach (ThingDef meds in testMedicine)
                {
                    foreach (int skill in testSkill)
                    {
                        DebugOutputsInfection.InfectionSimRow result = default(DebugOutputsInfection.InfectionSimRow);
                        result.illness  = hediff;
                        result.skill    = skill;
                        result.medicine = meds;
                        Pawn doctor = doctors[skill];
                        for (int i = 0; i < trials; i++)
                        {
                            Pawn patient    = PawnGenerator.GeneratePawn(pawngen);
                            int  startTicks = Find.TickManager.TicksGame;
                            patient.health.AddHediff(result.illness, null, null, null);
                            Hediff activeHediff = patient.health.hediffSet.GetFirstHediffOfDef(result.illness, false);
                            while (!patient.Dead && patient.health.hediffSet.HasHediff(result.illness, false))
                            {
                                if (activeHediff.TendableNow(false))
                                {
                                    activeHediff.Tended(TendUtility.CalculateBaseTendQuality(doctor, patient, meds), 0);
                                    result.medicineUsed += 1f;
                                }
                                foreach (Hediff hediff2 in patient.health.hediffSet.GetHediffsTendable())
                                {
                                    hediff2.Tended(TendUtility.CalculateBaseTendQuality(doctor, patient, meds), 0);
                                }
                                Find.TickManager.DebugSetTicksGame(Find.TickManager.TicksGame + 1);
                                patient.health.HealthTick();
                                if (Find.TickManager.TicksGame % 900 == 0)
                                {
                                    yield return(null);
                                }
                            }
                            if (patient.Dead)
                            {
                                result.deathChance += 1f;
                            }
                            else
                            {
                                result.recoveryTimeDays += (Find.TickManager.TicksGame - startTicks).TicksToDays();
                            }
                            currentTest++;
                            LongEventHandler.SetCurrentEventText(string.Format("Simulating ({0}/{1})", currentTest, totalTests));
                            yield return(null);
                        }
                        result.recoveryTimeDays /= (float)trials - result.deathChance;
                        result.deathChance      /= (float)trials;
                        result.medicineUsed     /= (float)trials;
                        results.Add(result);
                    }
                }
            }
            IEnumerable <DebugOutputsInfection.InfectionSimRow> dataSources = results;

            TableDataGetter <DebugOutputsInfection.InfectionSimRow>[] array = new TableDataGetter <DebugOutputsInfection.InfectionSimRow> [6];
            array[0] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("defName", (DebugOutputsInfection.InfectionSimRow isr) => isr.illness.defName);
            array[1] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("meds", (DebugOutputsInfection.InfectionSimRow isr) => (isr.medicine == null) ? "(none)" : isr.medicine.defName);
            array[2] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("skill", (DebugOutputsInfection.InfectionSimRow isr) => isr.skill.ToString());
            array[3] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("death chance", (DebugOutputsInfection.InfectionSimRow isr) => isr.deathChance.ToStringPercent());
            array[4] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("recovery time (days)", (DebugOutputsInfection.InfectionSimRow isr) => isr.recoveryTimeDays.ToString("F1"));
            array[5] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("medicine used", (DebugOutputsInfection.InfectionSimRow isr) => isr.medicineUsed.ToString());
            DebugTables.MakeTablesDialog <DebugOutputsInfection.InfectionSimRow>(dataSources, array);
            Find.TickManager.DebugSetTicksGame(originalTicks);
            yield break;
        }
示例#22
0
        private static void ExecuteTicks()
        {
            if (mapPreTickComplete && plantMaterialsCount > 0)
            {
                int index = Interlocked.Decrement(ref plantMaterialsCount);
                while (index >= 0)
                {
                    try
                    {
                        WindManager_Patch.plantMaterials[index].SetFloat(ShaderPropertyIDs.SwayHead, plantSwayHead);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Exception ticking " + WindManager_Patch.plantMaterials[index].ToStringSafe() + ": " + ex);
                    }
                    index = Interlocked.Decrement(ref plantMaterialsCount);
                }
                if (index == -1)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }

            else if (tickListNormalComplete && thingListNormalTicks > 0)
            {
                int index = Interlocked.Decrement(ref thingListNormalTicks);
                while (index >= 0)
                {
                    Thing thing = thingListNormal[index];
                    if (!thing.Destroyed)
                    {
                        try
                        {
                            thing.Tick();
                        }
                        catch (Exception ex)
                        {
                            string text = thing.Spawned ? (" (at " + thing.Position + ")") : "";
                            if (Prefs.DevMode)
                            {
                                Log.Error("Exception ticking " + thing.ToStringSafe() + text + ": " + ex);
                            }
                            else
                            {
                                Log.ErrorOnce("Exception ticking " + thing.ToStringSafe() + text + ". Suppressing further errors. Exception: " + ex, thing.thingIDNumber ^ 0x22627165);
                            }
                        }
                    }
                    index = Interlocked.Decrement(ref thingListNormalTicks);
                }
                if (index == -1)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }
            else if (tickListRareComplete && thingListRareTicks > 0)
            {
                int index = Interlocked.Decrement(ref thingListRareTicks);
                while (index >= 0)
                {
                    Thing thing = thingListRare[index];
                    if (!thing.Destroyed)
                    {
                        try
                        {
                            thing.TickRare();
                        }
                        catch (Exception ex)
                        {
                            string text = thing.Spawned ? (" (at " + thing.Position + ")") : "";
                            if (Prefs.DevMode)
                            {
                                Log.Error("Exception ticking " + thing.ToStringSafe() + text + ": " + ex);
                            }
                            else
                            {
                                Log.ErrorOnce("Exception ticking " + thing.ToStringSafe() + text + ". Suppressing further errors. Exception: " + ex, thing.thingIDNumber ^ 0x22627165);
                            }
                        }
                    }
                    index = Interlocked.Decrement(ref thingListRareTicks);
                }
                if (index == -1)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }
            else if (tickListLongComplete && thingListLongTicks > 0)
            {
                int index = Interlocked.Decrement(ref thingListLongTicks);
                while (index >= 0)
                {
                    Thing thing = thingListLong[index];
                    if (!thing.Destroyed)
                    {
                        try
                        {
                            thing.TickLong();
                        }
                        catch (Exception ex)
                        {
                            string text = thing.Spawned ? (" (at " + thing.Position + ")") : "";
                            if (Prefs.DevMode)
                            {
                                Log.Error("Exception ticking " + thing.ToStringSafe() + text + ": " + ex);
                            }
                            else
                            {
                                Log.ErrorOnce("Exception ticking " + thing.ToStringSafe() + text + ". Suppressing further errors. Exception: " + ex, thing.thingIDNumber ^ 0x22627165);
                            }
                        }
                    }
                    index = Interlocked.Decrement(ref thingListLongTicks);
                }
                if (index == -1)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }
            else if (worldTickComplete && worldPawnsTicks > 0)
            {
                int index = Interlocked.Decrement(ref worldPawnsTicks);
                while (index >= 0)
                {
                    Pawn pawn = worldPawnsAlive[index];
                    try
                    {
                        pawn.Tick();
                    }
                    catch (Exception ex)
                    {
                        Log.ErrorOnce("Exception ticking world pawn " + pawn.ToStringSafe() + ". Suppressing further errors. " + (object)ex, pawn.thingIDNumber ^ 1148571423, false);
                    }
                    try
                    {
                        if (!pawn.Dead && !pawn.Destroyed && (pawn.IsHashIntervalTick(7500) && !pawn.IsCaravanMember()) && !PawnUtility.IsTravelingInTransportPodWorldObject(pawn))
                        {
                            TendUtility.DoTend(null, pawn, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.ErrorOnce("Exception tending to a world pawn " + pawn.ToStringSafe() + ". Suppressing further errors. " + (object)ex, pawn.thingIDNumber ^ 8765780, false);
                    }
                    index = Interlocked.Decrement(ref worldPawnsTicks);
                }
                if (index == -1)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }

            else if (worldTickComplete && worldObjectsTicks > 0)
            {
                int index = Interlocked.Decrement(ref worldObjectsTicks);
                while (index >= 0)
                {
                    try
                    {
                        worldObjects[index].Tick();
                    } catch (Exception ex)
                    {
                        Log.Error("Exception ticking " + worldObjects[index].ToStringSafe() + ": " + ex);
                    }
                    index = Interlocked.Decrement(ref worldObjectsTicks);
                }
                if (index == -1)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }

            else if (worldTickComplete && allFactionsTicks > 0)
            {
                int index = Interlocked.Decrement(ref allFactionsTicks);
                while (index >= 0)
                {
                    try
                    {
                        allFactions[index].FactionTick();
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Exception ticking " + allFactions[index].ToStringSafe() + ": " + ex);
                    }
                    index = Interlocked.Decrement(ref allFactionsTicks);
                }
                if (index == -1)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }

            else if (mapPostTickComplete && steadyEnvironmentEffectsTicksCompleted < totalSteadyEnvironmentEffectsTicks)
            {
                int ticketIndex = Interlocked.Increment(ref steadyEnvironmentEffectsTicksCompleted) - 1;
                int steadyEnvironmentEffectsIndex = 0;
                while (ticketIndex < totalSteadyEnvironmentEffectsTicks)
                {
                    int index = ticketIndex;
                    while (ticketIndex >= steadyEnvironmentEffectsStructures[steadyEnvironmentEffectsIndex].steadyEnvironmentEffectsTicks)
                    {
                        steadyEnvironmentEffectsIndex++;
                    }
                    if (steadyEnvironmentEffectsIndex > 0)
                    {
                        index = ticketIndex - steadyEnvironmentEffectsStructures[steadyEnvironmentEffectsIndex - 1].steadyEnvironmentEffectsTicks;
                    }
                    int cycleIndex = (steadyEnvironmentEffectsStructures[steadyEnvironmentEffectsIndex].steadyEnvironmentEffectsCycleIndexOffset
                                      - index) % steadyEnvironmentEffectsStructures[steadyEnvironmentEffectsIndex].steadyEnvironmentEffectsArea;
                    IntVec3 c = steadyEnvironmentEffectsStructures[steadyEnvironmentEffectsIndex].steadyEnvironmentEffectsCellsInRandomOrder.Get(cycleIndex);
                    try
                    {
                        SteadyEnvironmentEffects_Patch.DoCellSteadyEffects(
                            steadyEnvironmentEffectsStructures[steadyEnvironmentEffectsIndex].steadyEnvironmentEffects, c);
                    } catch (Exception ex)
                    {
                        Log.Error("Exception ticking steadyEnvironmentEffectsCells " + index.ToStringSafe() + ": " + ex);
                    }
                    //Interlocked.Increment(ref SteadyEnvironmentEffects_Patch.cycleIndex(steadyEnvironmentEffectsInstance));
                    ticketIndex = Interlocked.Increment(ref steadyEnvironmentEffectsTicksCompleted) - 1;
                }
                if (ticketIndex == totalSteadyEnvironmentEffectsTicks)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }

            else if (mapPostTickComplete && wildPlantSpawnerTicksCompleted < wildPlantSpawnerTicksCount)
            {
                int ticketIndex           = Interlocked.Increment(ref wildPlantSpawnerTicksCompleted) - 1;
                int wildPlantSpawnerIndex = 0;
                WildPlantSpawnerStructure wildPlantSpawner;
                int index;
                while (ticketIndex < wildPlantSpawnerTicksCount)
                {
                    index = ticketIndex;
                    while (ticketIndex >= wildPlantSpawners[wildPlantSpawnerIndex].WildPlantSpawnerTicks)
                    {
                        wildPlantSpawnerIndex++;
                    }
                    if (wildPlantSpawnerIndex > 0)
                    {
                        index = ticketIndex - wildPlantSpawners[wildPlantSpawnerIndex - 1].WildPlantSpawnerTicks;
                    }
                    try
                    {
                        wildPlantSpawner = wildPlantSpawners[wildPlantSpawnerIndex];
                        int     cycleIndex = (wildPlantSpawner.WildPlantSpawnerCycleIndexOffset - index) % wildPlantSpawner.WildPlantSpawnerArea;
                        IntVec3 intVec     = wildPlantSpawner.WildPlantSpawnerCellsInRandomOrder.Get(cycleIndex);

                        if ((wildPlantSpawner.WildPlantSpawnerCycleIndexOffset - index) > wildPlantSpawner.WildPlantSpawnerArea)
                        {
                            Interlocked.Add(ref wildPlantSpawner.DesiredPlants2Tmp1000,
                                            1000 * (int)WildPlantSpawner_Patch.GetDesiredPlantsCountAt2(
                                                wildPlantSpawner.WildPlantSpawnerMap, intVec, intVec,
                                                wildPlantSpawner.WildPlantSpawnerCurrentPlantDensity));
                            if (intVec.GetTerrain(wildPlantSpawners[wildPlantSpawnerIndex].WildPlantSpawnerMap).fertility > 0f)
                            {
                                Interlocked.Increment(ref wildPlantSpawner.FertilityCells2Tmp);
                            }

                            float mtb = WildPlantSpawner_Patch.GoodRoofForCavePlant2(
                                wildPlantSpawner.WildPlantSpawnerMap, intVec) ? 130f :
                                        wildPlantSpawner.WildPlantSpawnerMap.Biome.wildPlantRegrowDays;
                            if (Rand.Chance(wildPlantSpawner.WildPlantSpawnerChance) && Rand.MTBEventOccurs(mtb, 60000f, 10000) &&
                                WildPlantSpawner_Patch.CanRegrowAt2(wildPlantSpawner.WildPlantSpawnerMap, intVec))
                            {
                                wildPlantSpawner.WildPlantSpawnerInstance.CheckSpawnWildPlantAt(intVec,
                                                                                                wildPlantSpawner.WildPlantSpawnerCurrentPlantDensity, wildPlantSpawner.DesiredPlantsTmp1000 / 1000.0f);
                            }
                        }
                        else
                        {
                            Interlocked.Add(ref wildPlantSpawner.DesiredPlantsTmp1000,
                                            1000 * (int)WildPlantSpawner_Patch.GetDesiredPlantsCountAt2(
                                                wildPlantSpawner.WildPlantSpawnerMap, intVec, intVec,
                                                wildPlantSpawner.WildPlantSpawnerCurrentPlantDensity));
                            if (intVec.GetTerrain(wildPlantSpawner.WildPlantSpawnerMap).fertility > 0f)
                            {
                                Interlocked.Increment(ref wildPlantSpawner.FertilityCellsTmp);
                            }

                            float mtb = WildPlantSpawner_Patch.GoodRoofForCavePlant2(wildPlantSpawner.WildPlantSpawnerMap, intVec) ? 130f :
                                        wildPlantSpawner.WildPlantSpawnerMap.Biome.wildPlantRegrowDays;
                            if (Rand.Chance(wildPlantSpawner.WildPlantSpawnerChance) && Rand.MTBEventOccurs(mtb, 60000f, 10000) &&
                                WildPlantSpawner_Patch.CanRegrowAt2(wildPlantSpawner.WildPlantSpawnerMap, intVec))
                            {
                                wildPlantSpawner.WildPlantSpawnerInstance.CheckSpawnWildPlantAt(intVec,
                                                                                                wildPlantSpawner.WildPlantSpawnerCurrentPlantDensity, wildPlantSpawner.DesiredPlants);
                            }
                        }

                        if (ticketIndex == wildPlantSpawners[wildPlantSpawnerIndex].WildPlantSpawnerTicks - 1)
                        {
                            if ((wildPlantSpawner.WildPlantSpawnerCycleIndexOffset - index) > wildPlantSpawner.WildPlantSpawnerArea)
                            {
                                WildPlantSpawner_Patch.calculatedWholeMapNumDesiredPlants(wildPlantSpawner.WildPlantSpawnerInstance)            = wildPlantSpawner.DesiredPlantsTmp1000 / 1000.0f;
                                WildPlantSpawner_Patch.calculatedWholeMapNumDesiredPlantsTmp(wildPlantSpawner.WildPlantSpawnerInstance)         = wildPlantSpawner.DesiredPlants2Tmp1000 / 1000.0f;
                                WildPlantSpawner_Patch.calculatedWholeMapNumNonZeroFertilityCells(wildPlantSpawner.WildPlantSpawnerInstance)    = wildPlantSpawner.FertilityCellsTmp;
                                WildPlantSpawner_Patch.calculatedWholeMapNumNonZeroFertilityCellsTmp(wildPlantSpawner.WildPlantSpawnerInstance) = wildPlantSpawner.FertilityCells2Tmp;
                            }
                            else
                            {
                                WildPlantSpawner_Patch.calculatedWholeMapNumDesiredPlantsTmp(wildPlantSpawner.WildPlantSpawnerInstance)      = wildPlantSpawner.DesiredPlantsTmp1000 / 1000.0f;
                                WildPlantSpawner_Patch.calculatedWholeMapNumNonZeroFertilityCells(wildPlantSpawner.WildPlantSpawnerInstance) = wildPlantSpawner.FertilityCellsTmp;
                            }
                            if (index == -1)
                            {
                                Interlocked.Increment(ref listsFullyProcessed);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Exception ticking WildPlantSpawner: " + ex);
                    }
                    ticketIndex = Interlocked.Increment(ref wildPlantSpawnerTicksCompleted) - 1;
                }
                if (ticketIndex == wildPlantSpawnerTicksCount)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }
            else if (mapPostTickComplete && totalTradeShipTicksCompleted < totalTradeShipTicks)
            {
                int ticketIndex         = Interlocked.Increment(ref totalTradeShipTicksCompleted) - 1;
                int totalTradeShipIndex = 0;
                while (ticketIndex < totalTradeShipTicks)
                {
                    int index = ticketIndex;
                    while (ticketIndex >= tradeShips[totalTradeShipIndex].TradeShipTicks)
                    {
                        totalTradeShipIndex++;
                    }
                    if (totalTradeShipIndex > 0)
                    {
                        index = ticketIndex - tradeShips[totalTradeShipIndex - 1].TradeShipTicks;
                    }
                    Pawn pawn = tradeShips[totalTradeShipIndex].TradeShipThings[index] as Pawn;
                    if (pawn != null)
                    {
                        try
                        {
                            pawn.Tick();
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Exception ticking Pawn: " + pawn.ToStringSafe() + " " + ex);
                        }
                        if (pawn.Dead)
                        {
                            lock (tradeShips[totalTradeShipIndex].TradeShipThings)
                            {
                                tradeShips[totalTradeShipIndex].TradeShipThings.Remove(pawn);
                            }
                        }
                    }
                    ticketIndex = Interlocked.Increment(ref totalTradeShipTicksCompleted) - 1;
                }
                if (ticketIndex == totalTradeShipTicks)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }
            else if (worldTickComplete && WorldComponentTicks > 0)
            {
                int index = Interlocked.Decrement(ref WorldComponentTicks);
                while (index >= 0)
                {
                    //try
                    //{
                    WorldComponent wc = WorldComponents[index];
                    if (null != wc)
                    {
                        lock (wc)
                        {
                            try
                            {
                                wc.WorldComponentTick();
                            } catch (Exception ex)
                            {
                                Log.Error("Exception ticking World Component: " + wc.ToStringSafe() + ex);
                            }
                        }
                    }
                    //}
                    //catch (Exception ex)
                    //{
                    //    Log.Error(ex.ToString());
                    //}
                    index = Interlocked.Decrement(ref WorldComponentTicks);
                }
                if (index == -1)
                {
                    Interlocked.Increment(ref listsFullyProcessed);
                }
            }

            /*
             * while(drawQueue.TryDequeue(out Thing drawThing))
             * {
             *  IntVec3 position = drawThing.Position;
             *  if ((cellRect.Contains(position) || drawThing.def.drawOffscreen) && (!fogGrid[cellIndices.CellToIndex(position)] || drawThing.def.seeThroughFog) && (drawThing.def.hideAtSnowDepth >= 1.0 || snowGrid.GetDepth(position) <= (double)drawThing.def.hideAtSnowDepth))
             *  {
             *      try
             *      {
             *          drawThing.Draw();
             *      }
             *      catch (Exception ex)
             *      {
             *          Log.Error("Exception drawing " + (object)drawThing + ": " + ex.ToString(), false);
             *      }
             *  }
             * }
             */
        }
示例#23
0
        private static IEnumerable InfectionSimulatorWorker()
        {
            int         trials    = 2;
            List <Pawn> doctors   = GenerateDoctorArray();
            List <int>  testSkill = new List <int>
            {
                4,
                10,
                16
            };
            List <ThingDef> testMedicine = new List <ThingDef>
            {
                null,
                ThingDefOf.MedicineHerbal,
                ThingDefOf.MedicineIndustrial,
                ThingDefOf.MedicineUltratech
            };
            PawnGenerationRequest pawngen  = new PawnGenerationRequest(PawnKindDefOf.Colonist, Faction.OfPlayer);
            int originalTicks              = Find.TickManager.TicksGame;
            List <InfectionSimRow> results = new List <InfectionSimRow>();
            int totalTests  = InfectionList().Count() * testMedicine.Count() * testSkill.Count() * trials;
            int currentTest = 0;

            foreach (HediffDef item in InfectionList())
            {
                foreach (ThingDef item2 in testMedicine)
                {
                    foreach (int item3 in testSkill)
                    {
                        InfectionSimRow result = new InfectionSimRow
                        {
                            illness  = item,
                            skill    = item3,
                            medicine = item2
                        };
                        Pawn doctor = doctors[item3];
                        int  i      = 0;
                        if (i < trials)
                        {
                            Pawn patient    = PawnGenerator.GeneratePawn(pawngen);
                            int  startTicks = Find.TickManager.TicksGame;
                            patient.health.AddHediff(result.illness);
                            Hediff activeHediff = patient.health.hediffSet.GetFirstHediffOfDef(result.illness);
                            while (!patient.Dead && patient.health.hediffSet.HasHediff(result.illness))
                            {
                                if (activeHediff.TendableNow())
                                {
                                    activeHediff.Tended(TendUtility.CalculateBaseTendQuality(doctor, patient, item2));
                                    result.medicineUsed += 1f;
                                }
                                foreach (Hediff item4 in patient.health.hediffSet.GetHediffsTendable())
                                {
                                    item4.Tended(TendUtility.CalculateBaseTendQuality(doctor, patient, item2));
                                }
                                Find.TickManager.DebugSetTicksGame(Find.TickManager.TicksGame + 1);
                                patient.health.HealthTick();
                                if (Find.TickManager.TicksGame % 900 == 0)
                                {
                                    yield return((object)null);

                                    /*Error: Unable to find new state assignment for yield return*/;
                                }
                            }
                            if (patient.Dead)
                            {
                                result.deathChance += 1f;
                            }
                            else
                            {
                                result.recoveryTimeDays += (Find.TickManager.TicksGame - startTicks).TicksToDays();
                            }
                            currentTest++;
                            LongEventHandler.SetCurrentEventText($"Simulating ({currentTest}/{totalTests})");
                            yield return((object)null);

                            /*Error: Unable to find new state assignment for yield return*/;
                        }
                        result.recoveryTimeDays /= (float)trials - result.deathChance;
                        result.deathChance      /= (float)trials;
                        result.medicineUsed     /= (float)trials;
                        results.Add(result);
                    }
                }
            }
            DebugTables.MakeTablesDialog(results, new TableDataGetter <InfectionSimRow>("defName", (InfectionSimRow isr) => isr.illness.defName), new TableDataGetter <InfectionSimRow>("meds", (InfectionSimRow isr) => (isr.medicine == null) ? "(none)" : isr.medicine.defName), new TableDataGetter <InfectionSimRow>("skill", (InfectionSimRow isr) => isr.skill.ToString()), new TableDataGetter <InfectionSimRow>("death chance", (InfectionSimRow isr) => isr.deathChance.ToStringPercent()), new TableDataGetter <InfectionSimRow>("recovery time (days)", (InfectionSimRow isr) => isr.recoveryTimeDays.ToString("F1")), new TableDataGetter <InfectionSimRow>("medicine used", (InfectionSimRow isr) => isr.medicineUsed.ToString()));
            Find.TickManager.DebugSetTicksGame(originalTicks);
            yield break;
IL_06f6:
            /*Error near IL_06f7: Unexpected return in MoveNext()*/;
        }
示例#24
0
        public static bool GetOptimalHediffsToTendWithSingleTreatment(
            Pawn patient,
            bool usingMedicine,
            List <Hediff> outHediffsToTend,
            List <Hediff> tendableHediffsInTendPriorityOrder = null)
        {
            outHediffsToTend.Clear();
            //TendUtility.tmpHediffs.Clear();
            List <Hediff> tmpHediffs = new List <Hediff>();

            if (tendableHediffsInTendPriorityOrder != null)
            {
                tmpHediffs.AddRange(tendableHediffsInTendPriorityOrder);
            }
            else
            {
                List <Hediff> hediffs = patient.health.hediffSet.hediffs;
                for (int index = 0; index < hediffs.Count; ++index)
                {
                    if (hediffs[index].TendableNow(false))
                    {
                        tmpHediffs.Add(hediffs[index]);
                    }
                }
                TendUtility.SortByTendPriority(tmpHediffs);
            }
            if (!tmpHediffs.Any())
            {
                return(false);
            }
            Hediff tmpHediff1 = tmpHediffs[0];

            outHediffsToTend.Add(tmpHediff1);
            HediffCompProperties_TendDuration propertiesTendDuration = tmpHediff1.def.CompProps <HediffCompProperties_TendDuration>();

            if (propertiesTendDuration != null && propertiesTendDuration.tendAllAtOnce)
            {
                for (int index = 0; index < tmpHediffs.Count; ++index)
                {
                    if (tmpHediffs[index] != tmpHediff1 && tmpHediffs[index].def == tmpHediff1.def)
                    {
                        outHediffsToTend.Add(tmpHediffs[index]);
                    }
                }
            }
            else if (tmpHediff1 is Hediff_Injury & usingMedicine)
            {
                float severity1 = tmpHediff1.Severity;
                for (int index = 0; index < tmpHediffs.Count; ++index)
                {
                    if (tmpHediffs[index] != tmpHediff1 && tmpHediffs[index] is Hediff_Injury tmpHediff2)
                    {
                        float severity2 = tmpHediff2.Severity;
                        if (severity1 + (double)severity2 <= 20.0)
                        {
                            severity1 += severity2;
                            outHediffsToTend.Add(tmpHediff2);
                        }
                    }
                }
            }
            //TendUtility.tmpHediffs.Clear();
            return(false);
        }