feat: food warnings: a strip when the stock drains, an alert with the desertion countdown when starving
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9878fb0527
commit
bb3796f22b
|
|
@ -0,0 +1,42 @@
|
|||
<script setup lang="ts">
|
||||
import type { Levy, Starvation } from '~/types/game'
|
||||
|
||||
defineProps<{
|
||||
starvation: Starvation
|
||||
levy: Levy
|
||||
secondsUntil: (iso: string) => number
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<!-- A flat strip under the village header while the food stock drains or is empty. -->
|
||||
<template>
|
||||
<div
|
||||
v-if="starvation.since"
|
||||
class="flex flex-wrap items-center gap-x-3 gap-y-1 border-b-2 border-wood-700 bg-blood-700 px-4 py-2 text-sm text-parchment-50 sm:px-6"
|
||||
role="alert"
|
||||
>
|
||||
<IconResource resource="food" class="size-5" />
|
||||
<span class="font-semibold">{{ $t('village.food.starving') }}</span>
|
||||
<span v-if="starvation.desertion_at">
|
||||
{{ $t('village.food.desertion_in') }}
|
||||
<span class="font-semibold tabular-nums">{{ formatDuration(secondsUntil(starvation.desertion_at)) }}</span>
|
||||
</span>
|
||||
<span class="w-full text-xs text-parchment-200 sm:ml-auto sm:w-auto">
|
||||
{{ levy.militia ? $t('village.food.fix_levy') : $t('village.food.fix') }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="starvation.food_empty_at"
|
||||
class="flex flex-wrap items-center gap-x-3 gap-y-1 border-b-2 border-wood-700 bg-gold-400 px-4 py-2 text-sm text-ink-900 sm:px-6"
|
||||
role="status"
|
||||
>
|
||||
<IconResource resource="food" class="size-5" />
|
||||
<span>
|
||||
{{ $t('village.food.runs_out_in') }}
|
||||
<span class="font-semibold tabular-nums">{{ formatDuration(secondsUntil(starvation.food_empty_at)) }}</span>
|
||||
</span>
|
||||
<span class="w-full text-xs text-ink-700 sm:ml-auto sm:w-auto">
|
||||
{{ levy.militia ? $t('village.food.fix_levy') : $t('village.food.then') }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -58,7 +58,7 @@ export function useVillage(villageId: number) {
|
|||
if (!v) return null
|
||||
const times = [
|
||||
...v.queue.flatMap((o) => (o.finishes_at ? [Date.parse(o.finishes_at)] : [])),
|
||||
...(v.levy.until ? [Date.parse(v.levy.until)] : []),
|
||||
...[v.levy.until, v.starvation.food_empty_at, v.starvation.desertion_at].flatMap((at) => (at ? [Date.parse(at)] : [])),
|
||||
...v.military.flatMap((m) =>
|
||||
m.queue.filter((o) => o.done < o.count).map((o) => Date.parse(o.starts_at) + (o.done + 1) * o.seconds_per_unit * 1000),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -430,6 +430,17 @@ function enqueue(state: MockState, v: MockVillage, order: Omit<MockOrder, 'id' |
|
|||
startWaiting(v, now)
|
||||
}
|
||||
|
||||
/** Only the warnings: the mock never makes soldiers desert. */
|
||||
function starvation(v: MockVillage) {
|
||||
const rate = rates(v).food
|
||||
const empty = v.resources.food <= 0.001
|
||||
return {
|
||||
food_empty_at: rate < 0 && !empty ? iso(v.resources_at + (v.resources.food / -rate) * 3_600_000) : null,
|
||||
since: rate < 0 && empty ? iso(v.resources_at) : null,
|
||||
desertion_at: null,
|
||||
}
|
||||
}
|
||||
|
||||
function view(v: MockVillage, now: number): VillageState {
|
||||
const assigned = assignWorkers(v)
|
||||
const pop = villagers(v)
|
||||
|
|
@ -455,6 +466,7 @@ function view(v: MockVillage, now: number): VillageState {
|
|||
training: (v.recruits ?? []).reduce((sum, o) => sum + o.count - o.done, 0),
|
||||
},
|
||||
levy: { militia: militia(v), until: v.levy_until ? iso(v.levy_until) : null, seconds: LEVY_SECONDS },
|
||||
starvation: starvation(v),
|
||||
troops: Object.fromEntries(Object.entries(v.troops ?? {}).filter(([, n]) => n)),
|
||||
military: military(v, now),
|
||||
builders: BUILDERS,
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ function openRecruit(buildingId?: number) {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<VillageFoodWarning :starvation="village.starvation" :levy="village.levy" :seconds-until="v.secondsUntil" />
|
||||
|
||||
<div class="relative">
|
||||
<div class="h-[clamp(260px,82vw,460px)] sm:h-[clamp(340px,62vh,760px)]">
|
||||
<VillageDiorama v-model:selected="selected" :village="village" :seconds-until="v.secondsUntil" />
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ export interface VillageState {
|
|||
population: Population
|
||||
/** Villagers drafted as militia: they eat but don't work until `until`. */
|
||||
levy: Levy
|
||||
starvation: Starvation
|
||||
/** Own units standing in the village. */
|
||||
troops: Partial<Record<UnitType, number>>
|
||||
/** One entry per building that trains units, in building order. */
|
||||
|
|
@ -110,6 +111,16 @@ export interface Levy {
|
|||
seconds: number
|
||||
}
|
||||
|
||||
/** Upkeep above income drains the food stock; once it is empty, soldiers desert after a grace time. */
|
||||
export interface Starvation {
|
||||
/** When the stock runs out at the current rates; null while food isn't draining. */
|
||||
food_empty_at: string | null
|
||||
/** Set while the stock is empty and the village eats more than it harvests. */
|
||||
since: string | null
|
||||
/** The next desertion wave, while starving. */
|
||||
desertion_at: string | null
|
||||
}
|
||||
|
||||
/** A barracks, stable, workshop or academy: what it trains and its own queue. */
|
||||
export interface MilitaryBuilding {
|
||||
building_id: number
|
||||
|
|
|
|||
|
|
@ -64,6 +64,14 @@ export default {
|
|||
recruit: 'Recruit',
|
||||
hint: 'Build barracks to recruit units.',
|
||||
},
|
||||
food: {
|
||||
runs_out_in: 'Your village eats more than it harvests. Food runs out in',
|
||||
then: 'Once the stores are empty, soldiers start to desert after a grace period.',
|
||||
starving: 'Your village is starving.',
|
||||
desertion_in: 'Soldiers desert in',
|
||||
fix: 'More farms or fewer soldiers stop it.',
|
||||
fix_levy: 'The drafted militia leave the farms unworked: ending the levy helps.',
|
||||
},
|
||||
levy: {
|
||||
title: 'Levy',
|
||||
militia: 'Militia',
|
||||
|
|
|
|||
Loading…
Reference in New Issue