Puzzles: a POP in a thin market counts its higher monthly rent

The puzzle price and the city panel now use the city's own monthly POP rent
(Suva is 1.5x), not the plain one, matching the higher setup already charged.
This commit is contained in:
Frederic Jung 2026-10-28 19:36:12 +01:00
parent 19a9c60fd5
commit 843811956b
No known key found for this signature in database
3 changed files with 13 additions and 2 deletions

View file

@ -28,7 +28,7 @@ function pzRoutes(a,b){const out=[],sub=isSub(a,b);
return out;}
const pzMo=(r,tier,div)=>Math.round(waveMo(r.km,r.sub,tier)*r.f*(div?DIVERSE:1));
const pzLinkCost=(r,tier,div)=>pzMo(r,tier,div)*PZ_YEAR;// leased waves have no setup fee: a year of rent
const pzPopCost=c=>popCost(c)+PZ_YEAR*POP_MO;
const pzPopCost=c=>popCost(c)+PZ_YEAR*popMo(c);// thin markets cost more every month too (#94)
const PZ_TIERS=[0,1,2];
function pzSpend(){let s=0;for(const c in S.pops)s+=pzPopCost(c);for(const l of S.links)s+=l.mo*PZ_YEAR;return s;}
// What one backhoe or one anchor takes out: waves in the same trench, or every wave on the same cable (a cable fails

View file

@ -29,7 +29,7 @@ function pzPanel(sel){const head=(eb,name,facts)=>`<div class="ph"><div style="m
const eb=k==='goal'?tr('puzzles.goal_city'):k==='via'?tr('puzzles.stepping_stone_optional'):tr('puzzles.off_limits');
let h=head(`${PZ_ICON[k]} ${eb}`,esc(C.name),p?`<span class="fact mine">${tr('common.your_pop')}</span>`:'')+'<div class="scroll">';
if(k==='avoid')return h+`<p class="lead">${tr('puzzles.not_this_one_find_a_way_around')}</p></div>`;
if(!p)h+=`<p class="lead">${tr('puzzles.a_pop_costs_setup_plus_a_year',{setup:fmt$(popCost(c)),mo:fmt$(POP_MO)})}</p><div class="btns">${btn(tr('puzzles.open_a_pop_cost',{cost:fmt$(pzPopCost(c))}),'pzPop',{city:c},'pink big')}</div>`;
if(!p)h+=`<p class="lead">${tr('puzzles.a_pop_costs_setup_plus_a_year',{setup:fmt$(popCost(c)),mo:fmt$(popMo(c))})}</p><div class="btns">${btn(tr('puzzles.open_a_pop_cost',{cost:fmt$(pzPopCost(c))}),'pzPop',{city:c},'pink big')}</div>`;
else{const others=[...S.pz.cities,...S.pz.via].filter(x=>x!==c);
h+=`<p class="lead">${tr('puzzles.drag_from_this_pop_onto_another')}</p><h3>${tr('puzzles.lease_a_wave_to')}</h3><div class="seg">${others.map(x=>btn(esc(CITY[x].name),'pzLinkTo',{a:c,b:x},S.pops[x]?'':'ghost')).join('')}</div>`;
const ls=S.links.filter(l=>l.a===c||l.b===c);if(ls.length)h+=`<h3 style="margin-top:10px">${tr('common.links')}</h3>`+ls.map(l=>`<div class="row"><div class="grow"><div class="nm">${esc(CITY[l.a===c?l.b:l.a].name)}</div><div class="meta">${capName(l)} · ${linkLat(l).toFixed(1)} ms</div></div>${btn(tr('common.open'),'selLink',{id:l.id},'ghost sm')}</div>`).join('');

View file

@ -263,3 +263,14 @@ test('puzzles in every language', () => {
assert.deepEqual(errors, [], lang);
}
});
test('a POP in a thin market costs its higher monthly rent too, and the panel says so', () => {
const { ev, errors } = load();
ev("pzBegin(pzDef('kiwi'))");
assert.ok(ev('colo("suv")') > 1, 'Suva is a thin market');
assert.equal(ev("pzPopCost('suv')"), ev("popCost('suv')+12*popMo('suv')"));
assert.ok(ev("pzPopCost('suv')") > ev("popCost('suv')+12*POP_MO"));
ev("selectCity('suv')");
assert.ok(ev("document.getElementById('panelBody').textContent").includes(ev("fmt$(popMo('suv'))") + '/mo'));
assert.deepEqual(errors, []);
});