Fix tactical retreat, destroyed wonder draws, and Defiant Stand journal

Release viewer 0.1.222 and engine 0.4.155. Destroyed wonders are tracked publicly; saves from before this release cannot reconstruct Wonders already destroyed.
This commit is contained in:
coyotte508 2026-11-18 17:13:57 +00:00
commit e69d7148fb
50 changed files with 505 additions and 15 deletions

View file

@ -275,6 +275,7 @@
"Decline": "Afvis",
"Defend - combat round": "Forsvar - kamprunde",
"Defend - combat round {p0}": "Forsvar - kamprunde {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} i samlet kampværdi (1 pr. angribende enhed)",
"Defender": "Forsvarer",
"Defender wins": "Forsvarer vinder",
"Defending with": "Forsvarer med",

View file

@ -275,6 +275,7 @@
"Decline": "Ablehnen",
"Defend - combat round": "Verteidigen – Kampfrunde",
"Defend - combat round {p0}": "Verteidigen – Kampfrunde {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} Gesamtkampfwert (1 pro angreifender Einheit)",
"Defender": "Verteidiger",
"Defender wins": "Verteidiger gewinnt",
"Defending with": "Verteidigen mit",

View file

@ -275,6 +275,7 @@
"Decline": "Απόρριψη",
"Defend - combat round": "Άμυνα - γύρος μάχης",
"Defend - combat round {p0}": "Άμυνα - γύρος μάχης {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} στη συνολική αξία μάχης (1 ανά επιτιθέμενη μονάδα)",
"Defender": "Αμυνόμενος",
"Defender wins": "Ο αμυνόμενος κερδίζει",
"Defending with": "Άμυνα με",

View file

@ -275,6 +275,7 @@
"Decline": "Decline",
"Defend - combat round": "Defend - combat round",
"Defend - combat round {p0}": "Defend - combat round {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: -{p0} total combat value (1 per attacking unit)",
"Defender": "Defender",
"Defender wins": "Defender wins",
"Defending with": "Defending with",

View file

@ -275,6 +275,7 @@
"Decline": "نپذیرفتن",
"Defend - combat round": "دفاع — دور نبرد",
"Defend - combat round {p0}": "دفاع — دور نبرد {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: مجموع ارزش نبرد {p0}− (۱ برای هر واحد مهاجم)",
"Defender": "مدافع",
"Defender wins": "مدافع پیروز می‌شود",
"Defending with": "دفاع با",

View file

@ -275,6 +275,7 @@
"Decline": "Refuser",
"Defend - combat round": "Défendre - tour de combat",
"Defend - combat round {p0}": "Défendre - tour de combat {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand : −{p0} à la valeur de combat totale (1 par unité attaquante)",
"Defender": "Défenseur",
"Defender wins": "Le défenseur gagne",
"Defending with": "Défend avec",

View file

@ -275,6 +275,7 @@
"Decline": "अस्वीकार करें",
"Defend - combat round": "रक्षा - युद्ध दौर",
"Defend - combat round {p0}": "रक्षा - युद्ध दौर {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: कुल युद्ध मान −{p0} (प्रति आक्रमणकारी इकाई 1)",
"Defender": "रक्षक",
"Defender wins": "रक्षक जीतता है",
"Defending with": "से रक्षा कर रहे हैं",

View file

@ -275,6 +275,7 @@
"Decline": "Rifiuta",
"Defend - combat round": "Difesa - round di combattimento",
"Defend - combat round {p0}": "Difesa - round di combattimento {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} al valore di combattimento totale (1 per unità attaccante)",
"Defender": "Difensore",
"Defender wins": "Vince il difensore",
"Defending with": "Difende con",

View file

@ -275,6 +275,7 @@
"Decline": "거절",
"Defend - combat round": "방어 - 전투 라운드",
"Defend - combat round {p0}": "방어 - 전투 라운드 {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: 총 전투력 −{p0} (공격 유닛당 1)",
"Defender": "방어자",
"Defender wins": "방어자 승리",
"Defending with": "방어 중",

View file

@ -275,6 +275,7 @@
"Decline": "Weigeren",
"Defend - combat round": "Verdedigen - gevechtsronde",
"Defend - combat round {p0}": "Verdedigen - gevechtsronde {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} totale gevechtswaarde (1 per aanvallende eenheid)",
"Defender": "Verdediger",
"Defender wins": "Verdediger wint",
"Defending with": "Verdedigen met",

View file

@ -275,6 +275,7 @@
"Decline": "Odrzuć",
"Defend - combat round": "Obrona - runda walki",
"Defend - combat round {p0}": "Obrona - runda walki {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} do łącznej wartości bojowej (1 za każdą jednostkę atakującą)",
"Defender": "Obrońca",
"Defender wins": "Obrońca wygrywa",
"Defending with": "Obrona przy użyciu",

View file

@ -275,6 +275,7 @@
"Decline": "Recusar",
"Defend - combat round": "Defender - rodada de combate",
"Defend - combat round {p0}": "Defender - rodada de combate {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} no valor total de combate (1 por unidade atacante)",
"Defender": "Defensor",
"Defender wins": "Defensor vence",
"Defending with": "Defendendo com",

View file

