Exclude friendly units from exhausted land placement

This commit is contained in:
coyotte508 2026-10-29 23:19:37 +01:00
commit 426d95f09d
5 changed files with 45 additions and 6 deletions

View file

@ -836,7 +836,7 @@ fn exhausted_land(builder: IncidentBuilder) -> IncidentBuilder {
.flat_map(|c| c.position.neighbors())
.filter(|pos| {
game.try_get_any_city(*pos).is_none()
&& !enemy_units_present(game, *pos, p.index)
&& !units_present(game, *pos)
&& game.map.get(*pos).is_some_and(is_valid_city_terrain)
})
.collect_vec();
@ -880,8 +880,8 @@ pub(crate) fn decrease_mod_and_log(
}
}
fn enemy_units_present(game: &Game, pos: Position, player: usize) -> bool {
fn units_present(game: &Game, pos: Position) -> bool {
game.players
.iter()
.any(|p| player != p.index && p.units.iter().any(|u| u.position == pos))
.any(|p| p.units.iter().any(|u| u.position == pos))
}

View file

@ -132,6 +132,38 @@ fn test_exhausted_land() {
);
}
#[test]
fn exhausted_land_skips_when_all_eligible_spaces_have_units() {
use server::map::Terrain;
use server::unit::Unit;
for owner in [0, 1] {
for unit_type in [UnitType::Infantry, UnitType::Settler] {
let mut game = JSON.load_game("exhausted_land");
let positions: Vec<_> = game.player(0).cities.iter()
.flat_map(|city| city.position.neighbors())
.filter(|pos| game.try_get_any_city(*pos).is_none()
&& matches!(game.map.get(*pos), Some(Terrain::Fertile | Terrain::Forest | Terrain::Mountain)))
.collect();
assert!(!positions.is_empty());
for (index, position) in positions.iter().enumerate() {
game.player_mut(owner).units.push(Unit::new(
owner, *position, unit_type, 1000 + index as u32,
));
}
let before = game.map.tiles.clone();
let game = server::game_api::execute(game,
Action::Response(EventResponse::SelectAdvance(Advance::Storage)), 0);
assert_eq!(game.map.tiles, before, "Occupied terrain must not be exhausted");
if let Some(handler) = game.current_event_handler() {
assert!(!matches!(handler.request,
server::content::persistent_events::PersistentEventRequest::SelectPositions(_)),
"No exhausted-land placement should remain pending");
}
}
}
}
const FAMINE: JsonTest = JsonTest::child("incidents", "famine");
#[test]

View file

@ -593,3 +593,10 @@ unchanged baseline. No live game data repair is included.
Keep player avatars, names and supporter badges on one line. Long names use an
ellipsis instead of wrapping below the avatar; the card tooltip retains the full
name. Verified desktop and mobile layouts and Svelte checks. Engine stays 0.4.119.
## Viewer 0.1.177 / engine 0.4.120
Exhausted-land placement now excludes spaces containing any player's units,
including the active player's own units. When no eligible empty space remains,
the placement is skipped. Regression coverage includes friendly and enemy
infantry and settlers; all 39 incident tests pass.

View file

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