From a64ed31bd613e063fc873daf3316521f68c0a50f Mon Sep 17 00:00:00 2001 From: yarukishi <150128243+yarukishi@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:05:54 +0900 Subject: [PATCH 1/2] Fix broken ore processors (#1283) Two different loops were using the galaxy_ship_types structure. The first one correctly powered ore processors (replacing the earlier foothold station loop that was deleted in #1265). However, the second loop checked for crew, and ore processors have no civilian or military crew requirements, so it always set `gal_on['ore_processor'] = 0`. --- src/main.js | 99 ++++++++++++++++++----------------------------------- 1 file changed, 33 insertions(+), 66 deletions(-) diff --git a/src/main.js b/src/main.js index ad409d7e6c..e79e51bde4 100644 --- a/src/main.js +++ b/src/main.js @@ -2755,21 +2755,25 @@ function fastLoop(){ let crew_civ = 0; let crew_mil = 0; let total = 0; + let andromeda_helium = 0; + let andromeda_deuterium = 0; for (let j=0; j 0 : true; const support_home = actions[area][region].info?.support; let used_support = 0; for (let i=0; i 0){ const max_operating = Math.floor((global[area][support_home].s_max - used_support) / operating_cost); @@ -2826,6 +2830,28 @@ function fastLoop(){ operating = Math.min(operating, Math.floor(global[area][ship].mil / milPerShip)); } } + + if (actions[area][region][ship].ship.hasOwnProperty('helium')){ + let increment = +int_fuel_adjust(actions[area][region][ship].ship.helium).toFixed(2); + let consume = operating * increment; + while (consume * time_multiplier > global.resource.Helium_3.amount + (global.resource.Helium_3.diff > 0 ? global.resource.Helium_3.diff * time_multiplier : 0) && operating > 0){ + consume -= increment; + operating--; + } + modRes('Helium_3', -(consume * time_multiplier)); + andromeda_helium += consume; + } + + if (actions[area][region][ship].ship.hasOwnProperty('deuterium')){ + let increment = +int_fuel_adjust(actions[area][region][ship].ship.deuterium).toFixed(2); + let consume = operating * increment; + while (consume * time_multiplier > global.resource.Deuterium.amount + (global.resource.Deuterium.diff > 0 ? global.resource.Deuterium.diff * time_multiplier : 0) && operating > 0){ + consume -= increment; + operating--; + } + modRes('Deuterium', -(consume * time_multiplier)); + andromeda_deuterium += consume; + } } if (operating < num_on){ @@ -2838,17 +2864,17 @@ function fastLoop(){ } used_support += operating * operating_cost; - gal_on[ship] = operating; - } - else { - gal_on[ship] = 0; } + gal_on[ship] = operating; } if (support_home && global?.[area]?.[support_home]?.hasOwnProperty('support')){ global[area][support_home].support = used_support; } } + breakdown.p.consume.Helium_3[loc('galaxy_fuel_consume')] = -(andromeda_helium); + breakdown.p.consume.Deuterium[loc('galaxy_fuel_consume')] = -(andromeda_deuterium); + global.civic.crew.workers = crew_civ; if (global.civic.garrison.hasOwnProperty('crew')){ if (global.space.hasOwnProperty('shipyard') && global.space.shipyard.hasOwnProperty('ships')){ @@ -3838,65 +3864,6 @@ function fastLoop(){ } } - let andromeda_helium = 0; - let andromeda_deuterium = 0; - - for (let j=0; j 0 ? true : false) : true; - if (p_on['s_gate'] && req && global[area][ship] && (global[area][ship].crew > 0 || global[area][ship].mil > 0)){ - let operating = 0; - if (actions[area][region][ship].ship.civ() > 0){ - operating = Math.floor(global[area][ship].crew / actions[area][region][ship].ship.civ()); - } - if (actions[area][region][ship].ship.mil() > 0){ - let mil_operating = Math.floor(global[area][ship].mil / actions[area][region][ship].ship.mil()); - if (actions[area][region][ship].ship.civ() === 0 || mil_operating < operating){ - operating = mil_operating; - } - } - - if (actions[area][region][ship].ship.hasOwnProperty('helium')){ - let increment = +int_fuel_adjust(actions[area][region][ship].ship.helium).toFixed(2); - let consume = (operating * increment); - while (consume * time_multiplier > global.resource.Helium_3.amount + (global.resource.Helium_3.diff > 0 ? global.resource.Helium_3.diff * time_multiplier : 0) && consume > 0){ - consume -= increment; - operating--; - } - modRes('Helium_3', -(consume * time_multiplier)); - andromeda_helium += consume; - } - - if (actions[area][region][ship].ship.hasOwnProperty('deuterium')){ - let increment = +int_fuel_adjust(actions[area][region][ship].ship.deuterium).toFixed(2); - let consume = (operating * increment); - while (consume * time_multiplier > global.resource.Deuterium.amount + (global.resource.Deuterium.diff > 0 ? global.resource.Deuterium.diff * time_multiplier : 0) && consume > 0){ - consume -= increment; - operating--; - } - modRes('Deuterium', -(consume * time_multiplier)); - andromeda_deuterium += consume; - } - - if (gal_on.hasOwnProperty(ship)){ - gal_on[ship] = gal_on[ship] > operating ? operating : gal_on[ship]; - } - else { - gal_on[ship] = operating; - } - } - else { - gal_on[ship] = 0; - } - } - } - - breakdown.p.consume.Helium_3[loc('galaxy_fuel_consume')] = -(andromeda_helium); - breakdown.p.consume.Deuterium[loc('galaxy_fuel_consume')] = -(andromeda_deuterium); - if (global.space['shipyard'] && global.space.shipyard['ships']){ let fuels = { Oil: 0, From e29137400daad9400b914953fd51918526721985 Mon Sep 17 00:00:00 2001 From: yarukishi <150128243+yarukishi@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:35:20 +0900 Subject: [PATCH 2/2] Don't clutter gal_on[] with tech-blocked structs The change looks big because of whitespace, but it's just 4 lines if you ignore the whitespace. --- src/main.js | 169 ++++++++++++++++++++++++++-------------------------- 1 file changed, 85 insertions(+), 84 deletions(-) diff --git a/src/main.js b/src/main.js index e79e51bde4..1aa7ced481 100644 --- a/src/main.js +++ b/src/main.js @@ -2766,106 +2766,107 @@ function fastLoop(){ let used_support = 0; for (let i=0; i 0){ - const max_operating = Math.floor((global[area][support_home].s_max - used_support) / operating_cost); - operating = Math.min(operating, max_operating); - } - - if (actions[area][region][ship].hasOwnProperty('ship')){ - if (actions[area][region][ship].ship.civ && global[area][ship].hasOwnProperty('crew')){ - // Civilian ships can only be crewed at a rate of 1 ship (per type) per fast tick - let civPerShip = actions[area][region][ship].ship.civ(); - if (civPerShip > 0){ - if (global[area][ship].crew < 0){ - global[area][ship].crew = 0; - } - if (global[area][ship].crew < operating * civPerShip){ - if (total < global.resource[global.race.species].amount){ - if (global.civic[global.civic.d_job].workers >= civPerShip){ - global.civic[global.civic.d_job].workers -= civPerShip; - global.civic.crew.workers += civPerShip; - global[area][ship].crew += civPerShip; + if (global[area][ship]){ + let operating = 0; + if (global[area][ship].hasOwnProperty('on') && req && (p_on['s_gate'] || area !== 'galaxy')){ + const id = actions[area][region][ship].id; + const num_on = global[area][ship].on; + operating = num_on; + + // Support cost + const operating_cost = actions[area][region][ship].hasOwnProperty('support') ? -(actions[area][region][ship].support()) : 0; + if (operating_cost > 0){ + const max_operating = Math.floor((global[area][support_home].s_max - used_support) / operating_cost); + operating = Math.min(operating, max_operating); + } + + if (actions[area][region][ship].hasOwnProperty('ship')){ + if (actions[area][region][ship].ship.civ && global[area][ship].hasOwnProperty('crew')){ + // Civilian ships can only be crewed at a rate of 1 ship (per type) per fast tick + let civPerShip = actions[area][region][ship].ship.civ(); + if (civPerShip > 0){ + if (global[area][ship].crew < 0){ + global[area][ship].crew = 0; + } + if (global[area][ship].crew < operating * civPerShip){ + if (total < global.resource[global.race.species].amount){ + if (global.civic[global.civic.d_job].workers >= civPerShip){ + global.civic[global.civic.d_job].workers -= civPerShip; + global.civic.crew.workers += civPerShip; + global[area][ship].crew += civPerShip; + } } } + else if (global[area][ship].crew > operating * civPerShip){ + global.civic[global.civic.d_job].workers += civPerShip; + global.civic.crew.workers -= civPerShip; + global[area][ship].crew -= civPerShip; + } + global.civic.crew.assigned = global.civic.crew.workers; + crew_civ += global[area][ship].crew; + total += global[area][ship].crew; + operating = Math.min(operating, Math.floor(global[area][ship].crew / civPerShip)); } - else if (global[area][ship].crew > operating * civPerShip){ - global.civic[global.civic.d_job].workers += civPerShip; - global.civic.crew.workers -= civPerShip; - global[area][ship].crew -= civPerShip; - } - global.civic.crew.assigned = global.civic.crew.workers; - crew_civ += global[area][ship].crew; - total += global[area][ship].crew; - operating = Math.min(operating, Math.floor(global[area][ship].crew / civPerShip)); } - } - if (actions[area][region][ship].ship.mil && global[area][ship].hasOwnProperty('mil')){ - // All military ships can be crewed instantly - let milPerShip = actions[area][region][ship].ship.mil(); - if (milPerShip > 0){ - if (global[area][ship].mil !== operating * milPerShip){ - global[area][ship].mil = operating * milPerShip; - } - if (global.civic.garrison.workers - global.portal.fortress.garrison < 0){ - let underflow = global.civic.garrison.workers - global.portal.fortress.garrison; - global[area][ship].mil -= underflow; - } - if (crew_mil + global[area][ship].mil > global.civic.garrison.workers - global.portal.fortress.garrison){ - global[area][ship].mil = global.civic.garrison.workers - global.portal.fortress.garrison - crew_mil; + if (actions[area][region][ship].ship.mil && global[area][ship].hasOwnProperty('mil')){ + // All military ships can be crewed instantly + let milPerShip = actions[area][region][ship].ship.mil(); + if (milPerShip > 0){ + if (global[area][ship].mil !== operating * milPerShip){ + global[area][ship].mil = operating * milPerShip; + } + if (global.civic.garrison.workers - global.portal.fortress.garrison < 0){ + let underflow = global.civic.garrison.workers - global.portal.fortress.garrison; + global[area][ship].mil -= underflow; + } + if (crew_mil + global[area][ship].mil > global.civic.garrison.workers - global.portal.fortress.garrison){ + global[area][ship].mil = global.civic.garrison.workers - global.portal.fortress.garrison - crew_mil; + } + if (global[area][ship].mil < 0){ + global[area][ship].mil = 0; + } + crew_mil += global[area][ship].mil; + operating = Math.min(operating, Math.floor(global[area][ship].mil / milPerShip)); } - if (global[area][ship].mil < 0){ - global[area][ship].mil = 0; + } + + if (actions[area][region][ship].ship.hasOwnProperty('helium')){ + let increment = +int_fuel_adjust(actions[area][region][ship].ship.helium).toFixed(2); + let consume = operating * increment; + while (consume * time_multiplier > global.resource.Helium_3.amount + (global.resource.Helium_3.diff > 0 ? global.resource.Helium_3.diff * time_multiplier : 0) && operating > 0){ + consume -= increment; + operating--; } - crew_mil += global[area][ship].mil; - operating = Math.min(operating, Math.floor(global[area][ship].mil / milPerShip)); + modRes('Helium_3', -(consume * time_multiplier)); + andromeda_helium += consume; } - } - if (actions[area][region][ship].ship.hasOwnProperty('helium')){ - let increment = +int_fuel_adjust(actions[area][region][ship].ship.helium).toFixed(2); - let consume = operating * increment; - while (consume * time_multiplier > global.resource.Helium_3.amount + (global.resource.Helium_3.diff > 0 ? global.resource.Helium_3.diff * time_multiplier : 0) && operating > 0){ - consume -= increment; - operating--; + if (actions[area][region][ship].ship.hasOwnProperty('deuterium')){ + let increment = +int_fuel_adjust(actions[area][region][ship].ship.deuterium).toFixed(2); + let consume = operating * increment; + while (consume * time_multiplier > global.resource.Deuterium.amount + (global.resource.Deuterium.diff > 0 ? global.resource.Deuterium.diff * time_multiplier : 0) && operating > 0){ + consume -= increment; + operating--; + } + modRes('Deuterium', -(consume * time_multiplier)); + andromeda_deuterium += consume; } - modRes('Helium_3', -(consume * time_multiplier)); - andromeda_helium += consume; } - if (actions[area][region][ship].ship.hasOwnProperty('deuterium')){ - let increment = +int_fuel_adjust(actions[area][region][ship].ship.deuterium).toFixed(2); - let consume = operating * increment; - while (consume * time_multiplier > global.resource.Deuterium.amount + (global.resource.Deuterium.diff > 0 ? global.resource.Deuterium.diff * time_multiplier : 0) && operating > 0){ - consume -= increment; - operating--; - } - modRes('Deuterium', -(consume * time_multiplier)); - andromeda_deuterium += consume; + if (operating < num_on){ + $(`#${id} .on`).addClass('warn'); + $(`#${id} .on`).prop('title',`ON ${operating}/${num_on}`); + } + else { + $(`#${id} .on`).removeClass('warn'); + $(`#${id} .on`).prop('title',`ON`); } - } - if (operating < num_on){ - $(`#${id} .on`).addClass('warn'); - $(`#${id} .on`).prop('title',`ON ${operating}/${num_on}`); - } - else { - $(`#${id} .on`).removeClass('warn'); - $(`#${id} .on`).prop('title',`ON`); + used_support += operating * operating_cost; } - - used_support += operating * operating_cost; + gal_on[ship] = operating; } - gal_on[ship] = operating; } if (support_home && global?.[area]?.[support_home]?.hasOwnProperty('support')){ global[area][support_home].support = used_support;