// Low-poly building models for the diorama, one per type and level tier. Each fits in // the square [-s, s] around its own origin and returns its faces and roof height. // Original shapes in the genre's style, solid from level 1: timber first, then bigger, // stone at high levels. import type { BuildingType } from '~/types/game' 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 = { wood: '#8a5f38', woodDark: '#6a4526', plank: '#a67c4e', thatch: '#b8984f', canvas: '#d6c7a0', canvasDark: '#b9a77f', roofRed: '#94452c', slate: '#575c63', stone: '#a39d92', stoneDark: '#847e74', field: '#8c9a4c', wheat: '#c4a552', furrow: '#9a7c44', soil: '#7d5c3a', leaf: '#56703a', leafDark: '#3f5a2c', trunk: '#5a3d24', clay: '#a8643f', clayDark: '#874c2f', clayWet: '#96583a', rock: '#8a857d', ore: '#4f5a63', fire: '#d98a2b', banner: '#7b1e16', hay: '#c9ad5e', cloth: '#6b4f3a', skin: '#d8a982', dark: '#2f2620', grass: '#78894a', conifer: '#3d5a2b', coniferDark: '#334d25', broadleaf: '#5a7339', broadleafDark: '#4c6431', bush: '#5f7a3c', barn: '#7c3f2c', shingle: '#6b4a30', metal: '#8b9094', water: '#5f7f87', chestnut: '#8a4f2a', bay: '#5e3a22', grey: '#b8b2a6', } export interface Model { faces: Face[] /** Highest point, for the level badge. */ height: number } /** 1 for levels 1–4, 2 for 5–14, 3 from 15 on. */ export const tier = (level: number) => (level < 5 ? 1 : level < 15 ? 2 : 3) // Small props function post(x: number, y: number, h: number, r: number, color = C.woodDark): Face[] { return prism(rect(x, y, r * 2, r * 2), 0, h, color) } function banner(x: number, y: number, h: number, size: number, color = C.banner): Face[] { return [ ...post(x, y, h, size * 0.035), plane( [ [x, y, h], [x - size * 0.05, y + size * 0.75, h - size * 0.1], [x - size * 0.05, y + size * 0.75, h - size * 0.5], [x, y, h - size * 0.42], ], color, ), ] } function crate(x: number, y: number, z: number, a: number): Face[] { return box(x, y, a, a, z, a, C.plank, C.wood) } export function tree(x: number, y: number, size: number, seed = 0): Face[] { const leaf = hash(seed, 3) > 0.5 ? C.leaf : C.leafDark const rot = hash(seed, 7) * Math.PI return [ ...prism(ngon(x, y, size * 0.09, 5, rot), 0, size * 0.32, C.trunk), ...pyramid(ngon(x, y, size * 0.48, 6, rot), size * 0.25, size * 0.75, leaf), ...pyramid(ngon(x, y, size * 0.34, 6, rot + 0.4), size * 0.68, size * 0.62, leaf), ] } export function rock(x: number, y: number, size: number, seed = 0, color = C.rock): Face[] { const base = ngon(x, y, size * 0.5, 5, hash(seed, 1) * 6).map(([px, py], i): V2 => { const k = 0.75 + 0.45 * hash(seed, i) return [x + (px - x) * k, y + (py - y) * k] }) return pyramid(base, 0, size * (0.45 + 0.3 * hash(seed, 9)), color, [x + size * 0.08, y - size * 0.06]) } // Landscape: lighter trees for the forest around the village (few faces each). /** A fir: two faceted tiers on a short trunk, the upper one a shade lighter. */ export function conifer(x: number, y: number, size: number, seed = 0): Face[] { const rot = hash(seed, 7) * Math.PI const color = hash(seed, 3) > 0.5 ? C.conifer : C.coniferDark return [ ...prism(ngon(x, y, size * 0.07, 4, rot), 0, size * 0.25, C.trunk), ...pyramid(ngon(x, y, size * 0.38, 5, rot), size * 0.18, size * 0.7, color), ...pyramid(ngon(x, y, size * 0.27, 5, rot + 0.6), size * 0.55, size * 0.68, scale(color, 1.1)), ] } /** A deciduous tree: a faceted crown (two pyramids back to back) on a trunk. */ export function broadleaf(x: number, y: number, size: number, seed = 0): Face[] { const rot = hash(seed, 5) * Math.PI const color = hash(seed, 4) > 0.5 ? C.broadleaf : C.broadleafDark const ring = ngon(x, y, size * 0.4, 5, rot) const mid = size * 0.62 // Downward cone under the crown, flipped so its faces point outwards. const bottom = pyramid(ring, mid, -size * 0.3, color).map((f) => ({ ...f, pts: orient(f.pts, [x, y, mid]) })) return [ ...prism(ngon(x, y, size * 0.07, 4, rot), 0, size * 0.36, C.trunk), ...bottom, ...pyramid(ring, mid, size * 0.42, color), ] } export function bush(x: number, y: number, size: number, seed = 0): Face[] { return pyramid(ngon(x, y, size * 0.4, 5, hash(seed, 2) * 6), 0, size * 0.35, C.bush) } /** The village well on the plaza. */ export function well(s: number): Model { return { faces: [ ...prism(ngon(0, 0, s * 0.42, 8), 0, s * 0.32, C.stone, C.dark), ...post(-s * 0.36, 0, s * 0.85, s * 0.05), ...post(s * 0.36, 0, s * 0.85, s * 0.05), ...house(0, 0, s * 0.95, s * 0.55, s * 0.85, s * 0.3, C.woodDark, C.roofRed, 'x').slice(5), ], height: s * 1.2, } } /** A villager: legs, a shirt and a head with hair, a few shaded faces. */ function person(x: number, y: number, s: number, shirt = C.cloth): Face[] { const r = s * 0.055 return [ ...prism(ngon(x, y, r * 0.8, 4, 0.4), 0, s * 0.09, C.dark), ...prism(ngon(x, y, r, 5), s * 0.09, s * 0.12, shirt), ...box(x, y, r * 1.2, r * 1.2, s * 0.21, r * 1.2, C.skin), ...box(x, y, r * 1.3, r * 1.3, s * 0.21 + r * 1.1, r * 0.35, C.woodDark), ] } function field(x: number, y: number, w: number, d: number, color: string, rows: number): Face[] { const faces: Face[] = [plane(rect(x, y, w, d).map(([px, py]) => [px, py, 0.6]), color)] for (let i = 1; i < rows; i++) { const fx = x - w / 2 + (w * i) / rows faces.push(plane([[fx - 0.5, y - d / 2 + 1, 0.8], [fx + 0.5, y - d / 2 + 1, 0.8], [fx + 0.5, y + d / 2 - 1, 0.8], [fx - 0.5, y + d / 2 - 1, 0.8]], C.furrow)) } return faces } function logPile(x: number, y: number, s: number, rows = 2): Face[] { const r = s * 0.09 const faces: Face[] = [] for (let row = 0; row < rows; row++) { const n = 3 - row for (let i = 0; i < n; i++) faces.push(...log(x, y - (n - 1) * r + i * r * 2, row * r * 1.7, s * 0.7, r, C.wood, C.plank)) } return faces } function bricks(x: number, y: number, s: number, layers: number): Face[] { const faces: Face[] = [] for (let i = 0; i < layers; i++) faces.push(...box(x, y, s * 0.3, s * 0.2, i * s * 0.08, s * 0.08, i % 2 ? C.clayDark : C.clay)) return faces } function fire(x: number, y: number, s: number): Face[] { const faces: Face[] = [] for (const [px, py] of ngon(x, y, s * 0.12, 6)) faces.push(...box(px, py, s * 0.05, s * 0.05, 0, s * 0.04, C.rock)) faces.push(...pyramid(ngon(x, y, s * 0.07, 4), 0, s * 0.2, C.fire).map((f) => ({ ...f, flat: true }))) return faces } function kiln(x: number, y: number, s: number): Face[] { return [ ...prism(ngon(x, y, s * 0.32, 7), 0, s * 0.4, C.clay, C.clayDark), ...pyramid(ngon(x, y, s * 0.32, 7), s * 0.4, s * 0.28, C.clayDark), ...box(x + s * 0.05, y - s * 0.05, s * 0.1, s * 0.1, s * 0.5, s * 0.35, C.stoneDark), ] } function headframe(x: number, y: number, s: number, h: number): Face[] { const a = s * 0.28 return [ ...post(x - a, y - a, h, s * 0.04), ...post(x + a, y - a, h, s * 0.04), ...post(x - a, y + a, h, s * 0.04), ...post(x + a, y + a, h, s * 0.04), ...box(x, y, a * 2.3, a * 2.3, h, s * 0.06, C.wood), ...pyramid(rect(x, y, a * 2.3, a * 2.3), h + s * 0.06, s * 0.25, C.woodDark), ] } // 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 } } /** Faces that must draw over a wall: sorted from `depth` on, in their own front-to-back order. */ function over(faces: Face[], depth: number): Face[] { const own = faces.map((f) => f.pts.reduce((n, [x, y, z]) => n + x + y + z, 0) / f.pts.length) const low = Math.min(...own) return faces.map((f, i) => ({ ...f, depth: depth + own[i]! - low })) } /** 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 siege engine in the making, facing +x: the frame on its wheels, two posts up. */ function frame(x: number, y: number, k: number): Face[] { return shift( [ ...[-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.plank, C.plank), ...post(-1.45 * k, -0.6 * k, 2.2 * k, 0.12 * k), ...post(1.45 * k, -0.6 * k, 2.2 * k, 0.12 * k), ...box(0, -0.6 * k, 3.1 * k, 0.12 * k, 2.1 * k, 0.12 * k, C.wood), ], 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.27, 0], [x1 + 0.1, y + d * 0.27, 0], [x1 + 0.1, y, h * 0.7]] : [[x - w * 0.27, y1 + 0.1, 0], [x + w * 0.27, y1 + 0.1, 0], [x, y1 + 0.1, h * 0.7]] 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 }, ...shift(along === 'x' ? post(x1, y, h * 0.2, w * 0.02) : post(x, y1, h * 0.2, d * 0.02), 0, 0, h * 0.94), ] } 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 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(-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.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, 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 * 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), ...openings(0, 0, s * 1.35, s * 1.35, 0, s * 0.9, C.stone), ...pyramid(rect(0, 0, s * 1.5, s * 1.5), s * 0.9, s * 0.65, 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), ...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), ...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.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: [...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: [ ...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.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, } }, farm(s, t) { if (t === 1) { return { faces: [ ...field(0, s * 0.3, s * 1.6, s * 1.0, C.wheat, 6), ...house(-s * 0.35, -s * 0.65, s * 0.7, s * 0.55, s * 0.4, s * 0.35, C.wood, C.thatch), ...person(s * 0.3, s * 0.3, s), ], height: s * 0.8, } } if (t === 2) { return { faces: [ ...field(-s * 0.4, s * 0.35, s * 1.05, s * 1.1, C.wheat, 4), ...field(s * 0.55, s * 0.35, s * 0.75, s * 1.1, C.field, 3), ...house(-s * 0.2, -s * 0.65, s * 0.9, s * 0.6, s * 0.45, s * 0.4, C.plank, C.roofRed), ...pyramid(ngon(s * 0.65, -s * 0.6, s * 0.22, 7), 0, s * 0.42, C.hay), ], height: s * 0.85, } } return { faces: [ ...field(-s * 0.3, s * 0.45, s * 1.3, s * 0.95, C.wheat, 5), ...field(s * 0.7, s * 0.45, s * 0.55, s * 0.95, C.field, 2), ...house(-s * 0.3, -s * 0.6, s * 1.1, s * 0.7, s * 0.6, s * 0.45, C.roofRed, C.slate), ...prism(ngon(s * 0.65, -s * 0.6, s * 0.22, 7), 0, s * 1.1, C.stone), ...pyramid(ngon(s * 0.65, -s * 0.6, s * 0.26, 7), s * 1.1, s * 0.3, C.slate), ], height: s * 1.4, } }, timber_camp(s, t) { if (t === 1) { return { faces: [ ...logPile(s * 0.2, s * 0.45, s, 2), ...post(-s * 0.75, -s * 0.15, s * 0.6, s * 0.04), ...post(-s * 0.15, -s * 0.15, s * 0.6, s * 0.04), ...post(-s * 0.75, -s * 0.75, s * 0.75, s * 0.04), ...post(-s * 0.15, -s * 0.75, s * 0.75, s * 0.04), plane([[-s * 0.85, -s * 0.85, s * 0.75], [-s * 0.05, -s * 0.85, s * 0.75], [-s * 0.05, -s * 0.05, s * 0.6], [-s * 0.85, -s * 0.05, s * 0.6]], C.woodDark), ...tree(s * 0.6, -s * 0.55, s * 1.1, 2), ...tree(-s * 0.7, s * 0.65, s * 0.9, 3), ], height: s * 1.1, } } if (t === 2) { return { faces: [ ...house(-s * 0.2, -s * 0.35, s * 1.1, s * 0.8, s * 0.5, s * 0.4, C.wood, C.plank), ...logPile(s * 0.25, s * 0.6, s, 2), ...tree(s * 0.7, -s * 0.6, s * 1.1, 4), ...tree(-s * 0.75, s * 0.7, s, 5), ], height: s * 1.1, } } return { faces: [ ...house(-s * 0.15, -s * 0.3, s * 1.35, s * 0.95, s * 0.6, s * 0.45, C.plank, C.roofRed), ...logPile(-s * 0.3, s * 0.7, s, 3), ...box(s * 0.55, s * 0.6, s * 0.5, s * 0.25, 0, s * 0.18, C.plank), ...tree(s * 0.75, -s * 0.7, s * 1.2, 6), ], height: s * 1.2, } }, clay_pit(s, t) { const pit = (x: number, y: number, r: number): Face[] => [ plane(ngon(x, y, r, 7, 0.2).map(([px, py]) => [px, py, 0.4]), C.clayDark), plane(ngon(x, y, r * 0.65, 7, 0.5).map(([px, py]) => [px, py, 0.6]), C.clayWet), ] if (t === 1) { return { faces: [...pit(-s * 0.2, s * 0.2, s * 0.6), ...bricks(s * 0.6, -s * 0.45, s, 4), ...bricks(s * 0.25, -s * 0.7, s, 3), ...person(s * 0.4, s * 0.3, s)], height: s * 0.45, } } if (t === 2) { return { faces: [...pit(-s * 0.3, s * 0.3, s * 0.55), ...kiln(s * 0.35, -s * 0.35, s), ...bricks(s * 0.65, s * 0.55, s, 5)], height: s * 0.85, } } return { faces: [ ...pit(-s * 0.35, s * 0.4, s * 0.5), ...kiln(s * 0.45, -s * 0.15, s), ...kiln(-s * 0.35, -s * 0.55, s), ...bricks(s * 0.65, s * 0.65, s, 6), ], height: s * 0.85, } }, iron_mine(s, t) { const outcrop = (k: number) => pyramid(ngon(-s * 0.2, -s * 0.25, s * 0.75 * k, 6, 0.4), 0, s * 0.95 * k, C.rock, [-s * 0.35, -s * 0.45]) const mouth = plane([[s * 0.32, -s * 0.35, 0], [s * 0.32, -s * 0.05, 0], [s * 0.2, -s * 0.05, s * 0.3], [s * 0.2, -s * 0.35, s * 0.3]], C.dark) const ore = (x: number, y: number) => pyramid(ngon(x, y, s * 0.18, 5), 0, s * 0.18, C.ore) if (t === 1) { return { faces: [ ...outcrop(1), mouth, ...post(s * 0.36, -s * 0.4, s * 0.38, s * 0.04), ...post(s * 0.36, 0, s * 0.38, s * 0.04), ...box(s * 0.36, -s * 0.2, s * 0.08, s * 0.5, s * 0.38, s * 0.06, C.woodDark), ...box(s * 0.6, s * 0.55, s * 0.3, s * 0.2, s * 0.04, s * 0.12, C.woodDark, C.ore), ...ore(s * 0.1, s * 0.6), ], height: s * 0.95, } } if (t === 2) return { faces: [...outcrop(1.05), mouth, ...headframe(s * 0.45, s * 0.35, s, s * 1.0), ...ore(-s * 0.5, s * 0.6)], height: s * 1.3 } return { faces: [ ...outcrop(1.15), mouth, ...headframe(s * 0.5, s * 0.25, s, s * 1.15), ...box(-s * 0.45, s * 0.6, s * 0.55, s * 0.45, 0, s * 0.4, C.stone), ...box(-s * 0.3, s * 0.5, s * 0.12, s * 0.12, s * 0.4, s * 0.5, C.stoneDark), { pts: ngon(-s * 0.3, s * 0.5, s * 0.05, 4).map(([x, y]): V3 => [x, y, s * 0.92]), color: C.fire, flat: true }, ], height: s * 1.45, } }, hiding_place(s, t) { const door = plane([[s * 0.45, -s * 0.2, 0], [s * 0.45, s * 0.2, 0], [s * 0.45, s * 0.2, s * 0.35], [s * 0.45, -s * 0.2, s * 0.35]], C.dark) if (t === 1) return { faces: [...pyramid(rect(0, 0, s * 1.2, s * 1.2), 0, s * 0.55, C.grass), door], height: s * 0.55 } return { faces: [...box(0, 0, s * 1.0, s * 1.0, 0, s * 0.4, C.stone), ...pyramid(rect(0, 0, s * 1.1, s * 1.1), s * 0.4, s * 0.3, C.grass), shift([door], s * 0.06, 0)[0]!], height: s * 0.7, } }, rally_point(s, t) { const stones: Face[] = ngon(0, 0, s * 0.6, 8).flatMap(([x, y]) => box(x, y, s * 0.14, s * 0.14, 0, s * 0.1, C.stone)) return { faces: [ ...box(0, 0, s * 0.9, s * 0.9, 0, s * 0.15, C.plank, C.wood), ...banner(-s * 0.3, -s * 0.3, s * 1.8, s * 0.8), ...banner(s * 0.3, s * 0.3, s * 1.5, s * 0.7, C.slate), ], height: s * 1.8, } }, // A lookout on stilts first, then a planked tower, then stone with a slate roof. watchtower(s, t) { // Four corner posts from z0 up to z0 + h, `r` from the middle. const corners = (r: number, z0: number, h: number) => [-1, 1].flatMap((dx) => [-1, 1].flatMap((dy) => prism(rect(dx * r, dy * r, s * 0.1, s * 0.1), z0, h, C.woodDark))) if (t === 1) { return { faces: [ ...corners(s * 0.32, 0, s * 1.5), ...box(0, 0, s * 0.85, s * 0.85, s * 1.5, s * 0.12, C.plank, C.wood), ...corners(s * 0.36, s * 1.62, s * 0.25), ...pyramid(rect(0, 0, s * 0.95, s * 0.95), s * 1.87, s * 0.45, C.thatch), ], height: s * 2.3, } } if (t === 2) { return { faces: [ ...box(0, 0, s * 0.8, s * 0.8, 0, s * 1.7, C.plank, C.wood), ...box(0, 0, s * 1.0, s * 1.0, s * 1.7, s * 0.14, C.wood), ...corners(s * 0.44, s * 1.84, s * 0.28), ...pyramid(rect(0, 0, s * 1.05, s * 1.05), s * 2.12, s * 0.5, C.roofRed), ...banner(0, 0, s * 3.0, s * 0.55), ], height: s * 3.0, } } return { faces: [ ...prism(ngon(0, 0, s * 0.55, 8), 0, s * 2.2, C.stone, C.stoneDark), ...prism(ngon(0, 0, s * 0.7, 8), s * 2.2, s * 0.25, C.stoneDark, C.plank), ...pyramid(ngon(0, 0, s * 0.72, 8), s * 2.45, s * 0.65, C.slate), plane([[s * 0.55, -s * 0.12, 0], [s * 0.55, s * 0.12, 0], [s * 0.55, s * 0.12, s * 0.45], [s * 0.55, -s * 0.12, s * 0.45]], C.dark), ...banner(0, 0, s * 3.5, s * 0.6), ], height: s * 3.5, } }, // 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: [ ...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.4, s * 0.65, s, 'x'), ...dummy(s * 0.8, -s * 0.2, s), ...fire(s * 0.4, s * 0.15, s), ...banner(-s * 0.95, -s * 0.85, s * 1.15, s * 0.45), ], 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( ...over(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]!, ), yDepth + 0.3), ) } } 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: wheels stand in a row by the door, timbers lie ready. // An open shed with a wheeled frame in the making first, then a ram ready in front, // then a stone hall with a ram and a catapult. workshop(s, t) { const shed = (x0: number, y0: number, x1: number, y1: number, h: number, roof: string): Face[] => { const inside = scale(C.plank, 0.55) 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]], inside), plane([[x0, y0, 0], [x0, y1, 0], [x0, y1, h], [x0, y0, h]], scale(inside, 0.9)), ...[x0, (x0 + x1) / 2, x1].flatMap((x) => [...post(x, y1, h, s * 0.045), ...post(x, y0, h, s * 0.045)]), ...post(x1, (y0 + y1) / 2, h, s * 0.045), ...gable(x0 - s * 0.06, y0 - s * 0.06, x1 + s * 0.06, y1 + s * 0.06, h, s * 0.3, 'x', roof, C.wood), ] } /** Finished wheels standing in a row along y, faces to the viewer. */ const wheels = (x: number, y: number, n: number) => Array.from({ length: n }, (_, i) => wheel(x, y + i * s * 0.34, s * 0.17, 'x')).flat() if (t === 1) { return { faces: [ ...shed(-s * 0.9, -s * 0.9, s * 0.2, -s * 0.15, s * 0.62, C.thatch), ...wheel(-s * 0.55, -s * 0.78, s * 0.2, 'y'), ...wheel(-s * 0.15, -s * 0.78, s * 0.2, 'y'), ...frame(s * 0.05, s * 0.35, s * 0.15), ...wheels(s * 0.75, -s * 0.6, 2), ...timbers(-s * 0.5, s * 0.6, s), ], height: s * 0.95, } } if (t === 2) { return { faces: [ ...shed(-s * 0.95, -s * 0.95, s * 0.35, -s * 0.15, s * 0.68, C.shingle), ...wheel(-s * 0.65, -s * 0.83, s * 0.2, 'y'), ...wheel(-s * 0.25, -s * 0.83, s * 0.2, 'y'), ...frame(-s * 0.3, -s * 0.45, s * 0.13), ...ram(s * 0.05, s * 0.4, s * 0.16), ...wheels(s * 0.8, -s * 0.75, 3), ...timbers(-s * 0.65, s * 0.55, s, 3), ], height: s * 1.05, } } return { faces: [ ...house(-s * 0.3, -s * 0.62, s * 1.35, s * 0.72, s * 0.62, s * 0.42, 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.42, s * 0.15), ...catapult(s * 0.62, s * 0.25, s * 0.15), ...wheels(s * 0.85, -s * 0.85, 2), ...timbers(-s * 0.1, s * 0.92, s, 2), ], height: s * 1.2, } }, // The academy (Adelshof): a stone manor with towers. academy(s, t) { const tower = (x: number, y: number, h: number): Face[] => [ ...prism(ngon(x, y, s * 0.24, 6), 0, h, C.stone), ...pyramid(ngon(x, y, s * 0.3, 6), h, s * 0.4, C.slate), ] return { faces: [ ...box(0, 0, s * 1.6, s * 1.3, 0, s * 0.9, C.stone, C.stoneDark), ...openings(0, 0, s * 1.6, s * 1.3, 0, s * 0.9, C.stone), ...pyramid(rect(0, 0, s * 1.75, s * 1.45), s * 0.9, s * 0.6, C.slate), ...tower(-s * 0.85, -s * 0.7, s * 1.5), ...tower(s * 0.85, s * 0.7, s * 1.5), ...banner(0, s * 0.75, s * 1.9, s * 0.6), ], height: s * 1.9, } }, // The wall is drawn as the ring around the village, see scene.ts. wall: () => ({ faces: [], height: 0 }), } export function buildingModel(type: BuildingType, level: number, s: number): Model { return models[type](s, tier(level)) } /** A queued new building: posts, planks and its outline on the ground. */ export function scaffold(s: number): Model { const a = s * 0.6 return { faces: [ plane(rect(0, 0, a * 2.1, a * 2.1).map(([x, y]) => [x, y, 0.5]), C.soil), ...post(-a, -a, s * 0.75, s * 0.035), ...post(a, -a, s * 0.75, s * 0.035), ...post(-a, a, s * 0.75, s * 0.035), ...post(a, a, s * 0.75, s * 0.035), ...box(0, a, a * 2.1, s * 0.05, s * 0.45, s * 0.05, C.plank), ...box(a, 0, s * 0.05, a * 2.1, s * 0.6, s * 0.05, C.plank), ...crate(-a * 0.3, a * 0.2, 0, s * 0.22), ], height: s * 0.8, } } /** A small crane beside a building that is being upgraded or taken down. */ export function crane(s: number, height: number): Face[] { const x = s * 0.85 const y = -s * 0.85 const h = height + s * 0.35 return [ ...post(x, y, h, s * 0.045, C.woodDark), ...box(x - s * 0.3, y, s * 0.75, s * 0.06, h, s * 0.06, C.wood), ...box(x - s * 0.6, y, s * 0.02, s * 0.02, h - s * 0.4, s * 0.4, C.dark), ...crate(x - s * 0.6, y, h - s * 0.55, s * 0.14), ] }