Prefer eligible free actions from city shortcuts

This commit is contained in:
coyotte508 2026-10-22 22:55:42 +02:00
commit 9cb57d4589
5 changed files with 27 additions and 17 deletions

View file

@ -441,3 +441,5 @@ Viewer 0.1.157 simplifies Great Person acquisition prompts: the Take card button
Viewer 0.1.158 / engine 0.4.108 checks City States against the original city's size and mood when activated, before construction changes its size. Requirements survive deferred rewards and reloads, and exhausted substitute cities are excluded. Pirate token rewards now count destroyed ships across the battle, allow a mood/culture split, and grant nothing for a retreat without kills. Existing per-ship gold rewards are retained. Completed historical actions are not rewritten.
Sources: official Monumental Edition rulebook, page 33 (City States explicitly allows size 2 growing to size 3 with a size-2 substitute) and page 27 (one gold and one mood/culture per pirate eliminated, regardless of winner). Verified with 32 Greek/combat Rust tests, 851 frontend/engine tests, 17 locales, type checking and production build. Regressions include Observatory card draw plus reload, both fleets wiped out, mixed token rewards, and zero-kill retreat.
Viewer 0.1.159 defaults both city shortcuts and main action entry points to eligible free Collect and Increase Happiness variants, including Voting. Happiness defaults are validated against the selected city, costs and leader restrictions. Explicit paid selections remain available. Verified with 851 frontend/engine tests, locales, type checking and production build. Engine remains 0.4.108.

View file

