feat: grim, war-worn village: cold overcast light, a dark desaturated palette, mud, ruts and puddles, rotten roofs, stumps and dead trees, a graveyard, the gallows, a burnt farmstead, blood on the training yard and rally ground, drab clothes, sooty smoke and crows

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-30 10:26:43 +01:00
parent bcba3edf73
commit 6ef5c3981e
10 changed files with 508 additions and 152 deletions

View File

@ -18,22 +18,22 @@ const peck = computed(() => (props.kind === 'chicken' ? 0.7 : 2.2))
<g> <g>
<g :transform="`scale(${size})`"> <g :transform="`scale(${size})`">
<template v-if="kind === 'sheep'"> <template v-if="kind === 'sheep'">
<path d="M-1 -0.9h0.6V0h-0.6zM1.2 -0.9h0.6V0h-0.6z" fill="#3a2a1c" /> <path d="M-1 -0.9h0.6V0h-0.6zM1.2 -0.9h0.6V0h-0.6z" fill="#211c18" />
<path d="M-2.2 -3.4Q-2.4 -1 -0.6 -0.7H2Q3 -1.6 2.4 -3.4Q0.2 -4.6 -2.2 -3.4z" fill="#e8e1cf" /> <path d="M-2.2 -3.4Q-2.4 -1 -0.6 -0.7H2Q3 -1.6 2.4 -3.4Q0.2 -4.6 -2.2 -3.4z" fill="#9b9483" />
<path d="M0.2 -0.7H2Q3 -1.6 2.4 -3.4Q1.4 -3.9 0.2 -3.9z" fill="#c9c1ad" /> <path d="M0.2 -0.7H2Q3 -1.6 2.4 -3.4Q1.4 -3.9 0.2 -3.9z" fill="#7f796b" />
<g> <g>
<animateTransform attributeName="transform" type="rotate" :values="`0 2.2 -2.6;28 2.2 -2.6;28 2.2 -2.6;0 2.2 -2.6;0 2.2 -2.6`" keyTimes="0;0.15;0.6;0.75;1" :dur="`${peck}s`" :begin="`${begin}s`" repeatCount="indefinite" /> <animateTransform attributeName="transform" type="rotate" :values="`0 2.2 -2.6;28 2.2 -2.6;28 2.2 -2.6;0 2.2 -2.6;0 2.2 -2.6`" keyTimes="0;0.15;0.6;0.75;1" :dur="`${peck}s`" :begin="`${begin}s`" repeatCount="indefinite" />
<path d="M2.1 -3.3L3.7 -3.1L3.6 -1.9L2.3 -2.1z" fill="#3a2a1c" /> <path d="M2.1 -3.3L3.7 -3.1L3.6 -1.9L2.3 -2.1z" fill="#211c18" />
</g> </g>
</template> </template>
<template v-else> <template v-else>
<path d="M-0.3 -0.8h0.3V0h-0.3zM0.4 -0.8h0.3V0h-0.3z" fill="#c49a2c" /> <path d="M-0.3 -0.8h0.3V0h-0.3zM0.4 -0.8h0.3V0h-0.3z" fill="#8a6c32" />
<path d="M-1.4 -2.6Q-1.2 -0.7 0.4 -0.8Q1.4 -1.2 1.2 -2.2Q0 -3.2 -1.4 -2.6z" fill="#f0e8d6" /> <path d="M-1.4 -2.6Q-1.2 -0.7 0.4 -0.8Q1.4 -1.2 1.2 -2.2Q0 -3.2 -1.4 -2.6z" fill="#6e5236" />
<g> <g>
<animateTransform attributeName="transform" type="rotate" values="0 1 -2.2;40 1 -2.2;0 1 -2.2;0 1 -2.2" keyTimes="0;0.2;0.4;1" :dur="`${peck}s`" :begin="`${begin}s`" repeatCount="indefinite" /> <animateTransform attributeName="transform" type="rotate" values="0 1 -2.2;40 1 -2.2;0 1 -2.2;0 1 -2.2" keyTimes="0;0.2;0.4;1" :dur="`${peck}s`" :begin="`${begin}s`" repeatCount="indefinite" />
<path d="M0.8 -3.4L1.7 -3.2L1.6 -2.2L0.9 -2.3z" fill="#f0e8d6" /> <path d="M0.8 -3.4L1.7 -3.2L1.6 -2.2L0.9 -2.3z" fill="#6e5236" />
<path d="M1.7 -3L2.3 -2.7L1.7 -2.5z" fill="#c49a2c" /> <path d="M1.7 -3L2.3 -2.7L1.7 -2.5z" fill="#8a6c32" />
<path d="M0.9 -3.6L1.4 -3.9L1.4 -3.3z" fill="#9b2a1c" /> <path d="M0.9 -3.6L1.4 -3.9L1.4 -3.3z" fill="#6e1c14" />
</g> </g>
</template> </template>
</g> </g>

View File

@ -2,13 +2,13 @@
defineProps<{ d: string; dur: number; begin: number; size: number }>() defineProps<{ d: string; dur: number; begin: number; size: number }>()
</script> </script>
<!-- A bird crossing the land, two flat wings beating. --> <!-- A crow crossing the land or circling, two black wings beating. -->
<template> <template>
<g> <g>
<g :transform="`scale(${size})`"> <g :transform="`scale(${size})`">
<g> <g>
<animateTransform attributeName="transform" type="scale" values="1 1;1 -0.6;1 1" keyTimes="0;0.5;1" dur="0.45s" :begin="`${begin}s`" repeatCount="indefinite" /> <animateTransform attributeName="transform" type="scale" values="1 1;1 -0.6;1 1" keyTimes="0;0.5;1" dur="0.45s" :begin="`${begin}s`" repeatCount="indefinite" />
<path d="M0 0L-3.2 -1.4L-1.4 0.2zM0 0L3.2 -1.4L1.4 0.2z" fill="#2f2620" /> <path d="M0 0L-3.8 -1.6L-1.6 0.3zM0 0L3.8 -1.6L1.6 0.3zM-0.5 -0.3H0.5V0.6H-0.5z" fill="#121212" />
</g> </g>
</g> </g>
<animateMotion :dur="`${dur}s`" :begin="`${begin}s`" repeatCount="indefinite" :path="d" /> <animateMotion :dur="`${dur}s`" :begin="`${begin}s`" repeatCount="indefinite" :path="d" />

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { BuildingType } from '~/types/game' import type { BuildingType } from '~/types/game'
import { mix, plane, project, toPolys, type V3 } from '~/diorama/iso' import { mix, plane, project, toPolys, type V3 } from '~/diorama/iso'
import { buildingModel } from '~/diorama/models' import { buildingModel, C } from '~/diorama/models'
const props = defineProps<{ type: BuildingType; level: number }>() const props = defineProps<{ type: BuildingType; level: number }>()
@ -15,8 +15,8 @@ const picture = computed(() => {
const r = S * (1.45 + 0.08 * Math.sin(i * 2.3)) const r = S * (1.45 + 0.08 * Math.sin(i * 2.3))
return [Math.cos(a) * r, Math.sin(a) * r, 0] return [Math.cos(a) * r, Math.sin(a) * r, 0]
}) })
const ground = toPolys([plane(patch, '#7f8f4b')]) const ground = toPolys([plane(patch, C.grass)])
const rim = toPolys([plane(patch.map(([x, y]): V3 => [x * 1.06, y * 1.06, -3]), mix('#7f8f4b', '#3e2b1a', 0.45))]) const rim = toPolys([plane(patch.map(([x, y]): V3 => [x * 1.06, y * 1.06, -3]), mix(C.grass, C.dark, 0.45))])
const polys = [...rim, ...ground, ...toPolys(model.faces)] const polys = [...rim, ...ground, ...toPolys(model.faces)]
const pts = polys.flatMap((p) => p.points.split(' ').map((xy) => xy.split(',').map(Number) as [number, number])) const pts = polys.flatMap((p) => p.points.split(' ').map((xy) => xy.split(',').map(Number) as [number, number]))
const top = project([0, 0, model.height])[1] const top = project([0, 0, model.height])[1]

View File

