diff --git a/app/Game/Buildings/BuildingRules.php b/app/Game/Buildings/BuildingRules.php index 74ded9a..8c93c7e 100644 --- a/app/Game/Buildings/BuildingRules.php +++ b/app/Game/Buildings/BuildingRules.php @@ -7,6 +7,7 @@ use App\Game\WorldConfig; /** * Cost, time, workers, output and capacity of a building type per level. Levels start * at 1: level 1 has the base values, and every level above multiplies by the factor. + * Build time is the exception: it takes a factor per level from a table (buildSeconds). */ final class BuildingRules { @@ -36,18 +37,61 @@ final class BuildingRules } /** - * Seconds to build $level, at world speed, sped up by the headquarters' level - * and slowed by its staffing (output factor 0..1). + * Seconds to build $level, Die Stämme's way: max(min, base × factor(level) × + * hq_factor^−HQ level), divided by world speed and by the headquarters' staffing + * (output factor 0..1), so an understaffed headquarters is slower at every level. */ public function buildSeconds(string $type, int $level, int $hqLevel, float $hqStaffing): int { - $time = $this->config->building($type)['build_time']; - $seconds = $time['base'] * $time['factor'] ** self::above($level) - / $this->config->speed() - / (1 + $this->config->get('economy.hq_build_speed_per_level', 0) * self::above($hqLevel)) - / max($hqStaffing, 0.01); + $time = $this->buildTime($type); + $work = $time['base'] * $this->timeFactor($type, $level) / $this->hqSpeedUp($hqLevel); + $seconds = max($time['min'], $work) / $this->config->speed() / max($hqStaffing, 0.01); - return max(1, (int) ceil($seconds)); + return max(1, (int) round($seconds)); + } + + /** + * The per-level build time factor: the type's own `factors` or economy.build_time's, + * indexed from level 1. Levels past the table's end grow by the ratio of its last two + * entries, so a level never lacks a time (lint wants the table to cover max_level). + */ + public function timeFactor(string $type, int $level): float + { + $factors = $this->buildTime($type)['factors']; + $count = count($factors); + $level = max(1, $level); + if ($count === 0) { + return 1.0; + } + if ($level <= $count) { + return (float) $factors[$level - 1]; + } + $growth = $count > 1 && $factors[$count - 2] > 0 ? $factors[$count - 1] / $factors[$count - 2] : 1.0; + + return $factors[$count - 1] * $growth ** ($level - $count); + } + + /** How many times faster the headquarters at this level builds than none: hq_factor^level. */ + public function hqSpeedUp(int $hqLevel): float + { + return (float) $this->config->get('economy.build_time.hq_factor', 1.0) ** max(0, $hqLevel); + } + + /** + * A type's build time rules: its `base`, and its own `factors` and `min` where it has + * them, else economy.build_time's. + * + * @return array{base: float|int, factors: list, min: float|int} + */ + public function buildTime(string $type): array + { + $own = $this->config->building($type)['build_time']; + + return [ + 'base' => $own['base'], + 'factors' => array_values($own['factors'] ?? $this->config->get('economy.build_time.factors', [1.0])), + 'min' => $own['min'] ?? $this->config->get('economy.build_time.min', 1), + ]; } /** @@ -211,7 +255,8 @@ final class BuildingRules * What one instance does at a level, for the building's own screen: production at * full staffing, storage, hiding, beds, 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). A copy shows its output, storage, + * are the bonus over level 1 (over no wall, and for build speed over no headquarters: + * HQ 1 builds 5% faster, HQ 20 165%). A copy shows its output, storage, * hiding, beds and training speed at its $share (instanceShares), so its training * speed can fall below level 1's. * @@ -240,7 +285,7 @@ final class BuildingRules $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' => 'build_speed', 'value' => (int) round(($this->hqSpeedUp($level) - 1) * 100)]; $effects[] = ['key' => 'builders', 'value' => $this->builders($level)]; $effects[] = ['key' => 'space', 'value' => $this->spaceMax((int) $this->config->get('world.village.space'), $level)]; } diff --git a/app/Game/ConfigLint.php b/app/Game/ConfigLint.php index 61ec5f1..e5ffbfe 100644 --- a/app/Game/ConfigLint.php +++ b/app/Game/ConfigLint.php @@ -22,6 +22,7 @@ final class ConfigLint ...self::farmsFeedTheirWorkers($config, $rules), ...self::farmStaffsEverything($config, $rules), ...self::costsFitStorage($config, $rules), + ...self::buildTimesGrow($config, $rules), ...self::copiesPenalised($config), ...self::requirementsReachable($config, $rules), ...self::unitsTrainable($config, $rules), @@ -321,6 +322,47 @@ final class ConfigLint } /** A levy has to end and desertion waves have to come apart in time, or the village stays stuck. */ + /** + * Every level of every type has a build time factor, above 0 and never below the + * level before; no level builds in under a second; a bigger headquarters never builds + * slower. + */ + private static function buildTimesGrow(WorldConfig $config, BuildingRules $rules): array + { + $problems = []; + $mins = ['economy.build_time.min' => $config->get('economy.build_time.min', 1)]; + foreach ($config->buildingTypes() as $type) { + $own = $config->building($type)['build_time'] ?? []; + $key = isset($own['factors']) ? "$type.build_time.factors" : 'economy.build_time.factors'; + $factors = $rules->buildTime($type)['factors']; + if (count($factors) < $rules->maxLevel($type)) { + $problems[] = "[$key] lists ".count($factors)." levels, fewer than [$type]'s max level {$rules->maxLevel($type)}."; + } + if ($factors && min($factors) <= 0) { + $problems[] = "[$key] must be above 0 at every level."; + } + foreach (array_slice($factors, 1, null, true) as $i => $factor) { + if ($factor < $factors[$i - 1]) { + $problems[] = "[$key] falls at level ".($i + 1).', so a higher level would build faster.'; + break; + } + } + if (isset($own['min'])) { + $mins["$type.build_time.min"] = $own['min']; + } + } + foreach ($mins as $key => $min) { + if ($min < 1) { + $problems[] = "[$key] must be at least 1 second."; + } + } + if ($config->get('economy.build_time.hq_factor', 1) < 1) { + $problems[] = '[economy.build_time.hq_factor] must be at least 1, or a bigger headquarters builds slower.'; + } + + return array_values(array_unique($problems)); + } + private static function timersRun(WorldConfig $config): array { $problems = []; diff --git a/config/game/buildings.php b/config/game/buildings.php index 4f909aa..f99d06b 100644 --- a/config/game/buildings.php +++ b/config/game/buildings.php @@ -2,10 +2,14 @@ // Values per building type. Levels start at 1, which has the base values. // `space` is how much of the village's building space an instance takes, at any level. -// Level n: cost = cost × factor^(n−1), build time = base × factor^(n−1) seconds at world -// speed 1, workers = round(base × factor^(n−1)), and production, capacity, hides, -// detection and beds = base × factor^(n−1). A new instance or level is only queued when -// idle villagers stand ready for the workers it adds; farms are exempt. +// Level n: cost = cost × factor^(n−1), workers = round(base × factor^(n−1)), and +// production, capacity, hides, detection and beds = base × factor^(n−1). A new instance or +// level is only queued when idle villagers stand ready for the workers it adds; farms are +// exempt. +// Build time follows Die Stämme (economy.build_time): `base` seconds at world speed 1 times +// a per-level factor, sped up by the headquarters, never under `min`. The bases are Die +// Stämme's; a building that differs there brings its own `min` (wall, watchtower) or +// `factors` (academy) here. // One instance of a type is enough; copies are the exception. The instance at rank n // (0-based, by level, highest first) costs instance_cost_factor^n times as much, and // copies work at a falling share (economy.instance_share). @@ -17,7 +21,7 @@ return [ 'max_per_village' => 1, 'max_level' => 30, 'cost' => ['wood' => 90, 'clay' => 80, 'iron' => 70, 'factor' => 1.26], - 'build_time' => ['base' => 120, 'factor' => 1.2], + 'build_time' => ['base' => 900], 'workers' => ['base' => 2, 'factor' => 1.1], 'production' => null, 'instance_cost_factor' => 1.0, @@ -29,7 +33,7 @@ return [ 'max_per_village' => null, 'max_level' => 30, 'cost' => ['wood' => 60, 'clay' => 50, 'iron' => 40, 'factor' => 1.27], - 'build_time' => ['base' => 100, 'factor' => 1.2], + 'build_time' => ['base' => 1020], 'workers' => ['base' => 1, 'factor' => 1.1], 'production' => null, 'capacity' => ['base' => 1000, 'factor' => 1.23], @@ -42,7 +46,7 @@ return [ 'max_per_village' => null, 'max_level' => 30, 'cost' => ['wood' => 45, 'clay' => 40, 'iron' => 30, 'factor' => 1.27], - 'build_time' => ['base' => 120, 'factor' => 1.2], + 'build_time' => ['base' => 1200], 'workers' => ['base' => 2, 'factor' => 1.1], 'production' => ['resource' => 'food', 'base' => 30, 'factor' => 1.25], 'instance_cost_factor' => 2.0, @@ -54,7 +58,7 @@ return [ 'max_per_village' => null, 'max_level' => 30, 'cost' => ['wood' => 50, 'clay' => 60, 'iron' => 40, 'factor' => 1.25], - 'build_time' => ['base' => 90, 'factor' => 1.2], + 'build_time' => ['base' => 900], 'workers' => ['base' => 2, 'factor' => 1.12], 'production' => ['resource' => 'wood', 'base' => 30, 'factor' => 1.163], 'instance_cost_factor' => 2.0, @@ -66,7 +70,7 @@ return [ 'max_per_village' => null, 'max_level' => 30, 'cost' => ['wood' => 65, 'clay' => 50, 'iron' => 40, 'factor' => 1.27], - 'build_time' => ['base' => 90, 'factor' => 1.2], + 'build_time' => ['base' => 900], 'workers' => ['base' => 2, 'factor' => 1.12], 'production' => ['resource' => 'clay', 'base' => 30, 'factor' => 1.163], 'instance_cost_factor' => 2.0, @@ -78,7 +82,7 @@ return [ 'max_per_village' => null, 'max_level' => 30, 'cost' => ['wood' => 75, 'clay' => 65, 'iron' => 70, 'factor' => 1.252], - 'build_time' => ['base' => 110, 'factor' => 1.2], + 'build_time' => ['base' => 1080], 'workers' => ['base' => 2, 'factor' => 1.12], 'production' => ['resource' => 'iron', 'base' => 30, 'factor' => 1.163], 'instance_cost_factor' => 2.0, @@ -90,7 +94,7 @@ return [ 'max_per_village' => null, 'max_level' => 10, 'cost' => ['wood' => 50, 'clay' => 60, 'iron' => 50, 'factor' => 1.25], - 'build_time' => ['base' => 60, 'factor' => 1.2], + 'build_time' => ['base' => 1800], 'workers' => ['base' => 0, 'factor' => 1.0], 'production' => null, // Wood, clay and iron each that raiders can't take; instances add up. @@ -105,7 +109,7 @@ return [ 'max_per_village' => 1, 'max_level' => 20, 'cost' => ['wood' => 50, 'clay' => 100, 'iron' => 20, 'factor' => 1.26], - 'build_time' => ['base' => 300, 'factor' => 1.2], + 'build_time' => ['base' => 3600, 'min' => 240], 'workers' => ['base' => 1, 'factor' => 1.1], 'production' => null, 'instance_cost_factor' => 1.0, @@ -117,7 +121,7 @@ return [ 'max_per_village' => 1, 'max_level' => 1, 'cost' => ['wood' => 10, 'clay' => 40, 'iron' => 30, 'factor' => 1.26], - 'build_time' => ['base' => 60, 'factor' => 1.2], + 'build_time' => ['base' => 10860], 'workers' => ['base' => 0, 'factor' => 1.0], 'production' => null, 'instance_cost_factor' => 1.0, @@ -130,7 +134,7 @@ return [ 'max_per_village' => 1, 'max_level' => 20, 'cost' => ['wood' => 12000, 'clay' => 14000, 'iron' => 10000, 'factor' => 1.17], - 'build_time' => ['base' => 6000, 'factor' => 1.2], + 'build_time' => ['base' => 13200, 'min' => 30], 'workers' => ['base' => 1, 'factor' => 1.1], 'production' => null, 'detection' => ['base' => 1.1, 'factor' => 1.162], @@ -146,7 +150,7 @@ return [ 'max_per_village' => null, 'max_level' => 25, 'cost' => ['wood' => 200, 'clay' => 170, 'iron' => 90, 'factor' => 1.26], - 'build_time' => ['base' => 600, 'factor' => 1.2], + 'build_time' => ['base' => 1800], 'workers' => ['base' => 3, 'factor' => 1.1], 'production' => null, 'instance_cost_factor' => 2.0, @@ -158,7 +162,7 @@ return [ 'max_per_village' => null, 'max_level' => 20, 'cost' => ['wood' => 270, 'clay' => 240, 'iron' => 260, 'factor' => 1.26], - 'build_time' => ['base' => 1200, 'factor' => 1.2], + 'build_time' => ['base' => 6000], 'workers' => ['base' => 3, 'factor' => 1.1], 'production' => null, 'instance_cost_factor' => 2.0, @@ -170,7 +174,7 @@ return [ 'max_per_village' => null, 'max_level' => 15, 'cost' => ['wood' => 300, 'clay' => 240, 'iron' => 260, 'factor' => 1.26], - 'build_time' => ['base' => 1800, 'factor' => 1.2], + 'build_time' => ['base' => 6000], 'workers' => ['base' => 4, 'factor' => 1.1], 'production' => null, 'instance_cost_factor' => 2.0, @@ -178,12 +182,14 @@ return [ 'requires' => ['barracks' => 5], ], // The Adelshof: trains noblemen. The one advanced building with real requirements. + // Die Stämme's has one level at base 586800 and the table's 0.0075; levels 2 and 3 are + // ours and take 1.5 times the level before. 'academy' => [ 'space' => 9, 'max_per_village' => 1, 'max_level' => 3, 'cost' => ['wood' => 15000, 'clay' => 25000, 'iron' => 10000, 'factor' => 2.0], - 'build_time' => ['base' => 5400, 'factor' => 1.5], + 'build_time' => ['base' => 586800, 'factors' => [0.0075, 0.01125, 0.016875]], 'workers' => ['base' => 5, 'factor' => 1.2], 'production' => null, 'instance_cost_factor' => 1.0, @@ -192,13 +198,14 @@ return [ ], // The Lazarett: a share of the own troops who fall defending the village come back // wounded into its beds and heal after a while (combat.hospital). A bed holds one - // wounded; beds add up over instances and shrink with staffing like production. + // wounded; beds add up over instances and shrink with staffing like production. Die + // Stämme has none: it builds at the barracks' pace. 'hospital' => [ 'space' => 4, 'max_per_village' => null, 'max_level' => 20, 'cost' => ['wood' => 160, 'clay' => 200, 'iron' => 120, 'factor' => 1.26], - 'build_time' => ['base' => 900, 'factor' => 1.2], + 'build_time' => ['base' => 1800], 'workers' => ['base' => 2, 'factor' => 1.1], 'production' => null, 'beds' => ['base' => 20, 'factor' => 1.2], @@ -213,7 +220,7 @@ return [ 'max_per_village' => 1, 'max_level' => 25, 'cost' => ['wood' => 100, 'clay' => 100, 'iron' => 100, 'factor' => 1.26], - 'build_time' => ['base' => 2700, 'factor' => 1.2], + 'build_time' => ['base' => 2700], 'workers' => ['base' => 1, 'factor' => 1.1], 'production' => null, 'merchants' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 19, 26, 35, 46, 59, 74, 91, 110, 131, 154, 179, 206, 235], diff --git a/config/game/economy.php b/config/game/economy.php index f1962eb..5e7193a 100644 --- a/config/game/economy.php +++ b/config/game/economy.php @@ -26,8 +26,25 @@ return [ 'demolish_refund' => 0.5, 'demolish_time_factor' => 0.5, - // Each headquarters level makes building this much faster (time / (1 + x·level)). - 'hq_build_speed_per_level' => 0.05, + // Build time of a level, Die Stämme's formula: max(min, base × factors[level] × + // hq_factor^−HQ level) seconds at world speed 1, divided by world speed and by the + // headquarters' staffing. `base` is per building (buildings.php); a building may bring + // its own `factors` or `min` there. + 'build_time' => [ + // One multiplier per level from 1: Die Stämme's table, levels 1 and 2 as its game + // pages show them in 2026 (pace.md in the research repo). Levels past the end grow + // by the ratio of the last two entries; lint wants one entry per level up to every + // type's max_level. + 'factors' => [ + 0.0075, 0.0075, 0.161516, 0.500291, 0.956687, 1.50819, 2.15872, 2.92402, 3.82642, 4.89346, + 6.15818, 7.65953, 9.44382, 11.5653, 14.0884, 17.0893, 20.6581, 24.9012, 29.9451, 35.9388, + 43.0592, 51.5155, 61.5554, 73.4716, 87.6114, 104.384, 124.276, 147.861, 175.818, 208.951, + ], + // Each headquarters level divides build time by this: HQ 20 builds in 0.377 of the time. + 'hq_factor' => 1.05, + // No level builds faster than this many seconds at world speed 1. + 'min' => 10, + ], // Each level of a military building makes training there this much faster. 'recruit_speed_per_level' => 0.05, diff --git a/tests/Feature/BuildQueueTest.php b/tests/Feature/BuildQueueTest.php index 3a16930..e810136 100644 --- a/tests/Feature/BuildQueueTest.php +++ b/tests/Feature/BuildQueueTest.php @@ -30,10 +30,11 @@ it('pays up front, reserves the space and finishes on time', function () { ->and($state['space'])->toBe(['used' => 21, 'max' => 40]) ->and($state['queue'][0])->toMatchArray([ 'type' => 'timber_camp', 'action' => 'build', 'space' => 4, 'builder' => 1, - 'starts_at' => '2026-10-28T12:00:00.000Z', 'finishes_at' => '2026-10-28T12:01:30.000Z', + 'starts_at' => '2026-10-28T12:00:00.000Z', 'finishes_at' => '2026-10-28T12:00:10.000Z', ]); - $this->travel(89)->seconds(); + // 900 × 0.0075 ÷ 1.05 is 6 s, under the 10 s floor. + $this->travel(9)->seconds(); expect(shown($village)['buildings'])->toHaveCount(3); $this->travel(1)->seconds(); @@ -96,16 +97,16 @@ it('keeps a third order waiting and starts it when a builder frees up', function $village = startVillage(); $user = owner($village); - app(QueueBuild::class)($user, $village->id, 'timber_camp'); // 90 s - app(QueueBuild::class)($user, $village->id, 'hiding_place'); // 60 s - app(QueueBuild::class)($user, $village->id, 'rally_point'); // 60 s, waits + app(QueueBuild::class)($user, $village->id, 'timber_camp'); // 10 s, the floor + app(QueueBuild::class)($user, $village->id, 'hiding_place'); // 1800 × 0.0075 ÷ 1.05: 13 s + app(QueueBuild::class)($user, $village->id, 'rally_point'); // 10860 × 0.0075 ÷ 1.05: 78 s, waits expect(collect(shown($village)['queue'])->pluck('builder')->all())->toBe([1, 2, null]); - // Caught up long after: the rally point started when the hiding place finished. + // Caught up long after: the rally point started when the timber camp finished. $this->travel(10)->minutes(); expect(shown($village)['queue'])->toBe([]) ->and(GameEvent::where('type', GameEvent::BUILD_ORDER_FINISHED)->orderBy('id')->pluck('fire_at')->map->format('H:i:s')->all()) - ->toBe(['12:01:30', '12:01:00', '12:02:00']); + ->toBe(['12:00:10', '12:00:13', '12:01:28']); }); it('queues upgrades of one building one after another', function () { @@ -122,8 +123,12 @@ it('queues upgrades of one building one after another', function () { ->and(collect($state['buildings'])->firstWhere('type', 'headquarters')['upgrade']['target_level'])->toBe(4) ->and($state['resources']['wood'])->toBe(500.0 - 113 - 143); - // HQ 2 takes 144 s; HQ 3 then builds with HQ 2's speed-up: 172.8 / 1.05 → 165 s. - $this->travel(144 + 165)->seconds(); + // HQ 2 takes the 10 s floor; HQ 3 then builds with HQ 2's speed-up: 900 × 0.161516 ÷ 1.05² → 132 s. + $this->travel(10)->seconds(); + expect(collect(shown($village)['buildings'])->firstWhere('type', 'headquarters')['level'])->toBe(2); + $this->travel(131)->seconds(); + expect(collect(shown($village)['buildings'])->firstWhere('type', 'headquarters')['level'])->toBe(2); + $this->travel(1)->seconds(); expect(collect(shown($village)['buildings'])->firstWhere('type', 'headquarters')['level'])->toBe(3); }); @@ -144,17 +149,20 @@ it('cancels an order, the orders that build on it, and refunds them in full', fu it('demolishes with a refund on finish and removes a building taken down from level 1', function () { $village = startVillage(); app(QueueBuild::class)(owner($village), $village->id, 'timber_camp'); - $this->travel(90)->seconds(); + $this->travel(10)->seconds(); $camp = collect(shown($village)['buildings'])->firstWhere('type', 'timber_camp'); app(QueueDemolish::class)(owner($village), $village->id, $camp['id']); expect(shown($village)['queue'][0])->toMatchArray(['action' => 'demolish', 'target_level' => 0]); + // Half the 10 s build time. $woodBefore = shown($village)['resources']['wood']; - $this->travel(45)->seconds(); + $this->travel(4)->seconds(); + expect(collect(shown($village)['buildings'])->firstWhere('type', 'timber_camp'))->not->toBeNull(); + $this->travel(1)->seconds(); $state = shown($village); expect(collect($state['buildings'])->firstWhere('type', 'timber_camp'))->toBeNull() - ->and($state['resources']['wood'])->toEqualWithDelta($woodBefore + 25 + 35 * 45 / 3600, 0.01); + ->and($state['resources']['wood'])->toEqualWithDelta($woodBefore + 25 + 35 * 5 / 3600, 0.01); }); it('keeps core buildings at level 1', function () { diff --git a/tests/Unit/Game/BuildingRulesTest.php b/tests/Unit/Game/BuildingRulesTest.php index ff0752a..bd7ed7e 100644 --- a/tests/Unit/Game/BuildingRulesTest.php +++ b/tests/Unit/Game/BuildingRulesTest.php @@ -51,21 +51,78 @@ it('gives every instance its full share when the world turns copies off', functi expect($rules->instanceShares([building(1, 'iron_mine'), building(2, 'iron_mine')]))->toEqual([1 => 1.0, 2 => 1.0]); }); -it('divides build time by world speed, headquarters level and staffing', function () { +it('builds as fast as Die Stämme, with the headquarters at the same level', function () { $rules = new BuildingRules(gameConfig()); + $time = fn (string $type, int $level, ?int $hq = null) => $rules->buildSeconds($type, $level, $hq ?? $level, 1.0); + + // Die Stämme at world speed 1 (pace.md): timber camp 0:10, 0:10, 2:06, 11:15, 45:04, + // 3:23:10 and 12:05:12; the headquarters 2:12, 11:48 and 47:19 built from the level below. + expect([$time('timber_camp', 1), $time('timber_camp', 2), $time('timber_camp', 3), $time('timber_camp', 5), $time('timber_camp', 10)]) + ->toBe([10, 10, 126, 675, 2704]) + ->and($time('timber_camp', 20))->toBe(3 * 3600 + 23 * 60 + 10) + ->and($time('timber_camp', 30))->toBe(12 * 3600 + 5 * 60 + 12) + ->and([$time('headquarters', 3, 2), $time('headquarters', 5, 4), $time('headquarters', 10, 9)])->toBe([132, 708, 2839]) + // Barracks 0:13, 0:12, 4:11; farm 2:47; iron mine 13:30; market 33:44. + ->and([$time('barracks', 1), $time('barracks', 2), $time('barracks', 3)])->toBe([13, 12, 251]) + ->and([$time('farm', 3), $time('iron_mine', 5), $time('market', 5)])->toBe([167, 810, 2024]); +}); + +it('never builds faster than the floor, 30 s for the watchtower and 240 s for the wall', function () { + $rules = new BuildingRules(gameConfig()); + + expect($rules->buildSeconds('timber_camp', 1, 1, 1.0))->toBe(10) + ->and($rules->buildSeconds('wall', 1, 1, 1.0))->toBe(240) + ->and($rules->buildSeconds('wall', 2, 20, 1.0))->toBe(240) + // 13200 × 0.0075 ÷ 1.05^20 is 37 s, ÷ 1.05^30 below 30. + ->and($rules->buildSeconds('watchtower', 1, 20, 1.0))->toBe(37) + ->and($rules->buildSeconds('watchtower', 1, 30, 1.0))->toBe(30) + ->and($rules->buildSeconds('wall', 4, 4, 1.0))->toBe(1482); +}); + +it('speeds building up by 1.05 per headquarters level', function () { + $rules = new BuildingRules(gameConfig()); + $flat = new BuildingRules(gameConfig(['economy' => ['build_time' => ['hq_factor' => 1.0]]])); + + // Timber camp 10: 900 × 4.89346 = 4404 s without a headquarters. + expect($rules->buildSeconds('timber_camp', 10, 0, 1.0))->toBe(4404) + ->and($rules->buildSeconds('timber_camp', 10, 1, 1.0))->toBe(4194) + ->and($rules->buildSeconds('timber_camp', 10, 20, 1.0))->toBe((int) round(4404.1153 / 1.05 ** 20)) + ->and($flat->buildSeconds('timber_camp', 10, 20, 1.0))->toBe(4404) + ->and($rules->hqSpeedUp(20))->toEqualWithDelta(2.6533, 0.0001); +}); + +it('divides build time by world speed and the headquarters staffing', function () { + $rules = new BuildingRules(gameConfig()); + $w1 = new BuildingRules(gameConfig(['world' => ['speed' => 4]])); $fast = new BuildingRules(gameConfig(['world' => ['speed' => 100]])); - expect($rules->buildSeconds('timber_camp', 1, 1, 1.0))->toBe(90) - ->and($rules->buildSeconds('timber_camp', 2, 1, 1.0))->toBe(108) - ->and($rules->buildSeconds('timber_camp', 1, 11, 1.0))->toBe(60) - ->and($rules->buildSeconds('timber_camp', 1, 1, 0.5))->toBe(180) + expect($rules->buildSeconds('timber_camp', 3, 3, 0.5))->toBe(251) + // The floor is slowed by staffing too: an understaffed headquarters is slower at every level. + ->and($rules->buildSeconds('timber_camp', 1, 1, 0.5))->toBe(20) + ->and($w1->buildSeconds('timber_camp', 3, 3, 1.0))->toBe(31) + ->and($w1->buildSeconds('timber_camp', 1, 1, 1.0))->toBe(3) + ->and($w1->buildSeconds('wall', 1, 1, 1.0))->toBe(60) ->and($fast->buildSeconds('timber_camp', 1, 1, 1.0))->toBe(1); }); +it('takes the academy from its own table, and grows past the end of a table', function () { + $rules = new BuildingRules(gameConfig()); + $high = new BuildingRules(gameConfig(['buildings' => ['timber_camp' => ['max_level' => 32]]])); + + // 586800 × 0.0075, × 1.5 per level after. + expect($rules->buildSeconds('academy', 1, 0, 1.0))->toBe(4401) + ->and($rules->buildSeconds('academy', 2, 0, 1.0))->toBe(6602) + ->and($rules->buildSeconds('academy', 3, 0, 1.0))->toBe(9902) + ->and($rules->timeFactor('timber_camp', 30))->toBe(208.951) + ->and($high->timeFactor('timber_camp', 31))->toEqualWithDelta(208.951 ** 2 / 175.818, 0.0001) + ->and($high->timeFactor('timber_camp', 32))->toEqualWithDelta(208.951 ** 3 / 175.818 ** 2, 0.0001); +}); + it('takes half the time and refunds half the cost when demolishing', function () { $rules = new BuildingRules(gameConfig()); - expect($rules->demolishSeconds('timber_camp', 2, 1, 1.0))->toBe(54) + expect($rules->demolishSeconds('timber_camp', 3, 3, 1.0))->toBe(63) + ->and($rules->demolishSeconds('timber_camp', 1, 1, 1.0))->toBe(5) ->and($rules->demolishRefund('timber_camp', 0))->toBe(['wood' => 25, 'clay' => 30, 'iron' => 20]); }); @@ -130,7 +187,7 @@ it('lists what an instance does at a level', function () { ->and($rules->effects('hiding_place', 1))->toBe([['key' => 'hides', 'value' => 150]]) ->and($rules->effects('hospital', 2))->toBe([['key' => 'beds', 'value' => 24]]) ->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' => 50]]) + ->and($rules->effects('headquarters', 3))->toBe([['key' => 'build_speed', 'value' => 16], ['key' => 'builders', 'value' => 2], ['key' => 'space', 'value' => 50]]) ->and($rules->effects('barracks', 6))->toBe([['key' => 'recruit_speed', 'value' => 25]]) ->and($rules->effects('rally_point', 1))->toBe([]); }); diff --git a/tests/Unit/Game/ConfigLintTest.php b/tests/Unit/Game/ConfigLintTest.php index 2019bcb..67cc9fc 100644 --- a/tests/Unit/Game/ConfigLintTest.php +++ b/tests/Unit/Game/ConfigLintTest.php @@ -77,6 +77,35 @@ it('reports a levy or desertion timer that never runs out', function () { ]); }); +it('finds no locks in World 1 at speed 4 with armies at half speed', function () { + expect(ConfigLint::check(gameConfig(['world' => ['speed' => 4], 'movement' => ['unit_speed' => 0.5]])))->toBe([]); +}); + +it('reports build time factors that miss a level, reach 0, or fall', function () { + $lint = fn (array $overrides) => ConfigLint::check(gameConfig($overrides)); + + expect($lint(['buildings' => ['hiding_place' => ['max_level' => 31]]])) + ->toContain("[economy.build_time.factors] lists 30 levels, fewer than [hiding_place]'s max level 31.") + ->and($lint(['economy' => ['build_time' => ['factors' => [0]]]]))->toBe(['[economy.build_time.factors] must be above 0 at every level.']) + ->and($lint(['buildings' => ['academy' => ['build_time' => ['factors' => [0.0075, 0.005, 0.01]]]]])) + ->toBe(['[academy.build_time.factors] falls at level 2, so a higher level would build faster.']) + ->and($lint(['buildings' => ['academy' => ['max_level' => 4]]])) + ->toContain("[academy.build_time.factors] lists 3 levels, fewer than [academy]'s max level 4."); +}); + +it('reports a build time floor under a second and a headquarters that slows building', function () { + $config = gameConfig([ + 'economy' => ['build_time' => ['min' => 0, 'hq_factor' => 0.95]], + 'buildings' => ['wall' => ['build_time' => ['min' => 0.5]]], + ]); + + expect(ConfigLint::check($config))->toBe([ + '[economy.build_time.min] must be at least 1 second.', + '[wall.build_time.min] must be at least 1 second.', + '[economy.build_time.hq_factor] must be at least 1, or a bigger headquarters builds slower.', + ]); +}); + it('reports copies that work for nothing, above full, or get cheaper', function () { $lint = fn (array $overrides) => ConfigLint::check(gameConfig($overrides));