I have a mod which changes the insect hive behaviour.
It uses a stored integer to determine the next tick when it will spawn a bug.
Relevant code:
This function gets called once then once the game counts to the next hive spawn tick, it changes again.
When i test, i create a hive which initializes this value to about 200,000. When i save and reload, that value gets changed to an astronomically high number. I don't understand why. Is there some trick i need to do when the game is saved and loaded so that the tick counter stays the same? How can i guarantee that this integer will be saved and loaded properly?
It uses a stored integer to determine the next tick when it will spawn a bug.
Relevant code:
Code Select
private int nextHiveSpawnTick = -1;
//... etc
public void CalculateNextHiveSpawnTick()
{
Room room = this.parent.GetRoom();
int num = 0;
int num1 = GenRadial.NumCellsInRadius(9f);
for (int i = 0; i < num1; i++)
{
IntVec3 position = this.parent.Position + GenRadial.RadialPattern[i];
if (position.InBounds(this.parent.Map))
{
if (position.GetRoom(this.parent.Map) == room)
{
if (position.GetThingList(this.parent.Map).Any<Thing>((Thing t) => t is Hive))
{
num++;
}
}
}
}
float single = GenMath.LerpDouble(0f, 7f, 1f, 0.35f, (float)Mathf.Clamp(num, 0, 7));
this.nextHiveSpawnTick = Find.TickManager.TicksGame + (int)(this.Props.HiveSpawnIntervalDays.RandomInRange * 60000f / (single * Find.Storyteller.difficulty.enemyReproductionRateFactor));
}
This function gets called once then once the game counts to the next hive spawn tick, it changes again.
When i test, i create a hive which initializes this value to about 200,000. When i save and reload, that value gets changed to an astronomically high number. I don't understand why. Is there some trick i need to do when the game is saved and loaded so that the tick counter stays the same? How can i guarantee that this integer will be saved and loaded properly?