Make sure a fertilized egg loads properly when loading a pre-ticks save

This commit is contained in:
lutepickle 2023-04-29 22:28:29 -07:00
parent 270ac427c8
commit 152a745af2

View file

@ -1968,7 +1968,7 @@ namespace RJW_Menstruation
public class Egg : IExposable
{
public bool fertilized;
public int lifeSpanTicks;
public int lifeSpanTicks; // Actual ticks scaled by cycleAcceleration
public Pawn fertilizer;
public int ageTicks;
public int ticksSinceFertilization = 0;
@ -1995,23 +1995,25 @@ namespace RJW_Menstruation
{
int lifespanhrs = -1;
int position = -1;
int fertstage = -1;
Scribe_Values.Look(ref lifespanhrs, "lifespanhrs", lifespanhrs, true);
Scribe_Values.Look(ref position, "position", position, true);
Scribe_Values.Look(ref fertstage, "fertstage", fertstage, true);
if (lifespanhrs >= 0) lifeSpanTicks = lifespanhrs * GenDate.TicksPerHour;
if (position >= 0) ageTicks = position * GenDate.TicksPerHour;
if (fertstage >= 0) ticksSinceFertilization = fertstage * GenDate.TicksPerHour;
}
Scribe_References.Look(ref fertilizer, "fertilizer", true);
Scribe_Values.Look(ref fertilized, "fertilized", false);
Scribe_Values.Look(ref lifeSpanTicks, "lifeSpanTicks", lifeSpanTicks, true);
Scribe_Values.Look(ref ageTicks, "ageTicks", ageTicks, true);
Scribe_Values.Look(ref ticksSinceFertilization, "ticksSinceFertilization", 0);
if (ticksSinceFertilization == 0 && Scribe.mode == LoadSaveMode.LoadingVars)
{
// A bit awkward to do this twice, but it prevents ticksSinceFertilization from getting overwritten on a fertstage load
int fertstage = -1;
Scribe_Values.Look(ref fertstage, "fertstage", fertstage, true);
if (fertstage >= 0) ticksSinceFertilization = fertstage * GenDate.TicksPerHour;
}
}
}
}
public class HediffComp_Anus : HediffComp