Alien waves priced against their fiber; crews halve a build at most (#203)

An alien wave rented for about as much as leasing the whole fiber, so a
route sold out to its market earned 11 to 35 times its lease and the
gear paid back in one to three months. A wave now rents for 30% of the
fiber's monthly cost (lease plus amplifiers), and each one sold between
the same two cities goes cheaper, down to 40% of the first: a full
route earns 2 to 6 times its lease. Signed contracts keep their price.
Gameplay rule F6.

Extra crews could bring any land build to the next day. They now cut it
to half its planned time at most, and the button says when it would be
done. Gameplay rule F7.

A typed order (the agent API) could end a wave, dark fiber or cable in a
city the map does not show, and opened a POP there.
This commit is contained in:
Frederic Jung 2026-11-05 06:50:19 +00:00
parent 45ffdba8ae
commit b8d313b029
No known key found for this signature in database
22 changed files with 144 additions and 20 deletions

View file

@ -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, []);
});

View file

@ -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');

View file

@ -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<M;i++){const r=wwRate(l,1);rs.push(r);S.biz.push({id:uid(),type:'wwave',link:l.id,slots:1,rate:r,city:l.a,city2:l.b,name:'n'+i,bw:1,mood:80,since:0,reqs:[]});}
return JSON.stringify({F,rs});})()`));
assert.ok(r.rs[0] <= 0.3 * r.F + 1, `F6: ${a}-${b} first wave ${r.rs[0]} vs fiber ${r.F}`);
for (let i = 1; i < r.rs.length; i++) assert.ok(r.rs[i] <= r.rs[i - 1], `F6: ${a}-${b} never dearer than the one before`);
const full = r.rs.reduce((x, y) => 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()`);

View file

@ -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');

View file

@ -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');