${btn(tr('link_panels.hire_extra_crews_price_30_days',{price:fmt$(crewCost(l))}),'crews',{id:l.id},'sm',!crewSteps(l)||S.cash
${!crewSteps(l)&&l.ready>S.day+1?`${tr('link_panels.crews_can_halve_a_build_at_most')}
`:''}`:''}${tr('link_panels.you_can_pre_install_optics_now')}
`;}
else if(inc&&linkDown(l))h+=`${tr('common.dark_6bf5')}
${esc(inc.msg)}
${shipNote(inc)}${inc.cost?btn(`${esc(inc.fix||tr('common.rush_repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash`;
h+=`${tr('common.capacity')}
${tr('link_panels.n_of_max_channels_lit',{n:(l.ch||[]).length,max:chMax(l)})}${soldSlots(l)?` · ${tr('link_panels.n_sold_as_alien_waves',{n:soldSlots(l)})}`:''}${fmtG(load)} / ${fmtG(cap)}
${seatPanel(l)}${l.own&&l.sub?`${tr('common.cable_design')}${tr((SEA_DESIGNS[l.seaDesign]||SEA_DESIGNS.standard).n)}
`:''}
diff --git a/src/i18n/en.js b/src/i18n/en.js
index 40031a8..ad8a9de 100644
--- a/src/i18n/en.js
+++ b/src/i18n/en.js
@@ -2636,6 +2636,7 @@
"link_panels.abandon_the_fiber":"Abandon the fiber",
"link_panels.add_parallel_link":"Add parallel link",
"link_panels.additional_traffic_lost":"Additional traffic lost",
+"link_panels.all_crews_done_in_n_days_price":{"one":"All the crews: done in {n} day {price}","other":"All the crews: done in {n} days {price}"},
"link_panels.an_alternate_path_exists_but_current":"An alternate path exists, but current routing and capacity deliver less traffic.",
"link_panels.apply_for_a_license_price_mo_n_days":"Apply for a license {price} + {mo}/mo · ~{n} days",
"link_panels.at_this_pop_net_s_traffic_always":"At this POP, {net}'s traffic always uses this port. POPs without one use their nearest transit port.",
@@ -2652,6 +2653,7 @@
"link_panels.connected_but_tight":"Connected, but tight.",
"link_panels.cost_on_this_link_w_allowed":"Cost on this link: {w}. Allowed: {lo} to {hi}.",
"link_panels.cost_the_exact_number_whatever_the":"Cost: the exact number, whatever the distance.",
+"link_panels.crews_can_halve_a_build_at_most":"Permits and rights of way set the pace: extra crews can cut a build to half its planned time, no further.",
"link_panels.dark_fiber_kind_km_km":"Dark fiber · {kind} · {km} km",
"link_panels.de_kicks_personalised_pricing_p_of":"DE-KICKS personalised pricing: {p}% of what a normal IX would charge (promo, {n} days left).",
"link_panels.de_kicks_personalised_pricing_p_of_3d4f":"DE-KICKS personalised pricing: {p}% of what a normal IX would charge.",
@@ -2659,7 +2661,6 @@
"link_panels.each_channel_is_a_pair_of":"Each channel is a pair of optics, one per end. ZR+ optics plug straight into your routers. Transponders sit on a shelf.",
"link_panels.enters_your_network_at":"Enters your network at",
"link_panels.every_pop_carries_net_s_traffic":"Every POP carries {net}'s traffic across your network to this port.",
-"link_panels.finish_in_1_day_price":"Finish in 1 day {price}",
"link_panels.foreign_networks_need_a_local_joint":"Foreign networks need a local joint venture and an operating license to build infrastructure here.",
"link_panels.found_your_own_ix_cost_mo":"Found your own IX {cost} + {mo}/mo",
"link_panels.full_links_during_the_test":"Full links during the test",
diff --git a/tests/alien-wave-rent.test.js b/tests/alien-wave-rent.test.js
new file mode 100644
index 0000000..9bd353e
--- /dev/null
+++ b/tests/alien-wave-rent.test.js
@@ -0,0 +1,67 @@
+// #203: renting out alien waves was a money machine. A wave is now priced against what the fiber itself costs, and gets
+// cheaper as a route fills; extra crews cut a build to half its planned time at most; a typed order cannot end a link
+// in a city the map does not show.
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const { load } = require('./harness');
+
+const fiber = (ev, id, a, b, km) => ev(`S.links.push({id:'${id}',a:'${a}',b:'${b}',kind:'df',own:true,sys:'cl',ch:[],km:${km},ready:0,day:0,cut:0,mo:1,trench:'own:${id}',pairs:1})`);
+const sell = (ev, id) => ev(`(()=>{const l=S.links.find(x=>x.id==='${id}'),r=wwRate(l,1);S.biz.push({id:uid(),type:'wwave',link:l.id,slots:1,rate:r,city:l.a,city2:l.b,name:'n'+S.biz.length,bw:1,mood:80,since:0,reqs:[]});return r})()`);
+
+test('#203 an alien wave rents for a share of the fiber, and each one sold on a route makes the next cheaper', () => {
+ const { ev, errors } = load();
+ ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;S.biz=[];S.offers=[];for(const c of ['lon','nyc'])if(!S.pops[c])ACT.buildPop({city:c})");
+ fiber(ev, 'f', 'lon', 'nyc', 5570);
+ const F = ev('dfLeaseMo(5570)+ampCount(5570)*AMP_MO'), M = ev("brMarket('lon','nyc')");
+ const rates = [];
+ for (let i = 0; i < M; i++) rates.push(sell(ev, 'f'));
+ assert.ok(rates[0] <= 0.3 * F + 1, `the first wave costs at most 30% of the fiber: ${rates[0]} vs ${F}`);
+ for (let i = 1; i < rates.length; i++) assert.ok(rates[i] <= rates[i - 1], 'never dearer than the one before');
+ assert.ok(rates.at(-1) < rates[0] * 0.45, 'the last waves of a full route go cheap');
+ const full = rates.reduce((a, b) => a + b, 0);
+ assert.ok(full / F > 2 && full / F < 8, `a full route earns a few times its lease, not dozens: ${(full / F).toFixed(1)}×`);
+ // The old price: one wave cost about as much as the whole fiber, and a full route earned ~29× its lease.
+ assert.ok(full < ev(`Math.round(waveMo(5570,false,2)*0.55)*${M}`) / 3);
+ // A random offer and a broker sale on the same route follow the same price.
+ fiber(ev, 'g', 'lon', 'nyc', 5570);
+ ev("S.biz=[]");
+ assert.equal(ev("(()=>{let n=0;const o=fiberOffer('wwave',S.links.find(l=>l.id==='g'),()=>'x');return o.rate===wwRate(S.links.find(l=>l.id==='g'),o.slots)})()"), true);
+ assert.deepEqual(errors, []);
+});
+
+test('#203 extra crews cut a build to half its planned time, no further', () => {
+ const { ev, errors, dom } = load();
+ ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=4;for(const c of ['fra','waw'])if(!S.pops[c])ACT.buildPop({city:c})");
+ const km = Math.round(ev("kmBetween('fra','waw')")), days = ev(`dfBuildDays(${km})`);
+ ev(`S.links.push({id:'b',a:'fra',b:'waw',kind:'df',own:true,sys:'roadm',ch:[],km:${km},ready:S.day+${days},day:S.day,cut:0,mo:1,trench:'own:b',pairs:1});after();UI.sel={type:'link',id:'b'};renderPanel()`);
+ const start = ev('S.day');
+ assert.match(ev("document.getElementById('panelBody').textContent"), new RegExp(`All the crews: done in ${Math.ceil(days / 2)} days`));
+ const cash = ev('S.cash');
+ ev("ACT.crews({id:'b',all:1})");
+ assert.equal(ev("S.links.find(l=>l.id==='b').ready"), start + Math.ceil(days / 2), 'half the planned build');
+ assert.ok(ev('S.cash') < cash);
+ const c2 = ev('S.cash');
+ ev("ACT.crews({id:'b'});ACT.crews({id:'b',all:1})");
+ assert.equal(ev('S.cash'), c2, 'no more crews to buy');
+ ev('renderPanel()');
+ const crews = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')];
+ assert.ok(crews.length && crews.every((b) => b.disabled));
+ assert.match(ev("document.getElementById('panelBody').textContent"), /half its planned time/);
+ // Phone: the panel still renders with the note.
+ ev("window.innerWidth=360;renderAll()");
+ assert.deepEqual(errors, []);
+});
+
+test('#203 a dark fiber, cable or wave cannot be ordered to a city the map does not show', () => {
+ const { ev, errors } = load();
+ ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6");
+ ev("ACT.buildPop({city:'sao'})");
+ const home = 'sao', off = ev("(()=>{const c=CITIES.find(c=>c.off&&!cityOn(c.id)&&dfAllowed('sao',c.id));return c?c.id:null})()");
+ assert.ok(off, 'there is a hidden city to try');
+ const pops = ev('Object.keys(S.pops).length');
+ ev(`UI.pending={a:'${home}',b:'${off}'};UI.dfSrc='lease';UI.dfSys='lite';ACT.orderDf()`);
+ ev(`UI.pending={a:'${home}',b:'${off}'};ACT.buildLink({tier:0})`);
+ assert.equal(ev('Object.keys(S.pops).length'), pops, 'no POP appears there');
+ assert.equal(ev(`S.links.some(l=>l.b==='${off}'||l.a==='${off}')`), false);
+ assert.deepEqual(errors, []);
+});
diff --git a/tests/cable-ships.test.js b/tests/cable-ships.test.js
index 5d00697..aea5daa 100644
--- a/tests/cable-ships.test.js
+++ b/tests/cable-ships.test.js
@@ -187,7 +187,7 @@ test('your own subsea cable: survey and factory first, then a lay ship; a second
assert.match(panel(), /Survey, permits and the cable factory/);
assert.match(panel(), /Laying starts in 560 days/);
assert.match(panel(), /Book a second lay ship/);
- assert.doesNotMatch(panel(), /Hire extra crews|Finish in 1 day/);
+ assert.doesNotMatch(panel(), /Hire extra crews|All the crews/);
const cash = ev('S.cash');
ev("ACT.crews({id:'own'})");
assert.equal(ev('S.cash'), cash, 'no crews at sea');
diff --git a/tests/gameplay-rules.test.js b/tests/gameplay-rules.test.js
index e40b5fa..bc0a0e1 100644
--- a/tests/gameplay-rules.test.js
+++ b/tests/gameplay-rules.test.js
@@ -412,6 +412,31 @@ test('F5: rented capacity never outgrows the route\'s market (#203)', () => {
assert.deepEqual(g.errors, []);
});
+test('F6: an alien wave is priced against its fiber, and a full route earns a few times its lease (#203)', () => {
+ const g = load();
+ g.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;S.biz=[];S.offers=[]");
+ for (const [a, b] of [['lon', 'par'], ['lon', 'nyc'], ['fra', 'sin'], ['nyc', 'sjc'], ['jed', 'gdx']]) {
+ const r = JSON.parse(g.ev(`(()=>{const l={id:'f6${a}${b}',a:'${a}',b:'${b}',kind:'df',own:true,sys:'cl',ch:[],km:Math.round(kmBetween('${a}','${b}')),ready:0,day:0,cut:0,mo:1,pairs:2};S.links.push(l);
+ const F=dfLeaseMo(l.km)+ampCount(l.km)*AMP_MO,M=brMarket(l.a,l.b),rs=[];
+ for(let i=0;i x + y, 0);
+ assert.ok(full < 8 * r.F, `F6: ${a}-${b} full route ${(full / r.F).toFixed(1)}× its lease`);
+ }
+ assert.deepEqual(g.errors, []);
+});
+
+test('F7: extra crews cut a build on land to half its planned time at most (#203)', () => {
+ const g = load();
+ g.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e11;S.lvl=4;for(const c of ['fra','mad'])if(!S.pops[c])ACT.buildPop({city:c})");
+ const km = Math.round(g.ev("kmBetween('fra','mad')")), days = g.ev(`dfBuildDays(${km})`), d0 = g.ev('S.day');
+ g.ev(`S.links.push({id:'f7',a:'fra',b:'mad',kind:'df',own:true,sys:'roadm',ch:[],km:${km},ready:S.day+${days},day:S.day,cut:0,mo:1,trench:'own:f7',pairs:1});ACT.crews({id:'f7',all:1});for(let i=0;i<50;i++)ACT.crews({id:'f7'})`);
+ assert.ok(g.ev("S.links.find(l=>l.id==='f7').ready") - d0 >= days / 2, 'F7: never under half the planned build');
+ assert.deepEqual(g.errors, []);
+});
+
// D1–D4: DDoS as networks see it (#242). tests/ddos-model.test.js plays each one in detail.
const ddFra = (ev) => ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=4;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=40;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.pops.fra.rgen=RG.findIndex(r=>r.fsN===8);S.biz.push({id:'g',type:'game',name:'G',city:'fra',bw:10,rate:1,mood:80,since:0,reqs:[]},{id:'d',type:'dia',name:'D',city:'fra',bw:5,rate:1,mood:80,since:0,reqs:[]});compute()");
const ddHit = (ev, g) => ev(`S.ev.ddos={id:'x',city:'fra',tgt:'g',vec:'dns',gbps:${g},start:S.day,until:S.day+2,bh:false};compute()`);
diff --git a/tests/issues.test.js b/tests/issues.test.js
index 09271f2..c2e22ad 100644
--- a/tests/issues.test.js
+++ b/tests/issues.test.js
@@ -1267,7 +1267,7 @@ test('#51 a dark fiber shows what is rented out, and spare capacity can be liste
ev("for(let i=0;i<120&&!S.biz.some(b=>b.link==='df1');i++)brTick();renderPanel()");
const b = JSON.parse(ev("JSON.stringify(S.biz.find(x=>x.link==='df1'))"));
assert.equal(b.type, 'wwave');
- assert.equal(b.rate, ev(`Math.round(waveMo(450,false,2)*0.55*${b.slots}*0.9)`), 'the usual alien-wave price minus the broker');
+ assert.equal(b.rate, ev(`(()=>{const F=dfLeaseMo(450)+ampCount(450)*AMP_MO,M=brMarket('fra','ams');let r=0;for(let i=0;i<${b.slots};i++)r+=F*WW_SHARE*(1-WW_FALL*Math.min(1,i/M));return Math.round(r*0.9)})()`), 'the alien-wave price, priced against the fiber, minus the broker');
assert.ok(txt().includes(b.name), 'the customer is listed on the fiber');
assert.match(txt(), new RegExp(`Free channels\\s*${62 - b.slots} / 64`));
assert.equal(ev("S.links[0].list?S.links[0].list.w:0"), 4 - b.slots, 'the listing shrinks by what sold');
diff --git a/tests/subsea-upgrade-timing.test.js b/tests/subsea-upgrade-timing.test.js
index 77a7bde..30e26b2 100644
--- a/tests/subsea-upgrade-timing.test.js
+++ b/tests/subsea-upgrade-timing.test.js
@@ -8,6 +8,12 @@ function setup(ev, sub = true) {
S.links=[{id:'cable',a:'lag',b:'bde',kind:'df',own:true,sub:${sub},sys:'roadm',km:15000,ch:[],day:100,ready:1000,cut:0,mo:1}];`);
}
+// Crews cut a land build to half its planned time at most (#203): plan these builds long enough that crews can still
+// bring them to tomorrow, so the tests below check the price and the one-click purchase.
+function plannedLong(ev) {
+ ev('S.links[0].day=101-Math.ceil(dfBuildDays(S.links[0].km)/2)');
+}
+
function dates(ev) {
return JSON.parse(ev('JSON.stringify([S.links[0].ready,S.links[0].subterminal,S.links[0].subengineering])'));
}
@@ -126,6 +132,7 @@ test('one-click completion on land costs the same as repeated crew hires', () =>
const { ev, dom, errors } = load();
try {
setup(ev, false);
+ plannedLong(ev);
ev("UI.sel={type:'link',id:'cable'};renderPanel()");
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');
@@ -140,6 +147,7 @@ test('one-click completion on land costs the same as repeated crew hires', () =>
ev("ACT.crews({id:'cable',all:1})");
assert.equal(ev('S.cash'), bulkCash, 'repeat submission cannot charge again');
setup(ev, false);
+ plannedLong(ev);
ev("for(let i=0;i<30;i++)ACT.crews({id:'cable'})");
assert.equal(ev('S.links[0].ready'), bulkReady);
assert.equal(ev('S.cash'), bulkCash);
@@ -156,6 +164,7 @@ test('one-click completion is atomic when unaffordable and handles short or comp
const { ev, dom } = load();
try {
setup(ev, false);
+ plannedLong(ev);
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);
@@ -177,7 +186,9 @@ test('owned ground fiber exposes the one-click button and uses the same crew pri
const { ev, dom, errors } = load();
try {
setup(ev);
- ev("ACT.buildPop({city:'ams'});Object.assign(S.links[0],{a:'fra',b:'ams',sub:false,km:800,ready:191});UI.sel={type:'link',id:'cable'};renderPanel()");
+ ev("ACT.buildPop({city:'ams'});Object.assign(S.links[0],{a:'fra',b:'ams',sub:false,km:800,ready:191})");
+ plannedLong(ev);
+ ev("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.ok(bulk && !bulk.disabled, 'ground construction has the same one-click control');
assert.ok(bulk.textContent.includes(ev('fmt$(3*(15000+800*6))')), '91 days remaining requires three hires');