War council: guards march to other towns, one fight, then home; main assault
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2b04db3b31
commit
a78274803b
5 changed files with 470 additions and 18 deletions
|
|
@ -775,7 +775,7 @@ function sidebar() {
|
|||
<div class="navhead">City</div>
|
||||
${nav("town", "🏘️", "Town square", `${S.city.population}`, "", `Population ${S.city.population}`)}
|
||||
${nav("council", "📜", "Council & threats", "", raid ? `<span class="alert"></span>` : "", raid ? "A threat is coming" : "")}
|
||||
${nav("kingdom", "🗺️", "Kingdom", `${S.kingdom.cities.length}`, S.kingdom.charter ? `<span class="badge">sign</span>` : "", S.kingdom.charter ? "A charter is waiting to be signed" : "")}
|
||||
${nav("kingdom", "🗺️", "Kingdom", `${S.kingdom.cities.length}`, S.kingdom.charter ? `<span class="badge">sign</span>` : votesWaiting() ? `<span class="badge">${votesWaiting()}</span>` : "", S.kingdom.charter ? "A charter is waiting to be signed" : votesWaiting() ? "The war council wants your vote" : "")}
|
||||
${nav("orders", ORDER_ICON(), "Work orders", "", takeable ? `<span class="badge">${takeable}</span>` : "", takeable ? `${takeable} for you` : "")}
|
||||
${nav("board", "💬", "Town board")}
|
||||
${rosterNav()}
|
||||
|
|
@ -935,6 +935,43 @@ function pageHtml() {
|
|||
// --- kingdom ----------------------------------------------------------------
|
||||
let pouch = {};
|
||||
|
||||
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 warTable() {
|
||||
const k = S.kingdom, me = S.me;
|
||||
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>
|
||||
<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>`;
|
||||
};
|
||||
const march = (m) => {
|
||||
const target = k.cities.find((c) => c.id === m.to);
|
||||
const known = target?.threat && (target.threat.exact || target.threat.latest);
|
||||
const late = m.status === "marching" && known && m.arrive > known;
|
||||
const text = { marching: `🛤️ ${dur(Math.max(0, m.arrive - S.now))}`, there: `🛡️ +${fmt(m.power)}`, returning: `🏠 ${dur(Math.max(0, m.arrive - S.now))}` }[m.status];
|
||||
return `<div class="council-row small"><span>💂 ${fmt(m.guards)} · ${esc(townName(m.from))} → ${esc(townName(m.to))}</span><span>${text}${late ? ` <span class="tag warn">Late</span>` : ""}</span><span></span></div>`;
|
||||
};
|
||||
const options = (key) => k.cities.map((c) => `<option value="${esc(c.id)}">${esc(c.name)}</option>`).join("");
|
||||
return `<div class="panel" style="margin-top:14px"><h2>War council</h2>
|
||||
${k.council.map(proposal).join("")}
|
||||
${k.marches.map(march).join("")}
|
||||
<div class="pouch-row"><select data-keep="march-from">${options()}</select> → <select data-keep="march-to">${options()}</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>
|
||||
<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>`;
|
||||
}
|
||||
|
||||
function regionPerks(region, scale) {
|
||||
const y = S.kingdom.region_yield;
|
||||
return `${region.skills.map((id) => skillOf(id).icon).join("")} +${pct(y[0] * scale)} → +${pct(y.at(-1) * scale)}`;
|
||||
|
|
@ -952,7 +989,9 @@ 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>
|
||||
<p class="small">${esc(c.tier)} · 👥 ${fmt(c.population)} · 🏆 ${fmt(c.repelled)}${road ? ` · 🛤️ ${road}` : ""}</p>
|
||||
${threatLine(c.threat)}
|
||||
<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>
|
||||
${here || me.travel ? "" : `<button class="btn primary" data-travel="${esc(c.id)}">🛤️ Travel (${dur(C.travel_time / S.city_speed)})</button>`}
|
||||
|
|
@ -984,7 +1023,8 @@ function kingdom() {
|
|||
<div class="grid" style="margin-top:14px">
|
||||
<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>`;
|
||||
</div>
|
||||
${k.cities.length > 1 ? warTable() : ""}`;
|
||||
}
|
||||
|
||||
// Where an item comes from: the recipe that makes it, else what finds it, else the fight that drops it.
|
||||
|
|
@ -2505,7 +2545,7 @@ function foodKinds(r) {
|
|||
function armoury(d) {
|
||||
const slots = { weapon: "Weapons", shield: "Shields", jerkin: "Body armour", salve: "Salves" };
|
||||
return Object.entries(slots).map(([slot, label]) => {
|
||||
const issued = d.kit[slot] || [], bare = d.posts - issued.reduce((n, [, q]) => n + q, 0);
|
||||
const issued = d.kit[slot] || [], bare = d.posts - d.away - issued.reduce((n, [, q]) => n + q, 0);
|
||||
let seat = 0;
|
||||
const chips = [...issued, ...(bare > 0 ? [[null, bare]] : [])].flatMap(([id, qty]) => {
|
||||
const paid = Math.max(0, Math.min(qty, d.guards - seat));
|
||||
|
|
@ -2521,14 +2561,14 @@ function armoury(d) {
|
|||
|
||||
function raidPrep(ev) {
|
||||
const city = S.city, me = S.me, d = city.defence;
|
||||
const names = { mercenaries: "Hired sellswords", ward: "Divine ward (temple)", rallied: "Rallied militia (favour)", drilled: "Drilled militia", townsfolk: "Townsfolk with pitchforks", walls: "Walls", militia: "Paid guards (barracks)", weapons: "Weapons the guards hold", shields: "Shields the guards hold", jerkins: "Body armour the guards wear", salves: "Salves", arrows: "Arrows", garrison: "Garrison" };
|
||||
const full = d.posts * d.wage, owed = Math.max(0, full - d.wages);
|
||||
const names = { mercenaries: "Hired sellswords", ward: "Divine ward (temple)", rallied: "Rallied militia (favour)", drilled: "Drilled militia", townsfolk: "Townsfolk with pitchforks", walls: "Walls", militia: "Paid guards (barracks)", weapons: "Weapons the guards hold", shields: "Shields the guards hold", jerkins: "Body armour the guards wear", salves: "Salves", arrows: "Arrows", garrison: "Garrison", reinforcements: "Reinforcements" };
|
||||
const full = (d.posts - d.away) * d.wage, owed = Math.max(0, full - d.wages);
|
||||
const reqs = (ev.requests || []).map(reqRow).join("");
|
||||
return `<div class="cols">
|
||||
<div class="panel"><h2>Raid readiness</h2>${reqs}
|
||||
<p class="small muted">Stockpile gear arms the defenders, best first. Fights use up arrows and break some gear.</p>
|
||||
<h2 style="margin-top:16px">Armoury</h2>${armoury(d)}</div>
|
||||
<div class="panel"><h2>Guards · ${d.guards} / ${d.posts} paid</h2>
|
||||
<div class="panel"><h2>Guards · ${d.guards} / ${d.posts - d.away} paid${d.away ? ` · 🛤️ ${d.away} away` : ""}${d.helping.length ? ` · +${d.helping.reduce((n, h) => n + h.guards, 0)} here` : ""}</h2>
|
||||
<p class="small">Wage chest ${COIN} ${fmt(d.wages)} / ${fmt(full)} · ${d.wage} gold a guard per threat</p>
|
||||
<div class="bar"><span style="width:${full ? Math.min(100, d.wages / full * 100) : 0}%"></span></div>
|
||||
<div class="btns" style="margin-top:8px">
|
||||
|
|
@ -3345,6 +3385,10 @@ 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 ("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) });
|
||||
}
|
||||
if (d.vote) return act("/api/council/vote", { id: Number(d.vote), yes: d.yes === "1" });
|
||||
if (d.travel) {
|
||||
if (!confirm(`Travel to ${townName(d.travel)}? Work stops on the road.`)) return;
|
||||
const sent = pouch;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue