Submarine upgrades that change nothing on a cable can't be bought (#198)
Premium submarine terminals and Optical engineering only extend the long-haul modes of the coherent optics. On many cable lengths (all of the Atlantic, and about 17,000-18,500 km like Atlanta to Sydney) neither changes what any optic carries, yet both could be bought. subHelps() compares every optic's rate with and without the upgrade, counting an upgrade that only helps together with the other one. The link panel disables Install with a note, ACT.subUpgrade refuses, and the cable order screen disables the toggle and only quotes and charges picks that still help on the chosen design.
This commit is contained in:
parent
48e6200c53
commit
f4c8400df1
14 changed files with 127 additions and 20 deletions
|
|
@ -898,10 +898,11 @@ test('submarine terminal and engineering upgrades commission independently and c
|
|||
test('new subsea builds include chosen transmission packages in the quote and saved order', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
try {
|
||||
ev("ACT.start({});S.cash=1e9;S.lvl=4;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'lon'});ACT.buildPop({city:'nyc'});UI.lmode='df';UI.dfSrc='cable';openLinkModal('lon','nyc')");
|
||||
const baseline = JSON.parse(ev("JSON.stringify(seaQuote('lon','nyc'))"));
|
||||
ev("ACT.start({});S.cash=1e9;S.lvl=4;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'sin'});ACT.buildPop({city:'lax'});UI.lmode='df';UI.dfSrc='cable';openLinkModal('sin','lax')");
|
||||
// Across the Pacific, where the two packages together lift it from 400G to 800G (#198).
|
||||
const baseline = JSON.parse(ev("JSON.stringify(seaQuote('sin','lax'))"));
|
||||
ev("document.querySelector('#modalCard [data-act=seaPackage][data-args*=terminal]').click();document.querySelector('#modalCard [data-act=seaPackage][data-args*=engineering]').click()");
|
||||
const quote = JSON.parse(ev("JSON.stringify(seaQuote('lon','nyc','standard',{terminal:true,engineering:true}))"));
|
||||
const quote = JSON.parse(ev("JSON.stringify(seaQuote('sin','lax','standard',{terminal:true,engineering:true}))"));
|
||||
assert.equal(quote.days, baseline.days + 210);
|
||||
assert.equal(quote.cost, baseline.cost + 5000000 + 12000000 + baseline.km * 1000);
|
||||
assert.equal(quote.ms, baseline.ms);
|
||||
|
|
@ -972,9 +973,12 @@ test('own subsea cables after #78: refunds of what was paid, upgrades a route ne
|
|||
const syd = JSON.parse(ev("JSON.stringify(S.links.at(-1))"));
|
||||
assert.equal(syd.b, 'syd'); assert.equal(syd.subterminal, syd.ready);
|
||||
ev('S.day=S.links.at(-1).ready'); assert.equal(ev("optG('tp16',S.links.at(-1))"), 400, 'lit across 18,387 km');
|
||||
// upgrades bought later count toward the price; sanitize keeps a sane price and drops junk
|
||||
// engineering adds nothing once the terminals light it (#198); upgrades bought later count toward the price
|
||||
ev("S.links.at(-1).subengineering=undefined;ACT.subUpgrade({id:S.links.at(-1).id,k:'engineering'})");
|
||||
assert.equal(ev('S.links.at(-1).paid'), syd.paid);
|
||||
ev("S.links.at(-1).subterminal=undefined;ACT.subUpgrade({id:S.links.at(-1).id,k:'engineering'})");
|
||||
assert.ok(ev('S.links.at(-1).paid') > syd.paid);
|
||||
// sanitize keeps a sane price and drops junk
|
||||
ev("S.links.at(-1).paid='lots';S.links[0].paid=-5;S=sanitize(S)");
|
||||
assert.equal(ev('S.links.at(-1).paid'), undefined); assert.equal(ev('S.links[0].paid'), undefined);
|
||||
// advice about upgrades only on cables you own
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const { load } = require('./harness');
|
|||
|
||||
function setup(ev) {
|
||||
ev(`ACT.start({});S.cash=1e11;S.lvl=13;S.day=100;for(const g of GOALS)S.done[g.id]=0;
|
||||
S.links=[{id:'cable',a:'lag',b:'bde',kind:'df',own:true,sub:true,sys:'roadm',km:7000,ch:[],day:100,ready:1000,cut:0,mo:1}];`);
|
||||
S.links=[{id:'cable',a:'lag',b:'bde',kind:'df',own:true,sub:true,sys:'roadm',km:15000,ch:[],day:100,ready:1000,cut:0,mo:1}];`);
|
||||
}
|
||||
|
||||
function dates(ev) {
|
||||
|
|
@ -55,7 +55,7 @@ test('packages included in the original order stay aligned with its accelerated
|
|||
const { ev, dom } = load();
|
||||
try {
|
||||
setup(ev);
|
||||
ev("S.won=true;UI.pending={a:'lag',b:'bde'};UI.seaterminal=UI.seaengineering=true;ACT.orderCable();S.links=[S.links.at(-1)]");
|
||||
ev("S.won=true;UI.pending={a:'sin',b:'lax'};UI.seaterminal=UI.seaengineering=true;ACT.orderCable();S.links=[S.links.at(-1)]");
|
||||
assert.equal(ev('S.links[0].subterminal'), ev('S.links[0].ready'));
|
||||
assert.equal(ev('S.links[0].subengineering'), ev('S.links[0].ready'));
|
||||
ev("ACT.crews({id:S.links[0].id})");
|
||||
|
|
@ -129,11 +129,11 @@ test('one-click completion costs the same as repeated crew hires and advances pe
|
|||
const button = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')].find(b => JSON.parse(b.dataset.args).all);
|
||||
assert.ok(button && !button.disabled, 'one-click option is available');
|
||||
const cash = ev('S.cash');
|
||||
assert.ok(button.textContent.includes(ev('fmt$(30*Math.round(15000+7000*6))')), 'full price is shown before purchase');
|
||||
assert.ok(button.textContent.includes(ev('fmt$(30*Math.round(15000+15000*6))')), 'full price is shown before purchase');
|
||||
button.click();
|
||||
const bulkDates = dates(ev), bulkCash = ev('S.cash');
|
||||
assert.deepEqual(bulkDates, [101, 131, 281]);
|
||||
assert.equal(cash - bulkCash, 30 * 57000);
|
||||
assert.equal(cash - bulkCash, 30 * 105000);
|
||||
const after = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')];
|
||||
assert.ok(after.every(b => b.disabled), 'both options stop at one day');
|
||||
ev("ACT.crews({id:'cable',all:1})");
|
||||
|
|
@ -150,18 +150,18 @@ test('one-click completion is atomic when unaffordable and handles short or comp
|
|||
const { ev, dom } = load();
|
||||
try {
|
||||
setup(ev);
|
||||
ev("S.cash=30*57000-1;UI.sel={type:'link',id:'cable'};renderPanel()");
|
||||
ev("S.cash=30*105000-1;UI.sel={type:'link',id:'cable'};renderPanel()");
|
||||
const bulk = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')].find(b => JSON.parse(b.dataset.args).all);
|
||||
assert.equal(bulk.disabled, true);
|
||||
ev("ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.cash'), 30 * 57000 - 1);
|
||||
assert.equal(ev('S.cash'), 30 * 105000 - 1);
|
||||
assert.equal(ev('S.links[0].ready'), 1000, 'no partial purchase');
|
||||
ev("S.cash=57000;S.links[0].ready=102;ACT.crews({id:'cable',all:1})");
|
||||
ev("S.cash=105000;S.links[0].ready=102;ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.cash'), 0);
|
||||
assert.equal(ev('S.links[0].ready'), 101, 'two days remaining costs one normal hire');
|
||||
assert.match(dom.window.document.body.textContent, /Construction is 1 day ahead\./);
|
||||
ev("S.cash=57000;S.day=101;ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.cash'), 57000, 'completed construction cannot be rushed');
|
||||
ev("S.cash=105000;S.day=101;ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.cash'), 105000, 'completed construction cannot be rushed');
|
||||
ev("S.day=100;S.links[0].ready=1000;S.links[0].own=false;ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.links[0].ready'), 1000, 'leased handovers cannot buy construction crews');
|
||||
} finally { dom.window.close(); }
|
||||
|
|
|
|||
86
tests/useless-subsea-upgrades.test.js
Normal file
86
tests/useless-subsea-upgrades.test.js
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// #198: submarine upgrades that change nothing on a cable can't be bought.
|
||||
function cable(ev, km) {
|
||||
ev(`ACT.start({});S.cash=1e11;S.lvl=13;S.day=100;S.won=true;for(const g of GOALS)S.done[g.id]=0;
|
||||
S.links=[{id:'c',a:'atn',b:'syd',kind:'df',own:true,sub:true,sys:'roadm',km:${km},ch:['tp16'],day:0,ready:50,cut:0,mo:1}];
|
||||
UI.sel={type:'link',id:'c'};renderPanel()`);
|
||||
}
|
||||
const installBtn = (dom, k) => dom.window.document.querySelector(`#panelBody [data-act=subUpgrade][data-args*="${k}"]`);
|
||||
|
||||
test('#198 upgrades that do nothing on a long Pacific cable are disabled and refused', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
try {
|
||||
cable(ev, 17500); // about Atlanta to Sydney: 400G per channel with or without upgrades
|
||||
for (const k of ['terminal', 'engineering']) {
|
||||
assert.equal(installBtn(dom, k).disabled, true, `${k} button disabled`);
|
||||
const cash = ev('S.cash');
|
||||
ev(`ACT.subUpgrade({id:'c',k:'${k}'})`);
|
||||
assert.equal(ev('S.cash'), cash, `${k}: no charge`);
|
||||
assert.equal(ev(`S.links[0].sub${k}`), undefined, `${k}: not installed`);
|
||||
}
|
||||
assert.match(dom.window.document.getElementById('panelBody').textContent, /Makes no difference on this cable/);
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
||||
test('#198 upgrades that only help together stay buyable, and one made useless by the other is not', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
try {
|
||||
cable(ev, 15000); // each alone: 400G, both: 800G
|
||||
assert.equal(installBtn(dom, 'terminal').disabled, false);
|
||||
assert.equal(installBtn(dom, 'engineering').disabled, false);
|
||||
ev("ACT.subUpgrade({id:'c',k:'terminal'})");
|
||||
assert.ok(ev('S.links[0].subterminal') > 0, 'terminal bought');
|
||||
ev('renderPanel()');
|
||||
assert.equal(installBtn(dom, 'engineering').disabled, false, 'engineering finishes the job');
|
||||
ev("ACT.subUpgrade({id:'c',k:'engineering'})");
|
||||
assert.ok(ev('S.links[0].subengineering') > 0, 'engineering bought');
|
||||
|
||||
cable(ev, 20000); // terminal lights it; engineering adds nothing once terminal is in
|
||||
ev("ACT.subUpgrade({id:'c',k:'terminal'});renderPanel()");
|
||||
assert.ok(ev('S.links[0].subterminal') > 0);
|
||||
assert.equal(installBtn(dom, 'engineering').disabled, true);
|
||||
ev("ACT.subUpgrade({id:'c',k:'engineering'})");
|
||||
assert.equal(ev('S.links[0].subengineering'), undefined);
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
||||
test('#198 ordering a cable: useless upgrades can not be picked, and stale picks are not charged', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
try {
|
||||
ev("ACT.start({});S.cash=1e11;S.lvl=13;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'lon'});ACT.buildPop({city:'nyc'});UI.lmode='df';UI.dfSrc='cable';UI.seaDesign='standard';openLinkModal('lon','nyc')");
|
||||
// A transatlantic cable already runs every optic at its long-haul best.
|
||||
const btn = k => dom.window.document.querySelector(`#modalCard [data-act=seaPackage][data-args*="${k}"]`);
|
||||
assert.equal(btn('terminal').disabled, true);
|
||||
assert.equal(btn('engineering').disabled, true);
|
||||
ev("ACT.seaPackage({k:'terminal'})");
|
||||
assert.equal(ev('!!UI.seaterminal'), false, 'refused');
|
||||
// Picks left over from a longer route (or a different design) neither show as picked nor get charged.
|
||||
ev("UI.seaterminal=true;UI.seaengineering=true;ACT.seaDesign({v:'standard'})");
|
||||
assert.equal(btn('terminal').textContent.includes('✓'), false);
|
||||
assert.equal(btn('engineering').textContent.includes('✓'), false);
|
||||
const cash = ev('S.cash'), cost = ev("seaQuote('lon','nyc','standard').cost");
|
||||
ev('ACT.orderCable()');
|
||||
assert.equal(cash - ev('S.cash'), cost, 'no upgrade charged');
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
||||
test('#198 ordering a transpacific cable: both upgrades help together, and the redundant one of a pair drops out', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
try {
|
||||
ev("ACT.start({});S.cash=1e11;S.lvl=13;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'sin'});ACT.buildPop({city:'lax'});UI.lmode='df';UI.dfSrc='cable';ACT.ownCab();UI.pending={a:'sin',b:'lax'};openLinkModal('sin','lax')");
|
||||
const km = ev("seaQuote('sin','lax','standard').km");
|
||||
assert.ok(km > 14000 && km < 17000, 'a route where only both upgrades together beat 400G');
|
||||
ev("ACT.seaPackage({k:'terminal'});ACT.seaPackage({k:'engineering'})");
|
||||
assert.equal(ev('!!UI.seaterminal&&!!UI.seaengineering'), true, 'both picked');
|
||||
assert.equal(ev("JSON.stringify(seaUps(seaQuote('sin','lax','standard').km))"), '{"terminal":true,"engineering":true}');
|
||||
// At 20,000 km either one alone lights the cable, so a pair keeps only the cheaper terminals.
|
||||
assert.equal(ev("JSON.stringify(seaUps(20000))"), '{"terminal":true,"engineering":false}');
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { dom.window.close(); }
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue