ability to cancel construction and have a portion of the funds returned
[browser-rts.git] / src / tasks / tick.ts
index 8160e9ae03bf4446299e0726988db0d37acff826..345f5af7e81f8e79ca6383bba3e5454416ba7f32 100644 (file)
@@ -9,13 +9,14 @@ type Tick = {
 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 
-       gold = gold + population * 2, 
-       bushels = round(
+       credits = credits + population * 2, 
+       food = round(
                max(
-                       bushels - (
+                       food - (
                                (soldiers*0.5)+
                                (population*0.25)+
                                (attackers*0.75)+
@@ -27,12 +28,31 @@ export const tick = new Task<Tick>('tick', async (task, job) => {
                )
                 + farms * 50
        ),
-       population = max(
-               min(
-                       population + round(coalesce(bushels/bushels, 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 {
@@ -45,14 +65,6 @@ export const tick = new Task<Tick>('tick', async (task, job) => {
                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);
        }
-
-});
\ No newline at end of file
+});