mirror of
https://github.com/db9979/tidefront.git
synced 2026-12-06 12:54:09 +01:00
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:
1 parent
b9421d5411
commit
f2df74ab98
2 files changed
+47
No files matched your search
@@ -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";
|
||||
|
||||
Reference in new issue
Block a user