+ {{ $t('village.copy.offer', { share: sharePercent(option.instance_share) }) }}
+
diff --git a/app/mock/catalog.ts b/app/mock/catalog.ts
index a01208d..1d06a44 100644
--- a/app/mock/catalog.ts
+++ b/app/mock/catalog.ts
@@ -98,3 +98,6 @@ export const DETECTION = 2
export const CANCEL_WINDOW = 600
/** Wood, clay and iron each in every barbarian village; it never runs out. */
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
diff --git a/app/mock/server.ts b/app/mock/server.ts
index 75cb21e..69e0c24 100644
--- a/app/mock/server.ts
+++ b/app/mock/server.ts
@@ -51,6 +51,7 @@ import {
BUILDING_TYPES,
CANCEL_WINDOW,
CATALOG,
+ COPY_SHARE,
DEFAULT_MODE,
DEFAULT_PRIORITY,
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 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) {
return v.buildings
.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. */
@@ -297,17 +316,17 @@ const staffing = (b: MockBuilding, assigned: Map) => {
/** Linear stand-in for the real staffing curve: empty buildings still make 10%. */
const outputFactor = (ratio: number) => 0.1 + 0.9 * ratio
-function production(b: MockBuilding, assigned: Map) {
+function production(v: MockVillage, b: MockBuilding, assigned: Map) {
const prod = CATALOG[b.type].production
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 {
const assigned = assignWorkers(v)
const r: Resources = { wood: BASE_TRICKLE, clay: BASE_TRICKLE, iron: BASE_TRICKLE, food: 0 }
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
}
r.food -= villagers(v) * VILLAGER_UPKEEP + soldierUpkeep(v)
@@ -317,7 +336,7 @@ function rates(v: MockVillage): Resources {
function storageCap(v: MockVillage) {
return v.buildings
.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. */
@@ -421,7 +440,7 @@ function upgradeOffer(v: MockVillage, b: MockBuilding): Offer | null {
const current = queuedLevel(v, b)
if (current < 1 || current >= MAX_LEVEL) return null
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 }
}
@@ -438,14 +457,14 @@ function demolishOffer(v: MockVillage, b: MockBuilding) {
function buildOptions(v: MockVillage): BuildOption[] {
return BUILDING_TYPES.map((type) => {
const entry = CATALOG[type]
- const cost = levelCost(type, 1)
+ const { cost, share } = newInstance(v, type)
const blocked =
entry.max_per_village !== null && instances(v, type) >= entry.max_per_village
? 'max_per_village'
: !spaceFits(v, type)
? 'no_space'
: 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 }))
}
-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[] {
const pop = villagers(v) - militia(v)
@@ -530,7 +550,7 @@ function military(v: MockVillage, at: number): MilitaryBuilding[] {
return {
unit,
cost,
- seconds: secondsPerUnit(b, unit),
+ seconds: secondsPerUnit(v, b, unit),
upkeep,
max: requires.length ? 0 : Math.max(0, Math.min(byResources, Math.floor(pop / upkeep))),
blocked: requires.length ? ('requires' as const) : null,
@@ -647,7 +667,7 @@ function view(state: MockState, v: MockVillage, now: number): VillageState {
builders: BUILDERS,
buildings: v.buildings.map(
(b): Building => {
- const p = production(b, assigned)
+ const p = production(v, b, assigned)
return {
id: b.id,
type: b.type,
@@ -662,6 +682,7 @@ function view(state: MockState, v: MockVillage, now: number): VillageState {
// Placeholder: production only; the backend lists every effect.
effects: p ? [{ key: 'production', value: round(p.per_hour), resource: p.resource }] : [],
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) {
const wounded = (v.wounded ?? []).filter((w) => w.heals_at > Date.now())
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),
share: 0.5,
heal_seconds: 14400,
@@ -1285,7 +1306,7 @@ const handlers: Record = {
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 (!spaceFits(v, type)) fail('no_space')
- const cost = levelCost(type, 1)
+ const { cost } = newInstance(v, type)
pay(v, cost)
enqueue(state, v, { building_id: null, type, action: 'build', target_level: 1, cost, seconds: levelSeconds(type, 1) }, now)
return view(state, v, now)
@@ -1340,7 +1361,7 @@ const handlers: Record = {
if (missingRequirements(v, unit).length) fail('requires')
if (count * entry.upkeep > villagers(v) - militia(v)) fail('villagers')
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 starts = last && last.finishes_at > now ? last.finishes_at : now
v.recruits = [
diff --git a/app/types/game.ts b/app/types/game.ts
index 670760e..1f19c9b 100644
--- a/app/types/game.ts
+++ b/app/types/game.ts
@@ -539,9 +539,15 @@ export interface Building {
upgrade: Offer | null
/** 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
- /** 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[]
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. */
@@ -564,6 +570,8 @@ export interface BuildOption extends Offer {
space: number
/** Requirements no building meets yet; only advanced buildings have any. */
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 {
diff --git a/app/utils/copies.ts b/app/utils/copies.ts
new file mode 100644
index 0000000..5bb2786
--- /dev/null
+++ b/app/utils/copies.ts
@@ -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
diff --git a/app/utils/demoVillage.ts b/app/utils/demoVillage.ts
index dc54d3f..b501790 100644
--- a/app/utils/demoVillage.ts
+++ b/app/utils/demoVillage.ts
@@ -15,7 +15,7 @@ export function demoVillage(): VillageState {
]
const buildings = levels.map(([type, level], i): Building => ({
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 {
id: 0, points: 2400, buildings, queue: [], troops: { spear: 160, sword: 90, light_cavalry: 30 },
diff --git a/i18n/pages/village.ts b/i18n/pages/village.ts
index 816a95e..2a85e54 100644
--- a/i18n/pages/village.ts
+++ b/i18n/pages/village.ts
@@ -337,6 +337,12 @@ export default {
free_space: '{free} space free',
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: {
title: 'Build queue',
builders: 'Builders: {count}',