Caravans: crewed wagons, town stock by vote, roads, ambushes; war table shows all scouted threats and march impact
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a4c9977e5c
commit
3486897630
6 changed files with 724 additions and 24 deletions
118
static/app.js
118
static/app.js
|
|
@ -934,15 +934,81 @@ function pageHtml() {
|
|||
|
||||
// --- kingdom ----------------------------------------------------------------
|
||||
let pouch = {};
|
||||
let cargo = {};
|
||||
const cargoFreight = new Set();
|
||||
|
||||
function votesWaiting() {
|
||||
return S.kingdom.council.filter((p) => p.status === "open" && !p.yes.includes(S.uid) && !p.no.includes(S.uid)).length;
|
||||
}
|
||||
|
||||
function threatLine(t) {
|
||||
if (!t) return `<p class="small muted">No threat rumoured</p>`;
|
||||
const size = t.strength ? fmt(t.strength) : t.range ? `${fmt(t.range[0])} - ${fmt(t.range[1])}` : t.size || "?";
|
||||
return `<p class="small">${eventIcon(t.kind)} ${eventWhen(t, true)} · ${esc(String(size))}${t.main ? ` <span class="tag warn" title="The bandits' main assault">Main assault</span>` : ""}</p>`;
|
||||
function threatSize(t) {
|
||||
return t?.strength ? fmt(t.strength) : t?.range ? `${fmt(t.range[0])} - ${fmt(t.range[1])}` : t?.size || "?";
|
||||
}
|
||||
|
||||
function threatLine(t, problems) {
|
||||
const trouble = problems.length ? `<p class="small">${problems.map((p) => `${p.icon} ${esc(p.name)}`).join(" · ")}</p>` : "";
|
||||
if (!t) return `<p class="small muted">No threat rumoured</p>${trouble}`;
|
||||
const pips = [1, 2, 3].map((n) => n <= t.intel ? "●" : "○").join("");
|
||||
return `<p class="small" title="${esc(t.headline)}">${eventIcon(t.kind)} <span title="Intel ${t.intel} / 3">${pips}</span> ${eventWhen(t, true)} · ${esc(String(threatSize(t)))}${t.main ? ` <span class="tag warn" title="The bandits' main assault">Main assault</span>` : ""}</p>
|
||||
${t.group || t.trait || t.sabotage ? `<p class="small muted">${[t.group && upperFirst(t.group), t.trait, t.sabotage && `-${t.sabotage}%`].filter(Boolean).map((x) => esc(String(x))).join(" · ")}</p>` : ""}${trouble}`;
|
||||
}
|
||||
|
||||
const upperFirst = (s) => s[0].toUpperCase() + s.slice(1);
|
||||
|
||||
// How a town's defence stands up to what its scouts know: ✅ holds, ⚠️ too close to call, ❌ falls, ❓ unknown.
|
||||
function holds(defence, t) {
|
||||
if (!t || !(t.strength || t.range)) return "❓";
|
||||
const low = t.strength || t.range[0], high = t.strength || t.range[1];
|
||||
return defence >= high ? "✅" : defence < low ? "❌" : "⚠️";
|
||||
}
|
||||
|
||||
// What a march does to both towns: defence now → after, against each town's threat as scouted.
|
||||
function marchImpact(source, target, guards) {
|
||||
const k = S.kingdom, from = k.cities.find((c) => c.id === source), to = k.cities.find((c) => c.id === target);
|
||||
if (!from || !to || source === target) return "";
|
||||
const n = Math.max(0, Math.min(guards || 0, from.curve.length - 1)), power = from.curve[n];
|
||||
const incoming = k.marches.filter((m) => m.to === to.id && m.status === "marching").reduce((sum, m) => sum + m.power, 0);
|
||||
const row = (c, now, after) => `<span>${esc(c.name)} 🛡️ ${fmt(now)} → <b>${fmt(after)}</b> vs ${c.threat ? eventIcon(c.threat.kind) : ""} ${esc(String(threatSize(c.threat)))} ${holds(after, c.threat)}</span>`;
|
||||
return `<div class="impact small">${row(from, from.defence, from.defence - power)}${row(to, to.defence + incoming, to.defence + incoming + power)}</div>`;
|
||||
}
|
||||
|
||||
function convoyPanel() {
|
||||
const k = S.kingdom, me = S.me, here = me.at;
|
||||
const others = k.cities.filter((c) => c.id !== here);
|
||||
const mine = k.caravans.find((c) => c.crew.includes(S.uid));
|
||||
const list = (items) => Object.entries(items || {}).map(([id, qty]) => itemChip(id, qty, undefined, false)).join(" ");
|
||||
const row = (c) => {
|
||||
const lead = c.leader === S.uid, aboard = c.crew.includes(S.uid), loading = c.status === "loading";
|
||||
const state = loading ? `📦 ${fmt(c.load)} / ${fmt(c.room)}` : `🛤️ ${dur(Math.max(0, c.arrive - S.now))}${c.ambush ? ` · ${c.ambush === "won" ? "⚔️ Beat an ambush" : "💀 Robbed"}` : ""}`;
|
||||
const buttons = !loading || me.travel ? "" : lead
|
||||
? `<button class="btn sm primary" data-caravan-depart="${c.id}">🛤️ Set off</button> <button class="btn sm" data-caravan-cancel="${c.id}">✖</button>`
|
||||
: c.from === here && !mine ? `<button class="btn sm" data-caravan-join="${c.id}">Join</button>` : "";
|
||||
return `<div class="council-row small"><span>🐎 ${esc(townName(c.from))} → ${esc(townName(c.to))} · ${c.crew.map((uid) => esc(playerName(uid))).join(", ")}</span><span>${state}</span><span>${buttons}</span></div>
|
||||
${aboard && (c.mine || Object.keys(c.freight).length) ? `<p class="small">${list(c.mine)} ${list(c.freight)}</p>` : ""}`;
|
||||
};
|
||||
const waiting = k.freight.map((f) => `<div class="council-row small"><span>📦 ${list(f.items)} ${esc(townName(f.from))} → ${esc(townName(f.to))}</span><span>${f.from === here && !me.travel ? `<button class="btn sm ${cargoFreight.has(f.id) ? "primary" : ""}" data-cargo-freight="${f.id}">${cargoFreight.has(f.id) ? "✓ Taking" : "Take"}</button>` : ""}</span><span></span></div>`).join("");
|
||||
const bank = Object.keys(me.bank).filter((id) => !cargo[id]).sort((a, b) => item(a).name.localeCompare(item(b).name));
|
||||
const stock = Object.keys(S.city.stockpile).sort((a, b) => item(a).name.localeCompare(item(b).name));
|
||||
const towns = others.map((c) => `<option value="${esc(c.id)}">${esc(c.name)}</option>`).join("");
|
||||
const chosen = others.find((c) => c.id === $("[data-keep=caravan-to]")?.value) || others[0];
|
||||
const route = chosen?.route;
|
||||
const forming = me.travel ? "" : `
|
||||
<h2 style="margin-top:16px">${mine && mine.status === "loading" ? "Load more" : "Load a caravan"}</h2>
|
||||
<p class="small">${Object.entries(cargo).map(([id, qty]) => `<button class="btn sm" data-cargo-drop="${id}" title="Take out">${itemChip(id, qty, undefined, false)} ✖</button>`).join(" ") || `<span class="muted">Your bank goods, none yet</span>`}</p>
|
||||
<div class="pouch-row"><select data-keep="cargo-item-${Object.keys(cargo).length}">${bank.map((id) => `<option value="${id}">${esc(item(id).name)} (${fmt(me.bank[id])})</option>`).join("")}</select>
|
||||
<input type="number" min="1" value="100" data-keep="cargo-qty" style="width:90px"><button class="btn sm" data-cargo-add ${bank.length ? "" : "disabled"}>+</button></div>
|
||||
${mine && mine.status === "loading" ? `<div class="pouch-row"><button class="btn primary" data-caravan-load="${mine.id}">📦 Load</button></div>`
|
||||
: `<div class="pouch-row"><select data-keep="caravan-to">${towns}</select><button class="btn primary" data-caravan-form>🐎 Form caravan</button></div>
|
||||
${route ? `<p class="small muted">⏱ ${dur(route.time)} · 📦 ${fmt(route.load)} per crew · ⚔️ up to ${Math.round(route.odds * 100)}% ambush · 🛤️ ${route.level}</p>` : ""}`}
|
||||
<h2 style="margin-top:16px">Send town stock</h2>
|
||||
<div class="pouch-row"><select data-keep="freight-item">${stock.map((id) => `<option value="${id}">${esc(item(id).name)} (${fmt(S.city.stockpile[id])})</option>`).join("")}</select>
|
||||
<input type="number" min="1" value="100" data-keep="freight-qty" style="width:90px"><select data-keep="freight-to">${towns}</select>
|
||||
<button class="btn" data-freight-propose>📜 Propose</button></div>`;
|
||||
return `<div class="panel" style="margin-top:14px"><h2>Caravans</h2>
|
||||
${k.caravans.map(row).join("")}${waiting}
|
||||
${k.caravans.length || k.freight.length ? "" : `<p class="small muted">None on the road</p>`}
|
||||
${forming}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function warTable() {
|
||||
|
|
@ -950,9 +1016,11 @@ function warTable() {
|
|||
const proposal = (p) => {
|
||||
const open = p.status === "open", mine = p.yes.includes(S.uid) ? "yes" : p.no.includes(S.uid) ? "no" : null;
|
||||
const result = { sent: "🛤️ Sent", rejected: "Kept home", failed: "No guards" }[p.status];
|
||||
return `<div class="council-row small"><span>💂 ${fmt(p.guards)} · ${esc(townName(p.from))} → ${esc(townName(p.to))} · ${esc(playerName(p.by))}</span>
|
||||
const freight = p.items ? Object.entries(p.items).map(([id, qty]) => itemChip(id, qty, undefined, false)).join(" ") : null;
|
||||
return `<div class="council-row small"><span>${freight ? `📦 ${freight}` : `💂 ${fmt(p.guards)}`} · ${esc(townName(p.from))} → ${esc(townName(p.to))} · ${esc(playerName(p.by))}</span>
|
||||
<span>✅ ${p.yes.length} ❌ ${p.no.length}${open ? ` · ⏳ ${dur(Math.max(0, p.ends - S.now))}` : ` · ${result}`}</span>
|
||||
${open ? `<span><button class="btn sm ${mine === "yes" ? "primary" : ""}" data-vote="${p.id}" data-yes="1">✅</button> <button class="btn sm ${mine === "no" ? "primary" : ""}" data-vote="${p.id}" data-yes="0">❌</button></span>` : "<span></span>"}</div>`;
|
||||
${open ? `<span><button class="btn sm ${mine === "yes" ? "primary" : ""}" data-vote="${p.id}" data-yes="1">✅</button> <button class="btn sm ${mine === "no" ? "primary" : ""}" data-vote="${p.id}" data-yes="0">❌</button></span>` : "<span></span>"}</div>
|
||||
${open && !p.items ? marchImpact(p.from, p.to, p.guards) : ""}`;
|
||||
};
|
||||
const march = (m) => {
|
||||
const target = k.cities.find((c) => c.id === m.to);
|
||||
|
|
@ -969,6 +1037,7 @@ function warTable() {
|
|||
<div class="pouch-row"><select data-keep="march-from">${options(home)}</select> → <select data-keep="march-to">${options(other)}</select>
|
||||
<input type="number" min="1" value="10" data-keep="march-guards" style="width:80px" title="Guards">
|
||||
<button class="btn primary" data-march-propose>📜 Propose</button></div>
|
||||
${marchImpact($("[data-keep=march-from]")?.value || home, $("[data-keep=march-to]")?.value || other, Number($("[data-keep=march-guards]")?.value ?? 10))}
|
||||
<p class="small muted">🛤️ ${dur(C.march_time / S.city_speed)} · vote ${dur(C.vote_time / S.city_speed)} · one fight, then home</p>
|
||||
</div>`;
|
||||
}
|
||||
|
|
@ -990,8 +1059,8 @@ function kingdom() {
|
|||
const region = k.regions[c.region];
|
||||
return `<div class="panel">
|
||||
<h2>${esc(c.name)} ${here ? `<span class="tag">📍 Here</span>` : ""}</h2>
|
||||
<p class="small">${esc(c.tier)} · 👥 ${fmt(c.population)} · 🏆 ${fmt(c.repelled)}${road ? ` · 🛤️ ${road}` : ""}</p>
|
||||
${threatLine(c.threat)}
|
||||
<p class="small">${esc(c.tier)} · 👥 ${fmt(c.population)} · 🏆 ${fmt(c.repelled)}${road ? ` · 🚶 ${road}` : ""}${c.roads ? ` · 🛤️ ${c.roads}` : ""}</p>
|
||||
${threatLine(c.threat, c.problems)}
|
||||
<p class="small" title="Defence · guards paid and at their posts · away">🛡️ ${fmt(c.defence)} · 💂 ${fmt(c.guards)} / ${fmt(c.posts - c.away)}${c.away ? ` · 🛤️ ${fmt(c.away)}` : ""}${c.garrison.length ? ` · 🏰 ${c.garrison.map((uid) => esc(playerName(uid))).join(", ")}` : ""}</p>
|
||||
${region ? `<p class="small" title="More per trip, by material tier. Grows with the town.">${region.icon} ${esc(region.name)} · ${regionPerks(region, c.town_scale)}</p>` : ""}
|
||||
<p class="small">${c.people.length ? c.people.map((uid) => esc(playerName(uid))).join(", ") : `<span class="muted">Nobody here</span>`}</p>
|
||||
|
|
@ -1025,7 +1094,7 @@ function kingdom() {
|
|||
<div class="panel"><h2>${me.travel ? "On the road" : "Travel pouch"}</h2>${pack}</div>
|
||||
<div class="panel"><h2>Found a town</h2>${founding}</div>
|
||||
</div>
|
||||
${k.cities.length > 1 ? warTable() : ""}`;
|
||||
${k.cities.length > 1 ? warTable() + convoyPanel() : ""}`;
|
||||
}
|
||||
|
||||
// Where an item comes from: the recipe that makes it, else what finds it, else the fight that drops it.
|
||||
|
|
@ -3387,6 +3456,32 @@ document.addEventListener("click", (e) => {
|
|||
if (d.install) return act("/api/install", { fitting: d.install, source: d.source });
|
||||
if ("plot" in d) return act("/api/plot", { id: d.plot || null });
|
||||
if (d.garrison) return act("/api/garrison", { join: d.garrison === "1" });
|
||||
if ("cargoAdd" in d) {
|
||||
const id = $("[data-keep^=cargo-item]").value, qty = Math.min(Number($("[data-keep=cargo-qty]").value) || 0, S.me.bank[id] || 0);
|
||||
if (id && qty > 0) cargo[id] = qty;
|
||||
return render();
|
||||
}
|
||||
if (d.cargoDrop) { delete cargo[d.cargoDrop]; return render(); }
|
||||
if (d.cargoFreight) {
|
||||
const id = Number(d.cargoFreight);
|
||||
if (cargoFreight.has(id)) cargoFreight.delete(id); else cargoFreight.add(id);
|
||||
return render();
|
||||
}
|
||||
if ("caravanForm" in d || d.caravanJoin || d.caravanLoad) {
|
||||
const body = { goods: cargo, freight: [...cargoFreight] };
|
||||
cargo = {};
|
||||
cargoFreight.clear();
|
||||
if ("caravanForm" in d) return act("/api/caravan/form", { ...body, to: $("[data-keep=caravan-to]").value });
|
||||
return act("/api/caravan/board", { ...body, id: Number(d.caravanJoin || d.caravanLoad) });
|
||||
}
|
||||
if (d.caravanDepart) {
|
||||
if (!confirm("Set off? Everyone aboard stops work until it arrives.")) return;
|
||||
return act("/api/caravan/depart", { id: Number(d.caravanDepart) });
|
||||
}
|
||||
if (d.caravanCancel) return act("/api/caravan/cancel", { id: Number(d.caravanCancel) });
|
||||
if ("freightPropose" in d) {
|
||||
return act("/api/council/freight", { to: $("[data-keep=freight-to]").value, item: $("[data-keep=freight-item]").value, qty: Number($("[data-keep=freight-qty]").value) });
|
||||
}
|
||||
if ("marchPropose" in d) {
|
||||
return act("/api/council/propose", { from: $("[data-keep=march-from]").value, to: $("[data-keep=march-to]").value, guards: Number($("[data-keep=march-guards]").value) });
|
||||
}
|
||||
|
|
@ -3468,7 +3563,12 @@ function pickOrderItem(id) {
|
|||
draft.reward = draft.item && !draft.city ? item(draft.item).value * (draft.kind === "craft" ? draft.qty : 1) : 0;
|
||||
}
|
||||
|
||||
document.addEventListener("change", (e) => {
|
||||
if (e.target.matches?.("[data-keep^=march-], [data-keep=caravan-to]")) render();
|
||||
});
|
||||
|
||||
document.addEventListener("input", (e) => {
|
||||
if (e.target.matches?.("[data-keep=march-guards]")) render();
|
||||
if (e.target.dataset.keep !== "order-search" || !draft) return;
|
||||
draft.search = e.target.value;
|
||||
render();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue