feat: levels start at 1: no tent stage, removal is target level 0
Level 1 starts at the timber model; tiers are 1-4, 5-14 and 15+. The mock shifts its stored levels once and follows the same rules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d2dc037849
commit
356a89a3b3
|
|
@ -8,7 +8,7 @@ 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.
|
||||||
- **Light Tailwind UI** (Tailwind 4, theme and component classes like `.panel`, `.btn` in `app/assets/css/main.css`) with simple hand-written inline SVG graphics (`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.
|
- **Light Tailwind UI** (Tailwind 4, theme and component classes like `.panel`, `.btn` in `app/assets/css/main.css`) with simple hand-written inline SVG graphics (`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.
|
||||||
- **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. Each type has a model per level tier (0, 1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that open their details card; 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 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 open their details card; 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.
|
||||||
- **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. 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. Keep components small and typed, with state in composables (`useVillage`, `useWorld`).
|
||||||
- **The village page is laid out like Die Stämme**: a compact strip with the stock and the screens (Overview, Headquarters, Recruit, Workforce), each a child route of `pages/village/[id].vue` sharing one `useVillage()` through `useVillageContext()`. The overview stays clean: the village and a narrow column of boxes (production, units, population, construction); tables live on the building screens.
|
- **The village page is laid out like Die Stämme**: a compact strip with the stock and the screens (Overview, Headquarters, Recruit, Workforce), each a child route of `pages/village/[id].vue` sharing one `useVillage()` through `useVillageContext()`. The overview stays clean: the village and a narrow column of boxes (production, units, population, construction); tables live on the building screens.
|
||||||
- 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`.
|
- 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`.
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ const demolishable = computed(() =>
|
||||||
@click="emit('demolish', b.id)"
|
@click="emit('demolish', b.id)"
|
||||||
>
|
>
|
||||||
{{
|
{{
|
||||||
b.demolish.target_level < 0
|
b.demolish.target_level < 1
|
||||||
? $t('village.build.remove')
|
? $t('village.build.remove')
|
||||||
: $t('village.build.level_button', { level: b.demolish.target_level })
|
: $t('village.build.level_button', { level: b.demolish.target_level })
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ function describe(o: BuildOrder) {
|
||||||
const type = t(`buildings.${o.type}`)
|
const type = t(`buildings.${o.type}`)
|
||||||
if (o.action === 'build') return t('village.queue.build', { type })
|
if (o.action === 'build') return t('village.queue.build', { type })
|
||||||
if (o.action === 'upgrade') return t('village.queue.upgrade', { type, level: o.target_level })
|
if (o.action === 'upgrade') return t('village.queue.upgrade', { type, level: o.target_level })
|
||||||
if (o.target_level < 0) return t('village.queue.remove', { type })
|
if (o.target_level < 1) return t('village.queue.remove', { type })
|
||||||
return t('village.queue.demolish', { type, level: o.target_level })
|
return t('village.queue.demolish', { type, level: o.target_level })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ const spaceShare = computed(() => props.village.space.used / props.village.space
|
||||||
function order(o: BuildOrder) {
|
function order(o: BuildOrder) {
|
||||||
const type = t(`buildings.${o.type}`)
|
const type = t(`buildings.${o.type}`)
|
||||||
if (o.action === 'build') return type
|
if (o.action === 'build') return type
|
||||||
return `${type} ${o.target_level < 0 ? '×' : `→ ${o.target_level}`}`
|
return `${type} ${o.target_level < 1 ? '×' : `→ ${o.target_level}`}`
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Low-poly building models for the diorama, one per type and level tier. Each fits in
|
// Low-poly building models for the diorama, one per type and level tier. Each fits in
|
||||||
// the square [-s, s] around its own origin and returns its faces and roof height.
|
// the square [-s, s] around its own origin and returns its faces and roof height.
|
||||||
// Original shapes in the genre's style: tents and lean-tos at level 0, timber next,
|
// Original shapes in the genre's style, solid from level 1: timber first, then bigger,
|
||||||
// stone and bigger at high levels.
|
// stone at high levels.
|
||||||
|
|
||||||
import type { BuildingType } from '~/types/game'
|
import type { BuildingType } from '~/types/game'
|
||||||
import { box, type Face, hash, house, log, ngon, orient, plane, prism, pyramid, rect, shift, type V2, type V3 } from './iso'
|
import { box, type Face, hash, house, log, ngon, orient, plane, prism, pyramid, rect, shift, type V2, type V3 } from './iso'
|
||||||
|
|
@ -50,8 +50,8 @@ export interface Model {
|
||||||
height: number
|
height: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 0 at level 0, 1 for 1–4, 2 for 5–14, 3 from 15 on. */
|
/** 1 for levels 1–4, 2 for 5–14, 3 from 15 on. */
|
||||||
export const tier = (level: number) => (level <= 0 ? 0 : level < 5 ? 1 : level < 15 ? 2 : 3)
|
export const tier = (level: number) => (level < 5 ? 1 : level < 15 ? 2 : 3)
|
||||||
|
|
||||||
// Small props
|
// Small props
|
||||||
|
|
||||||
|
|
@ -201,17 +201,6 @@ function headframe(x: number, y: number, s: number, h: number): Face[] {
|
||||||
|
|
||||||
const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
headquarters(s, t) {
|
headquarters(s, t) {
|
||||||
if (t === 0) {
|
|
||||||
return {
|
|
||||||
faces: [
|
|
||||||
...pyramid(ngon(0, 0, s * 0.62, 6, 0.3), 0, s * 1.0, C.canvas),
|
|
||||||
...pyramid(ngon(s * 0.05, s * 0.05, s * 0.2, 6, 0.3), s * 0.85, s * 0.25, C.canvasDark),
|
|
||||||
...fire(s * 0.62, s * 0.58, s),
|
|
||||||
...banner(-s * 0.6, s * 0.55, s * 1.25, s * 0.6),
|
|
||||||
],
|
|
||||||
height: s * 1.25,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (t === 1) {
|
if (t === 1) {
|
||||||
return {
|
return {
|
||||||
faces: [
|
faces: [
|
||||||
|
|
@ -249,24 +238,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
},
|
},
|
||||||
|
|
||||||
storage(s, t) {
|
storage(s, t) {
|
||||||
if (t === 0) {
|
|
||||||
const back = s * 0.85
|
|
||||||
const front = s * 0.5
|
|
||||||
return {
|
|
||||||
faces: [
|
|
||||||
...post(-s * 0.6, -s * 0.5, back, s * 0.05),
|
|
||||||
...post(s * 0.6, -s * 0.5, back, s * 0.05),
|
|
||||||
...post(-s * 0.6, s * 0.5, front, s * 0.05),
|
|
||||||
...post(s * 0.6, s * 0.5, front, s * 0.05),
|
|
||||||
plane([[-s * 0.75, -s * 0.6, back], [s * 0.75, -s * 0.6, back], [s * 0.75, s * 0.62, front], [-s * 0.75, s * 0.62, front]], C.plank),
|
|
||||||
...crate(-s * 0.25, 0, 0, s * 0.3),
|
|
||||||
...crate(s * 0.15, s * 0.05, 0, s * 0.3),
|
|
||||||
...crate(-s * 0.05, -s * 0.05, s * 0.3, s * 0.26),
|
|
||||||
...pyramid(ngon(s * 0.75, s * 0.75, s * 0.12, 5), 0, s * 0.22, C.canvasDark),
|
|
||||||
],
|
|
||||||
height: back,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (t === 1) return { faces: [...house(0, 0, s * 1.15, s * 1.0, s * 0.55, s * 0.4, C.wood, C.woodDark, 'y'), ...crate(s * 0.75, s * 0.7, 0, s * 0.28)], height: s * 0.95 }
|
if (t === 1) return { faces: [...house(0, 0, s * 1.15, s * 1.0, s * 0.55, s * 0.4, C.wood, C.woodDark, 'y'), ...crate(s * 0.75, s * 0.7, 0, s * 0.28)], height: s * 0.95 }
|
||||||
if (t === 2) {
|
if (t === 2) {
|
||||||
return {
|
return {
|
||||||
|
|
@ -290,17 +261,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
},
|
},
|
||||||
|
|
||||||
farm(s, t) {
|
farm(s, t) {
|
||||||
if (t === 0) {
|
|
||||||
return {
|
|
||||||
faces: [
|
|
||||||
...field(0, 0, s * 1.5, s * 1.2, C.wheat, 5),
|
|
||||||
...person(-s * 0.2, s * 0.15, s),
|
|
||||||
...person(s * 0.35, -s * 0.2, s, C.soil),
|
|
||||||
...pyramid(ngon(s * 0.85, s * 0.75, s * 0.13, 6), 0, s * 0.16, C.hay),
|
|
||||||
],
|
|
||||||
height: s * 0.4,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (t === 1) {
|
if (t === 1) {
|
||||||
return {
|
return {
|
||||||
faces: [
|
faces: [
|
||||||
|
|
@ -335,12 +295,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
},
|
},
|
||||||
|
|
||||||
timber_camp(s, t) {
|
timber_camp(s, t) {
|
||||||
if (t === 0) {
|
|
||||||
return {
|
|
||||||
faces: [...logPile(0, s * 0.2, s, 2), ...prism(ngon(-s * 0.55, -s * 0.4, s * 0.12, 6), 0, s * 0.14, C.wood, C.plank), ...tree(s * 0.55, -s * 0.55, s * 1.1, 1)],
|
|
||||||
height: s * 1.1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (t === 1) {
|
if (t === 1) {
|
||||||
return {
|
return {
|
||||||
faces: [
|
faces: [
|
||||||
|
|
@ -383,12 +337,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
plane(ngon(x, y, r, 7, 0.2).map(([px, py]) => [px, py, 0.4]), C.clayDark),
|
plane(ngon(x, y, r, 7, 0.2).map(([px, py]) => [px, py, 0.4]), C.clayDark),
|
||||||
plane(ngon(x, y, r * 0.65, 7, 0.5).map(([px, py]) => [px, py, 0.6]), C.clayWet),
|
plane(ngon(x, y, r * 0.65, 7, 0.5).map(([px, py]) => [px, py, 0.6]), C.clayWet),
|
||||||
]
|
]
|
||||||
if (t === 0) {
|
|
||||||
return {
|
|
||||||
faces: [...pit(-s * 0.1, s * 0.1, s * 0.6), ...pyramid(ngon(s * 0.6, -s * 0.55, s * 0.3, 6), 0, s * 0.3, C.clay), ...person(s * 0.15, -s * 0.3, s)],
|
|
||||||
height: s * 0.4,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (t === 1) {
|
if (t === 1) {
|
||||||
return {
|
return {
|
||||||
faces: [...pit(-s * 0.2, s * 0.2, s * 0.6), ...bricks(s * 0.6, -s * 0.45, s, 4), ...bricks(s * 0.25, -s * 0.7, s, 3), ...person(s * 0.4, s * 0.3, s)],
|
faces: [...pit(-s * 0.2, s * 0.2, s * 0.6), ...bricks(s * 0.6, -s * 0.45, s, 4), ...bricks(s * 0.25, -s * 0.7, s, 3), ...person(s * 0.4, s * 0.3, s)],
|
||||||
|
|
@ -416,7 +364,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
const outcrop = (k: number) => pyramid(ngon(-s * 0.2, -s * 0.25, s * 0.75 * k, 6, 0.4), 0, s * 0.95 * k, C.rock, [-s * 0.35, -s * 0.45])
|
const outcrop = (k: number) => pyramid(ngon(-s * 0.2, -s * 0.25, s * 0.75 * k, 6, 0.4), 0, s * 0.95 * k, C.rock, [-s * 0.35, -s * 0.45])
|
||||||
const mouth = plane([[s * 0.32, -s * 0.35, 0], [s * 0.32, -s * 0.05, 0], [s * 0.2, -s * 0.05, s * 0.3], [s * 0.2, -s * 0.35, s * 0.3]], C.dark)
|
const mouth = plane([[s * 0.32, -s * 0.35, 0], [s * 0.32, -s * 0.05, 0], [s * 0.2, -s * 0.05, s * 0.3], [s * 0.2, -s * 0.35, s * 0.3]], C.dark)
|
||||||
const ore = (x: number, y: number) => pyramid(ngon(x, y, s * 0.18, 5), 0, s * 0.18, C.ore)
|
const ore = (x: number, y: number) => pyramid(ngon(x, y, s * 0.18, 5), 0, s * 0.18, C.ore)
|
||||||
if (t === 0) return { faces: [...outcrop(1), mouth, ...ore(s * 0.55, s * 0.5)], height: s * 0.95 }
|
|
||||||
if (t === 1) {
|
if (t === 1) {
|
||||||
return {
|
return {
|
||||||
faces: [
|
faces: [
|
||||||
|
|
@ -446,7 +393,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
},
|
},
|
||||||
|
|
||||||
hiding_place(s, t) {
|
hiding_place(s, t) {
|
||||||
if (t === 0) return { faces: pyramid(ngon(0, 0, s * 0.62, 7), 0, s * 0.85, C.hay), height: s * 0.85 }
|
|
||||||
const door = plane([[s * 0.45, -s * 0.2, 0], [s * 0.45, s * 0.2, 0], [s * 0.45, s * 0.2, s * 0.35], [s * 0.45, -s * 0.2, s * 0.35]], C.dark)
|
const door = plane([[s * 0.45, -s * 0.2, 0], [s * 0.45, s * 0.2, 0], [s * 0.45, s * 0.2, s * 0.35], [s * 0.45, -s * 0.2, s * 0.35]], C.dark)
|
||||||
if (t === 1) return { faces: [...pyramid(rect(0, 0, s * 1.2, s * 1.2), 0, s * 0.55, C.grass), door], height: s * 0.55 }
|
if (t === 1) return { faces: [...pyramid(rect(0, 0, s * 1.2, s * 1.2), 0, s * 0.55, C.grass), door], height: s * 0.55 }
|
||||||
return {
|
return {
|
||||||
|
|
@ -457,7 +403,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
|
|
||||||
rally_point(s, t) {
|
rally_point(s, t) {
|
||||||
const stones: Face[] = ngon(0, 0, s * 0.6, 8).flatMap(([x, y]) => box(x, y, s * 0.14, s * 0.14, 0, s * 0.1, C.stone))
|
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))
|
||||||
if (t === 0) return { faces: [...stones, ...banner(0, 0, s * 1.6, s * 0.8)], height: s * 1.6 }
|
|
||||||
return {
|
return {
|
||||||
faces: [
|
faces: [
|
||||||
...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),
|
||||||
|
|
@ -470,19 +415,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
|
|
||||||
// Military: tents and a weapon rack at first, then a long hall that grows into stone.
|
// Military: tents and a weapon rack at first, then a long hall that grows into stone.
|
||||||
barracks(s, t) {
|
barracks(s, t) {
|
||||||
if (t === 0) {
|
|
||||||
return {
|
|
||||||
faces: [
|
|
||||||
...pyramid(ngon(-s * 0.4, -s * 0.25, s * 0.42, 6, 0.3), 0, s * 0.75, C.canvas),
|
|
||||||
...pyramid(ngon(s * 0.35, s * 0.3, s * 0.38, 6, 0.3), 0, s * 0.7, C.canvasDark),
|
|
||||||
...post(s * 0.55, -s * 0.6, s * 0.55, s * 0.04),
|
|
||||||
...post(s * 0.85, -s * 0.35, s * 0.55, s * 0.04),
|
|
||||||
...box(s * 0.7, -s * 0.48, s * 0.42, s * 0.06, s * 0.45, s * 0.05, C.woodDark),
|
|
||||||
...banner(-s * 0.8, s * 0.6, s * 1.15, s * 0.5),
|
|
||||||
],
|
|
||||||
height: s * 1.15,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (t === 1) {
|
if (t === 1) {
|
||||||
return {
|
return {
|
||||||
faces: [
|
faces: [
|
||||||
|
|
@ -520,18 +452,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
[-0.9, 0.55], [-0.45, 0.85], [0, 0.85], [0.45, 0.85], [0.9, 0.55],
|
[-0.9, 0.55], [-0.45, 0.85], [0, 0.85], [0.45, 0.85], [0.9, 0.55],
|
||||||
].flatMap(([x, y]) => post(s * x!, s * y!, s * 0.3, s * 0.035))
|
].flatMap(([x, y]) => post(s * x!, s * y!, s * 0.3, s * 0.035))
|
||||||
const hay = box(-s * 0.75, -s * 0.55, s * 0.32, s * 0.28, 0, s * 0.22, C.hay)
|
const hay = box(-s * 0.75, -s * 0.55, s * 0.32, s * 0.28, 0, s * 0.22, C.hay)
|
||||||
if (t === 0) {
|
|
||||||
return {
|
|
||||||
faces: [
|
|
||||||
...fence,
|
|
||||||
...hay,
|
|
||||||
...post(-s * 0.3, -s * 0.4, s * 0.55, s * 0.04),
|
|
||||||
...post(s * 0.5, -s * 0.4, s * 0.55, s * 0.04),
|
|
||||||
plane([[-s * 0.45, -s * 0.75, s * 0.6], [s * 0.65, -s * 0.75, s * 0.6], [s * 0.65, -s * 0.05, s * 0.45], [-s * 0.45, -s * 0.05, s * 0.45]], C.thatch),
|
|
||||||
],
|
|
||||||
height: s * 0.6,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const [walls, roof] = t === 1 ? [C.wood, C.thatch] : t === 2 ? [C.plank, C.roofRed] : [C.stone, C.slate]
|
const [walls, roof] = t === 1 ? [C.wood, C.thatch] : t === 2 ? [C.plank, C.roofRed] : [C.stone, C.slate]
|
||||||
return {
|
return {
|
||||||
faces: [...house(0, -s * 0.2, s * 1.9, s * 0.85, s * 0.45, s * 0.4, walls, roof), ...fence, ...hay],
|
faces: [...house(0, -s * 0.2, s * 1.9, s * 0.85, s * 0.45, s * 0.4, walls, roof), ...fence, ...hay],
|
||||||
|
|
@ -544,20 +464,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
...log(s * 0.55, s * 0.7, 0, s * 0.7, s * 0.08, C.wood, C.plank),
|
...log(s * 0.55, s * 0.7, 0, s * 0.7, s * 0.08, C.wood, C.plank),
|
||||||
...log(s * 0.55, s * 0.55, 0, s * 0.7, s * 0.08, C.woodDark, C.plank),
|
...log(s * 0.55, s * 0.55, 0, s * 0.7, s * 0.08, C.woodDark, C.plank),
|
||||||
]
|
]
|
||||||
if (t === 0) {
|
|
||||||
return {
|
|
||||||
faces: [
|
|
||||||
...post(-s * 0.6, -s * 0.5, s * 0.7, s * 0.04),
|
|
||||||
...post(s * 0.6, -s * 0.5, s * 0.7, s * 0.04),
|
|
||||||
...post(-s * 0.6, s * 0.3, s * 0.55, s * 0.04),
|
|
||||||
...post(s * 0.6, s * 0.3, s * 0.55, s * 0.04),
|
|
||||||
plane([[-s * 0.75, -s * 0.65, s * 0.72], [s * 0.75, -s * 0.65, s * 0.72], [s * 0.75, s * 0.45, s * 0.56], [-s * 0.75, s * 0.45, s * 0.56]], C.plank),
|
|
||||||
...crate(-s * 0.15, -s * 0.1, 0, s * 0.3),
|
|
||||||
...logs,
|
|
||||||
],
|
|
||||||
height: s * 0.75,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const [walls, roof] = t === 1 ? [C.wood, C.thatch] : t === 2 ? [C.plank, C.roofRed] : [C.stone, C.slate]
|
const [walls, roof] = t === 1 ? [C.wood, C.thatch] : t === 2 ? [C.plank, C.roofRed] : [C.stone, C.slate]
|
||||||
return {
|
return {
|
||||||
faces: [
|
faces: [
|
||||||
|
|
@ -575,12 +481,6 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
...prism(ngon(x, y, s * 0.24, 6), 0, h, C.stone),
|
...prism(ngon(x, y, s * 0.24, 6), 0, h, C.stone),
|
||||||
...pyramid(ngon(x, y, s * 0.3, 6), h, s * 0.4, C.slate),
|
...pyramid(ngon(x, y, s * 0.3, 6), h, s * 0.4, C.slate),
|
||||||
]
|
]
|
||||||
if (t === 0) {
|
|
||||||
return {
|
|
||||||
faces: [...house(0, 0, s * 1.4, s * 1.0, s * 0.65, s * 0.5, C.stone, C.slate), ...tower(s * 0.7, -s * 0.5, s * 1.2)],
|
|
||||||
height: s * 1.6,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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),
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ export interface CatalogEntry {
|
||||||
/** Building space an instance takes (0 for the wall). */
|
/** Building space an instance takes (0 for the wall). */
|
||||||
space: number
|
space: number
|
||||||
max_per_village: number | null
|
max_per_village: number | null
|
||||||
/** Level 0 values. Level n costs, takes, needs and produces (n + 1) times as much. */
|
/** Level 1 values. Level n costs, takes, needs and produces n times as much. */
|
||||||
cost: Cost
|
cost: Cost
|
||||||
seconds: number
|
seconds: number
|
||||||
workers: number
|
workers: number
|
||||||
|
|
@ -22,7 +22,7 @@ export const BASE_TRICKLE = 5
|
||||||
export const VILLAGER_UPKEEP = 1
|
export const VILLAGER_UPKEEP = 1
|
||||||
export const DEMOLISH_REFUND = 0.5
|
export const DEMOLISH_REFUND = 0.5
|
||||||
export const DEFAULT_PRIORITY = 5
|
export const DEFAULT_PRIORITY = 5
|
||||||
/** Building space at headquarters level 0, and what each level adds. */
|
/** Building space at headquarters level 1, and what each level above adds. */
|
||||||
export const MAX_SPACE = 40
|
export const MAX_SPACE = 40
|
||||||
export const SPACE_PER_HQ_LEVEL = 20
|
export const SPACE_PER_HQ_LEVEL = 20
|
||||||
export const START_RESOURCES: Resources = { wood: 500, clay: 500, iron: 500, food: 100 }
|
export const START_RESOURCES: Resources = { wood: 500, clay: 500, iron: 500, food: 100 }
|
||||||
|
|
@ -45,7 +45,7 @@ export const CATALOG: Record<BuildingType, CatalogEntry> = {
|
||||||
|
|
||||||
export const BUILDING_TYPES = Object.keys(CATALOG) as BuildingType[]
|
export const BUILDING_TYPES = Object.keys(CATALOG) as BuildingType[]
|
||||||
|
|
||||||
export const atLevel = (base: number, level: number) => base * (level + 1)
|
export const atLevel = (base: number, level: number) => base * Math.max(level, 1)
|
||||||
|
|
||||||
export interface UnitEntry {
|
export interface UnitEntry {
|
||||||
building: BuildingType
|
building: BuildingType
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ interface MockState {
|
||||||
villages: MockVillage[]
|
villages: MockVillage[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const STORAGE_KEY = 'vp.mock.v2'
|
const STORAGE_KEY = 'vp.mock.v3'
|
||||||
const LATENCY_MS = 60
|
const LATENCY_MS = 60
|
||||||
const WORLDS = [
|
const WORLDS = [
|
||||||
{ id: 1, name: 'World 1', slug: 'w1', speed: 1 },
|
{ id: 1, name: 'World 1', slug: 'w1', speed: 1 },
|
||||||
|
|
@ -130,6 +130,16 @@ function load(): MockState {
|
||||||
try {
|
try {
|
||||||
const raw = localStorage.getItem(STORAGE_KEY)
|
const raw = localStorage.getItem(STORAGE_KEY)
|
||||||
if (raw) return JSON.parse(raw)
|
if (raw) return JSON.parse(raw)
|
||||||
|
// v2 counted levels from 0: shift buildings and queued orders up by one.
|
||||||
|
const old = localStorage.getItem('vp.mock.v2')
|
||||||
|
if (old) {
|
||||||
|
const state: MockState = JSON.parse(old)
|
||||||
|
for (const v of state.villages) {
|
||||||
|
v.buildings.forEach((b) => b.level++)
|
||||||
|
v.orders.forEach((o) => o.target_level++)
|
||||||
|
}
|
||||||
|
return state
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// fall through to a fresh state
|
// fall through to a fresh state
|
||||||
}
|
}
|
||||||
|
|
@ -254,10 +264,10 @@ function spaceUsed(v: MockVillage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const spaceMax = (v: MockVillage) =>
|
const spaceMax = (v: MockVillage) =>
|
||||||
Math.min(v.space_max, MAX_SPACE) + SPACE_PER_HQ_LEVEL * (v.buildings.find((b) => b.type === 'headquarters')?.level ?? 0)
|
Math.min(v.space_max, MAX_SPACE) + SPACE_PER_HQ_LEVEL * Math.max(0, (v.buildings.find((b) => b.type === 'headquarters')?.level ?? 1) - 1)
|
||||||
const spaceFits = (v: MockVillage, type: BuildingType) => spaceUsed(v) + CATALOG[type].space <= spaceMax(v)
|
const spaceFits = (v: MockVillage, type: BuildingType) => spaceUsed(v) + CATALOG[type].space <= spaceMax(v)
|
||||||
|
|
||||||
/** Level after everything already queued for this building; -1 if it is being removed. */
|
/** Level after everything already queued for this building; 0 if it is being removed. */
|
||||||
function queuedLevel(v: MockVillage, b: MockBuilding) {
|
function queuedLevel(v: MockVillage, b: MockBuilding) {
|
||||||
const last = v.orders.filter((o) => o.building_id === b.id).at(-1)
|
const last = v.orders.filter((o) => o.building_id === b.id).at(-1)
|
||||||
return last ? last.target_level : b.level
|
return last ? last.target_level : b.level
|
||||||
|
|
@ -273,7 +283,7 @@ const isCore = (v: MockVillage, b: MockBuilding) =>
|
||||||
|
|
||||||
function upgradeOffer(v: MockVillage, b: MockBuilding): Offer | null {
|
function upgradeOffer(v: MockVillage, b: MockBuilding): Offer | null {
|
||||||
const current = queuedLevel(v, b)
|
const current = queuedLevel(v, b)
|
||||||
if (current < 0 || current >= MAX_LEVEL) return null
|
if (current < 1 || current >= MAX_LEVEL) return null
|
||||||
const target = current + 1
|
const target = current + 1
|
||||||
const cost = levelCost(b.type, target)
|
const cost = levelCost(b.type, target)
|
||||||
return { target_level: target, cost, seconds: levelSeconds(b.type, target), blocked: null }
|
return { target_level: target, cost, seconds: levelSeconds(b.type, target), blocked: null }
|
||||||
|
|
@ -281,7 +291,7 @@ function upgradeOffer(v: MockVillage, b: MockBuilding): Offer | null {
|
||||||
|
|
||||||
function demolishOffer(v: MockVillage, b: MockBuilding) {
|
function demolishOffer(v: MockVillage, b: MockBuilding) {
|
||||||
const current = queuedLevel(v, b)
|
const current = queuedLevel(v, b)
|
||||||
if (current < 0 || (current === 0 && isCore(v, b))) return null
|
if (current < 1 || (current === 1 && isCore(v, b))) return null
|
||||||
return {
|
return {
|
||||||
target_level: current - 1,
|
target_level: current - 1,
|
||||||
refund: mapCost(levelCost(b.type, current), (n) => Math.floor(n * DEMOLISH_REFUND)),
|
refund: mapCost(levelCost(b.type, current), (n) => Math.floor(n * DEMOLISH_REFUND)),
|
||||||
|
|
@ -292,14 +302,14 @@ function demolishOffer(v: MockVillage, b: MockBuilding) {
|
||||||
function buildOptions(v: MockVillage): BuildOption[] {
|
function buildOptions(v: MockVillage): BuildOption[] {
|
||||||
return BUILDING_TYPES.map((type) => {
|
return BUILDING_TYPES.map((type) => {
|
||||||
const entry = CATALOG[type]
|
const entry = CATALOG[type]
|
||||||
const cost = levelCost(type, 0)
|
const cost = levelCost(type, 1)
|
||||||
const blocked =
|
const blocked =
|
||||||
entry.max_per_village !== null && instances(v, type) >= entry.max_per_village
|
entry.max_per_village !== null && instances(v, type) >= entry.max_per_village
|
||||||
? 'max_per_village'
|
? 'max_per_village'
|
||||||
: !spaceFits(v, type)
|
: !spaceFits(v, type)
|
||||||
? 'no_space'
|
? 'no_space'
|
||||||
: null
|
: null
|
||||||
return { type, space: entry.space, target_level: 0, cost, seconds: levelSeconds(type, 0), blocked, requires: [] }
|
return { type, space: entry.space, target_level: 1, cost, seconds: levelSeconds(type, 1), blocked, requires: [] }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -326,7 +336,7 @@ function startWaiting(v: MockVillage, at: number) {
|
||||||
|
|
||||||
function finish(state: MockState, v: MockVillage, o: MockOrder) {
|
function finish(state: MockState, v: MockVillage, o: MockOrder) {
|
||||||
if (o.action === 'build') {
|
if (o.action === 'build') {
|
||||||
v.buildings.push({ id: nextId(state), type: o.type, level: 0, priority: DEFAULT_PRIORITY })
|
v.buildings.push({ id: nextId(state), type: o.type, level: 1, priority: DEFAULT_PRIORITY })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const b = v.buildings.find((b) => b.id === o.building_id)
|
const b = v.buildings.find((b) => b.id === o.building_id)
|
||||||
|
|
@ -335,7 +345,7 @@ function finish(state: MockState, v: MockVillage, o: MockOrder) {
|
||||||
refund(v, mapCost(levelCost(b.type, b.level), (n) => Math.floor(n * DEMOLISH_REFUND)))
|
refund(v, mapCost(levelCost(b.type, b.level), (n) => Math.floor(n * DEMOLISH_REFUND)))
|
||||||
}
|
}
|
||||||
b.level = o.target_level
|
b.level = o.target_level
|
||||||
if (b.level < 0) {
|
if (b.level < 1) {
|
||||||
v.buildings = v.buildings.filter((x) => x !== b)
|
v.buildings = v.buildings.filter((x) => x !== b)
|
||||||
// Units still in training there go back to work, refunded.
|
// Units still in training there go back to work, refunded.
|
||||||
for (const r of (v.recruits ?? []).filter((r) => r.building_id === b.id)) {
|
for (const r of (v.recruits ?? []).filter((r) => r.building_id === b.id)) {
|
||||||
|
|
@ -367,7 +377,7 @@ function missingRequirements(v: MockVillage, unit: UnitType) {
|
||||||
.map(([type, level]) => ({ type: type as BuildingType, level: level ?? 0 }))
|
.map(([type, level]) => ({ type: type as BuildingType, level: level ?? 0 }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const secondsPerUnit = (b: MockBuilding, unit: UnitType) => Math.max(1, Math.ceil(UNITS[unit].seconds / (1 + 0.05 * b.level)))
|
const secondsPerUnit = (b: MockBuilding, unit: UnitType) => Math.max(1, Math.ceil(UNITS[unit].seconds / (1 + 0.05 * Math.max(0, b.level - 1))))
|
||||||
|
|
||||||
function military(v: MockVillage, at: number): MilitaryBuilding[] {
|
function military(v: MockVillage, at: number): MilitaryBuilding[] {
|
||||||
const pop = villagers(v) - militia(v)
|
const pop = villagers(v) - militia(v)
|
||||||
|
|
@ -511,8 +521,8 @@ function view(v: MockVillage, now: number): VillageState {
|
||||||
|
|
||||||
const continentOf = (x: number, y: number) => `K${Math.floor(y / 100)}${Math.floor(x / 100)}`
|
const continentOf = (x: number, y: number) => `K${Math.floor(y / 100)}${Math.floor(x / 100)}`
|
||||||
|
|
||||||
/** Placeholder points: 5 per building level, counting level 0. */
|
/** Placeholder points: 5 per building level. */
|
||||||
const points = (v: MockVillage) => v.buildings.reduce((sum, b) => sum + 5 * (b.level + 1), 0)
|
const points = (v: MockVillage) => v.buildings.reduce((sum, b) => sum + 5 * b.level, 0)
|
||||||
|
|
||||||
/** Mock map: the stored player villages plus barbarians made up from a hash of the field. */
|
/** Mock map: the stored player villages plus barbarians made up from a hash of the field. */
|
||||||
function mapView(state: MockState, user: AuthUser, data: any): MapView {
|
function mapView(state: MockState, user: AuthUser, data: any): MapView {
|
||||||
|
|
@ -583,7 +593,7 @@ function createVillage(state: MockState, user: AuthUser, worldId: number, now: n
|
||||||
orders: [],
|
orders: [],
|
||||||
}
|
}
|
||||||
for (const type of ['headquarters', 'storage', 'farm'] as const) {
|
for (const type of ['headquarters', 'storage', 'farm'] as const) {
|
||||||
v.buildings.push({ id: nextId(state), type, level: 0, priority: DEFAULT_PRIORITY })
|
v.buildings.push({ id: nextId(state), type, level: 1, priority: DEFAULT_PRIORITY })
|
||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
@ -630,9 +640,9 @@ const handlers: Record<string, Handler> = {
|
||||||
const entry = CATALOG[type] ?? fail('not_found')
|
const entry = CATALOG[type] ?? fail('not_found')
|
||||||
if (entry.max_per_village !== null && instances(v, type) >= entry.max_per_village) fail('max_per_village')
|
if (entry.max_per_village !== null && instances(v, type) >= entry.max_per_village) fail('max_per_village')
|
||||||
if (!spaceFits(v, type)) fail('no_space')
|
if (!spaceFits(v, type)) fail('no_space')
|
||||||
const cost = levelCost(type, 0)
|
const cost = levelCost(type, 1)
|
||||||
pay(v, cost)
|
pay(v, cost)
|
||||||
enqueue(state, v, { building_id: null, type, action: 'build', target_level: 0, cost, seconds: levelSeconds(type, 0) }, now)
|
enqueue(state, v, { building_id: null, type, action: 'build', target_level: 1, cost, seconds: levelSeconds(type, 1) }, now)
|
||||||
return view(v, now)
|
return view(v, now)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ export interface Building {
|
||||||
production: { resource: Resource; per_hour: number } | null
|
production: { resource: Resource; per_hour: number } | null
|
||||||
/** Next level after everything already queued; null at max level. */
|
/** Next level after everything already queued; null at max level. */
|
||||||
upgrade: Offer | null
|
upgrade: Offer | null
|
||||||
/** null when the building cannot go lower (core buildings at level 0). */
|
/** null when the building cannot go lower (core buildings at level 1); target level 0 removes it. */
|
||||||
demolish: { target_level: number; refund: Cost; seconds: number } | null
|
demolish: { target_level: number; refund: Cost; seconds: number } | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,7 +193,7 @@ export interface BuildOrder {
|
||||||
building_id: number | null
|
building_id: number | null
|
||||||
type: BuildingType
|
type: BuildingType
|
||||||
action: 'build' | 'upgrade' | 'demolish'
|
action: 'build' | 'upgrade' | 'demolish'
|
||||||
/** -1 means the instance is removed. */
|
/** 0 means the instance is removed; levels start at 1. */
|
||||||
target_level: number
|
target_level: number
|
||||||
space: number
|
space: number
|
||||||
cost: Cost
|
cost: Cost
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ export default {
|
||||||
max_per_village: 'Only one of these per village.',
|
max_per_village: 'Only one of these per village.',
|
||||||
max_level: 'Already at max level.',
|
max_level: 'Already at max level.',
|
||||||
resources: 'Not enough resources.',
|
resources: 'Not enough resources.',
|
||||||
core_building: 'Core buildings cannot go below level 0.',
|
core_building: 'Core buildings cannot go below level 1.',
|
||||||
requires: 'Build its requirements first.',
|
requires: 'Build its requirements first.',
|
||||||
villagers: 'Not enough villagers to train that many.',
|
villagers: 'Not enough villagers to train that many.',
|
||||||
count: 'Pick at least one.',
|
count: 'Pick at least one.',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue