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:
parent
5b4af38229
commit
f0cf3551c8
|
|
@ -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 nextAttack = computed(() => attacks.value[0] ?? null)
|
||||
const support = computed(() => incoming.value.length - attacks.value.length)
|
||||
/** Villagers neither working nor levied: free to staff a new building or to train. */
|
||||
const idle = computed(() => Math.max(0, props.village.population.villagers - props.village.population.workers - props.village.levy.militia))
|
||||
/** Villagers free to staff a new building level, from the server. */
|
||||
const idle = computed(() => props.village.population.idle)
|
||||
const isActive = (path: string) => route.path === `${base.value}${path}`
|
||||
|
||||
/** Another of the player's villages, on the same screen where the URL has one. */
|
||||
|
|
@ -128,7 +128,7 @@ async function rename() {
|
|||
<NuxtLink
|
||||
:to="`${base}/workforce`"
|
||||
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" />
|
||||
<span class="flex flex-col leading-tight">
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ defineProps<{
|
|||
have?: Resources | null
|
||||
/** Keep the three amounts on one line, for table cells. */
|
||||
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
|
||||
|
|
@ -24,5 +28,6 @@ const list = ['wood', 'clay', 'iron'] as const
|
|||
<IconResource :resource="r" class="size-4" />
|
||||
{{ cost[r] }}
|
||||
</span>
|
||||
<UiVillagers :villagers="villagers" :idle="idle" />
|
||||
</span>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -7,7 +7,7 @@ const props = defineProps<{
|
|||
resources: Resources
|
||||
canAfford: (cost: Cost) => 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
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
|
|
@ -140,17 +140,23 @@ function value(e: BuildingEffect) {
|
|||
</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">
|
||||
<span class="flex items-center gap-2.5">
|
||||
<UiCost :cost="building.upgrade.cost" :have="resources" nowrap />
|
||||
<span class="flex flex-wrap items-center gap-2.5">
|
||||
<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">
|
||||
<IconUi name="clock" class="size-3.5" />
|
||||
{{ formatDuration(building.upgrade.seconds) }}
|
||||
</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" />
|
||||
{{ $t('village.buildings.upgrade', { level: building.upgrade.target_level }) }}
|
||||
</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>
|
||||
<p v-else class="text-ink-500">{{ $t('village.blocked.max_level') }}</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
<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>
|
||||
</div>
|
||||
<p v-if="tipBuilding && isCopy(tipBuilding.instance_share)" class="mt-1">
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const wounded = computed(() => {
|
|||
if (!list.length) return null
|
||||
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 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)
|
||||
|
|
@ -137,7 +137,9 @@ function order(o: BuildOrder) {
|
|||
<dt>{{ $t('village.population.idle') }}</dt>
|
||||
<dd class="text-right tabular-nums">{{ idle }}</dd>
|
||||
<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>
|
||||
</template>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ const props = defineProps<{
|
|||
resources: Resources
|
||||
canAfford: (cost: Cost) => boolean
|
||||
busy: boolean
|
||||
/** Villagers free for a new level (`population.idle`). */
|
||||
idle: number
|
||||
/** One of this type already stands; this plot is for another. */
|
||||
another: boolean
|
||||
/** The headquarters screen with every building. */
|
||||
|
|
@ -53,7 +55,7 @@ const reason = computed(() => {
|
|||
</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 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">
|
||||
<IconUi name="clock" class="size-3" />
|
||||
{{ formatDuration(option.seconds) }}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ const props = defineProps<{
|
|||
const stats = computed(() => [
|
||||
{ key: 'villagers', value: props.population.villagers },
|
||||
{ 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 },
|
||||
])
|
||||
</script>
|
||||
|
|
@ -22,19 +22,20 @@ const stats = computed(() => [
|
|||
<IconUi name="users" class="size-5 text-ink-400" />
|
||||
</div>
|
||||
<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">
|
||||
<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">
|
||||
<IconResource resource="food" class="size-4" />
|
||||
{{ $t('village.population.food_per_hour', { value: population.food_budget }) }}
|
||||
<IconUi name="users" class="size-4 text-wood-800" />
|
||||
{{ $t('village.population.heads', { value: population.food_budget }) }}
|
||||
</p>
|
||||
</div>
|
||||
<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="mt-0.5 flex items-center gap-1 font-semibold tabular-nums">
|
||||
<IconResource resource="food" class="size-4" />
|
||||
{{ $t('village.population.food_per_hour', { value: population.upkeep }) }}
|
||||
<IconUi name="users" class="size-4 text-wood-800" />
|
||||
{{ $t('village.population.heads', { value: population.upkeep }) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -45,6 +46,9 @@ const stats = computed(() => [
|
|||
<dt class="text-xs text-ink-500">{{ $t(`village.population.${s.key}`) }}</dt>
|
||||
</div>
|
||||
</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 class="mb-1 flex justify-between text-xs text-ink-500">
|
||||
|
|
|
|||
|
|
@ -91,6 +91,11 @@ export function useVillage(villageId: number) {
|
|||
}
|
||||
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 })
|
||||
/** 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. */
|
||||
const resources = computed<Resources | null>(() => {
|
||||
|
|
@ -152,8 +157,9 @@ export function useVillage(villageId: number) {
|
|||
const o = v.buildable.find((b) => b.type === type)
|
||||
if (!o) return
|
||||
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
|
||||
hold(v, o.villagers)
|
||||
},
|
||||
}),
|
||||
upgrade: (buildingId: number) =>
|
||||
|
|
@ -162,7 +168,8 @@ export function useVillage(villageId: number) {
|
|||
const b = v.buildings.find((x) => x.id === buildingId)
|
||||
if (!b?.upgrade) return
|
||||
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) =>
|
||||
|
|
@ -170,7 +177,7 @@ export function useVillage(villageId: number) {
|
|||
optimistic: (v) => {
|
||||
const b = v.buildings.find((x) => x.id === buildingId)
|
||||
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) =>
|
||||
|
|
@ -181,6 +188,7 @@ export function useVillage(villageId: number) {
|
|||
v.queue = v.queue.filter((x) => x !== o)
|
||||
pay(v, o.cost, 1)
|
||||
if (o.action === 'build') v.space.used -= o.space
|
||||
hold(v, o.villagers ?? 0, 1)
|
||||
},
|
||||
}),
|
||||
setPriority: (buildingId: number, priority: number) =>
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ async function build(type: BuildingType) {
|
|||
:resources="resources"
|
||||
:can-afford="v.canAfford"
|
||||
:busy="v.busy.value"
|
||||
:idle="village.population.idle"
|
||||
:another="village.buildings.some((b) => b.type === plotOption!.type)"
|
||||
:all-link="`${base}/build`"
|
||||
@build="build"
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ export function buildingTag(
|
|||
|
||||
case 'farm': {
|
||||
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 short = wanted > p.workers
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ export default {
|
|||
resources: 'Not enough resources.',
|
||||
core_building: 'Core buildings cannot go below level 1.',
|
||||
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.',
|
||||
levy_active: 'A levy is already under way.',
|
||||
no_rally_point: 'Build a rally point first.',
|
||||
|
|
|
|||
|
|
@ -139,9 +139,12 @@ export default {
|
|||
villagers: 'Villagers',
|
||||
workers: 'Working',
|
||||
idle: 'Idle',
|
||||
reserved: 'Held for the queue',
|
||||
soldiers: 'Soldiers',
|
||||
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: {
|
||||
title: 'Workforce',
|
||||
|
|
@ -340,8 +343,12 @@ export default {
|
|||
space: 'Space {space}',
|
||||
free_space: '{free} space free',
|
||||
submit: 'Build',
|
||||
villagers_title: '{need} free villagers needed as workers, {idle} free',
|
||||
group: '{name} · {count}',
|
||||
},
|
||||
copy: {
|
||||
name: '{name}, copy {n}',
|
||||
nth: 'Copy {n} · {share}%',
|
||||
share: 'works at {share}%',
|
||||
this: 'Copy: works at {share}%',
|
||||
new: 'New copy: works at {share}%, costs more',
|
||||
|
|
@ -368,6 +375,7 @@ export default {
|
|||
max_level: 'Max level',
|
||||
resources: 'Not enough resources',
|
||||
requires: 'Needs a bigger headquarters',
|
||||
villagers: 'Not enough free villagers: build up the farm',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue