feat: half-timbered houses with framed doors and shuttered windows; villagers come and go through doors, every queued order shows at its site, recruits drill

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-29 16:08:57 +01:00
parent 2c8865bbd4
commit f690e06919
11 changed files with 265 additions and 42 deletions

View File

@ -8,8 +8,8 @@ This is the Nuxt client for a browser strategy game in the style of Tribal Wars.
- **`ssr: false` for every target**, so one static build serves both the web and Steam. Code must not rely on Nuxt server routes or SSR-only APIs. - **`ssr: false` for every target**, so one static build serves both the web and Steam. Code must not rely on Nuxt server routes or SSR-only APIs.
- **Transport** is WS-first through the `ws` singleton from `@blax-software/networking`, the same as learn-atc. HTTP is only for login and register, which return the bearer token. Load the `blax-websockets` skill before you write `ws.send` or `ws.listen` code. - **Transport** is WS-first through the `ws` singleton from `@blax-software/networking`, the same as learn-atc. HTTP is only for login and register, which return the bearer token. Load the `blax-websockets` skill before you write `ws.send` or `ws.listen` code.
- **Dense and plain, like the old browser strategy games** (the reference is Die Stämme; notes and screenshots in the sibling repo `game-village-politics-research` (`../game-village-politics-research/die-staemme/`), kept out of this repo). A 16 px root (17 px from 1800 px wide; rem sizes only, `text-sm` for body text, no fixed `text-[13px]`), square frames with thin lines, tan header bands, tight table rows (`.grid-table`), small squared buttons (`.btn-primary` dark wood, `.btn-attack` red for attacks only), thin notice bars. Actions are buttons, not text links: `.btn` for screen links and commands, `.btn-fill` for the "(20)" that fills an amount field; names inside lists and tables stay links. Bigger text must not add line wraps: keep rows `whitespace-nowrap` where they were one line. No rounded cards, pills, big padding or decorative icons: an icon only where it carries meaning. Theme and component classes live in `app/assets/css/main.css`; hand-written inline SVG graphics in `app/components/icon/`, colours in `app/utils/palette.ts`. No paid, hosted or licensed assets: no icon packs, web fonts or images from outside the repo, and nothing copied from Die Stämme. - **Dense and plain, like the old browser strategy games** (the reference is Die Stämme; notes and screenshots in the sibling repo `game-village-politics-research` (`../game-village-politics-research/die-staemme/`), kept out of this repo). A 16 px root (17 px from 1800 px wide; rem sizes only, `text-sm` for body text, no fixed `text-[13px]`), square frames with thin lines, tan header bands, tight table rows (`.grid-table`), small squared buttons (`.btn-primary` dark wood, `.btn-attack` red for attacks only), thin notice bars. Actions are buttons, not text links: `.btn` for screen links and commands, `.btn-fill` for the "(20)" that fills an amount field; names inside lists and tables stay links. Bigger text must not add line wraps: keep rows `whitespace-nowrap` where they were one line. No rounded cards, pills, big padding or decorative icons: an icon only where it carries meaning. Theme and component classes live in `app/assets/css/main.css`; hand-written inline SVG graphics in `app/components/icon/`, colours in `app/utils/palette.ts`. No paid, hosted or licensed assets: no icon packs, web fonts or images from outside the repo, and nothing copied from Die Stämme.
- **The village is a ground-level land view** (`app/components/village/Diorama.vue`, geometry in `app/diorama/`): isometric low-poly, drawn as inline SVG, no WebGL. The land fills the frame edge to edge (no island, no sky), cut to the container's shape; narrow screens scroll sideways. There are no tiles or positions: the server only sends each building's `space` and the village's `space.used/max`, and the client lays everything out deterministically in id order. The village core sits in the middle (headquarters on the plaza, storage, hiding places and rally point around it, inside the wall ring when there is one, a dirt edge without). Resource sites stand outside in their zones: iron mines at the rocky hill (upper left), clay pits on clay ground (lower left), timber camps at the forest edge (lower right), farms with fields (right); dirt roads lead from the gates to each zone and forest fills the rest. Levels start at 1. Each type has a model per level tier (1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that enter the building (`buildingRoute`): the headquarters opens construction, the rally point its commands, a military building its recruiting, every other building its own screen (`/village/<id>/building/<bid>`); each of these screens starts with `VillageBuildingHeader`: a close-up (`VillageCloseup`, `app/diorama/closeup.ts`: the building large on its ground, its props and forest, its assigned workers walking to where they work and back carrying what they make), what it does now and one level up (`effects`/`next_effects` from the server), workers, priority, upgrade and demolish. The open building stays outlined in the village, and clicking it again returns to the overview. Buildings are clickable anywhere on their outline (`hit`, a convex hull round their polygons and ground ring), the thin wall also along a wide band on its ring, and their level badges and countdowns as well; a type that doesn't stand yet keeps an invisible empty plot that opens its build card. Buildings never move or light up on hover: only a click outlines the ground under them. The village feels alive, and life stays out of the way: flat ground shadows, smoke from chimneys, forges and kilns; workers go out to their zone with their tool (`VillageWorker`, timing in `app/diorama/life.ts`: one SMIL clock per figure for the walk, stepping legs, the tool swing at work, the load on the way home and turning round), two villagers talk on the plaza, a builder hammers at every order in the works, a guard paces inside the gate, sheep graze past the farms and chickens peck round the plaza (`VillageAnimal`), birds cross now and then (`VillageBird`); the close-up does the same for its building. All motion stops under `prefers-reduced-motion`; people who stay put then stand still. The same models draw the building portraits on screen headers, the HQ list and the building cards (`VillageBuildingPortrait`). The world map groups forests, lakes and rocky hills by smooth noise of the coordinates, and village markers grow in five sizes with points. Map coordinates run around 0|0, negative included (−500 to 499 on a 1000-field map, lowest value from `map.view`'s `min`); continents are named from the top-left like Die Stämme, so 0|0 is the corner of K44, K45, K54 and K55. Use `app/utils/map.ts` for bounds and continents, never `0` or `500` literals. - **The village is a ground-level land view** (`app/components/village/Diorama.vue`, geometry in `app/diorama/`): isometric low-poly, drawn as inline SVG, no WebGL. The land fills the frame edge to edge (no island, no sky), cut to the container's shape; narrow screens scroll sideways. There are no tiles or positions: the server only sends each building's `space` and the village's `space.used/max`, and the client lays everything out deterministically in id order. The village core sits in the middle (headquarters on the plaza, storage, hiding places and rally point around it, inside the wall ring when there is one, a dirt edge without). Resource sites stand outside in their zones: iron mines at the rocky hill (upper left), clay pits on clay ground (lower left), timber camps at the forest edge (lower right), farms with fields (right); dirt roads lead from the gates to each zone and forest fills the rest. Levels start at 1. Each type has a model per level tier (1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that enter the building (`buildingRoute`): the headquarters opens construction, the rally point its commands, a military building its recruiting, every other building its own screen (`/village/<id>/building/<bid>`); each of these screens starts with `VillageBuildingHeader`: a close-up (`VillageCloseup`, `app/diorama/closeup.ts`: the building large on its ground, its props and forest, its assigned workers walking to where they work and back carrying what they make), what it does now and one level up (`effects`/`next_effects` from the server), workers, priority, upgrade and demolish. The open building stays outlined in the village, and clicking it again returns to the overview. Buildings are clickable anywhere on their outline (`hit`, a convex hull round their polygons and ground ring), the thin wall also along a wide band on its ring, and their level badges and countdowns as well; a type that doesn't stand yet keeps an invisible empty plot that opens its build card. Buildings never move or light up on hover: only a click outlines the ground under them. The village feels alive, and life stays out of the way: flat ground shadows, smoke from chimneys, forges and kilns; workers go out to their zone with their tool (`VillageWorker`, timing in `app/diorama/life.ts`: one SMIL clock per figure for the walk, stepping legs, the tool swing at work, the load on the way home and turning round), two villagers talk on the plaza, every order in the queue shows at its site (planks and stones piled up, a porter carrying more from the storage door, and while it runs a builder with a hammer, or a pick to tear down), units in training drill in front of their building with an instructor, villagers step out of their doors and go back in (a building's door is found by its `DOOR` colour; resting figures with `indoors` are out of sight), a guard paces inside the gate, sheep graze past the farms and chickens peck round the plaza (`VillageAnimal`), birds cross now and then (`VillageBird`); the close-up does the same for its building. All motion stops under `prefers-reduced-motion`; people who stay put then stand still. The same models draw the building portraits on screen headers, the HQ list and the building cards (`VillageBuildingPortrait`). The world map groups forests, lakes and rocky hills by smooth noise of the coordinates, and village markers grow in five sizes with points. Map coordinates run around 0|0, negative included (−500 to 499 on a 1000-field map, lowest value from `map.view`'s `min`); continents are named from the top-left like Die Stämme, so 0|0 is the corner of K44, K45, K54 and K55. Use `app/utils/map.ts` for bounds and continents, never `0` or `500` literals.
- **Flat medieval colours only**, in the diorama and everywhere else: no gradients (CSS or SVG), no blur or backdrop-blur, no SVG filters or glows, no translucent overlays. Depth comes from the three flat shades per face in `app/diorama/iso.ts`, solid borders and hard shadows. In the diorama there are no outlines: a polygon strokes in its own fill only to close seams, detail comes from a few large shaded panels (a stone plinth, a door and windows from `house()`/`openings()`, two-tier firs, people as shaded shapes in `VillageWalker`), not from many small nodes. A face that must draw over its wall (doors, windows) sets `depth`; offsets and `shift()` carry it along. In the close-up, workers are sorted in among the objects by depth. Surfaces carry small repeating patterns generated in code at startup (`app/utils/patterns.ts` → `--pat-*` custom properties, set by `plugins/patterns.client.ts`, painted per `bg-parchment-*`/`bg-wood-*` class and on `.panel`, `.frame`, `.btn-primary` in `main.css`): parchment flecks, woven header bands with a stitched hem, wood grain; flat opaque shades a step off the surface, never images or opacity. Keep them minimal. One look for every part: each header band is `.panel-head` with a `.panel-title`, everything that floats over the village has the `.float` hard shadow and sits in a bordered frame, and every vertical scroll area is `.scroll-y`, whose bar always shows so content never shifts sideways; the one scrollbar style (wood handle with notches in a parchment track) lives in `main.css`. Every page keeps the page scrollbar, the fullscreen village included (an empty track there), so the usable width never changes when hopping between the village, the map and the reports. Keep components small and typed, with state in composables (`useVillage`, `useWorld`). - **Flat medieval colours only**, in the diorama and everywhere else: no gradients (CSS or SVG), no blur or backdrop-blur, no SVG filters or glows, no translucent overlays. Depth comes from the three flat shades per face in `app/diorama/iso.ts`, solid borders and hard shadows. In the diorama there are no outlines: a polygon strokes in its own fill only to close seams, detail comes from a few large shaded panels (`house()`: a stone plinth, half-timber beams on wooden walls, a framed door, framed windows with shutters, a ridge beam; `openings()` for stone halls; two-tier firs; people as shaded shapes in `VillageWalker`), not from many small nodes. Panels on a wall sort a step in front of that wall face's centroid depth. A face that must draw over its wall (doors, windows) sets `depth`; offsets and `shift()` carry it along. In the close-up, workers are sorted in among the objects by depth. Surfaces carry small repeating patterns generated in code at startup (`app/utils/patterns.ts` → `--pat-*` custom properties, set by `plugins/patterns.client.ts`, painted per `bg-parchment-*`/`bg-wood-*` class and on `.panel`, `.frame`, `.btn-primary` in `main.css`): parchment flecks, woven header bands with a stitched hem, wood grain; flat opaque shades a step off the surface, never images or opacity. Keep them minimal. One look for every part: each header band is `.panel-head` with a `.panel-title`, everything that floats over the village has the `.float` hard shadow and sits in a bordered frame, and every vertical scroll area is `.scroll-y`, whose bar always shows so content never shifts sideways; the one scrollbar style (wood handle with notches in a parchment track) lives in `main.css`. Every page keeps the page scrollbar, the fullscreen village included (an empty track there), so the usable width never changes when hopping between the village, the map and the reports. Keep components small and typed, with state in composables (`useVillage`, `useWorld`).
- **The village fills the screen.** On the village's own screens (`/village/<id>/…`) `GameVillageFrame` draws the diorama fixed across the whole browser window and docks everything over it, solid and opaque: the menu and the village bar along the top, the overview boxes in a right column (on phones a bottom sheet on the overview), and the open screen (headquarters, recruit, rally point, workforce) in a `UiWindow` on the left that folds and closes back to the overview; on the overview the left slot holds the build card of an empty plot picked in the village (`useVillageSelection`). Screen grids inside a window use container queries (`@4xl:`), not viewport breakpoints. The village scales to fit, no pan: the frame measures what the bars, the right column, the phone tab bar and the bottom sheet cover (`inset`), `buildScene` fits the whole village into the rest, and ground and forest are generated for the whole stage, so nothing of the village is ever cut off. Windows are docked now and meant to become draggable later, so `UiWindow` holds no position logic. This is where the game deliberately leaves Die Stämme's look behind. - **The village fills the screen.** On the village's own screens (`/village/<id>/…`) `GameVillageFrame` draws the diorama fixed across the whole browser window and docks everything over it, solid and opaque: the menu and the village bar along the top, the overview boxes in a right column (on phones a bottom sheet on the overview), and the open screen (headquarters, recruit, rally point, workforce) in a `UiWindow` on the left that folds and closes back to the overview; on the overview the left slot holds the build card of an empty plot picked in the village (`useVillageSelection`). Screen grids inside a window use container queries (`@4xl:`), not viewport breakpoints. The village scales to fit, no pan: the frame measures what the bars, the right column, the phone tab bar and the bottom sheet cover (`inset`), `buildScene` fits the whole village into the rest, and ground and forest are generated for the whole stage, so nothing of the village is ever cut off. Windows are docked now and meant to become draggable later, so `UiWindow` holds no position logic. This is where the game deliberately leaves Die Stämme's look behind.
- **One stage for the whole world.** Every page of a world shares that frame, so nothing moves when hopping between them: the reports open in the window over the village, and the map fills the screen under the menu bar itself (it reads `useStage()` for where the menu ends) and teleports its panels (centre and zoom, minimap with the jump form, field info, legend) into the right dock (`#stage-dock`); on phones a small strip with home and zoom floats over it. Only pages outside a world, or a world whose village isn't known yet, sit in the centred column (1100 px). All world pages use `layouts/game.vue` (on village screens `GameVillageFrame` draws the same parts over the village): the dark main menu (`GameMenuBar`: village, map, reports with its count inline, each with a hover dropdown of its sub-pages; server clock; account dropdown), then the village header (`GameVillageBar`, in two pieces with the village showing between them: on the left the quick bar with the village's screens over the village row, on the right the stock in thin cells and incoming troops; the space between lets clicks through), thin notices, and the content in a `.frame`. On phones the screens move to a bottom tab bar (`GameTabBar`). The header's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`. Pages outside a world use `layouts/default.vue` (menu only). A page has one of two shapes: a title with box tabs (`UiSubTabs`: buildings like the rally point) or a title with a sub-menu on the left (`UiSideMenu`: lists like reports). One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. The map shows a popup over a hovered village and actions under a clicked one. The village row starts with the quest book (`QuestBook`, a native `<dialog>` without a veil): it opens by itself when `quests.claimable` goes up, and a goal's "show me" opens its screen, a building goal the headquarters with `?hint=<type>` marking that row. - **One stage for the whole world.** Every page of a world shares that frame, so nothing moves when hopping between them: the reports open in the window over the village, and the map fills the screen under the menu bar itself (it reads `useStage()` for where the menu ends) and teleports its panels (centre and zoom, minimap with the jump form, field info, legend) into the right dock (`#stage-dock`); on phones a small strip with home and zoom floats over it. Only pages outside a world, or a world whose village isn't known yet, sit in the centred column (1100 px). All world pages use `layouts/game.vue` (on village screens `GameVillageFrame` draws the same parts over the village): the dark main menu (`GameMenuBar`: village, map, reports with its count inline, each with a hover dropdown of its sub-pages; server clock; account dropdown), then the village header (`GameVillageBar`, in two pieces with the village showing between them: on the left the quick bar with the village's screens over the village row, on the right the stock in thin cells and incoming troops; the space between lets clicks through), thin notices, and the content in a `.frame`. On phones the screens move to a bottom tab bar (`GameTabBar`). The header's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`. Pages outside a world use `layouts/default.vue` (menu only). A page has one of two shapes: a title with box tabs (`UiSubTabs`: buildings like the rally point) or a title with a sub-menu on the left (`UiSideMenu`: lists like reports). One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. The map shows a popup over a hovered village and actions under a clicked one. The village row starts with the quest book (`QuestBook`, a native `<dialog>` without a veil): it opens by itself when `quests.claimable` goes up, and a goal's "show me" opens its screen, a building goal the headquarters with `?hint=<type>` marking that row.
- All user-facing text goes through i18n keys, with `en` as the first locale. Sources are `i18n/locales/` and `i18n/pages/` (`@blax-software/i18n` layout); register a new page file in `i18n/messageloader.ts`. vue-i18n reads a bare `|` as a plural separator and drops what follows, so coordinates in messages are written `"{x}{'|'}{y}"` inside a double-quoted string. - All user-facing text goes through i18n keys, with `en` as the first locale. Sources are `i18n/locales/` and `i18n/pages/` (`@blax-software/i18n` layout); register a new page file in `i18n/messageloader.ts`. vue-i18n reads a bare `|` as a plural separator and drops what follows, so coordinates in messages are written `"{x}{'|'}{y}"` inside a double-quoted string.

