export const tick = new Task<Tick>('tick', async (task, job) => {
const nextTick = job.data.lastTick+1;
+ const start = Date.now();
// +population*1.1 is where we take into account farms for bonus food production
let sql = `update cities set
)
+ farms * 50
),
- population = max(
- min(
- population + round(coalesce(food/food, 0) * population*0.08),
- farms * 70
- ),
- population
+ energy = min(
+ max(
+ energy - (
+ farms * 4 +
+ barracks * 6 +
+ special_attacker_trainer * 10 +
+ special_defender_trainer * 8 +
+ homes * 1 +
+ warehouses * 3 +
+ solar_panels * 1 +
+ accumulators * 10 +
+ mining_facilities * 8 +
+ ore_refinery * 4
+ ),
+ 0
+ ) + solar_panels * 125,
+ accumulators * 150
+ ),
+ alloys = min(
+ (alloys + mining_facilities * 20),
+ ore_refinery * 75
+ ),
+ population = min(
+ (population + round(population * 0.08)),
+ homes * 25
)`;
try {
console.log(e);
}
finally {
- const now = new Date();
- const nextTickAt = 60 - now.getMinutes();
- console.log(`Tick scheduled for ${nextTickAt}min`);
-
- task.trigger({
- lastTickAt: +now,
- lastTick: nextTick
- }, { delay: 60000 * nextTickAt});
+ console.log('Tick complete', Date.now() - start);
}
-
});