From 9d803dfdec400c4088cc134d563d937097f9352f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Preu=C3=9F?= Date: Wed, 19 Jul 2023 19:17:18 +0200 Subject: [PATCH] don't speed up `fastloop()` under accelerated time Instead of simply running the game in tighter loops, multiply resource calculations by game speed. This is only done for `fastloop()` for now as most other code is tightly build around the timings of `midloop()` and `longloop()`. In a few places a `++` was replaced by `4*time_multiplier` to account for the loop running 4 times per second and `time_multiplier` being 0.25 under normal game speed. --- src/functions.js | 7 ++++--- src/main.js | 29 ++++++++++++----------------- src/portal.js | 6 +++--- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/functions.js b/src/functions.js index 681fbb5e84..32748d5c14 100644 --- a/src/functions.js +++ b/src/functions.js @@ -139,9 +139,10 @@ export function gameLoop(act){ global.settings.gameSpeed *= fast; } - for (let key in webWorker.timers) { - webWorker.timers[key] /= global.settings.gameSpeed; - } + // timers.main stays as is since ressource calculations in + // fastloop() are already gamespeed compensated + webWorker.timers.mid /= global.settings.gameSpeed; + webWorker.timers.long /= global.settings.gameSpeed; if (webWorker.w){ webWorker.w.postMessage({ loop: 'short', period: webWorker.timers.main }); diff --git a/src/main.js b/src/main.js index 6a67608b5e..af8b9e37f6 100644 --- a/src/main.js +++ b/src/main.js @@ -978,7 +978,7 @@ function fastLoop(){ breakdown.p[res] = {}; }); - var time_multiplier = 0.25; + var time_multiplier = webWorker.timers.main * global.settings.gameSpeed / 1000; if (global.race.species === 'protoplasm'){ // Early Evolution Game @@ -1879,7 +1879,7 @@ function fastLoop(){ if (global.space['m_relay']){ if (p_on['m_relay']){ if (global.space.m_relay.charged < 10000){ - global.space.m_relay.charged++; + global.space.m_relay.charged += 4 * time_multiplier; } } else { @@ -3365,12 +3365,15 @@ function fastLoop(){ // Fortress Repair if (global.portal['fortress'] && global.portal.fortress.walls < 100){ if (modRes('Stone', -(200 * time_multiplier))){ - global.portal.fortress.repair++; + global.portal.fortress.repair += 4 * time_multiplier; breakdown.p.consume.Stone[loc('portal_fortress_name')] = -200; } if (global.portal.fortress.repair >= actions.portal.prtl_fortress.info.repair()){ global.portal.fortress.repair = 0; - global.portal.fortress.walls++; + global.portal.fortress.walls += 4 * time_multiplier; + if (global.portal.fortress.walls > 100) { + global.portal.fortress.walls = 100; + } } } @@ -3548,7 +3551,7 @@ function fastLoop(){ if (global.race['emfield']){ if (global.race['discharge'] && global.race['discharge'] > 0){ - global.race.discharge--; + global.race.discharge -= 4 * time_multiplier; } else { global.race.emfield++; @@ -7020,7 +7023,7 @@ function fastLoop(){ if (!$('#portal-carport .count').hasClass('has-text-alert')){ $('#portal-carport .count').addClass('has-text-alert'); } - global.portal.carport.repair++; + global.portal.carport.repair += 4 * time_multiplier; if (global.portal.carport.repair >= actions.portal.prtl_fortress.carport.repair()){ global.portal.carport.repair = 0; global.portal.carport.damaged--; @@ -11231,21 +11234,13 @@ function q_check(load){ } function diffCalc(res,period){ - let sec = 1000; - if (global.race['slow']){ - let slow = 1 + (traits.slow.vars()[0] / 100); - sec = Math.floor(sec * slow); - } - if (global.race['hyper']){ - let fast = 1 - (traits.hyper.vars()[0] / 100); - sec = Math.floor(sec * fast); - } + const periods = 1000 / period - global.resource[res].diff = +(global.resource[res].delta / (period / sec)).toFixed(2); + global.resource[res].diff = +(global.resource[res].delta * periods).toFixed(2); global.resource[res].delta = 0; if (global.resource[res].hasOwnProperty('gen') && global.resource[res].hasOwnProperty('gen_d')){ - global.resource[res].gen = +(global.resource[res].gen_d / (period / sec)).toFixed(2); + global.resource[res].gen = +(global.resource[res].gen_d * periods).toFixed(2); global.resource[res].gen_d = 0; } diff --git a/src/portal.js b/src/portal.js index 3b0c9abdeb..d575dbf530 100644 --- a/src/portal.js +++ b/src/portal.js @@ -1970,7 +1970,7 @@ export function buildFortress(parent,full){ let wallStatus = $('
'); fort.append(wallStatus); - wallStatus.append($(`${loc('fortress_wall')} {{ f.walls }}%`)) + wallStatus.append($(`${loc('fortress_wall')} {{ Math.ceil(f.walls) }}%`)) let station = $(`
`); fort.append(station); @@ -2543,7 +2543,7 @@ export function bloodwar(){ if (siege > 0){ damage++; global.portal.fortress.walls--; - if (global.portal.fortress.walls === 0){ + if (global.portal.fortress.walls <= 0){ siege_report.destroyed = true; destroyed = true; break; @@ -5294,4 +5294,4 @@ function purgeReports(refresh){ } return removed; } -} \ No newline at end of file +}