Beispiel #1
0
        public static void MultipliedAgeTick(ref int interval, Pawn_AgeTracker __instance)
        {
            //Find the pawn this tracker belongs to
            Pawn      pawn          = null;
            FieldInfo pawnFieldInfo = AccessTools.Field(__instance.GetType(), "pawn");

            if (pawnFieldInfo != null && pawnFieldInfo.FieldType.Equals(typeof(Verse.Pawn)))
            {
                pawn = (Verse.Pawn)pawnFieldInfo.GetValue(__instance);
            }

            if (pawn != null)
            {
                //Determine multiplier
                int multiplier = FasterAging.GetPawnAgingMultiplier(pawn);


                //Experimental Chronological age modification
                //I judge this too likely to cause issues and too practically insignificant to include as a default feature.
                if (FasterAging.modifyChronologicalAge)
                {
                    __instance.BirthAbsTicks -= (multiplier - 1) * interval; //Similar system to how the AgeTick patch works, just on the scale of the base interval rather than single ticks. Moves the pawn's birthday to correctly account for modified age rate.
                }


                //Edit the referenced interval value to take the multiplier into account.
                //The game will now run AgeTickMothballed() with this edited interval, accelerating or halting aging.
                interval = multiplier * interval;
            }
        }
Beispiel #2
0
        public static void MultiTick(Pawn __instance)
        {
            //Determine multiplier
            int multiplier = FasterAging.GetPawnAgingMultiplier(__instance);


            //Run extra aging.
            if (multiplier == 0) //Aging is disabled - Manually revert the age increase from the core game's AgeTick call
            {
                __instance.ageTracker.AgeBiologicalTicks += -1;
                //Note - there is still a potential issue if the age multiplier setting is changed by the player to 0 on a birthday tick, causing that birthday to get re-run.
                //This is a hilariously impossible edge case, but if I want to improve code safety, this is something to work on.
            }
            else
            {
                if (!FasterAging.useAlternateAging)
                {
                    //Primary aging algorithm - repeat calls AgeTick until a correct number of calls has been made to match the multiplier.
                    //This system is more performance intensive, and will trip up any mods that expect AgeTick to be called once per pawn tick.
                    //However, I judge that it is more likely and more problematic that a mod expects a specific age tick count to occur after
                    //an AgeTick call, which will get skipped using the alternative method.
                    //Thus this is the default algorithm.
                    for (int additionalTick = 0; additionalTick < multiplier - 1; additionalTick++) //AgeTick already runs once naturally - subtract 1 from the multiplier to get how many times it should be called again
                    {
                        __instance.ageTracker.AgeTick();
                    }
                }
                else
                {
                    //Alternative aging algorithm - directly increment the pawn's age tick value to the appropriate amount. Similar to vanilla AgeTickMothballed
                    //This is much less performance hungry, but may cause issues if another mod expects AgeTick to only increment the age value by 1, or if
                    //another mod has a trigger set up to check for a specific age tick value after AgeTick is called.
                    //It's an optional alternate method for these reasons.
                    int ageYearsBefore = __instance.ageTracker.AgeBiologicalYears; //Save the pawn's age before the increment for birthday calculation

                    __instance.ageTracker.AgeBiologicalTicks += multiplier - 1;    //Advances the pawn's age value. It has already been increased by 1 by vanilla code.

                    //Vanilla's AgeTickMothballed includes a check for life stage recalculation here.
                    //I don't think this is necessary/it has already been solved by my daily check.
                    //It also includes a Find call that I worry might not work well with a mod, so I didn't include the code.

                    //Birthday check - run BiologicalBirthday once for every full year of age that the pawn has advanced during this algorithm
                    //Tynan used a much more complicated system of comparing age tick values, but I cannot say why. If this is an issue, though, I should replace this with his system.
                    for (int year = ageYearsBefore; year < __instance.ageTracker.AgeBiologicalYears; year++)
                    {
                        __instance.ageTracker.DebugForceBirthdayBiological(); //This method is public where BirthdayBiological is private. The debug method does nothing but call the proper method fortunately.
                    }
                }
            }


            //Experimental Chronological age modification
            //I judge this too likely to cause issues and too practically insignificant to include as a default feature.
            if (FasterAging.modifyChronologicalAge)
            {
                __instance.ageTracker.BirthAbsTicks -= multiplier - 1; //Move the character's birthday earlier in time, accelerating how distant it is from the current. If multiplier is 0, actually moves birthday forward 1 tick, keeping it a constant distance from the current tick and thus a constant age.
            }
        }