View File

@ -16,8 +16,18 @@ const emit = defineEmits<{
}>() }>()
const { t } = useI18n() const { t } = useI18n()
const v = useVillageContext() const v = useVillageContext()
/** A builder is at work on it right now. */ /** What goes on at it right now, for the close-up: orders running or waiting, units in training. */
const upgrading = computed(() => !!v.village.value?.queue.some((o) => o.building_id === props.building.id && o.builder !== null)) const state = computed(() => {
const village = v.village.value
const orders = village?.queue.filter((o) => o.building_id === props.building.id) ?? []
const running = orders.find((o) => o.builder !== null)
return {
upgrading: running?.action === 'upgrade',
demolishing: running?.action === 'demolish',
queued: orders.length > 0,
training: !!village?.military.find((m) => m.building_id === props.building.id)?.queue.length,
}
})
/** Effects side by side: now and one level up (null at max level). */ /** Effects side by side: now and one level up (null at max level). */
const rows = computed(() => const rows = computed(() =>
@ -49,7 +59,7 @@ function value(e: BuildingEffect) {
<template> <template>
<section class="grid gap-3 @3xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]"> <section class="grid gap-3 @3xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
<div class="h-52 border border-wood-700 @3xl:h-auto @3xl:min-h-60"> <div class="h-52 border border-wood-700 @3xl:h-auto @3xl:min-h-60">
<VillageCloseup :type="building.type" :level="building.level" :workers="building.workers.assigned" :upgrading="upgrading" /> <VillageCloseup :type="building.type" :level="building.level" :workers="building.workers.assigned" :state="state" />
</div> </div>
<div class="space-y-2.5 text-sm"> <div class="space-y-2.5 text-sm">

View File

@ -1,14 +1,14 @@
<script setup lang="ts"> <script setup lang="ts">
import type { BuildingType } from '~/types/game' import type { BuildingType } from '~/types/game'
import { buildCloseup } from '~/diorama/closeup' import { buildCloseup, type CloseupState } from '~/diorama/closeup'
import { workInPlace } from '~/diorama/life' import { drillThrust, workInPlace } from '~/diorama/life'
const props = defineProps<{ const props = defineProps<{
type: BuildingType type: BuildingType
level: number level: number
workers: number workers: number
/** A builder hammers at it while an upgrade is running. */ /** Orders running or waiting at it, units in training: builders, materials, a drill. */
upgrading?: boolean state?: CloseupState
}>() }>()
// Drawn for the stage's own shape, so land and forest fill it edge to edge. // Drawn for the stage's own shape, so land and forest fill it edge to edge.
@ -26,8 +26,9 @@ onMounted(() => {
}) })
onBeforeUnmount(() => observer?.disconnect()) onBeforeUnmount(() => observer?.disconnect())
const scene = computed(() => buildCloseup(props.type, props.level, props.workers, aspect.value, props.upgrading)) const scene = computed(() => buildCloseup(props.type, props.level, props.workers, aspect.value, props.state))
const hammering = workInPlace() const hammering = workInPlace()
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)
@ -55,13 +56,15 @@ const SHIRTS = ['#6b4f3a', '#7b1e16', '#3d5a26', '#57391f', '#5a5f63']
:work="l.walk.work" :work="l.walk.work"
:tool="l.walk.tool" :tool="l.walk.tool"
:carry="l.walk.carry" :carry="l.walk.carry"
:rest="l.walk.rest"
:indoors="l.walk.indoors"
:shirt="SHIRTS[i % SHIRTS.length]!" :shirt="SHIRTS[i % SHIRTS.length]!"
:size="2.6" :size="2.6"
:begin="l.walk.begin" :begin="l.walk.begin"
/> />
</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 :shirt="SHIRTS[i % SHIRTS.length]!" :facing="l.life.facing" :tool="l.life.tool" :swing="motion ? hammering : null" /> <VillageWalker :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">
<polygon v-for="(p, j) in l.polys" :key="j" :points="p.points" :fill="p.fill" :stroke="p.stroke" /> <polygon v-for="(p, j) in l.polys" :key="j" :points="p.points" :fill="p.fill" :stroke="p.stroke" />

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { BuildingType, VillageState } from '~/types/game' import type { BuildingType, VillageState } from '~/types/game'
import { 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'
const props = defineProps<{ const props = defineProps<{
@ -213,10 +213,26 @@ const timers = computed(() => {
:shirt="SHIRTS[obj.life.shirt % SHIRTS.length]!" :shirt="SHIRTS[obj.life.shirt % SHIRTS.length]!"
:facing="obj.life.facing" :facing="obj.life.facing"
:tool="obj.life.tool" :tool="obj.life.tool"
:swing="motion && obj.life.tool ? workInPlace() : null" :swing="motion && obj.life.tool ? (obj.life.drill ? drillThrust() : workInPlace()) : null"
/> />
</g> </g>
</g> </g>
<!-- Villagers coming out of a door and going back in, porters bringing materials. -->
<g v-else-if="obj.walker" class="pointer-events-none">
<VillageWorker
v-if="motion"
:d="obj.walker.d"
:walk="obj.walker.walk"
:work="obj.walker.work"
:rest="obj.walker.rest"
:indoors="obj.walker.indoors"
:tool="obj.walker.tool"
:carry="obj.walker.carry"
:shirt="SHIRTS[obj.walker.shirt % SHIRTS.length]!"
:size="1.6"
:begin="obj.walker.begin"
/>
</g>
<g v-else v-memo="[obj]" stroke-width="0.6" stroke-linejoin="round"> <g v-else v-memo="[obj]" stroke-width="0.6" stroke-linejoin="round">
<polygon v-for="(p, i) in obj.polys" :key="i" :points="p.points" :fill="p.fill" :stroke="p.stroke" /> <polygon v-for="(p, i) in obj.polys" :key="i" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
<title v-if="obj.planned">{{ $t('village.diorama.planned') }}</title> <title v-if="obj.planned">{{ $t('village.diorama.planned') }}</title>

View File

@ -44,6 +44,16 @@ const HEADS: Record<Tool, string> = {
--> -->
<template> <template>
<g :transform="`scale(${facing ?? 1} 1)`"> <g :transform="`scale(${facing ?? 1} 1)`">
<animate
v-if="cycle?.presence"
attributeName="visibility"
calcMode="discrete"
:values="cycle.presence.values"
:keyTimes="cycle.presence.keyTimes"
:dur="`${cycle.dur}s`"
:begin="begin"
repeatCount="indefinite"
/>
<animateTransform <animateTransform
v-if="cycle" v-if="cycle"
attributeName="transform" attributeName="transform"
@ -68,7 +78,7 @@ const HEADS: Record<Tool, string> = {
<g v-if="tool"> <g v-if="tool">
<animateTransform <animateTransform
v-if="toolSwing && tool !== 'spear'" v-if="toolSwing && (tool !== 'spear' || swing)"
attributeName="transform" attributeName="transform"
type="rotate" type="rotate"
:values="swingValues" :values="swingValues"

View File

@ -13,6 +13,10 @@ const props = defineProps<{
size: number size: number
/** Seconds into its cycle, so workers on one road don't move in lockstep. */ /** Seconds into its cycle, so workers on one road don't move in lockstep. */
begin: number begin: number
/** Seconds at home between trips (default 1.2). */
rest?: number
/** Home is a building: out of sight while resting there. */
indoors?: boolean
}>() }>()
/** Faces right when the way out leads right on screen. */ /** Faces right when the way out leads right on screen. */
@ -20,7 +24,7 @@ const facing = computed<1 | -1>(() => {
const nums = props.d.match(/-?\d+(\.\d+)?/g)?.map(Number) ?? [] const nums = props.d.match(/-?\d+(\.\d+)?/g)?.map(Number) ?? []
return nums.length >= 4 && nums[nums.length - 2]! < nums[0]! ? -1 : 1 return nums.length >= 4 && nums[nums.length - 2]! < nums[0]! ? -1 : 1
}) })
const cycle = computed(() => workCycle(props.walk, props.work, 1.2, facing.value)) const cycle = computed(() => workCycle(props.walk, props.work, props.rest ?? 1.2, facing.value, props.indoors))
</script> </script>
<!-- A villager going out to work, working, and bringing the load home, round and round. --> <!-- A villager going out to work, working, and bringing the load home, round and round. -->

View File

@ -4,7 +4,7 @@
// rocks for an iron mine, fields for a farm, the wall walk for the wall). // rocks for an iron mine, fields for a farm, the wall walk for the wall).
import type { BuildingType } from '~/types/game' import type { BuildingType } from '~/types/game'
import { type Face, hash, plane, type Poly, project, 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, rock } from './models'
import { disc, ground, shadow, U, wallSegments } from './scene' import { disc, ground, shadow, U, wallSegments } from './scene'
@ -22,7 +22,7 @@ export interface Closeup {
layers: ( layers: (
| { key: string; polys: Poly[]; walk?: undefined; life?: undefined } | { key: string; polys: Poly[]; walk?: undefined; life?: undefined }
| { key: string; walk: Walk; polys?: undefined; life?: undefined } | { key: string; walk: Walk; polys?: undefined; life?: undefined }
| { key: string; life: { at: V2; facing: 1 | -1; tool: Tool | null }; polys?: undefined; walk?: undefined } | { key: string; life: { at: V2; facing: 1 | -1; tool: Tool | null; drill?: boolean }; polys?: undefined; walk?: undefined }
)[] )[]
/** Sheep at a farm, chickens round the core buildings. */ /** Sheep at a farm, chickens round the core buildings. */
herds: { kind: 'sheep' | 'chicken'; d: string; dur: number; begin: number }[] herds: { kind: 'sheep' | 'chicken'; d: string; dur: number; begin: number }[]
@ -37,6 +37,17 @@ export interface Walk {
begin: number begin: number
tool: Tool | null tool: Tool | null
carry: string | null carry: string | null
/** Seconds at the start between trips, out of sight when they live in the building. */
rest?: number
indoors?: boolean
}
/** What is going on at the building: an order running or waiting, units in training. */
export interface CloseupState {
upgrading?: boolean
demolishing?: boolean
queued?: boolean
training?: boolean
} }
type Kind = 'timber' | 'clay' | 'iron' | 'farm' | 'wall' | 'core' type Kind = 'timber' | 'clay' | 'iron' | 'farm' | 'wall' | 'core'
@ -62,7 +73,7 @@ const at = (a: number, r: number): V2 => [Math.cos(a) * r, Math.sin(a) * r]
const screen = ([x, y]: V2, z = 1.2) => project([x, y, z]) const screen = ([x, y]: V2, z = 1.2) => project([x, y, z])
const line = (pts: V2[]) => pts.map((p, i) => `${i ? 'L' : 'M'}${screen(p).map((v) => v.toFixed(1)).join(' ')}`).join(' ') const line = (pts: V2[]) => pts.map((p, i) => `${i ? 'L' : 'M'}${screen(p).map((v) => v.toFixed(1)).join(' ')}`).join(' ')
export function buildCloseup(type: BuildingType, level: number, workers: number, aspect = 2, upgrading = false): Closeup { export function buildCloseup(type: BuildingType, level: number, workers: number, aspect = 2, state: CloseupState = {}): Closeup {
const kind = KIND[type] ?? 'core' const kind = KIND[type] ?? 'core'
const objects: { key: string; depth: number; polys: Poly[] }[] = [] const objects: { key: string; depth: number; polys: Poly[] }[] = []
const decals: Face[] = [plane(disc(0, 0, S * 2.3, 16, 7, 0.5), GROUND[kind])] const decals: Face[] = [plane(disc(0, 0, S * 2.3, 16, 7, 0.5), GROUND[kind])]
@ -70,6 +81,8 @@ export function buildCloseup(type: BuildingType, level: number, workers: number,
const taken: { x: number; y: number; r: number }[] = [{ x: 0, y: 0, r: S * 1.5 }] const taken: { x: number; y: number; r: number }[] = [{ x: 0, y: 0, r: S * 1.5 }]
/** Where workers go; each leaves the building on the side that faces their spot. */ /** Where workers go; each leaves the building on the side that faces their spot. */
const spots: V2[] = [] const spots: V2[] = []
/** Just outside the building's door, if it has one. */
let door: V2 | null = null
const put = (key: string, x: number, y: number, faces: Face[], r: number) => { const put = (key: string, x: number, y: number, faces: Face[], r: number) => {
objects.push({ key, depth: x + y, polys: toPolys(faces) }) objects.push({ key, depth: x + y, polys: toPolys(faces) })
taken.push({ x, y, r }) taken.push({ x, y, r })
@ -83,6 +96,8 @@ export function buildCloseup(type: BuildingType, level: number, workers: number,
} else { } else {
const model = buildingModel(type, level, S) const model = buildingModel(type, level, S)
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)
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.8), 3))
} }
@ -177,11 +192,41 @@ export function buildCloseup(type: BuildingType, level: number, workers: number,
walk: { d: line(path), walk, work, begin: -(i * (walk * 2 + work)) / Math.max(1, shown), tool: TOOL[kind], carry: CARRY[kind] }, walk: { d: line(path), walk, work, begin: -(i * (walk * 2 + work)) / Math.max(1, shown), tool: TOOL[kind], carry: CARRY[kind] },
}) })
} }
// A builder hammers at the building while it is being upgraded. // A builder works at the building while an order runs: a hammer to build, a pick to tear
const life: { key: string; depth: number; life: { at: V2; facing: 1 | -1; tool: Tool | null } }[] = [] // down. Any order for it piles materials in front, and a porter brings more.
if (upgrading && kind !== 'wall') { const life: { key: string; depth: number; life: { at: V2; facing: 1 | -1; tool: Tool | null; drill?: boolean } }[] = []
const [x, y] = at(deg(15), S * 1.35) const person = (key: string, [x, y]: V2, facing: 1 | -1, tool: Tool | null, drill = false) =>
life.push({ key: 'builder', depth: x + y, life: { at: screen([x, y]), facing: -1, tool: 'hammer' } }) life.push({ key, depth: x + y, life: { at: screen([x, y]), facing, tool, drill } })
if ((state.upgrading || state.demolishing) && kind !== 'wall') person('builder', at(deg(15), S * 1.35), -1, state.demolishing ? 'pick' : 'hammer')
if ((state.queued || state.upgrading) && kind !== 'wall') {
const pile = at(deg(80), S * 1.45)
objects.push({
key: 'pile',
depth: pile[0] + pile[1],
polys: toPolys([
...box(pile[0], pile[1], U * 0.9, U * 0.4, 0, U * 0.13, C.plank, C.wood),
...box(pile[0] + U * 0.05, pile[1] - U * 0.05, U * 0.85, U * 0.36, U * 0.13, U * 0.13, C.wood, C.plank),
...pyramid(ngon(pile[0] + U * 0.7, pile[1] + U * 0.2, U * 0.26, 5), 0, U * 0.26, C.stone),
]),
})
const from = at(deg(100), S * 3.4)
const to: V2 = [pile[0] - U * 0.2, pile[1] + U * 0.5]
const walk = Math.hypot(to[0] - from[0], to[1] - from[1]) / U
walkers.push({ key: 'porter', depth: Math.max(from[0] + from[1], to[0] + to[1]), walk: { d: line([from, to]), walk, work: 1.4, begin: -2, tool: null, carry: C.plank, rest: 2, indoors: true } })
}
// Units in training drill in front, an instructor facing them.
if (state.training) {
for (let k = 0; k < 3; k++) person(`drill${k}`, [S * 1.95, -S * 0.55 + k * U * 0.85], 1, 'spear', true)
person('instructor', [S * 1.95 + U * 1.5, S * 0.1], -1, null)
}
// Someone steps out of the door now and then, stands a moment, and goes back in.
if (door && kind === 'core') {
const out = at(deg(25), S * 2.1)
walkers.push({
key: 'visitor',
depth: Math.max(door[0] + door[1], out[0] + out[1]),
walk: { d: line([door, out]), walk: Math.hypot(out[0] - door[0], out[1] - door[1]) / U * 0.9, work: 3, begin: -4, tool: null, carry: null, rest: 7, indoors: true },
})
} }
// Animals and birds. // Animals and birds.

