feat: ConfigLint: instance_share above 0 and at most 1, instance_cost_factor at least 1
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5b5a412d71
commit
b4a7c61921
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue