feat: village role box on the overview (resource or military village, space per kind, bonuses); mock space grows 5 per HQ level
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5935f395f7
commit
def5553b14
|
|
@ -114,7 +114,7 @@ const demolishable = computed(() =>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<span class="badge badge-plain">
|
<span class="badge badge-plain">
|
||||||
{{ $t('village.build.free_space', { free: space.max - space.used }) }}
|
{{ $t('village.build.free_space', { free: Math.max(0, space.max - space.used) }) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { BuildOrder, UnitType, VillageState } from '~/types/game'
|
import type { BuildOrder, UnitType, VillageRole, VillageState } from '~/types/game'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
village: VillageState
|
village: VillageState
|
||||||
|
|
@ -15,6 +15,10 @@ const idle = computed(() => props.village.population.villagers - props.village.p
|
||||||
const spaceShare = computed(() => props.village.space.used / props.village.space.max)
|
const spaceShare = computed(() => props.village.space.used / props.village.space.max)
|
||||||
const incoming = computed(() => props.village.movements.filter((m) => m.direction === 'in' && m.type === 'attack'))
|
const incoming = computed(() => props.village.movements.filter((m) => m.direction === 'in' && m.type === 'attack'))
|
||||||
const commands = computed(() => props.village.movements.filter((m) => m.direction !== 'in').length)
|
const commands = computed(() => props.village.movements.filter((m) => m.direction !== 'in').length)
|
||||||
|
const spec = computed(() => props.village.specialisation)
|
||||||
|
const roleSpace = computed(() => spec.value.roles.reduce((sum, r) => sum + (spec.value.space[r.role] ?? 0), 0))
|
||||||
|
const roleShare = (role: VillageRole) => (roleSpace.value ? Math.round((100 * (spec.value.space[role] ?? 0)) / roleSpace.value) : 0)
|
||||||
|
const bonuses = computed(() => Object.entries(spec.value.roles.find((r) => r.role === spec.value.role)?.bonuses ?? {}))
|
||||||
|
|
||||||
function order(o: BuildOrder) {
|
function order(o: BuildOrder) {
|
||||||
const type = t(`buildings.${o.type}`)
|
const type = t(`buildings.${o.type}`)
|
||||||
|
|
@ -89,6 +93,23 @@ function order(o: BuildOrder) {
|
||||||
</dl>
|
</dl>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section class="side-box">
|
||||||
|
<h2 class="panel-head panel-title">{{ $t('village.role.title') }}</h2>
|
||||||
|
<div class="side-body">
|
||||||
|
<p class="font-semibold">{{ spec.role ? $t(`village.role.${spec.role}`) : $t('village.role.none') }}</p>
|
||||||
|
<ul v-if="spec.role" class="text-moss-700">
|
||||||
|
<li v-for="[key, value] in bonuses" :key="key">{{ $t(`village.role.bonus.${key}`, { value: Math.round(value * 100) }) }}</li>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li v-for="r in spec.roles" :key="r.role" class="flex items-center gap-2">
|
||||||
|
<span class="flex-1">{{ $t(`village.role.kinds.${r.role}`) }}</span>
|
||||||
|
<span class="tabular-nums">{{ $t('village.role.space', { space: spec.space[r.role] ?? 0, share: roleShare(r.role) }) }}</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<p v-if="!spec.role" class="text-xs text-ink-500">{{ $t('village.role.hint', { min: spec.min_space, share: Math.round(spec.share * 100) }) }}</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section class="side-box">
|
<section class="side-box">
|
||||||
<h2 class="panel-head panel-title">{{ $t('village.side.construction') }}</h2>
|
<h2 class="panel-head panel-title">{{ $t('village.side.construction') }}</h2>
|
||||||
<div class="side-body">
|
<div class="side-body">
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export const DEMOLISH_REFUND = 0.5
|
||||||
export const DEFAULT_PRIORITY = 5
|
export const DEFAULT_PRIORITY = 5
|
||||||
/** Building space at headquarters level 1, and what each level above 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 = 5
|
||||||
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 }
|
||||||
|
|
||||||
export const CATALOG: Record<BuildingType, CatalogEntry> = {
|
export const CATALOG: Record<BuildingType, CatalogEntry> = {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
import { onUnmounted, ref } from 'vue'
|
import { onUnmounted, ref } from 'vue'
|
||||||
import type {
|
import type {
|
||||||
|
Specialisation,
|
||||||
AuthResult,
|
AuthResult,
|
||||||
QuestBookState,
|
QuestBookState,
|
||||||
QuestClaimed,
|
QuestClaimed,
|
||||||
|
|
@ -332,6 +333,23 @@ function refund(v: MockVillage, amount: Cost) {
|
||||||
v.resources.iron = Math.min(cap, v.resources.iron + amount.iron)
|
v.resources.iron = Math.min(cap, v.resources.iron + amount.iron)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Village roles as the backend defines them (world.village.specialisation); the mock grants no bonus. */
|
||||||
|
const ROLES: Specialisation['roles'] = [
|
||||||
|
{ role: 'resources', buildings: ['timber_camp', 'clay_pit', 'iron_mine'], bonuses: { production: 0.2 } },
|
||||||
|
{ role: 'military', buildings: ['barracks', 'stable', 'workshop', 'academy'], bonuses: { recruit_speed: 0.2, defense: 0.1 } },
|
||||||
|
]
|
||||||
|
|
||||||
|
function specialisation(v: MockVillage): Specialisation {
|
||||||
|
const space: Specialisation['space'] = { resources: 0, military: 0 }
|
||||||
|
for (const b of v.buildings) {
|
||||||
|
const r = ROLES.find((r) => r.buildings.includes(b.type))
|
||||||
|
if (r) space[r.role] += CATALOG[b.type].space
|
||||||
|
}
|
||||||
|
const total = space.resources + space.military
|
||||||
|
const role = ROLES.find((r) => total > 0 && space[r.role] >= 16 && space[r.role] / total >= 0.7)?.role ?? null
|
||||||
|
return { role, space, share: 0.7, min_space: 16, roles: ROLES }
|
||||||
|
}
|
||||||
|
|
||||||
/** Building space taken by buildings and by queued new buildings. */
|
/** Building space taken by buildings and by queued new buildings. */
|
||||||
function spaceUsed(v: MockVillage) {
|
function spaceUsed(v: MockVillage) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -544,6 +562,7 @@ function view(state: MockState, v: MockVillage, now: number): VillageState {
|
||||||
continent: continentOf(v.x, v.y),
|
continent: continentOf(v.x, v.y),
|
||||||
points: points(v),
|
points: points(v),
|
||||||
space: { used: spaceUsed(v), max: spaceMax(v) },
|
space: { used: spaceUsed(v), max: spaceMax(v) },
|
||||||
|
specialisation: specialisation(v),
|
||||||
resources: { ...v.resources },
|
resources: { ...v.resources },
|
||||||
resources_at: iso(v.resources_at),
|
resources_at: iso(v.resources_at),
|
||||||
rates: rates(v),
|
rates: rates(v),
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,22 @@ export interface WorldSummary {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** `village.show`, and the reply to every `village.*` mutation. */
|
/** `village.show`, and the reply to every `village.*` mutation. */
|
||||||
|
export type VillageRole = 'resources' | 'military'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What fills the space gives a village its role: one kind of building taking at least
|
||||||
|
* `share` of the space both kinds take, and at least `min_space`.
|
||||||
|
*/
|
||||||
|
export interface Specialisation {
|
||||||
|
role: VillageRole | null
|
||||||
|
/** Space the standing buildings of each role take. */
|
||||||
|
space: Record<VillageRole, number>
|
||||||
|
share: number
|
||||||
|
min_space: number
|
||||||
|
/** Bonuses as shares: production (camps' output), recruit_speed, defense. */
|
||||||
|
roles: { role: VillageRole; buildings: BuildingType[]; bonuses: Partial<Record<'production' | 'recruit_speed' | 'defense', number>> }[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface VillageState {
|
export interface VillageState {
|
||||||
id: number
|
id: number
|
||||||
world_id: number
|
world_id: number
|
||||||
|
|
@ -78,6 +94,7 @@ export interface VillageState {
|
||||||
points: number
|
points: number
|
||||||
/** Building space: what buildings and queued new buildings take, out of the village maximum. */
|
/** Building space: what buildings and queued new buildings take, out of the village maximum. */
|
||||||
space: { used: number; max: number }
|
space: { used: number; max: number }
|
||||||
|
specialisation: Specialisation
|
||||||
/** Amounts stored at `resources_at`. */
|
/** Amounts stored at `resources_at`. */
|
||||||
resources: Resources
|
resources: Resources
|
||||||
resources_at: string
|
resources_at: string
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,16 @@ export default {
|
||||||
space: "Building space",
|
space: "Building space",
|
||||||
recruit_speed: "Training speed",
|
recruit_speed: "Training speed",
|
||||||
},
|
},
|
||||||
|
role: {
|
||||||
|
title: 'Village role',
|
||||||
|
none: 'No role yet',
|
||||||
|
resources: 'Resource village',
|
||||||
|
military: 'Military village',
|
||||||
|
kinds: { resources: 'Camps', military: 'Military buildings' },
|
||||||
|
space: '{space} space, {share}%',
|
||||||
|
hint: 'Give one kind {min} space or more, and {share}% of what camps and military buildings take together, for a role.',
|
||||||
|
bonus: { production: '+{value}% from camps', recruit_speed: '+{value}% training speed', defense: '+{value}% defence' },
|
||||||
|
},
|
||||||
side: {
|
side: {
|
||||||
production: 'Production',
|
production: 'Production',
|
||||||
units: 'Units',
|
units: 'Units',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue