From 2276c7224829b1bcc6938c4a4184cac32382bb92 Mon Sep 17 00:00:00 2001 From: Drefvelin <54400154+Drefvelin@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:36:21 +0000 Subject: [PATCH] Start sea routes only from land joined to the capital A landlocked overlord could claim across the sea from a vassal's capital that did not touch its own, and a guild capital or overseas holding could open a further sea route. That let the Brotherhood of Alms reach the bog through New Waters Port's coast. Sea routes (any number of connected sea or water zones) now start only from the capital's land blob: land joined by land to the faction capital, through its own provinces or vassal land that connects to it. Vassal land elsewhere still anchors land claims next to it, but never sets sail. Sea-mode claims and relocation follow the same rule; a realm without a seated capital still sails from what it holds. Co-Authored-By: Claude Opus 5.5 --- .../objects/handler/ProvinceHandler.java | 231 +++++------------- .../inventory/FactionMenusCoverageTest.java | 6 +- .../handler/ProvinceHandlerEnclaveTest.java | 22 +- .../handler/ProvinceHandlerSeaClaimTest.java | 39 +++ .../ProvinceHandlerVassalLandTest.java | 81 +++++- 5 files changed, 199 insertions(+), 180 deletions(-) diff --git a/src/main/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandler.java b/src/main/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandler.java index 8aa907d5..c65434f4 100644 --- a/src/main/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandler.java +++ b/src/main/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandler.java @@ -146,7 +146,7 @@ public boolean canClaim(int provinceId, boolean sea) { if (target == null || !target.isValid()) return false; if (provinces.isEmpty()) return true; - return bordersRealm(pm, provinceId) || sea && isSeaAdjacentFromSet(pm, target, seaClaimSources(pm)); + return bordersRealm(pm, provinceId) || sea && seaReachableCoasts(pm, seaClaimSources(pm)).contains(provinceId); } /** @@ -161,17 +161,13 @@ public boolean canClaimAny(java.util.Collection targets) { if (pm == null) return false; Set capitalCoasts = seaReachableCoasts(pm, capitalLandBlob(pm)); - // Land touching a sea reachable from the sea claim sources: what isSeaAdjacentFromSet accepts. - Set seaSources = seaClaimSources(pm); - Set sailingCoasts = seaReachableCoasts(pm, seaSources); + Set sailingCoasts = seaReachableCoasts(pm, seaClaimSources(pm)); Set sources = claimSources(pm); for (Integer provinceId : targets) { if (provinceId == null || provinces.contains(provinceId)) continue; Province target = pm.get(provinceId); if (target == null || !target.isValid()) continue; if (capitalCoasts.contains(provinceId) || sailingCoasts.contains(provinceId)) return true; - // The coast sets hold only land, so a sea province in the list takes the per-target check. - if (target.isSea() && isSeaAdjacentFromSet(pm, target, seaSources)) return true; for (int ownedId : sources) { if (isEffectivelyAdjacent(pm, ownedId, provinceId, capitalCoasts)) return true; } @@ -205,7 +201,8 @@ private Set claimSources(ProvinceManager pm) { /** * Land held by this faction's vassals and their vassals. It anchors the realm like the capital: * claims may border it and own land joined to it stays claimed, even where it does not touch the - * capital. It is never this faction's own. + * capital. It is never this faction's own. Only vassal land joined by land to the capital opens a + * sea crossing; see {@link #capitalLandBlob(ProvinceManager)}. */ private Set vassalLand() { Set land = new HashSet<>(); @@ -266,17 +263,10 @@ public boolean canClaim(int provinceId, boolean sea, Guild guild) { // Apply the same river/coastal adjacency as normal claims, without the old guild capital. Set capitalBlob = new HashSet<>(); - if (hasCapital() && capital != guild.getCapital()) { + boolean seated = hasCapital() && provinces.contains(capital); + if (seated && capital != guild.getCapital()) { capitalBlob.add(capital); floodLandExcluding(pm, capital, capitalBlob, guild.getCapital()); - if (provinces.contains(capital)) { - // Vassal capitals open the sea too, as in capitalLandBlob. - for (int seat : subjectSeats()) { - if (seat != guild.getCapital() && !capitalBlob.contains(seat)) { - floodLandExcluding(pm, seat, capitalBlob, guild.getCapital()); - } - } - } } Set seaCoasts = seaReachableCoasts(pm, capitalBlob); for (int ownedId : legalWithoutGuildCapital) { @@ -285,12 +275,8 @@ public boolean canClaim(int provinceId, boolean sea, Guild guild) { } } - // 2) Sea-adjacency mode (only from legal provinces) - if (sea) { - return isSeaAdjacentFromSet(pm, target, legalWithoutGuildCapital); - } - - return false; + // 2) Sea mode: a realm without a seated capital may sail from what it keeps. + return sea && !seated && seaReachableCoasts(pm, legalWithoutGuildCapital).contains(provinceId); } /** @@ -360,99 +346,6 @@ private void floodLandExcluding(ProvinceManager pm, int start, Set out, } } - /** - * Check sea adjacency from a specific set of provinces (used for guild relocation checks). - */ - private boolean isSeaAdjacentFromSet(ProvinceManager pm, Province target, Set fromProvinces) { - Set visited = new HashSet<>(); - ArrayDeque queue = new ArrayDeque<>(); - - // Seed the queue with sea provinces adjacent to the legal province set - for (int ownedId : fromProvinces) { - Province owned = pm.get(ownedId); - if (owned == null) continue; - - for (int nId : owned.getNeighbours()) { - Province n = pm.get(nId); - if (n == null) continue; - - if (n.isSea()) { - queue.add(nId); - visited.add(nId); - } - } - } - - // Flood-fill sea region - while (!queue.isEmpty()) { - int currentId = queue.poll(); - Province current = pm.get(currentId); - if (current == null) continue; - - // If target touches this sea province - if (current.getNeighbours().contains(target.getId())) { - return true; - } - - for (int nId : current.getNeighbours()) { - if (visited.contains(nId)) continue; - - Province n = pm.get(nId); - if (n == null || !n.isSea()) continue; - - visited.add(nId); - queue.add(nId); - } - } - - return false; - } - - private boolean isSeaAdjacent(ProvinceManager pm, Province target) { - Set visited = new HashSet<>(); - ArrayDeque queue = new ArrayDeque<>(); - - // Seed the queue with sea/water provinces adjacent to owned territory - for (int ownedId : provinces) { - Province owned = pm.get(ownedId); - if (owned == null) continue; - - for (int nId : owned.getNeighbours()) { - Province n = pm.get(nId); - if (n == null) continue; - - if (n.isSea()) { - queue.add(nId); - visited.add(nId); - } - } - } - - // Flood-fill sea region - while (!queue.isEmpty()) { - int currentId = queue.poll(); - Province current = pm.get(currentId); - if (current == null) continue; - - // If target touches this sea province - if (current.getNeighbours().contains(target.getId())) { - return true; - } - - for (int nId : current.getNeighbours()) { - if (visited.contains(nId)) continue; - - Province n = pm.get(nId); - if (n == null || !n.isSea()) continue; - - visited.add(nId); - queue.add(nId); - } - } - - return false; - } - public void revalidateClaims() { ProvinceManager pm = SimpleFactions.getInstance().getProvinceManager(); @@ -566,14 +459,14 @@ private Set computeLegalProvinces(ProvinceManager pm, int factionCapita } /** - * Where a sea-mode claim may set sail from: land that traces back to the faction capital. - * A realm without a seated capital keeps sailing from anything it owns. + * Where a sea-mode claim may set sail from: the capital's land blob, as for any other claim. + * A realm without a seated capital sails from anything it owns. */ private Set seaClaimSources(ProvinceManager pm) { if (!provinces.contains(capital)) { return new HashSet<>(provinces); } - return computeLegalProvinces(pm, capital); + return capitalLandBlob(pm); } private Set legalGuildCapitals(ProvinceManager pm, int factionCapital, java.util.Collection candidates) { @@ -581,9 +474,11 @@ private Set legalGuildCapitals(ProvinceManager pm, int factionCapital, } /** - * Guild capitals that trace back to the faction capital: over owned land, or by water from - * land already traced, so one colony can anchor the next. An enclave cut off from the realm - * cannot vouch for itself by touching its own lake. + * Guild capitals that keep their seat: on land joined to the faction capital or to vassal land, + * on a shore a sea route from the capital's land blob reaches, or across one river or lake from + * land that traces back. A guild capital never opens a sea route of its own, so one colony cannot + * anchor the next, and an enclave cut off from the realm cannot vouch for itself by touching its + * own lake. */ private Set legalGuildCapitals(ProvinceManager pm, int factionCapital, java.util.Collection candidates, Set capitalBlob) { @@ -597,47 +492,55 @@ private Set legalGuildCapitals(ProvinceManager pm, int factionCapital, } if (!provinces.contains(factionCapital)) { // Without a seated faction capital there is nothing to trace back to. + Set shores = seaReachableCoasts(pm, new HashSet<>(provinces)); for (int cap : pending) { - if (isSeaAdjacent(pm, pm.get(cap))) legal.add(cap); + if (shores.contains(cap)) legal.add(cap); } return legal; } - Set seeds = new HashSet<>(Set.of(factionCapital)); - // Vassal land anchors guild capitals as the faction capital does: over land, or by water. + // Vassal land anchors guild capitals as the faction capital does. Set anchors = vassalLand(); - seeds.addAll(anchors); Set anchoredLand = new HashSet<>(); for (int anchor : anchors) { if (!anchoredLand.contains(anchor)) floodLand(pm, anchor, anchoredLand); } - boolean changed = true; - while (changed) { - changed = false; - Set reached = expandLegal(pm, seeds, capitalBlob); - for (java.util.Iterator it = pending.iterator(); it.hasNext();) { - int cap = it.next(); - if (capitalBlob.contains(cap) || anchoredLand.contains(cap) - || isSeaAdjacentFromSet(pm, pm.get(cap), reached)) { - legal.add(cap); - seeds.add(cap); - it.remove(); - changed = true; - } + Set seeds = new HashSet<>(Set.of(factionCapital)); + seeds.addAll(anchors); + Set reached = expandLegal(pm, seeds, capitalBlob); + Set seaCoasts = seaReachableCoasts(pm, capitalBlob); + for (int cap : pending) { + if (capitalBlob.contains(cap) || anchoredLand.contains(cap) || seaCoasts.contains(cap) + || acrossWaterFrom(pm, cap, reached)) { + legal.add(cap); } } return legal; } + /** Whether {@code id} faces land in {@code from} across one WATER (river or lake) province. */ + private boolean acrossWaterFrom(ProvinceManager pm, int id, Set from) { + Province province = pm.get(id); + if (province == null) return false; + for (int neighbour : province.getNeighbours()) { + Province water = pm.get(neighbour); + if (water == null || water.getTerrain() != Terrain.WATER) continue; + for (int shore : water.getNeighbours()) { + if (shore != id && from.contains(shore)) return true; + } + } + return false; + } + private Set expandLegal(ProvinceManager pm, Set seeds, Set capitalBlob) { Set legal = new HashSet<>(seeds); Set seaCoasts = seaReachableCoasts(pm, capitalBlob); // Follow the same edges that allowed these claims: owned land, WATER // bridges, and continuous sea routes from the proposed capital's land blob. - // Reached overseas holdings may extend inland or over WATER, but do not - // become new sources for SEA crossings. Vassal land carries the connection - // like owned land, so the result can include it. + // Reached overseas holdings and vassal land may extend inland or over WATER, + // but never become new sources for sea crossings. Vassal land carries the + // connection like owned land, so the result can include it. Set realm = realmLand(); ArrayDeque queue = new ArrayDeque<>(legal); while (!queue.isEmpty()) { @@ -752,7 +655,7 @@ public String getClaimDeniedReason(int provinceId, boolean sea) { : "§cThis province does not border your realm or your vassals' land."; } - if (adjacent || isSeaAdjacentFromSet(pm, target, seaClaimSources(pm))) { + if (adjacent || seaReachableCoasts(pm, seaClaimSources(pm)).contains(provinceId)) { return "Success"; } @@ -760,9 +663,10 @@ public String getClaimDeniedReason(int provinceId, boolean sea) { } /** - * Realm land reachable without crossing sea from the faction capital, or from a vassal's capital, - * since vassals anchor the realm too. A sea crossing is allowed from any province in this blob, - * not only the capitals themselves. Empty while the faction capital is not seated. + * The realm's main region: land joined by land to the faction capital, through its own provinces + * or its vassals'. Vassal land counts only where it connects to the capital this way. A sea + * route may start from any province in this blob and from nowhere else. Empty while the + * faction capital is not seated. */ private Set capitalLandBlob(ProvinceManager pm) { return capitalLandBlob(pm, capital); @@ -774,46 +678,35 @@ private Set capitalLandBlob(ProvinceManager pm, int factionCapital) { return blob; } floodLand(pm, factionCapital, blob); - for (int seat : subjectSeats()) { - if (!blob.contains(seat)) { - floodLand(pm, seat, blob); - } - } return blob; } - /** The capitals this faction's vassals and their vassals hold. */ - private List subjectSeats() { - List seats = new ArrayList<>(); - for (Faction subject : allSubjects()) { - int seat = subject.getCapital(); - if (seat != -1 && subject.getProvinces().contains(seat)) { - seats.add(seat); - } - } - return seats; - } - - /** Shores reachable through SEA/WATER, without crossing any intervening land. */ - private Set seaReachableCoasts(ProvinceManager pm, Set capitalBlob) { - Set coasts = new HashSet<>(); - Set visited = new HashSet<>(); + /** + * What a sea route from {@code from} reaches: every SEA or WATER province joined to one those + * provinces border, without crossing land, and every province on the shore of one of them. + */ + private Set seaReachableCoasts(ProvinceManager pm, Set from) { + Set reached = new HashSet<>(); ArrayDeque queue = new ArrayDeque<>(); - for (int id : capitalBlob) { + for (int id : from) { Province province = pm.get(id); if (province == null) continue; for (int neighbour : province.getNeighbours()) { Province water = pm.get(neighbour); - if (water != null && water.isSea() && visited.add(neighbour)) queue.add(neighbour); + if (water != null && water.isSea() && reached.add(neighbour)) queue.add(neighbour); } } + Set coasts = new HashSet<>(reached); while (!queue.isEmpty()) { Province water = pm.get(queue.poll()); for (int neighbour : water.getNeighbours()) { Province next = pm.get(neighbour); if (next == null) continue; if (!next.isSea()) coasts.add(neighbour); - else if (visited.add(neighbour)) queue.add(neighbour); + else if (reached.add(neighbour)) { + coasts.add(neighbour); + queue.add(neighbour); + } } } return coasts; diff --git a/src/test/java/net/tfminecraft/simplefactions/managers/inventory/FactionMenusCoverageTest.java b/src/test/java/net/tfminecraft/simplefactions/managers/inventory/FactionMenusCoverageTest.java index 8183db41..932a7d2d 100644 --- a/src/test/java/net/tfminecraft/simplefactions/managers/inventory/FactionMenusCoverageTest.java +++ b/src/test/java/net/tfminecraft/simplefactions/managers/inventory/FactionMenusCoverageTest.java @@ -366,11 +366,11 @@ void releasePreviewCountsDisconnectedLandLossAndMatchesDissolve() { @Test void releasePreviewKeepsTheLaterGuildCapitalReachableThroughOrdinarySeaClaims() { - // Realm capital 1. Colony 4 lies two sea tiles away; colony 6 two more sea tiles beyond 4, - // on a separate sea. Ordinary sea claims now keep 4 legal even after its guild leaves. + // Realm capital 1. Colony 4 lies two sea tiles away; colony 6 two more sea tiles beyond 4, on + // water the capital's sea also reaches. Ordinary sea claims keep both legal after a guild leaves. for (int id : List.of(1, 4, 6)) province(id, "PLAINS"); for (int id : List.of(2, 3, 5, 7)) province(id, "SEA"); - link(1, 2); link(2, 3); link(3, 4); link(4, 5); link(5, 7); link(7, 6); + link(1, 2); link(2, 3); link(3, 4); link(4, 5); link(3, 5); link(5, 7); link(7, 6); faction.getProvinceHandler().getProvinces().addAll(List.of(1, 4, 6)); faction.setCapital(1, true, false); fixture.guild(faction, "Anchor", "One"); diff --git a/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerEnclaveTest.java b/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerEnclaveTest.java index 8c941fed..f05cadf8 100644 --- a/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerEnclaveTest.java +++ b/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerEnclaveTest.java @@ -92,22 +92,36 @@ void colonyReachedBySeaFromTheRealmKeepsItsCapital() { } @Test - void aColonyCanAnchorAnotherColonyAcrossADifferentSea() { + void aColonyCannotAnchorAnotherColonyAcrossADifferentSea() { load(Map.of(1, Terrain.PLAINS, 2, Terrain.SEA, 3, Terrain.SEA, 4, Terrain.PLAINS, 6, Terrain.SEA, 7, Terrain.SEA, 8, Terrain.PLAINS)); link(1, 2); link(2, 3); link(3, 4); link(4, 6); link(6, 7); link(7, 8); - // Listed far colony first so it only becomes legal once the near one is traced. + // Only the capital's land sets sail, and its sea stops at the near colony 4. Guild far = guild("far", 8); Guild near = guild("near", 4); ProvinceHandler handler = new ProvinceHandler(faction, 1, List.of(1, 4, 8)); handler.revalidateClaims(); - assertEquals(List.of(1, 4, 8), handler.getProvinces()); - verify(far, never()).setCapital(anyInt()); + assertEquals(List.of(1, 4), handler.getProvinces()); + verify(far).setCapital(-1); verify(near, never()).setCapital(anyInt()); } + @Test + void aColonyAcrossOneRiverFromTracedLandKeepsItsSeat() { + load(Map.of(1, Terrain.PLAINS, 2, Terrain.SEA, 4, Terrain.PLAINS, 5, Terrain.WATER, + 8, Terrain.PLAINS)); + link(1, 2); link(2, 4); link(4, 5); link(5, 8); + Guild river = guild("river", 8); + ProvinceHandler handler = new ProvinceHandler(faction, 1, List.of(1, 4, 8)); + + handler.revalidateClaims(); + + assertEquals(List.of(1, 4, 8), handler.getProvinces()); + verify(river, never()).setCapital(anyInt()); + } + @Test void twoEnclavesOnOneLakeCannotVouchForEachOther() { load(Map.of(1, Terrain.PLAINS, 5, Terrain.PLAINS, 7, Terrain.WATER, 8, Terrain.PLAINS)); diff --git a/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerSeaClaimTest.java b/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerSeaClaimTest.java index 5ec4027a..7b1717c8 100644 --- a/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerSeaClaimTest.java +++ b/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerSeaClaimTest.java @@ -236,6 +236,45 @@ void canClaimAnyAcceptsASeaProvinceTheRealmCanSailTo() { assertTrue(handler.canClaimAny(List.of(4))); } + @Test + void anOverseasHoldingDoesNotStartASecondCrossing() { + // 5 was reached over the capital's sea 2; the sea 4 behind it touches only 5 and 7. + Province capital = land(1); + Province nearSea = sea(2); + Province holding = land(5); + Province farSea = sea(4); + Province target = land(7); + link(capital, nearSea); + link(nearSea, holding); + link(holding, farSea); + link(farSea, target); + load(capital, nearSea, holding, farSea, target); + + ProvinceHandler handler = handler(1, 1, 5); + + assertFalse(handler.canClaim(7, false)); + assertFalse(handler.canClaim(7, true)); + assertFalse(handler.canClaimAny(List.of(7))); + } + + @Test + void seaModeWithoutASeatedCapitalSailsFromOwnedLand() { + Province owned = land(1); + Province nearSea = sea(2); + Province farSea = sea(3); + Province target = land(4); + link(owned, nearSea); + link(nearSea, farSea); + link(farSea, target); + load(owned, nearSea, farSea, target); + + ProvinceHandler handler = handler(-1, 1); + + assertFalse(handler.canClaim(4, false)); + assertTrue(handler.canClaim(4, true)); + assertTrue(handler.getClaimDeniedReason(4, true).contains("Success")); + } + @Test void canClaimAnyReachesNothingWithoutLand() { Province target = land(1); diff --git a/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerVassalLandTest.java b/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerVassalLandTest.java index 9dafce6a..3162b6bd 100644 --- a/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerVassalLandTest.java +++ b/src/test/java/net/tfminecraft/simplefactions/objects/handler/ProvinceHandlerVassalLandTest.java @@ -120,7 +120,7 @@ void ownLandJoinedOnlyToADistantVassalStaysClaimed() { } @Test - void aLandlockedOverlordMaySailFromItsVassalsCapital() { + void aLandlockedOverlordCannotSailFromADistantVassalsCapital() { // 1 is inland; the vassal's capital 5 and its island 7 share the sea 20, which also touches 8. load(Map.of(1, Terrain.PLAINS, 5, Terrain.PLAINS, 7, Terrain.PLAINS, 8, Terrain.PLAINS, 20, Terrain.SEA)); @@ -130,12 +130,45 @@ void aLandlockedOverlordMaySailFromItsVassalsCapital() { when(vassal.getCapital()).thenReturn(5); ProvinceHandler handler = new ProvinceHandler(overlord, 1, List.of(1)); + assertFalse(handler.canClaim(8, false)); + assertFalse(handler.canClaim(8, true)); + assertFalse(handler.canClaimAny(List.of(8))); + assertEquals("§cThis province must be connected to your realm by land or by sea.", + handler.getClaimDeniedReason(8, true)); + } + + @Test + void ownLandOverseasFromADistantVassalIsDroppedOnRevalidation() { + // The overlord took 8 by sailing from its vassal's coast 5, which does not touch its capital 1. + load(Map.of(1, Terrain.PLAINS, 5, Terrain.PLAINS, 8, Terrain.PLAINS, 9, Terrain.PLAINS, + 20, Terrain.SEA)); + link(5, 20); link(8, 20); link(8, 9); + vassalProvinces.add(5); + when(vassal.getCapital()).thenReturn(5); + ProvinceHandler handler = new ProvinceHandler(overlord, 1, List.of(1, 8, 9)); + + assertEquals(Set.of(1), handler.previewLegalProvinces(List.of(1, 8, 9))); + handler.revalidateClaims(); + + assertEquals(List.of(1), handler.getProvinces()); + } + + @Test + void vassalLandJoinedToTheCapitalByLandOpensTheSea() { + // The vassal's coast 2 touches the capital 1, so the sea 20 it borders is the realm's sea. + load(Map.of(1, Terrain.PLAINS, 2, Terrain.PLAINS, 8, Terrain.PLAINS, 20, Terrain.SEA, + 21, Terrain.SEA)); + link(1, 2); link(2, 20); link(20, 21); link(21, 8); + vassalProvinces.add(2); + ProvinceHandler handler = new ProvinceHandler(overlord, 1, List.of(1)); + assertTrue(handler.canClaim(8, false)); assertTrue(handler.canClaimAny(List.of(8))); + assertEquals(Set.of(1, 8), handler.previewLegalProvinces(List.of(1, 8))); } @Test - void aVassalsOverseasLandSetsSailOnlyInSeaMode() { + void aVassalsOverseasLandDoesNotSetSailEvenInSeaMode() { load(Map.of(1, Terrain.PLAINS, 5, Terrain.PLAINS, 7, Terrain.PLAINS, 8, Terrain.PLAINS, 20, Terrain.SEA)); link(7, 20); link(8, 20); @@ -145,7 +178,18 @@ void aVassalsOverseasLandSetsSailOnlyInSeaMode() { ProvinceHandler handler = new ProvinceHandler(overlord, 1, List.of(1)); assertFalse(handler.canClaim(8, false)); - assertTrue(handler.canClaim(8, true)); + assertFalse(handler.canClaim(8, true)); + } + + @Test + void aVassalsShoreProvinceStillAnchorsClaimsAlongItByLand() { + // Once the vassal holds the shore 7, the overlord may claim land next to it. + load(Map.of(1, Terrain.PLAINS, 7, Terrain.PLAINS, 8, Terrain.PLAINS, 20, Terrain.SEA)); + link(7, 20); link(7, 8); + vassalProvinces.add(7); + ProvinceHandler handler = new ProvinceHandler(overlord, 1, List.of(1)); + + assertTrue(handler.canClaim(8, false)); } @Test @@ -246,7 +290,7 @@ void aRelocationCheckWithoutASeatedCapitalIgnoresVassalAnchors() { } @Test - void aRelocationCheckMaySailFromAVassalsCapital() { + void aRelocationCheckCannotSailFromADistantVassalsCapital() { load(Map.of(1, Terrain.PLAINS, 5, Terrain.PLAINS, 8, Terrain.PLAINS, 9, Terrain.PLAINS, 20, Terrain.SEA)); link(5, 20); link(8, 20); @@ -257,9 +301,38 @@ void aRelocationCheckMaySailFromAVassalsCapital() { when(overlord.getCapital()).thenReturn(1); ProvinceHandler handler = new ProvinceHandler(overlord, 1, List.of(1, 9)); + assertFalse(handler.canClaim(8, false, moving)); + assertFalse(handler.canClaim(8, true, moving)); + } + + @Test + void aRelocationCheckSailsFromTheCapitalsCoast() { + load(Map.of(1, Terrain.PLAINS, 8, Terrain.PLAINS, 9, Terrain.PLAINS, 20, Terrain.SEA, + 21, Terrain.SEA)); + link(1, 20); link(20, 21); link(21, 8); + Guild moving = guild(overlord, "moving", 9); + when(moving.getFaction()).thenReturn(overlord); + when(overlord.getCapital()).thenReturn(1); + ProvinceHandler handler = new ProvinceHandler(overlord, 1, List.of(1, 9)); + assertTrue(handler.canClaim(8, false, moving)); } + @Test + void aRelocationCheckWithoutASeatedCapitalSailsOnlyInSeaMode() { + load(Map.of(1, Terrain.PLAINS, 8, Terrain.PLAINS, 9, Terrain.PLAINS, 10, Terrain.PLAINS, + 20, Terrain.SEA)); + link(10, 20); link(20, 8); + Guild moving = guild(overlord, "moving", 9); + guild(overlord, "staying", 10); + when(moving.getFaction()).thenReturn(overlord); + when(overlord.getCapital()).thenReturn(1); + ProvinceHandler handler = new ProvinceHandler(overlord, 1, List.of(9, 10)); + + assertFalse(handler.canClaim(8, false, moving)); + assertTrue(handler.canClaim(8, true, moving)); + } + @Test void aGuildCapitalJoinedToVassalLandStaysSeated() { // The vassal's capital 5 and its province 7 do not touch; the guild capital 8 touches only 7.