diff --git a/app/components/village/BuildingHeader.vue b/app/components/village/BuildingHeader.vue index 357ec50..5d9a0c3 100644 --- a/app/components/village/BuildingHeader.vue +++ b/app/components/village/BuildingHeader.vue @@ -41,11 +41,12 @@ function value(e: BuildingEffect) { case 'production': return t('village.resources.per_hour', { rate: formatRate(e.value) }) case 'wall_defense': - return `+${e.value}` + return formatSigned(e.value) + // A copy's training speed can fall below a single building's: the sign comes from the value. case 'wall_bonus': case 'build_speed': case 'recruit_speed': - return `+${e.value}%` + return `${formatSigned(e.value)}%` case 'detection': return t('village.effects.fields', { n: e.value }) default: diff --git a/app/mock/server.ts b/app/mock/server.ts index 5bdeac4..f593aea 100644 --- a/app/mock/server.ts +++ b/app/mock/server.ts @@ -535,6 +535,12 @@ function missingRequirements(v: MockVillage, unit: UnitType) { .map(([type, level]) => ({ type: type as BuildingType, level: level ?? 0 })) } +const trains = (b: MockBuilding) => UNIT_TYPES.some((u) => UNITS[u].building === b.type) + +/** Training speed against a single level-1 building, in percent; a copy's can be negative. */ +const recruitSpeed = (v: MockVillage, b: MockBuilding, level: number) => + ({ key: 'recruit_speed', value: Math.round(((1 + 0.05 * Math.max(0, level - 1)) * instanceShare(v, b) - 1) * 100) }) as const + 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))) @@ -682,9 +688,9 @@ function view(state: MockState, v: MockVillage, now: number): VillageState { production: p ? { resource: p.resource, per_hour: round(p.per_hour) } : null, upgrade: upgradeOffer(v, b), demolish: demolishOffer(v, b), - // Placeholder: production only; the backend lists every effect. - effects: p ? [{ key: 'production', value: round(p.per_hour), resource: p.resource }] : [], - next_effects: null, + // Placeholder: production and training speed only; the backend lists every effect. + effects: p ? [{ key: 'production', value: round(p.per_hour), resource: p.resource }] : trains(b) ? [recruitSpeed(v, b, b.level)] : [], + next_effects: !p && trains(b) && b.level < MAX_LEVEL ? [recruitSpeed(v, b, b.level + 1)] : null, instance_share: instanceShare(v, b), } }, diff --git a/app/utils/buildingTags.ts b/app/utils/buildingTags.ts index e41a92a..c399361 100644 --- a/app/utils/buildingTags.ts +++ b/app/utils/buildingTags.ts @@ -133,7 +133,7 @@ export function buildingTag( case 'wall': return { icon: { kind: 'ui', name: 'support' }, - text: t('village.tags.percent', { value: effect('wall_bonus') }), + text: t('village.tags.percent', { value: formatSigned(effect('wall_bonus')) }), tone: 'plain', title: t('village.tags.wall', { bonus: effect('wall_bonus'), defense: effect('wall_defense') }), } diff --git a/app/utils/format.ts b/app/utils/format.ts index 515c9c4..42ae730 100644 --- a/app/utils/format.ts +++ b/app/utils/format.ts @@ -20,4 +20,7 @@ export const formatAmount = (n: number) => String(Math.floor(n)) /** 12.5 → "+12.5", -3 → "-3" */ export const formatRate = (n: number) => `${n >= 0 ? '+' : ''}${Math.round(n * 10) / 10}` +/** A bonus with its sign from the value: 20 → "+20", -50 → "−50", 0 → "0". */ +export const formatSigned = (n: number) => `${n > 0 ? '+' : n < 0 ? '−' : ''}${Math.abs(n)}` + export const formatCost = (cost: Cost) => `${cost.wood} / ${cost.clay} / ${cost.iron}` diff --git a/i18n/pages/village.ts b/i18n/pages/village.ts index c87c5ce..0905202 100644 --- a/i18n/pages/village.ts +++ b/i18n/pages/village.ts @@ -77,7 +77,7 @@ export default { troops: '{troops}', troops_attacked: '{troops} · {attacks} incoming', troops_title: '{own} own troops and {support} support in the village', - percent: '+{value}%', + percent: '{value}%', wall: 'Defenders fight {bonus}% harder, plus {defense} defence', hides: 'Hides {amount} of each resource from raiders', fields: '{fields} fields',