feat: every building tells what it does at its level and the next one
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
a3b16bfe9b
commit
12586f853d
|
|
@ -115,6 +115,46 @@ final class BuildingRules
|
||||||
return $detection ? $detection['base'] * $detection['factor'] ** self::above($level) : 0.0;
|
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<array{key: string, value: float|int, resource?: string}>
|
||||||
|
*/
|
||||||
|
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. */
|
/** Points an instance at this level adds to its village. */
|
||||||
public function points(string $type, int $level): int
|
public function points(string $type, int $level): int
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,9 @@ final class VillagePresenter
|
||||||
'workers' => ['assigned' => $workforce->assigned[$b->id] ?? 0, 'required' => $workforce->required[$b->id] ?? 0],
|
'workers' => ['assigned' => $workforce->assigned[$b->id] ?? 0, 'required' => $workforce->required[$b->id] ?? 0],
|
||||||
'staffing' => round($workforce->ratio($b->id), 4),
|
'staffing' => round($workforce->ratio($b->id), 4),
|
||||||
'production' => $output ? ['resource' => $output['resource'], 'per_hour' => round($output['per_hour'], 2)] : null,
|
'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),
|
'upgrade' => $sim->upgradeOffer($b),
|
||||||
'demolish' => $sim->demolishOffer($b),
|
'demolish' => $sim->demolishOffer($b),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -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.
|
- 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.
|
- 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.
|
- 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.
|
A new village starts with HQ 0, storage 0, and farm 0, plus starting resources from world config.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,3 +90,15 @@ it('adds building space for every headquarters level', function () {
|
||||||
->and($rules->spaceMax(40, 2))->toBe(60)
|
->and($rules->spaceMax(40, 2))->toBe(60)
|
||||||
->and($rules->spaceMax(40, 30))->toBe(620);
|
->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([]);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue