From 12586f853dfe7b2888d50f16d313ede43f8b0037 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Thu, 29 Oct 2026 14:32:19 +0100 Subject: [PATCH] feat: every building tells what it does at its level and the next one Co-Authored-By: Claude Opus 5.5 (1M context) --- app/Game/Buildings/BuildingRules.php | 40 +++++++++++++++++++++++++++ app/Presenters/VillagePresenter.php | 3 ++ docs/architecture.md | 1 + tests/Unit/Game/BuildingRulesTest.php | 12 ++++++++ 4 files changed, 56 insertions(+) diff --git a/app/Game/Buildings/BuildingRules.php b/app/Game/Buildings/BuildingRules.php index c550380..5d72326 100644 --- a/app/Game/Buildings/BuildingRules.php +++ b/app/Game/Buildings/BuildingRules.php @@ -115,6 +115,46 @@ final class BuildingRules return $detection ? $detection['base'] * $detection['factor'] ** self::above($level) : 0.0; } + /** + * What one instance does at a level, for the building's own screen: production at + * full staffing, storage, hiding, detection, the wall's defence, the headquarters' + * build speed, builders and space, a military building's training speed. Percentages + * are the bonus over level 1 (or over no wall). + * + * @return list + */ + public function effects(string $type, int $level): array + { + $effects = []; + if ($output = $this->output($type, $level)) { + $effects[] = ['key' => 'production', 'value' => round($output['per_hour'], 1), 'resource' => $output['resource']]; + } + foreach (['capacity', 'hides'] as $key) { + if ($value = $this->{$key}($type, $level)) { + $effects[] = ['key' => $key, 'value' => (int) round($value)]; + } + } + if ($detection = $this->detection($type, $level)) { + $effects[] = ['key' => 'detection', 'value' => round($detection, 1)]; + } + if ($type === 'wall') { + $wall = $this->config->get('combat.wall'); + $effects[] = ['key' => 'wall_defense', 'value' => $wall['basic_defense'] * $level]; + $effects[] = ['key' => 'wall_bonus', 'value' => (int) round(($wall['factor'] ** $level - 1) * 100)]; + } + if ($type === 'headquarters') { + $effects[] = ['key' => 'build_speed', 'value' => (int) round($this->config->get('economy.hq_build_speed_per_level', 0) * self::above($level) * 100)]; + $effects[] = ['key' => 'builders', 'value' => $this->builders($level)]; + $effects[] = ['key' => 'space', 'value' => $this->spaceMax((int) $this->config->get('world.village.space'), $level)]; + } + $trains = array_filter($this->config->get('units', []), fn (array $u) => ($u['building'] ?? null) === $type); + if ($trains) { + $effects[] = ['key' => 'recruit_speed', 'value' => (int) round($this->config->get('economy.recruit_speed_per_level', 0) * self::above($level) * 100)]; + } + + return $effects; + } + /** Points an instance at this level adds to its village. */ public function points(string $type, int $level): int { diff --git a/app/Presenters/VillagePresenter.php b/app/Presenters/VillagePresenter.php index ba32e29..fcfffe1 100644 --- a/app/Presenters/VillagePresenter.php +++ b/app/Presenters/VillagePresenter.php @@ -92,6 +92,9 @@ final class VillagePresenter 'workers' => ['assigned' => $workforce->assigned[$b->id] ?? 0, 'required' => $workforce->required[$b->id] ?? 0], 'staffing' => round($workforce->ratio($b->id), 4), 'production' => $output ? ['resource' => $output['resource'], 'per_hour' => round($output['per_hour'], 2)] : null, + // What it does at this level and would do one level up, for its own screen. + 'effects' => $rules->effects($b->type, $b->level), + 'next_effects' => $b->level < $rules->maxLevel($b->type) ? $rules->effects($b->type, $b->level + 1) : null, 'upgrade' => $sim->upgradeOffer($b), 'demolish' => $sim->demolishOffer($b), ]; diff --git a/docs/architecture.md b/docs/architecture.md index 8f02ad6..18bfb71 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -85,6 +85,7 @@ A wave takes the fewest units that make income cover upkeep again: support stati - Demolishing goes through the build queue. It lowers an instance by one level and refunds `demolish_refund` × that level's cost (default 0.5). Taking level 1 down removes the instance (an order with target level 0) and frees its space. - The wall takes 0 space: it surrounds the village. - Each building level is worth `points` (config); a village's points are their sum, kept on the row when an order finishes and shown on the map. +- Every building in the village payload carries `effects` and `next_effects` (`BuildingRules::effects`): what one instance does at its level and one level up, as `{key, value, resource?}`: production at full staffing, capacity, hides, detection, the wall's flat defence and bonus %, the headquarters' build speed %, builders and village space, a military building's training speed %. The client shows them on the building's own screen. A new village starts with HQ 0, storage 0, and farm 0, plus starting resources from world config. diff --git a/tests/Unit/Game/BuildingRulesTest.php b/tests/Unit/Game/BuildingRulesTest.php index eb62e6f..893ffc2 100644 --- a/tests/Unit/Game/BuildingRulesTest.php +++ b/tests/Unit/Game/BuildingRulesTest.php @@ -90,3 +90,15 @@ it('adds building space for every headquarters level', function () { ->and($rules->spaceMax(40, 2))->toBe(60) ->and($rules->spaceMax(40, 30))->toBe(620); }); + +it('lists what an instance does at a level', function () { + $rules = new BuildingRules(gameConfig()); + + expect($rules->effects('timber_camp', 1))->toBe([['key' => 'production', 'value' => 30.0, 'resource' => 'wood']]) + ->and($rules->effects('storage', 2))->toBe([['key' => 'capacity', 'value' => 1230]]) + ->and($rules->effects('hiding_place', 1))->toBe([['key' => 'hides', 'value' => 150]]) + ->and($rules->effects('wall', 3))->toBe([['key' => 'wall_defense', 'value' => 60], ['key' => 'wall_bonus', 'value' => 12]]) + ->and($rules->effects('headquarters', 3))->toBe([['key' => 'build_speed', 'value' => 10], ['key' => 'builders', 'value' => 2], ['key' => 'space', 'value' => 80]]) + ->and($rules->effects('barracks', 6))->toBe([['key' => 'recruit_speed', 'value' => 25]]) + ->and($rules->effects('rally_point', 1))->toBe([]); +});