diff --git a/app/Game/ConfigLint.php b/app/Game/ConfigLint.php index faa8aa3..30eff36 100644 --- a/app/Game/ConfigLint.php +++ b/app/Game/ConfigLint.php @@ -21,6 +21,7 @@ final class ConfigLint ...self::foodCanBeStored($config), ...self::farmsFeedTheirWorkers($config, $rules), ...self::costsFitStorage($config, $rules), + ...self::copiesPenalised($config), ...self::requirementsReachable($config, $rules), ...self::unitsTrainable($config, $rules), ...self::timersRun($config), @@ -340,6 +341,26 @@ final class ConfigLint return $problems; } + /** + * A copy works at a share above 0 (or it gives nothing and trains never) and at most + * 1, and it never costs less than the instance before it. + */ + private static function copiesPenalised(WorldConfig $config): array + { + $problems = []; + $share = $config->get('economy.instance_share', 1.0); + if ($share <= 0 || $share > 1) { + $problems[] = "[economy.instance_share] must be above 0 and at most 1 (is $share)."; + } + foreach ($config->buildingTypes() as $type) { + if (($config->building($type)['instance_cost_factor'] ?? 1.0) < 1) { + $problems[] = "[$type] instance_cost_factor must be at least 1, or copies get cheaper."; + } + } + + return $problems; + } + /** Requirements name real types and levels, and have no cycles. */ /** Every unit has a real building to train at, reachable requirements, and a cost storage can hold. */ private static function unitsTrainable(WorldConfig $config, BuildingRules $rules): array diff --git a/tests/Unit/Game/ConfigLintTest.php b/tests/Unit/Game/ConfigLintTest.php index 82d9dc5..e82d868 100644 --- a/tests/Unit/Game/ConfigLintTest.php +++ b/tests/Unit/Game/ConfigLintTest.php @@ -62,6 +62,16 @@ it('reports a levy or desertion timer that never runs out', function () { ]); }); +it('reports copies that work for nothing, above full, or get cheaper', function () { + $lint = fn (array $overrides) => ConfigLint::check(gameConfig($overrides)); + + expect($lint(['economy' => ['instance_share' => 0]]))->toBe(['[economy.instance_share] must be above 0 and at most 1 (is 0).']) + ->and($lint(['economy' => ['instance_share' => 1.5]]))->toBe(['[economy.instance_share] must be above 0 and at most 1 (is 1.5).']) + ->and($lint(['economy' => ['instance_share' => 1]]))->toBe([]) + ->and($lint(['buildings' => ['barracks' => ['instance_cost_factor' => 0.9]]])) + ->toBe(['[barracks] instance_cost_factor must be at least 1, or copies get cheaper.']); +}); + it('reports garrisons that would starve their village or never regroup', function () { $config = gameConfig(['world' => ['map' => ['barbarians' => ['garrison' => [ 'max_food_share' => 0.9,