@ -275,6 +275,7 @@
"Decline": "Refuză",
"Defend - combat round": "Apără - rundă de luptă",
"Defend - combat round {p0}": "Apără - rundă de luptă {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} la valoarea totală de luptă (1 pentru fiecare unitate atacatoare)",
"Defender": "Apărător",
"Defender wins": "Apărătorul câștigă",
"Defending with": "Se apără cu",

View file

@ -275,6 +275,7 @@
"Decline": "Отклонить",
"Defend - combat round": "Защита — раунд боя",
"Defend - combat round {p0}": "Защита — раунд боя {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} к общей боевой силе (1 за каждый атакующий отряд)",
"Defender": "Защитник",
"Defender wins": "Защитник побеждает",
"Defending with": "Защита с помощью",

View file

@ -275,6 +275,7 @@
"Decline": "Từ chối",
"Defend - combat round": "Phòng thủ - vòng chiến đấu",
"Defend - combat round {p0}": "Phòng thủ - vòng chiến đấu {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} tổng giá trị chiến đấu (1 cho mỗi đơn vị tấn công)",
"Defender": "Người phòng thủ",
"Defender wins": "Người phòng thủ thắng",
"Defending with": "Phòng thủ với",

View file

@ -275,6 +275,7 @@
"Decline": "拒绝",
"Defend - combat round": "防守 - 战斗轮",
"Defend - combat round {p0}": "防守 - 第{p0}战斗轮",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand:总战斗值 −{p0}(每个攻击单位 1 点)",
"Defender": "防守方",
"Defender wins": "防守方获胜",
"Defending with": "防守兵力",

View file

@ -275,6 +275,7 @@
"Decline": "拒絕",
"Defend - combat round": "防禦 - 戰鬥回合",
"Defend - combat round {p0}": "防禦 - 戰鬥回合 {p0}",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand:總戰鬥值 −{p0}(每個攻擊單位 1 點)",
"Defender": "防禦方",
"Defender wins": "防守方獲勝",
"Defending with": "正在防守",

View file

@ -3,15 +3,17 @@ use crate::action_card::{gain_action_card, gain_action_card_from_pile};
use crate::card::HandCardLocation;
use crate::combat::{Combat, update_combat_strength};
use crate::combat_listeners::{CombatResult, CombatRoundStart, CombatStrength, kill_combat_units};
use crate::content::civilizations::persia::stack_limit;
use crate::content::persistent_events::{PaymentRequest, PositionRequest, UnitsRequest};
use crate::game::Game;
use crate::leader::Leader;
use crate::position::Position;
use crate::resource_pile::ResourcePile;
use crate::tactics_card::{
CombatLocation, CombatRole, FighterRequirement, OpponentTacticsStatus, TacticsCard,
TacticsCardTarget, opponent_tactics_status,
};
use crate::unit::set_unit_position;
use crate::unit::{UnitType, set_unit_position};
use crate::utils::a_or_an;
use itertools::Itertools;
use std::vec;
@ -119,7 +121,7 @@ pub(crate) fn heavy_resistance(id: u8) -> TacticsCard {
let v = c.fighting_units(game, player).len() as i8;
s.extra_combat_value -= v;
s.roll_log.push(format!(
"Heavy resistance added -{v} to combat value for each unit"
"Defiant Stand: -{v} total combat value (1 per attacking unit)"
));
})
.build()
@ -288,11 +290,34 @@ pub(crate) fn tactical_retreat(id: u8) -> TacticsCard {
}
fn tactical_retreat_targets(c: &Combat, game: &Game) -> Vec<Position> {
let player = c.defender();
let player = game.player(c.defender());
let moving_army = player
.get_units(c.defender_position())
.iter()
.filter(|u| u.is_army_unit() && !u.is_transported())
.count();
let moving_xerxes = player
.get_units(c.defender_position())
.iter()
.any(|u| u.unit_type == UnitType::Leader(Leader::Xerxes));
c.defender_position()
.neighbors()
.into_iter()
.filter(|&p| game.map.is_land(p) && game.enemy_player(player, p).is_none())
.filter(|&p| {
let existing_army = player
.get_units(p)
.iter()
.filter(|u| u.is_army_unit() && !u.is_transported())
.count();
let limit = if moving_xerxes {
5
} else {
stack_limit(player, p)
};
game.map.is_land(p)
&& game.enemy_player(player.index, p).is_none()
&& moving_army + existing_army <= limit
})
.collect()
}
@ -454,3 +479,43 @@ pub(crate) fn flanking(id: u8) -> TacticsCard {
})
.build()
}
#[cfg(test)]
mod retreat_tests {
use super::tactical_retreat_targets;
use crate::game::{Game, GameContext};
use crate::game_data::GameData;
use crate::leader::Leader;
use crate::unit::{Unit, UnitType};
#[test]
fn xerxes_can_retreat_into_a_five_army_stack() {
let data: GameData = serde_json::from_str(include_str!(
"../../tests/test_games/tactics_cards/heavy_resistance.json"
))
.unwrap();
let cache = crate::cache::Cache::new(&data.options);
let mut game = Game::from_data(data, cache, GameContext::Play);
let from = crate::position::Position::from_offset("C1");
let destination = crate::position::Position::from_offset("B1");
game.players[1].civilization = game.cache.get_civilization("Persia");
game.players[1].units.clear();
for id in 0..3 {
game.players[1]
.units
.push(Unit::new(1, from, UnitType::Infantry, id));
}
game.players[1]
.units
.push(Unit::new(1, from, UnitType::Leader(Leader::Xerxes), 4));
game.players[1]
.units
.push(Unit::new(1, destination, UnitType::Infantry, 5));
let combat = crate::combat::Combat::new(
vec![],
false,
crate::combat_stats::new_combat_stats(&game, 1, from, 0, &[0], None),
);
assert_eq!(tactical_retreat_targets(&combat, &game), vec![destination]);
}
}

