seriesoftubes/tests/alien-wave-rent.test.js
Frederic Jung b8d313b029
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.
2026-11-05 06:50:25 +00:00

67 lines
4.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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