mirror of
https://github.com/db9979/tidefront.git
synced 2026-12-06 12:54:09 +01:00
Merge branch 'worktree-agent-a56ff51e42e942c8b'
This commit is contained in:
commit
28693d1fc2
14 files changed
+274
-53
No files matched your search
@@ -31,7 +31,13 @@ pub.on("error", () => {});
|
||||
sub.on("error", () => {});
|
||||
|
||||
const BODY_LIMIT = 256 * 1024;
|
||||
const app = Fastify({ logger: { level: process.env.LOG_LEVEL ?? "info" }, trustProxy: true, bodyLimit: BODY_LIMIT });
|
||||
// maxParamLength: gebündelte tRPC-Abfragen stehen im Pfad (/trpc/a,b,c…); die Vorgabe 100 lieferte sonst 414.
|
||||
const app = Fastify({
|
||||
logger: { level: process.env.LOG_LEVEL ?? "info" },
|
||||
trustProxy: true,
|
||||
bodyLimit: BODY_LIMIT,
|
||||
routerOptions: { maxParamLength: 1000 },
|
||||
});
|
||||
|
||||
const engine: Engine = {
|
||||
db,
|
||||
|
||||
@@ -45,16 +45,25 @@ export function sabotagedUntil(base: BaseData, id: string, now: number): number
|
||||
export function IntelPanel({ base, now }: { base: BaseData; now: number }) {
|
||||
const i = base.intel;
|
||||
if (!i) return null;
|
||||
// Kurze Werte, damit die Beschriftung auf Handybreite nicht in eine schmale Spalte gedrückt wird.
|
||||
const rows: [string, string][] = [
|
||||
["Spione", `${fmtNum(i.spies.home)} daheim · ${fmtNum(i.spies.away)} unterwegs · ${fmtNum(i.spies.training)} in Ausbildung (höchstens ${fmtNum(i.cap)})`],
|
||||
["Abwehr gegen fremde Spione", `${i.defense.total} (${partsText(i.defense)})`],
|
||||
["Spione daheim", fmtNum(i.spies.home)],
|
||||
["Spione unterwegs", fmtNum(i.spies.away)],
|
||||
...(i.spies.training > 0 ? [["Spione in Ausbildung", fmtNum(i.spies.training)] as [string, string]] : []),
|
||||
["Höchstzahl Spione", fmtNum(i.cap)],
|
||||
["Abwehr gegen fremde Spione", String(i.defense.total)],
|
||||
["Erfolgswert Erkunden", String(i.success.erkunden?.total ?? 0)],
|
||||
["Erfolgswert Sabotage", String(i.success.sabotage?.total ?? 0)],
|
||||
["Gelungene Aufträge", `${fmtNum(i.successes)} (Erfahrung)`],
|
||||
["Gelungene Aufträge (Erfahrung)", fmtNum(i.successes)],
|
||||
];
|
||||
if (i.disinfo.count > 0 && i.disinfo.untilMs) rows.push(["Desinformation ausgelegt", `${i.disinfo.count} · bis ${fmtTime(i.disinfo.untilMs)}`]);
|
||||
if (i.sabotageCooldownUntilMs > now) rows.push(["Alarmbereitschaft nach Sabotage", `bis ${fmtTime(i.sabotageCooldownUntilMs)}`]);
|
||||
return <div className="mb-3"><StatTable rows={rows} /></div>;
|
||||
return (
|
||||
<div className="mb-3">
|
||||
<StatTable rows={rows} />
|
||||
<p className="text-xs text-ink2 mt-1">Abwehr: {partsText(i.defense)}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface SpyData {
|
||||
@@ -71,7 +80,7 @@ function Dice({ s }: { s: SpyData }) {
|
||||
<div className="flex items-center gap-3 rounded-lg bg-paper border border-rule p-2 mb-2">
|
||||
<div className={`w-12 h-12 grid place-items-center rounded-lg border-2 font-display text-xl ${s.success ? "border-moos text-moos" : "border-siegel text-siegel"}`}>{s.roll}</div>
|
||||
<div className="text-sm">
|
||||
<div>W{s.die}: <strong>{s.roll}</strong> {s.success ? "≤" : ">"} Zielzahl {s.threshold} – {s.success ? "unentdeckt" : "enttarnt"}</div>
|
||||
<div>Wurf W{s.die}: <strong>{s.roll}</strong> {s.success ? "≤" : ">"} Zielzahl {s.threshold} – <strong className={s.success ? "text-moos" : "text-siegel"}>{s.success ? "gelungen, unentdeckt" : "misslungen, enttarnt"}</strong></div>
|
||||
{s.successValue && <div className="text-xs text-slate-400">Erfolgswert {s.successValue.total} ({partsText(s.successValue)})</div>}
|
||||
{s.defenseValue && <div className="text-xs text-slate-400">Abwehr {s.defenseValue.total} ({partsText(s.defenseValue)})</div>}
|
||||
</div>
|
||||
@@ -89,7 +98,7 @@ export function SpyReport({ d, role }: { d: Record<string, unknown>; role: strin
|
||||
{role === "defender" ? (
|
||||
<p className="text-sm mb-2">Absender: <strong>{s.from}</strong>. Auftrag: {what}. {fmtNum(s.spies)} {s.spies === 1 ? "Spion" : "Spione"} ausgeschaltet.</p>
|
||||
) : (
|
||||
<p className="text-sm mb-2">Ziel: {s.targetName}{s.owner && s.kind !== "kartell" ? ` (${s.owner})` : ""}. {s.aborted ?? (s.success ? "Der Auftrag ist gelungen; das Ziel hat nichts bemerkt." : `Enttarnt – ${s.spies === 1 ? "der Spion ist" : "die Spione sind"} verloren, das Ziel kennt jetzt deinen Namen.`)}</p>
|
||||
<p className="text-sm mb-2">Ziel: {s.targetName}{s.owner && s.kind !== "kartell" ? ` (${s.owner})` : ""}. {s.aborted ?? (s.success ? "Der Auftrag ist gelungen; das Ziel hat nichts bemerkt." : `Enttarnt – ${s.spies === 1 ? "der Spion ist" : "die Spione sind"} verloren${s.kind === "kartell" ? "." : ", das Ziel kennt jetzt deinen Namen."}`)}</p>
|
||||
)}
|
||||
<Dice s={s} />
|
||||
</Card>
|
||||
@@ -157,7 +166,7 @@ function Cartel({ c }: { c: CartelData }) {
|
||||
<p>{c.next ? `Nächstes Unternehmen: ${c.next.kind ? label(c.next.kind) : "unbekannt"} um ${fmtTime(c.next.atMs)}.` : "Kein weiteres Unternehmen geplant."}</p>
|
||||
{c.events.length === 0 && <p className="text-slate-400">Derzeit kein Weltereignis.</p>}
|
||||
{c.events.map((e) => (
|
||||
<div key={e.id} className="rounded-lg bg-paper border border-rule p-2">
|
||||
<div key={e.id} className="rounded-lg bg-paper border border-rule p-2 break-words">
|
||||
<strong>{e.name}</strong> · Feld {e.position.col}/{e.position.row} · endet {fmtTime(e.endsAtMs)}
|
||||
<div className="text-xs"><CountsLine counts={e.units} /></div>
|
||||
{e.harbor && <div className="text-xs">Zielhafen: Feld {e.harbor.col}/{e.harbor.row}</div>}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { fmtSeconds, fmtTime } from "../lib/time.ts";
|
||||
import type { Target } from "../App.tsx";
|
||||
import { HexMap } from "../screens/LazyHexMap.tsx";
|
||||
import { Icon } from "../icons.tsx";
|
||||
import { RELATION_HEX } from "../map/TacticalIcon.tsx";
|
||||
import { Button, Card, ErrorLine } from "../ui.tsx";
|
||||
|
||||
type Kind = "erkunden" | "sabotage" | "desinformation" | "kartell";
|
||||
@@ -39,6 +40,8 @@ export function partsText(v: { parts: { id: string; value: number }[] }): string
|
||||
}
|
||||
|
||||
const pct = (x: number) => `${Math.round(x * 100)} %`;
|
||||
/** Verhältnis zum Ziel (aus der Kartenansicht); neutral ohne Zusatz. */
|
||||
const REL: Record<string, string> = { own: "eigener Hafen", allianz: "Allianzmitglied", pakt: "Paktpartner", krieg: "Kriegsgegner", neutral: "" };
|
||||
|
||||
export function SpyPlan({ base, map, target, setTarget, center, onClose }: { base: BaseData; map: MapData; target: Target | null; setTarget: (t: Target | null) => void; center: Target; onClose: () => void }) {
|
||||
const [kind, setKind] = useState<Kind>("erkunden");
|
||||
@@ -89,7 +92,7 @@ export function SpyPlan({ base, map, target, setTarget, center, onClose }: { bas
|
||||
<HexMap data={map} selected={target} onSelect={setTarget} center={center} />
|
||||
</div>
|
||||
<p className="text-sm">
|
||||
{!target || target.eventId ? "Spielerhafen auf der Karte antippen." : tBase ? <>Hafen <strong>{tBase.name}</strong> ({tBase.owner})</> : <span className="text-slate-400">Feld {target.col}/{target.row}: kein Hafen</span>}
|
||||
{!target || target.eventId ? "Spielerhafen auf der Karte antippen." : tBase ? <>Hafen <strong>{tBase.name}</strong> ({tBase.owner}){REL[tBase.relation] && <span className="font-semibold" style={{ color: RELATION_HEX[tBase.relation] }}> · {REL[tBase.relation]}</span>}</> : <span className="text-slate-400">Feld {target.col}/{target.row}: kein Hafen</span>}
|
||||
</p>
|
||||
</Card>
|
||||
)}
|
||||
@@ -118,15 +121,20 @@ export function SpyPlan({ base, map, target, setTarget, center, onClose }: { bas
|
||||
<>
|
||||
<div className="flex justify-between"><span>Erfolgswert</span><strong className="mono">{p.success.total}</strong></div>
|
||||
<div className="text-xs text-slate-400">{partsText(p.success)}</div>
|
||||
<div className="flex justify-between"><span>Abwehr des Ziels</span><strong className="mono">{p.defense.total}</strong></div>
|
||||
<div className="flex justify-between"><span>{kind === "kartell" ? "Abwehr des Kartells" : "Abwehr des Ziels"}</span><strong className="mono">− {p.defense.total}</strong></div>
|
||||
<div className="text-xs text-slate-400">{partsText(p.defense)}</div>
|
||||
<div className="flex justify-between"><span>Gelingt bei W{p.die} ≤</span><strong className="mono">{p.threshold}</strong></div>
|
||||
<div className="flex h-2 overflow-hidden rounded bg-navy-950 mt-1">
|
||||
<div className="bg-moos" style={{ width: pct(p.chance) }} />
|
||||
<div className="flex justify-between gap-2 border-t border-rule pt-1">
|
||||
<span>Gelingt bei Wurf (W{p.die}) von 1 bis</span><strong className="mono">{p.threshold}</strong>
|
||||
</div>
|
||||
{/* Breite in CSS-Schreibweise (pct() setzt ein Leerzeichen vor %, das wäre ungültig). */}
|
||||
<div className="flex h-2.5 overflow-hidden rounded bg-navy-950 mt-1" role="img" aria-label={`Erfolg ${pct(p.chance)}, Enttarnung ${pct(p.detectChance)}`}>
|
||||
<div className="bg-moos" style={{ width: `${Math.round(p.chance * 100)}%` }} />
|
||||
<div className="bg-siegel flex-1" />
|
||||
</div>
|
||||
<div className="flex justify-between text-xs"><span className="text-moos">Erfolg {pct(p.chance)}</span><span className="text-siegel">Enttarnung {pct(p.detectChance)}</span></div>
|
||||
<p className="text-xs text-slate-400">Enttarnt: die Spione sind verloren und das Ziel erfährt, wer sie geschickt hat. Gewürfelt wird bei Ankunft mit den dann gültigen Werten.</p>
|
||||
<div className="flex justify-between text-xs font-semibold"><span className="text-moos">Erfolg {pct(p.chance)}</span><span className="text-siegel">Enttarnt {pct(p.detectChance)}</span></div>
|
||||
<p className="text-xs text-slate-400">
|
||||
Misslingt der Wurf, wird der Spion enttarnt: {kind === "kartell" ? "er ist verloren." : "er ist verloren und das Ziel erfährt, wer ihn geschickt hat."} Gewürfelt wird bei Ankunft mit den dann gültigen Werten.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
{p.ok ? (
|
||||
|
||||
@@ -54,7 +54,12 @@ export function useLive(enabled: boolean): void {
|
||||
return () => {
|
||||
stopped = true;
|
||||
clearTimeout(timer);
|
||||
ws?.close();
|
||||
// Noch im Aufbau: erst nach dem Öffnen schließen (sonst Konsolenwarnung „closed before the connection is established“).
|
||||
const w = ws;
|
||||
if (w && w.readyState === WebSocket.CONNECTING) {
|
||||
w.onopen = () => w.close();
|
||||
w.onmessage = null;
|
||||
} else w?.close();
|
||||
};
|
||||
}, [enabled]);
|
||||
}
|
||||
+53
-17
@@ -1,18 +1,47 @@
|
||||
// Einklappbare Legende der Kartenzeichen.
|
||||
// Einklappbare Legende der Kartenzeichen: Häfen nach Verhältnis, Kartell und See, Übersichtspunkte, Wetter.
|
||||
import { useState, type ReactNode } from "react";
|
||||
import { TacticalIcon } from "./TacticalIcon.tsx";
|
||||
|
||||
const ITEMS: { icon: ReactNode; text: string }[] = [
|
||||
{ icon: <TacticalIcon kind="own" />, text: "Eigener Stützpunkt" },
|
||||
{ icon: <TacticalIcon kind="other" />, text: "Anderer Spieler, gestrichelter Ring: geschützt" },
|
||||
{ icon: <TacticalIcon kind="nest" level={3} />, text: "Piratennest, Stufe I–V" },
|
||||
{ icon: <TacticalIcon kind="nestEmpty" level={2} />, text: "Nest verlassen, wird neu besetzt" },
|
||||
{ icon: <TacticalIcon kind="wreck" />, text: "Wrackfeld, bergbar" },
|
||||
{ icon: <TacticalIcon kind="port" />, text: "Handelshafen der Börse" },
|
||||
{ icon: <><TacticalIcon kind="ship" size={22} /><TacticalIcon kind="shipBack" size={22} /></>, text: "Eigener Verband: Hinfahrt, Rückfahrt" },
|
||||
{ icon: <Hatch d="M2 14 L14 2 M7 16 L16 7 M0 9 L9 0" color="#18273a" />, text: "Wetter: Wolken (Schraffur)" },
|
||||
{ icon: <Hatch d="M2 14 L9 4 L16 14 M6 14 L13 4" color="#a8331f" />, text: "Sturm: Schiffe langsamer, Flugzeuge bleiben am Boden" },
|
||||
{ icon: <Hatch d="M1 6 H4 M7 6 H10 M13 6 H16 M1 11 H4 M7 11 H10 M13 11 H16" color="#2d5b7a" />, text: "Nebel: Radar und Aufklärung schlechter" },
|
||||
type Item = { icon: ReactNode; text: string };
|
||||
|
||||
const GROUPS: { title: string; items: Item[] }[] = [
|
||||
{
|
||||
title: "Häfen",
|
||||
items: [
|
||||
{ icon: <TacticalIcon kind="own" />, text: "Eigener Stützpunkt" },
|
||||
{ icon: <TacticalIcon kind="ally" />, text: "Allianzmitglied (grün, Doppelring)" },
|
||||
{ icon: <TacticalIcon kind="pact" />, text: "Paktpartner: Nichtangriffspakt (ocker)" },
|
||||
{ icon: <TacticalIcon kind="war" />, text: "Kriegsgegner (rot, Peilstriche)" },
|
||||
{ icon: <TacticalIcon kind="other" />, text: "Neutraler Spieler; gestrichelter Ring: geschützt" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Kartell und See",
|
||||
items: [
|
||||
{ icon: <TacticalIcon kind="nest" level={3} />, text: "Kartellnest (Piraten), Stufe I–V" },
|
||||
{ icon: <TacticalIcon kind="nestEmpty" level={2} />, text: "Nest verlassen, wird neu besetzt" },
|
||||
{ icon: <TacticalIcon kind="wreck" />, text: "Wrackfeld, bergbar" },
|
||||
{ icon: <TacticalIcon kind="port" />, text: "Handelshafen der Börse" },
|
||||
{ icon: <><TacticalIcon kind="ship" size={22} /><TacticalIcon kind="shipBack" size={22} /></>, text: "Eigener Verband: Hinfahrt, Rückfahrt" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Übersicht (weit herausgezoomt)",
|
||||
items: [
|
||||
{ icon: <><TacticalIcon kind="dotAlly" size={18} /><TacticalIcon kind="dotPact" size={18} /></>, text: "Punkt: Hafen von Allianz (grün) oder Paktpartner (ocker)" },
|
||||
{ icon: <><TacticalIcon kind="dotWar" size={18} /><TacticalIcon kind="dotOther" size={18} /></>, text: "Punkt: Kriegsgegner (rot, größer) oder neutral (blau)" },
|
||||
{ icon: <TacticalIcon kind="dotNest" size={18} />, text: "Raute: Kartellnest, größer = höhere Stufe" },
|
||||
{ icon: <TacticalIcon kind="dotPort" size={18} />, text: "Hohler Ring: Handelshafen" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Wetter (Knopf „Wetter an/aus“)",
|
||||
items: [
|
||||
{ icon: <Hatch d="M2 14 L14 2 M7 16 L16 7 M0 9 L9 0" color="#18273a" />, text: "Wolken (Schraffur)" },
|
||||
{ icon: <Hatch d="M2 14 L9 4 L16 14 M6 14 L13 4" color="#a8331f" />, text: "Sturm: Schiffe langsamer, Flugzeuge bleiben am Boden" },
|
||||
{ icon: <Hatch d="M1 6 H4 M7 6 H10 M13 6 H16 M1 11 H4 M7 11 H10 M13 11 H16" color="#2d5b7a" />, text: "Nebel: Radar und Aufklärung schlechter" },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
function Hatch({ d, color }: { d: string; color: string }) {
|
||||
@@ -28,12 +57,19 @@ export function MapLegend() {
|
||||
{open ? "▾ Legende" : "▸ Legende"}
|
||||
</button>
|
||||
{open && (
|
||||
<ul className="px-3 pb-3 space-y-1.5 text-xs text-ink">
|
||||
{ITEMS.map((i) => (
|
||||
<li key={i.text} className="flex items-center gap-2"><span className="flex w-12 justify-center">{i.icon}</span><span>{i.text}</span></li>
|
||||
<div className="px-3 pb-3 text-xs text-ink max-h-[min(60vh,480px)] overflow-y-auto">
|
||||
{GROUPS.map((g) => (
|
||||
<section key={g.title} className="pt-1.5">
|
||||
<h3 className="font-display text-[10px] uppercase tracking-[0.12em] text-ink2 border-b border-rule pb-0.5 mb-1">{g.title}</h3>
|
||||
<ul className="space-y-1.5">
|
||||
{g.items.map((i) => (
|
||||
<li key={i.text} className="flex items-center gap-2"><span className="flex w-12 shrink-0 justify-center">{i.icon}</span><span className="min-w-0">{i.text}</span></li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
))}
|
||||
<li className="text-ink2 pt-1">Feld antippen für Details · ziehen zum Schwenken · zwei Finger oder +/− zum Zoomen</li>
|
||||
</ul>
|
||||
<p className="text-ink2 pt-2">Feld antippen für Details · ziehen zum Schwenken · zwei Finger oder +/− zum Zoomen</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,9 +3,28 @@ const INK = "#18273a";
|
||||
const PAPER = "#fbf8f0";
|
||||
const SIEGEL = "#a8331f";
|
||||
const SEE = "#2d5b7a";
|
||||
const ALLY = "#3d6b4f";
|
||||
const PAKT = "#9a7424";
|
||||
const ROMAN = ["", "I", "II", "III", "IV", "V"];
|
||||
|
||||
export type TacticalKind = "own" | "other" | "nest" | "nestEmpty" | "wreck" | "port" | "ship" | "shipBack";
|
||||
/** Farben der Verhältnisse (wie map/symbols.ts). */
|
||||
export const RELATION_HEX = { own: INK, allianz: ALLY, pakt: PAKT, krieg: SIEGEL, neutral: SEE } as const;
|
||||
|
||||
export type TacticalKind =
|
||||
| "own" | "other" | "ally" | "pact" | "war" | "nest" | "nestEmpty" | "wreck" | "port" | "ship" | "shipBack"
|
||||
// Übersichtspunkte (rausgezoomte Karte)
|
||||
| "dotAlly" | "dotPact" | "dotWar" | "dotOther" | "dotNest" | "dotPort";
|
||||
|
||||
/** Zeichen eines fremden Hafens nach Verhältnis. */
|
||||
export function relationKind(relation: string | undefined): TacticalKind {
|
||||
return relation === "allianz" ? "ally" : relation === "pakt" ? "pact" : relation === "krieg" ? "war" : "other";
|
||||
}
|
||||
|
||||
function Dot({ color, r = 7, hollow = false }: { color: string; r?: number; hollow?: boolean }) {
|
||||
return hollow
|
||||
? <circle r={r} fill={PAPER} stroke={color} strokeWidth="1.6" />
|
||||
: <><circle r={r + 1.6} fill={PAPER} stroke="#c9c2b0" strokeWidth="0.6" /><circle r={r} fill={color} /></>;
|
||||
}
|
||||
|
||||
function Anchor({ color, k = 1 }: { color: string; k?: number }) {
|
||||
return (
|
||||
@@ -22,6 +41,20 @@ export function TacticalIcon({ kind, level = 1, size = 28 }: { kind: TacticalKin
|
||||
<svg viewBox="-17 -17 34 34" width={size} height={size} aria-hidden="true" className="shrink-0">
|
||||
{kind === "own" && (<><circle r="14" fill={INK} /><circle r="11" fill="none" stroke={PAPER} strokeWidth="0.8" /><Anchor color={PAPER} k={1.15} /></>)}
|
||||
{kind === "other" && (<><circle r="12" fill={PAPER} stroke={SEE} strokeWidth="1.6" /><Anchor color={SEE} /></>)}
|
||||
{kind === "ally" && (<><circle r="12" fill={PAPER} stroke={ALLY} strokeWidth="2" /><circle r="9.6" fill="none" stroke={ALLY} strokeWidth="0.7" /><Anchor color={ALLY} k={0.85} /></>)}
|
||||
{kind === "pact" && (<><circle r="12" fill={PAPER} stroke={PAKT} strokeWidth="2" /><Anchor color={PAKT} /></>)}
|
||||
{kind === "war" && (
|
||||
<>
|
||||
<circle r="12" fill={PAPER} stroke={SIEGEL} strokeWidth="2" /><Anchor color={SIEGEL} />
|
||||
<path d="M0 -13 V-17 M0 13 V17 M-13 0 H-17 M13 0 H17" stroke={SIEGEL} strokeWidth="1.6" />
|
||||
</>
|
||||
)}
|
||||
{kind === "dotAlly" && <Dot color={ALLY} />}
|
||||
{kind === "dotPact" && <Dot color={PAKT} />}
|
||||
{kind === "dotWar" && <Dot color={SIEGEL} r={8.5} />}
|
||||
{kind === "dotOther" && <Dot color={SEE} />}
|
||||
{kind === "dotPort" && <Dot color={INK} r={6} hollow />}
|
||||
{kind === "dotNest" && (<><polygon points="0,-11 11,0 0,11 -11,0" fill={PAPER} /><polygon points="0,-9 9,0 0,9 -9,0" fill={SIEGEL} /></>)}
|
||||
{kind === "nest" && (
|
||||
<>
|
||||
<polygon points="0,-13 13,0 0,13 -13,0" fill={SIEGEL} />
|
||||
|
||||
@@ -26,7 +26,7 @@ export function nameTag(text: string, color: number, y = 18): Container {
|
||||
const t = txt(text.toUpperCase(), 10.5, INK, SERIF, "600", 1.2);
|
||||
t.anchor.set(0.5, 0);
|
||||
const w = t.width + 10;
|
||||
const bg = new Graphics().rect(-w / 2, y, w, t.height + 3).fill({ color: PAPER }).stroke({ color: color === SEE ? SEE : INK, width: 1 });
|
||||
const bg = new Graphics().rect(-w / 2, y, w, t.height + 3).fill({ color: PAPER }).stroke({ color, width: color === SEE || color === INK ? 1 : 1.4 });
|
||||
t.position.set(0, y + 1.5);
|
||||
c.addChild(bg, t);
|
||||
return c;
|
||||
@@ -49,14 +49,41 @@ export function ownBaseSymbol(): Container {
|
||||
return c;
|
||||
}
|
||||
|
||||
/** Fremder Spielerhafen: Papierkreis mit Tintenanker; geschützt mit gestricheltem Außenring. */
|
||||
export function otherBaseSymbol(isProtected: boolean): Container {
|
||||
/** Verhältnis eines fremden Hafens zum Betrachter (aus der Kartenansicht). */
|
||||
export type Relation = "allianz" | "pakt" | "krieg" | "neutral";
|
||||
/** Grünspan für die eigene Allianz, Ocker für Paktpartner, Siegelrot für Kriegsgegner, Seeblau neutral. */
|
||||
export const ALLY = 0x3d6b4f;
|
||||
export const PAKT = 0x9a7424;
|
||||
export const RELATION_COLOR: Record<Relation, number> = { allianz: ALLY, pakt: PAKT, krieg: SIEGEL, neutral: SEE };
|
||||
|
||||
/**
|
||||
* Fremder Spielerhafen: Papierkreis mit Anker in der Farbe des Verhältnisses; Allianz mit innerem Doppelring,
|
||||
* Krieg mit vier Peilstrichen, geschützt mit gestricheltem Außenring.
|
||||
*/
|
||||
export function otherBaseSymbol(isProtected: boolean, relation: Relation = "neutral"): Container {
|
||||
const c = new Container();
|
||||
const g = new Graphics();
|
||||
g.circle(0, 0, 12).fill({ color: PAPER }).stroke({ color: SEE, width: 1.6 });
|
||||
anchor(g, SEE, 1);
|
||||
const col = RELATION_COLOR[relation];
|
||||
g.circle(0, 0, 12).fill({ color: PAPER }).stroke({ color: col, width: relation === "neutral" ? 1.6 : 2 });
|
||||
if (relation === "allianz") g.circle(0, 0, 9.6).stroke({ color: col, width: 0.7 });
|
||||
anchor(g, col, relation === "allianz" ? 0.85 : 1);
|
||||
if (relation === "krieg") {
|
||||
g.moveTo(0, -13).lineTo(0, -19).moveTo(0, 13).lineTo(0, 19).moveTo(-13, 0).lineTo(-19, 0).moveTo(13, 0).lineTo(19, 0);
|
||||
g.stroke({ color: SIEGEL, width: 1.6 });
|
||||
}
|
||||
if (isProtected) for (let i = 0; i < 12; i++) g.arc(0, 0, 16, (i * Math.PI) / 6, (i * Math.PI) / 6 + 0.28).moveTo(0, 0);
|
||||
if (isProtected) g.stroke({ color: SEE, width: 1.2 });
|
||||
if (isProtected) g.stroke({ color: col, width: 1.2 });
|
||||
c.addChild(g);
|
||||
return c;
|
||||
}
|
||||
|
||||
/** Übersichtspunkt eines Nests: kleine Raute (Häfen sind Kreise), Größe nach Stufe. */
|
||||
export function diamondDot(color: number, r: number, alpha = 1): Container {
|
||||
const c = new Container();
|
||||
const g = new Graphics();
|
||||
const o = r + 1.1;
|
||||
g.poly([0, -o, o, 0, 0, o, -o, 0]).fill({ color: PAPER, alpha: 0.9 });
|
||||
g.poly([0, -r, r, 0, 0, r, -r, 0]).fill({ color, alpha });
|
||||
c.addChild(g);
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -127,8 +127,9 @@ export function AdminStats() {
|
||||
<li key={r.id}>
|
||||
<div className="flex justify-between gap-2">
|
||||
<span className="inline-flex items-center gap-1"><Icon id={r.id} size={16} /> {label(r.id)}</span>
|
||||
<span className="mono">{fmtNum(r.offset * 100, 1)} % <span className="text-ink2 text-xs">(Ziel {fmtNum(r.target * 100, 1)} %, Richtwert {fmtNum(r.effective, 3)})</span></span>
|
||||
<span className="mono">{fmtNum(r.offset * 100, 1)} %</span>
|
||||
</div>
|
||||
<div className="mono text-ink2 text-xs pl-6">Ziel {fmtNum(r.target * 100, 1)} % · Richtwert {fmtNum(r.effective, 3)}</div>
|
||||
{r.influences.map((x, i) => (
|
||||
<div key={i} className="text-xs text-ink2 pl-6">{x.reason}: {fmtNum(x.now * 100, 1)} %</div>
|
||||
))}
|
||||
|
||||
@@ -29,7 +29,7 @@ export function AllianceScreen({ onCompose }: { onCompose: (d: Draft) => void })
|
||||
<div className="flex gap-1 overflow-x-auto mb-3" role="tablist" aria-label="Allianz">
|
||||
{subs.map((s) => (
|
||||
<button key={s.id} type="button" role="tab" aria-selected={active === s.id} onClick={() => setSub(s.id)}
|
||||
className={`tap shrink-0 flex-1 rounded-lg px-3 text-xs font-semibold ${active === s.id ? "bg-ink text-paper" : "bg-navy-950/60 text-slate-400"}`}>
|
||||
className={`tap shrink-0 flex-1 rounded-lg px-2 text-xs font-semibold ${active === s.id ? "bg-ink text-paper" : "bg-navy-950/60 text-slate-400"}`}>
|
||||
{s.label}
|
||||
</button>
|
||||
))}
|
||||
|
||||
@@ -18,7 +18,7 @@ import { buildTerrain, hexPoints, xyOf } from "../map/terrain.ts";
|
||||
import { Graticule } from "../map/graticule.ts";
|
||||
import { MAP_BOUNDS, attachGestures, clampScale, clampView, minScale, zoomAround } from "../map/gestures.ts";
|
||||
import {
|
||||
INK, SEE, SIEGEL, alertRing, compassRose, dotSymbol, mapLabel, nameTag, nestSymbol, otherBaseSymbol, ownBaseSymbol, portSymbol, shipSymbol, wreckSymbol,
|
||||
INK, RELATION_COLOR, SEE, SIEGEL, alertRing, compassRose, diamondDot, dotSymbol, mapLabel, nameTag, nestSymbol, otherBaseSymbol, ownBaseSymbol, portSymbol, shipSymbol, wreckSymbol,
|
||||
} from "../map/symbols.ts";
|
||||
import { LOD_NEAR, LOD_OVERVIEW, fade, layout, pinScale, snap, weatherAlpha, type Pinned } from "../map/lod.ts";
|
||||
import { buildWeatherLayer, type WeatherLayer } from "../map/weather.ts"; // Wetterschicht (v1.6)
|
||||
@@ -140,7 +140,17 @@ export function HexMap(props: HexMapProps) {
|
||||
el.appendChild(app.canvas);
|
||||
app.canvas.style.touchAction = "none";
|
||||
app.canvas.style.display = "block";
|
||||
shot.ready(app.canvas, () => app.render());
|
||||
// Vor der Aufnahme auf die aktuelle Größe des Kartenrahmens bringen und Randzeichen neu setzen,
|
||||
// sonst schneidet der Rahmen eine veraltete, breitere Fläche ab (Windrose am rechten Rand).
|
||||
shot.ready(app.canvas, () => {
|
||||
app.resize();
|
||||
tick(app.ticker);
|
||||
app.render();
|
||||
});
|
||||
// resizeTo hört nur auf Fenstergrößen; Größenänderungen des Rahmens (Info-Blatt, Overlays) zusätzlich.
|
||||
const ro = new ResizeObserver(() => app.queueResize());
|
||||
ro.observe(el);
|
||||
cleanups.push(() => ro.disconnect());
|
||||
const world = new Container();
|
||||
app.stage.addChild(world);
|
||||
const terrain = buildTerrain();
|
||||
@@ -309,18 +319,21 @@ export function HexMap(props: HexMapProps) {
|
||||
// Detailstufen: Übersicht nur Punkte (Nester nach Stufe, fremde Häfen), ab mittlerer Stufe Zeichen, nah alles.
|
||||
for (const w of data.wrecks) add(wreckSymbol(), w.col, w.row, { min: LOD_NEAR });
|
||||
for (const n of data.nests) {
|
||||
if (!n.empty) add(dotSymbol(SIEGEL, 1.6 + n.level * 0.45, 0.72), n.col, n.row, { max: LOD_OVERVIEW, fixed: true });
|
||||
// Kartell-Nester in der Übersicht als Rauten (Häfen sind Kreise), Größe nach Stufe.
|
||||
if (!n.empty) add(diamondDot(SIEGEL, 2.2 + n.level * 0.5, 0.8), n.col, n.row, { max: LOD_OVERVIEW, fixed: true });
|
||||
add(nestSymbol(n.level, n.empty), n.col, n.row, { min: LOD_OVERVIEW });
|
||||
}
|
||||
for (const b of data.bases) {
|
||||
const tag = nameTag(b.own ? b.name : `${b.name} · ${b.owner}`, b.own ? INK : SEE);
|
||||
const rel = b.relation === "own" ? "neutral" : b.relation;
|
||||
const tag = nameTag(b.own ? b.name : `${b.name} · ${b.owner}`, b.own ? INK : RELATION_COLOR[rel]);
|
||||
if (b.own) {
|
||||
add(ownBaseSymbol(), b.col, b.row, { prio: PRIO.always });
|
||||
add(tag, b.col, b.row, { fixed: true, prio: PRIO.always });
|
||||
continue;
|
||||
}
|
||||
add(dotSymbol(SEE, 3, 0.95), b.col, b.row, { max: LOD_OVERVIEW, fixed: true });
|
||||
add(otherBaseSymbol(b.protection !== null), b.col, b.row, { min: LOD_OVERVIEW });
|
||||
// Übersicht: Punkt in der Farbe des Verhältnisses; Kriegsgegner etwas größer.
|
||||
add(dotSymbol(RELATION_COLOR[rel], rel === "krieg" ? 3.6 : 3, 0.95), b.col, b.row, { max: LOD_OVERVIEW, fixed: true });
|
||||
add(otherBaseSymbol(b.protection !== null, rel), b.col, b.row, { min: LOD_OVERVIEW });
|
||||
add(tag, b.col, b.row, { min: LOD_NAMES, fixed: true, prio: PRIO.base });
|
||||
}
|
||||
// Eigener Hafen zuoberst
|
||||
|
||||
@@ -8,13 +8,20 @@ import type { Target } from "../App.tsx";
|
||||
import { HexMap } from "./LazyHexMap.tsx";
|
||||
import { Button, Loading } from "../ui.tsx";
|
||||
import { MapLegend } from "../map/Legend.tsx";
|
||||
import { TacticalIcon } from "../map/TacticalIcon.tsx";
|
||||
import { RELATION_HEX, TacticalIcon, relationKind } from "../map/TacticalIcon.tsx";
|
||||
import { fmtPosition } from "../map/coords.ts";
|
||||
// Weltereignisse
|
||||
import { WorldEventCard, useWorldEvents } from "../components/WorldEvents.tsx";
|
||||
|
||||
const TERRAIN: Record<string, string> = { sea: "Offene See", coast: "Küste", land: "Binnenland" };
|
||||
const LEVEL_TEXT = ["", "schwach besetzt", "kleine Bande", "befestigt", "Festung", "Hauptquartier"];
|
||||
const RELATION_TEXT: Record<string, string> = {
|
||||
own: "",
|
||||
allianz: "Allianzmitglied – kein Überfall möglich",
|
||||
pakt: "Paktpartner – Nichtangriffspakt, kein Überfall möglich",
|
||||
krieg: "Kriegsgegner",
|
||||
neutral: "Neutral",
|
||||
};
|
||||
const LEVEL_TEXT =["", "schwach besetzt", "kleine Bande", "befestigt", "Festung", "Hauptquartier"];
|
||||
|
||||
export function MapScreen({ base, focus, onPlan }: { base: BaseData; focus: Target | null; onPlan: (t: Target) => void }) {
|
||||
const map = useQuery({ ...trpc.world.map.queryOptions(), refetchInterval: 60000 });
|
||||
@@ -100,12 +107,15 @@ export function MapScreen({ base, focus, onPlan }: { base: BaseData; focus: Targ
|
||||
{info.base && (
|
||||
<div className="mt-1">
|
||||
<div className="font-serif text-[19px] leading-tight flex items-center gap-2 mt-0.5">
|
||||
<TacticalIcon kind={info.base.own ? "own" : "other"} size={26} /> {info.base.name}
|
||||
<TacticalIcon kind={info.base.own ? "own" : relationKind(info.base.relation)} size={26} /> {info.base.name}
|
||||
</div>
|
||||
<div className="text-xs text-slate-300">{info.base.own ? "Dein Stützpunkt" : `Stützpunkt von ${info.base.owner}`}</div>
|
||||
{!info.base.own && (
|
||||
<div className="text-xs font-semibold" style={{ color: RELATION_HEX[info.base.relation] }}>{RELATION_TEXT[info.base.relation]}</div>
|
||||
)}
|
||||
{info.base.protection ? (
|
||||
<div className="text-emerald-300 text-xs">Schutz: {label(info.base.protection)} – kein Überfall möglich</div>
|
||||
) : !info.base.own && <div className="text-siegel text-xs">Kein Schutz aktiv – Überfall möglich</div>}
|
||||
) : !info.base.own && info.base.relation !== "allianz" && info.base.relation !== "pakt" && <div className="text-siegel text-xs">Kein Schutz aktiv – Überfall möglich</div>}
|
||||
{isHome && <div className="text-xs text-slate-400">Nächster Handelshafen: {nearestTradePort(home).name} ({fmtNum(nearestTradePort(home).distanceKm)} km)</div>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -169,3 +169,47 @@ export async function atWar(db: DbOrTx, attackerId: number, defenderId: number,
|
||||
));
|
||||
return !!r;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Kartenansicht
|
||||
|
||||
/** Verhältnis eines fremden Spielers zum Betrachter (für die Kartenfarben). */
|
||||
export type Relation = "allianz" | "pakt" | "krieg" | "neutral";
|
||||
|
||||
/**
|
||||
* Verhältnis des Betrachters zu anderen Spielern, nur aus dem, was er ohnehin sieht: eigene Allianz sowie Pakte
|
||||
* und Kriege der eigenen Partei. Angebotene Pakte zählen nicht, die Kündigungsfrist schon; ein erklärter Krieg
|
||||
* gilt schon während der Vorlaufzeit. Nicht enthaltene Spieler sind neutral.
|
||||
*/
|
||||
export async function relationsOf(db: DbOrTx, viewerId: number, atMs: number): Promise<Map<number, Relation>> {
|
||||
const members = await db
|
||||
.select({ playerId: tables.allianceMember.playerId, allianceId: tables.allianceMember.allianceId })
|
||||
.from(tables.allianceMember);
|
||||
const allianceOf = new Map(members.map((m) => [m.playerId, m.allianceId]));
|
||||
const partyFor = (id: number) => (allianceOf.has(id) ? `a:${allianceOf.get(id)}` : `p:${id}`);
|
||||
const me = partyFor(viewerId);
|
||||
const rows = await db
|
||||
.select({ partyA: tables.diplomacy.partyA, partyB: tables.diplomacy.partyB, kind: tables.diplomacy.kind, status: tables.diplomacy.status, endsAt: tables.diplomacy.endsAt })
|
||||
.from(tables.diplomacy)
|
||||
.where(or(eq(tables.diplomacy.partyA, me), eq(tables.diplomacy.partyB, me)));
|
||||
const byParty = new Map<string, Relation>();
|
||||
for (const r of rows) {
|
||||
const other = r.partyA === me ? r.partyB : r.partyA;
|
||||
if (r.kind === "krieg") byParty.set(other, "krieg");
|
||||
else if (r.kind === "pakt" && r.status === "aktiv" && (!r.endsAt || r.endsAt.getTime() > atMs) && byParty.get(other) !== "krieg") {
|
||||
byParty.set(other, "pakt");
|
||||
}
|
||||
}
|
||||
const relationOf = (id: number): Relation => {
|
||||
const party = partyFor(id);
|
||||
return party === me ? "allianz" : byParty.get(party) ?? "neutral";
|
||||
};
|
||||
const out = new Map<number, Relation>();
|
||||
for (const m of members) out.set(m.playerId, relationOf(m.playerId));
|
||||
// Spieler ohne Allianz: nur die mit eigener Diplomatie, der Rest bleibt neutral.
|
||||
for (const party of byParty.keys()) {
|
||||
const p = parseParty(party);
|
||||
if (p.kind === "p") out.set(p.id, relationOf(p.id));
|
||||
}
|
||||
out.delete(viewerId);
|
||||
return out;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ import { modifierBreakdown, modsOf } from "./modifiers.ts";
|
||||
import { veteranView } from "./veterans.ts";
|
||||
import { withLuckFactors } from "./battle-stats.ts";
|
||||
import { researchView } from "./research.ts";
|
||||
import { diplomacyBlock } from "./alliance-core.ts";
|
||||
import { diplomacyBlock, relationsOf } from "./alliance-core.ts";
|
||||
import { intelView } from "./espionage.ts";
|
||||
import { gridView, missionWeather } from "./weather.ts";
|
||||
import { detectIncoming } from "./radar.ts";
|
||||
@@ -208,6 +208,8 @@ export async function mapView(engine: Engine, playerId: number) {
|
||||
.innerJoin(tables.player, eq(tables.player.id, tables.base.playerId));
|
||||
const nests = await engine.db.select().from(tables.nest);
|
||||
const wrecks = await engine.db.select().from(tables.wreck);
|
||||
// Freund/Feind aus Sicht des Betrachters (nur eigene Allianz, eigene Pakte und Kriege).
|
||||
const relations = await relationsOf(engine.db, playerId, nowMs);
|
||||
return {
|
||||
serverNow: nowMs,
|
||||
bases: bases.map((b) => ({
|
||||
@@ -217,6 +219,7 @@ export async function mapView(engine: Engine, playerId: number) {
|
||||
row: b.row,
|
||||
owner: b.owner,
|
||||
own: b.playerId === playerId,
|
||||
relation: b.playerId === playerId ? ("own" as const) : relations.get(b.playerId) ?? ("neutral" as const),
|
||||
protection: protectionStatus((b.state as BaseState).protection, nowMs, balance).reason,
|
||||
})),
|
||||
nests: nests.map((n) => ({
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
launchMission,
|
||||
leaveAlliance,
|
||||
makePeace,
|
||||
mapView,
|
||||
missionPreview,
|
||||
playerTradeStats,
|
||||
offersView,
|
||||
@@ -282,6 +283,31 @@ test("Krieg mit 12 h Vorlauf; im Krieg entfällt die Schwachziel-Kürzung", asyn
|
||||
assert.equal(await atWar(db, E.playerId, F.playerId, Date.now() + 2 * WAR_LEAD_MS), false);
|
||||
});
|
||||
|
||||
test("Kartenansicht: Freund/Feind aus Sicht des Betrachters (Allianz, Pakt, Krieg, neutral)", async () => {
|
||||
const ally = `a:${allianceId}`;
|
||||
const rows = await db.insert(tables.diplomacy).values([
|
||||
{ partyA: ally, partyB: `p:${E.playerId}`, kind: "pakt", status: "aktiv", proposedBy: ally },
|
||||
{ partyA: ally, partyB: `p:${F.playerId}`, kind: "krieg", status: "aktiv", proposedBy: ally, activeFrom: new Date(Date.now() + WAR_LEAD_MS) },
|
||||
// Nur angeboten: zählt nicht als Pakt.
|
||||
{ partyA: ally, partyB: `p:${D.playerId}`, kind: "pakt", status: "angeboten", proposedBy: ally },
|
||||
]).returning({ id: tables.diplomacy.id });
|
||||
const rel = async (viewer: P) =>
|
||||
Object.fromEntries((await mapView(engine, viewer.playerId)).bases.map((b) => [b.id, b.relation]));
|
||||
const a = await rel(A);
|
||||
assert.equal(a[A.baseId], "own");
|
||||
assert.equal(a[B.baseId], "allianz");
|
||||
assert.equal(a[C.baseId], "allianz");
|
||||
assert.equal(a[D.baseId], "neutral");
|
||||
assert.equal(a[E.baseId], "pakt");
|
||||
assert.equal(a[F.baseId], "krieg", "erklärter Krieg zählt schon im Vorlauf");
|
||||
// Gegenseite sieht die ganze Allianz; Dritte sehen nur ihre eigenen Verträge.
|
||||
const f = await rel(F);
|
||||
assert.deepEqual([f[A.baseId], f[B.baseId], f[C.baseId], f[E.baseId]], ["krieg", "krieg", "krieg", "neutral"]);
|
||||
const d = await rel(D);
|
||||
assert.deepEqual([d[A.baseId], d[E.baseId], d[F.baseId]], ["neutral", "neutral", "neutral"]);
|
||||
for (const r of rows) await db.delete(tables.diplomacy).where(eq(tables.diplomacy.id, r.id));
|
||||
});
|
||||
|
||||
test("Handel: Treuhand, Annahme, Lieferung mit Reisezeit, Rückzug, Prüflauf ok", async () => {
|
||||
const stahl0 = (await stateOf(E.baseId)).resources.stahl;
|
||||
const o = await createOffer(engine, E.playerId, key(), { give: "stahl", giveQty: 1000, want: "elektronik", wantQty: 200, visibility: "public" });
|
||||
|
||||
Reference in new issue
Block a user