#This formula is responsible for updating this data, it will be passed in each time


MiliSecs_Since_Last_Spawn = MiliSecs_Since_Last_Spawn + MiliSecs_Since_Last_Execution

Running_Average_Happiness = ((Running_Average_Happiness * 10000) + (Current_Average_Happiness * MiliSecs_Since_Last_Execution)) /(10000 + MiliSecs_Since_Last_Execution)

Current_Fraction_Happiness = Current_Average_Happiness/100

SecondsElapsed = MiliSecs_Since_Last_Execution/1000


#If you have full happiness, this will give you the percent chance per second of spawning a new creature
PercentChancePerSecond = 14

ChanceAgainst = (100 * RAND)/(SecondsElapsed  * Current_Fraction_Happiness * Current_Fraction_Happiness )


if( (ChanceAgainst < PercentChancePerSecond) and (Current_Average_Happiness > 55) )
 MiliSecs_Since_Last_Spawn = 0
 Do_Spawn = 1
else
 Do_Spawn = 0
endif