private void UpdateRelativeFieldsFromTicks(int ticksToUse)
        {
            var diff = GenDate.TickGameToAbs(ticksToUse) - Find.TickManager.TicksAbs;
            int years = 0, quadrums = 0, days = 0;
            var hours = 8f;

            if (diff > 0)
            {
                GenDate.TicksToPeriod(diff, out years, out quadrums, out days, out hours);
            }

            hoursFromNowValue = Mathf.CeilToInt(hours);
            daysFromNowValue  = days + quadrums * GenDate.DaysPerQuadrum + years * GenDate.DaysPerYear;

            var remainder = hoursFromNowValue == 24;

            if (remainder)
            {
                hoursFromNowValue = 0;
                daysFromNowValue += 1;
            }

            hoursFromNowBuffer = hoursFromNowValue.ToString();
            daysFromNowBuffer  = daysFromNowValue.ToString();

            Log.Debug($"Set to {hoursFromNowValue} ({hoursFromNowBuffer}) on day {daysFromNowValue} ({daysFromNowBuffer})");
        }
Esempio n. 2
0
        private static float HarvestPartChance(bool bionic, Building_WorkTable table, Pawn butcher, Pawn corpse)
        {
            if (bionic)
            {
                return(1f);
            }
            float baseFactor = 0.5f;
            // TABLE
            float           tableQualityFactor = 1f, tableStuffFactor = 1f;
            QualityCategory qc;

            table.TryGetQuality(out qc);
            string tableQuality   = qc.GetLabel();
            string tableStuff     = table.Stuff.LabelCap;

            switch (tableQuality)
            {
            case "awful":
                tableQualityFactor = 0.7f;
                break;

            case "shoddy":
                tableQualityFactor = 0.8f;
                break;

            case "poor":
                tableQualityFactor = 0.9f;
                break;

            case "normal":
                tableQualityFactor = 1f;
                break;

            case "good":
                tableQualityFactor = 1.1f;
                break;

            case "superior":
                tableQualityFactor = 1.2f;
                break;

            case "excellent":
                tableQualityFactor = 1.3f;
                break;

            case "masterwork":
                tableQualityFactor = 1.4f;
                break;

            case "legendary":
                tableQualityFactor = 1.5f;
                break;
            }
            switch (tableStuff)
            {
            case "Silver":
                tableStuffFactor = 1.2f;
                break;

            case "Steel":
                tableStuffFactor = 1.1f;
                break;

            case "Wood":
                tableStuffFactor = 0.9f;
                break;
            }

            // ROOM
            float infectionChance = table.GetRoom(RegionType.Set_Passable).GetStat(RoomStatDefOf.InfectionChanceFactor);
            float roomInfectionFactor = (1 - infectionChance) + 0.5f;
            // BUTCHER
            SkillRecord skill      = butcher.skills.GetSkill(SkillDefOf.Medicine);
            int         skillLevel = 0;

            if (skill != null)
            {
                skillLevel = skill.Level;
            }
            float doctorSkillFactor = (skillLevel * skillLevel + 1f) / 300f;

            // CORPSE
            int   years = 0, quadrums = 0, days = 0;
            float hours = 0f;

            GenDate.TicksToPeriod(corpse.Corpse.Age, out years, out quadrums, out days, out hours);
            float corpseAge       = hours + 24 * days + 15 * 24 * quadrums + 4 * 15 * 24 * years;
            float corpseAgeFactor = 1.01f;

            if (corpseAge > 12 && corpseAge < 24)
            {
                corpseAgeFactor = (24f - corpseAge) / 20f + 0.01f;
            }
            else if (corpseAge >= 24)
            {
                corpseAgeFactor = 0.01f;
            }
            float chance = baseFactor * tableQualityFactor * tableStuffFactor * roomInfectionFactor * doctorSkillFactor * corpseAgeFactor;

            if (Prefs.DevMode)
            {
                Log.Message("Base chance: " + baseFactor);
                Log.Message("Table quality: " + tableQuality + " = " + tableQualityFactor);
                Log.Message("Table stuff: " + tableStuff + " = " + tableStuffFactor);
                Log.Message("Infection chance: " + infectionChance + " = " + roomInfectionFactor);
                Log.Message("Doctor skill: " + skillLevel + " = " + doctorSkillFactor);
                Log.Message("Corpse age: " + corpseAge + "h" + " = " + corpseAgeFactor);
                Log.Message("Total: " + chance);
            }
            return(chance);
        }