E2E: Heimathafen mit erreichbarem Nachbar-Küstenfeld (spawnNear "nachbar") für 20-kopfgeld und 34-transport-geleit

This commit is contained in:
db9979 committed 2026-11-29 11:17:00 +01:00
1 parent 4f3c490a1e
commit 5307ec90cb
3 files changed
+24 -2

No files matched your search

+3
View File
@@ -6,6 +6,9 @@ import { E2E } from "./env.ts";
import { awayFromEdge, expect, expectNoHorizontalOverflow, tapHex, test, uniqueName } from "./fixtures.ts";
import { setUnits, updateState } from "./game.ts";
// Heimathafen mit freiem, erreichbarem Küstenfeld in der Nähe (fixtures.ts, spawnNear "nachbar"; sonst je nach Startplatz kein Ziel).
test.use({ spawnNear: "nachbar" });
test("Kopfgeld auf die Spitze: Rangliste, Kartenblatt und Missionsplanung", async ({ page, player, seed }) => {
// Zielspieler in der Nähe, mit großer Flotte klar auf Rang 1, ohne Anfängerschutz.
const taken = new Set((await seed.sql`select col, row from base union all select col, row from nest union all select col, row from resource_field`).map((r) => `${r.col},${r.row}`));
+3
View File
@@ -7,6 +7,9 @@ import { E2E } from "./env.ts";
import { awayFromEdge, expect, expectNoHorizontalOverflow, tapHex, test, uniqueName } from "./fixtures.ts";
import { setBuildings, setResources, setUnits } from "./game.ts";
// Heimathafen mit freiem, erreichbarem Küstenfeld in der Nähe (fixtures.ts, spawnNear "nachbar"; sonst je nach Startplatz kein Ziel).
test.use({ spawnNear: "nachbar" });
test("Transport: Geleit-Empfehlung übernehmen setzt die Korvetten, der Konvoi fährt mit Geleit", async ({ page, player, seed }) => {
test.slow();
await setBuildings(seed.sql, player.baseId, { werft: 3, kommandozentrale: 5, hafenkommandantur: 4, lagerkomplex: 6 });
+18 -2
View File
@@ -7,7 +7,7 @@ import Valkey from "iovalkey";
import { createDb } from "@tidefront/db";
import { chooseBase, register, type Engine } from "@tidefront/engine";
import { hexSteps } from "@tidefront/game-core";
import { COLS, ROWS, hexAtLonLat, hexCenter, hexDistanceKm, hexIndex, nearestTradePort, terrainMap } from "@tidefront/world";
import { COLS, ROWS, hexAtLonLat, hexCenter, hexDistanceKm, hexIndex, isCoast, nearestTradePort, seaRoute, terrainMap } from "@tidefront/world";
import { E2E } from "./env.ts";
import { foundingSpot } from "./game.ts";
@@ -68,7 +68,8 @@ const SPOTS: [number, number][] = [
let spot = 0;
/** "founding": wie "spot", aber nur Hafenlagen, neben denen noch ein freies Gründungsfeld liegt (Außenposten, Radarposten, Seekabel). */
export type SpawnNear = "spot" | "nest" | "field" | "founding";
/** "nachbar": wie "spot", aber mit einem freien Küstenfeld in 170–260 km, per Schiff erreichbar (Zielhafen eines zweiten Spielers). */
export type SpawnNear = "spot" | "nest" | "field" | "founding" | "nachbar";
/** Abseits des Kartenrands (dort lässt sich die Karte nicht weit genug verschieben, um ein Feld frei anzutippen). */
export function awayFromEdge(h: { col: number; row: number }): boolean {
@@ -117,6 +118,7 @@ async function claimSpawn(seed: Seed, playerId: number, name: string, near: Spaw
for (const pt of points) {
for (const h of (await freeCoastNear(q, pt.lon, pt.lat)).filter(free).slice(0, 40)) {
if (near === "founding" && !(await foundingSpot(q, h).then(() => true, () => false))) continue;
if (near === "nachbar" && !(await neighborCoast(q, h))) continue;
const res = await chooseBase(seed.engine, playerId, `e2e-${name}-${h.col}-${h.row}`, {
col: h.col, row: h.row, name: `Hafen ${name.slice(4)}`, nightShieldStartHour: null, tzOffsetMinutes: E2E.tzOffsetMinutes,
});
@@ -136,6 +138,20 @@ async function claimSpawn(seed: Seed, playerId: number, name: string, near: Spaw
}) as Promise<{ home: { col: number; row: number }; nest: { id: number; col: number; row: number } | null; reservations: number[] }>;
}
/** Freies Küstenfeld 170–260 km von `h`, abseits des Kartenrands und der Handelshäfen, per Seeweg ganz erreichbar? */
async function neighborCoast(sql: Sql, h: { col: number; row: number }): Promise<boolean> {
const taken = new Set((await sql`select col, row from base union all select col, row from nest union all select col, row from resource_field`).map((r) => `${r.col},${r.row}`));
const t = terrainMap();
for (let row = Math.max(0, h.row - 6); row <= Math.min(ROWS - 1, h.row + 6); row++) for (let col = Math.max(0, h.col - 6); col <= Math.min(COLS - 1, h.col + 6); col++) {
const c = { col, row };
if (t[hexIndex(col, row)] !== "coast" || !isCoast(col, row) || taken.has(`${col},${row}`) || !awayFromEdge(c)) continue;
const d = hexDistanceKm(h, c);
if (d < 170 || d > 260 || nearestTradePort(c).distanceKm < 1) continue;
if (!seaRoute(h, c).partial) return true;
}
return false;
}
function shuffle<T>(a: T[]): T[] {
const out = [...a];
for (let i = out.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [out[i], out[j]] = [out[j], out[i]]; }