View file

@ -198,6 +198,8 @@ pub struct Game {
pub dice_roll_log: Vec<u8>,
pub dropped_players: Vec<usize>,
pub wonders_left: Vec<Wonder>,
/// Public history of wonders removed permanently from this game.
pub destroyed_wonders: Vec<Wonder>,
pub action_cards_left: Vec<u8>,
pub action_cards_discarded: Vec<u8>,
pub objective_cards_left: Vec<u8>,

View file

@ -106,6 +106,9 @@ pub struct GameData {
wonders_left: Vec<Wonder>,
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
destroyed_wonders: Vec<Wonder>,
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
action_cards_left: Vec<u8>,
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
@ -175,6 +178,7 @@ pub fn from_data(data: GameData, cache: Cache, context: GameContext) -> Game {
dice_roll_log: data.dice_roll_log,
dropped_players: data.dropped_players,
wonders_left: data.wonders_left,
destroyed_wonders: data.destroyed_wonders,
action_cards_left: data.action_cards_left,
action_cards_discarded: data.action_cards_discarded,
objective_cards_left: data.objective_cards_left,
@ -240,6 +244,7 @@ pub fn data(game: Game) -> GameData {
dice_roll_log: game.dice_roll_log,
dropped_players: game.dropped_players,
wonders_left: game.wonders_left,
destroyed_wonders: game.destroyed_wonders,
action_cards_left: game.action_cards_left,
action_cards_discarded: game.action_cards_discarded,
objective_cards_left: game.objective_cards_left,
@ -286,6 +291,7 @@ pub fn cloned_data(game: &Game) -> GameData {
dice_roll_log: game.dice_roll_log.clone(),
dropped_players: game.dropped_players.clone(),
wonders_left: game.wonders_left.clone(),
destroyed_wonders: game.destroyed_wonders.clone(),
action_cards_left: game.action_cards_left.clone(),
action_cards_discarded: game.action_cards_discarded.clone(),
objective_cards_left: game.objective_cards_left.clone(),

View file

@ -230,6 +230,7 @@ pub fn setup_game_with_cache(setup: &GameSetup, cache: Cache) -> Game {
dice_roll_log: Vec::new(),
dropped_players: Vec::new(),
wonders_left,
destroyed_wonders: Vec::new(),
action_cards_left,
action_cards_discarded: Vec::new(),
objective_cards_left,

View file

@ -303,7 +303,9 @@ pub(crate) fn force_draw_wonder_from_anywhere(
{
false
} else {
panic!("Wonder card {wonder} not found in the game state, but was requested to be drawn.")
// Old saves cannot recover destructions which predate destroyed_wonders.
// Treat an unavailable expert wonder as an ordinary draw rather than panic.
false
}
}
@ -557,6 +559,9 @@ pub(crate) fn destroy_wonder(
wonder: Wonder,
position: Position,
) {
if !game.destroyed_wonders.contains(&wonder) {
game.destroyed_wonders.push(wonder);
}
lose_wonder(game, player, wonder, position);
for p in &mut game.players {
remove_element(&mut p.wonders_built, &wonder);
@ -678,3 +683,161 @@ pub(crate) fn wonder_cost(game: &Game, player: &Player, w: Wonder) -> CostInfo {
.add_extra_options(player, EventOrigin::Wonder(w)),
)
}
#[cfg(test)]
mod destroyed_wonder_tests {
use super::Wonder;
use crate::action::Action;
use crate::advance::Advance;
use crate::cache::Cache;
use crate::content::persistent_events::{EventResponse, SelectedStructure};
use crate::game::{Game, GameContext};
use crate::game_api;
use crate::game_data::GameData;
use crate::leader::Leader;
use crate::playing_actions::PlayingAction::WonderCard;
use crate::position::Position;
use crate::resource_pile::ResourcePile;
use crate::structure::Structure;
use crate::unit::UnitType;
fn game() -> Game {
let data: GameData = serde_json::from_str(include_str!(
"../tests/test_games/civilizations/china/great_wall.json"
))
.unwrap();
let cache = Cache::new(&data.options);
Game::from_data(data, cache, GameContext::Play)
}
fn response(game: Game, response: EventResponse) -> Game {
game_api::execute(game, Action::Response(response), 0)
}
fn destroyed_wonder_expert_game(wonder: Wonder, civilization: &str) -> Game {
let city = Position::from_offset("D1");
let mut game = game();
game.players[0].civilization = game.cache.get_civilization(civilization);
let leader = if civilization == "China" {
Leader::Qin
} else {
Leader::Hammurabi
};
game.players[0].units[0].unit_type = UnitType::Leader(leader);
game.players[0].recruited_leaders = vec![leader];
game.players[0].wonder_cards = vec![wonder];
game.players[0].resources = ResourcePile::new(9, 9, 9, 9, 9, 9, 9);
game.players[0]
.cities
.push(crate::city::City::new(0, Position::from_offset("C1")));
game.players[0].advances.insert(Advance::Engineering);
game.players[0].advances.insert(Advance::Irrigation);
game.players[0].advances.insert(Advance::Math);
game.players[0].advances.insert(Advance::Astronomy);
let mut game = game.clone();
game.wonders_left.retain(|w| *w != wonder);
game.players[1].wonder_cards.clear();
let mut game = game_api::execute(game, Action::Playing(WonderCard(wonder)), 0);
let payment = if wonder == Wonder::GreatWall {
ResourcePile::new(3, 2, 7, 0, 0, 0, 3)
} else {
ResourcePile::new(5, 5, 2, 0, 0, 0, 5)
};
game = response(game, EventResponse::Payment(vec![payment]));
assert!(
game.players[0]
.get_city(city)
.pieces
.wonders
.contains(&wonder)
);
game.player_mut(0).special_advances.clear();
game.player_mut(0).incident_tokens = 1;
game.incidents_left = vec![30];
game.wonders_left.retain(|w| *w != Wonder::Pyramids);
game.wonders_left.push(Wonder::Pyramids);
game.permanent_effects.clear();
game.actions_left = 1;
game = game_api::execute(
game,
Action::Playing(crate::playing_actions::PlayingAction::Advance(
crate::advance::AdvanceAction::new(Advance::Storage, ResourcePile::food(2)),
)),
0,
);
assert!(game.cache.get_incident(30).name == "Earthquake");
response(
game,
EventResponse::SelectStructures(vec![SelectedStructure::new(
city,
Structure::Wonder(wonder),
)]),
)
}
fn ordinary_engineering_draw(mut game: Game) -> Game {
game.player_mut(0).advances.remove(Advance::Roads);
game.player_mut(0).advances.remove(Advance::Engineering);
let cache = game.cache.clone();
game = Game::from_data(game.cloned_data(), cache, GameContext::Play);
game_api::execute(
game,
Action::Playing(crate::playing_actions::PlayingAction::Advance(
crate::advance::AdvanceAction::new(Advance::Engineering, ResourcePile::empty()),
)),
0,
)
}
#[test]
fn destroyed_wonders_are_public_unique_and_legacy_compatible() {
let data = game().cloned_data();
let value = serde_json::to_value(&data).unwrap();
assert!(value.get("destroyed_wonders").is_none());
let legacy: GameData = serde_json::from_value(value).unwrap();
let legacy = Game::from_data(legacy, game().cache, GameContext::Play);
assert!(legacy.destroyed_wonders.is_empty());
let game = destroyed_wonder_expert_game(Wonder::GreatWall, "China");
let cache = game.cache.clone();
let roundtrip = Game::from_data(game.cloned_data(), cache, GameContext::Play);
assert!(roundtrip.cloned_data() == game.cloned_data());
for seat in [Some(0), Some(1), None] {
let public = crate::game_api::strip_secret(game.clone(), seat);
assert_eq!(public.destroyed_wonders, vec![Wonder::GreatWall]);
}
assert_eq!(game.destroyed_wonders, vec![Wonder::GreatWall]);
}
#[test]
fn destroyed_great_wall_is_not_forced_back_by_qin_engineering() {
let city = Position::from_offset("D1");
let mut game = destroyed_wonder_expert_game(Wonder::GreatWall, "China");
assert_eq!(game.destroyed_wonders, vec![Wonder::GreatWall]);
assert!(game.players[0].wonders_built.is_empty());
assert!(game.players[0].get_city(city).pieces.wonders.is_empty());
game.actions_left = 1;
let game = ordinary_engineering_draw(game);
assert_eq!(game.players[0].wonder_cards.len(), 1);
assert_ne!(game.players[0].wonder_cards[0], Wonder::GreatWall);
assert!(game.players[0].wonders_built.is_empty());
assert!(game.players[0].get_city(city).pieces.wonders.is_empty());
for seat in [Some(0), Some(1), None] {
let public = crate::game_api::strip_secret(game.clone(), seat);
assert_eq!(public.destroyed_wonders, vec![Wonder::GreatWall]);
}
}
#[test]
fn babylonia_also_skips_destroyed_great_gardens() {
let mut game = destroyed_wonder_expert_game(Wonder::GreatGardens, "Babylonia");
game.actions_left = 1;
let game = ordinary_engineering_draw(game);
assert_eq!(game.players[0].wonder_cards.len(), 1);
assert_ne!(game.players[0].wonder_cards[0], Wonder::GreatGardens);
for seat in [Some(0), Some(1), None] {
let public = crate::game_api::strip_secret(game.clone(), seat);
assert_eq!(public.destroyed_wonders, vec![Wonder::GreatGardens]);
}
}
}

View file

@ -344,6 +344,97 @@ fn fortress_without_army_cannot_use_tactical_retreat_even_from_a_saved_prompt()
);
}
fn retreat_game(defender_army: usize) -> server::game::Game {
use server::unit::{Unit, UnitType};
let city = Position::from_offset("C1");
let destination = Position::from_offset("B1");
let mut setup = JSON.load_game("heavy_resistance");
setup.players[0].action_cards.clear();
setup.players[0]
.advances
.insert(server::advance::Advance::Engineering);
setup.players[0].cities.clear();
setup.players[1].civilization = setup.cache.get_civilization("Persia");
setup.players[1].action_cards = vec![19];
setup.players[1].units.clear();
for id in 0..defender_army as u32 {
setup.players[1]
.units
.push(Unit::new(1, city, UnitType::Infantry, id));
}
setup.players[1]
.units
.push(Unit::new(1, city, UnitType::Settler, 10));
setup.players[1]
.units
.push(Unit::new(1, destination, UnitType::Infantry, 11));
setup.players[1].next_unit_id = 12;
setup.clone()
}
fn retreat_view(game: &server::game::Game) -> serde_json::Value {
server::web_view::view(game, Some(1))
}
#[test]
fn tactical_retreat_respects_stack_limit_and_moves_settlers() {
use server::game_api;
use server::unit::UnitType;
let city = Position::from_offset("C1");
let destination = Position::from_offset("B1");
let setup = retreat_game(1);
let game = game_api::execute(setup, move_action(vec![0], city), 0);
let view = retreat_view(&game);
assert_eq!(view["decision"]["options"].as_array().unwrap().len(), 1);
let game = game_api::execute(
game,
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
19,
)])),
1,
);
let text = serde_json::to_value(game.cloned_data()).unwrap()["log"].to_string();
assert!(text.contains("withdraws to B1"));
assert_eq!(game.player(1).get_units(destination).len(), 3);
assert!(game.player(1).get_units(city).is_empty());
assert!(
game.player(1)
.get_units(destination)
.iter()
.any(|u| u.unit_type == UnitType::Settler)
);
}
#[test]
fn tactical_retreat_is_unavailable_when_every_destination_would_overflow() {
use server::game_api;
use server::unit::{Unit, UnitType};
let city = Position::from_offset("C1");
let other = Position::from_offset("B2");
let mut setup = retreat_game(2);
setup.players[1]
.units
.push(Unit::new(1, other, UnitType::Infantry, 12));
setup.players[1]
.units
.push(Unit::new(1, other, UnitType::Infantry, 13));
setup.players[1]
.units
.push(Unit::new(1, other, UnitType::Infantry, 14));
let game = game_api::execute(setup, move_action(vec![0], city), 0);
let game = game_api::execute(
game,
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
19,
)])),
1,
);
let text = serde_json::to_value(game.cloned_data()).unwrap()["log"].to_string();
assert!(text.contains("withdraws to"));
assert!(game.player(1).get_units(city).is_empty());
}
#[test]
fn high_ground_is_not_skipped_after_attacker_flanking() {
let mut game = JSON.load_game("high_ground");

View file

@ -513,5 +513,8 @@
],
"wonders_left": [
"Pyramids"
],
"destroyed_wonders": [
"GreatWall"
]
}
}

