feat: the villagers a level needs stand next to its cost (plot card, upgrade hover card, building header), red when too few are free, with the villagers refusal in plain words; population counts heads and the free villagers come from the server

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-11-03 09:56:37 +01:00
parent 5b4af38229
commit f0cf3551c8
13 changed files with 81 additions and 23 deletions

View File

@ -10,8 +10,8 @@ const incoming = computed(() => props.village.movements.filter((m) => m.directio
const attacks = computed(() => incoming.value.filter((m) => m.type === 'attack')) const attacks = computed(() => incoming.value.filter((m) => m.type === 'attack'))
const nextAttack = computed(() => attacks.value[0] ?? null) const nextAttack = computed(() => attacks.value[0] ?? null)
const support = computed(() => incoming.value.length - attacks.value.length) const support = computed(() => incoming.value.length - attacks.value.length)
/** Villagers neither working nor levied: free to staff a new building or to train. */ /** Villagers free to staff a new building level, from the server. */
const idle = computed(() => Math.max(0, props.village.population.villagers - props.village.population.workers - props.village.levy.militia)) const idle = computed(() => props.village.population.idle)
const isActive = (path: string) => route.path === `${base.value}${path}` const isActive = (path: string) => route.path === `${base.value}${path}`
/** Another of the player's villages, on the same screen where the URL has one. */ /** Another of the player's villages, on the same screen where the URL has one. */
@ -128,7 +128,7 @@ async function rename() {
<NuxtLink <NuxtLink
:to="`${base}/workforce`" :to="`${base}/workforce`"
class="cell flex hover:bg-parchment-100" class="cell flex hover:bg-parchment-100"
:title="`${$t('village.population.villagers')}: ${village.population.villagers} · ${$t('village.population.upkeep')}: ${village.population.upkeep}/${village.population.food_budget}`" :title="`${$t('village.population.villagers')}: ${village.population.villagers} · ${$t('village.population.upkeep')}: ${$t('village.population.upkeep_of', { upkeep: village.population.upkeep, budget: village.population.food_budget })}`"
> >
<IconUi name="users" class="size-4 shrink-0 text-wood-800 sm:size-5" /> <IconUi name="users" class="size-4 shrink-0 text-wood-800 sm:size-5" />
<span class="flex flex-col leading-tight"> <span class="flex flex-col leading-tight">

View File

@ -7,6 +7,10 @@ defineProps<{
have?: Resources | null have?: Resources | null
/** Keep the three amounts on one line, for table cells. */ /** Keep the three amounts on one line, for table cells. */
nowrap?: boolean nowrap?: boolean
/** Free villagers the level needs as workers (the server's `villagers`); hidden at 0. */
villagers?: number
/** The village's free villagers (`population.idle`): the villager count turns red above it. */
idle?: number
}>() }>()
const list = ['wood', 'clay', 'iron'] as const const list = ['wood', 'clay', 'iron'] as const
@ -24,5 +28,6 @@ const list = ['wood', 'clay', 'iron'] as const
<IconResource :resource="r" class="size-4" /> <IconResource :resource="r" class="size-4" />
{{ cost[r] }} {{ cost[r] }}
</span> </span>
<UiVillagers :villagers="villagers" :idle="idle" />
</span> </span>
</template> </template>

View File

@ -0,0 +1,21 @@
<script setup lang="ts">
defineProps<{
/** Free villagers a level needs as workers (the server's `villagers`); nothing shows at 0. */
villagers?: number
/** The village's free villagers (`population.idle`): the count turns red above it. */
idle?: number
}>()
</script>
<!-- The villagers a level needs, next to its cost: a small villager icon and the number. -->
<template>
<span
v-if="villagers"
class="inline-flex items-center gap-1 text-xs tabular-nums whitespace-nowrap"
:class="idle !== undefined && villagers > idle ? 'font-semibold text-blood-700' : 'text-ink-700'"
:title="$t('village.build.villagers_title', { need: villagers, idle: idle ?? '–' })"
>
<IconUi name="users" class="size-4" :class="idle !== undefined && villagers > idle ? '' : 'text-wood-800'" />
{{ villagers }}
</span>
</template>

View File

@ -7,7 +7,7 @@ const props = defineProps<{
resources: Resources resources: Resources
canAfford: (cost: Cost) => boolean canAfford: (cost: Cost) => boolean
busy: boolean busy: boolean
/** "Timber camp 2" when the village has more than one of the type. */ /** "Timber camp, copy 2" for a copy, in the server's rank. */
title: string title: string
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
@ -140,17 +140,23 @@ function value(e: BuildingEffect) {
</div> </div>
<div v-if="building.upgrade" class="flex flex-wrap items-center justify-between gap-2 border border-wood-600/50 bg-parchment-100 p-2"> <div v-if="building.upgrade" class="flex flex-wrap items-center justify-between gap-2 border border-wood-600/50 bg-parchment-100 p-2">
<span class="flex items-center gap-2.5"> <span class="flex flex-wrap items-center gap-2.5">
<UiCost :cost="building.upgrade.cost" :have="resources" nowrap /> <UiCost :cost="building.upgrade.cost" :have="resources" :villagers="building.upgrade.villagers" :idle="v.village.value?.population.idle" nowrap />
<span class="flex items-center gap-1 text-xs text-ink-500 tabular-nums"> <span class="flex items-center gap-1 text-xs text-ink-500 tabular-nums">
<IconUi name="clock" class="size-3.5" /> <IconUi name="clock" class="size-3.5" />
{{ formatDuration(building.upgrade.seconds) }} {{ formatDuration(building.upgrade.seconds) }}
</span> </span>
</span> </span>
<button type="button" class="btn btn-primary" :disabled="busy || !canAfford(building.upgrade.cost)" @click="emit('upgrade', building.id)"> <button
type="button"
class="btn btn-primary"
:disabled="busy || !!building.upgrade.blocked || !canAfford(building.upgrade.cost)"
@click="emit('upgrade', building.id)"
>
<IconUi name="up" class="size-4" /> <IconUi name="up" class="size-4" />
{{ $t('village.buildings.upgrade', { level: building.upgrade.target_level }) }} {{ $t('village.buildings.upgrade', { level: building.upgrade.target_level }) }}
</button> </button>
<p v-if="building.upgrade.blocked" class="w-full text-xs font-semibold text-blood-700">{{ $t(`village.blocked.${building.upgrade.blocked}`) }}</p>
</div> </div>
<p v-else class="text-ink-500">{{ $t('village.blocked.max_level') }}</p> <p v-else class="text-ink-500">{{ $t('village.blocked.max_level') }}</p>

View File

@ -364,7 +364,7 @@ const timers = computed(() => {
> >
<p class="mb-1 font-semibold whitespace-nowrap text-wood-900">{{ $t('village.diorama.upgrade_to', { name: tipName, from: tipOffer.target_level - 1, level: tipOffer.target_level }) }}</p> <p class="mb-1 font-semibold whitespace-nowrap text-wood-900">{{ $t('village.diorama.upgrade_to', { name: tipName, from: tipOffer.target_level - 1, level: tipOffer.target_level }) }}</p>
<div class="flex items-center gap-3 whitespace-nowrap"> <div class="flex items-center gap-3 whitespace-nowrap">
<UiCost :cost="tipOffer.cost" :have="resources ?? undefined" nowrap /> <UiCost :cost="tipOffer.cost" :have="resources ?? undefined" :villagers="tipOffer.villagers" :idle="village.population.idle" nowrap />
<span class="inline-flex items-center gap-1 text-ink-700 tabular-nums"><IconUi name="clock" class="size-3.5" />{{ formatDuration(tipOffer.seconds) }}</span> <span class="inline-flex items-center gap-1 text-ink-700 tabular-nums"><IconUi name="clock" class="size-3.5" />{{ formatDuration(tipOffer.seconds) }}</span>
</div> </div>
<p v-if="tipBuilding && isCopy(tipBuilding.instance_share)" class="mt-1"> <p v-if="tipBuilding && isCopy(tipBuilding.instance_share)" class="mt-1">

View File

@ -18,7 +18,7 @@ const wounded = computed(() => {
if (!list.length) return null if (!list.length) return null
return { count: props.village.hospital.occupied, next: list[0]!.heals_at } return { count: props.village.hospital.occupied, next: list[0]!.heals_at }
}) })
const idle = computed(() => props.village.population.villagers - props.village.population.workers - props.village.levy.militia) const idle = computed(() => props.village.population.idle)
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)
@ -137,7 +137,9 @@ function order(o: BuildOrder) {
<dt>{{ $t('village.population.idle') }}</dt> <dt>{{ $t('village.population.idle') }}</dt>
<dd class="text-right tabular-nums">{{ idle }}</dd> <dd class="text-right tabular-nums">{{ idle }}</dd>
<dt>{{ $t('village.population.upkeep') }}</dt> <dt>{{ $t('village.population.upkeep') }}</dt>
<dd class="text-right tabular-nums">{{ village.population.upkeep }}/{{ village.population.food_budget }}</dd> <dd class="text-right tabular-nums" :title="$t('village.population.heads_hint')">
{{ $t('village.population.upkeep_of', { upkeep: village.population.upkeep, budget: village.population.food_budget }) }}
</dd>
</dl> </dl>
</template> </template>

View File

@ -6,6 +6,8 @@ const props = defineProps<{
resources: Resources resources: Resources
canAfford: (cost: Cost) => boolean canAfford: (cost: Cost) => boolean
busy: boolean busy: boolean
/** Villagers free for a new level (`population.idle`). */
idle: number
/** One of this type already stands; this plot is for another. */ /** One of this type already stands; this plot is for another. */
another: boolean another: boolean
/** The headquarters screen with every building. */ /** The headquarters screen with every building. */
@ -53,7 +55,7 @@ const reason = computed(() => {
</p> </p>
<div v-if="!option.requires.length" class="space-y-1.5 rounded-sm border border-wood-600/50 bg-parchment-100 p-3"> <div v-if="!option.requires.length" class="space-y-1.5 rounded-sm border border-wood-600/50 bg-parchment-100 p-3">
<div class="flex items-center justify-between gap-2 text-xs text-ink-500"> <div class="flex items-center justify-between gap-2 text-xs text-ink-500">
<UiCost :cost="option.cost" :have="resources" /> <UiCost :cost="option.cost" :have="resources" :villagers="option.villagers" :idle="idle" />
<span class="flex items-center gap-1 tabular-nums"> <span class="flex items-center gap-1 tabular-nums">
<IconUi name="clock" class="size-3" /> <IconUi name="clock" class="size-3" />
{{ formatDuration(option.seconds) }} {{ formatDuration(option.seconds) }}

View File

@ -10,7 +10,7 @@ const props = defineProps<{
const stats = computed(() => [ const stats = computed(() => [
{ key: 'villagers', value: props.population.villagers }, { key: 'villagers', value: props.population.villagers },
{ key: 'workers', value: props.population.workers }, { key: 'workers', value: props.population.workers },
{ key: 'idle', value: props.population.villagers - props.population.workers - props.militia }, { key: 'idle', value: props.population.idle },
{ key: 'soldiers', value: props.population.soldiers }, { key: 'soldiers', value: props.population.soldiers },
]) ])
</script> </script>
@ -22,19 +22,20 @@ const stats = computed(() => [
<IconUi name="users" class="size-5 text-ink-400" /> <IconUi name="users" class="size-5 text-ink-400" />
</div> </div>
<div class="panel-body space-y-4"> <div class="panel-body space-y-4">
<div class="grid grid-cols-2 gap-3"> <!-- Heads, the same on every world speed: the food per hour is in the resource bar. -->
<div class="grid grid-cols-2 gap-3" :title="$t('village.population.heads_hint')">
<div class="rounded-sm border-2 border-parchment-300 bg-parchment-100 p-3"> <div class="rounded-sm border-2 border-parchment-300 bg-parchment-100 p-3">
<p class="text-xs text-ink-500">{{ $t('village.population.food_budget') }}</p> <p class="text-xs text-ink-500">{{ $t('village.population.food_budget') }}</p>
<p class="mt-0.5 flex items-center gap-1 font-semibold tabular-nums"> <p class="mt-0.5 flex items-center gap-1 font-semibold tabular-nums">
<IconResource resource="food" class="size-4" /> <IconUi name="users" class="size-4 text-wood-800" />
{{ $t('village.population.food_per_hour', { value: population.food_budget }) }} {{ $t('village.population.heads', { value: population.food_budget }) }}
</p> </p>
</div> </div>
<div class="rounded-sm border-2 border-parchment-300 bg-parchment-100 p-3"> <div class="rounded-sm border-2 border-parchment-300 bg-parchment-100 p-3">
<p class="text-xs text-ink-500">{{ $t('village.population.upkeep') }}</p> <p class="text-xs text-ink-500">{{ $t('village.population.upkeep') }}</p>
<p class="mt-0.5 flex items-center gap-1 font-semibold tabular-nums"> <p class="mt-0.5 flex items-center gap-1 font-semibold tabular-nums">
<IconResource resource="food" class="size-4" /> <IconUi name="users" class="size-4 text-wood-800" />
{{ $t('village.population.food_per_hour', { value: population.upkeep }) }} {{ $t('village.population.heads', { value: population.upkeep }) }}
</p> </p>
</div> </div>
</div> </div>
@ -45,6 +46,9 @@ const stats = computed(() => [
<dt class="text-xs text-ink-500">{{ $t(`village.population.${s.key}`) }}</dt> <dt class="text-xs text-ink-500">{{ $t(`village.population.${s.key}`) }}</dt>
</div> </div>
</dl> </dl>
<p v-if="population.reserved" class="text-xs text-ink-500">
{{ $t('village.population.reserved') }}: <span class="font-semibold tabular-nums">{{ population.reserved }}</span>
</p>
<div> <div>
<div class="mb-1 flex justify-between text-xs text-ink-500"> <div class="mb-1 flex justify-between text-xs text-ink-500">

View File

@ -91,6 +91,11 @@ export function useVillage(villageId: number) {
} }
const queueOrder = (v: VillageState, order: Omit<BuildOrder, 'id' | 'position' | 'builder' | 'starts_at' | 'finishes_at'>) => const queueOrder = (v: VillageState, order: Omit<BuildOrder, 'id' | 'position' | 'builder' | 'starts_at' | 'finishes_at'>) =>
v.queue.push({ ...order, id: --placeholder, position: v.queue.length + 1, builder: null, starts_at: null, finishes_at: null }) v.queue.push({ ...order, id: --placeholder, position: v.queue.length + 1, builder: null, starts_at: null, finishes_at: null })
/** The queue holds back (or, with sign 1, frees) the villagers an order needs, as the server counts them. */
const hold = (v: VillageState, villagers: number, sign = -1) => {
v.population.idle = Math.max(0, v.population.idle + sign * villagers)
v.population.reserved = Math.max(0, v.population.reserved - sign * villagers)
}
/** stored + rate × elapsed, kept between 0 and the storage cap. */ /** stored + rate × elapsed, kept between 0 and the storage cap. */
const resources = computed<Resources | null>(() => { const resources = computed<Resources | null>(() => {
@ -152,8 +157,9 @@ export function useVillage(villageId: number) {
const o = v.buildable.find((b) => b.type === type) const o = v.buildable.find((b) => b.type === type)
if (!o) return if (!o) return
pay(v, o.cost) pay(v, o.cost)
queueOrder(v, { building_id: null, type, action: 'build', target_level: 1, space: o.space, cost: o.cost }) queueOrder(v, { building_id: null, type, action: 'build', target_level: 1, space: o.space, cost: o.cost, villagers: o.villagers })
v.space.used += o.space v.space.used += o.space
hold(v, o.villagers)
}, },
}), }),
upgrade: (buildingId: number) => upgrade: (buildingId: number) =>
@ -162,7 +168,8 @@ export function useVillage(villageId: number) {
const b = v.buildings.find((x) => x.id === buildingId) const b = v.buildings.find((x) => x.id === buildingId)
if (!b?.upgrade) return if (!b?.upgrade) return
pay(v, b.upgrade.cost) pay(v, b.upgrade.cost)
queueOrder(v, { building_id: b.id, type: b.type, action: 'upgrade', target_level: b.upgrade.target_level, space: b.space, cost: b.upgrade.cost }) queueOrder(v, { building_id: b.id, type: b.type, action: 'upgrade', target_level: b.upgrade.target_level, space: b.space, cost: b.upgrade.cost, villagers: b.upgrade.villagers })
hold(v, b.upgrade.villagers)
}, },
}), }),
demolish: (buildingId: number) => demolish: (buildingId: number) =>
@ -170,7 +177,7 @@ export function useVillage(villageId: number) {
optimistic: (v) => { optimistic: (v) => {
const b = v.buildings.find((x) => x.id === buildingId) const b = v.buildings.find((x) => x.id === buildingId)
if (!b?.demolish) return if (!b?.demolish) return
queueOrder(v, { building_id: b.id, type: b.type, action: 'demolish', target_level: b.demolish.target_level, space: b.space, cost: { wood: 0, clay: 0, iron: 0 } }) queueOrder(v, { building_id: b.id, type: b.type, action: 'demolish', target_level: b.demolish.target_level, space: b.space, cost: { wood: 0, clay: 0, iron: 0 }, villagers: 0 })
}, },
}), }),
cancel: (orderId: number) => cancel: (orderId: number) =>
@ -181,6 +188,7 @@ export function useVillage(villageId: number) {
v.queue = v.queue.filter((x) => x !== o) v.queue = v.queue.filter((x) => x !== o)
pay(v, o.cost, 1) pay(v, o.cost, 1)
if (o.action === 'build') v.space.used -= o.space if (o.action === 'build') v.space.used -= o.space
hold(v, o.villagers ?? 0, 1)
}, },
}), }),
setPriority: (buildingId: number, priority: number) => setPriority: (buildingId: number, priority: number) =>

