diff --git a/app/components/game/VillageBar.vue b/app/components/game/VillageBar.vue index 841fb3d..cd5ad1a 100644 --- a/app/components/game/VillageBar.vue +++ b/app/components/game/VillageBar.vue @@ -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() { diff --git a/app/components/ui/Cost.vue b/app/components/ui/Cost.vue index 2a5ee43..57da0e9 100644 --- a/app/components/ui/Cost.vue +++ b/app/components/ui/Cost.vue @@ -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 {{ cost[r] }} + diff --git a/app/components/ui/Villagers.vue b/app/components/ui/Villagers.vue new file mode 100644 index 0000000..1cf92a0 --- /dev/null +++ b/app/components/ui/Villagers.vue @@ -0,0 +1,21 @@ + + + + diff --git a/app/components/village/BuildingHeader.vue b/app/components/village/BuildingHeader.vue index 5d9a0c3..e7143b8 100644 --- a/app/components/village/BuildingHeader.vue +++ b/app/components/village/BuildingHeader.vue @@ -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) {
- - + + {{ formatDuration(building.upgrade.seconds) }} - +

{{ $t(`village.blocked.${building.upgrade.blocked}`) }}

{{ $t('village.blocked.max_level') }}

diff --git a/app/components/village/Diorama.vue b/app/components/village/Diorama.vue index 8c49f1e..b11b0cb 100644 --- a/app/components/village/Diorama.vue +++ b/app/components/village/Diorama.vue @@ -364,7 +364,7 @@ const timers = computed(() => { >

{{ $t('village.diorama.upgrade_to', { name: tipName, from: tipOffer.target_level - 1, level: tipOffer.target_level }) }}

- + {{ formatDuration(tipOffer.seconds) }}

diff --git a/app/components/village/OverviewSidebar.vue b/app/components/village/OverviewSidebar.vue index 723b90d..fc4f089 100644 --- a/app/components/village/OverviewSidebar.vue +++ b/app/components/village/OverviewSidebar.vue @@ -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) {

{{ $t('village.population.idle') }}
{{ idle }}
{{ $t('village.population.upkeep') }}
-
{{ village.population.upkeep }}/{{ village.population.food_budget }}
+
+ {{ $t('village.population.upkeep_of', { upkeep: village.population.upkeep, budget: village.population.food_budget }) }} +
diff --git a/app/components/village/PlotCard.vue b/app/components/village/PlotCard.vue index 8d9eef4..fa7bc21 100644 --- a/app/components/village/PlotCard.vue +++ b/app/components/village/PlotCard.vue @@ -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(() => {

- + {{ formatDuration(option.seconds) }} diff --git a/app/components/village/PopulationPanel.vue b/app/components/village/PopulationPanel.vue index e74a6bd..f264666 100644 --- a/app/components/village/PopulationPanel.vue +++ b/app/components/village/PopulationPanel.vue @@ -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 }, ]) @@ -22,19 +22,20 @@ const stats = computed(() => [
-
+ +

{{ $t('village.population.food_budget') }}

- - {{ $t('village.population.food_per_hour', { value: population.food_budget }) }} + + {{ $t('village.population.heads', { value: population.food_budget }) }}

{{ $t('village.population.upkeep') }}

- - {{ $t('village.population.food_per_hour', { value: population.upkeep }) }} + + {{ $t('village.population.heads', { value: population.upkeep }) }}

@@ -45,6 +46,9 @@ const stats = computed(() => [
{{ $t(`village.population.${s.key}`) }}
+

+ {{ $t('village.population.reserved') }}: {{ population.reserved }} +

diff --git a/app/composables/useVillage.ts b/app/composables/useVillage.ts index 45d73f9..0d92856 100644 --- a/app/composables/useVillage.ts +++ b/app/composables/useVillage.ts @@ -91,6 +91,11 @@ export function useVillage(villageId: number) { } const queueOrder = (v: VillageState, order: Omit) => 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(() => { @@ -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) => diff --git a/app/pages/village/[id]/index.vue b/app/pages/village/[id]/index.vue index b2da09c..3acfdfc 100644 --- a/app/pages/village/[id]/index.vue +++ b/app/pages/village/[id]/index.vue @@ -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" diff --git a/app/utils/buildingTags.ts b/app/utils/buildingTags.ts index 02ead7c..cb968c7 100644 --- a/app/utils/buildingTags.ts +++ b/app/utils/buildingTags.ts @@ -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 { diff --git a/i18n/locales/en.ts b/i18n/locales/en.ts index 464024d..2c90546 100644 --- a/i18n/locales/en.ts +++ b/i18n/locales/en.ts @@ -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.', diff --git a/i18n/pages/village.ts b/i18n/pages/village.ts index ddf9052..3e05c4e 100644 --- a/i18n/pages/village.ts +++ b/i18n/pages/village.ts @@ -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', }, }, },