@ -2,6 +2,7 @@
import type { BuildingType } from '~/types/game' import type { BuildingType } from '~/types/game'
import { buildCloseup, type CloseupState } from '~/diorama/closeup' import { buildCloseup, type CloseupState } from '~/diorama/closeup'
import { drillThrust, workInPlace } from '~/diorama/life' import { drillThrust, workInPlace } from '~/diorama/life'
import { SHIRTS, UNIFORM } from '~/diorama/models'
const props = defineProps<{ const props = defineProps<{
type: BuildingType type: BuildingType
@ -33,12 +34,11 @@ const drilling = drillThrust()
// Workers only walk for players who don't ask for reduced motion. // Workers only walk for players who don't ask for reduced motion.
const motion = ref(false) const motion = ref(false)
onMounted(() => (motion.value = !window.matchMedia('(prefers-reduced-motion: reduce)').matches)) onMounted(() => (motion.value = !window.matchMedia('(prefers-reduced-motion: reduce)').matches))
const SHIRTS = ['#6b4f3a', '#7b1e16', '#3d5a26', '#57391f', '#5a5f63']
</script> </script>
<!-- The building up close, its workers walking between it and where they work. --> <!-- The building up close, its workers walking between it and where they work. -->
<template> <template>
<div ref="stage" class="h-full w-full overflow-hidden bg-[#74864a]"> <div ref="stage" class="h-full w-full overflow-hidden bg-[#4f5436]">
<svg class="block h-full w-full select-none" :viewBox="scene.viewBox" preserveAspectRatio="xMidYMid slice" aria-hidden="true"> <svg class="block h-full w-full select-none" :viewBox="scene.viewBox" preserveAspectRatio="xMidYMid slice" aria-hidden="true">
<g stroke-width="0.6" stroke-linejoin="round"> <g stroke-width="0.6" stroke-linejoin="round">
<polygon v-for="(p, i) in scene.terrain" :key="`t${i}`" :points="p.points" :fill="p.fill" :stroke="p.stroke" /> <polygon v-for="(p, i) in scene.terrain" :key="`t${i}`" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
@ -64,7 +64,7 @@ const SHIRTS = ['#6b4f3a', '#7b1e16', '#3d5a26', '#57391f', '#5a5f63']
/> />
</template> </template>
<g v-else-if="l.life" :transform="`translate(${l.life.at[0]} ${l.life.at[1]}) scale(2.6)`"> <g v-else-if="l.life" :transform="`translate(${l.life.at[0]} ${l.life.at[1]}) scale(2.6)`">
<VillageWalker v-if="l.life.guard" shirt="#57391f" :facing="l.life.facing" tool="spear" soldier /> <VillageWalker v-if="l.life.guard" :shirt="UNIFORM" :facing="l.life.facing" tool="spear" soldier />
<VillageWalker v-else :shirt="SHIRTS[i % SHIRTS.length]!" :facing="l.life.facing" :tool="l.life.tool" :swing="motion && l.life.tool ? (l.life.drill ? drilling : hammering) : null" /> <VillageWalker v-else :shirt="SHIRTS[i % SHIRTS.length]!" :facing="l.life.facing" :tool="l.life.tool" :swing="motion && l.life.tool ? (l.life.drill ? drilling : hammering) : null" />
</g> </g>
<g v-else v-memo="[l]" stroke-width="0.6" stroke-linejoin="round"> <g v-else v-memo="[l]" stroke-width="0.6" stroke-linejoin="round">

View File

@ -2,6 +2,7 @@
import type { BuildingType, Resources, VillageState } from '~/types/game' import type { BuildingType, Resources, VillageState } from '~/types/game'
import { drillThrust, workInPlace } from '~/diorama/life' import { drillThrust, workInPlace } from '~/diorama/life'
import { buildScene, type SceneBuilding, type SceneInset, type ScenePlot } from '~/diorama/scene' import { buildScene, type SceneBuilding, type SceneInset, type ScenePlot } from '~/diorama/scene'
import { SHIRTS, SMOKE, UNIFORM } from '~/diorama/models'
import type { BuildingTag } from '~/utils/buildingTags' import type { BuildingTag } from '~/utils/buildingTags'
const props = defineProps<{ const props = defineProps<{
@ -51,9 +52,6 @@ onBeforeUnmount(() => observer?.disconnect())
// Walkers and smoke only move for players who don't ask for reduced motion. // Walkers and smoke only move for players who don't ask for reduced motion.
const motion = ref(false) const motion = ref(false)
onMounted(() => (motion.value = !window.matchMedia('(prefers-reduced-motion: reduce)').matches)) onMounted(() => (motion.value = !window.matchMedia('(prefers-reduced-motion: reduce)').matches))
const SHIRTS = ['#6b4f3a', '#7b1e16', '#3d5a26', '#57391f', '#5a5f63']
/** Soldiers wear the village colour under the shield. */
const UNIFORM = '#57391f'
const name = (b: SceneBuilding) => t(`buildings.${b.type}`) const name = (b: SceneBuilding) => t(`buildings.${b.type}`)
const label = (b: SceneBuilding) => t('village.diorama.label', { name: name(b), level: b.level }) const label = (b: SceneBuilding) => t('village.diorama.label', { name: name(b), level: b.level })
@ -151,7 +149,7 @@ const timers = computed(() => {
</script> </script>
<template> <template>
<div ref="scroller" class="h-full w-full overflow-y-hidden bg-[#74864a]" :class="fill ? 'overflow-x-hidden' : 'overflow-x-auto'"> <div ref="scroller" class="h-full w-full overflow-y-hidden bg-[#4f5436]" :class="fill ? 'overflow-x-hidden' : 'overflow-x-auto'">
<div ref="stage" class="h-full" :class="fill ? '' : 'min-w-[640px]'"> <div ref="stage" class="h-full" :class="fill ? '' : 'min-w-[640px]'">
<svg <svg
class="block h-full w-full select-none" class="block h-full w-full select-none"
@ -285,7 +283,7 @@ const timers = computed(() => {
</template> </template>
<!-- Smoke from chimneys, forges and kilns: flat puffs that rise, drift and shrink away. --> <!-- Smoke from chimneys, forges and kilns: flat puffs that rise, drift and shrink away. -->
<g v-if="motion" class="pointer-events-none" fill="#d6cfbf" stroke="#b3ab98" stroke-width="0.5"> <g v-if="motion" class="pointer-events-none" :fill="SMOKE.fill" :stroke="SMOKE.edge" stroke-width="0.5">
<g v-for="(p, i) in scene.smoke" :key="`smoke-${i}`" :transform="`translate(${p[0]} ${p[1]})`"> <g v-for="(p, i) in scene.smoke" :key="`smoke-${i}`" :transform="`translate(${p[0]} ${p[1]})`">
<circle v-for="n in 3" :key="n" class="puff" r="5.5" :style="{ animationDelay: `${-(n * 1.3 + i * 0.9)}s` }" /> <circle v-for="n in 3" :key="n" class="puff" r="5.5" :style="{ animationDelay: `${-(n * 1.3 + i * 0.9)}s` }" />
</g> </g>

View File

@ -28,8 +28,8 @@ const toolDur = computed(() => `${props.cycle?.dur ?? props.swing?.dur ?? 1}s`)
/** Rotation values about the shoulder, where the hand holds the tool. */ /** Rotation values about the shoulder, where the hand holds the tool. */
const swingValues = computed(() => toolSwing.value?.values.split(';').map((a) => `${a} 1.1 -6.4`).join(';') ?? '') const swingValues = computed(() => toolSwing.value?.values.split(';').map((a) => `${a} 1.1 -6.4`).join(';') ?? '')
const METAL = '#8b9094' const METAL = '#6e7376'
const HANDLE = '#6a4526' const HANDLE = '#4a3a2c'
const HEADS: Record<Tool, string> = { const HEADS: Record<Tool, string> = {
axe: 'M3.3 -11.4L5.5 -10.5L5 -9.3L3.6 -10.1z', axe: 'M3.3 -11.4L5.5 -10.5L5 -9.3L3.6 -10.1z',
pick: 'M2.1 -11.7L5.7 -10.1L5.4 -9.7L3.8 -10.5L2.3 -11.1z', pick: 'M2.1 -11.7L5.7 -10.1L5.4 -9.7L3.8 -10.5L2.3 -11.1z',
@ -67,21 +67,21 @@ const HEADS: Record<Tool, string> = {
:begin="begin" :begin="begin"
repeatCount="indefinite" repeatCount="indefinite"
/> />
<rect x="-1.5" y="-2.4" width="1.2" height="2.4" fill="#3a2a1c"> <rect x="-1.5" y="-2.4" width="1.2" height="2.4" fill="#2c2620">
<animateTransform v-if="cycle" attributeName="transform" type="translate" :values="cycle.step.values" :keyTimes="cycle.step.keyTimes" :dur="`${cycle.dur}s`" :begin="begin" repeatCount="indefinite" /> <animateTransform v-if="cycle" attributeName="transform" type="translate" :values="cycle.step.values" :keyTimes="cycle.step.keyTimes" :dur="`${cycle.dur}s`" :begin="begin" repeatCount="indefinite" />
</rect> </rect>
<rect x="0.3" y="-2.4" width="1.2" height="2.4" fill="#2f2219"> <rect x="0.3" y="-2.4" width="1.2" height="2.4" fill="#221d18">
<animateTransform v-if="cycle" attributeName="transform" type="translate" :values="cycle.step.mirrored" :keyTimes="cycle.step.keyTimes" :dur="`${cycle.dur}s`" :begin="begin" repeatCount="indefinite" /> <animateTransform v-if="cycle" attributeName="transform" type="translate" :values="cycle.step.mirrored" :keyTimes="cycle.step.keyTimes" :dur="`${cycle.dur}s`" :begin="begin" repeatCount="indefinite" />
</rect> </rect>
<path d="M-1.9 -6.9L0 -7.3V-2.2H-1.7z" :fill="shirt" /> <path d="M-1.9 -6.9L0 -7.3V-2.2H-1.7z" :fill="shirt" />
<path d="M0 -7.3L1.9 -6.9L1.7 -2.2H0z" :fill="shirtShade" /> <path d="M0 -7.3L1.9 -6.9L1.7 -2.2H0z" :fill="shirtShade" />
<circle cy="-8.9" r="1.65" fill="#d8a982" /> <circle cy="-8.9" r="1.65" fill="#a98a72" />
<template v-if="soldier"> <template v-if="soldier">
<path d="M-1.85 -9Q-1.8 -11.2 0 -11.3Q1.8 -11.2 1.85 -9z" :fill="METAL" /> <path d="M-1.85 -9Q-1.8 -11.2 0 -11.3Q1.8 -11.2 1.85 -9z" :fill="METAL" />
<path d="M0 -11.3Q1.8 -11.2 1.85 -9H0z" fill="#6f7478" /> <path d="M0 -11.3Q1.8 -11.2 1.85 -9H0z" fill="#4f5356" />
<path d="M0.75 -9H1.15V-7.9H0.75z" fill="#6f7478" /> <path d="M0.75 -9H1.15V-7.9H0.75z" fill="#4f5356" />
</template> </template>
<path v-else d="M-1.7 -9.1Q0 -11.5 1.7 -9.1Q0 -9.9 -1.7 -9.1z" fill="#4a3220" /> <path v-else d="M-1.7 -9.1Q0 -11.5 1.7 -9.1Q0 -9.9 -1.7 -9.1z" fill="#2a211a" />
<g v-if="tool"> <g v-if="tool">
<animateTransform <animateTransform
@ -100,9 +100,9 @@ const HEADS: Record<Tool, string> = {
</g> </g>
<g v-if="soldier"> <g v-if="soldier">
<path d="M-0.1 -6.9H2.5V-4.7Q2.5 -3.1 1.2 -2.1Q-0.1 -3.1 -0.1 -4.7z" fill="#7b1e16" /> <path d="M-0.1 -6.9H2.5V-4.7Q2.5 -3.1 1.2 -2.1Q-0.1 -3.1 -0.1 -4.7z" fill="#5e1813" />
<path d="M1.2 -6.9H2.5V-4.7Q2.5 -3.1 1.2 -2.1z" fill="#5c1610" /> <path d="M1.2 -6.9H2.5V-4.7Q2.5 -3.1 1.2 -2.1z" fill="#3f100d" />
<path d="M1 -6.9H1.4V-2.3L1.2 -2.1L1 -2.3z" fill="#d6c7a0" /> <path d="M1 -6.9H1.4V-2.3L1.2 -2.1L1 -2.3z" fill="#7d735f" />
</g> </g>
<g v-if="carry" :visibility="cycle ? 'hidden' : 'visible'"> <g v-if="carry" :visibility="cycle ? 'hidden' : 'visible'">

View File

@ -6,8 +6,8 @@
import type { BuildingType } from '~/types/game' import type { BuildingType } from '~/types/game'
import { box, DOOR, type Face, hash, ngon, plane, type Poly, project, pyramid, rect, scale, toPolys, type V2, type V3 } from './iso' import { box, DOOR, type Face, hash, ngon, plane, type Poly, project, pyramid, rect, scale, toPolys, type V2, type V3 } from './iso'
import type { Tool } from './life' import type { Tool } from './life'
import { broadleaf, buildingModel, bush, C, conifer, rock } from './models' import { broadleaf, buildingModel, bush, C, conifer, deadTree, rock, stump } from './models'
import { disc, ground, guardSpots, guardsAt, shadow, U, wallSegments } from './scene' import { disc, fade, ground, guardSpots, guardsAt, shadow, U, wallSegments } from './scene'
export interface Closeup { export interface Closeup {
viewBox: string viewBox: string
@ -55,12 +55,12 @@ export interface CloseupState {
type Kind = 'timber' | 'clay' | 'iron' | 'farm' | 'wall' | 'core' type Kind = 'timber' | 'clay' | 'iron' | 'farm' | 'wall' | 'core'
const KIND: Partial<Record<BuildingType, Kind>> = { timber_camp: 'timber', clay_pit: 'clay', iron_mine: 'iron', farm: 'farm', wall: 'wall' } const KIND: Partial<Record<BuildingType, Kind>> = { timber_camp: 'timber', clay_pit: 'clay', iron_mine: 'iron', farm: 'farm', wall: 'wall' }
const GROUND: Record<Kind, string> = { const GROUND: Record<Kind, string> = {
timber: '#76703f', timber: '#554a33',
clay: '#8d5a3b', clay: '#5f3f2c',
iron: '#7c776a', iron: '#55524c',
farm: '#7f8f4b', farm: '#4f5436',
wall: '#8c7350', wall: '#463829',
core: '#a3885c', core: '#564533',
} }
/** What a worker carries home: logs, clay, ore, sheaves; core buildings move crates. */ /** What a worker carries home: logs, clay, ore, sheaves; core buildings move crates. */
const CARRY: Record<Kind, string | null> = { timber: C.wood, clay: C.clay, iron: C.ore, farm: C.wheat, wall: null, core: C.plank } const CARRY: Record<Kind, string | null> = { timber: C.wood, clay: C.clay, iron: C.ore, farm: C.wheat, wall: null, core: C.plank }
@ -100,7 +100,7 @@ export function buildCloseup(type: BuildingType, level: number, workers: number,
objects.push({ key: 'building', depth: 0, polys: toPolys(model.faces) }) objects.push({ key: 'building', depth: 0, polys: toPolys(model.faces) })
const doorFace = model.faces.find((f) => f.color === DOOR) const doorFace = model.faces.find((f) => f.color === DOOR)
if (doorFace) door = [doorFace.pts.reduce((n, p) => n + p[0], 0) / doorFace.pts.length + U * 0.3, doorFace.pts.reduce((n, p) => n + p[1], 0) / doorFace.pts.length] if (doorFace) door = [doorFace.pts.reduce((n, p) => n + p[0], 0) / doorFace.pts.length + U * 0.3, doorFace.pts.reduce((n, p) => n + p[1], 0) / doorFace.pts.length]
shadows.push(shadow(0, 0, S * 0.95, scale(GROUND[kind], 0.8), 3)) shadows.push(shadow(0, 0, S * 0.95, scale(GROUND[kind], 0.68), 3))
} }
if (kind === 'timber') { if (kind === 'timber') {
@ -109,6 +109,11 @@ export function buildCloseup(type: BuildingType, level: number, workers: number,
put(`tree${i}`, x, y, conifer(x, y, U * (1.4 + 0.4 * hash(i, 3)), i), U * 0.7) put(`tree${i}`, x, y, conifer(x, y, U * (1.4 + 0.4 * hash(i, 3)), i), U * 0.7)
spots.push([x * 0.85, y * 0.85]) spots.push([x * 0.85, y * 0.85])
} }
// Stumps of the trees already felled, between the camp and the standing ones.
for (let i = 0; i < 7; i++) {
const [x, y] = at(deg(-70 + i * 30 + (hash(i, 6) - 0.5) * 16), S * (1.75 + 0.35 * hash(i, 7)))
put(`stump${i}`, x, y, stump(x, y, U * 1.4, 50 + i), U * 0.2)
}
} else if (kind === 'clay') { } else if (kind === 'clay') {
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
const [x, y] = at(deg(-20 + i * 42), S * 2.2) const [x, y] = at(deg(-20 + i * 42), S * 2.2)
@ -151,7 +156,8 @@ export function buildCloseup(type: BuildingType, level: number, workers: number,
const kindRoll = hash(i, j, 64) const kindRoll = hash(i, j, 64)
const size = U * (1.0 + 0.5 * hash(i, j, 65)) const size = U * (1.0 + 0.5 * hash(i, j, 65))
const seed = i * 131 + j const seed = i * 131 + j
put(`t${i}:${j}`, x, y, kindRoll < 0.15 ? bush(x, y, size * 0.8, seed) : kindRoll < 0.7 ? conifer(x, y, size, seed) : broadleaf(x, y, size, seed), size * 0.3) const faces = kindRoll < 0.15 ? bush(x, y, size * 0.8, seed) : kindRoll < 0.68 ? conifer(x, y, size, seed) : kindRoll < 0.76 ? deadTree(x, y, size, seed) : broadleaf(x, y, size, seed)
put(`t${i}:${j}`, x, y, faces.map((face) => ({ ...face, color: fade(face.color, r, S * 3, S * 6.5, 0.4) })), size * 0.3)
} }
} }
@ -257,7 +263,7 @@ export function buildCloseup(type: BuildingType, level: number, workers: number,
viewBox: `${view.x.toFixed(1)} ${view.y.toFixed(1)} ${w.toFixed(1)} ${h.toFixed(1)}`, viewBox: `${view.x.toFixed(1)} ${view.y.toFixed(1)} ${w.toFixed(1)} ${h.toFixed(1)}`,
width: w, width: w,
height: h, height: h,
terrain: ground(view), terrain: ground(view, { r0: S * 3, r1: S * 6.5 }),
decals: [...decals, ...shadows].flatMap((face) => toPolys([face])), decals: [...decals, ...shadows].flatMap((face) => toPolys([face])),
layers: layers.map((l) => ('walk' in l ? { key: l.key, walk: l.walk } : 'life' in l ? { key: l.key, life: l.life } : { key: l.key, polys: l.polys })), layers: layers.map((l) => ('walk' in l ? { key: l.key, walk: l.walk } : 'life' in l ? { key: l.key, life: l.life } : { key: l.key, polys: l.polys })),
herds, herds,

View File

@ -90,9 +90,16 @@ export function mix(a: string, b: string, t: number): string {
return hex([x[0] + (y[0] - x[0]) * t, x[1] + (y[1] - x[1]) * t, x[2] + (y[2] - x[2]) * t]) return hex([x[0] + (y[0] - x[0]) * t, x[1] + (y[1] - x[1]) * t, x[2] + (y[2] - x[2]) * t])
} }
/** Light from the upper left: tops keep their colour, left faces dim a little, right faces more. */ /** What faces turned away from the light sink towards: a cold, overcast dark. */
const COLD = '#1c2128'
/**
* Light from the upper left under an overcast sky: tops keep their colour, faces turned
* away from the light drop to half and go cold, so the shadow side reads hard and grey.
*/
function shade(color: string, n: V3): string { function shade(color: string, n: V3): string {
return scale(color, 0.6 + (0.4 * Math.max(0, dot(n, LIGHT))) / LIGHT_TOP) const lit = Math.min(1.05, Math.max(0, dot(n, LIGHT)) / LIGHT_TOP)
return mix(scale(color, 0.5 + 0.5 * lit), COLD, (1 - Math.min(1, lit)) * 0.22)
} }
/** Deterministic 0..1 noise for stable variety (same input, same output). */ /** Deterministic 0..1 noise for stable variety (same input, same output). */
@ -143,10 +150,17 @@ export function orient(pts: V3[], inside: V3): V3[] {
// Shapes. Bases are counter-clockwise seen from above. // Shapes. Bases are counter-clockwise seen from above.
const STONE = '#948d82' const STONE = '#6f6a62'
/** Doors are this colour; the scene finds a building's door by it. */ /** Doors are this colour; the scene finds a building's door by it. */
export const DOOR = '#4a3220' export const DOOR = '#33261c'
const WINDOW = '#2f2620' const WINDOW = '#141110'
/** Wet earth splashed up the foot of the walls. */
const MUD = '#3b3024'
/** Rot and moss on old roofs. */
const ROT = '#2c3022'
/** Door and window frames: the wall's wood, worn a little paler. */
export const trim = (walls: string) => mix(walls, '#958a74', 0.3)
export function rect(cx: number, cy: number, w: number, d: number): V2[] { export function rect(cx: number, cy: number, w: number, d: number): V2[] {
return [ return [
@ -225,7 +239,7 @@ export function gable(
return faces.map((f) => ({ ...f, pts: orient(f.pts, inside) })) return faces.map((f) => ({ ...f, pts: orient(f.pts, inside) }))
} }
/** A dark panel on the outside of a wall facing +x or +y: a door or a window. */ /** A panel on the outside of a wall facing +x or +y, lit like the wall: a door, a window, a beam. */
export 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 a0 = along - w / 2
const a1 = along + w / 2 const a1 = along + w / 2
@ -233,7 +247,7 @@ export function wallPanel(face: 'x' | 'y', at: number, along: number, z0: number
face === 'x' face === 'x'
? [[at, a0, z0], [at, a1, z0], [at, a1, z0 + h], [at, a0, z0 + h]] ? [[at, a0, z0], [at, a1, z0], [at, a1, z0 + h], [at, a0, z0 + h]]
: [[a0, at, z0], [a1, at, z0], [a1, at, z0 + h], [a0, at, z0 + h]] : [[a0, at, z0], [a1, at, z0], [a1, at, z0 + h], [a0, at, z0 + h]]
return { pts, color, twoSided: true, flat: true, depth: wallDepth + 0.05 } return { pts, color, twoSided: true, depth: wallDepth + 0.05 }
} }
/** /**
@ -247,7 +261,7 @@ export function openings(cx: number, cy: number, w: number, d: number, z0: numbe
// The depth of the wall face behind (its centroid, as toPolys sorts it), a step in front. // The depth of the wall face behind (its centroid, as toPolys sorts it), a step in front.
const xDepth = cx + w / 2 + cy + (z0 + h) / 2 + 0.1 const xDepth = cx + w / 2 + cy + (z0 + h) / 2 + 0.1
const yDepth = cx + cy + d / 2 + (z0 + h) / 2 + 0.1 const yDepth = cx + cy + d / 2 + (z0 + h) / 2 + 0.1
const frame = mix(walls, '#efe4c6', 0.45) const frame = trim(walls)
const shutter = scale(walls, 0.7) const shutter = scale(walls, 0.7)
const door = Math.min(d * 0.28, h * 0.5) const door = Math.min(d * 0.28, h * 0.5)
const doorH = (h - z0) * 0.62 const doorH = (h - z0) * 0.62
@ -286,16 +300,46 @@ export function framing(cx: number, cy: number, w: number, d: number, z0: number
] ]
} }
const STONE_WALLS = new Set(['#a39d92', '#847e74', STONE]) /** C.stone and C.stoneDark in models.ts, and the plinth: stone walls carry no beams. */
const STONE_WALLS = new Set(['#77736b', '#5a5751', STONE])
/** Mud splashed up the two walls in view, just above the plinth, under the beams. */
export function mudline(cx: number, cy: number, w: number, d: number, z0: number, h: number, walls: string): Face[] {
const band = (h - z0) * 0.2
const color = mix(walls, MUD, 0.55)
const xDepth = cx + w / 2 + cy + (z0 + h) / 2 + 0.01
const yDepth = cx + cy + d / 2 + (z0 + h) / 2 + 0.01
return [wallPanel('x', cx + w / 2 + 0.12, cy, z0, d, band, xDepth, color), wallPanel('y', cy + d / 2 + 0.12, cx, z0, w, band, yDepth, color)]
}
/**
* A rotten, mossy patch on the slope of a gable roof that faces the viewer, somewhere
* along it (from the seed); about a third of the roofs have none.
*/
export function roofRot(x0: number, y0: number, x1: number, y1: number, z: number, rise: number, along: 'x' | 'y', roof: string, seed: number): Face[] {
if (hash(seed, 31) < 0.33) return []
const u0 = 0.12 + 0.55 * hash(seed, 32)
const u1 = u0 + 0.16 + 0.12 * hash(seed, 33)
const v0 = 0.1 + 0.15 * hash(seed, 34)
const v1 = v0 + 0.3 + 0.2 * hash(seed, 35)
const r = z + rise
const at = (u: number, v: number): V3 =>
along === 'x'
? [x0 + (x1 - x0) * u, y1 + ((y0 + y1) / 2 - y1) * v + 0.3, z + rise * v + 0.3]
: [x1 + ((x0 + x1) / 2 - x1) * v + 0.3, y0 + (y1 - y0) * u, z + rise * v + 0.3]
// Over its slope (centroid halfway up, along the whole length), under the ridge beam.
const slope = along === 'x' ? (x0 + x1) / 2 + (y1 * 3 + y0) / 4 + (z + r) / 2 : (x1 * 3 + x0) / 4 + (y0 + y1) / 2 + (z + r) / 2
return [{ pts: [at(u0, v0), at(u1, v0), at(u1, v1), at(u0, v1)], color: mix(roof, ROT, 0.4), twoSided: true, depth: slope + 0.3 }]
}
/** Height of the stone plinth under a house's walls. */ /** 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) 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 * A box with a gable roof: the most common house. It stands on a low stone plinth with
* walls show their beams, the door on the wall towards the lower right and framed, * mud splashed up its walls, wooden walls show their beams, the door on the wall towards
* shuttered windows on the one towards the lower left, a dark beam along the ridge. * the lower right and framed, shuttered windows on the one towards the lower left, a
* A few large faces, no outlines. * rotten patch on most roofs, a dark beam along the ridge. A few large faces, no outlines.
*/ */
export function house( export function house(
cx: number, cx: number,
@ -321,9 +365,11 @@ export function house(
return [ return [
...box(cx, cy, w + plinth * 0.6, d + plinth * 0.6, 0, plinth, STONE, STONE), ...box(cx, cy, w + plinth * 0.6, d + plinth * 0.6, 0, plinth, STONE, STONE),
...box(cx, cy, w, d, plinth, h - plinth, walls), ...box(cx, cy, w, d, plinth, h - plinth, walls),
...mudline(cx, cy, w, d, plinth, h, walls),
...(STONE_WALLS.has(walls) ? [] : framing(cx, cy, w, d, plinth, h, walls)), ...(STONE_WALLS.has(walls) ? [] : framing(cx, cy, w, d, plinth, h, walls)),
...(bare ? [] : 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), ...gable(cx - w / 2 - o, cy - d / 2 - o, cx + w / 2 + o, cy + d / 2 + o, h, rise, along, roof, walls),
...roofRot(cx - w / 2 - o, cy - d / 2 - o, cx + w / 2 + o, cy + d / 2 + o, h, rise, along, roof, cx * 7 + cy * 13 + w),
...ridge, ...ridge,
] ]
} }

View File

@ -4,53 +4,73 @@
// stone at high levels. // stone at high levels.
import type { BuildingType } from '~/types/game' 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' import { box, cylinder, DOOR, type Face, framing, gable, gambrel, hash, house, log, mix, mudline, ngon, openings, orient, plane, plinthOf, prism, pyramid, rect, scale, shift, slab, trim, turn, type V2, type V3, wallPanel } from './iso'
/** Muted medieval colours, all flat: faces get their light from iso.ts shading only. */ /**
* Hard times: weathered, dirty, cold colours, all flat; faces get their light from iso.ts
* shading only. Wood is grey with age, straw is old, cloth is undyed or faded, and the
* only warm colours are fire and blood.
*/
export const C = { export const C = {
wood: '#8a5f38', wood: '#5f4b38',
woodDark: '#6a4526', woodDark: '#3f3127',
plank: '#a67c4e', plank: '#746149',
thatch: '#b8984f', thatch: '#776847',
canvas: '#d6c7a0', canvas: '#8f8571',
canvasDark: '#b9a77f', canvasDark: '#73695a',
roofRed: '#94452c', roofRed: '#5c3528',
slate: '#575c63', slate: '#3a3e44',
stone: '#a39d92', stone: '#77736b',
stoneDark: '#847e74', stoneDark: '#5a5751',
field: '#8c9a4c', field: '#474e31',
wheat: '#c4a552', wheat: '#76693f',
furrow: '#9a7c44', furrow: '#43382a',
soil: '#7d5c3a', soil: '#45372a',
leaf: '#56703a', leaf: '#3a4429',
leafDark: '#3f5a2c', leafDark: '#2f3822',
trunk: '#5a3d24', trunk: '#352a21',
clay: '#a8643f', clay: '#7a4d35',
clayDark: '#874c2f', clayDark: '#5a3827',
clayWet: '#96583a', clayWet: '#4f3324',
rock: '#8a857d', rock: '#57544e',
ore: '#4f5a63', ore: '#393f45',
fire: '#d98a2b', fire: '#c96f26',
banner: '#7b1e16', banner: '#5e1813',
hay: '#c9ad5e', hay: '#857449',
cloth: '#6b4f3a', cloth: '#4a3e33',
skin: '#d8a982', skin: '#a98a72',
dark: '#2f2620', dark: '#1b1714',
grass: '#78894a', grass: '#4f5337',
conifer: '#3d5a2b', conifer: '#243021',
coniferDark: '#334d25', coniferDark: '#1d271b',
broadleaf: '#5a7339', broadleaf: '#3b4229',
broadleafDark: '#4c6431', broadleafDark: '#333a24',
bush: '#5f7a3c', bush: '#373e26',
barn: '#7c3f2c', barn: '#552f24',
shingle: '#6b4a30', shingle: '#47392d',
metal: '#8b9094', metal: '#6e7376',
water: '#5f7f87', water: '#2f3b3c',
chestnut: '#8a4f2a', chestnut: '#5a3721',
bay: '#5e3a22', bay: '#3a281b',
grey: '#b8b2a6', grey: '#7d786f',
/** Dried blood on the ground, and fresh. */
blood: '#4a1410',
bloodFresh: '#6b1a12',
/** Burnt timber and the ash round it. */
char: '#1f1b18',
ash: '#45413b',
/** Bare dead wood and the pale cut of a stump. */
deadWood: '#4b4239',
cut: '#8a7a5d',
crow: '#121212',
} }
/** What villagers wear: undyed linen, brown and grey wool, faded red and green. Soldiers in dark wool. */
export const SHIRTS = ['#5a4a3a', '#62342a', '#474b36', '#6a6355', '#434548']
export const UNIFORM = '#3a2f26'
/** Smoke from hearths, forges and smouldering ruins: sooty, not white. */
export const SMOKE = { fill: '#55514c', edge: '#45423e' }
export interface Model { export interface Model {
faces: Face[] faces: Face[]
/** Highest point, for the level badge. */ /** Highest point, for the level badge. */
@ -95,12 +115,18 @@ export function tree(x: number, y: number, size: number, seed = 0): Face[] {
] ]
} }
/** A broken rock: a crooked main peak and a lower shoulder split off beside it. */
export function rock(x: number, y: number, size: number, seed = 0, color = C.rock): Face[] { 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 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) const k = 0.75 + 0.45 * hash(seed, i)
return [x + (px - x) * k, y + (py - y) * k] 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]) const a = hash(seed, 10) * Math.PI * 2
const [sx, sy] = [x + Math.cos(a) * size * 0.3, y + Math.sin(a) * size * 0.3]
return [
...pyramid(base, 0, size * (0.45 + 0.3 * hash(seed, 9)), color, [x + size * (0.04 + 0.12 * hash(seed, 11)), y - size * (0.02 + 0.1 * hash(seed, 12))]),
...pyramid(ngon(sx, sy, size * 0.3, 5, a), 0, size * (0.22 + 0.12 * hash(seed, 13)), scale(color, 0.85), [sx + size * 0.05, sy + size * 0.03]),
]
} }
// Landscape: lighter trees for the forest around the village (few faces each). // Landscape: lighter trees for the forest around the village (few faces each).
@ -135,6 +161,157 @@ 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) return pyramid(ngon(x, y, size * 0.4, 5, hash(seed, 2) * 6), 0, size * 0.35, C.bush)
} }
// Hard times: what the forest, the war and the winters leave behind.
/** An irregular flat patch on the ground: a stain, a puddle, a heap of ash. */
export function blot(cx: number, cy: number, r: number, n: number, seed: number, z: number, color: string): Face {
const pts = ngon(cx, cy, r, n, hash(seed, 1) * 6).map(([x, y], i): V3 => {
const k = 0.6 + 0.55 * hash(seed, i, 2)
return [cx + (x - cx) * k, cy + (y - cy) * k, z]
})
// Under everything else of its object, layered by height: ash, then char, then blood.
return { ...plane(pts, color), depth: -1e5 + z }
}
/** Blood soaked into the ground: a dark pool, a fresher heart and a few drops round it. */
export function blood(x: number, y: number, r: number, seed = 0): Face[] {
const faces = [blot(x, y, r, 9, seed, 0.7, C.blood), blot(x + r * 0.1, y - r * 0.05, r * 0.45, 7, seed + 1, 0.75, C.bloodFresh)]
for (let i = 0; i < 4; i++) {
const a = hash(seed, i, 3) * Math.PI * 2
const d = r * (1.2 + 0.6 * hash(seed, i, 4))
faces.push(blot(x + Math.cos(a) * d, y + Math.sin(a) * d, r * (0.12 + 0.1 * hash(seed, i, 5)), 5, seed + 10 + i, 0.7, C.blood))
}
return faces
}
/** What is left of a felled tree: a low stump with its pale cut. */
export function stump(x: number, y: number, size: number, seed = 0): Face[] {
const r = size * (0.07 + 0.04 * hash(seed, 1))
return prism(ngon(x, y, r, 6, hash(seed, 2) * 6), 0, size * (0.08 + 0.08 * hash(seed, 3)), C.trunk, C.cut)
}
/** A dead tree: a bare grey trunk, broken at the top, with two or three crooked branches. */
export function deadTree(x: number, y: number, size: number, seed = 0): Face[] {
const h = size * (0.75 + 0.3 * hash(seed, 1))
const r = size * 0.06
const faces: Face[] = [...prism(ngon(x, y, r, 5, hash(seed, 2) * 6), 0, h * 0.8, C.deadWood), ...pyramid(ngon(x, y, r, 5, hash(seed, 2) * 6), h * 0.8, h * 0.2, C.deadWood)]
const n = 2 + Math.floor(hash(seed, 3) * 2)
for (let i = 0; i < n; i++) {
const a = hash(seed, i, 4) * Math.PI * 2
const z = h * (0.4 + 0.35 * (i / n))
const len = size * (0.25 + 0.15 * hash(seed, i, 5))
const t = r * 0.5
const [ex, ey] = [x + Math.cos(a) * len, y + Math.sin(a) * len]
faces.push(
...slab(
[[x - t, y - t, z], [x + t, y - t, z], [x + t, y + t, z], [x - t, y + t, z]],
[[ex - t * 0.5, ey - t * 0.5, z + len * 0.8], [ex + t * 0.5, ey - t * 0.5, z + len * 0.8], [ex + t * 0.5, ey + t * 0.5, z + len * 0.8], [ex - t * 0.5, ey + t * 0.5, z + len * 0.8]],
C.deadWood,
),
)
}
return faces
}
/** A crow sitting, beak towards +x before `quarters` turns, its feet at z. */
export function perchedCrow(x: number, y: number, z: number, k: number, quarters = 0): Face[] {
const faces: Face[] = [
...slab(
[[-1.2 * k, -0.4 * k, 0.3 * k], [0.6 * k, -0.45 * k, 0.4 * k], [0.6 * k, 0.45 * k, 0.4 * k], [-1.2 * k, 0.4 * k, 0.3 * k]],
[[-1.4 * k, -0.3 * k, 1.1 * k], [0.7 * k, -0.4 * k, 1.5 * k], [0.7 * k, 0.4 * k, 1.5 * k], [-1.4 * k, 0.3 * k, 1.1 * k]],
C.crow,
),
...box(0.8 * k, 0, 0.7 * k, 0.6 * k, 1.3 * k, 0.6 * k, C.crow),
...box(1.35 * k, 0, 0.5 * k, 0.16 * k, 1.5 * k, 0.12 * k, '#2a2622'),
]
return shift(turn(faces, quarters), x, y, z)
}
/**
* A grave: a long mound of earth with a wooden cross at its head, the cross leaning a
* little on old graves; a few have a rough headstone. A fresh one lies open, its earth
* heaped beside it and a shovel stuck in.
*/
export function grave(x: number, y: number, s: number, seed = 0, fresh = false): Face[] {
const len = s * 0.62
const wid = s * 0.28
if (fresh) {
return [
plane(rect(x, y, len, wid).map(([px, py]): V3 => [px, py, 0.8]), C.dark),
...slab(
rect(x, y + wid * 1.05, len * 1.05, wid * 0.9).map(([px, py]): V3 => [px, py, 0]),
rect(x, y + wid * 1.05, len * 0.7, wid * 0.4).map(([px, py]): V3 => [px, py, s * 0.16]),
C.soil,
),
...shift(slab(rect(0, 0, s * 0.03, s * 0.03).map(([px, py]): V3 => [px, py, 0]), rect(s * 0.08, 0, s * 0.03, s * 0.03).map(([px, py]): V3 => [px, py, s * 0.5]), C.woodDark), x + len * 0.3, y + wid * 1.05, s * 0.1),
]
}
const mound = slab(
rect(x, y, len, wid).map(([px, py]): V3 => [px, py, 0]),
rect(x, y, len * 0.8, wid * 0.55).map(([px, py]): V3 => [px, py, s * 0.08]),
hash(seed, 1) > 0.5 ? C.soil : mix(C.soil, C.grass, 0.5),
)
const hx = x - len / 2 - s * 0.04
if (hash(seed, 2) < 0.25) return [...mound, ...box(hx, y, s * 0.07, wid * 0.8, 0, s * 0.3, C.stoneDark, C.stone)]
const lean = (hash(seed, 3) - 0.5) * s * 0.12
const h = s * (0.42 + 0.1 * hash(seed, 4))
const t = s * 0.035
return [
...mound,
...slab(rect(hx, y, t, t).map(([px, py]): V3 => [px, py, 0]), rect(hx, y + lean, t, t).map(([px, py]): V3 => [px, py, h]), C.deadWood),
...box(hx, y + lean * 0.75, t, s * 0.26, h * 0.68, t, C.deadWood),
]
}
/** The gallows by the road: a platform, two posts and a beam, a noose, crows on the beam. */
export function gallows(x: number, y: number, s: number, seed = 0): Face[] {
const a = s * 0.5
const h = s * 1.45
const t = s * 0.06
return [
...box(x, y, s * 1.2, s * 0.8, 0, s * 0.22, C.plank, C.wood),
...prism(rect(x, y - a, t * 2, t * 2), 0, h, C.woodDark),
...prism(rect(x, y + a, t * 2, t * 2), 0, h, C.woodDark),
...box(x, y, t * 2.2, a * 2 + t * 4, h, t * 2, C.woodDark),
...box(x, y + a * 0.2, s * 0.015, s * 0.015, h - s * 0.45, s * 0.45, C.cut),
...box(x, y + a * 0.2, s * 0.08, s * 0.08, h - s * 0.55, s * 0.1, C.cut),
...perchedCrow(x, y - a * 0.6, h + t * 2, s * 0.06, hash(seed, 1) > 0.5 ? 1 : 3),
...perchedCrow(x, y + a * 0.75, h + t * 2, s * 0.055, 0),
]
}
/**
* A farmstead burnt to the ground: soot-black stumps of the corner posts, a beam fallen
* across, a piece of the roof on the ground, rubble of the chimney, all in a ring of ash.
*/
export function ruin(x: number, y: number, s: number, seed = 0): Face[] {
const w = s * 1.3
const d = s * 0.9
const p = s * 0.12
const posts = [
[-1, -1, 0.95],
[1, -1, 0.4],
[1, 1, 0.65],
[-1, 1, 0.25],
[0, -1, 0.7],
] as const
return [
blot(x, y, s * 1.25, 11, seed, 0.6, C.ash),
blot(x + s * 0.1, y, s * 0.8, 9, seed + 1, 0.7, C.char),
...box(x, y, w + p, d + p, 0, p, C.stoneDark, mix(C.stoneDark, C.char, 0.5)),
...posts.flatMap(([fx, fy, k]) => box(x + (fx * w) / 2, y + (fy * d) / 2, s * 0.09, s * 0.09, p, s * 0.75 * k, C.char)),
...slab(
rect(x + w * 0.5, y + d * 0.5, s * 0.08, s * 0.08).map(([px, py]): V3 => [px, py, s * 0.55]),
rect(x - w * 0.2, y + d * 0.65, s * 0.08, s * 0.08).map(([px, py]): V3 => [px, py, p]),
C.char,
),
plane([[x - w * 0.45, y - d * 0.1, p + 1], [x + w * 0.1, y - d * 0.35, p + 1], [x + w * 0.2, y + d * 0.1, s * 0.3], [x - w * 0.35, y + d * 0.3, s * 0.3]], mix(C.thatch, C.char, 0.7)),
...box(x - w * 0.42, y - d * 0.42, s * 0.25, s * 0.25, p, s * 0.5, C.stoneDark),
...pyramid(ngon(x - w * 0.15, y - d * 0.55, s * 0.18, 5, 1), 0, s * 0.14, C.stoneDark),
...pyramid(ngon(x - w * 0.6, y - d * 0.1, s * 0.14, 5, 2), 0, s * 0.1, C.stone),
]
}
/** The village well on the plaza. */ /** The village well on the plaza. */
export function well(s: number): Model { export function well(s: number): Model {
return { return {
@ -216,7 +393,7 @@ function headframe(x: number, y: number, s: number, h: number): Face[] {
/** A round on a wall facing +x or +y, seen flat: a shield, a target's rings. */ /** 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 { 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])) 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 } return { pts, color, twoSided: true, depth }
} }
/** Faces that must draw over a wall: sorted from `depth` on, in their own front-to-back order. */ /** Faces that must draw over a wall: sorted from `depth` on, in their own front-to-back order. */
@ -381,7 +558,7 @@ function tent(x: number, y: number, w: number, d: number, h: number, along: 'x'
const depth = (along === 'x' ? x1 + y : x + y1) + h / 3 + 0.2 const depth = (along === 'x' ? x1 + y : x + y1) + h / 3 + 0.2
return [ return [
...gable(x - w / 2, y - d / 2, x1, y1, 0, h, along, color, scale(color, 0.9)), ...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 }, { pts: flap, color: door ? DOOR : C.dark, twoSided: 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), ...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),
] ]
} }
@ -439,13 +616,14 @@ function barn(cx: number, cy: number, w: number, d: number, h: number, rise: num
const xDepth = x1 + cy + (p + h) / 2 + 0.1 const xDepth = x1 + cy + (p + h) / 2 + 0.1
const yDepth = cx + cy + d / 2 + (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 endDepth = x1 + o + cy + h + rise * 0.44 + 0.1
const frame = mix(walls, '#efe4c6', 0.45) const frame = trim(walls)
const dw = d * 0.46 const dw = d * 0.46
const dh = (h - p) * 0.82 const dh = (h - p) * 0.82
const loftZ = h + rise * 0.12 const loftZ = h + rise * 0.12
const faces: Face[] = [ const faces: Face[] = [
...box(cx, cy, w + p * 0.6, d + p * 0.6, 0, p, C.stone), ...box(cx, cy, w + p * 0.6, d + p * 0.6, 0, p, C.stone),
...box(cx, cy, w, d, p, h - p, walls), ...box(cx, cy, w, d, p, h - p, walls),
...mudline(cx, cy, w, d, p, h, walls),
...(walls === C.stone ? [] : framing(cx, cy, w, d, p, h, 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), ...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.25, cy, p, dw * 1.14, dh + d * 0.05, xDepth, frame),
@ -733,13 +911,25 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
} }
}, },
rally_point(s, t) { // Where the army gathers and comes back: the platform with its banners, spears left
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)) // stuck in the ground, a split shield, and blood trodden into the mud.
rally_point(s) {
const spear = (x: number, y: number, dx: number, dy: number): Face[] => [
...slab(rect(x, y, s * 0.03, s * 0.03).map(([px, py]): V3 => [px, py, 0]), rect(x + dx, y + dy, s * 0.03, s * 0.03).map(([px, py]): V3 => [px, py, s * 0.62]), C.woodDark),
...pyramid(rect(x + dx, y + dy, s * 0.05, s * 0.05), s * 0.62, s * 0.1, C.metal),
]
return { return {
faces: [ faces: [
...blood(s * 0.6, s * 0.15, s * 0.2, 21),
...blood(-s * 0.35, s * 0.7, s * 0.14, 22),
...box(0, 0, s * 0.9, s * 0.9, 0, s * 0.15, C.plank, C.wood), ...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.8, s * 0.8),
...banner(s * 0.3, s * 0.3, s * 1.5, s * 0.7, C.slate), ...banner(s * 0.3, s * 0.3, s * 1.5, s * 0.7, C.slate),
...spear(s * 0.75, -s * 0.55, -s * 0.08, s * 0.1),
...spear(s * 0.88, -s * 0.38, s * 0.1, -s * 0.04),
...spear(-s * 0.7, s * 0.3, s * 0.05, s * 0.12),
plane(ngon(s * 0.45, s * 0.65, s * 0.13, 7).map(([x, y]): V3 => [x, y, 1]), C.banner),
plane(ngon(s * 0.62, s * 0.72, s * 0.1, 3, 0.4).map(([x, y]): V3 => [x, y, 1.1]), scale(C.banner, 0.8)),
], ],
height: s * 1.8, height: s * 1.8,
} }
@ -796,6 +986,7 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
...tent(-s * 0.6, s * 0.42, s * 0.75, s * 0.55, s * 0.5, 'x', C.canvasDark), ...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'), ...weaponRack(s * 0.4, s * 0.65, s, 'x'),
...dummy(s * 0.8, -s * 0.2, s), ...dummy(s * 0.8, -s * 0.2, s),
...blood(s * 0.85, s * 0.25, s * 0.13, 11),
...fire(s * 0.4, s * 0.15, s), ...fire(s * 0.4, s * 0.15, s),
...banner(-s * 0.95, -s * 0.85, s * 1.15, s * 0.45), ...banner(-s * 0.95, -s * 0.85, s * 1.15, s * 0.45),
], ],
@ -821,6 +1012,7 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
...weaponRack(s * 0.55, s * 0.6, s, 'x'), ...weaponRack(s * 0.55, s * 0.6, s, 'x'),
...dummy(-s * 0.55, s * 0.6, s), ...dummy(-s * 0.55, s * 0.6, s),
...dummy(-s * 0.1, s * 0.75, s), ...dummy(-s * 0.1, s * 0.75, s),
...blood(-s * 0.3, s * 0.42, s * 0.17, 12),
...target(s * 0.9, -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), ...banner(s * 0.95, s * 0.05, s * 1.3, s * 0.5),
], ],
@ -843,6 +1035,7 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
...weaponRack(s * 0.55, s * 0.6, s, 'x'), ...weaponRack(s * 0.55, s * 0.6, s, 'x'),
...dummy(-s * 0.6, s * 0.55, s), ...dummy(-s * 0.6, s * 0.55, s),
...dummy(-s * 0.2, s * 0.72, s), ...dummy(-s * 0.2, s * 0.72, s),
...blood(-s * 0.4, s * 0.38, s * 0.18, 13),
...target(s * 0.95, -s * 0.85, s), ...target(s * 0.95, -s * 0.85, s),
], ],
height: h * 1.55 + s * 0.75, height: h * 1.55 + s * 0.75,
@ -887,7 +1080,7 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
} }
} }
faces.push( 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.25, cy, h * 0.12, d * 0.5, h * 0.62, xDepth, trim(walls)),
wallPanel('x', x1 + 0.3, cy, h * 0.12, d * 0.4, h * 0.56, xDepth + 0.05, DOOR), 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. // The paddock, with a horse more for every tier.

