feat: seasons: season box with crown forts, holder and countdown; crowns on the map and in its legend; ended worlds show their winner

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-29 16:34:42 +01:00
parent c6220b09e4
commit 21de40930a
15 changed files with 685 additions and 76 deletions

View File

@ -1,7 +1,7 @@
<script setup lang="ts">
export type MapRelation = 'own' | 'player' | 'barbarian'
const props = defineProps<{ tier: 1 | 2 | 3 | 4 | 5; relation: MapRelation }>()
const props = defineProps<{ tier: 1 | 2 | 3 | 4 | 5; relation: MapRelation; crown?: boolean }>()
// Low-poly settlements in a 100 × 100 box that grow with the village's points, like the
// five village sizes on the Die Stämme map: a hut, a hamlet, a village with a tower, a
@ -113,5 +113,15 @@ const pole = computed(() => {
</g>
<line :x1="pole.x" :y1="pole.y" :x2="pole.x" :y2="pole.y - 20" stroke="#4a3b2e" stroke-width="2" />
<polygon :points="pts(pole.x, pole.y - 20, pole.x + 15, pole.y - 15, pole.x, pole.y - 10)" :fill="flag" stroke="#2b2118" stroke-width="0.8" />
<!-- A crown fort of the season wears a gold crown over its flag. -->
<g v-if="crown">
<polygon
:points="pts(pole.x - 12, pole.y - 22, pole.x - 12, pole.y - 36, pole.x - 6, pole.y - 29, pole.x, pole.y - 40, pole.x + 6, pole.y - 29, pole.x + 12, pole.y - 36, pole.x + 12, pole.y - 22)"
fill="#d9b44a"
stroke="#6b4f16"
stroke-width="1.2"
/>
<rect :x="pole.x - 12" :y="pole.y - 26" width="24" height="4" fill="#a8842e" />
</g>
</g>
</template>

View File

@ -300,7 +300,7 @@ function onKey(e: KeyboardEvent) {
:transform="`translate(${f.x * field} ${f.y * field}) scale(${field / 100})`"
class="pointer-events-none"
>
<MapVillageMarker :tier="tier(f.village!.points)" :relation="relation(f.village!)" />
<MapVillageMarker :tier="tier(f.village!.points)" :relation="relation(f.village!)" :crown="f.village!.crown" />
</g>
<rect

View File

@ -16,6 +16,7 @@ const spaceShare = computed(() => props.village.space.used / props.village.space
const incoming = computed(() => props.village.movements.filter((m) => m.direction === 'in' && m.type === 'attack'))
const commands = computed(() => props.village.movements.filter((m) => m.direction !== 'in').length)
const spec = computed(() => props.village.specialisation)
const season = computed(() => props.village.season)
const roleSpace = computed(() => spec.value.roles.reduce((sum, r) => sum + (spec.value.space[r.role] ?? 0), 0))
const roleShare = (role: VillageRole) => (roleSpace.value ? Math.round((100 * (spec.value.space[role] ?? 0)) / roleSpace.value) : 0)
const bonuses = computed(() => Object.entries(spec.value.roles.find((r) => r.role === spec.value.role)?.bonuses ?? {}))
@ -93,6 +94,34 @@ function order(o: BuildOrder) {
</dl>
</section>
<section class="side-box">
<h2 class="panel-head panel-title">{{ $t('village.season.title') }}</h2>
<div class="side-body">
<template v-if="season.winner">
<p class="font-semibold">{{ $t('village.season.won', { player: season.winner.name }) }}</p>
<div class="side-actions">
<NuxtLink to="/worlds" class="btn btn-outline">{{ $t('village.season.next') }}</NuxtLink>
</div>
</template>
<p v-else-if="!season.crowns.length">{{ $t('village.season.crowns_in', { time: formatSpan(secondsUntil(season.crowns_at), t) }) }}</p>
<template v-else>
<ul>
<li v-for="c in season.crowns" :key="c.id" class="flex items-center gap-2">
<NuxtLink :to="{ path: `/map/${village.world_id}`, query: { x: c.x, y: c.y } }" class="tabular-nums hover:underline">({{ c.x }}|{{ c.y }})</NuxtLink>
<span class="min-w-0 flex-1 truncate text-right">{{ c.player?.name ?? $t('village.season.barbarians') }}</span>
</li>
</ul>
<p v-if="season.holder && season.ends_at" class="font-semibold">
{{ $t('village.season.holds', { player: season.holder.name, time: formatSpan(secondsUntil(season.ends_at), t) }) }}
</p>
<p v-else>{{ $t('village.season.nobody', { needed: season.needed }) }}</p>
</template>
<p v-if="!season.winner" class="text-xs text-ink-500">
{{ $t('village.season.rule', { needed: season.needed, count: season.count, time: formatSpan(season.hold_seconds, t) }) }}
</p>
</div>
</section>
<section class="side-box">
<h2 class="panel-head panel-title">{{ $t('village.role.title') }}</h2>
<div class="side-body">

View File

@ -226,7 +226,7 @@ export function gable(
}
/** A dark panel on the outside of a wall facing +x or +y: a door or a window. */
function wallPanel(face: 'x' | 'y', at: number, along: number, z0: number, w: number, h: number, wallDepth: number, color: string): Face {
export function wallPanel(face: 'x' | 'y', at: number, along: number, z0: number, w: number, h: number, wallDepth: number, color: string): Face {
const a0 = along - w / 2
const a1 = along + w / 2
const pts: V3[] =
@ -268,7 +268,7 @@ export function openings(cx: number, cy: number, w: number, d: number, z0: numbe
}
/** Dark beams of a half-timbered wall: corner posts and a top beam on the two walls in view. */
function framing(cx: number, cy: number, w: number, d: number, z0: number, h: number, walls: string): Face[] {
export function framing(cx: number, cy: number, w: number, d: number, z0: number, h: number, walls: string): Face[] {
const beam = scale(walls, 0.62)
const t = Math.min(w, d) * 0.06
const ex = cx + w / 2 + 0.15
@ -288,6 +288,9 @@ function framing(cx: number, cy: number, w: number, d: number, z0: number, h: nu
const STONE_WALLS = new Set(['#a39d92', '#847e74', STONE])
/** Height of the stone plinth under a house's walls. */
export const plinthOf = (w: number, d: number, h: number) => Math.min(h * 0.16, Math.min(w, d) * 0.12)
/**
* A box with a gable roof: the most common house. It stands on a low stone plinth, wooden
* walls show their beams, the door on the wall towards the lower right and framed,
@ -304,9 +307,11 @@ export function house(
walls: string,
roof: string,
along: 'x' | 'y' = w >= d ? 'x' : 'y',
/** Leave out the door and windows, for a building that sets its own. */
bare = false,
): Face[] {
const o = Math.min(w, d) * 0.08
const plinth = Math.min(h * 0.16, Math.min(w, d) * 0.12)
const plinth = plinthOf(w, d, h)
const t = Math.min(w, d) * 0.07
const top = h + rise
// The ridge beam draws over the roof it sits on.
@ -317,12 +322,86 @@ export function house(
...box(cx, cy, w + plinth * 0.6, d + plinth * 0.6, 0, plinth, STONE, STONE),
...box(cx, cy, w, d, plinth, h - plinth, walls),
...(STONE_WALLS.has(walls) ? [] : framing(cx, cy, w, d, plinth, h, walls)),
...openings(cx, cy, w, d, plinth, h, walls),
...(bare ? [] : openings(cx, cy, w, d, plinth, h, walls)),
...gable(cx - w / 2 - o, cy - d / 2 - o, cx + w / 2 + o, cy + d / 2 + o, h, rise, along, roof, walls),
...ridge,
]
}
/**
* A gambrel roof, the barn's: steep lower slopes, flatter upper ones up to the ridge,
* over the rectangle [x0, x1] × [y0, y1] at height z, ridge along x or y.
*/
export function gambrel(
x0: number,
y0: number,
x1: number,
y1: number,
z: number,
rise: number,
along: 'x' | 'y',
color: string,
ends: string,
): Face[] {
// The profile across the ridge, as (offset across, height).
const [u0, u1, a0, a1] = along === 'x' ? [y0, y1, x0, x1] : [x0, x1, y0, y1]
const k = (u1 - u0) * 0.16
const profile: V2[] = [
[u0, z],
[u0 + k, z + rise * 0.6],
[(u0 + u1) / 2, z + rise],
[u1 - k, z + rise * 0.6],
[u1, z],
]
const at = (a: number, [u, h]: V2): V3 => (along === 'x' ? [a, u, h] : [u, a, h])
const inside: V3 = [(x0 + x1) / 2, (y0 + y1) / 2, z + rise / 3]
const faces: Face[] = []
for (let i = 0; i < profile.length - 1; i++) {
faces.push({ pts: [at(a0, profile[i]!), at(a1, profile[i]!), at(a1, profile[i + 1]!), at(a0, profile[i + 1]!)], color })
}
faces.push({ pts: profile.map((p) => at(a0, p)), color: ends }, { pts: profile.map((p) => at(a1, p)), color: ends })
return faces.map((f) => ({ ...f, pts: orient(f.pts, inside) }))
}
/** A box whose top is moved against its bottom: a slanted neck, a leaning beam. Corners counter-clockwise from above. */
export function slab(bottom: V3[], top: V3[], color: string, topColor = color): Face[] {
const inside = centroid([...bottom, ...top])
const faces: Face[] = [{ pts: top, color: topColor }, { pts: bottom, color }]
bottom.forEach((b, i) => {
const j = (i + 1) % bottom.length
faces.push({ pts: [b, bottom[j]!, top[j]!, top[i]!], color })
})
return faces.map((f) => ({ ...f, pts: orient(f.pts, inside) }))
}
/** A short round lying on its side, axis along x or y, centred at height cz: a wheel, a target, a barrel on its side. */
export function cylinder(cx: number, cy: number, cz: number, r: number, len: number, along: 'x' | 'y', color: string, cap = color, n = 8): Face[] {
const ring = Array.from({ length: n }, (_, i): V2 => {
const a = (i / n) * Math.PI * 2 + Math.PI / n
return [Math.cos(a) * r, Math.sin(a) * r]
})
const at = (a: number, [u, h]: V2): V3 => (along === 'x' ? [cx + a, cy + u, cz + h] : [cx + u, cy + a, cz + h])
const inside: V3 = [cx, cy, cz]
const faces: Face[] = ring.map((p, i) => {
const q = ring[(i + 1) % n]!
return { pts: [at(-len / 2, p), at(len / 2, p), at(len / 2, q), at(-len / 2, q)], color }
})
faces.push({ pts: ring.map((p) => at(len / 2, p)), color: cap }, { pts: ring.map((p) => at(-len / 2, p)), color: cap })
return faces.map((f) => ({ ...f, pts: orient(f.pts, inside) }))
}
/** Faces turned by quarter turns about (cx, cy) on the ground, counter-clockwise seen from above. */
export function turn(faces: Face[], quarters: number, cx = 0, cy = 0): Face[] {
const q = ((quarters % 4) + 4) % 4
const rot = ([x, y, z]: V3): V3 => {
const dx = x - cx
const dy = y - cy
const [rx, ry] = q === 0 ? [dx, dy] : q === 1 ? [-dy, dx] : q === 2 ? [-dx, -dy] : [dy, -dx]
return [cx + rx, cy + ry, z]
}
return faces.map(({ depth: _depth, ...f }) => ({ ...f, pts: f.pts.map(rot) }))
}
/** A log lying along x: a hexagonal prism on its side. */
export function log(cx: number, cy: number, z: number, len: number, r: number, color: string, cut: string): Face[] {
const ring = Array.from({ length: 6 }, (_, i): V2 => {

View File

@ -4,7 +4,7 @@
// stone at high levels.
import type { BuildingType } from '~/types/game'
import { box, type Face, hash, house, log, ngon, openings, orient, plane, prism, pyramid, rect, scale, shift, type V2, type V3 } from './iso'
import { box, cylinder, DOOR, type Face, framing, gable, gambrel, hash, house, log, mix, ngon, openings, orient, plane, plinthOf, prism, pyramid, rect, scale, shift, slab, turn, type V2, type V3, wallPanel } from './iso'
/** Muted medieval colours, all flat: faces get their light from iso.ts shading only. */
export const C = {
@ -42,6 +42,13 @@ export const C = {
broadleaf: '#5a7339',
broadleafDark: '#4c6431',
bush: '#5f7a3c',
barn: '#7c3f2c',
shingle: '#6b4a30',
metal: '#8b9094',
water: '#5f7f87',
chestnut: '#8a4f2a',
bay: '#5e3a22',
grey: '#b8b2a6',
}
export interface Model {
@ -204,32 +211,302 @@ function headframe(x: number, y: number, s: number, h: number): Face[] {
]
}
// Props that say what a building is for: horses, wheels and siege engines, weapons, stores.
/** A round on a wall facing +x or +y, seen flat: a shield, a target's rings. */
function wallDisc(face: 'x' | 'y', at: number, along: number, zc: number, r: number, depth: number, color: string, n = 8): Face {
const pts = ngon(along, zc, r, n, Math.PI / n).map(([a, z]): V3 => (face === 'x' ? [at, a, z] : [a, at, z]))
return { pts, color, twoSided: true, flat: true, depth }
}
/** A beam lying on the ground between two points, or raised to z: a fence rail, a timber. */
function beam([ax, ay]: V2, [bx, by]: V2, z: number, t: number, h: number, color: string): Face[] {
const len = Math.hypot(bx - ax, by - ay) || 1
const nx = (-(by - ay) / len) * (t / 2)
const ny = ((bx - ax) / len) * (t / 2)
const base: V2[] = [
[ax - nx, ay - ny],
[bx - nx, by - ny],
[bx + nx, by + ny],
[ax + nx, ay + ny],
]
const ccw = (base[1]![0] - base[0]![0]) * (base[2]![1] - base[0]![1]) - (base[1]![1] - base[0]![1]) * (base[2]![0] - base[0]![0]) > 0
return prism(ccw ? base : [...base].reverse(), z, h, color)
}
/** A rail fence along the points: a post at each, two rails between. */
function fence(pts: V2[], h: number, t: number): Face[] {
const faces: Face[] = pts.flatMap(([x, y]) => post(x, y, h, t))
for (let i = 0; i < pts.length - 1; i++) {
faces.push(...beam(pts[i]!, pts[i + 1]!, h * 0.45, t * 0.8, t * 0.8, C.wood), ...beam(pts[i]!, pts[i + 1]!, h * 0.85, t * 0.8, t * 0.8, C.wood))
}
return faces
}
/**
* A horse standing on four legs, head towards +x before `quarters` turns: body, legs,
* a slanted neck with its mane, the head bent down, a tail. `k` is about a hand's height.
*/
export function horse(x: number, y: number, k: number, quarters: number, color: string): Face[] {
const legs = scale(color, 0.8)
const mane = scale(color, 0.5)
const faces: Face[] = [
...[-1, 1].flatMap((fx) => [-1, 1].flatMap((fy) => box(fx * 1.3 * k, fy * 0.4 * k, 0.32 * k, 0.32 * k, 0, 1.6 * k, legs))),
...box(0, 0, 3.5 * k, 1.15 * k, 1.55 * k, 1.3 * k, color),
...slab(
[[1.15 * k, -0.34 * k, 2.3 * k], [2.05 * k, -0.34 * k, 2.3 * k], [2.05 * k, 0.34 * k, 2.3 * k], [1.15 * k, 0.34 * k, 2.3 * k]],
[[1.85 * k, -0.28 * k, 3.65 * k], [2.45 * k, -0.28 * k, 3.65 * k], [2.45 * k, 0.28 * k, 3.65 * k], [1.85 * k, 0.28 * k, 3.65 * k]],
color,
mane,
),
...slab(
[[2.15 * k, -0.27 * k, 3.0 * k], [3.3 * k, -0.2 * k, 2.55 * k], [3.3 * k, 0.2 * k, 2.55 * k], [2.15 * k, 0.27 * k, 3.0 * k]],
[[2.15 * k, -0.27 * k, 3.75 * k], [3.3 * k, -0.2 * k, 3.05 * k], [3.3 * k, 0.2 * k, 3.05 * k], [2.15 * k, 0.27 * k, 3.75 * k]],
color,
),
...slab(
[[-1.95 * k, -0.12 * k, 1.2 * k], [-1.7 * k, -0.12 * k, 1.2 * k], [-1.7 * k, 0.12 * k, 1.2 * k], [-1.95 * k, 0.12 * k, 1.2 * k]],
[[-1.85 * k, -0.15 * k, 2.75 * k], [-1.6 * k, -0.15 * k, 2.75 * k], [-1.6 * k, 0.15 * k, 2.75 * k], [-1.85 * k, 0.15 * k, 2.75 * k]],
mane,
),
]
return shift(turn(faces, quarters), x, y)
}
/** A plank wheel standing upright, axle along x or y. */
function wheel(x: number, y: number, r: number, along: 'x' | 'y'): Face[] {
return [...cylinder(x, y, r, r, r * 0.3, along, C.woodDark, C.plank, 10), ...cylinder(x, y, r, r * 0.25, r * 0.5, along, C.dark, C.metal, 6)]
}
/** A battering ram facing +x before `quarters` turns: a pointed log under a plank roof on four wheels. */
function ram(x: number, y: number, k: number, quarters = 0): Face[] {
const faces: Face[] = [
...[-1, 1].flatMap((fx) => [-1, 1].map((fy) => [fx, fy])).flatMap(([fx, fy]) => wheel(fx! * 1.25 * k, fy! * 0.95 * k, 0.6 * k, 'y')),
...box(0, 0, 3.3 * k, 1.5 * k, 0.65 * k, 0.3 * k, C.wood, C.plank),
...[-1, 1].flatMap((fx) => [-1, 1].flatMap((fy) => post(fx * 1.45 * k, fy * 0.6 * k, 2.2 * k, 0.12 * k))),
...log(0.35 * k, -0.3 * k, 1.05 * k, 4.2 * k, 0.32 * k, C.trunk, C.plank),
...pyramid(rect(2.5 * k, 0, 0.5 * k, 0.6 * k), 1.05 * k, 0.6 * k, C.metal),
...gable(-1.75 * k, -0.9 * k, 1.75 * k, 0.9 * k, 2.2 * k, 0.85 * k, 'x', C.plank, C.wood),
]
return shift(turn(faces, quarters), x, y)
}
/** A catapult facing +x before `quarters` turns: a wheeled frame, two uprights with a crossbar, the arm with its bucket raised. */
function catapult(x: number, y: number, k: number, quarters = 0): Face[] {
const faces: Face[] = [
...[-1, 1].flatMap((fx) => [-1, 1].map((fy) => [fx, fy])).flatMap(([fx, fy]) => wheel(fx! * 1.2 * k, fy! * 0.9 * k, 0.55 * k, 'y')),
...box(0, 0, 3.2 * k, 1.4 * k, 0.6 * k, 0.28 * k, C.wood, C.plank),
...post(0.4 * k, -0.55 * k, 2.4 * k, 0.13 * k),
...post(0.4 * k, 0.55 * k, 2.4 * k, 0.13 * k),
...box(0.4 * k, 0, 0.24 * k, 1.35 * k, 2.15 * k, 0.24 * k, C.woodDark),
...slab(
[[-1.3 * k, -0.13 * k, 0.9 * k], [-1.1 * k, -0.13 * k, 0.9 * k], [-1.1 * k, 0.13 * k, 0.9 * k], [-1.3 * k, 0.13 * k, 0.9 * k]],
[[0.9 * k, -0.11 * k, 2.85 * k], [1.1 * k, -0.11 * k, 2.85 * k], [1.1 * k, 0.11 * k, 2.85 * k], [0.9 * k, 0.11 * k, 2.85 * k]],
C.wood,
),
...box(1.1 * k, 0, 0.55 * k, 0.55 * k, 2.8 * k, 0.3 * k, C.woodDark, C.dark),
]
return shift(turn(faces, quarters), x, y)
}
/** A rack of spears with a shield leaning on it, along x or y. */
function weaponRack(x: number, y: number, s: number, along: 'x' | 'y'): Face[] {
const len = s * 0.55
const at = (u: number): V2 => (along === 'x' ? [x + u, y] : [x, y + u])
const faces: Face[] = [...post(...at(-len / 2), s * 0.5, s * 0.03), ...post(...at(len / 2), s * 0.5, s * 0.03)]
faces.push(...(along === 'x' ? box(x, y, len, s * 0.04, s * 0.38, s * 0.04, C.wood) : box(x, y, s * 0.04, len, s * 0.38, s * 0.04, C.wood)))
for (let i = 0; i < 4; i++) {
const [px, py] = at(-len * 0.36 + (i * len * 0.72) / 3)
faces.push(...box(px, py, s * 0.025, s * 0.025, 0, s * 0.72, C.woodDark), ...pyramid(rect(px, py, s * 0.05, s * 0.05), s * 0.72, s * 0.1, C.metal))
}
return faces
}
/** A straw training dummy on a post, arms out. */
function dummy(x: number, y: number, s: number): Face[] {
return [
...post(x, y, s * 0.6, s * 0.025),
...box(x, y, s * 0.17, s * 0.13, s * 0.3, s * 0.24, C.hay),
...box(x, y, s * 0.05, s * 0.42, s * 0.45, s * 0.05, C.wood),
...box(x, y, s * 0.11, s * 0.11, s * 0.56, s * 0.11, C.hay),
]
}
/** An archery target facing +x on two legs, its rings in red. */
function target(x: number, y: number, s: number): Face[] {
const r = s * 0.2
const zc = s * 0.33
const front = x + s * 0.04
const depth = front + y + zc + 0.2
return [
...post(x - s * 0.08, y - r * 0.6, zc, s * 0.02),
...post(x - s * 0.08, y + r * 0.6, zc, s * 0.02),
...cylinder(x, y, zc, r, s * 0.08, 'x', C.hay, C.hay, 10),
wallDisc('x', front + 0.1, y, zc, r * 0.66, depth, C.banner, 10),
wallDisc('x', front + 0.2, y, zc, r * 0.4, depth + 0.1, C.canvas, 10),
wallDisc('x', front + 0.3, y, zc, r * 0.18, depth + 0.2, C.banner, 8),
]
}
/** A canvas tent: a ridge from the ground, its open flap on the end towards the viewer. */
function tent(x: number, y: number, w: number, d: number, h: number, along: 'x' | 'y', color: string, door = false): Face[] {
const x1 = x + w / 2
const y1 = y + d / 2
const flap: V3[] =
along === 'x'
? [[x1 + 0.1, y - d * 0.2, 0], [x1 + 0.1, y + d * 0.2, 0], [x1 + 0.1, y, h * 0.62]]
: [[x - w * 0.2, y1 + 0.1, 0], [x + w * 0.2, y1 + 0.1, 0], [x, y1 + 0.1, h * 0.62]]
const depth = (along === 'x' ? x1 + y : x + y1) + h / 3 + 0.2
return [
...gable(x - w / 2, y - d / 2, x1, y1, 0, h, along, color, scale(color, 0.9)),
{ pts: flap, color: door ? DOOR : C.dark, twoSided: true, flat: true, depth },
...(along === 'x' ? post(x1, y, h * 1.12, w * 0.02) : post(x, y1, h * 1.12, d * 0.02)),
]
}
function barrel(x: number, y: number, s: number): Face[] {
return [...prism(ngon(x, y, s * 0.1, 8), 0, s * 0.24, C.wood, C.woodDark), ...prism(ngon(x, y, s * 0.105, 8), s * 0.08, s * 0.025, C.dark)]
}
function sack(x: number, y: number, s: number): Face[] {
return [...prism(ngon(x, y, s * 0.09, 6, 0.3), 0, s * 0.14, C.canvas), ...pyramid(ngon(x, y, s * 0.09, 6, 0.3), s * 0.14, s * 0.07, C.canvasDark)]
}
function hayBale(x: number, y: number, s: number, along: 'x' | 'y' = 'x'): Face[] {
return along === 'x' ? box(x, y, s * 0.32, s * 0.2, 0, s * 0.18, C.hay) : box(x, y, s * 0.2, s * 0.32, 0, s * 0.18, C.hay)
}
function trough(x: number, y: number, s: number): Face[] {
return [...box(x, y, s * 0.42, s * 0.16, 0, s * 0.13, C.wood), plane(rect(x, y, s * 0.34, s * 0.09).map(([px, py]): V3 => [px, py, s * 0.131]), C.water)]
}
/** Squared timbers piled along x. */
function timbers(x: number, y: number, s: number, layers = 2): Face[] {
const faces: Face[] = []
for (let l = 0; l < layers; l++) {
for (let i = 0; i < 3 - l; i++) faces.push(...box(x, y - s * 0.1 * (2 - l) / 2 + i * s * 0.1, s * 0.75, s * 0.085, l * s * 0.085, s * 0.085, i % 2 ? C.plank : C.wood, C.plank))
}
return faces
}
/** Merlons along the top edges of a flat-topped box. */
function battlements(cx: number, cy: number, w: number, d: number, z: number, m: number, color: string): Face[] {
const faces: Face[] = []
const nx = Math.max(2, Math.round(w / (m * 2)))
const ny = Math.max(2, Math.round(d / (m * 2)))
for (let i = 0; i <= nx; i++) {
const x = Math.min(cx + w / 2 - m / 2, Math.max(cx - w / 2 + m / 2, cx - w / 2 + (i * w) / nx))
faces.push(...box(x, cy - d / 2 + m / 2, m, m, z, m, color), ...box(x, cy + d / 2 - m / 2, m, m, z, m, color))
}
for (let j = 1; j < ny; j++) {
const y = cy - d / 2 + (j * d) / ny
faces.push(...box(cx - w / 2 + m / 2, y, m, m, z, m, color), ...box(cx + w / 2 - m / 2, y, m, m, z, m, color))
}
return faces
}
/**
* A barn, ridge along x so its gable end faces the viewer: walls on a plinth, a gambrel
* roof, big double doors in the end wall and a loft door above (with a hoist beam and a
* sack on its rope when `hoist`), vents high on the long side.
*/
function barn(cx: number, cy: number, w: number, d: number, h: number, rise: number, walls: string, roof: string, hoist: boolean): Face[] {
const p = Math.min(h * 0.14, d * 0.1)
const o = d * 0.06
const x1 = cx + w / 2
const xDepth = x1 + cy + (p + h) / 2 + 0.1
const yDepth = cx + cy + d / 2 + (p + h) / 2 + 0.1
const endDepth = x1 + o + cy + h + rise * 0.44 + 0.1
const frame = mix(walls, '#efe4c6', 0.45)
const dw = d * 0.46
const dh = (h - p) * 0.82
const loftZ = h + rise * 0.12
const faces: Face[] = [
...box(cx, cy, w + p * 0.6, d + p * 0.6, 0, p, C.stone),
...box(cx, cy, w, d, p, h - p, walls),
...(walls === C.stone ? [] : framing(cx, cy, w, d, p, h, walls)),
...gambrel(cx - w / 2 - o, cy - d / 2 - o, x1 + o, cy + d / 2 + o, h, rise, 'x', roof, walls),
wallPanel('x', x1 + 0.25, cy, p, dw * 1.14, dh + d * 0.05, xDepth, frame),
wallPanel('x', x1 + 0.3, cy, p, dw, dh, xDepth + 0.05, DOOR),
wallPanel('x', x1 + 0.35, cy, p, d * 0.025, dh, xDepth + 0.1, scale(DOOR, 0.7)),
wallPanel('x', x1 + 0.35, cy, p + dh * 0.45, dw, d * 0.035, xDepth + 0.1, frame),
wallPanel('x', x1 + o + 0.3, cy, loftZ, d * 0.24, rise * 0.34, endDepth, frame),
wallPanel('x', x1 + o + 0.35, cy, loftZ + rise * 0.02, d * 0.19, rise * 0.29, endDepth + 0.05, hoist ? C.hay : C.dark),
...[-0.28, 0.28].map((u) => wallPanel('y', cy + d / 2 + 0.25, cx + u * w, h * 0.62, w * 0.07, h * 0.18, yDepth, C.dark)),
]
if (hoist) {
const bz = loftZ + rise * 0.4
faces.push(
...box(x1 + o + d * 0.12, cy, d * 0.3, d * 0.05, bz, d * 0.05, C.woodDark),
...box(x1 + o + d * 0.24, cy, d * 0.012, d * 0.012, bz - rise * 0.32, rise * 0.32, C.dark),
...sack(x1 + o + d * 0.24, cy, d).map((f) => ({ ...f, pts: f.pts.map(([x, y, z]): V3 => [x, y, z + bz - rise * 0.32 - d * 0.2]) })),
)
}
return faces
}
/** The village banner on a tall pole, flying from its top. */
function flag(x: number, y: number, h: number, size: number): Face[] {
return [...post(x, y, h, size * 0.03), plane([[x, y, h], [x - size * 0.1, y + size * 0.85, h - size * 0.08], [x, y, h - size * 0.4]], C.banner)]
}
// Buildings
const models: Record<BuildingType, (s: number, t: number) => Model> = {
// The village hall, the biggest building: its door between two banners and steps up to
// it. A thatched longhouse with a cross wing and a porch first, then a hall of timber on
// stone with a flag tower, then a stone keep.
headquarters(s, t) {
if (t === 1) {
const x1 = s * 0.6
const yd = -s * 0.05 + s * 0.95 * 0.12
return {
faces: [
...house(0, 0, s * 1.35, s * 1.0, s * 0.5, s * 0.5, C.wood, C.thatch),
...banner(s * 0.85, -s * 0.6, s * 1.25, s * 0.55),
...fire(s * 0.7, s * 0.72, s),
...house(-s * 0.15, -s * 0.05, s * 1.5, s * 0.95, s * 0.55, s * 0.6, C.wood, C.thatch),
...flag(-s * 0.75, -s * 0.75, s * 1.75, s * 0.45),
...post(x1 + s * 0.36, yd - s * 0.24, s * 0.44, s * 0.035),
...post(x1 + s * 0.36, yd + s * 0.24, s * 0.44, s * 0.035),
...gable(x1 - s * 0.02, yd - s * 0.3, x1 + s * 0.44, yd + s * 0.3, s * 0.44, s * 0.24, 'x', C.thatch, C.wood),
...banner(x1 + s * 0.55, yd - s * 0.5, s * 0.95, s * 0.42),
...banner(x1 + s * 0.55, yd + s * 0.5, s * 0.95, s * 0.42),
...fire(s * 0.15, s * 0.8, s),
],
height: s * 1.25,
height: s * 1.75,
}
}
if (t === 2) {
const w = s * 1.4
const d = s * 1.0
const h1 = s * 0.38
const h2 = s * 0.38
const j = s * 0.06
const x1 = w / 2
const yd = d * 0.12
const up = h1 + h2
const xDepth = x1 + j / 2 + (h1 + up) / 2 + 0.12
const yDepth = d / 2 + j / 2 + (h1 + up) / 2 + 0.12
const win = s * 0.12
return {
faces: [
...box(0, 0, s * 1.6, s * 1.2, 0, s * 0.14, C.stoneDark, C.stone),
...shift(house(0, 0, s * 1.45, s * 1.05, s * 0.5, s * 0.55, C.plank, C.roofRed), 0, 0, s * 0.14),
...box(-s * 0.62, -s * 0.48, s * 0.5, s * 0.5, 0, s * 1.25, C.stone),
...pyramid(rect(-s * 0.62, -s * 0.48, s * 0.6, s * 0.6), s * 1.25, s * 0.45, C.roofRed),
...banner(s * 0.85, s * 0.7, s * 1.3, s * 0.55),
...box(0, 0, w, d, 0, h1, C.stone, C.stoneDark),
...openings(0, 0, w, d, 0, h1 * 1.25, C.stone),
...box(0, 0, w + j, d + j, h1, h2, C.plank),
...framing(0, 0, w + j, d + j, h1, up, C.plank),
...[-0.25, 0.25].map((u) => wallPanel('x', x1 + j / 2 + 0.3, u * d, h1 + h2 * 0.3, win, win * 1.1, xDepth, C.dark)),
...[-0.3, 0, 0.3].map((u) => wallPanel('y', d / 2 + j / 2 + 0.3, u * w, h1 + h2 * 0.3, win, win * 1.1, yDepth, C.dark)),
...gable(-w / 2 - j, -d / 2 - j, w / 2 + j, d / 2 + j, up, s * 0.5, 'x', C.roofRed, C.plank),
...box(-s * 0.55, -s * 0.42, s * 0.48, s * 0.48, 0, s * 1.4, C.stone, C.stoneDark),
...pyramid(rect(-s * 0.55, -s * 0.42, s * 0.6, s * 0.6), s * 1.4, s * 0.42, C.roofRed),
...flag(-s * 0.55, -s * 0.42, s * 2.15, s * 0.45),
...box(x1 + s * 0.12, yd, s * 0.22, s * 0.42, 0, s * 0.05, C.stoneDark, C.stone),
...banner(x1 + s * 0.38, yd - s * 0.42, s * 1.05, s * 0.45),
...banner(x1 + s * 0.38, yd + s * 0.42, s * 1.05, s * 0.45),
],
height: s * 1.7,
height: s * 2.15,
}
}
const x1 = s * 0.675
const yd = s * 1.35 * 0.12
return {
faces: [
...box(0, 0, s * 1.35, s * 1.35, 0, s * 0.9, C.stone, C.stoneDark),
@ -239,32 +516,57 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
...pyramid(ngon(-s * 0.72, s * 0.72, s * 0.34, 6), s * 1.3, s * 0.45, C.slate),
...prism(ngon(s * 0.72, -s * 0.72, s * 0.28, 6), 0, s * 1.3, C.stone),
...pyramid(ngon(s * 0.72, -s * 0.72, s * 0.34, 6), s * 1.3, s * 0.45, C.slate),
...banner(0, 0, s * 2.0, s * 0.6),
...prism(ngon(-s * 0.5, -s * 0.5, s * 0.3, 6), 0, s * 1.75, C.stone),
...pyramid(ngon(-s * 0.5, -s * 0.5, s * 0.36, 6), s * 1.75, s * 0.5, C.slate),
...flag(-s * 0.5, -s * 0.5, s * 2.6, s * 0.5),
...box(x1 + s * 0.12, yd, s * 0.22, s * 0.45, 0, s * 0.06, C.stoneDark, C.stone),
...banner(x1 + s * 0.4, yd - s * 0.4, s * 1.15, s * 0.45),
...banner(x1 + s * 0.4, yd + s * 0.4, s * 1.15, s * 0.45),
],
height: s * 2.0,
height: s * 2.6,
}
},
// A barn: tall walls under a gambrel roof, big double doors in the gable end and a loft
// door with its hoist above, sacks and barrels at the door. Wood first, then painted
// planks with a hay loft, then stone with a granary on staddle stones beside it.
storage(s, t) {
if (t === 1) return { faces: [...house(0, 0, s * 1.15, s * 1.0, s * 0.55, s * 0.4, C.wood, C.woodDark, 'y'), ...crate(s * 0.75, s * 0.7, 0, s * 0.28)], height: s * 0.95 }
if (t === 2) {
if (t === 1) {
return {
faces: [
...house(0, -s * 0.1, s * 1.5, s * 1.1, s * 0.75, s * 0.55, C.plank, C.roofRed),
plane([[s * 0.76, -s * 0.28, 0], [s * 0.76, s * 0.08, 0], [s * 0.76, s * 0.08, s * 0.45], [s * 0.76, -s * 0.28, s * 0.45]], C.dark),
...crate(s * 0.55, s * 0.78, 0, s * 0.26),
...crate(s * 0.2, s * 0.8, 0, s * 0.26),
],
faces: [...barn(-s * 0.2, -s * 0.05, s * 1.25, s * 1.0, s * 0.6, s * 0.6, C.wood, C.thatch, false), ...barrel(s * 0.75, -s * 0.45, s), ...sack(s * 0.72, s * 0.42, s), ...sack(s * 0.88, s * 0.3, s)],
height: s * 1.3,
}
}
if (t === 2) {
return {
faces: [
...house(-s * 0.1, -s * 0.1, s * 1.55, s * 1.25, s * 0.85, s * 0.55, C.stone, C.slate),
...house(s * 0.7, s * 0.65, s * 0.55, s * 0.5, s * 0.4, s * 0.25, C.wood, C.woodDark),
...crate(-s * 0.55, s * 0.8, 0, s * 0.26),
...barn(-s * 0.2, -s * 0.1, s * 1.4, s * 1.1, s * 0.72, s * 0.72, C.barn, C.shingle, true),
...barrel(s * 0.8, -s * 0.55, s),
...barrel(s * 0.8, -s * 0.33, s),
...sack(s * 0.75, s * 0.38, s),
...sack(s * 0.92, s * 0.48, s),
...sack(s * 0.82, s * 0.6, s),
...hayBale(-s * 0.45, s * 0.75, s),
...shift(hayBale(-s * 0.45, s * 0.75, s), 0, 0, s * 0.18),
],
height: s * 1.4,
height: s * 1.55,
}
}
const granary: Face[] = [
...[-1, 1].flatMap((fx) => [-1, 1].flatMap((fy) => prism(ngon(-s * 0.55 + fx * s * 0.18, s * 0.78 + fy * s * 0.14, s * 0.05, 5), 0, s * 0.16, C.stone))),
...shift(house(-s * 0.55, s * 0.78, s * 0.5, s * 0.4, s * 0.3, s * 0.25, C.wood, C.thatch, 'x', true), 0, 0, s * 0.16),
]
return {
faces: [
...barn(-s * 0.1, -s * 0.2, s * 1.5, s * 1.15, s * 0.78, s * 0.78, C.stone, C.slate, true),
...granary,
...barrel(s * 0.9, -s * 0.65, s),
...barrel(s * 0.9, -s * 0.43, s),
...barrel(s * 1.06, -s * 0.54, s),
...sack(s * 0.85, s * 0.35, s),
...sack(s * 1.0, s * 0.45, s),
],
height: s * 1.65,
}
},
@ -461,64 +763,180 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
}
},
// Military: tents and a weapon rack at first, then a long hall that grows into stone.
// Military: an army camp of tents first, then a timber hall with shields on its walls,
// then a stone hall with battlements. A training yard in front: spears on a rack,
// straw dummies, a target.
barracks(s, t) {
if (t === 1) {
return {
faces: [
...house(0, 0, s * 1.7, s * 0.9, s * 0.5, s * 0.45, C.wood, C.woodDark),
...post(s * 0.8, s * 0.72, s * 0.5, s * 0.05),
...banner(-s * 0.85, s * 0.6, s * 1.2, s * 0.5),
...tent(-s * 0.3, -s * 0.4, s * 0.95, s * 0.7, s * 0.62, 'x', C.canvas, true),
...tent(-s * 0.6, s * 0.42, s * 0.75, s * 0.55, s * 0.5, 'x', C.canvasDark),
...weaponRack(s * 0.5, s * 0.55, s, 'x'),
...dummy(s * 0.75, -s * 0.05, s),
...fire(s * 0.15, s * 0.2, s),
...banner(-s * 0.95, -s * 0.85, s * 1.15, s * 0.45),
],
height: s * 1.2,
height: s * 1.15,
}
}
if (t === 2) {
const cx = -s * 0.1
const cy = -s * 0.3
const w = s * 1.7
const d = s * 0.8
const h = s * 0.58
const ey = cy + d / 2 + 0.3
const depth = cx + cy + d / 2 + (plinthOf(w, d, h) + h) / 2 + 0.3
const shields = [-0.42, 0, 0.42].flatMap((u, i) => [
wallDisc('y', ey, cx + u * w, h * 0.62, s * 0.085, depth, i === 1 ? C.slate : C.banner),
wallDisc('y', ey + 0.1, cx + u * w, h * 0.62, s * 0.025, depth + 0.1, C.metal, 6),
])
return {
faces: [
...house(cx, cy, w, d, h, s * 0.45, C.plank, C.woodDark),
...shields,
...weaponRack(s * 0.55, s * 0.6, s, 'x'),
...dummy(-s * 0.55, s * 0.6, s),
...dummy(-s * 0.1, s * 0.75, s),
...target(s * 0.9, -s * 0.75, s),
...banner(s * 0.95, s * 0.05, s * 1.3, s * 0.5),
],
height: s * 1.3,
}
}
const cx = -s * 0.1
const cy = -s * 0.3
const w = s * 1.75
const d = s * 0.85
const h = s * 0.72
return {
faces: [
...box(cx, cy, w, d, 0, h, C.stone, C.stoneDark),
...openings(cx, cy, w, d, 0, h * 0.9, C.stone),
...battlements(cx, cy, w, d, h, s * 0.1, C.stone),
...prism(ngon(cx - w / 2, cy - d / 2, s * 0.3, 8), 0, h * 1.55, C.stone, C.stoneDark),
...battlements(cx - w / 2, cy - d / 2, s * 0.5, s * 0.5, h * 1.55, s * 0.09, C.stone),
...flag(cx - w / 2, cy - d / 2, h * 1.55 + s * 0.75, s * 0.45),
...weaponRack(s * 0.55, s * 0.6, s, 'x'),
...dummy(-s * 0.6, s * 0.55, s),
...dummy(-s * 0.2, s * 0.72, s),
...target(s * 0.95, -s * 0.85, s),
],
height: h * 1.55 + s * 0.75,
}
},
// A long, low stable with a stall door for every horse, heads looking out, and a fenced
// paddock in front where horses stand by the trough and the hay.
stable(s, t) {
const [walls, roof] = t === 1 ? [C.wood, C.thatch] : t === 2 ? [C.plank, C.shingle] : [C.stone, C.slate]
const cx = -s * 0.05
const cy = -s * 0.5
const w = s * 1.8
const d = s * 0.62
const h = s * 0.48
const x1 = cx + w / 2
const ey = cy + d / 2 + 0.25
const yDepth = cx + cy + d / 2 + (plinthOf(w, d, h) + h) / 2 + 0.1
const xDepth = x1 + cy + (plinthOf(w, d, h) + h) / 2 + 0.1
const coats = [C.chestnut, C.bay, C.grey]
const stalls = 4
const heads = t
const faces: Face[] = [...house(cx, cy, w, d, h, s * 0.36, walls, roof, 'x', true)]
for (let i = 0; i < stalls; i++) {
const x = cx - w / 2 + (w * (i + 0.5)) / stalls
faces.push(
wallPanel('y', ey, x, h * 0.12, s * 0.27, h * 0.45, yDepth, scale(walls, 0.72)),
wallPanel('y', ey + 0.05, x, h * 0.6, s * 0.24, h * 0.3, yDepth + 0.05, C.dark),
)
if (i < heads) {
// A head looking out over the stall door, nose down.
const k = s * 0.1
const y0 = ey + 0.1
const z0 = h * 0.88
faces.push(
...slab(
[[x - 0.26 * k, y0, z0 - 0.75 * k], [x + 0.26 * k, y0, z0 - 0.75 * k], [x + 0.2 * k, y0 + 1.25 * k, z0 - 1.2 * k], [x - 0.2 * k, y0 + 1.25 * k, z0 - 1.2 * k]],
[[x - 0.26 * k, y0, z0], [x + 0.26 * k, y0, z0], [x + 0.2 * k, y0 + 1.25 * k, z0 - 0.75 * k], [x - 0.2 * k, y0 + 1.25 * k, z0 - 0.75 * k]],
coats[(i + 1) % 3]!,
).map((f) => ({ ...f, depth: yDepth + 0.3 + k })),
...pyramid(rect(x, y0 + 0.15 * k, 0.4 * k, 0.2 * k), z0, 0.35 * k, scale(coats[(i + 1) % 3]!, 0.6)).map((f) => ({ ...f, depth: yDepth + 0.4 + k })),
)
}
}
faces.push(
wallPanel('x', x1 + 0.25, cy, h * 0.12, d * 0.5, h * 0.62, xDepth, mix(walls, '#efe4c6', 0.45)),
wallPanel('x', x1 + 0.3, cy, h * 0.12, d * 0.4, h * 0.56, xDepth + 0.05, DOOR),
)
// The paddock, with a horse more for every tier.
const py0 = cy + d / 2 + s * 0.08
faces.push(...fence([[-s * 0.95, py0], [-s * 0.95, s * 0.95], [s * 0.95, s * 0.95], [s * 0.95, s * 0.35]], s * 0.24, s * 0.035))
faces.push(...trough(s * 0.55, py0 + s * 0.14, s), ...hayBale(-s * 0.72, py0 + s * 0.14, s))
const spots: [number, number, number][] = [
[-s * 0.35, s * 0.42, 0],
[s * 0.35, s * 0.7, 1],
[s * 0.4, s * 0.15, 3],
]
spots.slice(0, t).forEach(([x, y, q], i) => faces.push(...horse(x, y, s * 0.13, q, coats[i]!)))
return { faces, height: s * 1.0 }
},
// Where siege engines are made: an open shed with wheels against its back wall and a
// frame on the floor, timbers outside; then a ram under the roof; then a stone hall
// with a catapult in front.
workshop(s, t) {
const shed = (x0: number, y0: number, x1: number, y1: number, h: number, roof: string): Face[] => {
const back = scale(C.plank, 0.9)
return [
plane(rect((x0 + x1) / 2, (y0 + y1) / 2, x1 - x0, y1 - y0).map(([x, y]): V3 => [x, y, 0.5]), C.soil),
plane([[x0, y0, 0], [x1, y0, 0], [x1, y0, h], [x0, y0, h]], back),
plane([[x0, y0, 0], [x0, y1, 0], [x0, y1, h], [x0, y0, h]], scale(back, 0.9)),
...[x0, (x0 + x1) / 2, x1].flatMap((x) => [...post(x, y1, h, s * 0.04), ...post(x, y0, h, s * 0.04)]),
...post(x1, (y0 + y1) / 2, h, s * 0.04),
...gable(x0 - s * 0.06, y0 - s * 0.06, x1 + s * 0.06, y1 + s * 0.06, h, s * 0.32, 'x', roof, C.wood),
]
}
const leaning = (x: number, y: number) => [...wheel(x, y, s * 0.15, 'y'), ...wheel(x + s * 0.26, y, s * 0.15, 'y')]
if (t === 1) {
return {
faces: [
...shed(-s * 0.8, -s * 0.8, s * 0.5, s * 0.1, s * 0.55, C.thatch),
...leaning(-s * 0.55, -s * 0.66),
...box(-s * 0.1, -s * 0.3, s * 0.5, s * 0.22, s * 0.1, s * 0.06, C.wood, C.plank),
...wheel(-s * 0.25, -s * 0.15, s * 0.12, 'y'),
...timbers(-s * 0.2, s * 0.6, s),
...wheel(s * 0.75, s * 0.25, s * 0.15, 'x'),
...box(s * 0.8, -s * 0.4, s * 0.4, s * 0.2, 0, s * 0.2, C.wood, C.plank),
],
height: s * 0.95,
}
}
if (t === 2) {
return {
faces: [
...house(0, 0, s * 1.85, s * 1.0, s * 0.6, s * 0.5, C.plank, C.roofRed),
...banner(-s * 0.9, s * 0.65, s * 1.35, s * 0.55),
...banner(s * 0.9, s * 0.65, s * 1.35, s * 0.55),
...house(-s * 0.95, -s * 0.85, s * 0.5, s * 0.5, s * 0.5, s * 0.25, C.stone, C.slate),
...box(-s * 0.95, -s * 0.85, s * 0.12, s * 0.12, s * 0.6, s * 0.4, C.stoneDark),
...shed(-s * 0.65, -s * 0.85, s * 0.75, s * 0.05, s * 0.62, C.shingle),
...leaning(-s * 0.45, -s * 0.72),
...leaning(s * 0.15, -s * 0.72),
...ram(s * 0.05, -s * 0.35, s * 0.11),
...timbers(-s * 0.3, s * 0.6, s, 3),
...wheel(s * 0.75, s * 0.45, s * 0.15, 'x'),
...wheel(s * 0.75, s * 0.2, s * 0.15, 'x'),
],
height: s * 1.35,
height: s * 1.05,
}
}
return {
faces: [
...box(0, 0, s * 1.9, s * 1.1, 0, s * 0.75, C.stone, C.stoneDark),
...openings(0, 0, s * 1.9, s * 1.1, 0, s * 0.75, C.stone),
...pyramid(rect(0, 0, s * 2.0, s * 1.2), s * 0.75, s * 0.45, C.slate),
...prism(ngon(s * 0.85, -s * 0.5, s * 0.25, 6), 0, s * 1.3, C.stone),
...pyramid(ngon(s * 0.85, -s * 0.5, s * 0.3, 6), s * 1.3, s * 0.4, C.slate),
...banner(-s * 0.95, s * 0.65, s * 1.6, s * 0.6),
],
height: s * 1.7,
}
},
stable(s, t) {
const fence: Face[] = [
[-0.9, 0.55], [-0.45, 0.85], [0, 0.85], [0.45, 0.85], [0.9, 0.55],
].flatMap(([x, y]) => post(s * x!, s * y!, s * 0.3, s * 0.035))
const hay = box(-s * 0.75, -s * 0.55, s * 0.32, s * 0.28, 0, s * 0.22, C.hay)
const [walls, roof] = t === 1 ? [C.wood, C.thatch] : t === 2 ? [C.plank, C.roofRed] : [C.stone, C.slate]
return {
faces: [...house(0, -s * 0.2, s * 1.9, s * 0.85, s * 0.45, s * 0.4, walls, roof), ...fence, ...hay],
height: s * 0.9,
}
},
workshop(s, t) {
const logs: Face[] = [
...log(s * 0.55, s * 0.7, 0, s * 0.7, s * 0.08, C.wood, C.plank),
...log(s * 0.55, s * 0.55, 0, s * 0.7, s * 0.08, C.woodDark, C.plank),
]
const [walls, roof] = t === 1 ? [C.wood, C.thatch] : t === 2 ? [C.plank, C.roofRed] : [C.stone, C.slate]
return {
faces: [
...house(-s * 0.1, -s * 0.15, s * 1.5, s * 1.0, s * 0.55, s * 0.45, walls, roof),
...box(s * 0.45, -s * 0.45, s * 0.2, s * 0.2, s * 0.55, s * 0.55, C.stoneDark),
...logs,
...house(-s * 0.35, -s * 0.6, s * 1.3, s * 0.75, s * 0.65, s * 0.4, C.stone, C.slate),
...box(-s * 0.85, -s * 0.85, s * 0.14, s * 0.14, s * 0.75, s * 0.5, C.stoneDark),
...ram(-s * 0.45, s * 0.3, s * 0.11),
...catapult(s * 0.55, s * 0.15, s * 0.12),
...timbers(s * 0.05, s * 0.85, s, 3),
...wheel(s * 0.75, -s * 0.55, s * 0.15, 'x'),
...wheel(s * 0.75, -s * 0.3, s * 0.15, 'x'),
],
height: s * 1.2,
}

View File

@ -590,6 +590,18 @@ function view(state: MockState, v: MockVillage, now: number): VillageState {
.filter((o) => o.user_id === v.user_id && o.world_id === v.world_id)
.map((o) => ({ id: o.id, name: o.name, x: o.x, y: o.y, points: points(o) })),
quests: { claimable: questBook(state, v).lines.filter((l) => l.quest?.complete).length, rewards: 0 },
// The mock's crowns stand from the start, all barbarian.
season: {
crowns_at: iso(now - 86_400_000),
count: CROWN_SPOTS.length,
needed: 3,
hold_seconds: 7 * 86400,
crowns: CROWN_SPOTS.map(([x, y], i) => ({ id: -900 - i, name: 'Crown fort', x, y, player: null })),
holder: null,
ends_at: null,
ended_at: null,
winner: null,
},
unread_reports: (state.reports ?? []).filter((r) => r.user_id === v.user_id && r.world_id === v.world_id && !r.read).length,
builders: BUILDERS,
buildings: v.buildings.map(
@ -647,6 +659,10 @@ function barbarianAt(x: number, y: number) {
return near && r < 0.08 ? { id: -((y - MAP_MIN) * MAP_SIZE + (x - MAP_MIN) + 1), name: BARBARIAN_NAME, points: 20 + Math.floor(r * 1000) } : null
}
/** The season's crown forts, barbarian in the mock, on the backend's ring round 0|0. */
const CROWN_SPOTS: [number, number][] = [[0, -10], [10, -3], [6, 8], [-6, 8], [-10, -3]]
const crownAt = (x: number, y: number) => CROWN_SPOTS.findIndex(([cx, cy]) => cx === x && cy === y)
/** Mock map: the stored player villages plus barbarians made up from a hash of the field. */
function mapView(state: MockState, user: AuthUser, data: any): MapView {
const size = MAP_SIZE
@ -672,12 +688,18 @@ function mapView(state: MockState, user: AuthUser, data: any): MapView {
continent: continentOf(x, y),
player: { id: player.user_id, name: owner?.name ?? '?' },
own: player.user_id === user.id,
crown: false,
})
continue
}
const crown = crownAt(x, y)
if (crown >= 0) {
villages.push({ id: -900 - crown, x, y, name: 'Crown fort', points: 3000, continent: continentOf(x, y), player: null, own: false, crown: true })
continue
}
const barbarian = barbarianAt(x, y)
if (barbarian) {
villages.push({ ...barbarian, x, y, continent: continentOf(x, y), player: null, own: false })
villages.push({ ...barbarian, x, y, continent: continentOf(x, y), player: null, own: false, crown: false })
}
}
}
@ -1112,6 +1134,8 @@ const handlers: Record<string, Handler> = {
WORLDS.map((w) => ({
...w,
village_id: state.villages.find((v) => v.world_id === w.id && v.user_id === user.id)?.id ?? null,
ended_at: null,
winner: null,
})),
'world.join': (state, user, data, now) => {

View File

@ -185,7 +185,8 @@ const counts = computed(() => {
return {
own: villages.filter((v) => v.own).length,
players: villages.filter((v) => v.player && !v.own).length,
barbarians: villages.filter((v) => !v.player).length,
barbarians: villages.filter((v) => !v.player && !v.crown).length,
crowns: villages.filter((v) => v.crown).length,
}
})
@ -297,6 +298,7 @@ const continent = computed(() => (rounded.value ? continentOf(rounded.value.x, r
<li class="flex items-center gap-2"><span class="size-3 border border-wood-900 bg-[#d9b44a]" /> {{ $t('map.legend.own') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.own }}</span></li>
<li class="flex items-center gap-2"><span class="size-3 border border-wood-900 bg-[#962a1f]" /> {{ $t('map.legend.players') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.players }}</span></li>
<li class="flex items-center gap-2"><span class="size-3 border border-wood-900 bg-[#8b9094]" /> {{ $t('map.legend.barbarians') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.barbarians }}</span></li>
<li v-if="counts.crowns" class="flex items-center gap-2"><span class="size-3 border border-[#6b4f16] bg-[#d9b44a]" /> {{ $t('map.legend.crowns') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.crowns }}</span></li>
<li class="pt-1 text-xs text-ink-500">{{ $t('map.legend.lines') }}</li>
<li class="text-xs text-ink-500">{{ $t('map.controls') }}<template v-if="busy"> · {{ $t('common.loading') }}</template></li>
</ul>

View File

@ -44,10 +44,12 @@ async function resetMock() {
<p class="mt-0.5 flex flex-wrap gap-1.5">
<span class="badge badge-plain">{{ $t('worlds.speed_value', { speed: w.speed }) }}</span>
<span v-if="w.village_id" class="badge badge-moss">{{ $t('worlds.joined') }}</span>
<span v-if="w.ended_at" class="badge badge-plain">{{ w.winner ? $t('worlds.won_by', { player: w.winner.name }) : $t('worlds.ended') }}</span>
</p>
</div>
<div class="flex w-full gap-2 sm:w-auto">
<button
v-if="w.village_id || !w.ended_at"
type="button"
class="btn flex-1 sm:flex-none"
:class="w.village_id ? 'btn-primary' : 'btn-outline'"

View File

@ -63,6 +63,26 @@ export interface WorldSummary {
slug: string
speed: number
village_id: number | null
/** Set once someone won the world; it stays readable. */
ended_at: string | null
winner: { id: number; name: string } | null
}
/** A world as a season: crown forts appear round 0|0, holding most of them long enough wins. */
export interface SeasonState {
/** When the crowns appear, or appeared. */
crowns_at: string
count: number
/** Crowns a player must hold to start the clock. */
needed: number
/** How long the holder must keep them. */
hold_seconds: number
crowns: { id: number; name: string; x: number; y: number; player: { id: number; name: string } | null }[]
holder: { id: number; name: string } | null
/** When the holder wins if they keep the crowns. */
ends_at: string | null
ended_at: string | null
winner: { id: number; name: string } | null
}
/** `village.show`, and the reply to every `village.*` mutation. */
@ -95,6 +115,7 @@ export interface VillageState {
/** Building space: what buildings and queued new buildings take, out of the village maximum. */
space: { used: number; max: number }
specialisation: Specialisation
season: SeasonState
/** Amounts stored at `resources_at`. */
resources: Resources
resources_at: string

View File

@ -11,6 +11,8 @@ export interface MapVillage {
/** null for barbarian villages. */
player: { id: number; name: string } | null
own: boolean
/** A crown fort of the season. */
crown: boolean
}
/** `map.view {world_id, x?, y?, w, h}`: the w × h window around center, kept inside the map. */

View File

@ -8,6 +8,13 @@ export function formatDuration(totalSeconds: number) {
return `${Math.floor(s / 3600)}:${pad(Math.floor((s % 3600) / 60))}:${pad(s % 60)}`
}
/** Like formatDuration, with whole days in front once there are any: "3 d 4:05:00". */
export function formatSpan(totalSeconds: number, t: (key: string, values?: Record<string, unknown>) => string) {
const s = Math.max(0, Math.round(totalSeconds))
const days = Math.floor(s / 86400)
return days ? t('time.span_days', { days, time: formatDuration(s % 86400) }) : formatDuration(s)
}
export const formatAmount = (n: number) => String(Math.floor(n))
/** 12.5 → "+12.5", -3 → "-3" */

View File

@ -26,6 +26,7 @@ export default {
tomorrow: 'tomorrow at {time}',
yesterday: 'yesterday at {time}',
on: 'on {date} at {time}',
span_days: '{days} d {time}',
},
resources: {
wood: 'Wood',
@ -68,6 +69,7 @@ export default {
invalid_credentials: 'Wrong email or password.',
email_taken: 'This email is already registered.',
not_found: 'Not found.',
world_ended: 'This world has ended.',
no_space: 'Not enough building space.',
max_per_village: 'Only one of these per village.',
max_level: 'Already at max level.',

View File

@ -30,6 +30,7 @@ export default {
own: 'Your villages',
players: 'Other players',
barbarians: 'Barbarian villages',
crowns: 'Crown forts',
// {'|'} is a literal pipe: a bare | separates plural forms in vue-i18n.
lines: "Thin lines mark sectors of 10 fields, thick lines the continents of 100 (0{'|'}0 is the corner of K44, K45, K54 and K55).",
},

View File

@ -57,6 +57,16 @@ export default {
space: "Building space",
recruit_speed: "Training speed",
},
season: {
title: 'Season',
crowns_in: "Crown forts appear round 0{'|'}0 in {time}.",
rule: 'Hold {needed} of the {count} crown forts for {time} to win the world.',
holds: '{player} holds the crowns and wins in {time}.',
nobody: 'Nobody holds {needed} crowns yet.',
barbarians: 'Barbarians',
won: '{player} won this world.',
next: 'To the worlds',
},
role: {
title: 'Village role',
none: 'No role yet',

View File

@ -12,6 +12,8 @@ export default {
joined: 'Your village is here',
village: 'Your village',
join: 'Join',
ended: 'Ended',
won_by: 'Won by {player}',
open: 'Open village',
none: 'No worlds yet.',
reset: 'Reset mock data',