View file

@ -542,5 +542,8 @@
],
"incidents_discarded": [
31
],
"destroyed_wonders": [
"GreatGardens"
]
}
}

View file

@ -400,5 +400,8 @@
],
"incidents_discarded": [
29
],
"destroyed_wonders": [
"Pyramids"
]
}
}

View file

@ -317,7 +317,7 @@
"combat_value": 6,
"hits": 1,
"combat_modifiers": [
"Heavy resistance added -1 to combat value for each unit"
"Defiant Stand: -1 total combat value (1 per attacking unit)"
]
},
"origin": {

View file

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

View file

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

View file

@ -13,7 +13,7 @@
"web-client/src/civilization-emblems.ts": "01b0cbf3fa77a8466532ccd73d63c1a3ddc9bbc79fc06ce7224b425322a9c9f0",
"web-client/src/civilization-flags.ts": "cd176076bfe05b3059093b80c88596b7ae46b77898695c6c7406cbe1a3a0f78b",
"server/src/content/civilizations.rs": "73602f3db506f3dc2dbc6de43d01179440fd3bb034c997ff209336faaef2a332",
"web-client/package-lock.json": "f198e8d7b6e5cedc731a145c57146ac5db75f70ef6baf4683a066b5b054a07ab",
"web-client/package-lock.json": "fdd8822dddd32f6cead371a15091c6c5394cb6687a380ac4d17a3fceb4798bf0",
"web-client/node_modules/lucide-svelte/dist/Icon.svelte": "f7b49ab842c143fa680fa8bd9a54a9efdc48c2e2d49fa574bd5ccf8f6cfca5be",
"web-client/node_modules/lucide-svelte/dist/defaultAttributes.js": "5b8981c6e3434ae6538716af9e0403554e7708c4087f18d060950a7bef00d96a",
"web-client/node_modules/lucide-svelte/LICENSE": "668dcc52803480e0a026b31140a4cae668772663cd764e5991d252eef03f98db"

View file

@ -1,10 +1,15 @@
{
"name": "@boardgamers/clash-server",
"version": "0.4.154",
"version": "0.4.155",
"description": "Clash of Cultures: Monumental edition engine for Boardgamers Space",
"license": "MIT",
"type": "commonjs",
"main": "server.js",
"types": "server.d.ts",
"files": ["server.js", "server_bg.wasm", "server.d.ts", "server_bg.wasm.d.ts"]
"files": [
"server.js",
"server_bg.wasm",
"server.d.ts",
"server_bg.wasm.d.ts"
]
}

View file

@ -262,6 +262,20 @@ test('ambiguous adjacent parameters are not guessed, and nested caches do not po
assert.equal(t.translate('city size 3, Fortress'), 'ville de taille 3, Forteresse');
});
test('Defiant Stand journal uses a single total penalty and preserves legacy translation', async () => {
const { readFile } = await import('node:fs/promises');
const modern = 'Defiant Stand: -3 total combat value (1 per attacking unit)';
const legacy = 'Heavy resistance added -3 to combat value for each unit';
for (const locale of ['en', 'fr', 'de', 'da', 'el', 'fa', 'hi', 'it', 'ko', 'nl', 'pl', 'pt-BR', 'ro', 'ru', 'vi', 'zh-CN', 'zh-TW']) {
const catalog = JSON.parse(await readFile(new URL(`./localization/${locale}.json`, import.meta.url), 'utf8'));
const translator = createTranslator({ [locale]: catalog }, locale);
const expected = catalog['Defiant Stand: -{p0} total combat value (1 per attacking unit)'].replace('{p0}', '3');
assert.equal(translator.translate(modern), expected, locale);
assert.equal(translator.translate(legacy), catalog['Heavy resistance added -{p0} to combat value for each unit'].replace('{p0}', '3'), locale);
assert.ok(!expected.includes('3 total combat value (3'), locale);
}
});
test('wonder research hints translate the complete required-for caption and private-hand subtitle', async () => {
const { readFile } = await import('node:fs/promises');
for (const locale of ['en', 'fr', 'de', 'da', 'el', 'fa', 'hi', 'it', 'ko', 'nl', 'pl', 'pt-BR', 'ro', 'ru', 'vi', 'zh-CN', 'zh-TW']) {

View file

@ -4724,6 +4724,7 @@
"Routing": "Omringet",
"Tactical Surprise": "Overraskelse",
"The Siege": "Belejring",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} i samlet kampværdi (1 pr. angribende enhed)",
"Defiant Stand": "Hård modstand",
"Upgraded Defenses": "Forbedret forsvar",
"Prepared Defenses": "Defensiv formation",

View file

@ -4724,6 +4724,7 @@
"Routing": "Umzingelt",
"Tactical Surprise": "Überraschung",
"The Siege": "Belagerung",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} Gesamtkampfwert (1 pro angreifender Einheit)",
"Defiant Stand": "Heftiger Widerstand",
"Upgraded Defenses": "Verbesserte Verteidigung",
"Prepared Defenses": "Defensivformation",

View file

@ -4724,6 +4724,7 @@
"Routing": "Περικυκλωμένος",
"Tactical Surprise": "Αιφνιδιασμός",
"The Siege": "Πολιορκία",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} στη συνολική αξία μάχης (1 ανά επιτιθέμενη μονάδα)",
"Defiant Stand": "Ισχυρή Αντίσταση",
"Upgraded Defenses": "Βελτιωμένες Άμυνες",
"Prepared Defenses": "Αμυντικός Σχηματισμός",