View File

@ -10,9 +10,9 @@
// deterministically and in id order, so buildings stay put when new ones are added. // deterministically and in id order, so buildings stay put when new ones are added.
import type { BuildingType, VillageState } from '~/types/game' import type { BuildingType, VillageState } from '~/types/game'
import { box, DOOR, type Face, hash, ngon, plane, type Poly, prism, project, pyramid, scale, toPolys, type V2, type V3 } from './iso' import { box, DOOR, type Face, hash, mix, ngon, plane, type Poly, prism, project, pyramid, scale, toPolys, type V2, type V3 } from './iso'
import type { Tool } from './life' import type { Tool } from './life'
import { broadleaf, buildingModel, bush, C, conifer, crane, rock, scaffold, well } from './models' import { blot, broadleaf, buildingModel, bush, C, conifer, crane, deadTree, gallows, grave, rock, ruin, scaffold, stump, well } from './models'
/** World units per unit of building space, roughly. */ /** World units per unit of building space, roughly. */
export const U = 24 export const U = 24
@ -30,18 +30,30 @@ type Zone = 'iron' | 'clay' | 'timber' | 'farm'
const ZONE_OF: Partial<Record<BuildingType, Zone>> = { iron_mine: 'iron', clay_pit: 'clay', timber_camp: 'timber', farm: 'farm' } const ZONE_OF: Partial<Record<BuildingType, Zone>> = { iron_mine: 'iron', clay_pit: 'clay', timber_camp: 'timber', farm: 'farm' }
/** Centre angle, half the angle it spans, model scale, and slot spacing in model sizes. */ /** Centre angle, half the angle it spans, model scale, and slot spacing in model sizes. */
const ZONES: Record<Zone, { angle: number; half: number; scale: number; gap: number; ground: string | null }> = { const ZONES: Record<Zone, { angle: number; half: number; scale: number; gap: number; ground: string | null }> = {
iron: { angle: deg(196), half: deg(26), scale: 1.15, gap: 2.5, ground: '#7c776a' }, iron: { angle: deg(196), half: deg(26), scale: 1.15, gap: 2.5, ground: '#55524c' },
clay: { angle: deg(102), half: deg(24), scale: 1.1, gap: 2.4, ground: '#8d5a3b' }, clay: { angle: deg(102), half: deg(24), scale: 1.1, gap: 2.4, ground: '#5f3f2c' },
timber: { angle: deg(8), half: deg(22), scale: 1.1, gap: 2.4, ground: '#76703f' }, timber: { angle: deg(8), half: deg(22), scale: 1.1, gap: 2.4, ground: '#554a33' },
farm: { angle: deg(-62), half: deg(27), scale: 1.3, gap: 2.6, ground: null }, farm: { angle: deg(-62), half: deg(27), scale: 1.3, gap: 2.6, ground: null },
} }
const ZONE_NAMES = Object.keys(ZONES) as Zone[] const ZONE_NAMES = Object.keys(ZONES) as Zone[]
const GRASS = ['#7a8b48', '#778848', '#7d8d4a', '#748546'] /** Tired grass, trodden and yellowed in places; roads and the plaza are mud. */
const DIRT = '#9c8157' const GRASS = ['#4f5436', '#4b5034', '#535539', '#575438']
const PLAZA = '#a3885c' const DIRT = '#4f3f2e'
const VILLAGE_GROUND = '#868d4d' const PLAZA = '#564533'
const WALL_EARTH = '#8c7350' const VILLAGE_GROUND = '#4f4c33'
const WALL_EARTH = '#463829'
/** Ruts cut by cart wheels, and the rain standing in them. */
const RUT = '#3a2e22'
const PUDDLE = '#2c3233'
/** The land darkens towards the edges, into the forest. */
const DUSK = '#14170f'
/** A ground colour darkened from `r0` out to `r1`, at most by `max`. */
export function fade(color: string, r: number, r0: number, r1: number, max = 0.5): string {
const k = Math.min(1, Math.max(0, (r - r0) / (r1 - r0)))
return k ? mix(color, DUSK, k * max) : color
}
export interface SceneBuilding { export interface SceneBuilding {
id: number id: number
@ -144,7 +156,7 @@ export interface Scene {
walks: { d: string; count: number; walk: number; work: number; tool: Tool | null; carry: string | null }[] walks: { d: string; count: number; walk: number; work: number; tool: Tool | null; carry: string | null }[]
/** Sheep by the farms and chickens on the plaza, wandering small loops. */ /** Sheep by the farms and chickens on the plaza, wandering small loops. */
herds: { kind: 'sheep' | 'chicken'; d: string; dur: number; begin: number }[] herds: { kind: 'sheep' | 'chicken'; d: string; dur: number; begin: number }[]
/** Birds crossing the land now and then. */ /** Crows crossing the land now and then, and circling over the graves and the gallows. */
birds: { d: string; dur: number; begin: number }[] birds: { d: string; dur: number; begin: number }[]
/** A wide click band along the wall ring, so the thin wall is easy to hit. */ /** A wide click band along the wall ring, so the thin wall is easy to hit. */
wallBand: { id: number; ring: { cx: number; cy: number; rx: number; ry: number }; width: number } | null wallBand: { id: number; ring: { cx: number; cy: number; rx: number; ry: number }; width: number } | null
@ -182,7 +194,7 @@ export function guardSpots(type: BuildingType, [x, y]: V2, n: number, unit: numb
/** Buildings that smoke, from this level on. */ /** Buildings that smoke, from this level on. */
const SMOKY: Partial<Record<BuildingType, number>> = { headquarters: 1, barracks: 1, workshop: 1, academy: 1, clay_pit: 1, iron_mine: 5 } const SMOKY: Partial<Record<BuildingType, number>> = { headquarters: 1, barracks: 1, workshop: 1, academy: 1, clay_pit: 1, iron_mine: 5 }
const WATER = '#5f7f87' const WATER = '#2f3b3c'
/** A scene object with its painter order (x + y of its ground point). */ /** A scene object with its painter order (x + y of its ground point). */
type Ordered = SceneObject & { depth: number } type Ordered = SceneObject & { depth: number }
@ -304,8 +316,11 @@ function inverse([X, Y]: V2): V2 {
return [Y + X / 2, Y - X / 2] return [Y + X / 2, Y - X / 2]
} }
/** A low-poly ground mesh that covers the view; vertices hash from their grid index, so it never shifts. */ /**
export function ground(view: { x: number; y: number; w: number; h: number }): Poly[] { * A low-poly ground mesh that covers the view; vertices hash from their grid index, so it
* never shifts. With `dark`, the land darkens from radius r0 out to r1.
*/
export function ground(view: { x: number; y: number; w: number; h: number }, dark?: { r0: number; r1: number }): Poly[] {
const g = U * 2.6 const g = U * 2.6
const corners = [ const corners = [
inverse([view.x, view.y]), inverse([view.x, view.y]),
@ -335,8 +350,11 @@ export function ground(view: { x: number; y: number; w: number; h: number }): Po
const minY = Math.min(...xs.map((p) => p[1])) const minY = Math.min(...xs.map((p) => p[1]))
const maxY = Math.max(...xs.map((p) => p[1])) const maxY = Math.max(...xs.map((p) => p[1]))
if (maxX < view.x || minX > view.x + view.w || maxY < view.y || minY > view.y + view.h) continue if (maxX < view.x || minX > view.x + view.w || maxY < view.y || minY > view.y + view.h) continue
const tone = (k: number) => GRASS[Math.floor(hash(i, j, k) * GRASS.length)]! const tone = (k: number, p: V3, q: V3) => {
faces.push({ pts: [a, b, c], color: tone(4), twoSided: true }, { pts: [a, c, d], color: tone(5), twoSided: true }) const color = GRASS[Math.floor(hash(i, j, k) * GRASS.length)]!
return dark ? fade(color, Math.hypot((a[0] + p[0] + q[0]) / 3, (a[1] + p[1] + q[1]) / 3), dark.r0, dark.r1) : color
}
faces.push({ pts: [a, b, c], color: tone(4, b, c), twoSided: true }, { pts: [a, c, d], color: tone(5, c, d), twoSided: true })
} }
} }
return toPolys(faces).map((p) => ({ ...p, stroke: p.fill })) return toPolys(faces).map((p) => ({ ...p, stroke: p.fill }))
@ -377,6 +395,30 @@ function road(a: number, r0: number, r1: number, half: number, seed: number): Fa
return plane([...left, ...right.reverse()], DIRT) return plane([...left, ...right.reverse()], DIRT)
} }
/** Two wheel ruts along a road, and rain standing in them here and there. */
function ruts(a: number, r0: number, r1: number, half: number, seed: number): Face[] {
const [dx, dy] = dir(a)
const line = roadLine(a, r0, r1, seed)
const faces: Face[] = []
const color = mix(DIRT, RUT, 0.6)
for (const side of [-1, 1]) {
const off = side * half * 0.36
const w = U * 0.03
const left: V3[] = line.map((p): V3 => [p.x - dy * (off - w), p.y + dx * (off - w), 1.3])
const right: V3[] = line.map((p): V3 => [p.x - dy * (off + w), p.y + dx * (off + w), 1.3])
faces.push(plane([...left, ...right.reverse()], color))
}
// Now and then the rain stands in a rut.
for (let i = 1; i < line.length - 1; i++) {
if (hash(seed, i, 7) > 0.22) continue
const side = hash(seed, i, 8) > 0.5 ? 1 : -1
const p = line[i]!
const off = side * half * 0.3
faces.push(blot(p.x - dy * off, p.y + dx * off, U * (0.2 + 0.12 * hash(seed, i, 9)), 7, seed * 31 + i, 1.4, PUDDLE))
}
return faces
}
/** The screen path along a road between two radii, for villagers to walk. */ /** The screen path along a road between two radii, for villagers to walk. */
function walkPath(a: number, r0: number, r1: number, seed: number, from: number, to: number): string { function walkPath(a: number, r0: number, r1: number, seed: number, from: number, to: number): string {
const pts = roadLine(a, r0, r1, seed).filter((p) => p.t >= from && p.t <= to) const pts = roadLine(a, r0, r1, seed).filter((p) => p.t >= from && p.t <= to)
@ -391,24 +433,14 @@ export function shadow(x: number, y: number, r: number, color: string, seed: num
/** A band around the village: worn earth under the wall, or the village's edge without one. */ /** A band around the village: worn earth under the wall, or the village's edge without one. */
function ringBand(r: number, width: number, color: string): Face[] { function ringBand(r: number, width: number, color: string): Face[] {
const n = 56 const n = 56
const faces: Face[] = [] // Trodden unevenly: each edge wanders in and out.
for (let i = 0; i < n; i++) { const edge = (i: number, side: number) => {
const a0 = (i / n) * Math.PI * 2 const a = ((i % n) / n) * Math.PI * 2
const a1 = ((i + 1) / n) * Math.PI * 2 const k = r + side * (width / 2) * (0.55 + 0.9 * hash(i % n, side + 3, 17))
const r0 = r - width / 2 return [Math.cos(a) * k, Math.sin(a) * k, 1] as V3
const r1 = r + width / 2
faces.push(
plane(
[
[Math.cos(a0) * r0, Math.sin(a0) * r0, 1],
[Math.cos(a1) * r0, Math.sin(a1) * r0, 1],
[Math.cos(a1) * r1, Math.sin(a1) * r1, 1],
[Math.cos(a0) * r1, Math.sin(a0) * r1, 1],
],
color,
),
)
} }
const faces: Face[] = []
for (let i = 0; i < n; i++) faces.push(plane([edge(i, -1), edge(i + 1, -1), edge(i + 1, 1), edge(i, 1)], color))
return faces return faces
} }
@ -559,7 +591,7 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
labelTops.push(label[1]) labelTops.push(label[1])
anchorOfBuilding.set(b.id, label) anchorOfBuilding.set(b.id, label)
const ground = b.type === 'headquarters' ? PLAZA : zone ? (ZONES[zone].ground ?? GRASS[0]!) : VILLAGE_GROUND const ground = b.type === 'headquarters' ? PLAZA : zone ? (ZONES[zone].ground ?? GRASS[0]!) : VILLAGE_GROUND
shadows.push(shadow(slot.x, slot.y, s * (zone ? 1.0 : 0.95), scale(ground, 0.8), b.id)) shadows.push(shadow(slot.x, slot.y, s * (zone ? 1.0 : 0.95), scale(ground, 0.68), b.id))
const smokyFrom = SMOKY[b.type] const smokyFrom = SMOKY[b.type]
if (smokyFrom !== undefined && b.level >= smokyFrom && !upgrading) smoke.push(project([slot.x - s * 0.35, slot.y + s * 0.3, model.height * 0.72])) if (smokyFrom !== undefined && b.level >= smokyFrom && !upgrading) smoke.push(project([slot.x - s * 0.35, slot.y + s * 0.3, model.height * 0.72]))
objects.push({ objects.push({
@ -662,8 +694,17 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
if (!color) continue if (!color) continue
zoneSlots[zone].forEach((s, i) => decalFaces.push(plane(disc(s.x, s.y, s.r * 1.3, 9, 30 + i * 7 + zone.length, 0.8), color))) zoneSlots[zone].forEach((s, i) => decalFaces.push(plane(disc(s.x, s.y, s.r * 1.3, 9, 30 + i * 7 + zone.length, 0.8), color)))
} }
decalFaces.push(road(FRONT, hqRadius * 0.9, Rz * 3, PATH_HALF, 1)) // Trodden mud between the houses.
for (const zone of activeZones) decalFaces.push(road(ZONES[zone].angle, hqRadius * 0.9, zoneEnd(zone) + U * 0.5, ZONE_PATH_HALF, ZONE_NAMES.indexOf(zone) + 2)) for (let k = 0; k < 9; k++) {
const a = hash(k, 81) * Math.PI * 2
const r = (Rv - U) * Math.sqrt(hash(k, 82))
decalFaces.push(blot(Math.cos(a) * r, Math.sin(a) * r, U * (0.6 + 0.7 * hash(k, 83)), 9, 800 + k, 0.55, mix(VILLAGE_GROUND, DIRT, 0.6)))
}
decalFaces.push(road(FRONT, hqRadius * 0.9, Rz * 3, PATH_HALF, 1), ...ruts(FRONT, hqRadius * 0.9, Rz * 3, PATH_HALF, 1))
for (const zone of activeZones) {
const seed = ZONE_NAMES.indexOf(zone) + 2
decalFaces.push(road(ZONES[zone].angle, hqRadius * 0.9, zoneEnd(zone) + U * 0.5, ZONE_PATH_HALF, seed), ...ruts(ZONES[zone].angle, hqRadius * 0.9, zoneEnd(zone), ZONE_PATH_HALF, seed))
}
// Footpaths: from every door to the nearest road or the plaza, around other buildings, // Footpaths: from every door to the nearest road or the plaza, around other buildings,
// with a trodden patch in front of the door; from every site outside to its zone road. // with a trodden patch in front of the door; from every site outside to its zone road.
const blockers = [{ key: 'hq', x: 0, y: 0, r: hqRadius * 0.8 }, ...allSlots.filter((sl) => sl.key !== 'hq').map((sl) => ({ key: sl.key, x: sl.x, y: sl.y, r: sl.r * 0.85 }))] const blockers = [{ key: 'hq', x: 0, y: 0, r: hqRadius * 0.8 }, ...allSlots.filter((sl) => sl.key !== 'hq').map((sl) => ({ key: sl.key, x: sl.x, y: sl.y, r: sl.r * 0.85 }))]
@ -706,6 +747,11 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
} }
decalFaces.push(...ringBand(Rv, U * (wall || wallPlanned ? 0.55 : 0.4), wall || wallPlanned ? WALL_EARTH : DIRT)) decalFaces.push(...ringBand(Rv, U * (wall || wallPlanned ? 0.55 : 0.4), wall || wallPlanned ? WALL_EARTH : DIRT))
decalFaces.push(plane(disc(0, 0, hqRadius * 1.3, 11, 3, 1.6), PLAZA)) decalFaces.push(plane(disc(0, 0, hqRadius * 1.3, 11, 3, 1.6), PLAZA))
// Rain standing on the plaza, where the carts turn.
for (let k = 0; k < 3; k++) {
const [px, py] = dir(FRONT + deg(-50 + k * 50 + hash(k, 85) * 20))
decalFaces.push(blot(px * hqRadius * 1.12, py * hqRadius * 1.12, U * (0.22 + 0.15 * hash(k, 86)), 7, 860 + k, 1.7, PUDDLE))
}
// Landscape: a rocky hill behind the iron zone, then forest everywhere else. // Landscape: a rocky hill behind the iron zone, then forest everywhere else.
const taken: { x: number; y: number; r: number }[] = allSlots.map((s) => ({ x: s.x, y: s.y, r: s.r + U * 0.45 })) const taken: { x: number; y: number; r: number }[] = allSlots.map((s) => ({ x: s.x, y: s.y, r: s.r + U * 0.45 }))
@ -736,7 +782,7 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
const pondOut = Math.max(Rv + U * 2.6, zoneEnd('clay') * 0.85) const pondOut = Math.max(Rv + U * 2.6, zoneEnd('clay') * 0.85)
const [pondX, pondY] = [Math.cos(deg(150)) * pondOut, Math.sin(deg(150)) * pondOut] const [pondX, pondY] = [Math.cos(deg(150)) * pondOut, Math.sin(deg(150)) * pondOut]
if (!taken.some((t) => Math.hypot(pondX - t.x, pondY - t.y) < t.r + pondR)) { if (!taken.some((t) => Math.hypot(pondX - t.x, pondY - t.y) < t.r + pondR)) {
decalFaces.push(plane(disc(pondX, pondY, pondR * 1.18, 14, 91, 0.9), '#7d7348')) decalFaces.push(plane(disc(pondX, pondY, pondR * 1.18, 14, 91, 0.9), '#3f3a2a'))
decalFaces.push(plane(disc(pondX, pondY, pondR, 14, 92, 1.0), WATER)) decalFaces.push(plane(disc(pondX, pondY, pondR, 14, 92, 1.0), WATER))
decalFaces.push(plane(disc(pondX - pondR * 0.25, pondY + pondR * 0.1, pondR * 0.45, 8, 93, 1.1), scale(WATER, 1.12))) decalFaces.push(plane(disc(pondX - pondR * 0.25, pondY + pondR * 0.1, pondR * 0.45, 8, 93, 1.1), scale(WATER, 1.12)))
taken.push({ x: pondX, y: pondY, r: pondR * 1.3 }) taken.push({ x: pondX, y: pondY, r: pondR * 1.3 })
@ -744,7 +790,7 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
const a = (k / 7) * Math.PI * 2 + hash(k, 94) const a = (k / 7) * Math.PI * 2 + hash(k, 94)
const [x, y] = [pondX + Math.cos(a) * pondR * 1.12, pondY + Math.sin(a) * pondR * 1.12] const [x, y] = [pondX + Math.cos(a) * pondR * 1.12, pondY + Math.sin(a) * pondR * 1.12]
const h = U * (0.3 + 0.25 * hash(k, 95)) const h = U * (0.3 + 0.25 * hash(k, 95))
objects.push({ key: `reed-${k}`, depth: x + y, polys: toPolys(prism(ngon(x, y, U * 0.05, 4), 0, h, '#5b6b2e', '#7a8a3a')) }) objects.push({ key: `reed-${k}`, depth: x + y, polys: toPolys(prism(ngon(x, y, U * 0.05, 4), 0, h, '#45482c', '#5c5a38')) })
} }
} }
const iron = ZONES.iron const iron = ZONES.iron
@ -769,6 +815,57 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
return Math.abs(Math.atan2(Math.sin(a - ZONES[zone].angle), Math.cos(a - ZONES[zone].angle))) < ZONES[zone].half + pad return Math.abs(Math.atan2(Math.sin(a - ZONES[zone].angle), Math.cos(a - ZONES[zone].angle))) < ZONES[zone].half + pad
} }
// Hard times outside the wall: the graveyard behind the village, a grave more as it
// grows and the newest still open; the gallows by the main road; a farmstead burnt down
// and still smouldering. Each takes the first free spot of a few it may stand at.
const free = (x: number, y: number, r: number) =>
!taken.some((t) => Math.hypot(x - t.x, y - t.y) < t.r + r) &&
!ZONE_NAMES.some((z) => inSector(x, y, z, deg(4))) &&
[0, 1, 2, 3, 4, 5, 6, 7, 8].every((k) => !roadClear(x + (k ? Math.cos((k / 8) * Math.PI * 2) * r : 0), y + (k ? Math.sin((k / 8) * Math.PI * 2) * r : 0)))
const site = (angles: number[], from: number, r: number): V2 | null => {
for (let step = 0; step < 8; step++) {
for (const a of angles) {
const [x, y] = dir(a)
if (free(x * (from + step * U * 0.7), y * (from + step * U * 0.7), r)) return [x * (from + step * U * 0.7), y * (from + step * U * 0.7)]
}
}
return null
}
const hard: { key: string; x: number; y: number; faces: Face[] }[] = []
const yard = site([deg(250), deg(240), deg(260), deg(232)], Rv + U * 2.6, U * 1.8)
if (yard) {
const [gx, gy] = yard
const count = Math.min(14, 4 + Math.floor(village.points / 150))
for (let k = 0; k < count; k++) {
const x = gx + (Math.floor(k / 4) - 1) * U * 0.95 + (hash(k, 91) - 0.5) * U * 0.12
const y = gy + ((k % 4) - 1.5) * U * 0.52 + (hash(k, 92) - 0.5) * U * 0.1
hard.push({ key: `grave-${k}`, x, y, faces: grave(x, y, U, 900 + k, k === count - 1) })
}
hard.push({ key: 'grave-tree', x: gx - U * 1.6, y: gy - U * 1.2, faces: deadTree(gx - U * 1.6, gy - U * 1.2, U * 1.5, 77) })
taken.push({ x: gx, y: gy, r: U * 2.1 })
}
{
const [fx, fy] = dir(FRONT)
const t = Rv + U * 2.6
for (const side of [1, -1]) {
const off = (PATH_HALF + U * 2) * side
const [x, y] = [fx * t - fy * off, fy * t + fx * off]
if (!free(x, y, U * 0.8)) continue
hard.push({ key: 'gallows', x, y, faces: gallows(x, y, U * 1.1, side) })
taken.push({ x, y, r: U * 1.1 })
break
}
}
const burnt = site([deg(64), deg(-24), deg(134), deg(150)], Rv + U * 4.2, U * 1.6)
if (burnt) {
const [x, y] = burnt
hard.push({ key: 'ruin', x, y, faces: ruin(x, y, U * 1.15, 5) })
hard.push({ key: 'ruin-tree', x: x + U * 1.3, y: y - U * 0.9, faces: deadTree(x + U * 1.3, y - U * 0.9, U * 1.3, 78) })
smoke.push(project([x + U * 0.1, y, U * 0.35]))
taken.push({ x, y, r: U * 1.8 })
}
for (const o of hard) objects.push({ key: o.key, depth: o.x + o.y, polys: toPolys(o.faces) })
const f = U * 1.25 const f = U * 1.25
const cornersW = [inverse([view.x, view.y]), inverse([view.x + w, view.y]), inverse([view.x, view.y + h]), inverse([view.x + w, view.y + h])] const cornersW = [inverse([view.x, view.y]), inverse([view.x + w, view.y]), inverse([view.x, view.y + h]), inverse([view.x + w, view.y + h])]
const fi0 = Math.floor(Math.min(...cornersW.map((c) => c[0])) / f) const fi0 = Math.floor(Math.min(...cornersW.map((c) => c[0])) / f)
@ -794,14 +891,20 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
if (inSector(x, y, 'farm', deg(6)) && r < zoneEnd('farm') + U * 1.5) density *= 0.15 if (inSector(x, y, 'farm', deg(6)) && r < zoneEnd('farm') + U * 1.5) density *= 0.15
if (inSector(x, y, 'iron', deg(10))) density *= 0.45 if (inSector(x, y, 'iron', deg(10))) density *= 0.45
if (inSector(x, y, 'clay', deg(4)) && r < zoneEnd('clay') + U) density *= 0.4 if (inSector(x, y, 'clay', deg(4)) && r < zoneEnd('clay') + U) density *= 0.4
if (hash(i, j, 63) > Math.min(density, 0.88)) continue
const kind = hash(i, j, 64)
const size = U * (1.0 + 0.55 * hash(i, j, 65)) const size = U * (1.0 + 0.55 * hash(i, j, 65))
const seed = i * 131 + j const seed = i * 131 + j
const faces = kind < 0.1 ? bush(x, y, size * 0.8, seed) : kind < 0.62 ? conifer(x, y, size, seed) : broadleaf(x, y, size, seed) if (hash(i, j, 63) > Math.min(density, 0.88)) {
// The forest round the village has been cut for timber and firewood: stumps remain.
const cleared = r < Rz * 1.1 && !inSector(x, y, 'farm', deg(6)) ? 0.16 : 0.03
if (hash(i, j, 66) < cleared) objects.push({ key: `s${i}:${j}`, depth: x + y, polys: toPolys(stump(x, y, size, seed)) })
continue
}
const kind = hash(i, j, 64)
const faces = kind < 0.1 ? bush(x, y, size * 0.8, seed) : kind < 0.6 ? conifer(x, y, size, seed) : kind < 0.68 ? deadTree(x, y, size, seed) : broadleaf(x, y, size, seed)
taken.push({ x, y, r: size * 0.3 }) taken.push({ x, y, r: size * 0.3 })
shadows.push(shadow(x, y, size * 0.34, scale(GRASS[3]!, 0.8), seed)) shadows.push(shadow(x, y, size * 0.34, scale(GRASS[3]!, 0.68), seed))
objects.push({ key: `t${i}:${j}`, depth: x + y, polys: toPolys(faces) }) // Further out the forest goes dark.
objects.push({ key: `t${i}:${j}`, depth: x + y, polys: toPolys(faces.map((face) => ({ ...face, color: fade(face.color, r, Rz * 0.8, Rz * 1.7, 0.4) }))) })
} }
} }
// A few stones in the meadows. // A few stones in the meadows.
@ -919,18 +1022,28 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
}) })
}) })
// Birds cross the upper part of the view now and then. // Crows cross the upper part of the view now and then, and circle over the graves and
// the gallows.
const birds: Scene['birds'] = [0, 1].map((k) => { const birds: Scene['birds'] = [0, 1].map((k) => {
const y0 = view.y + h * (0.12 + 0.1 * k) const y0 = view.y + h * (0.12 + 0.1 * k)
return { d: `M${(view.x - U * 2).toFixed(1)} ${y0.toFixed(1)} L${(view.x + w + U * 2).toFixed(1)} ${(y0 - h * 0.08).toFixed(1)}`, dur: 30 + k * 11, begin: -k * 17 } return { d: `M${(view.x - U * 2).toFixed(1)} ${y0.toFixed(1)} L${(view.x + w + U * 2).toFixed(1)} ${(y0 - h * 0.08).toFixed(1)}`, dur: 30 + k * 11, begin: -k * 17 }
}) })
const circle = ([x, y]: V2, rx: number, k: number) => {
const [cx, cy] = project([x, y, U * (3.2 + k)])
const ry = rx * 0.4
return `M${(cx - rx).toFixed(1)} ${cy.toFixed(1)} A${rx.toFixed(1)} ${ry.toFixed(1)} 0 1 1 ${(cx + rx).toFixed(1)} ${cy.toFixed(1)} A${rx.toFixed(1)} ${ry.toFixed(1)} 0 1 1 ${(cx - rx).toFixed(1)} ${cy.toFixed(1)}`
}
const gallowsAt = hard.find((o) => o.key === 'gallows')
for (const [k, at] of [yard, yard, gallowsAt ? ([gallowsAt.x, gallowsAt.y] as V2) : null].entries()) {
if (at) birds.push({ d: circle(at, U * (1.6 + k * 0.5), k * 0.6), dur: 9 + k * 3, begin: -k * 4 })
}
objects.sort((a, b) => a.depth - b.depth) objects.sort((a, b) => a.depth - b.depth)
return { return {
viewBox: `${view.x.toFixed(1)} ${view.y.toFixed(1)} ${w.toFixed(1)} ${h.toFixed(1)}`, viewBox: `${view.x.toFixed(1)} ${view.y.toFixed(1)} ${w.toFixed(1)} ${h.toFixed(1)}`,
width: w, width: w,
height: h, height: h,
terrain: ground(view), terrain: ground(view, { r0: Rz * 0.8, r1: Rz * 1.7 }),
// One at a time, so the layers keep the order they were added in. // One at a time, so the layers keep the order they were added in.
decals: [...decalFaces, ...shadows].flatMap((face) => toPolys([face])), decals: [...decalFaces, ...shadows].flatMap((face) => toPolys([face])),
// Wall segments keep their own outlines; the band below covers the stretches between. // Wall segments keep their own outlines; the band below covers the stretches between.