View File

@ -144,7 +144,8 @@ 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 = '#948d82'
const DOOR = '#4a3220' /** Doors are this colour; the scene finds a building's door by it. */
export const DOOR = '#4a3220'
const WINDOW = '#2f2620' const WINDOW = '#2f2620'
export function rect(cx: number, cy: number, w: number, d: number): V2[] { export function rect(cx: number, cy: number, w: number, d: number): V2[] {
@ -237,24 +238,61 @@ function wallPanel(face: 'x' | 'y', at: number, along: number, z0: number, w: nu
/** /**
* A door on the wall towards the lower right and windows on the one towards the lower * A door on the wall towards the lower right and windows on the one towards the lower
* left of a box standing on z0, as flat dark panels just outside the walls. * left of a box standing on z0: flat panels just outside the walls. The door sits in a
* light frame; each window has a frame and a shutter either side.
*/ */
export function openings(cx: number, cy: number, w: number, d: number, z0: number, h: number): Face[] { export function openings(cx: number, cy: number, w: number, d: number, z0: number, h: number, walls = '#8a5f38'): Face[] {
const ex = cx + w / 2 + 0.25 const ex = cx + w / 2 + 0.25
const ey = cy + d / 2 + 0.25 const ey = cy + d / 2 + 0.25
// 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 yDepth = cx + cy + d / 2 + (z0 + h) / 2 + 0.1
const frame = mix(walls, '#efe4c6', 0.45)
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 doorAt = cy + d * 0.12
const win = Math.min(w, d) * 0.16 const win = Math.min(w, d) * 0.16
const winZ = z0 + (h - z0) * 0.45
const windows = w > d * 1.15 ? [cx - w * 0.22, cx + w * 0.22] : [cx] const windows = w > d * 1.15 ? [cx - w * 0.22, cx + w * 0.22] : [cx]
return [ return [
wallPanel('x', ex, cy + d * 0.12, z0, door, (h - z0) * 0.62, ex + cy + h * 0.5, DOOR), wallPanel('x', ex, doorAt, z0, door * 1.3, doorH + door * 0.18, xDepth, frame),
...windows.map((wx) => wallPanel('y', ey, wx, z0 + (h - z0) * 0.45, win, win * 0.9, cx + ey + h * 0.5, WINDOW)), wallPanel('x', ex + 0.05, doorAt, z0, door, doorH, xDepth + 0.05, DOOR),
...windows.flatMap((wx) => [
wallPanel('y', ey, wx, winZ - win * 0.12, win * 1.3, win * 1.12, yDepth, frame),
wallPanel('y', ey + 0.05, wx, winZ, win, win * 0.88, yDepth + 0.05, WINDOW),
wallPanel('y', ey, wx - win * 0.98, winZ, win * 0.42, win * 0.88, yDepth, shutter),
wallPanel('y', ey, wx + win * 0.98, winZ, win * 0.42, win * 0.88, yDepth, shutter),
]),
] ]
} }
/** Dark beams of a half-timbered wall: corner posts and a top beam on the two walls in view. */
function framing(cx: number, cy: number, w: number, d: number, z0: number, h: number, walls: string): Face[] {
const beam = scale(walls, 0.62)
const t = Math.min(w, d) * 0.06
const ex = cx + w / 2 + 0.15
const ey = cy + d / 2 + 0.15
// Just in front of the wall face, behind doors and windows.
const xDepth = cx + w / 2 + cy + (z0 + h) / 2 + 0.02
const yDepth = cx + cy + d / 2 + (z0 + h) / 2 + 0.02
return [
wallPanel('x', ex, cy - d / 2 + t / 2, z0, t, h - z0, xDepth, beam),
wallPanel('x', ex, cy + d / 2 - t / 2, z0, t, h - z0, xDepth, beam),
wallPanel('x', ex, cy, h - t, d, t, xDepth, beam),
wallPanel('y', ey, cx - w / 2 + t / 2, z0, t, h - z0, yDepth, beam),
wallPanel('y', ey, cx + w / 2 - t / 2, z0, t, h - z0, yDepth, beam),
wallPanel('y', ey, cx, h - t, w, t, yDepth, beam),
]
}
const STONE_WALLS = new Set(['#a39d92', '#847e74', STONE])
/** /**
* A box with a gable roof: the most common house. It stands on a low stone plinth and * A box with a gable roof: the most common house. It stands on a low stone plinth, wooden
* shows a door on the wall towards the lower right and windows on the one towards the * walls show their beams, the door on the wall towards the lower right and framed,
* lower left, as flat dark panels: a few large faces, no outlines. * shuttered windows on the one towards the lower left, a dark beam along the ridge.
* A few large faces, no outlines.
*/ */
export function house( export function house(
cx: number, cx: number,
@ -269,11 +307,19 @@ export function house(
): Face[] { ): Face[] {
const o = Math.min(w, d) * 0.08 const o = Math.min(w, d) * 0.08
const plinth = Math.min(h * 0.16, Math.min(w, d) * 0.12) const plinth = Math.min(h * 0.16, Math.min(w, d) * 0.12)
const t = Math.min(w, d) * 0.07
const top = h + rise
// The ridge beam draws over the roof it sits on.
const ridge = (along === 'x' ? box(cx, cy, w + o * 2, t, top - t * 0.6, t, scale(roof, 0.62)) : box(cx, cy, t, d + o * 2, top - t * 0.6, t, scale(roof, 0.62))).map(
(f) => ({ ...f, depth: cx + cy + top + w + d }),
)
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),
...openings(cx, cy, w, d, plinth, h), ...(STONE_WALLS.has(walls) ? [] : framing(cx, cy, w, d, plinth, h, walls)),
...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),
...ridge,
] ]
} }