@ -1,12 +1,12 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.158",
"version": "0.1.159",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@boardgamers/clash-web-client",
"version": "0.1.158",
"version": "0.1.159",
"dependencies": {
"@boardgamers/protocol": "0.9.0",
"lucide-svelte": "^0.577.0",

View file

@ -1,6 +1,6 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.158",
"version": "0.1.159",
"private": true,
"type": "module",
"scripts": {

View file

@ -305,13 +305,13 @@ test('diplomatic attacks preview their cost before confirmation', async () => {
}
});
test('action bar defaults to available free collection and happiness variants', async () => {
test('action entry points default to available free collection and happiness variants', async () => {
const app = paymentController(),
c = app.controller;
try {
c.setPlayer(0);
await c.load(engine.stripSecret(fixture('advances/collect_free_economy'), 0));
c.beginCollect(undefined, true);
c.beginCollect();
const economy = app.session().view!.collectActions!.find((offer) => offer.name === 'Free Economy')!;
assert.deepEqual(app.session().collectVariant, economy.value);
c.patch({
@ -320,18 +320,23 @@ test('action bar defaults to available free collection and happiness variants',
collectActions: app.session().view!.collectActions!.filter((offer) => !offer.free),
},
});
c.beginCollect(undefined, true);
c.beginCollect();
assert.deepEqual(app.session().collectVariant, app.session().view!.collectActions![0].value);
await c.load(engine.stripSecret(fixture('advances/increase_happiness_voting'), 0));
c.beginHappiness(undefined, true);
c.beginHappiness();
assert.equal(app.session().view!.happinessActions![app.session().happinessVariant!].name, 'Voting');
const city = app.session().view!.cities.find((city) => city.mood !== 'Happy')!.position;
c.openCities(city, 'happiness');
assert.equal(app.session().view!.happinessActions![app.session().happinessVariant!].name, 'Voting');
c.switchHappinessVariant(0);
assert.equal(app.session().happinessVariant, 0, 'explicit paid selection is retained');
c.patch({
view: {
...app.session().view!,
happinessActions: app.session().view!.happinessActions!.filter((offer) => !offer.free),
},
});
c.beginHappiness(undefined, true);
c.beginHappiness();
assert.equal(app.session().happinessVariant, 0);
assert.deepEqual(app.sent, [], 'opening an action never submits it');
} finally {
@ -345,7 +350,7 @@ test('map happiness selects multiple cities, preserves them across variants, and
const raw = fixture('advances/increase_happiness_voting');
c.setPlayer(0);
await c.load(engine.stripSecret(raw, 0));
c.openCities('C2', 'happiness');
c.beginHappiness('C2', false);
assert.equal(app.session().mode, 'happiness');
assert.deepEqual(app.session().happinessSteps, { C2: 1 });
assert(!happinessCities(app.session()).includes('A1'), 'happy cities are not targets');
@ -402,7 +407,7 @@ test('map happiness keeps Lawgiver distinct and blocks unaffordable selections',
p.resources = { mood_tokens: 1, culture_tokens: 1 };
c.setPlayer(0);
await c.load(engine.stripSecret(JSON.stringify(game), 0));
c.beginHappiness();
c.beginHappiness(undefined, false);
c.selectTile('C2');
assert.deepEqual(app.session().happinessSteps, { C2: 2 });
assert.equal(app.session().happinessLawgiver, 'C2');
@ -1224,7 +1229,7 @@ test('changing collection action keeps selected tiles and requotes the submitted
try {
c.setPlayer(0);
await c.load(engine.stripSecret(fixture('advances/collect_free_economy'), 0));
c.beginCollect();
c.beginCollect(undefined, false);
c.toggleChoice(
app.session().view!.cities.find((city) => city.position === app.session().city)!.choices[0],
);
@ -2725,7 +2730,7 @@ test('Rituals happiness lets the player choose repeated resources or a mixed pay
const raw = JSON.stringify(game);
c.setPlayer(0);
await c.load(engine.stripSecret(raw, 0));
c.openCities('C2', 'happiness');
c.beginHappiness('C2', false);
c.setHappinessCity('C2', 2);
const base = happinessPreview(app.session(), (input) => c.query(input), undefined, undefined, undefined, true);
const total = Object.values(base.payment).reduce((sum, n) => sum + (n ?? 0), 0);

View file

@ -1430,14 +1430,14 @@ export class Controller {
index < 0 ? (direction > 0 ? 0 : water.length - 1) : (index + direction + water.length) % water.length;
this.patch({ seaRouteStart: water[next] });
}
beginCollect(position?: string, preferFree = position !== undefined) {
beginCollect(position?: string, preferFree = true) {
const s = get(this.session);
if (s.pending) return;
const offers = s.view?.collectActions ?? [];
const variant =
(preferFree ? offers.find((offer) => offer.free && (!position ||
(preferFree ? offers.find((offer) => offer.free &&
this.query<CollectionPotential[]>({ kind: 'collectionPotential', variant: offer.value })
.some((city) => city.position === position && city.amount > 0))) : undefined)?.value ?? offers[0]?.value ?? 'Collect';
.some((city) => (!position || city.position === position) && city.amount > 0)) : undefined)?.value ?? offers[0]?.value ?? 'Collect';
const city =
position ??
defaultCity(
@ -1559,7 +1559,7 @@ export class Controller {
error: '',
});
}
beginHappiness(position?: string, preferFree = false) {
beginHappiness(position?: string, preferFree = true) {
const s = get(this.session);
if (s.pending || s.seat === undefined) return;
this.closeActivity();
@ -1574,7 +1574,10 @@ export class Controller {
happinessSteps: {},
happinessCity: null,
happinessVariant: preferFree
? Math.max(0, s.view?.happinessActions?.findIndex((offer) => offer.free) ?? -1)
? Math.max(0, s.view?.happinessActions?.findIndex((offer, index) => offer.free &&
(position ? [position] : s.view?.cities.map((city) => city.position) ?? []).some((city) =>
happinessTargets({ ...s, happinessVariant: index, happinessSteps: {}, happinessLawgiver: null },
(input) => this.query(input), city).some((target) => target.action))) ?? -1)
: 0,
happinessLawgiver: null,
error: '',