Mark sea tiles blocked by pirates with persistent dashed borders

This commit is contained in:
coyotte508 2026-10-12 20:16:33 +02:00
commit 09ee31e063
27 changed files with 211 additions and 22 deletions

View file

@ -233,3 +233,7 @@ Verified with 718 frontend/engine tests, type checks, production build, and desk
# Viewer 0.1.75 / engine unchanged (0.4.68)
Clicking a friendly fleet now immediately boards the selected land group across its available capacity. Removed the redundant Board all confirmation. Desktop/mobile browser and controller tests cover immediate boarding with and without optimistic prediction, while retaining one group-move cost.
# Viewer 0.1.76 / engine unchanged (0.4.68)
Sea spaces occupied by or adjacent to pirates now have persistent dashed red borders with a pale outline in both 3D and Strategy views. Hover and tile details explain that collection and Trade Routes are blocked. The guide follows live and replayed pirate positions, excludes land and unexplored spaces, and ignores escorted Pirate Allies controlled by Carthage. Thumbnail exports omit the overlay. All 16 locales include the explanation; the rules engine is unchanged. Verified with 721 tests, locale validation, type checks, and light/dark browser previews.

View file

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

View file

@ -1,5 +1,6 @@
<script lang="ts">
import { Skull } from 'lucide-svelte';
import { Skull, Ban } from 'lucide-svelte';
import { pirateBlockade } from './pirate-blockade';
import type { Game } from './types';
import { positionXY } from './model';
let {
@ -22,6 +23,7 @@
const blocked = $derived(
game.map.tiles.filter(([p, t]) => t === 'Water' && (p === position || adjacent(p))).map(([p]) => p),
);
const blockaded = $derived(pirateBlockade(game).includes(position));
</script>
{#if pirateShips.length}
@ -38,6 +40,11 @@
>{/each}
</div>
</section>
{:else if blockaded}
<section class="pirate-details" aria-label="Pirate effects">
<h3><Ban size={17} />Pirate blockade</h3>
<p>No collection or Trade Routes on this sea tile.</p>
</section>
{:else if allied}
<section class="pirate-details" aria-label="Allied pirate effects">
<h3><Skull size={17} />Pirate Allies</h3>

View file

@ -1,7 +1,7 @@
<script lang="ts">
import { buildingInfo } from './city';
import type { Readable } from 'svelte/store';
import { Skull, Landmark, Star } from 'lucide-svelte';
import { Skull, Landmark, Star, Ban } from 'lucide-svelte';
import type { TileHoverData } from './tile-hover';
import { playerColor, playerSymbol } from './types';
import { terrainInfo } from './terrain';
@ -31,6 +31,12 @@
{#each $data.city.wonders as name}<span><Star size={14} />{name}</span>{/each}
</div>
{/if}
{#if $data.pirateBlockade}
<div class="tile-hover-blockade">
<strong><Ban size={15} />Pirate blockade</strong>
<small>No collection or Trade Routes on this sea tile.</small>
</div>
{/if}
{#each $data.stacks as { player, groups }}
<div
class="tile-hover-owner"

View file

@ -27,6 +27,8 @@ import { PieceModels, type BuildingKind } from './piece-models';
import { MapGesture } from './map-gesture';
import { SeaOverlay } from './sea-overlay';
import { TradeOverlay } from './trade-overlay';
import { PirateBlockadeOverlay } from './pirate-blockade-overlay';
import { pirateBlockade } from './pirate-blockade';
import { CombatOverlay } from './combat-overlay';
import { PlacementAnimation } from './placement-animation';
import { activeCombat } from './active-combat';
@ -69,6 +71,7 @@ export class World {
private rings = new THREE.Group();
private seaOverlay = new SeaOverlay();
private tradeOverlay = new TradeOverlay();
private pirateBlockadeOverlay = new PirateBlockadeOverlay();
private combatOverlay = new CombatOverlay();
private combatLabel: HTMLDivElement;
private combatLabelText: Text;
@ -272,7 +275,7 @@ export class World {
this.geometries.add(markerGeometry);
this.structureMarker = [markerGeometry, markerMaterial];
this.scene.add(this.structureMarkers);
this.scene.add(this.seaOverlay.group, this.tradeOverlay.group);
this.scene.add(this.seaOverlay.group, this.tradeOverlay.group, this.pirateBlockadeOverlay.group);
this.scene.add(this.combatOverlay.group);
this.combatLabel = document.createElement('div');
this.combatLabel.className = 'map-combat-label';
@ -617,6 +620,7 @@ export class World {
this.referenceRing,
this.seaOverlay.group,
this.tradeOverlay.group,
this.pirateBlockadeOverlay.group,
this.combatOverlay.group,
this.explorationOverlay.group,
this.placement.group,
@ -1104,6 +1108,7 @@ export class World {
!s.view?.objectiveDecision;
this.seaRouteStart = s.seaRouteStart;
this.seaOverlay.update(s.game.map.tiles, s.view?.seaRoutes ?? []);
this.pirateBlockadeOverlay.update(pirateBlockade(s.game));
const tradePlayer = s.tradeRoutePlayer ?? s.seat ?? s.view?.activePlayer;
this.tradeOverlay.group.visible = !!s.tradeRoutes && s.mode === 'overview' && !s.playback &&
!s.view?.decision && !s.view?.choiceDecision && !s.view?.objectiveDecision && !s.view?.explorationDecision;
@ -2179,6 +2184,7 @@ export class World {
this.unitBadges = [];
this.seaOverlay.dispose();
this.tradeOverlay.dispose();
this.pirateBlockadeOverlay.dispose();
this.combatOverlay.dispose();
this.explorationOverlay.dispose();
this.explorationLabel.remove();

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Luk aktive effekter",
"No active effects.": "Ingen aktive effekter.",
"action cards": "handlingskort",
"Click the destination again to explore the highlighted region.": "Klik på destinationen igen for at udforske det fremhævede område."
"Click the destination again to explore the highlighted region.": "Klik på destinationen igen for at udforske det fremhævede område.",
"No collection or Trade Routes on this sea tile.": "Ingen indsamling eller handelsruter på dette havfelt."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Aktive Effekte schließen",
"No active effects.": "Keine aktiven Effekte.",
"action cards": "Aktionskarten",
"Click the destination again to explore the highlighted region.": "Klicke erneut auf das Ziel, um die hervorgehobene Region zu erkunden."
"Click the destination again to explore the highlighted region.": "Klicke erneut auf das Ziel, um die hervorgehobene Region zu erkunden.",
"No collection or Trade Routes on this sea tile.": "Auf diesem Seefeld sind weder Sammeln noch Handelsrouten möglich."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Κλείσιμο ενεργών αποτελεσμάτων",
"No active effects.": "Δεν υπάρχουν ενεργά αποτελέσματα.",
"action cards": "κάρτες ενέργειας",
"Click the destination again to explore the highlighted region.": "Κάντε ξανά κλικ στον προορισμό για να εξερευνήσετε την επισημασμένη περιοχή."
"Click the destination again to explore the highlighted region.": "Κάντε ξανά κλικ στον προορισμό για να εξερευνήσετε την επισημασμένη περιοχή.",
"No collection or Trade Routes on this sea tile.": "Δεν επιτρέπεται η συλλογή πόρων ή η χρήση Εμπορικών Οδών σε αυτή τη θαλάσσια θέση."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Close active effects",
"No active effects.": "No active effects.",
"action cards": "action cards",
"Click the destination again to explore the highlighted region.": "Click the destination again to explore the highlighted region."
"Click the destination again to explore the highlighted region.": "Click the destination again to explore the highlighted region.",
"No collection or Trade Routes on this sea tile.": "No collection or Trade Routes on this sea tile."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "بستن اثرات فعال",
"No active effects.": "هیچ اثر فعالی وجود ندارد.",
"action cards": "کارت‌های اقدام",
"Click the destination again to explore the highlighted region.": "برای کاوش منطقهٔ مشخص‌شده، دوباره روی مقصد کلیک کنید."
"Click the destination again to explore the highlighted region.": "برای کاوش منطقهٔ مشخص‌شده، دوباره روی مقصد کلیک کنید.",
"No collection or Trade Routes on this sea tile.": "در این خانهٔ دریایی نمی‌توان منابع جمع‌آوری کرد یا از مسیرهای تجاری استفاده کرد."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Fermer les effets actifs",
"No active effects.": "Aucun effet actif.",
"action cards": "cartes Action",
"Click the destination again to explore the highlighted region.": "Cliquez à nouveau sur la destination pour explorer la région en surbrillance."
"Click the destination again to explore the highlighted region.": "Cliquez à nouveau sur la destination pour explorer la région en surbrillance.",
"No collection or Trade Routes on this sea tile.": "Aucune collecte ni route commerciale sur cette case de mer."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "सक्रिय प्रभाव बंद करें",
"No active effects.": "कोई सक्रिय प्रभाव नहीं।",
"action cards": "ऐक्शन कार्ड",
"Click the destination again to explore the highlighted region.": "हाइलाइट किए गए क्षेत्र की खोज करने के लिए गंतव्य पर फिर से क्लिक करें।"
"Click the destination again to explore the highlighted region.": "हाइलाइट किए गए क्षेत्र की खोज करने के लिए गंतव्य पर फिर से क्लिक करें।",
"No collection or Trade Routes on this sea tile.": "इस समुद्री खाने पर संसाधन एकत्र नहीं कर सकते और व्यापार मार्गों का उपयोग नहीं कर सकते।"
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Chiudi effetti attivi",
"No active effects.": "Nessun effetto attivo.",
"action cards": "carte Azione",
"Click the destination again to explore the highlighted region.": "Fai di nuovo clic sulla destinazione per esplorare la regione evidenziata."
"Click the destination again to explore the highlighted region.": "Fai di nuovo clic sulla destinazione per esplorare la regione evidenziata.",
"No collection or Trade Routes on this sea tile.": "Non puoi raccogliere risorse né usare Rotte Commerciali in questo spazio di mare."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "활성 효과 닫기",
"No active effects.": "활성 효과가 없습니다.",
"action cards": "행동 카드",
"Click the destination again to explore the highlighted region.": "강조된 지역을 탐험하려면 목적지를 다시 클릭하세요."
"Click the destination again to explore the highlighted region.": "강조된 지역을 탐험하려면 목적지를 다시 클릭하세요.",
"No collection or Trade Routes on this sea tile.": "이 바다 칸에서는 자원을 수집하거나 교역로를 이용할 수 없습니다."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Actieve effecten sluiten",
"No active effects.": "Geen actieve effecten.",
"action cards": "actiekaarten",
"Click the destination again to explore the highlighted region.": "Klik nogmaals op de bestemming om het gemarkeerde gebied te verkennen."
"Click the destination again to explore the highlighted region.": "Klik nogmaals op de bestemming om het gemarkeerde gebied te verkennen.",
"No collection or Trade Routes on this sea tile.": "Op dit zeeveld kun je geen grondstoffen verzamelen of handelsroutes gebruiken."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Zamknij aktywne efekty",
"No active effects.": "Brak aktywnych efektów.",
"action cards": "karty akcji",
"Click the destination again to explore the highlighted region.": "Kliknij ponownie miejsce docelowe, aby zbadać podświetlony region."
"Click the destination again to explore the highlighted region.": "Kliknij ponownie miejsce docelowe, aby zbadać podświetlony region.",
"No collection or Trade Routes on this sea tile.": "Na tym polu morskim nie można zbierać zasobów ani korzystać ze szlaków handlowych."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Fechar efeitos ativos",
"No active effects.": "Nenhum efeito ativo.",
"action cards": "cartas de ação",
"Click the destination again to explore the highlighted region.": "Clique novamente no destino para explorar a região destacada."
"Click the destination again to explore the highlighted region.": "Clique novamente no destino para explorar a região destacada.",
"No collection or Trade Routes on this sea tile.": "Não é possível coletar recursos nem usar Rotas Comerciais neste espaço de mar."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Închide efectele active",
"No active effects.": "Nu există efecte active.",
"action cards": "cărți de acțiune",
"Click the destination again to explore the highlighted region.": "Apasă din nou pe destinație pentru a explora regiunea evidențiată."
"Click the destination again to explore the highlighted region.": "Apasă din nou pe destinație pentru a explora regiunea evidențiată.",
"No collection or Trade Routes on this sea tile.": "Nu poți colecta resurse sau folosi Rute Comerciale pe acest spațiu de mare."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Закрыть активные эффекты",
"No active effects.": "Нет активных эффектов.",
"action cards": "карты действий",
"Click the destination again to explore the highlighted region.": "Нажмите на место назначения ещё раз, чтобы исследовать выделенную область."
"Click the destination again to explore the highlighted region.": "Нажмите на место назначения ещё раз, чтобы исследовать выделенную область.",
"No collection or Trade Routes on this sea tile.": "На этой морской клетке нельзя собирать ресурсы или использовать торговые пути."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "Đóng hiệu ứng đang hoạt động",
"No active effects.": "Không có hiệu ứng đang hoạt động.",
"action cards": "thẻ hành động",
"Click the destination again to explore the highlighted region.": "Nhấp lại vào điểm đến để khám phá vùng được tô sáng."
"Click the destination again to explore the highlighted region.": "Nhấp lại vào điểm đến để khám phá vùng được tô sáng.",
"No collection or Trade Routes on this sea tile.": "Không thể thu thập tài nguyên hoặc sử dụng Tuyến Thương Mại trên ô biển này."
}

View file

@ -4752,5 +4752,6 @@
"Close active effects": "關閉生效中的效果",
"No active effects.": "目前沒有生效中的效果。",
"action cards": "行動牌",
"Click the destination again to explore the highlighted region.": "再次點擊目的地以探索標示的區域。"
"Click the destination again to explore the highlighted region.": "再次點擊目的地以探索標示的區域。",
"No collection or Trade Routes on this sea tile.": "此海洋格無法採集資源或使用貿易路線。"
}

View file

@ -0,0 +1,54 @@
import * as THREE from 'three';
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
import { positionXY } from './model.ts';
/** Dashed, two-tone borders remain distinct from legal-move and selection rings. */
export class PirateBlockadeOverlay {
readonly group = new THREE.Group();
private signature = '';
update(positions: string[]) {
const signature = JSON.stringify(positions);
if (signature === this.signature) return;
this.dispose();
this.signature = signature;
if (!positions.length) return;
for (const [color, width, height] of [
['#ffebc8', 0.075, 0.39],
['#b3332b', 0.038, 0.405],
] as const) {
const segments: THREE.BufferGeometry[] = [];
for (const position of positions) {
const [x, z] = positionXY(position);
for (let side = 0; side < 6; side++) {
const a = (side * Math.PI) / 3,
b = ((side + 1) * Math.PI) / 3;
const start = new THREE.Vector3(x + 0.89 * Math.cos(a), height, z + 0.89 * Math.sin(a));
const end = new THREE.Vector3(x + 0.89 * Math.cos(b), height, z + 0.89 * Math.sin(b));
for (const offset of [0.08, 0.58]) {
const from = start.clone().lerp(end, offset),
to = start.clone().lerp(end, offset + 0.34);
const geometry = new THREE.BoxGeometry(from.distanceTo(to), 0.012, width);
geometry.rotateY(-Math.atan2(to.z - from.z, to.x - from.x));
geometry.translate((from.x + to.x) / 2, height, (from.z + to.z) / 2);
segments.push(geometry);
}
}
}
const geometry = mergeGeometries(segments);
segments.forEach((segment) => segment.dispose());
const mesh = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({ color, toneMapped: false }));
this.group.add(mesh);
}
}
dispose() {
for (const child of this.group.children) {
const mesh = child as THREE.Mesh<THREE.BufferGeometry, THREE.Material>;
mesh.geometry.dispose();
mesh.material.dispose();
}
this.group.clear();
this.signature = '';
}
}

View file

@ -0,0 +1,62 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { pirateBlockade } from './pirate-blockade.ts';
import { PirateBlockadeOverlay } from './pirate-blockade-overlay.ts';
import type { Game, Terrain } from './types.ts';
function board(): Pick<Game, 'map' | 'players'> {
return {
map: {
tiles: ['A', 'B', 'C', 'D', 'E'].flatMap((col) =>
[1, 2, 3, 4, 5].map((row): [string, Terrain] => [`${col}${row}`, 'Water']),
),
},
players: [
{
id: 0,
civilization: 'Carthage',
units: [{ id: 0, position: 'A1', unit_type: 'Ship', pirate: true }],
},
{ id: 3, civilization: 'Pirates', units: [{ id: 0, position: 'C3', unit_type: 'Ship' }] },
],
};
}
test('pirate blockade covers the occupied and adjacent sea spaces, never land or unexplored spaces', () => {
const game = board();
assert.deepEqual(pirateBlockade(game), ['B2', 'B3', 'C2', 'C3', 'C4', 'D2', 'D3']);
game.map.tiles = game.map.tiles.map(([p, terrain]) => [
p,
p === 'C4' ? 'Fertile' : p === 'D2' ? 'Unexplored' : terrain,
]);
assert.deepEqual(pirateBlockade(game), ['B2', 'B3', 'C2', 'C3', 'D3']);
// Odd columns use the other pair of diagonal neighbors.
game.players[1].units![0].position = 'B3';
assert.deepEqual(pirateBlockade(game), ['A3', 'A4', 'B2', 'B3', 'B4', 'C3']);
});
test('blockade follows current or replayed pirate positions and ignores Carthage escorts', () => {
const game = board();
const previous = structuredClone(game);
game.players[1].units = [];
assert.deepEqual(pirateBlockade(game), [], 'allied pirate ships do not blockade');
assert.ok(pirateBlockade(previous).includes('C3'), 'an older replay position still shows its pirates');
game.players = game.players.slice(0, 1);
assert.deepEqual(pirateBlockade(game), [], 'games without NPC pirates are supported');
});
test('blockade redraws only when positions change and disposes the removed outlines', () => {
const overlay = new PirateBlockadeOverlay();
overlay.update(pirateBlockade(board()));
const old = overlay.group.children[0] as import('three').Mesh;
let disposed = false;
old.geometry.addEventListener('dispose', () => {
disposed = true;
});
overlay.update(pirateBlockade(board()));
assert.equal(overlay.group.children[0], old);
overlay.update([]);
assert.equal(overlay.group.children.length, 0);
assert.equal(disposed, true);
overlay.dispose();
});

View file

@ -0,0 +1,16 @@
import { positionXY } from './model.ts';
import type { Game } from './types.ts';
/** The same public sea-space restriction as Game::is_pirate_zone. */
export function pirateBlockade(game: Pick<Game, 'map' | 'players'>): string[] {
// Escorted Pirate Allies belong to Carthage, so they do not create a blockade.
const pirates = game.players.find((p) => p.civilization === 'Pirates')?.units ?? [];
const origins = [...new Set(pirates.map((u) => u.position))].map(positionXY);
return game.map.tiles
.filter(([position, terrain]) => {
if (terrain !== 'Water') return false;
const [x, z] = positionXY(position);
return origins.some(([px, pz]) => (px - x) ** 2 + (pz - z) ** 2 <= 3.001);
})
.map(([position]) => position);
}

View file

@ -579,6 +579,21 @@ small {
color: var(--muted);
font-size: 11px;
}
.tile-hover-blockade {
margin-top: 8px;
padding-top: 7px;
border-top: 1px dashed var(--line);
}
.tile-hover-blockade strong {
display: flex;
align-items: center;
gap: 5px;
}
.tile-hover-blockade small {
display: block;
margin-top: 3px;
max-width: 220px;
}
.tile-hover-empty {
display: block;
margin-top: 3px;

View file

@ -3,10 +3,12 @@ import { writable } from 'svelte/store';
import type { Session, Terrain } from './types';
import { tileUnitStacks } from './tile-units';
import TileHover from './TileHover.svelte';
import { pirateBlockade } from './pirate-blockade';
export interface TileHoverData {
position: string;
terrain: Terrain;
pirateBlockade: boolean;
city?: { owner: number; civilization: string; mood: string; buildings: string[]; wonders: string[] };
stacks: ReturnType<typeof tileUnitStacks>;
colorBlind: boolean;
@ -78,6 +80,7 @@ export class TileTooltip {
this.data.set({
position: this.position,
terrain,
pirateBlockade: pirateBlockade(session.game).includes(this.position),
city:
terrain === 'Unexplored'
? undefined