View file

@ -4724,6 +4724,7 @@
"Routing": "Routing",
"Tactical Surprise": "Tactical Surprise",
"The Siege": "The Siege",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: -{p0} total combat value (1 per attacking unit)",
"Defiant Stand": "Defiant Stand",
"Upgraded Defenses": "Upgraded Defenses",
"Prepared Defenses": "Prepared Defenses",

View file

@ -4724,6 +4724,7 @@
"Routing": "محاصره‌شده",
"Tactical Surprise": "غافلگیری",
"The Siege": "محاصره",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: مجموع ارزش نبرد {p0}− (۱ برای هر واحد مهاجم)",
"Defiant Stand": "مقاومت شدید",
"Upgraded Defenses": "دفاع پیشرفته",
"Prepared Defenses": "آرایش دفاعی",

View file

@ -4724,6 +4724,7 @@
"Routing": "Encerclé",
"Tactical Surprise": "Surprise",
"The Siege": "Siège",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand : −{p0} à la valeur de combat totale (1 par unité attaquante)",
"Defiant Stand": "Résistance Acharnée",
"Upgraded Defenses": "Défenses améliorées",
"Prepared Defenses": "Formation défensive",

View file

@ -4724,6 +4724,7 @@
"Routing": "घेर लिया गया",
"Tactical Surprise": "अचानक हमला",
"The Siege": "घेराबंदी",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: कुल युद्ध मान −{p0} (प्रति आक्रमणकारी इकाई 1)",
"Defiant Stand": "भारी प्रतिरोध",
"Upgraded Defenses": "बेहतर सुरक्षा",
"Prepared Defenses": "रक्षात्मक संरचना",

