New networks start at half speed (#186)

This commit is contained in:
Frederic Jung 2026-10-28 07:53:36 +01:00
parent b4f8d9c7f5
commit 3b8bd4e534
No known key found for this signature in database
3 changed files with 41 additions and 0 deletions

View file

@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows
## [Unreleased]
- Every new network starts at ½ speed, so you can find your feet before the bills arrive (#186). Saved games still continue at the speed you left them.
- You can put a link on standby, so one of two links between the same cities sits idle as a backup (#122). It carries traffic only when the other links are full or down, so its capacity is never wasted, and the map draws it dashed while it waits. The routing metric still applies to every link between the two cities.
## [1.35.1] — 2026-10-28

View file

@ -35,6 +35,8 @@ function beginGame(nm,city,o={}){if(needPitch()&&!UI.pitched){UI.pendGame=[nm,ci
if(o.scn){const sc=o.scn;S.scn={id:sc.id,rules:sc.rules||{},days:sc.days,name:sc.n||tr('features.weekly_challenge_key',{key:sc.key}),key:sc.key||null,mods:(sc.mods||[]).map(m=>m.id)};S.rng=(o.seed||hstr(sc.id))|0;S.mode='scenario';S.asn=200000+Math.floor(Math.random()*15000);
if(sc.cash)S.cash=sc.cash;if(sc.setup)sc.setup();
for(const m of S.scn.mods){if(m==='pricey')S.priceMul=1.3;if(m==='poor')S.cash=100000;if(m==='chaos')S.scn.rules.chaos=true;if(m==='boom')S.scn.rules.boom=true;if(m==='dk')S.scn.rules.dkAll=true;if(m==='sharks')S.scn.rules.sharks=true;}}
// Every new network starts at ½ speed (#186), whatever the last one ran at: slow enough to look around, but things happen.
UI.speed=UI.lastSpeed=0.5;UI.resumeSpeed=null;
track('game_new');UI.started=true;closeModal();compute();cam.x=CITY[city].x;cam.y=CITY[city].y;cam.z=innerWidth<760?1.1:1.4;selectCity(city);
toast(S.scn?`<b>${esc(S.scn.name)}</b><br>${o.scn.goal?esc(o.scn.goal)+'.':tr('common.serve_as_much_traffic_as_you')} ${tr('scenarios.you_have_n_days',{n:S.scn.days})}`:S.mode==='sandbox'?tr('scenarios.sandbox_mode_a_billion_dollars_every'):tr('scenarios.welcome_name_the_ripe_ncc_assigned',{name:esc(nm),asn:S.asn,city:CITY[city].name}),'goal');
renderAll();save();if(!S.scn&&S.mode!=='sandbox')tutorialStart();}

View file

@ -0,0 +1,38 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
test('#186 a new network starts at half speed, even after a game at 8×', () => {
const { ev, dom, errors } = load();
ev("ACT.start({});ACT.speed({v:8})");
assert.equal(ev('UI.speed'), 8);
ev("ACT.newgame();ACT.start({})");
assert.equal(ev('UI.speed'), 0.5, 'normal game');
assert.ok(dom.window.document.getElementById('sp0.5').classList.contains('on'), 'the HUD shows ½×');
ev("ACT.speed({v:0});ACT.newgame();UI.mode='sandbox';ACT.start({})");
assert.equal(ev('UI.speed'), 0.5, 'sandbox, and a paused game does not stay paused');
ev("ACT.speed({v:4});ACT.startScn({id:SCN[0].id,sure:1})");
assert.equal(ev('UI.speed'), 0.5, 'scenario');
ev("ACT.speed({v:2});ACT.startWeekly({sure:1})");
assert.equal(ev('UI.speed'), 0.5, 'weekly challenge');
assert.deepEqual(errors, []);
});
test('#186 on a phone, play after pause resumes at half speed, not the old game\'s speed', () => {
const { ev, errors } = load();
ev("window.innerWidth=360;ACT.start({});ACT.phoneSpeed();ACT.phoneSpeed();ACT.phoneSpeed()");
assert.notEqual(ev('UI.lastSpeed'), 0.5);
ev("ACT.newgame();ACT.start({});if(UI.pendGame)ACT.pitchSkip();ACT.phonePlay();ACT.phonePlay()");
assert.ok(ev("UI.started&&!UI.pendGame"), "the new game is running");
assert.equal(ev('UI.speed'), 0.5);
assert.deepEqual(errors, []);
});
test('#186 a saved game still continues at the speed it was saved at', () => {
const a = load();
a.ev("ACT.start({});ACT.speed({v:4});save(true)");
const b = load({ storage: { 'sot-save-v1': a.ev("localStorage.getItem('sot-save-v1')") } });
assert.equal(b.ev('UI.speed'), 4);
assert.deepEqual(a.errors, []);
assert.deepEqual(b.errors, []);
});