#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_Average_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 = 2

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


if( ChanceAgainst < PercentChancePerSecond  )
 MiliSecs_Since_Last_Spawn = 0
 Do_Spawn = 1
else
 Do_Spawn = 0
endif