View file

@ -4724,6 +4724,7 @@
"Routing": "Accerchiato",
"Tactical Surprise": "Sorpresa",
"The Siege": "Assedio",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} al valore di combattimento totale (1 per unità attaccante)",
"Defiant Stand": "Resistenza Accanita",
"Upgraded Defenses": "Difese Migliorate",
"Prepared Defenses": "Formazione Difensiva",

View file

@ -4724,6 +4724,7 @@
"Routing": "포위됨",
"Tactical Surprise": "기습",
"The Siege": "공성전",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: 총 전투력 −{p0} (공격 유닛당 1)",
"Defiant Stand": "강력한 저항",
"Upgraded Defenses": "개선된 방어",
"Prepared Defenses": "방어 진형",

View file

@ -4724,6 +4724,7 @@
"Routing": "Omsingeld",
"Tactical Surprise": "Verrassing",
"The Siege": "Beleg",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} totale gevechtswaarde (1 per aanvallende eenheid)",
"Defiant Stand": "Zware Weerstand",
"Upgraded Defenses": "Verbeterde Verdediging",
"Prepared Defenses": "Defensieve formatie",

View file

@ -4724,6 +4724,7 @@
"Routing": "Okrążony",
"Tactical Surprise": "Zaskoczenie",
"The Siege": "Oblężenie",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} do łącznej wartości bojowej (1 za każdą jednostkę atakującą)",
"Defiant Stand": "Silny Opór",
"Upgraded Defenses": "Ulepszone Obrony",
"Prepared Defenses": "Formacja obronna",

View file

@ -4724,6 +4724,7 @@
"Routing": "Cercado",
"Tactical Surprise": "Surpresa",
"The Siege": "Cerco",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} no valor total de combate (1 por unidade atacante)",
"Defiant Stand": "Resistência Pesada",
"Upgraded Defenses": "Defesas Melhoradas",
"Prepared Defenses": "Formação Defensiva",

View file

@ -4724,6 +4724,7 @@
"Routing": "Încercuit",
"Tactical Surprise": "Surpriză",
"The Siege": "Asediu",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} la valoarea totală de luptă (1 pentru fiecare unitate atacatoare)",
"Defiant Stand": "Rezistență Puternică",
"Upgraded Defenses": "Apărări Îmbunătățite",
"Prepared Defenses": "Formație Defensivă",

View file

@ -4724,6 +4724,7 @@
"Routing": "Окружён",
"Tactical Surprise": "Внезапность",
"The Siege": "Осада",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} к общей боевой силе (1 за каждый атакующий отряд)",
"Defiant Stand": "Ожесточённое сопротивление",
"Upgraded Defenses": "Улучшенная оборона",
"Prepared Defenses": "Оборонительный строй",

View file

@ -4724,6 +4724,7 @@
"Routing": "Bị bao vây",
"Tactical Surprise": "Bất ngờ",
"The Siege": "Vây hãm",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand: −{p0} tổng giá trị chiến đấu (1 cho mỗi đơn vị tấn công)",
"Defiant Stand": "Kháng cự mạnh mẽ",
"Upgraded Defenses": "Phòng thủ Cải tiến",
"Prepared Defenses": "Đội hình Phòng thủ",

View file

@ -4724,6 +4724,7 @@
"Routing": "溃败",
"Tactical Surprise": "战术奇袭",
"The Siege": "围城",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand:总战斗值 −{p0}(每个攻击单位 1 点)",
"Defiant Stand": "顽强坚守",
"Upgraded Defenses": "升级防御",
"Prepared Defenses": "预备防御",

View file

@ -4724,6 +4724,7 @@
"Routing": "被包圍",
"Tactical Surprise": "奇襲",
"The Siege": "圍攻",
"Defiant Stand: -{p0} total combat value (1 per attacking unit)": "Defiant Stand:總戰鬥值 −{p0}(每個攻擊單位 1 點)",
"Defiant Stand": "頑強抵抗",
"Upgraded Defenses": "改良防禦",
"Prepared Defenses": "防禦陣型",

View file

