Honor each Revolution sacrifice independently

This commit is contained in:
coyotte508 2026-10-13 03:01:42 +02:00
commit f338c976d8
6 changed files with 65 additions and 18 deletions

View file

@ -133,7 +133,7 @@ fn revolution() -> Incident {
|game, _player| can_lose_action(game),
);
b = b.add_simple_incident_listener(IncidentTarget::ActivePlayer, 2, |game, p, i| {
if can_lose_action(game) && i.player.sacrifice == 0 {
if can_lose_action(game) && i.player.sacrifice & 1 == 0 {
if get_status_phase(game).is_some() {
p.log(game, "Lose an action for the next turn");
game.permanent_effects
@ -153,7 +153,7 @@ fn revolution() -> Incident {
b,
|event| &mut event.incident,
ChangeGovernmentOption::FreeAndMandatory,
|i, p, game| i.active_player == p && can_change_government_for_free(game.player(p), game),
|i, p, game| i.active_player == p && i.player.sacrifice & 2 == 0 && can_change_government_for_free(game.player(p), game),
|_, _| {}, // don't need to pay
|_| true,
);
@ -171,7 +171,7 @@ fn kill_unit_for_revolution(
IncidentTarget::ActivePlayer,
priority,
move |game, p, i| {
i.player.sacrifice = 0;
if priority == 11 { i.player.sacrifice = 0; }
let units = p
.get(game)
.units
@ -190,10 +190,24 @@ fn kill_unit_for_revolution(
&description,
))
},
|game, s, i| {
move |game, s, i| {
// Old saves reset the first choice when opening step two. Recover
// that already-paid sacrifice from the active history before adding
// this response's casualty. Never inspect undone future entries.
if priority == 10 && i.player.sacrifice == 0 {
for item in crate::log::linear_action_entries(game).iter().rev().flat_map(|a| a.items.iter().rev()) {
if matches!(&item.entry, crate::log::ActionLogEntry::Text(text) if text == "triggers the event Revolution") { break; }
if item.player == s.player_index && item.origin == crate::events::EventOrigin::Incident(38)
&& matches!(&item.entry, crate::log::ActionLogEntry::Units { balance: crate::log::ActionLogBalance::Loss, .. }) {
i.player.sacrifice |= 1;
break;
}
}
}
kill_incident_units(game, s);
if !s.choice.is_empty() {
i.player.sacrifice = 1;
i.player.sacrifice |= if priority == 11 { 1 } else { 2 };
s.log(game, if priority == 11 { "Sacrificed an army unit: keep the action" } else { "Sacrificed an army unit: keep the current government" });
}
},
)

View file

@ -325,6 +325,13 @@
"origin": {
"Incident": 38
}
},
{
"player": 0,
"Text": "Sacrificed an army unit: keep the action",
"origin": {
"Incident": 38
}
}
],
"active_events": 1
@ -343,15 +350,6 @@
"origin": {
"Incident": 38
}
},
{
"player": 0,
"Action": {
"balance": "Loss"
},
"origin": {
"Incident": 38
}
}
],
"active_events": 1
@ -441,7 +439,7 @@
],
"log_index": 4,
"undo_limit": 1,
"actions_left": 1,
"actions_left": 2,
"round": 1,
"age": 1,
"messages": [

View file

@ -313,3 +313,5 @@ Viewer 0.1.96 / engine 0.4.76 prefixes BGS platform move summaries with the acti
Viewer 0.1.97 / engine 0.4.77 adds a Regions map guide using the engine's public map setup. Region perimeters are outlined in both map views; the selected civilization's starting region is gold. The guide counts other regions containing that civilization's cities for Ruler of the World. The mobile map toolbar uses an icon-only Strategy toggle to keep the guides visible. Validated with 758 tests, type checks, map partition checks for 2/3/4 players, and desktop/mobile 3D plus Strategy browser checks.
Viewer 0.1.98 keeps the region city count inline and only shows that count and the Ruler of the World combat explanation for the selected Greek civilization. Persia instead shows its count including the starting region and explains King of Persia, including its city-size limit. The region boundary guide remains available to all civilizations. Engine remains 0.4.77.
Viewer 0.1.99 / engine 0.4.78 fixes Revolution's independent sacrifices: the first prevents action loss and the second prevents government change. Step two no longer overwrites step one's result, and the government prompt checks the second sacrifice. Saved games already awaiting step two recover the first sacrifice from active (not undone) history. The journal explicitly names the consequence prevented. Validated all four sacrifice combinations and saved-step compatibility, plus the reported game's local copy; no live moves were submitted.

View file

@ -1,12 +1,12 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.98",
"version": "0.1.99",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@boardgamers/clash-web-client",
"version": "0.1.98",
"version": "0.1.99",
"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.98",
"version": "0.1.99",
"private": true,
"type": "module",
"scripts": {

View file

@ -0,0 +1,33 @@
import {test} from 'node:test';
import assert from 'node:assert/strict';
import {createRequire} from 'node:module';
import {readFileSync} from 'node:fs';
const engine=createRequire(import.meta.url)('../.engine/server.js');
const npcs=JSON.parse(await engine.init(2,[],{},'revolution',{})).players.slice(2);
function move(state:string, response:unknown) { return engine.tryMove(state,JSON.stringify({Response:response}),0); }
function request(state:string) { return JSON.parse(state).events?.at(-1)?.handler?.request; }
for(const first of [false,true]) for(const second of [false,true]) {
test(`Revolution sacrifices independently prevent action loss=${first}, government change=${second}`,()=>{
const game=JSON.parse(readFileSync(new URL('../../server/tests/test_games/incidents/civil_war/revolution.json',import.meta.url),'utf8'));
game.players.push(...npcs);
let state=engine.tryMove(JSON.stringify(game),JSON.stringify({Playing:{Advance:{advance:'Storage',payment:{gold:2}}}}),0);
const actions=JSON.parse(state).actions_left;
const one=request(state).SelectUnits.choices[0];
state=move(state,{SelectUnits:first?[one]:[]});
const two=request(state).SelectUnits.choices[0];
state=move(state,{SelectUnits:second?[two]:[]});
assert.equal(JSON.parse(state).actions_left,actions-(first?0:1));
assert.equal(request(state)==='ChangeGovernment',!second);
});
}
test('saved step two with an erased first-sacrifice flag preserves its earlier sacrifice',()=>{
const game=JSON.parse(readFileSync(new URL('../../server/tests/test_games/incidents/civil_war/revolution.json',import.meta.url),'utf8'));
game.players.push(...npcs);
let state=engine.tryMove(JSON.stringify(game),JSON.stringify({Playing:{Advance:{advance:'Storage',payment:{gold:2}}}}),0);
const actions=JSON.parse(state).actions_left;
state=move(state,{SelectUnits:[request(state).SelectUnits.choices[0]]});
const legacy=JSON.parse(state);delete legacy.events.at(-1).event_type.Incident.sacrifice;
state=move(JSON.stringify(legacy),{SelectUnits:[]});
assert.equal(JSON.parse(state).actions_left,actions);
assert.equal(request(state),'ChangeGovernment');
});