View File

@ -16,6 +16,8 @@ export interface Cycle {
load: { values: string; keyTimes: string } load: { values: string; keyTimes: string }
/** Turns round to walk home. */ /** Turns round to walk home. */
face: { values: string; keyTimes: string } face: { values: string; keyTimes: string }
/** Gone indoors while resting at home, for people who live in a building; null: always seen. */
presence: { values: string; keyTimes: string } | null
} }
const STEP = 0.32 const STEP = 0.32
@ -47,8 +49,9 @@ function keys(points: [number, string][]): { values: string; keyTimes: string }
/** /**
* A work cycle: walk out for `walk` seconds, work for `work`, walk home for `walk`, stand * A work cycle: walk out for `walk` seconds, work for `work`, walk home for `walk`, stand
* for `rest`. `facing` is 1 when walking out goes to the right on screen, else -1. * for `rest`. `facing` is 1 when walking out goes to the right on screen, else -1.
* `indoors`: the rest is spent inside a building, out of sight.
*/ */
export function workCycle(walk: number, work: number, rest = 1.2, facing: 1 | -1 = 1): Cycle { export function workCycle(walk: number, work: number, rest = 1.2, facing: 1 | -1 = 1, indoors = false): Cycle {
const dur = walk * 2 + work + rest const dur = walk * 2 + work + rest
const a = walk / dur const a = walk / dur
const b = (walk + work) / dur const b = (walk + work) / dur
@ -66,6 +69,7 @@ export function workCycle(walk: number, work: number, rest = 1.2, facing: 1 | -1
swing: keys([[0, '0'], [a, '0'], ...alternate(walk, walk + work, dur, SWING, '-70', '35'), [b, '0'], [1, '0']]), swing: keys([[0, '0'], [a, '0'], ...alternate(walk, walk + work, dur, SWING, '-70', '35'), [b, '0'], [1, '0']]),
load: { values: 'hidden;visible;hidden', keyTimes: `0;${b.toFixed(4)};${c.toFixed(4)}` }, load: { values: 'hidden;visible;hidden', keyTimes: `0;${b.toFixed(4)};${c.toFixed(4)}` },
face: { values: `${facing} 1;${-facing} 1;${facing} 1`, keyTimes: `0;${b.toFixed(4)};${c.toFixed(4)}` }, face: { values: `${facing} 1;${-facing} 1;${facing} 1`, keyTimes: `0;${b.toFixed(4)};${c.toFixed(4)}` },
presence: indoors ? { values: 'visible;hidden', keyTimes: `0;${c.toFixed(4)}` } : null,
} }
} }
@ -73,3 +77,8 @@ export function workCycle(walk: number, work: number, rest = 1.2, facing: 1 | -1
export function workInPlace(): { dur: number; values: string; keyTimes: string } { export function workInPlace(): { dur: number; values: string; keyTimes: string } {
return { dur: SWING * 2, values: '-70;35;-70', keyTimes: '0;0.5;1' } return { dur: SWING * 2, values: '-70;35;-70', keyTimes: '0;0.5;1' }
} }
/** A recruit in drill: the spear comes down to the front and back up, in time with the others. */
export function drillThrust(): { dur: number; values: string; keyTimes: string } {
return { dur: 1.8, values: '0;62;62;0;0', keyTimes: '0;0.18;0.4;0.6;1' }
}

View File

@ -233,7 +233,7 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
return { return {
faces: [ faces: [
...box(0, 0, s * 1.35, s * 1.35, 0, s * 0.9, C.stone, C.stoneDark), ...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), ...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), ...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), ...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), ...pyramid(ngon(-s * 0.72, s * 0.72, s * 0.34, 6), s * 1.3, s * 0.45, C.slate),
@ -486,7 +486,7 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
return { return {
faces: [ faces: [
...box(0, 0, s * 1.9, s * 1.1, 0, s * 0.75, C.stone, C.stoneDark), ...box(0, 0, s * 1.9, s * 1.1, 0, s * 0.75, C.stone, C.stoneDark),
...openings(0, 0, s * 1.9, s * 1.1, 0, s * 0.75), ...openings(0, 0, s * 1.9, s * 1.1, 0, s * 0.75, C.stone),
...pyramid(rect(0, 0, s * 2.0, s * 1.2), s * 0.75, s * 0.45, C.slate), ...pyramid(rect(0, 0, s * 2.0, s * 1.2), s * 0.75, s * 0.45, C.slate),
...prism(ngon(s * 0.85, -s * 0.5, s * 0.25, 6), 0, s * 1.3, C.stone), ...prism(ngon(s * 0.85, -s * 0.5, s * 0.25, 6), 0, s * 1.3, C.stone),
...pyramid(ngon(s * 0.85, -s * 0.5, s * 0.3, 6), s * 1.3, s * 0.4, C.slate), ...pyramid(ngon(s * 0.85, -s * 0.5, s * 0.3, 6), s * 1.3, s * 0.4, C.slate),
@ -533,7 +533,7 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
return { return {
faces: [ faces: [
...box(0, 0, s * 1.6, s * 1.3, 0, s * 0.9, C.stone, C.stoneDark), ...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), ...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), ...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),
...tower(s * 0.85, s * 0.7, s * 1.5), ...tower(s * 0.85, s * 0.7, s * 1.5),

View File

@ -10,7 +10,7 @@
// 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 { type Face, hash, ngon, plane, type Poly, prism, project, pyramid, scale, toPolys, type V2, type V3 } from './iso' import { box, DOOR, type Face, hash, 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 { broadleaf, buildingModel, bush, C, conifer, crane, rock, scaffold, well } from './models'
@ -63,8 +63,24 @@ export interface SceneObject {
polys: Poly[] polys: Poly[]
building?: SceneBuilding building?: SceneBuilding
planned?: boolean planned?: boolean
/** A villager who stays put, sorted in among the buildings: chatting, or building with a hammer. */ /** A villager who stays put, sorted in among the buildings: chatting, building, drilling. */
life?: SceneLife life?: SceneLife
/** A villager going somewhere and back, sorted in among the buildings: out of a door, a porter. */
walker?: SceneWalker
}
export interface SceneWalker {
/** Screen path from where they start (a door, a store) to where they go. */
d: string
walk: number
work: number
rest: number
/** Out of sight while resting: they live in the building they come out of. */
indoors: boolean
tool: Tool | null
carry: string | null
shirt: number
begin: number
} }
export interface SceneLife { export interface SceneLife {
@ -73,6 +89,8 @@ export interface SceneLife {
facing: 1 | -1 facing: 1 | -1
tool: Tool | null tool: Tool | null
shirt: number shirt: number
/** A recruit thrusting the spear in drill, instead of a tool at work. */
drill?: boolean
} }
/** What each zone's workers work with and bring home. */ /** What each zone's workers work with and bring home. */
@ -464,13 +482,20 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
const anchorOfBuilding = new Map<number, V2>() const anchorOfBuilding = new Map<number, V2>()
const anchorOfOrder = new Map<number, V2>() const anchorOfOrder = new Map<number, V2>()
// Buildings and queued new ones. // Buildings and queued new ones. Each door is remembered as the ground point just outside it.
const doorOf = new Map<number, V2>()
for (const b of village.buildings) { for (const b of village.buildings) {
if (b.type === 'wall') continue if (b.type === 'wall') continue
const slot = b.type === 'headquarters' ? core[0]! : slotOf(`b${b.id}`) const slot = b.type === 'headquarters' ? core[0]! : slotOf(`b${b.id}`)
const zone = ZONE_OF[b.type] const zone = ZONE_OF[b.type]
const s = zone ? slot.s : halfSize(b.space) const s = zone ? slot.s : halfSize(b.space)
const model = buildingModel(b.type, b.level, s) const model = buildingModel(b.type, b.level, s)
const doorFace = model.faces.find((f) => f.color === DOOR)
if (doorFace) {
const dx = doorFace.pts.reduce((n, p) => n + p[0], 0) / doorFace.pts.length
const dy = doorFace.pts.reduce((n, p) => n + p[1], 0) / doorFace.pts.length
doorOf.set(b.id, [slot.x + dx + U * 0.3, slot.y + dy])
}
const upgrading = running.has(b.id) const upgrading = running.has(b.id)
const faces = upgrading ? [...model.faces, ...crane(s, model.height)] : model.faces const faces = upgrading ? [...model.faces, ...crane(s, model.height)] : model.faces
const label = project([slot.x, slot.y, model.height + 10]) const label = project([slot.x, slot.y, model.height + 10])
@ -724,13 +749,68 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
const [chatX, chatY] = dir(FRONT + deg(32)).map((v) => v * hqRadius * 1.3) const [chatX, chatY] = dir(FRONT + deg(32)).map((v) => v * hqRadius * 1.3)
people('chat-a', chatX! - U * 0.45, chatY! + U * 0.45, 1, null, 1) people('chat-a', chatX! - U * 0.45, chatY! + U * 0.45, 1, null, 1)
people('chat-b', chatX! + U * 0.45, chatY! - U * 0.45, -1, null, 3) people('chat-b', chatX! + U * 0.45, chatY! - U * 0.45, -1, null, 3)
for (const o of village.queue.filter((q) => q.builder !== null)) { const path = (pts: V2[]) => pts.map(([x, y], i) => `${i ? 'L' : 'M'}${project([x, y, 1.2]).map((v) => v.toFixed(1)).join(' ')}`).join(' ')
const walker = (key: string, from: V2, to: V2, w: Omit<SceneWalker, 'd' | 'walk'>) =>
objects.push({ key, depth: Math.max(from[0] + from[1], to[0] + to[1]), polys: [], walker: { d: path([from, to]), walk: Math.max(2, Math.hypot(to[0] - from[0], to[1] - from[1]) / U * 0.9), ...w } })
// Every order in the queue shows where it goes: building materials piled at the site, a
// porter bringing more from the storage, and while it runs, a builder at work.
const store = village.buildings.find((b) => b.type === 'storage') ?? village.buildings.find((b) => b.type === 'headquarters')
const storeDoor = store ? doorOf.get(store.id) : undefined
const sites = new Set<string>()
for (const o of village.queue) {
const b = o.building_id !== null ? village.buildings.find((x) => x.id === o.building_id) : null const b = o.building_id !== null ? village.buildings.find((x) => x.id === o.building_id) : null
if (b?.type === 'wall') continue if (b?.type === 'wall' || (!b && o.type === 'wall')) continue
const slot = b ? (b.type === 'headquarters' ? core[0]! : slotOf(`b${b.id}`)) : slotOf(`o${o.id}`) const slot = b ? (b.type === 'headquarters' ? core[0]! : slotOf(`b${b.id}`)) : slotOf(`o${o.id}`)
people(`builder-${o.id}`, slot.x + slot.r * 0.95, slot.y + slot.r * 0.35, -1, 'hammer', o.id) if (o.builder !== null) {
people(`builder-${o.id}`, slot.x + slot.r * 0.95, slot.y + slot.r * 0.35, -1, o.action === 'demolish' ? 'pick' : 'hammer', o.id)
}
if (sites.has(slot.key) || o.action === 'demolish') continue
sites.add(slot.key)
const pile: V2 = [slot.x + slot.r * 0.3, slot.y + slot.r * 1.05]
const pileFaces = [
...box(pile[0], pile[1], U * 0.75, U * 0.32, 0, U * 0.11, C.plank, C.wood),
...box(pile[0] + U * 0.05, pile[1] - U * 0.04, U * 0.7, U * 0.3, U * 0.11, U * 0.11, C.wood, C.plank),
...pyramid(ngon(pile[0] + U * 0.55, pile[1] + U * 0.15, U * 0.22, 5), 0, U * 0.22, C.stone),
]
objects.push({ key: `pile-${o.id}`, depth: pile[0] + pile[1], polys: toPolys(pileFaces) })
if (storeDoor && Math.hypot(storeDoor[0] - pile[0], storeDoor[1] - pile[1]) > U * 1.5) {
walker(`porter-${o.id}`, storeDoor, [pile[0] + U * 0.6, pile[1] - U * 0.3], { work: 1.4, rest: 3, indoors: true, tool: null, carry: C.plank, shirt: o.id + 2, begin: -o.id * 1.7 })
}
} }
// Units in training drill in front of their building, an instructor facing them.
for (const m of village.military) {
if (!m.queue.length) continue
const b = village.buildings.find((x) => x.id === m.building_id)
if (!b) continue
const slot = slotOf(`b${b.id}`)
for (let k = 0; k < 3; k++) {
const x = slot.x + slot.r * 1.15
const y = slot.y - slot.r * 0.35 + k * U * 0.55
objects.push({ key: `drill-${b.id}-${k}`, depth: x + y, polys: [], life: { at: project([x, y, 1.2]), facing: 1, tool: 'spear', shirt: 1, drill: true } })
}
people(`instructor-${b.id}`, slot.x + slot.r * 1.15 + U * 1.1, slot.y + slot.r * 0.2, -1, null, 4)
}
// Villagers step out of their buildings now and then, stand a moment, and go back in.
const homes = village.buildings.filter((b) => doorOf.has(b.id) && !ZONE_OF[b.type]).slice(0, 6)
homes.forEach((b, k) => {
const door = doorOf.get(b.id)!
const a = FRONT + deg(-40 + hash(b.id, 7) * 60)
const out: V2 = [door[0] + Math.cos(a) * U * (1.3 + hash(b.id, 8)), door[1] + Math.sin(a) * U * (1.3 + hash(b.id, 8))]
const soldier = village.military.some((m) => m.building_id === b.id)
walker(`visitor-${b.id}`, door, out, {
work: 2 + hash(b.id, 9) * 3,
rest: 6 + hash(b.id, 10) * 10,
indoors: true,
tool: soldier ? 'spear' : null,
carry: b.type === 'storage' ? C.plank : null,
shirt: b.id,
begin: -k * 4.3,
})
})
// Birds cross the upper part of the view now and then. // Birds cross the upper part of the view now and then.
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)