feat: rally point, troop movements, support, reports, scouts, battle simulator and village rename
Send attacks and support from the rally point with a live travel-time preview, see own
commands and spotted incoming attacks with countdowns and call-back, send support home
or withdraw it, read battle and support reports with an unread badge, run the battle
simulator, rename villages, and send troops straight from the map. The watchtower gets
a diorama model; the mock server answers every new intent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 23:16:06 +00:00
|
|
|
import type { BattleSide, BuildingType, Report, UnitType, VillageRef } from '~/types/game'
|
|
|
|
|
import { BUILDING_COLORS } from './palette'
|
|
|
|
|
|
|
|
|
|
/** Units in the order Die Stämme lists them, grouped like its rally point. */
|
|
|
|
|
export const UNIT_GROUPS: { name: 'infantry' | 'cavalry' | 'siege' | 'other'; units: UnitType[] }[] = [
|
|
|
|
|
{ name: 'infantry', units: ['spear', 'sword', 'archer'] },
|
|
|
|
|
{ name: 'cavalry', units: ['scout', 'light_cavalry', 'heavy_cavalry'] },
|
|
|
|
|
{ name: 'siege', units: ['ram', 'catapult'] },
|
|
|
|
|
{ name: 'other', units: ['nobleman'] },
|
|
|
|
|
]
|
|
|
|
|
export const UNIT_ORDER: UnitType[] = UNIT_GROUPS.flatMap((g) => g.units)
|
|
|
|
|
|
|
|
|
|
/** Every building type, in building order: what catapults can aim at. */
|
|
|
|
|
export const BUILDING_TYPES = Object.keys(BUILDING_COLORS) as BuildingType[]
|
|
|
|
|
|
2026-10-29 00:57:00 +00:00
|
|
|
/** "Name (12|-34)" */
|
feat: rally point, troop movements, support, reports, scouts, battle simulator and village rename
Send attacks and support from the rally point with a live travel-time preview, see own
commands and spotted incoming attacks with countdowns and call-back, send support home
or withdraw it, read battle and support reports with an unread badge, run the battle
simulator, rename villages, and send troops straight from the map. The watchtower gets
a diorama model; the mock server answers every new intent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 23:16:06 +00:00
|
|
|
export const villageLabel = (v: VillageRef) => `${v.name} (${v.x}|${v.y})`
|
|
|
|
|
|
2026-10-29 00:57:00 +00:00
|
|
|
/** "12|-34", "12 -34" or "12,-34" → coordinates; the world starts at 0|0, so they can be negative. */
|
feat: rally point, troop movements, support, reports, scouts, battle simulator and village rename
Send attacks and support from the rally point with a live travel-time preview, see own
commands and spotted incoming attacks with countdowns and call-back, send support home
or withdraw it, read battle and support reports with an unread badge, run the battle
simulator, rename villages, and send troops straight from the map. The watchtower gets
a diorama model; the mock server answers every new intent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 23:16:06 +00:00
|
|
|
export function parseCoords(text: string): { x: number; y: number } | null {
|
2026-10-29 00:57:00 +00:00
|
|
|
const m = /^\s*(-?\d{1,4})\s*[|,;\s]\s*(-?\d{1,4})\s*$/.exec(text)
|
feat: rally point, troop movements, support, reports, scouts, battle simulator and village rename
Send attacks and support from the rally point with a live travel-time preview, see own
commands and spotted incoming attacks with countdowns and call-back, send support home
or withdraw it, read battle and support reports with an unread badge, run the battle
simulator, rename villages, and send troops straight from the map. The watchtower gets
a diorama model; the mock server answers every new intent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 23:16:06 +00:00
|
|
|
return m ? { x: Number(m[1]), y: Number(m[2]) } : null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Unit counts above zero, in unit order, with `militia` last. */
|
|
|
|
|
export function unitRows(units: Partial<Record<string, number>> | null | undefined): [string, number][] {
|
|
|
|
|
if (!units) return []
|
|
|
|
|
const order = [...UNIT_ORDER, 'militia'] as string[]
|
|
|
|
|
return Object.entries(units)
|
|
|
|
|
.filter((e): e is [string, number] => (e[1] ?? 0) > 0)
|
|
|
|
|
.sort(([a], [b]) => order.indexOf(a) - order.indexOf(b))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const lost = (side: BattleSide) => Object.values(side.lost ?? {}).reduce((a, b) => a + b, 0)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The dot colour of a report, as in Die Stämme: green for a win without losses, yellow
|
|
|
|
|
* for a win with losses, red for a loss, blue for support.
|
|
|
|
|
*/
|
|
|
|
|
export function reportTone(r: Report): 'won' | 'losses' | 'lost' | 'info' {
|
|
|
|
|
if (r.type === 'support') return 'info'
|
|
|
|
|
const p = r.payload
|
2026-10-29 15:17:00 +00:00
|
|
|
if ('scattered' in p) return 'won'
|
feat: rally point, troop movements, support, reports, scouts, battle simulator and village rename
Send attacks and support from the rally point with a live travel-time preview, see own
commands and spotted incoming attacks with countdowns and call-back, send support home
or withdraw it, read battle and support reports with an unread badge, run the battle
simulator, rename villages, and send troops straight from the map. The watchtower gets
a diorama model; the mock server answers every new intent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 23:16:06 +00:00
|
|
|
const ownSide = r.type === 'attack' ? p.attacker : p.defender
|
|
|
|
|
const won = r.type === 'attack' ? p.won : !p.won
|
|
|
|
|
if (!won) return 'lost'
|
|
|
|
|
return lost(ownSide) > 0 ? 'losses' : 'won'
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-29 15:17:00 +00:00
|
|
|
/** A report's subject line: who attacked or supported whom, raiders by name. */
|
|
|
|
|
export function reportSubject(r: Report, t: (key: string, values?: Record<string, unknown>) => string) {
|
|
|
|
|
if (r.type === 'support') return t('reports.title_support', { from: villageLabel(r.payload.from), to: villageLabel(r.payload.to) })
|
|
|
|
|
const p = r.payload
|
|
|
|
|
if ('scattered' in p) return t('reports.title_scattered', { from: villageLabel(p.attacker.village) })
|
|
|
|
|
return t(p.raid ? 'reports.title_raid' : 'reports.title_attack', { from: villageLabel(p.attacker.village), to: villageLabel(p.defender.village) })
|
|
|
|
|
}
|
|
|
|
|
|
feat: rally point, troop movements, support, reports, scouts, battle simulator and village rename
Send attacks and support from the rally point with a live travel-time preview, see own
commands and spotted incoming attacks with countdowns and call-back, send support home
or withdraw it, read battle and support reports with an unread badge, run the battle
simulator, rename villages, and send troops straight from the map. The watchtower gets
a diorama model; the mock server answers every new intent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 23:16:06 +00:00
|
|
|
/** "Today 13:30:05", "Tomorrow 08:00:00" or "31.10. 13:30:05" in the player's clock. */
|
|
|
|
|
export function formatArrival(ms: number, now: number, t: (key: string, values?: Record<string, unknown>) => string) {
|
|
|
|
|
const at = new Date(ms)
|
|
|
|
|
const time = at.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false })
|
|
|
|
|
const day = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime()
|
|
|
|
|
const days = Math.round((day(at) - day(new Date(now))) / 86_400_000)
|
|
|
|
|
if (days === 0) return t('time.today', { time })
|
|
|
|
|
if (days === 1) return t('time.tomorrow', { time })
|
|
|
|
|
if (days === -1) return t('time.yesterday', { time })
|
|
|
|
|
return t('time.on', { date: at.toLocaleDateString(undefined, { day: '2-digit', month: '2-digit' }), time })
|
|
|
|
|
}
|