Lage: Felderträge je Feld gebündelt (eine Zeile unter Unterwegs, nur die nächste Lieferung unter Als Nächstes)

This commit is contained in:
db9979 committed 2026-11-29 08:34:51 +01:00
1 parent b9421d5411
commit f2df74ab98
2 files changed
+47

No files matched your search

+28
View File
@@ -182,8 +182,36 @@ async function convoyRows(db: DbOrTx, playerId: number, bases: BaseRow[], nowMs:
const rows = await db.select().from(t).where(and(eq(t.status, "underway"), gt(t.arriveAt, new Date(nowMs)), or(eq(t.recipientId, playerId), eq(t.senderId, playerId))));
const others = [...new Set(rows.flatMap((c) => [c.senderId, c.recipientId]).filter((x): x is number => x !== null && x !== playerId))];
const names = new Map(others.length === 0 ? [] : (await db.select({ id: tables.player.id, name: tables.player.name }).from(tables.player).where(inArray(tables.player.id, others))).map((p) => [p.id, p.name]));
// Felderträge je Feld bündeln: Ein besetztes Feld schickt laufend Lieferungen, einzeln würden sie die Lage fluten.
// „Unterwegs“ zeigt eine Zeile je Feld (Summe, Anzahl, nächste Ankunft), „Als Nächstes“ nur die nächste Lieferung.
const fieldGroups = new Map<string, typeof rows>();
for (const c of rows) {
if (c.kind !== "feld" || c.recipientId !== playerId) continue;
const k = `${c.fromCol}:${c.fromRow}:${c.recipientBaseId ?? ""}`;
fieldGroups.set(k, [...(fieldGroups.get(k) ?? []), c]);
}
for (const [k, list] of fieldGroups) {
list.sort((a, b) => a.arriveAt.getTime() - b.arriveAt.getTime());
const next = list[0];
const total: Record<string, number> = {};
for (const c of list) for (const [r, v] of Object.entries(c.cargo as ResourceMap)) total[r] = (total[r] ?? 0) + (Number(v) || 0);
const at = next.arriveAt.getTime();
const field = `Rohstofffeld ${next.fromCol}/${next.fromRow}`;
const icon = Object.keys(next.cargo as ResourceMap)[0] ?? "konvoi";
const jump = { to: "map" as const, col: next.toCol, row: next.toRow, baseId: next.recipientBaseId, convoyId: next.id };
const harbor = harborSub(bases, next.recipientBaseId);
soon.push(row({ key: `konvoi:${next.id}`, kind: "konvoi", atMs: at, icon, text: `Feldertrag trifft ein: ${amounts(next.cargo as ResourceMap)}`, sub: [`von ${field}`, harbor].filter(Boolean).join(" · "), jump }));
const more = list.length > 1 ? `${list.length} Lieferungen unterwegs, zusammen ${amounts(total as ResourceMap)}` : null;
underway.push(row({
key: `feld-weg:${k}`, kind: "konvoi", atMs: at, icon: "konvoi",
text: `Feldertrag: ${amounts(next.cargo as ResourceMap)}`,
sub: [`von ${field}`, more, harbor].filter(Boolean).join(" · "),
progress: { fromMs: next.departAt.getTime(), toMs: at }, jump,
}));
}
for (const c of rows) {
if (c.kind === "transport") continue;
if (c.kind === "feld" && c.recipientId === playerId) continue; // oben je Feld gebündelt
const incoming = c.recipientId === playerId;
const cargo = amounts(c.cargo as ResourceMap);
const label = CONVOY_TEXT[c.kind] ?? "Konvoi";
+19
View File
@@ -104,6 +104,25 @@ test("Feldertrag nennt das Rohstofffeld als Herkunft, nicht einen Handelshafen",
assert.doesNotMatch(r.sub ?? "", /Handelshafen/);
});
test("Felderträge desselben Felds stehen gebündelt: eine Zeile unter Unterwegs, nur die nächste unter Als Nächstes", async () => {
const a = await newPlayer("Feldbuendel", coastByPort(150, 600));
const ids: number[] = [];
for (let i = 0; i < 3; i++) {
const d = await buyStahl(a.playerId, 100 + i * 50);
await db.update(tables.convoy).set({ kind: "feld", fromCol: 21, fromRow: 30, arriveAt: new Date(Date.now() + (i + 1) * 3_600_000) }).where(eq(tables.convoy.deliveryId, d.id));
const [cv] = await db.select({ id: tables.convoy.id }).from(tables.convoy).where(eq(tables.convoy.deliveryId, d.id));
ids.push(cv.id);
}
const v = await lageView(engine, a.playerId);
const ways = v.underway.filter((r) => r.key.startsWith("feld-weg:"));
assert.equal(ways.length, 1, "eine Zeile je Feld");
assert.match(ways[0].sub ?? "", /^von Rohstofffeld 21\/30 · 3 Lieferungen unterwegs, zusammen 450 Stahl/);
assert.match(ways[0].text, /^Feldertrag: 100 Stahl/, "nächste Lieferung zuerst");
const soonField = v.soon.filter((r) => /^Feldertrag trifft ein/.test(r.text));
assert.deepEqual(soonField.map((r) => r.key), [`konvoi:${ids[0]}`], "nur die nächste Lieferung");
assert.equal(v.underway.some((r) => ids.some((id) => r.key === `konvoi-weg:${id}`)), false);
});
test("lage.get bündelt Angriff, Bau, Ausbildung, Mission, Konvoi, Vertrag; brief zählt nur Dringendes", async () => {
const a = await newPlayer("Lagechef", coastByPort(150, 600));
const foe = await newPlayer("Angreifer", coastByPort(150, 1200));