View File

@ -29,6 +29,7 @@ async function build(type: BuildingType) {
:resources="resources" :resources="resources"
:can-afford="v.canAfford" :can-afford="v.canAfford"
:busy="v.busy.value" :busy="v.busy.value"
:idle="village.population.idle"
:another="village.buildings.some((b) => b.type === plotOption!.type)" :another="village.buildings.some((b) => b.type === plotOption!.type)"
:all-link="`${base}/build`" :all-link="`${base}/build`"
@build="build" @build="build"

View File

@ -73,7 +73,8 @@ export function buildingTag(
case 'farm': { case 'farm': {
const p = village.population const p = village.population
const free = Math.max(0, p.villagers - p.workers - village.levy.militia) // Free for a new building level, from the server: not drafted, not working, not held for the queue.
const free = p.idle
const wanted = village.buildings.reduce((n, x) => n + x.workers.required, 0) const wanted = village.buildings.reduce((n, x) => n + x.workers.required, 0)
const short = wanted > p.workers const short = wanted > p.workers
return { return {

View File

@ -100,7 +100,7 @@ export default {
resources: 'Not enough resources.', resources: 'Not enough resources.',
core_building: 'Core buildings cannot go below level 1.', 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 free villagers: build up the farm.',
count: 'Pick at least one.', count: 'Pick at least one.',
levy_active: 'A levy is already under way.', levy_active: 'A levy is already under way.',
no_rally_point: 'Build a rally point first.', no_rally_point: 'Build a rally point first.',

View File

@ -139,9 +139,12 @@ export default {
villagers: 'Villagers', villagers: 'Villagers',
workers: 'Working', workers: 'Working',
idle: 'Idle', idle: 'Idle',
reserved: 'Held for the queue',
soldiers: 'Soldiers', soldiers: 'Soldiers',
workforce: 'Villagers at work', workforce: 'Villagers at work',
food_per_hour: '{value} food/h', heads: '{value} heads',
upkeep_of: '{upkeep}/{budget} heads',
heads_hint: 'A head eats one food per hour at world speed 1, more on faster worlds. The farms feed the same heads on every world speed.',
}, },
buildings: { buildings: {
title: 'Workforce', title: 'Workforce',
@ -340,8 +343,12 @@ export default {
space: 'Space {space}', space: 'Space {space}',
free_space: '{free} space free', free_space: '{free} space free',
submit: 'Build', submit: 'Build',
villagers_title: '{need} free villagers needed as workers, {idle} free',
group: '{name} · {count}',
}, },
copy: { copy: {
name: '{name}, copy {n}',
nth: 'Copy {n} · {share}%',
share: 'works at {share}%', share: 'works at {share}%',
this: 'Copy: works at {share}%', this: 'Copy: works at {share}%',
new: 'New copy: works at {share}%, costs more', new: 'New copy: works at {share}%, costs more',
@ -368,6 +375,7 @@ export default {
max_level: 'Max level', max_level: 'Max level',
resources: 'Not enough resources', resources: 'Not enough resources',
requires: 'Needs a bigger headquarters', requires: 'Needs a bigger headquarters',
villagers: 'Not enough free villagers: build up the farm',
}, },
}, },
}, },