@ -0,0 +1,100 @@
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)(process.env.CLASH_TEST_ENGINE ?? '../.engine/server.js');
const fixture = (name: string) => JSON.parse(readFileSync(new URL(`../../server/tests/test_games/${name}.json`, import.meta.url), 'utf8'));
const apply = (raw: string, action: unknown, player = engine.currentPlayer(raw)) => engine.tryMove(raw, JSON.stringify(action), player);
const view = (raw: string, player: number) => JSON.parse(engine.webView(engine.stripSecret(raw, player), player));
const city = { id: 0, player_id: 0, mood_state: 'Happy', position: 'C1', pieces: { wonders: [] } };
const infantry = (id: number, position: string) => ({ id, player_id: 1, position, unit_type: 'Infantry' });
function retreat(defenders: number) {
const g = fixture('tactics_cards/heavy_resistance');
g.players[0].action_cards = [];
g.players[0].advances.push('Engineering');
g.players[0].cities = [];
g.players[1].civilization = 'Persia';
g.players[1].action_cards = [19];
g.players[1].units = Array.from({ length: defenders }, (_, i) => infantry(i, 'C1'));
g.players[1].units.push({ id: 10, player_id: 1, position: 'C1', unit_type: 'Settler' });
g.players[1].units.push(infantry(11, 'B1'));
g.players[1].next_unit_id = 12;
return g;
}
test('actual Tactical Retreat options include stack limits and the full group', () => {
let raw = apply(JSON.stringify(retreat(1)), { Movement: { Move: { units: [0], destination: 'C1', payment: {} } } }, 0);
assert.equal(view(raw, 1).decision.options.length, 1);
raw = apply(raw, { Response: { SelectHandCards: [{ ActionCard: 19 }] } }, 1);
const g = JSON.parse(raw);
assert.equal(g.players[1].units.filter((u: any) => u.position === 'B1').length, 3);
assert.equal(g.players[1].units.filter((u: any) => u.position === 'C1').length, 0);
assert(g.players[1].units.some((u: any) => u.unit_type === 'Settler' && u.position === 'B1'));
assert.equal(g.players[0].units.length, 8);
});
test('actual Tactical Retreat remains playable when every destination would overflow', () => {
const g = retreat(2);
g.players[1].units.push(infantry(12, 'B2'), infantry(13, 'B2'), infantry(14, 'B2'));
let raw = apply(JSON.stringify(g), { Movement: { Move: { units: [0], destination: 'C1', payment: {} } } }, 0);
raw = apply(raw, { Response: { SelectHandCards: [{ ActionCard: 19 }] } }, 1);
assert(JSON.stringify(JSON.parse(raw).log).includes('withdraws to'));
});
async function destroyedWonder(wonder: string, civilization: string) {
const g = fixture('civilizations/china/great_wall');
const npcs = JSON.parse(await engine.init(2, [], {}, 'wonder-regression', {})).players.slice(2);
g.players.push(...npcs);
const leader = civilization === 'China' ? 'Qin' : 'Hammurabi';
g.players[0].civilization = civilization;
g.players[0].units[0].unit_type = { Leader: leader };
g.players[0].recruited_leaders = [leader];
g.players[0].wonder_cards = [wonder];
g.players[0].resources = { food: 9, wood: 9, ore: 9, ideas: 9, gold: 9, mood_tokens: 9, culture_tokens: 9 };
g.players[0].cities.push(city);
for (const advance of ['Engineering', 'Irrigation', 'Math', 'Astronomy']) if (!g.players[0].advances.includes(advance)) g.players[0].advances.push(advance);
g.wonders_left = g.wonders_left.filter((w: string) => w !== wonder);
g.players[1].wonder_cards = [];
let raw = apply(JSON.stringify(g), { Playing: { WonderCard: wonder } }, 0);
raw = apply(raw, { Response: { SelectPositions: ['D1'] } }, 0);
const payment = wonder === 'GreatWall' ? { food: 3, wood: 2, ore: 7, culture_tokens: 3 } : { food: 5, wood: 5, ore: 2, culture_tokens: 5 };
raw = apply(raw, { Response: { Payment: [payment] } }, 0);
let state = JSON.parse(raw);
assert.equal(state.events?.length ?? 0, 0, JSON.stringify(state.events));
assert(state.players[0].cities.find((c: any) => c.position === 'D1').city_pieces.wonders.includes(wonder));
state.players[0].special_advances = [];
state.players[0].incident_tokens = 1;
state.incidents_left = [30];
state.wonders_left = ['Pyramids'];
state.permanent_effects = [];
state.actions_left = 1;
raw = apply(JSON.stringify(state), { Playing: { Advance: { advance: 'Storage', payment: { food: 2 } } } }, 0);
if (civilization === 'Babylonia') {
// Astronomy enables Star Catalogues, which legitimately resolves before the incident.
raw = apply(raw, { Response: { ResourceReward: { ideas: 1 } } }, 0);
}
raw = apply(raw, { Response: { SelectStructures: [{ position: 'D1', structure: { Wonder: wonder } }] } }, 0);
state = JSON.parse(raw);
assert.equal(state.events?.length ?? 0, 0, JSON.stringify(state.events));
assert.deepEqual(state.destroyed_wonders, [wonder]);
state.players[0].advances = state.players[0].advances.filter((a: string) => !['Roads', 'Engineering'].includes(a));
state.actions_left = 1;
raw = apply(JSON.stringify(state), { Playing: { Advance: { advance: 'Engineering', payment: {} } } }, 0);
state = JSON.parse(raw);
assert.deepEqual(state.players[0].wonder_cards, ['Pyramids']);
assert.equal(state.players[0].wonders_built?.length ?? 0, 0);
for (const seat of [0, 1, null]) {
const publicState = JSON.parse(engine.stripSecret(raw, seat));
assert.deepEqual(publicState.destroyed_wonders, [wonder]);
}
assert.deepEqual(JSON.parse(raw).destroyed_wonders, [wonder]);
const original = fixture('civilizations/china/great_wall');
assert.equal(original.destroyed_wonders, undefined);
}
test('Qin and Babylonia use ordinary Engineering draws after real Earthquake destruction', async () => {
await destroyedWonder('GreatWall', 'China');
await destroyedWonder('GreatGardens', 'Babylonia');
});
test('Defiant Stand journal reports one total arithmetic penalty', () => {
let raw = JSON.stringify(fixture('tactics_cards/heavy_resistance'));
raw = apply(raw, { Movement: { Move: { units: [0], destination: 'C1', payment: {} } } }, 0);
raw = apply(raw, { Response: { SelectHandCards: [{ ActionCard: 7 }] } }, 1);
assert(JSON.stringify(JSON.parse(raw).log).includes('Defiant Stand: -1 total combat value (1 per attacking unit)'));
});