Skip to content

Commit

Permalink
adjust timers under accelerated time
Browse files Browse the repository at this point in the history
The previous versions all assumed `midloop()` would run exactly once a
second.  This isn't the case under accelerated time.  This will
correctly subtract the time between `midloop()` calls from timers such
that the displayed timer accurately represents real time left.

Currently this is done for the spy's training and mission timers as well
as the gene mutation timer.
  • Loading branch information
Daxtorim authored and Fabian Preuß committed Jul 29, 2023
1 parent 9d803df commit 99de001
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/arpa.js
Original file line number Diff line number Diff line change
Expand Up @@ -1785,11 +1785,12 @@ function genetics(){
filters: {
timer(val){
if (global.arpa.sequence.on && global.arpa.sequence.labs > 0){
const time = val / (global.settings.gameSpeed * global.arpa.sequence.labs);
if (global.arpa.sequence.boost){
return timeFormat(val / (global.arpa.sequence.labs * 2));
return timeFormat(time / 2);
}
else {
return timeFormat(val / global.arpa.sequence.labs);
return timeFormat(time);
}
}
else {
Expand Down
19 changes: 10 additions & 9 deletions src/civics.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ export function foreignGov(){

let actions = $(`<div></div>`);
actions.append($(`<button :label="battleAssessment(${i})" class="button gaction attack" @click="campaign(${i})"><span v-show="!f${i}.occ && !f${i}.anx && !f${i}.buy">${loc('civics_garrison_attack')}</span><span v-show="f${i}.occ || f${i}.anx || f${i}.buy">${loc('civics_garrison_unoccupy')}</span></button>`));
actions.append($(`<span class="tspy inline"><button :label="spyDesc(${i})" v-show="t.spy >= 1 && !f${i}.occ && !f${i}.anx && !f${i}.buy" :disabled="spy_disabled(${i})" class="button gaction" @click="spy(${i})"><span v-show="f${i}.trn === 0">${loc('tech_spy')}: {{ f${i}.spy }}</span><span v-show="f${i}.trn > 0">${loc('civics_train')}: {{ f${i}.trn }}</span></button></span>`));
actions.append($(`<span class="sspy inline"><button :label="espDesc()" v-show="t.spy >= 2 && !f${i}.occ && !f${i}.anx && !f${i}.buy && f${i}.spy >= 1" :disabled="f${i}.sab > 0" class="button gaction" @click="trigModal(${i})"><span v-show="f${i}.sab === 0">${loc('tech_espionage')}</span><span v-show="f${i}.sab > 0">{{ f${i}.act | sab }}: {{ f${i}.sab }}</span></button></span>`));
actions.append($(`<span class="tspy inline"><button :label="spyDesc(${i})" v-show="t.spy >= 1 && !f${i}.occ && !f${i}.anx && !f${i}.buy" :disabled="spy_disabled(${i})" class="button gaction" @click="spy(${i})"><span v-show="f${i}.trn <= 0">${loc('tech_spy')}: {{ f${i}.spy }}</span><span v-show="f${i}.trn > 0">${loc('civics_train')}: {{ Math.ceil(f${i}.trn / s.gameSpeed) }}</span></button></span>`));
actions.append($(`<span class="sspy inline"><button :label="espDesc()" v-show="t.spy >= 2 && !f${i}.occ && !f${i}.anx && !f${i}.buy && f${i}.spy >= 1" :disabled="f${i}.sab > 0" class="button gaction" @click="trigModal(${i})"><span v-show="f${i}.sab <= 0">${loc('tech_espionage')}</span><span v-show="f${i}.sab > 0">{{ f${i}.act | sab }}: {{ Math.ceil(f${i}.sab / s.gameSpeed) }}</span></button></span>`));
gov.append(actions);

gov.append($(`<div v-show="!f${i}.occ && !f${i}.anx && !f${i}.buy"><span class="has-text-advanced glabel">${loc('civics_gov_mil_rate')}:</span> <span class="glevel">{{ f${i}.mil | military(${i}) }}<span class="has-text-warning" v-show="f${i}.spy >= 2"> ({{ f${i}.mil }})</span></span></div>`));
Expand All @@ -450,7 +450,8 @@ export function foreignGov(){
f0: global.civic.foreign[`gov0`],
f1: global.civic.foreign[`gov1`],
f2: global.civic.foreign[`gov2`],
t: global.tech
t: global.tech,
s: global.settings
};
if (global.race['truepath']){
bindData['f3'] = global.civic.foreign[`gov3`];
Expand Down Expand Up @@ -700,7 +701,7 @@ function spyCost(i){
}

function trainSpy(i){
if (global.tech['spy'] && global.civic.foreign[`gov${i}`].trn === 0){
if (global.tech['spy'] && global.civic.foreign[`gov${i}`].trn <= 0){
let cost = spyCost(i)
if (global.resource.Money.amount >= cost){
global.resource.Money.amount -= cost;
Expand Down Expand Up @@ -737,7 +738,7 @@ function spyAction(sa,g){
switch (sa){
case 'influence':
{
if (global.tech['spy'] && global.tech['spy'] >= 2 && global.civic.foreign[`gov${g}`].spy >= 1 && global.civic.foreign[`gov${g}`].sab === 0){
if (global.tech['spy'] && global.tech['spy'] >= 2 && global.civic.foreign[`gov${g}`].spy >= 1 && global.civic.foreign[`gov${g}`].sab <= 0){
let timer = global.tech['spy'] >= 4 ? 200 : 300;
if (global.race['befuddle']){
timer = Math.round(timer * (1 - traits.befuddle.vars()[0] / 100));
Expand All @@ -753,7 +754,7 @@ function spyAction(sa,g){
break;
case 'sabotage':
{
if (global.tech['spy'] && global.tech['spy'] >= 2 && global.civic.foreign[`gov${g}`].spy >= 1 && global.civic.foreign[`gov${g}`].sab === 0){
if (global.tech['spy'] && global.tech['spy'] >= 2 && global.civic.foreign[`gov${g}`].spy >= 1 && global.civic.foreign[`gov${g}`].sab <= 0){
let timer = global.tech['spy'] >= 4 ? 400 : 600;
if (global.race['befuddle']){
timer = Math.round(timer * (1 - traits.befuddle.vars()[0] / 100));
Expand All @@ -770,7 +771,7 @@ function spyAction(sa,g){
case 'incite':
{
if (g >= 3){ break; }
else if (global.tech['spy'] && global.tech['spy'] >= 2 && global.civic.foreign[`gov${g}`].spy >= 1 && global.civic.foreign[`gov${g}`].sab === 0){
else if (global.tech['spy'] && global.tech['spy'] >= 2 && global.civic.foreign[`gov${g}`].spy >= 1 && global.civic.foreign[`gov${g}`].sab <= 0){
let timer = global.tech['spy'] >= 4 ? 600 : 900;
if (global.race['befuddle']){
timer = Math.round(timer * (1 - traits.befuddle.vars()[0] / 100));
Expand Down Expand Up @@ -840,7 +841,7 @@ function drawEspModal(gov){
annex(g){
if (g >= 3){ return; }
if (global.civic.foreign[`gov${gov}`].hstl <= 50 && global.civic.foreign[`gov${gov}`].unrest >= 50 && global.city.morale.current >= (200 + global.civic.foreign[`gov${gov}`].hstl - global.civic.foreign[`gov${gov}`].unrest)){
if (global.tech['spy'] && global.tech['spy'] >= 2 && global.civic.foreign[`gov${g}`].spy >= 1 && global.civic.foreign[`gov${g}`].sab === 0){
if (global.tech['spy'] && global.tech['spy'] >= 2 && global.civic.foreign[`gov${g}`].spy >= 1 && global.civic.foreign[`gov${g}`].sab <= 0){
let timer = global.tech['spy'] >= 4 ? 150 : 300;
if (global.race['befuddle']){
timer = Math.round(timer * (1 - traits.befuddle.vars()[0] / 100));
Expand All @@ -861,7 +862,7 @@ function drawEspModal(gov){
if (g >= 3){ return; }
let price = govPrice(g);
if (price <= global.resource.Money.amount){
if (global.tech['spy'] && global.tech['spy'] >= 2 && global.civic.foreign[`gov${g}`].spy >= 3 && global.civic.foreign[`gov${g}`].sab === 0){
if (global.tech['spy'] && global.tech['spy'] >= 2 && global.civic.foreign[`gov${g}`].spy >= 3 && global.civic.foreign[`gov${g}`].sab <= 0){
global.resource.Money.amount -= price;
let timer = global.tech['spy'] >= 4 ? 150 : 300;
if (global.race['befuddle']){
Expand Down
6 changes: 3 additions & 3 deletions src/governor.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ export const gov_tasks = {
let min = global.tech['world_control'] ? 3 : 0;
for (let i=min; i<max; i++){
let cost = govCivics('s_cost',i);
if (!global.civic.foreign[`gov${i}`].anx && !global.civic.foreign[`gov${i}`].buy && !global.civic.foreign[`gov${i}`].occ && global.civic.foreign[`gov${i}`].trn === 0 && global.resource.Money.amount >= cost && (global.resource.Money.diff >= cost || global.resource.Money.amount + global.resource.Money.diff >= cashCap)){
if (!global.civic.foreign[`gov${i}`].anx && !global.civic.foreign[`gov${i}`].buy && !global.civic.foreign[`gov${i}`].occ && global.civic.foreign[`gov${i}`].trn <= 0 && global.resource.Money.amount >= cost && (global.resource.Money.diff >= cost || global.resource.Money.amount + global.resource.Money.diff >= cashCap)){
govCivics('t_spy',i);
}
}
Expand All @@ -998,7 +998,7 @@ export const gov_tasks = {
let range = global.race['truepath'] && global.tech['rival'] ? [0,1,2,3] : [0,1,2];
if (global.tech['world_control']){ range = [3]; }
range.forEach(function(gov){
if (global.civic.foreign[`gov${gov}`].sab === 0 && global.civic.foreign[`gov${gov}`].spy > 0 && !global.civic.foreign[`gov${gov}`].anx && !global.civic.foreign[`gov${gov}`].buy && !global.civic.foreign[`gov${gov}`].occ){
if (global.civic.foreign[`gov${gov}`].sab <= 0 && global.civic.foreign[`gov${gov}`].spy > 0 && !global.civic.foreign[`gov${gov}`].anx && !global.civic.foreign[`gov${gov}`].buy && !global.civic.foreign[`gov${gov}`].occ){
global.race.governor.config.spyop[`gov${gov}`].every(function (mission){
switch (mission){
case 'influence':
Expand Down Expand Up @@ -1388,4 +1388,4 @@ export const gov_tasks = {
}
}
},
};
};
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9085,14 +9085,14 @@ function midLoop(){
}
for (let i=0; i<espEnd; i++){
if (global.civic.foreign[`gov${i}`].trn > 0){
global.civic.foreign[`gov${i}`].trn--;
if (global.civic.foreign[`gov${i}`].trn === 0){
global.civic.foreign[`gov${i}`].trn -= webWorker.timers.mid * global.settings.gameSpeed / 1000;
if (global.civic.foreign[`gov${i}`].trn <= 0){
global.civic.foreign[`gov${i}`].spy++;
}
}
if (global.civic.foreign[`gov${i}`].sab > 0){
global.civic.foreign[`gov${i}`].sab--;
if (global.civic.foreign[`gov${i}`].sab === 0){
global.civic.foreign[`gov${i}`].sab -= webWorker.timers.mid * global.settings.gameSpeed / 1000;
if (global.civic.foreign[`gov${i}`].sab <= 0){
switch (global.civic.foreign[`gov${i}`].act){
case 'influence':
if (Math.floor(seededRandom(0,4 + spyCatchMod)) === 0){
Expand Down

0 comments on commit 99de001

Please sign in to comment.