diff --git a/client/js/src/localization/da.json b/client/js/src/localization/da.json index 9fc8f592..e86b245f 100644 --- a/client/js/src/localization/da.json +++ b/client/js/src/localization/da.json @@ -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", diff --git a/client/js/src/localization/de.json b/client/js/src/localization/de.json index 6b8bea26..6f678ad9 100644 --- a/client/js/src/localization/de.json +++ b/client/js/src/localization/de.json @@ -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", diff --git a/client/js/src/localization/el.json b/client/js/src/localization/el.json index dac7993e..2f88eab4 100644 --- a/client/js/src/localization/el.json +++ b/client/js/src/localization/el.json @@ -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": "Άμυνα με", diff --git a/client/js/src/localization/en.json b/client/js/src/localization/en.json index e585c5b7..ff2c3582 100644 --- a/client/js/src/localization/en.json +++ b/client/js/src/localization/en.json @@ -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", diff --git a/client/js/src/localization/fa.json b/client/js/src/localization/fa.json index f065c060..cd15f1ca 100644 --- a/client/js/src/localization/fa.json +++ b/client/js/src/localization/fa.json @@ -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": "دفاع با", diff --git a/client/js/src/localization/fr.json b/client/js/src/localization/fr.json index dcb9cf04..92824ee4 100644 --- a/client/js/src/localization/fr.json +++ b/client/js/src/localization/fr.json @@ -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", diff --git a/client/js/src/localization/hi.json b/client/js/src/localization/hi.json index 61b7a02a..2f3041b9 100644 --- a/client/js/src/localization/hi.json +++ b/client/js/src/localization/hi.json @@ -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": "से रक्षा कर रहे हैं", diff --git a/client/js/src/localization/it.json b/client/js/src/localization/it.json index 73a4ba2b..136b6163 100644 --- a/client/js/src/localization/it.json +++ b/client/js/src/localization/it.json @@ -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", diff --git a/client/js/src/localization/ko.json b/client/js/src/localization/ko.json index 7763d383..03bb24f4 100644 --- a/client/js/src/localization/ko.json +++ b/client/js/src/localization/ko.json @@ -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": "방어 중", diff --git a/client/js/src/localization/nl.json b/client/js/src/localization/nl.json index d9b69fd0..ab5f19ff 100644 --- a/client/js/src/localization/nl.json +++ b/client/js/src/localization/nl.json @@ -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", diff --git a/client/js/src/localization/pl.json b/client/js/src/localization/pl.json index 20ebfe80..f43e7759 100644 --- a/client/js/src/localization/pl.json +++ b/client/js/src/localization/pl.json @@ -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", diff --git a/client/js/src/localization/pt-BR.json b/client/js/src/localization/pt-BR.json index ef267911..34482d83 100644 --- a/client/js/src/localization/pt-BR.json +++ b/client/js/src/localization/pt-BR.json @@ -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", diff --git a/client/js/src/localization/ro.json b/client/js/src/localization/ro.json index b6f671cc..7d3b9bd6 100644 --- a/client/js/src/localization/ro.json +++ b/client/js/src/localization/ro.json @@ -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", diff --git a/client/js/src/localization/ru.json b/client/js/src/localization/ru.json index 1426604b..bd413e93 100644 --- a/client/js/src/localization/ru.json +++ b/client/js/src/localization/ru.json @@ -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": "Защита с помощью", diff --git a/client/js/src/localization/vi.json b/client/js/src/localization/vi.json index e5bb542d..567d06fc 100644 --- a/client/js/src/localization/vi.json +++ b/client/js/src/localization/vi.json @@ -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", diff --git a/client/js/src/localization/zh-CN.json b/client/js/src/localization/zh-CN.json index 5fb7b060..d6754257 100644 --- a/client/js/src/localization/zh-CN.json +++ b/client/js/src/localization/zh-CN.json @@ -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": "防守兵力", diff --git a/client/js/src/localization/zh-TW.json b/client/js/src/localization/zh-TW.json index 1627ce4c..38125425 100644 --- a/client/js/src/localization/zh-TW.json +++ b/client/js/src/localization/zh-TW.json @@ -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": "正在防守", diff --git a/server/src/content/tactics_cards.rs b/server/src/content/tactics_cards.rs index 6886d22f..4d482dfe 100644 --- a/server/src/content/tactics_cards.rs +++ b/server/src/content/tactics_cards.rs @@ -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 { - 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]); + } +} diff --git a/server/src/game.rs b/server/src/game.rs index 8d3e6287..0a8da7da 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -198,6 +198,8 @@ pub struct Game { pub dice_roll_log: Vec, pub dropped_players: Vec, pub wonders_left: Vec, + /// Public history of wonders removed permanently from this game. + pub destroyed_wonders: Vec, pub action_cards_left: Vec, pub action_cards_discarded: Vec, pub objective_cards_left: Vec, diff --git a/server/src/game_data.rs b/server/src/game_data.rs index 74263e56..cadcbd16 100644 --- a/server/src/game_data.rs +++ b/server/src/game_data.rs @@ -106,6 +106,9 @@ pub struct GameData { wonders_left: Vec, #[serde(default)] #[serde(skip_serializing_if = "Vec::is_empty")] + destroyed_wonders: Vec, + #[serde(default)] + #[serde(skip_serializing_if = "Vec::is_empty")] action_cards_left: Vec, #[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(), diff --git a/server/src/game_setup.rs b/server/src/game_setup.rs index 651093de..0d6d3c45 100644 --- a/server/src/game_setup.rs +++ b/server/src/game_setup.rs @@ -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, diff --git a/server/src/wonder.rs b/server/src/wonder.rs index 3518162c..41486697 100644 --- a/server/src/wonder.rs +++ b/server/src/wonder.rs @@ -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]); + } + } +} diff --git a/server/tests/tactics_card_tests.rs b/server/tests/tactics_card_tests.rs index 5e576760..6fd0f318 100644 --- a/server/tests/tactics_card_tests.rs +++ b/server/tests/tactics_card_tests.rs @@ -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"); diff --git a/server/tests/test_games/combat/capture_and_raze_city.outcome.json b/server/tests/test_games/combat/capture_and_raze_city.outcome.json index 09bb39b3..4c9ce8a0 100644 --- a/server/tests/test_games/combat/capture_and_raze_city.outcome.json +++ b/server/tests/test_games/combat/capture_and_raze_city.outcome.json @@ -513,5 +513,8 @@ ], "wonders_left": [ "Pyramids" + ], + "destroyed_wonders": [ + "GreatWall" ] -} \ No newline at end of file +} diff --git a/server/tests/test_games/incidents/earthquake/earthquake.outcome3.json b/server/tests/test_games/incidents/earthquake/earthquake.outcome3.json index 72535a1e..fcd4827a 100644 --- a/server/tests/test_games/incidents/earthquake/earthquake.outcome3.json +++ b/server/tests/test_games/incidents/earthquake/earthquake.outcome3.json @@ -542,5 +542,8 @@ ], "incidents_discarded": [ 31 + ], + "destroyed_wonders": [ + "GreatGardens" ] -} \ No newline at end of file +} diff --git a/server/tests/test_games/incidents/earthquake/volcano.outcome1.json b/server/tests/test_games/incidents/earthquake/volcano.outcome1.json index f435ad8a..8eb39d09 100644 --- a/server/tests/test_games/incidents/earthquake/volcano.outcome1.json +++ b/server/tests/test_games/incidents/earthquake/volcano.outcome1.json @@ -400,5 +400,8 @@ ], "incidents_discarded": [ 29 + ], + "destroyed_wonders": [ + "Pyramids" ] -} \ No newline at end of file +} diff --git a/server/tests/test_games/tactics_cards/heavy_resistance.outcome1.json b/server/tests/test_games/tactics_cards/heavy_resistance.outcome1.json index 9ee13754..c14c05d2 100644 --- a/server/tests/test_games/tactics_cards/heavy_resistance.outcome1.json +++ b/server/tests/test_games/tactics_cards/heavy_resistance.outcome1.json @@ -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": { diff --git a/web-client/package-lock.json b/web-client/package-lock.json index 395bde1f..ee3f3e36 100644 --- a/web-client/package-lock.json +++ b/web-client/package-lock.json @@ -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", diff --git a/web-client/package.json b/web-client/package.json index 781f4eb3..840057e2 100644 --- a/web-client/package.json +++ b/web-client/package.json @@ -1,6 +1,6 @@ { "name": "@boardgamers/clash-web-client", - "version": "0.1.221", + "version": "0.1.222", "private": true, "type": "module", "scripts": { diff --git a/web-client/release/achievement-assets.json b/web-client/release/achievement-assets.json index 0e7ed439..91b459d4 100644 --- a/web-client/release/achievement-assets.json +++ b/web-client/release/achievement-assets.json @@ -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" diff --git a/web-client/release/engine-package.json b/web-client/release/engine-package.json index 3dd73eaf..7f279773 100644 --- a/web-client/release/engine-package.json +++ b/web-client/release/engine-package.json @@ -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" + ] } diff --git a/web-client/src/localization.test.ts b/web-client/src/localization.test.ts index 19135bc9..29bfa5ea 100644 --- a/web-client/src/localization.test.ts +++ b/web-client/src/localization.test.ts @@ -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']) { diff --git a/web-client/src/localization/da.json b/web-client/src/localization/da.json index 996559f1..a8a33c71 100644 --- a/web-client/src/localization/da.json +++ b/web-client/src/localization/da.json @@ -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", diff --git a/web-client/src/localization/de.json b/web-client/src/localization/de.json index c3afec24..ffc4e2d1 100644 --- a/web-client/src/localization/de.json +++ b/web-client/src/localization/de.json @@ -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", diff --git a/web-client/src/localization/el.json b/web-client/src/localization/el.json index 93a5bc5c..a8636df4 100644 --- a/web-client/src/localization/el.json +++ b/web-client/src/localization/el.json @@ -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": "Αμυντικός Σχηματισμός", diff --git a/web-client/src/localization/en.json b/web-client/src/localization/en.json index cb754385..b1ef8ef8 100644 --- a/web-client/src/localization/en.json +++ b/web-client/src/localization/en.json @@ -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", diff --git a/web-client/src/localization/fa.json b/web-client/src/localization/fa.json index 56c4250b..8bbb6e2e 100644 --- a/web-client/src/localization/fa.json +++ b/web-client/src/localization/fa.json @@ -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": "آرایش دفاعی", diff --git a/web-client/src/localization/fr.json b/web-client/src/localization/fr.json index 32f6e5e9..781c4415 100644 --- a/web-client/src/localization/fr.json +++ b/web-client/src/localization/fr.json @@ -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", diff --git a/web-client/src/localization/hi.json b/web-client/src/localization/hi.json index d5598a26..ad29fe7e 100644 --- a/web-client/src/localization/hi.json +++ b/web-client/src/localization/hi.json @@ -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": "रक्षात्मक संरचना", diff --git a/web-client/src/localization/it.json b/web-client/src/localization/it.json index 018b4c3b..55adb9dc 100644 --- a/web-client/src/localization/it.json +++ b/web-client/src/localization/it.json @@ -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", diff --git a/web-client/src/localization/ko.json b/web-client/src/localization/ko.json index a518adea..5816bd18 100644 --- a/web-client/src/localization/ko.json +++ b/web-client/src/localization/ko.json @@ -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": "방어 진형", diff --git a/web-client/src/localization/nl.json b/web-client/src/localization/nl.json index 610f9029..3b7b2c78 100644 --- a/web-client/src/localization/nl.json +++ b/web-client/src/localization/nl.json @@ -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", diff --git a/web-client/src/localization/pl.json b/web-client/src/localization/pl.json index 785fd7a9..eafdd78d 100644 --- a/web-client/src/localization/pl.json +++ b/web-client/src/localization/pl.json @@ -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", diff --git a/web-client/src/localization/pt-BR.json b/web-client/src/localization/pt-BR.json index ae66c9b2..3f765576 100644 --- a/web-client/src/localization/pt-BR.json +++ b/web-client/src/localization/pt-BR.json @@ -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", diff --git a/web-client/src/localization/ro.json b/web-client/src/localization/ro.json index f93fbc2a..08a3bc6b 100644 --- a/web-client/src/localization/ro.json +++ b/web-client/src/localization/ro.json @@ -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ă", diff --git a/web-client/src/localization/ru.json b/web-client/src/localization/ru.json index 7d12e0f5..5832f8b3 100644 --- a/web-client/src/localization/ru.json +++ b/web-client/src/localization/ru.json @@ -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": "Оборонительный строй", diff --git a/web-client/src/localization/vi.json b/web-client/src/localization/vi.json index fddaef8b..3b207154 100644 --- a/web-client/src/localization/vi.json +++ b/web-client/src/localization/vi.json @@ -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ủ", diff --git a/web-client/src/localization/zh-CN.json b/web-client/src/localization/zh-CN.json index 854e0b75..8a351535 100644 --- a/web-client/src/localization/zh-CN.json +++ b/web-client/src/localization/zh-CN.json @@ -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": "预备防御", diff --git a/web-client/src/localization/zh-TW.json b/web-client/src/localization/zh-TW.json index b10bd8d5..123cd014 100644 --- a/web-client/src/localization/zh-TW.json +++ b/web-client/src/localization/zh-TW.json @@ -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": "防禦陣型", diff --git a/web-client/src/three-fixes-engine.test.ts b/web-client/src/three-fixes-engine.test.ts new file mode 100644 index 00000000..49fd99a2 --- /dev/null +++ b/web-client/src/three-fixes-engine.test.ts @@ -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)')); +});