feat: building copies: each instance shows the share it works at (amber chip on copy rows, the building header and the upgrade card), the build row and plot card of a new copy warn it works at 50% and costs more; the mock ranks copies by level and scales their output and cost
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
eb799666cf
commit
b746bb9b00
|
|
@ -170,14 +170,18 @@ const demolishable = computed(() =>
|
||||||
{{ row.name }}
|
{{ row.name }}
|
||||||
</button>
|
</button>
|
||||||
<p v-else class="truncate font-semibold">{{ row.name }}</p>
|
<p v-else class="truncate font-semibold">{{ row.name }}</p>
|
||||||
<p class="text-xs text-ink-500">
|
<!-- A copy works at a share of the first: one amber chip, from the server's share. -->
|
||||||
{{
|
<p class="flex items-center gap-1.5 text-xs whitespace-nowrap text-ink-500">
|
||||||
row.kind === 'upgrade'
|
<template v-if="row.kind === 'upgrade'">
|
||||||
? $t('village.buildings.level_n', { level: row.building.level })
|
{{ $t('village.buildings.level_n', { level: row.building.level }) }}
|
||||||
: row.another
|
<span v-if="isCopy(row.building.instance_share)" class="badge badge-gold">
|
||||||
? $t('village.build.another_hint')
|
{{ $t('village.copy.share', { share: sharePercent(row.building.instance_share) }) }}
|
||||||
: $t('village.build.not_built')
|
</span>
|
||||||
}}
|
</template>
|
||||||
|
<span v-else-if="isCopy(row.option.instance_share)" class="badge badge-gold">
|
||||||
|
{{ $t('village.copy.new', { share: sharePercent(row.option.instance_share) }) }}
|
||||||
|
</span>
|
||||||
|
<template v-else>{{ row.another ? $t('village.build.another_hint') : $t('village.build.not_built') }}</template>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,9 @@ function value(e: BuildingEffect) {
|
||||||
<h1 class="font-display text-lg leading-tight font-bold text-wood-950">
|
<h1 class="font-display text-lg leading-tight font-bold text-wood-950">
|
||||||
{{ title }} <span class="font-normal">({{ $t('village.buildings.level_n', { level: building.level }) }})</span>
|
{{ title }} <span class="font-normal">({{ $t('village.buildings.level_n', { level: building.level }) }})</span>
|
||||||
</h1>
|
</h1>
|
||||||
|
<p v-if="isCopy(building.instance_share)" class="mt-0.5">
|
||||||
|
<span class="badge badge-gold">{{ $t('village.copy.this', { share: sharePercent(building.instance_share) }) }}</span>
|
||||||
|
</p>
|
||||||
<p class="mt-0.5 text-ink-700">{{ $t(`village.building_about.${building.type}`) }}</p>
|
<p class="mt-0.5 text-ink-700">{{ $t(`village.building_about.${building.type}`) }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,10 +158,8 @@ const badges = computed(() => {
|
||||||
const tip = ref<{ id: number; x: number; y: number } | null>(null)
|
const tip = ref<{ id: number; x: number; y: number } | null>(null)
|
||||||
const tipOffer = computed(() => (tip.value ? (badges.value.find((p) => p.b.id === tip.value!.id)?.offer ?? null) : null))
|
const tipOffer = computed(() => (tip.value ? (badges.value.find((p) => p.b.id === tip.value!.id)?.offer ?? null) : null))
|
||||||
/** Which building the card is about: "Hiding place 2" when there are several. */
|
/** Which building the card is about: "Hiding place 2" when there are several. */
|
||||||
const tipName = computed(() => {
|
const tipBuilding = computed(() => (tip.value ? (props.village.buildings.find((x) => x.id === tip.value!.id) ?? null) : null))
|
||||||
const b = tip.value ? props.village.buildings.find((x) => x.id === tip.value!.id) : null
|
const tipName = computed(() => (tipBuilding.value ? buildingName(props.village, tipBuilding.value, t) : ''))
|
||||||
return b ? buildingName(props.village, b, t) : ''
|
|
||||||
})
|
|
||||||
function showTip(id: number, e: Event) {
|
function showTip(id: number, e: Event) {
|
||||||
const r = (e.currentTarget as Element).getBoundingClientRect()
|
const r = (e.currentTarget as Element).getBoundingClientRect()
|
||||||
tip.value = { id, x: r.left + r.width / 2, y: r.top }
|
tip.value = { id, x: r.left + r.width / 2, y: r.top }
|
||||||
|
|
@ -369,6 +367,9 @@ const timers = computed(() => {
|
||||||
<UiCost :cost="tipOffer.cost" :have="resources ?? undefined" nowrap />
|
<UiCost :cost="tipOffer.cost" :have="resources ?? undefined" 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">
|
||||||
|
<span class="badge badge-gold">{{ $t('village.copy.this', { share: sharePercent(tipBuilding.instance_share) }) }}</span>
|
||||||
|
</p>
|
||||||
<p v-if="tipOffer.blocked" class="mt-1 text-xs font-semibold text-blood-700">{{ $t(`village.blocked.${tipOffer.blocked}`) }}</p>
|
<p v-if="tipOffer.blocked" class="mt-1 text-xs font-semibold text-blood-700">{{ $t(`village.blocked.${tipOffer.blocked}`) }}</p>
|
||||||
<p v-else-if="!affordable(tipOffer)" class="mt-1 text-xs font-semibold text-blood-700">{{ $t('village.blocked.resources') }}</p>
|
<p v-else-if="!affordable(tipOffer)" class="mt-1 text-xs font-semibold text-blood-700">{{ $t('village.blocked.resources') }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,11 @@ const reason = computed(() => {
|
||||||
{{ $t('village.build.requirement', { type: $t(`buildings.${r.type}`), level: r.level }) }}
|
{{ $t('village.build.requirement', { type: $t(`buildings.${r.type}`), level: r.level }) }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="space-y-1.5 rounded-sm border border-wood-600/50 bg-parchment-100 p-3">
|
<!-- A copy works at a share of the first and costs more: say so before the cost. -->
|
||||||
|
<p v-if="isCopy(option.instance_share)" class="border border-gold-600 bg-gold-400 px-2 py-0.5 text-xs text-ink-900">
|
||||||
|
{{ $t('village.copy.offer', { share: sharePercent(option.instance_share) }) }}
|
||||||
|
</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">
|
<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" />
|
||||||
<span class="flex items-center gap-1 tabular-nums">
|
<span class="flex items-center gap-1 tabular-nums">
|
||||||
|
|
|
||||||
|
|
@ -98,3 +98,6 @@ export const DETECTION = 2
|
||||||
export const CANCEL_WINDOW = 600
|
export const CANCEL_WINDOW = 600
|
||||||
/** Wood, clay and iron each in every barbarian village; it never runs out. */
|
/** Wood, clay and iron each in every barbarian village; it never runs out. */
|
||||||
export const BARBARIAN_STOCK = 1000
|
export const BARBARIAN_STOCK = 1000
|
||||||
|
|
||||||
|
/** Each copy of a building type works at this share of the one ranked above it, and costs its inverse as much. */
|
||||||
|
export const COPY_SHARE = 0.5
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ import {
|
||||||
BUILDING_TYPES,
|
BUILDING_TYPES,
|
||||||
CANCEL_WINDOW,
|
CANCEL_WINDOW,
|
||||||
CATALOG,
|
CATALOG,
|
||||||
|
COPY_SHARE,
|
||||||
DEFAULT_MODE,
|
DEFAULT_MODE,
|
||||||
DEFAULT_PRIORITY,
|
DEFAULT_PRIORITY,
|
||||||
DEMOLISH_REFUND,
|
DEMOLISH_REFUND,
|
||||||
|
|
@ -242,10 +243,28 @@ const levelCost = (type: BuildingType, level: number) => mapCost(CATALOG[type].c
|
||||||
const levelSeconds = (type: BuildingType, level: number) => atLevel(CATALOG[type].seconds, level)
|
const levelSeconds = (type: BuildingType, level: number) => atLevel(CATALOG[type].seconds, level)
|
||||||
const requiredWorkers = (b: MockBuilding) => atLevel(CATALOG[b.type].workers, b.level)
|
const requiredWorkers = (b: MockBuilding) => atLevel(CATALOG[b.type].workers, b.level)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The share an instance works at: the first of its type (by level, then age) fully, each copy
|
||||||
|
* COPY_SHARE of the one ranked above it. A crude stand-in for the backend's copy rule.
|
||||||
|
*/
|
||||||
|
function instanceShare(v: MockVillage, b: MockBuilding) {
|
||||||
|
const rank = v.buildings
|
||||||
|
.filter((o) => o.type === b.type)
|
||||||
|
.sort((p, q) => q.level - p.level || p.id - q.id)
|
||||||
|
.indexOf(b)
|
||||||
|
return COPY_SHARE ** Math.max(0, rank)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What another instance of a type would cost and work at; unique types have no copies. */
|
||||||
|
function newInstance(v: MockVillage, type: BuildingType) {
|
||||||
|
const share = CATALOG[type].max_per_village === 1 ? 1 : COPY_SHARE ** instances(v, type)
|
||||||
|
return { share, cost: mapCost(levelCost(type, 1), (n) => Math.round(n / share)) }
|
||||||
|
}
|
||||||
|
|
||||||
function foodBudget(v: MockVillage) {
|
function foodBudget(v: MockVillage) {
|
||||||
return v.buildings
|
return v.buildings
|
||||||
.filter((b) => b.type === 'farm')
|
.filter((b) => b.type === 'farm')
|
||||||
.reduce((sum, b) => sum + atLevel(CATALOG.farm.production!.per_hour, b.level), 0)
|
.reduce((sum, b) => sum + atLevel(CATALOG.farm.production!.per_hour, b.level) * instanceShare(v, b), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Known unit types with a positive count. */
|
/** Known unit types with a positive count. */
|
||||||
|
|
@ -297,17 +316,17 @@ const staffing = (b: MockBuilding, assigned: Map<number, number>) => {
|
||||||
/** Linear stand-in for the real staffing curve: empty buildings still make 10%. */
|
/** Linear stand-in for the real staffing curve: empty buildings still make 10%. */
|
||||||
const outputFactor = (ratio: number) => 0.1 + 0.9 * ratio
|
const outputFactor = (ratio: number) => 0.1 + 0.9 * ratio
|
||||||
|
|
||||||
function production(b: MockBuilding, assigned: Map<number, number>) {
|
function production(v: MockVillage, b: MockBuilding, assigned: Map<number, number>) {
|
||||||
const prod = CATALOG[b.type].production
|
const prod = CATALOG[b.type].production
|
||||||
if (!prod) return null
|
if (!prod) return null
|
||||||
return { resource: prod.resource, per_hour: atLevel(prod.per_hour, b.level) * outputFactor(staffing(b, assigned)) }
|
return { resource: prod.resource, per_hour: atLevel(prod.per_hour, b.level) * outputFactor(staffing(b, assigned)) * instanceShare(v, b) }
|
||||||
}
|
}
|
||||||
|
|
||||||
function rates(v: MockVillage): Resources {
|
function rates(v: MockVillage): Resources {
|
||||||
const assigned = assignWorkers(v)
|
const assigned = assignWorkers(v)
|
||||||
const r: Resources = { wood: BASE_TRICKLE, clay: BASE_TRICKLE, iron: BASE_TRICKLE, food: 0 }
|
const r: Resources = { wood: BASE_TRICKLE, clay: BASE_TRICKLE, iron: BASE_TRICKLE, food: 0 }
|
||||||
for (const b of v.buildings) {
|
for (const b of v.buildings) {
|
||||||
const p = production(b, assigned)
|
const p = production(v, b, assigned)
|
||||||
if (p) r[p.resource] += p.per_hour
|
if (p) r[p.resource] += p.per_hour
|
||||||
}
|
}
|
||||||
r.food -= villagers(v) * VILLAGER_UPKEEP + soldierUpkeep(v)
|
r.food -= villagers(v) * VILLAGER_UPKEEP + soldierUpkeep(v)
|
||||||
|
|
@ -317,7 +336,7 @@ function rates(v: MockVillage): Resources {
|
||||||
function storageCap(v: MockVillage) {
|
function storageCap(v: MockVillage) {
|
||||||
return v.buildings
|
return v.buildings
|
||||||
.filter((b) => b.type === 'storage')
|
.filter((b) => b.type === 'storage')
|
||||||
.reduce((sum, b) => sum + atLevel(CATALOG.storage.capacity!, b.level), 0)
|
.reduce((sum, b) => sum + atLevel(CATALOG.storage.capacity!, b.level) * instanceShare(v, b), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** stored + rate × elapsed, written back into the village. */
|
/** stored + rate × elapsed, written back into the village. */
|
||||||
|
|
@ -421,7 +440,7 @@ function upgradeOffer(v: MockVillage, b: MockBuilding): Offer | null {
|
||||||
const current = queuedLevel(v, b)
|
const current = queuedLevel(v, b)
|
||||||
if (current < 1 || current >= MAX_LEVEL) return null
|
if (current < 1 || current >= MAX_LEVEL) return null
|
||||||
const target = current + 1
|
const target = current + 1
|
||||||
const cost = levelCost(b.type, target)
|
const cost = mapCost(levelCost(b.type, target), (n) => Math.round(n / instanceShare(v, b)))
|
||||||
return { target_level: target, cost, seconds: levelSeconds(b.type, target), blocked: null }
|
return { target_level: target, cost, seconds: levelSeconds(b.type, target), blocked: null }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -438,14 +457,14 @@ function demolishOffer(v: MockVillage, b: MockBuilding) {
|
||||||
function buildOptions(v: MockVillage): BuildOption[] {
|
function buildOptions(v: MockVillage): BuildOption[] {
|
||||||
return BUILDING_TYPES.map((type) => {
|
return BUILDING_TYPES.map((type) => {
|
||||||
const entry = CATALOG[type]
|
const entry = CATALOG[type]
|
||||||
const cost = levelCost(type, 1)
|
const { cost, share } = newInstance(v, type)
|
||||||
const blocked =
|
const blocked =
|
||||||
entry.max_per_village !== null && instances(v, type) >= entry.max_per_village
|
entry.max_per_village !== null && instances(v, type) >= entry.max_per_village
|
||||||
? 'max_per_village'
|
? 'max_per_village'
|
||||||
: !spaceFits(v, type)
|
: !spaceFits(v, type)
|
||||||
? 'no_space'
|
? 'no_space'
|
||||||
: null
|
: null
|
||||||
return { type, space: entry.space, target_level: 1, cost, seconds: levelSeconds(type, 1), blocked, requires: [] }
|
return { type, space: entry.space, target_level: 1, cost, seconds: levelSeconds(type, 1), blocked, requires: [], instance_share: share }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -513,7 +532,8 @@ function missingRequirements(v: MockVillage, unit: UnitType) {
|
||||||
.map(([type, level]) => ({ type: type as BuildingType, level: level ?? 0 }))
|
.map(([type, level]) => ({ type: type as BuildingType, level: level ?? 0 }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const secondsPerUnit = (b: MockBuilding, unit: UnitType) => Math.max(1, Math.ceil(UNITS[unit].seconds / (1 + 0.05 * Math.max(0, b.level - 1))))
|
const secondsPerUnit = (v: MockVillage, b: MockBuilding, unit: UnitType) =>
|
||||||
|
Math.max(1, Math.ceil(UNITS[unit].seconds / (1 + 0.05 * Math.max(0, b.level - 1)) / instanceShare(v, b)))
|
||||||
|
|
||||||
function military(v: MockVillage, at: number): MilitaryBuilding[] {
|
function military(v: MockVillage, at: number): MilitaryBuilding[] {
|
||||||
const pop = villagers(v) - militia(v)
|
const pop = villagers(v) - militia(v)
|
||||||
|
|
@ -530,7 +550,7 @@ function military(v: MockVillage, at: number): MilitaryBuilding[] {
|
||||||
return {
|
return {
|
||||||
unit,
|
unit,
|
||||||
cost,
|
cost,
|
||||||
seconds: secondsPerUnit(b, unit),
|
seconds: secondsPerUnit(v, b, unit),
|
||||||
upkeep,
|
upkeep,
|
||||||
max: requires.length ? 0 : Math.max(0, Math.min(byResources, Math.floor(pop / upkeep))),
|
max: requires.length ? 0 : Math.max(0, Math.min(byResources, Math.floor(pop / upkeep))),
|
||||||
blocked: requires.length ? ('requires' as const) : null,
|
blocked: requires.length ? ('requires' as const) : null,
|
||||||
|
|
@ -647,7 +667,7 @@ function view(state: MockState, v: MockVillage, now: number): VillageState {
|
||||||
builders: BUILDERS,
|
builders: BUILDERS,
|
||||||
buildings: v.buildings.map(
|
buildings: v.buildings.map(
|
||||||
(b): Building => {
|
(b): Building => {
|
||||||
const p = production(b, assigned)
|
const p = production(v, b, assigned)
|
||||||
return {
|
return {
|
||||||
id: b.id,
|
id: b.id,
|
||||||
type: b.type,
|
type: b.type,
|
||||||
|
|
@ -662,6 +682,7 @@ function view(state: MockState, v: MockVillage, now: number): VillageState {
|
||||||
// Placeholder: production only; the backend lists every effect.
|
// Placeholder: production only; the backend lists every effect.
|
||||||
effects: p ? [{ key: 'production', value: round(p.per_hour), resource: p.resource }] : [],
|
effects: p ? [{ key: 'production', value: round(p.per_hour), resource: p.resource }] : [],
|
||||||
next_effects: null,
|
next_effects: null,
|
||||||
|
instance_share: instanceShare(v, b),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
@ -804,7 +825,7 @@ const travelMode = (mode: unknown) => TRAVEL_MODES.find((m) => m.mode === mode)
|
||||||
function hospital(v: MockVillage) {
|
function hospital(v: MockVillage) {
|
||||||
const wounded = (v.wounded ?? []).filter((w) => w.heals_at > Date.now())
|
const wounded = (v.wounded ?? []).filter((w) => w.heals_at > Date.now())
|
||||||
return {
|
return {
|
||||||
beds: v.buildings.filter((b) => b.type === 'hospital').reduce((n, b) => n + 20 * b.level, 0),
|
beds: v.buildings.filter((b) => b.type === 'hospital').reduce((n, b) => n + Math.floor(20 * b.level * instanceShare(v, b)), 0),
|
||||||
occupied: wounded.reduce((n, w) => n + Object.values(w.units).reduce((a, c) => a + (c ?? 0), 0), 0),
|
occupied: wounded.reduce((n, w) => n + Object.values(w.units).reduce((a, c) => a + (c ?? 0), 0), 0),
|
||||||
share: 0.5,
|
share: 0.5,
|
||||||
heal_seconds: 14400,
|
heal_seconds: 14400,
|
||||||
|
|
@ -1285,7 +1306,7 @@ const handlers: Record<string, Handler> = {
|
||||||
const entry = CATALOG[type] ?? fail('not_found')
|
const entry = CATALOG[type] ?? fail('not_found')
|
||||||
if (entry.max_per_village !== null && instances(v, type) >= entry.max_per_village) fail('max_per_village')
|
if (entry.max_per_village !== null && instances(v, type) >= entry.max_per_village) fail('max_per_village')
|
||||||
if (!spaceFits(v, type)) fail('no_space')
|
if (!spaceFits(v, type)) fail('no_space')
|
||||||
const cost = levelCost(type, 1)
|
const { cost } = newInstance(v, type)
|
||||||
pay(v, cost)
|
pay(v, cost)
|
||||||
enqueue(state, v, { building_id: null, type, action: 'build', target_level: 1, cost, seconds: levelSeconds(type, 1) }, now)
|
enqueue(state, v, { building_id: null, type, action: 'build', target_level: 1, cost, seconds: levelSeconds(type, 1) }, now)
|
||||||
return view(state, v, now)
|
return view(state, v, now)
|
||||||
|
|
@ -1340,7 +1361,7 @@ const handlers: Record<string, Handler> = {
|
||||||
if (missingRequirements(v, unit).length) fail('requires')
|
if (missingRequirements(v, unit).length) fail('requires')
|
||||||
if (count * entry.upkeep > villagers(v) - militia(v)) fail('villagers')
|
if (count * entry.upkeep > villagers(v) - militia(v)) fail('villagers')
|
||||||
pay(v, mapCost(entry.cost, (n) => n * count))
|
pay(v, mapCost(entry.cost, (n) => n * count))
|
||||||
const seconds = secondsPerUnit(b, unit)
|
const seconds = secondsPerUnit(v, b, unit)
|
||||||
const last = (v.recruits ?? []).filter((o) => o.building_id === b.id).at(-1)
|
const last = (v.recruits ?? []).filter((o) => o.building_id === b.id).at(-1)
|
||||||
const starts = last && last.finishes_at > now ? last.finishes_at : now
|
const starts = last && last.finishes_at > now ? last.finishes_at : now
|
||||||
v.recruits = [
|
v.recruits = [
|
||||||
|
|
|
||||||
|
|
@ -539,9 +539,15 @@ export interface Building {
|
||||||
upgrade: Offer | null
|
upgrade: Offer | null
|
||||||
/** null when the building cannot go lower (core buildings at level 1); target level 0 removes it. */
|
/** null when the building cannot go lower (core buildings at level 1); target level 0 removes it. */
|
||||||
demolish: { target_level: number; refund: Cost; seconds: number } | null
|
demolish: { target_level: number; refund: Cost; seconds: number } | null
|
||||||
/** What one instance does at its level, and one level up (null at max level). */
|
/** What one instance does at its level, and one level up (null at max level); a copy's come scaled by `instance_share`. */
|
||||||
effects: BuildingEffect[]
|
effects: BuildingEffect[]
|
||||||
next_effects: BuildingEffect[] | null
|
next_effects: BuildingEffect[] | null
|
||||||
|
/**
|
||||||
|
* Share of full output this instance works at (production, capacity, hides, beds, training
|
||||||
|
* speed): 1 for the only or first instance of its type, then 0.5, 0.25, … for the copies,
|
||||||
|
* ranked by level. Copies cost more too; the server's costs include it.
|
||||||
|
*/
|
||||||
|
instance_share: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/** One line of what a building does: production at full staffing (per hour), percentages as whole numbers. */
|
/** One line of what a building does: production at full staffing (per hour), percentages as whole numbers. */
|
||||||
|
|
@ -564,6 +570,8 @@ export interface BuildOption extends Offer {
|
||||||
space: number
|
space: number
|
||||||
/** Requirements no building meets yet; only advanced buildings have any. */
|
/** Requirements no building meets yet; only advanced buildings have any. */
|
||||||
requires: { type: BuildingType; level: number }[]
|
requires: { type: BuildingType; level: number }[]
|
||||||
|
/** Share the new instance would work at: 1 for the first of its type, below 1 for a copy (whose `cost` is already raised). */
|
||||||
|
instance_share: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BuildOrder {
|
export interface BuildOrder {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
// Building copies: the server sends each instance's `instance_share` (1 for the first of a
|
||||||
|
// type, 0.5, 0.25, … for the copies); the client only shows it as a percentage.
|
||||||
|
|
||||||
|
/** A copy works below full output. Missing shares (older servers) count as full. */
|
||||||
|
export const isCopy = (share: number | undefined) => share !== undefined && share < 1
|
||||||
|
|
||||||
|
/** 0.5 → 50, 0.125 → 12.5. */
|
||||||
|
export const sharePercent = (share: number) => Math.round(share * 1000) / 10
|
||||||
|
|
@ -15,7 +15,7 @@ export function demoVillage(): VillageState {
|
||||||
]
|
]
|
||||||
const buildings = levels.map(([type, level], i): Building => ({
|
const buildings = levels.map(([type, level], i): Building => ({
|
||||||
id: i + 1, type, level, space: SPACE[type] ?? 4, priority: 5,
|
id: i + 1, type, level, space: SPACE[type] ?? 4, priority: 5,
|
||||||
workers: { assigned: 4, required: 4 }, staffing: 1, production: null, upgrade: null, demolish: null, effects: [], next_effects: null,
|
workers: { assigned: 4, required: 4 }, staffing: 1, production: null, upgrade: null, demolish: null, effects: [], next_effects: null, instance_share: 1,
|
||||||
}))
|
}))
|
||||||
return {
|
return {
|
||||||
id: 0, points: 2400, buildings, queue: [], troops: { spear: 160, sword: 90, light_cavalry: 30 },
|
id: 0, points: 2400, buildings, queue: [], troops: { spear: 160, sword: 90, light_cavalry: 30 },
|
||||||
|
|
|
||||||
|
|
@ -337,6 +337,12 @@ export default {
|
||||||
free_space: '{free} space free',
|
free_space: '{free} space free',
|
||||||
submit: 'Build',
|
submit: 'Build',
|
||||||
},
|
},
|
||||||
|
copy: {
|
||||||
|
share: 'works at {share}%',
|
||||||
|
this: 'Copy: works at {share}%',
|
||||||
|
new: 'New copy: works at {share}%, costs more',
|
||||||
|
offer: 'This copy would work at {share}% and cost more than the first.',
|
||||||
|
},
|
||||||
queue: {
|
queue: {
|
||||||
title: 'Build queue',
|
title: 'Build queue',
|
||||||
builders: 'Builders: {count}',
|
builders: 'Builders: {count}',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue