Select Tribal Allies armies before payment and publish 0.4.124

This commit is contained in:
coyotte508 2026-11-01 14:24:32 +01:00
commit c84f175bbc
8 changed files with 864 additions and 14 deletions

View file

@ -31,11 +31,68 @@ pub(crate) fn celts() -> Civilization {
.add_combat_strength_listener(115,|game,c,s,r|{if game.player(c.opponent(c.player(r))).is_human()&&c.is_land_battle(game){let bonus=get_barbarians_player(game).cities.iter().filter(|city|game.map.within_revealed_distance(city.position,c.defender_position(),2)).count().min(4) as i8;s.extra_combat_value+=bonus;if bonus>0{s.roll_log.push(format!("Tribal Warfare adds +{bonus} combat value"));}}}).build(),
SpecialAdvanceInfo::builder(SpecialAdvance::TribalAllies,SpecialAdvanceRequirement::Advance(Advance::Draft),"Tribal Allies","Once per turn, as an action, spawn Barbarians as for an event's Barbarian spawn icon. When you trigger Barbarian movement, pay 1 food to stop any number of those armies.")
.add_custom_action(CustomActionType::TribalAllies,|c|c.once_per_turn().action().no_resources(),spawn,|game,p|!possible_barbarians_spawns(game,p).is_empty()||!possible_barbarians_reinforcements(game).is_empty())
.add_payment_request_listener(|e|&mut e.stop_barbarian_movement,5,|game,p,m|{
let own=game.events.iter().any(|e|matches!(&e.event_type,crate::content::persistent_events::PersistentEventType::Incident(i) if i.active_player==p.index));
(own&&!m.is_empty()).then(||vec![PaymentRequest::optional(p.payment_options().resources(p.get(game),ResourcePile::food(1)),"Tribal Allies · Stop Barbarian armies")])
},|game,s,_|{if !s.choice[0].is_empty(){s.player().get_mut(game).event_info.insert("Tribal Allies stop".into(),"paid".into());}})
.add_position_request(|e|&mut e.stop_barbarian_movement,4,|game,p,m|p.get_mut(game).event_info.remove("Tribal Allies stop").map(|_|PositionRequest::new(m.clone(),0..=m.len() as u8,"Tribal Allies · Select armies that will not move")),|game,s,m|{m.retain(|pos|!s.choice.contains(pos));s.log(game,&format!("Stopped {} Barbarian armies",s.choice.len()));}).build(),
.add_position_request(
|e| &mut e.stop_barbarian_movement,
6,
|game, p, movable| {
let own = game.events.iter().any(|e| matches!(
&e.event_type,
crate::content::persistent_events::PersistentEventType::Incident(i)
if i.active_player == p.index
));
let cost = p.payment_options().resources(p.get(game), ResourcePile::food(1));
(own && !movable.is_empty() && p.get(game).can_afford(&cost)).then(|| {
PositionRequest::new(movable.clone(), 0..=movable.len() as u8,
"Select armies to stop · 1 food total")
})
},
|game, s, _| {
if !s.choice.is_empty() {
s.player().get_mut(game).event_info.insert(
"Tribal Allies armies".into(),
serde_json::to_string(&s.choice).expect("positions serialize"),
);
}
},
)
.add_payment_request_listener(
|e| &mut e.stop_barbarian_movement,
5,
|game, p, _| {
p.get(game).event_info.contains_key("Tribal Allies armies").then(|| vec![
PaymentRequest::optional(
p.payment_options().resources(p.get(game), ResourcePile::food(1)),
"Stop selected armies",
)
])
},
|game, s, movable| {
let armies = s.player().get_mut(game).event_info.remove("Tribal Allies armies");
if s.choice[0].is_empty() {
return;
}
if let Some(armies) = armies {
let armies: Vec<Position> = serde_json::from_str(&armies).expect("saved positions");
movable.retain(|pos| !armies.contains(pos));
s.log(game, &format!("Stopped {} Barbarian armies", armies.len()));
} else {
// Finish a payment already pending in saves from the previous flow.
s.player().get_mut(game).event_info.insert("Tribal Allies stop".into(), "paid".into());
}
},
)
.add_position_request(
|e| &mut e.stop_barbarian_movement,
4,
|game, p, movable| p.get_mut(game).event_info.remove("Tribal Allies stop").map(|_| {
PositionRequest::new(movable.clone(), 1..=movable.len() as u8,
"Select armies to stop")
}),
|game, s, movable| {
movable.retain(|pos| !s.choice.contains(pos));
s.log(game, &format!("Stopped {} Barbarian armies", s.choice.len()));
},
).build(),
SpecialAdvanceInfo::builder(SpecialAdvance::DruidicInfluence,SpecialAdvanceRequirement::Advance(Advance::Priesthood),"Druidic Influence","Influence a Barbarian settlement to place your culture marker there, worth 1 objective point. It remains Barbarian. Each settlement holds at most one marker; capturing or converting it removes the marker.")
.add_transient_event_listener(|e|&mut e.dynamic_victory_points,6,|points,game,(),p|{let count=get_barbarians_player(game).cities.iter().filter(|c|c.influence_marker==Some(p.index)).count();points.push(SpecialVictoryPoints::new(count as f32,p.origin.clone(),VictoryPointAttribution::Objectives));}).build(),
SpecialAdvanceInfo::builder(SpecialAdvance::TribalTrade,SpecialAdvanceRequirement::Advance(Advance::TradeRoutes),"Tribal Trade","Your units may trade with non-Angry Barbarian cities. Each such route gives food, including when you have Currency.").build(),

View file

@ -631,3 +631,11 @@ leader preserves other unused leaders; only taking 2 VP prevents future leaders.
With no unused leaders remaining, the event grants no VP. Update the card name
and choice explanations. Verified the incident regression and eight bridge tests,
including recruitment availability after replacement death and reload.
## Viewer 0.1.182 / engine 0.4.124
Tribal Allies selects barbarian armies on the map before offering payment.
The selection shows the total one-food cost; skipping or declining payment costs
nothing. Food and gold substitution remain supported. Previously pending payments
continue into an army selection. Includes a restartable local preview and six
regressions covering selection, payment, cancellation, and old pending payments.

View file

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

View file

@ -0,0 +1,712 @@
{
"state": "Playing",
"events": [
{
"event_type": {
"StatusPhase": "FreeAdvance"
},
"player": 0,
"last_priority_used": 0
},
{
"event_type": {
"Incident": {
"incident_id": 28,
"cause": {
"Advance": "Storage"
},
"active_player": 0,
"barbarians": {
"move_units": true
}
}
},
"player": 0,
"last_priority_used": 199
},
{
"event_type": {
"StopBarbarianMovement": [
"A3",
"B3"
]
},
"player": 0,
"last_priority_used": 6,
"handler": {
"priority": 6,
"request": {
"SelectPositions": {
"choices": [
"A3",
"B3"
],
"needed": {
"start": 0,
"end": 2
},
"description": "Select armies to stop · 1 food total"
}
},
"origin": {
"SpecialAdvance": "TribalAllies"
}
}
}
],
"players": [
{
"id": 0,
"resources": {
"food": 1,
"wood": 6,
"ore": 6,
"ideas": 5,
"gold": 7,
"mood_tokens": 8,
"culture_tokens": 7
},
"resource_limit": {
"food": 7,
"wood": 7,
"ore": 7,
"ideas": 7,
"gold": 7,
"mood_tokens": 7,
"culture_tokens": 7
},
"cities": [
{
"mood_state": "Happy",
"position": "A1"
},
{
"city_pieces": {
"fortress": 1
},
"mood_state": "Angry",
"position": "C2"
}
],
"units": [
{
"position": "C2",
"unit_type": "Infantry",
"id": 0
},
{
"position": "C2",
"unit_type": "Cavalry",
"id": 1
},
{
"position": "C2",
"unit_type": "Infantry",
"id": 2
},
{
"position": "C2",
"unit_type": "Elephant",
"id": 3
},
{
"position": "C2",
"unit_type": "Settler",
"id": 4
},
{
"position": "C2",
"unit_type": "Settler",
"id": 5
},
{
"position": "C2",
"unit_type": "Settler",
"id": 6
},
{
"position": "C2",
"unit_type": "Settler",
"id": 7
}
],
"civilization": "Celts",
"advances": [
"Draft",
"Farming",
"Mining",
"Storage",
"Tactics"
],
"incident_tokens": 3,
"next_unit_id": 8
},
{
"id": 1,
"resources": {
"food": 2,
"wood": 7,
"ore": 7,
"ideas": 7,
"gold": 7,
"mood_tokens": 7,
"culture_tokens": 7
},
"resource_limit": {
"food": 2,
"wood": 7,
"ore": 7,
"ideas": 7,
"gold": 7,
"mood_tokens": 7,
"culture_tokens": 7
},
"cities": [
{
"mood_state": "Angry",
"position": "C1"
}
],
"units": [
{
"position": "C1",
"unit_type": "Infantry",
"id": 1
}
],
"civilization": "Carthage",
"advances": [
"Farming",
"Mining"
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"resource_limit": {
"food": 2,
"wood": 7,
"ore": 7,
"ideas": 7,
"gold": 7
},
"cities": [
{
"mood_state": "Neutral",
"position": "B3"
}
],
"units": [
{
"position": "B3",
"unit_type": "Infantry",
"id": 0
},
{
"position": "A3",
"unit_type": "Elephant",
"id": 1
},
{
"position": "B3",
"unit_type": "Infantry",
"id": 2
},
{
"position": "A3",
"unit_type": "Infantry",
"id": 4
}
],
"civilization": "Barbarians",
"incident_tokens": 3,
"next_unit_id": 5
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {
"tiles": [
[
"A1",
"Fertile"
],
[
"A2",
"Water"
],
[
"A3",
"Mountain"
],
[
"B1",
"Mountain"
],
[
"B2",
"Forest"
],
[
"B3",
"Fertile"
],
[
"C1",
"Barren"
],
[
"C2",
"Forest"
],
[
"C3",
"Water"
],
[
"D2",
"Water"
]
]
},
"starting_player_index": 0,
"current_player_index": 0,
"log": [
{
"age": 1,
"rounds": [
{
"round": 1,
"turns": [
{
"turn_type": {
"Player": 0
},
"actions": [
{
"action": {
"Response": {
"SelectAdvance": "Storage"
}
},
"player": 0,
"items": [
{
"player": 0,
"Resources": {
"resources": {
"mood_tokens": 1
},
"balance": "Gain"
},
"origin": {
"Advance": "Storage"
}
},
{
"player": 0,
"Advance": {
"advance": "Storage",
"incident_token": {
"Take": 0
},
"balance": "Gain"
},
"origin": {
"Ability": "Free Advance"
}
},
{
"player": 0,
"Text": "triggers the event Population Boom",
"origin": {
"Advance": "Storage"
}
},
{
"player": 0,
"Text": "Base effect: Barbarians move",
"origin": {
"Incident": 28
}
}
],
"active_events": 1
}
]
}
]
}
]
}
],
"board_history": {
"id": "9e86bec6ee4c0d9c03010087d8e68152087f3a9a657884a24c13cfb57b1baa33",
"frames": [
{
"cursor": 0,
"actor": null,
"ended_turn": false,
"title": "Earlier position",
"age": 1,
"round": 1,
"tiles": [
[
"A1",
"Fertile"
],
[
"A2",
"Water"
],
[
"A3",
"Mountain"
],
[
"B1",
"Mountain"
],
[
"B2",
"Forest"
],
[
"B3",
"Fertile"
],
[
"C1",
"Barren"
],
[
"C2",
"Forest"
],
[
"C3",
"Water"
],
[
"D2",
"Water"
]
],
"players": [
{
"id": 0,
"civilization": "Celts",
"cities": [
{
"mood_state": "Happy",
"position": "A1"
},
{
"city_pieces": {
"fortress": 1
},
"mood_state": "Angry",
"position": "C2"
}
],
"units": [
{
"position": "C2",
"unit_type": "Infantry",
"id": 0
},
{
"position": "C2",
"unit_type": "Cavalry",
"id": 1
},
{
"position": "C2",
"unit_type": "Infantry",
"id": 2
},
{
"position": "C2",
"unit_type": "Elephant",
"id": 3
},
{
"position": "C2",
"unit_type": "Settler",
"id": 4
},
{
"position": "C2",
"unit_type": "Settler",
"id": 5
},
{
"position": "C2",
"unit_type": "Settler",
"id": 6
},
{
"position": "C2",
"unit_type": "Settler",
"id": 7
}
]
},
{
"id": 1,
"civilization": "Carthage",
"cities": [
{
"mood_state": "Angry",
"position": "C1"
}
],
"units": [
{
"position": "C1",
"unit_type": "Infantry",
"id": 1
}
]
},
{
"id": 2,
"civilization": "Barbarians",
"cities": [
{
"mood_state": "Neutral",
"position": "B3"
}
],
"units": [
{
"position": "B3",
"unit_type": "Infantry",
"id": 0
},
{
"position": "A3",
"unit_type": "Elephant",
"id": 1
},
{
"position": "B3",
"unit_type": "Infantry",
"id": 2
},
{
"position": "A3",
"unit_type": "Infantry",
"id": 4
}
]
},
{
"id": 3,
"civilization": "Pirates",
"cities": [],
"units": []
}
]
},
{
"cursor": 1,
"actor": 0,
"ended_turn": false,
"title": "Free Advance",
"age": 1,
"round": 1,
"tiles": [
[
"A1",
"Fertile"
],
[
"A2",
"Water"
],
[
"A3",
"Mountain"
],
[
"B1",
"Mountain"
],
[
"B2",
"Forest"
],
[
"B3",
"Fertile"
],
[
"C1",
"Barren"
],
[
"C2",
"Forest"
],
[
"C3",
"Water"
],
[
"D2",
"Water"
]
],
"players": [
{
"id": 0,
"civilization": "Celts",
"cities": [
{
"mood_state": "Happy",
"position": "A1"
},
{
"city_pieces": {
"fortress": 1
},
"mood_state": "Angry",
"position": "C2"
}
],
"units": [
{
"position": "C2",
"unit_type": "Infantry",
"id": 0
},
{
"position": "C2",
"unit_type": "Cavalry",
"id": 1
},
{
"position": "C2",
"unit_type": "Infantry",
"id": 2
},
{
"position": "C2",
"unit_type": "Elephant",
"id": 3
},
{
"position": "C2",
"unit_type": "Settler",
"id": 4
},
{
"position": "C2",
"unit_type": "Settler",
"id": 5
},
{
"position": "C2",
"unit_type": "Settler",
"id": 6
},
{
"position": "C2",
"unit_type": "Settler",
"id": 7
}
]
},
{
"id": 1,
"civilization": "Carthage",
"cities": [
{
"mood_state": "Angry",
"position": "C1"
}
],
"units": [
{
"position": "C1",
"unit_type": "Infantry",
"id": 1
}
]
},
{
"id": 2,
"civilization": "Barbarians",
"cities": [
{
"mood_state": "Neutral",
"position": "B3"
}
],
"units": [
{
"position": "B3",
"unit_type": "Infantry",
"id": 0
},
{
"position": "A3",
"unit_type": "Elephant",
"id": 1
},
{
"position": "B3",
"unit_type": "Infantry",
"id": 2
},
{
"position": "A3",
"unit_type": "Infantry",
"id": 4
}
]
},
{
"id": 3,
"civilization": "Pirates",
"cities": [],
"units": []
}
]
}
]
},
"log_index": 1,
"undo_limit": 1,
"actions_left": 3,
"round": 1,
"age": 1,
"messages": [
"The game has started"
],
"dice_roll_outcomes": [
1,
1,
10,
10,
10,
10,
10,
10,
10
],
"dice_roll_log": [
10
],
"wonders_left": [
"Pyramids"
],
"incidents_discarded": [
28
]
}

View file

@ -6,20 +6,21 @@
import { mountLocalization } from './localization';
import settlerFixture from '../scripts/async-preview-fixture.json';
import tradeFixture from '../scripts/tech-queue-fixture.json';
import tribalFixture from '../scripts/tribal-preview-fixture.json';
import './style.css';
let scenario=$state<'settler'|'trade'>('trade');
let scenario=$state<'settler'|'trade'|'tribal'>(new URLSearchParams(location.search).get('scenario') === 'tribal' ? 'tribal' : 'trade');
let seat=$state(0), ready=$state(false), error=$state('');
let engine: Awaited<ReturnType<typeof loadTutorialEngine>>;
let game:any;
let controller=$state<Controller>();
let names=$derived((scenario==='settler'?settlerFixture:tradeFixture).players.slice(0,2).map(p=>p.civilization));
let names=$derived((scenario==='tribal'?tribalFixture:scenario==='settler'?settlerFixture:tradeFixture).players.slice(0,2).map(p=>p.civilization));
async function refresh(){controller!.setPlayer(seat);await controller!.load(engine.stripSecret(JSON.stringify(game),seat));}
async function move(raw:string){
try{game=JSON.parse(engine.tryMove(JSON.stringify(game),raw,seat));error='';await refresh();}
catch(e){error=String(e);controller!.moveResult({ok:false,error});}
}
async function restart(next=scenario){
scenario=next;game=structuredClone(next==='settler'?settlerFixture:tradeFixture);
scenario=next;game=structuredClone(next==='tribal'?tribalFixture:next==='settler'?settlerFixture:tradeFixture);
game.board_history??={id:'async-queue-preview',frames:[]};
for(const c of game.players[0].cities){c.activations=0;c.mood_state='Happy';}
game.players[0].resources.food=1;seat=0;error='';await refresh();ready=true;
@ -38,8 +39,8 @@
</script>
<div class="prototype-tools">
<span>Local test · Live queue implementation</span>
<div><button class:chosen={scenario==='settler'} onclick={()=>restart('settler')}>Replacement settler</button><button class:chosen={scenario==='trade'} onclick={()=>restart('trade')}>Technology Trade</button></div>
<span>Local test</span>
<div><button class:chosen={scenario==='tribal'} onclick={()=>restart('tribal')}>Tribal Allies</button><button class:chosen={scenario==='settler'} onclick={()=>restart('settler')}>Replacement settler</button><button class:chosen={scenario==='trade'} onclick={()=>restart('trade')}>Technology Trade</button></div>
<div><button class:chosen={seat===0} onclick={()=>switchSeat(0)}>Play as {names[0]}</button><button class:chosen={seat===1} onclick={()=>switchSeat(1)}>Play as {names[1]}</button><button onclick={()=>restart()}>Restart</button></div>
</div>
{#if error}<div class="prototype-error">{error}<button onclick={()=>error=''}>×</button></div>{/if}

View file

@ -33,6 +33,7 @@
const session = $derived(controller.session);
const panelId = $props.id();
const selected = $derived($session.decisionSelection);
const tribalStopChoice = $derived(decision.name === 'Tribal Allies' && decision.description === 'Select armies to stop · 1 food total');
const razeChoice = $derived(decision.name === 'Raze city');
const firstPlayerChoice = $derived(decision.name === 'Determine First Player');
const mapChoice = $derived(mapDecisionOptions(decision).length > 0);
@ -504,7 +505,7 @@
title={preview.error || 'Confirm selection'}
onclick={() => preview.action && controller.submit(preview.action)}
>
{selected.length === 0 && !decision.fields.length && decision.min === 0 ? 'Skip' : 'Confirm'}<Check
{selected.length === 0 && !decision.fields.length && decision.min === 0 ? 'Skip' : tribalStopChoice ? 'Continue' : 'Confirm'}{#if tribalStopChoice && selected.length}<ResourceAmount pile={{ food: 1 }} compact />{/if}<Check
size={16}
/>
</button>

View file

@ -0,0 +1,71 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
const engine = createRequire(import.meta.url)('../.engine/server.js');
const fresh = JSON.parse(await engine.init(2, [], {}, 'tribal-allies', {}));
const move = (g: any, action: unknown) =>
JSON.parse(engine.tryMove(JSON.stringify(g), JSON.stringify(action), 0));
const request = (g: any) => g.events?.at(-1)?.handler?.request;
function start() {
const g = JSON.parse(readFileSync(new URL('../../server/tests/test_games/incidents/barbarians_move.json', import.meta.url), 'utf8'));
g.players[0].civilization = 'Celts';
g.players[0].advances.push('Draft');
g.players[1].units = g.players[1].units.filter((u: any) => !u.unit_type.Leader);
g.players.push(structuredClone(fresh.players[3]));
return move(g, { Response: { SelectAdvance: 'Storage' } });
}
test('Tribal Allies selects armies before charging anything; skipping is free', () => {
const g = start();
assert.deepEqual(request(g).SelectPositions.choices, ['A3', 'B3']);
assert.equal(g.players[0].resources.food, 1);
const after = move(g, { Response: { SelectPositions: [] } });
assert.equal(after.players[0].resources.food, 1);
assert(!JSON.stringify(after.events).includes('StopBarbarianMovement'));
});
for (const payment of [{ food: 1 }, { gold: 1 }]) {
test(`Tribal Allies stops selected armies for one total payment: ${JSON.stringify(payment)}`, () => {
let g = start();
const before = structuredClone(g.players[0].resources);
g = move(g, { Response: { SelectPositions: ['A3', 'B3'] } });
assert.deepEqual(g.players[0].resources, before);
assert(request(g).Payment);
g = move(g, { Response: { Payment: [payment] } });
assert(g.players[2].units.filter((u: any) => [1, 4].includes(u.id)).every((u: any) => u.position === 'A3'));
assert(g.players[2].units.filter((u: any) => [0, 2].includes(u.id)).every((u: any) => u.position === 'B3'));
const key = Object.keys(payment)[0];
assert.equal(g.players[0].resources[key] ?? 0, before[key] - 1);
assert(!g.players[0].event_info?.['Tribal Allies armies']);
});
}
test('canceling payment stops no armies and spends nothing', () => {
let g = start();
const before = structuredClone(g.players[0].resources);
g = move(g, { Response: { SelectPositions: ['A3'] } });
g = move(g, { Response: { Payment: [{}] } });
assert.deepEqual(g.players[0].resources, before);
assert(!g.players[0].event_info?.['Tribal Allies armies']);
assert(!JSON.stringify(g.events).includes('StopBarbarianMovement'));
});
test('only selected armies stop', () => {
let g = start();
g = move(g, { Response: { SelectPositions: ['A3'] } });
g = move(g, { Response: { Payment: [{ food: 1 }] } });
assert(g.players[2].units.filter((u: any) => [1, 4].includes(u.id)).every((u: any) => u.position === 'A3'));
assert(g.players[2].units.filter((u: any) => [0, 2].includes(u.id)).every((u: any) => u.position !== 'B3'));
});
test('a payment pending from the previous flow still leads to an army selection', () => {
let g = move(start(), { Response: { SelectPositions: ['A3'] } });
delete g.players[0].event_info['Tribal Allies armies'];
g = move(g, { Response: { Payment: [{ food: 1 }] } });
assert.equal(request(g).SelectPositions.needed.start, 1);
assert.throws(() => move(g, { Response: { SelectPositions: [] } }));
g = move(g, { Response: { SelectPositions: ['A3'] } });
assert(g.players[2].units.filter((u: any) => [1, 4].includes(u.id)).every((u: any) => u.position === 'A3'));
});