feat: scarce building space (5 per headquarters level) and village roles

A village whose space is mostly camps becomes a resource village (+20% from its
camps); one mostly barracks, stable and workshop a military village (+20% training
speed, +10% defence). The payload carries the role and the space per role.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-29 16:20:52 +01:00
parent c5286bc19a
commit 02abcac325
15 changed files with 355 additions and 20 deletions

View File

@ -100,7 +100,7 @@ final class Military
{
$staffing = $this->sim->staffingFactor($this->sim->workforce()->ratio($building->id));
return $this->units->seconds($unit, $building->level, $staffing);
return $this->units->seconds($unit, $building->level, $staffing, $this->sim->specialisation()->recruitBonus($this->sim->role()));
}
/** Queue units at a military building. Pays up front; the villagers stop working at once. */

View File

@ -280,6 +280,8 @@ final class Rally
// Raiders (no player) attack at full strength.
$morale = $combat->morale($defenderPoints, $movement->player_id ? (int) Village::where('player_id', $movement->player_id)->sum('points') : 0);
$night = $combat->night($at);
// A military village's defenders fight harder.
$fort = 1 + $this->sim->specialisation()->defenseBonus($this->sim->role());
// Scouts meet the defending scouts first and never fight; the rest of the army does.
$isScout = fn (string $unit) => (bool) $config->get("units.$unit.scout", false);
@ -287,7 +289,7 @@ final class Rally
$army = array_diff_key($movement->units, $scouts);
$watchers = array_sum(array_filter($defense, fn (int $n, string $unit) => $isScout($unit), ARRAY_FILTER_USE_BOTH));
[$through, $scoutsLost] = $combat->scout(array_sum($scouts), $watchers);
$battle = $army ? $combat->fight($army, $defense, $wall?->level ?? 0, $morale, $luck, $night) : null;
$battle = $army ? $combat->fight($army, $defense, $wall?->level ?? 0, $morale, $luck, $night * $fort) : null;
$won = $battle ? $battle->attackerWon : $through;
// Defenders fall in every stack alike, support included.

View File

@ -5,6 +5,7 @@ namespace App\Engine;
use App\Game\Buildings\BuildingRules;
use App\Game\Buildings\BuildingState;
use App\Game\Buildings\BuildQueue;
use App\Game\Buildings\Specialisation;
use App\Game\Economy\Population;
use App\Game\Economy\Production;
use App\Game\Economy\Settle;
@ -92,7 +93,18 @@ final class Simulation
/** @return array{resource: string, per_hour: float}|null */
public function output(Building $building, Workforce $workforce): ?array
{
return $this->production->output($building->state(), $workforce);
return $this->production->output($building->state(), $workforce, $this->specialisation()->productionBonus($this->role(), $building->type));
}
public function specialisation(): Specialisation
{
return new Specialisation($this->config);
}
/** The village's role from the buildings standing, or null. */
public function role(): ?string
{
return $this->specialisation()->role($this->village->buildings->pluck('type'));
}
public function staffingFactor(float $ratio): float

View File

@ -0,0 +1,109 @@
<?php
namespace App\Game\Buildings;
use App\Game\WorldConfig;
/**
* A village's role from what fills its space (world.village.specialisation): when one
* role's buildings take at least `share` of the space both roles take together, and at
* least `min_space`, the village has that role. A resource village produces more in its
* camps; a military village trains faster and its defenders fight harder.
*/
final class Specialisation
{
private BuildingRules $rules;
public function __construct(private readonly WorldConfig $config)
{
$this->rules = new BuildingRules($config);
}
/** @return list<string> */
public function roles(): array
{
return array_keys($this->config->get('world.village.specialisation.roles', []));
}
/**
* Space each role's buildings take, from one entry per standing instance.
*
* @param iterable<string> $types
* @return array<string, int>
*/
public function space(iterable $types): array
{
$space = array_fill_keys($this->roles(), 0);
foreach ($types as $type) {
if ($role = $this->roleOf($type)) {
$space[$role] += $this->rules->space($type);
}
}
return $space;
}
/**
* The village's role, or null while no role's buildings dominate.
*
* @param iterable<string> $types one entry per standing instance
*/
public function role(iterable $types): ?string
{
$space = $this->space($types);
$total = array_sum($space);
$share = (float) $this->config->get('world.village.specialisation.share', 1);
$min = (int) $this->config->get('world.village.specialisation.min_space', 0);
foreach ($space as $role => $taken) {
if ($total > 0 && $taken >= $min && $taken / $total >= $share) {
return $role;
}
}
return null;
}
/** The role a building type counts for, if any. */
public function roleOf(string $type): ?string
{
foreach ($this->config->get('world.village.specialisation.roles', []) as $role => $values) {
if (in_array($type, $values['buildings'] ?? [], true)) {
return $role;
}
}
return null;
}
/** Extra output share of this building in a village with that role (0.2 = +20%). */
public function productionBonus(?string $role, string $type): float
{
return $role !== null && $this->roleOf($type) === $role ? $this->bonus($role, 'production') : 0.0;
}
/** Extra training speed share in a village with that role. */
public function recruitBonus(?string $role): float
{
return $role !== null ? $this->bonus($role, 'recruit_speed') : 0.0;
}
/** Extra defence share for everyone defending a village with that role. */
public function defenseBonus(?string $role): float
{
return $role !== null ? $this->bonus($role, 'defense') : 0.0;
}
/** @return array<string, float> the role's bonuses by key, for the client */
public function bonuses(string $role): array
{
$values = $this->config->get("world.village.specialisation.roles.$role", []);
unset($values['buildings']);
return array_map('floatval', $values);
}
private function bonus(string $role, string $key): float
{
return (float) $this->config->get("world.village.specialisation.roles.$role.$key", 0);
}
}

View File

@ -27,6 +27,7 @@ final class ConfigLint
...self::questsReachable($config, $rules),
...self::garrisonsRegroup($config),
...self::raidsPause($config),
...self::rolesReachable($config),
];
}
@ -133,6 +134,39 @@ final class ConfigLint
return $problems;
}
/**
* Every role names real buildings, each building counts for one role at most, and a
* role's min_space fits a village of the largest headquarters, or nobody reaches it.
*/
private static function rolesReachable(WorldConfig $config): array
{
$roles = $config->get('world.village.specialisation.roles', []);
$share = $config->get('world.village.specialisation.share', 1);
$problems = [];
if ($roles && ($share <= 0.5 || $share > 1)) {
$problems[] = '[specialisation.share] must be above 0.5 and at most 1, so a village has one role at most.';
}
$rules = new BuildingRules($config);
$hqMax = $config->hasBuilding('headquarters') ? $rules->maxLevel('headquarters') : 1;
$room = $rules->spaceMax((int) $config->get('world.village.space'), $hqMax) - $rules->spaceUsed($config->get('world.village.start_buildings', []));
$seen = [];
foreach ($roles as $role => $values) {
foreach ($values['buildings'] ?? [] as $type) {
if (! $config->hasBuilding($type)) {
$problems[] = "Role [$role] counts unknown building [$type].";
} elseif (isset($seen[$type])) {
$problems[] = "[$type] counts for two roles, [{$seen[$type]}] and [$role].";
}
$seen[$type] = $role;
}
}
if ($roles && $config->get('world.village.specialisation.min_space', 0) > $room) {
$problems[] = '[specialisation.min_space] is more than a village has room for.';
}
return $problems;
}
/** A levy has to end and desertion waves have to come apart in time, or the village stays stuck. */
private static function timersRun(WorldConfig $config): array
{

View File

@ -4,6 +4,7 @@ namespace App\Game\Economy;
use App\Game\Buildings\BuildingRules;
use App\Game\Buildings\BuildingState;
use App\Game\Buildings\Specialisation;
use App\Game\WorldConfig;
/** Resource rates per hour from the base trickle, buildings and their staffing. */
@ -13,9 +14,12 @@ final class Production
private BuildingRules $rules;
private Specialisation $specialisation;
public function __construct(private readonly WorldConfig $config)
{
$this->rules = new BuildingRules($config);
$this->specialisation = new Specialisation($config);
}
/** Output share at staffing ratio r: e^(k·(r−1)). Full is 1, empty about 0.1. */
@ -24,20 +28,24 @@ final class Production
return exp($this->config->get('economy.staffing.k', 2.3) * (min(1.0, max(0.0, $ratio)) - 1));
}
/** @return array{resource: string, per_hour: float}|null */
public function output(BuildingState $building, Workforce $workforce): ?array
/**
* @param float $bonus extra share from the village's role (0.2 = +20%)
* @return array{resource: string, per_hour: float}|null
*/
public function output(BuildingState $building, Workforce $workforce, float $bonus = 0.0): ?array
{
$output = $this->rules->output($building->type, $building->level);
if (! $output) {
return null;
}
$output['per_hour'] *= $this->staffingFactor($workforce->ratio($building->id));
$output['per_hour'] *= $this->staffingFactor($workforce->ratio($building->id)) * (1 + $bonus);
return $output;
}
/**
* Net change per hour. Food is farm output minus upkeep, so it can go negative.
* Net change per hour, with the village role's bonus on its buildings. Food is farm
* output minus upkeep, so it can go negative.
*
* @param list<BuildingState> $buildings
* @return array{wood: float, clay: float, iron: float, food: float}
@ -48,8 +56,9 @@ final class Production
foreach ($this->config->get('economy.base_production', []) as $resource => $perHour) {
$rates[$resource] += $perHour * $this->config->speed();
}
$role = $this->specialisation->role(array_map(fn (BuildingState $b) => $b->type, $buildings));
foreach ($buildings as $b) {
if ($output = $this->output($b, $workforce)) {
if ($output = $this->output($b, $workforce, $this->specialisation->productionBonus($role, $b->type))) {
$rates[$output['resource']] += $output['per_hour'];
}
}

View File

@ -46,13 +46,14 @@ final class UnitRules
/**
* Seconds to train one unit, at world speed, sped up by the training building's
* level and slowed by its staffing (output factor 0..1).
* level and a military village's bonus, and slowed by its staffing (output factor 0..1).
*/
public function seconds(string $unit, int $buildingLevel, float $staffing): int
public function seconds(string $unit, int $buildingLevel, float $staffing, float $bonus = 0.0): int
{
$seconds = $this->unit($unit)['build_time']
/ $this->config->speed()
/ (1 + $this->config->get('economy.recruit_speed_per_level', 0) * BuildingRules::above($buildingLevel))
/ (1 + $bonus)
/ max($staffing, 0.01);
return max(1, (int) ceil($seconds));

View File

@ -42,6 +42,7 @@ final class VillagePresenter
'continent' => Continent::of($village->x, $village->y, (int) $sim->config()->get('world.map.size', 1000)),
'points' => $village->points,
'space' => ['used' => $sim->spaceUsed(), 'max' => $sim->spaceMax()],
'specialisation' => self::specialisation($village, $sim),
'resources' => array_map(fn (float $n) => round($n, 4), $village->resources()),
'resources_at' => self::iso($village->resources_at),
'rates' => array_map(fn (float $n) => round($n, 4), $sim->rates()),
@ -162,6 +163,28 @@ final class VillagePresenter
return $out;
}
/**
* The village's role, the space each role's buildings take, and what makes a role
* and what it gives, so the client can show how close the village is to one.
*/
private static function specialisation(Village $village, Simulation $sim): array
{
$spec = $sim->specialisation();
$config = $sim->config();
return [
'role' => $sim->role(),
'space' => (object) $spec->space($village->buildings->pluck('type')),
'share' => (float) $config->get('world.village.specialisation.share'),
'min_space' => (int) $config->get('world.village.specialisation.min_space'),
'roles' => array_map(fn (string $role) => [
'role' => $role,
'buildings' => $config->get("world.village.specialisation.roles.$role.buildings"),
'bonuses' => (object) $spec->bonuses($role),
], $spec->roles()),
];
}
/** Coins and noble slots of the player, and what a coin costs. */
private static function conquest(Village $village): array
{

View File

@ -8,9 +8,22 @@ return [
'village' => [
// Building space: the sum of the buildings' `space` may not exceed
// space + space_per_hq_level × (headquarters level − 1): 40 at level 1, 60 at 2, ...
// space + space_per_hq_level × (headquarters level − 1): 40 at level 1, 45 at 2, 85 at
// 10. Scarce on purpose: what goes in is the village's main choice.
'space' => 40,
'space_per_hq_level' => 20,
'space_per_hq_level' => 5,
// What fills the space gives a village its role. When one role's buildings take at
// least `share` of the space both roles' buildings take together, and min_space of
// it, the village has that role and its bonus: a resource village produces more in
// its camps, a military village trains faster and its defenders fight harder.
'specialisation' => [
'share' => 0.7,
'min_space' => 16,
'roles' => [
'resources' => ['buildings' => ['timber_camp', 'clay_pit', 'iron_mine'], 'production' => 0.2],
'military' => ['buildings' => ['barracks', 'stable', 'workshop', 'academy'], 'recruit_speed' => 0.2, 'defense' => 0.1],
],
],
'start_resources' => ['wood' => 500, 'clay' => 500, 'iron' => 500, 'food' => 300],
// Auto-placed at level 1 in this order.
'start_buildings' => ['headquarters', 'storage', 'farm'],

View File

@ -76,7 +76,7 @@ A wave takes the fewest units that make income cover upkeep again: support stati
## Village space
- Each village has a building space budget that grows with its headquarters: `space + village.space_per_hq_level × (HQ level − 1)` (defaults 40 and 20, so 40 at level 1, 60 at level 2). The village row stores its own base `space`, so terrain or specials can change it per village later. The new space arrives when an HQ level finishes; a queued HQ demolition already counts, and the HQ can't be demolished below what stands.
- Each village has a building space budget that grows with its headquarters: `space + village.space_per_hq_level × (HQ level − 1)` (defaults 40 and 5, so 40 at level 1, 45 at level 2 and 85 at level 10). Space is scarce on purpose: one of every building type only fits from headquarters level 5, so what goes in is the village's main choice. The village row stores its own base `space`, so terrain or specials can change it per village later. The new space arrives when an HQ level finishes; a queued HQ demolition already counts, and the HQ can't be demolished below what stands.
- Each building type takes a fixed `space` from config, for example HQ 9, barracks 6, resource buildings 4, and hiding place 1. The level changes only the look, never the space. A building fits when the space of all buildings plus new buildings still in the queue, plus its own, stays within the budget. The space is reserved when the order is queued.
- There are no tiles and no stored positions. The client draws the village as a low-poly isometric diorama and lays the buildings out itself (HQ in the centre, the rest around it), so where a building stands is presentation, not game state.
- Levels start at 1, as in Die Stämme, and a new instance is built at level 1. Every per-level formula uses `level − 1` as the exponent of its factor, so level 1 has the base values.
@ -84,6 +84,7 @@ A wave takes the fewest units that make income cover upkeep again: support stati
- Basic buildings have no requirements: everything in the core set, the wall included, can be built from the start. Only advanced buildings get `requires` (type => minimum level of any instance), for example the academy (Adelshof) needs the headquarters and a barracks (Kaserne). A build option lists what is still missing.
- 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.
- **Roles** (`Specialisation`, `world.village.specialisation`): what fills the space gives a village a role. Resource buildings (timber camp, clay pit, iron mine) and military buildings (barracks, stable, workshop, academy) count; when one kind takes at least `share` (70%) of the space both kinds take together, and at least `min_space` (16), the village has that role. A resource village's camps produce `production` (+20%) more; a military village trains `recruit_speed` (+20%) faster and everyone defending it, support included, fights with `defense` (+10%) more. Farms, storage and the rest count for neither, since both kinds of village need them. Only standing buildings count, so a role starts and ends when an order finishes. The payload's `specialisation` carries the role, the space per role and the rules.
- 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.

View File

@ -188,7 +188,7 @@ it('lets the worker finish orders of idle villages', function () {
->and(GameEvent::whereNull('processed_at')->count())->toBe(0);
});
it('grows the building space by 20 with every headquarters level', function () {
it('grows the building space by 5 with every headquarters level', function () {
$village = startVillage();
$hq = $village->buildings->firstWhere('type', 'headquarters');
@ -197,18 +197,18 @@ it('grows the building space by 20 with every headquarters level', function () {
expect(shown($village)['space']['max'])->toBe(40);
$this->travel(1)->hours();
expect(shown($village)['space']['max'])->toBe(60);
expect(shown($village)['space']['max'])->toBe(45);
});
it('keeps the headquarters from shrinking below what stands, and plans with a queued demolition', function () {
$village = startVillage();
$hq = $village->buildings->firstWhere('type', 'headquarters');
$hq->update(['level' => 3]);
// 17 + 7 × 4 = 45 of 80: level 2 (60) still fits, level 1 (40) would not.
// 17 + 7 × 4 = 45 of 50: level 2 (45) still fits, level 1 (40) would not.
$village->buildings()->createMany(array_fill(0, 7, ['type' => 'timber_camp', 'level' => 1]));
app(QueueDemolish::class)(owner($village), $village->id, $hq->id);
$state = shown($village);
expect($state['space'])->toBe(['used' => 45, 'max' => 60])
expect($state['space'])->toBe(['used' => 45, 'max' => 45])
->and(rule(fn () => app(QueueDemolish::class)(owner($village), $village->id, $hq->id)))->toBe('no_space');
});

View File

@ -0,0 +1,76 @@
<?php
use App\Engine\Barbarians;
use App\Engine\VillageFactory;
use App\Models\Movement;
use App\Models\Report;
use App\Models\Village;
use App\Models\World;
use Carbon\CarbonImmutable;
beforeEach(fn () => $this->travelTo(CarbonImmutable::parse('2026-10-29 12:00:00')));
/** @param list<string> $types new level-1 instances */
function withBuildings(Village $village, array $types): Village
{
foreach ($types as $type) {
$village->buildings()->create(['type' => $type, 'level' => 1]);
}
return $village->fresh();
}
it('makes a village of camps a resource village whose camps produce a fifth more', function () {
$village = startVillage();
$village->buildings()->where('type', 'farm')->update(['level' => 10]);
$before = shown(withBuildings($village, ['timber_camp', 'clay_pit', 'iron_mine']));
expect($before['specialisation'])->toMatchArray(['role' => null, 'share' => 0.7, 'min_space' => 16])
->and((array) $before['specialisation']['space'])->toBe(['resources' => 12, 'military' => 0]);
$state = shown(withBuildings($village, ['timber_camp']));
$camp = collect($state['buildings'])->firstWhere('type', 'clay_pit');
// 30/h at level 1, full staffing.
expect($state['specialisation']['role'])->toBe('resources')
->and($camp['production']['per_hour'])->toBe(36.0)
->and($state['rates']['clay'])->toBe(5 + 36.0);
});
it('trains a fifth faster in a military village', function () {
$village = startVillage();
$village->buildings()->where('type', 'farm')->update(['level' => 10]);
$plain = shown(withBuildings($village, ['barracks']));
$seconds = collect($plain['military'][0]['units'])->firstWhere('unit', 'spear')['seconds'];
$state = shown(withBuildings($village, ['stable', 'workshop']));
expect($state['specialisation']['role'])->toBe('military')
->and(collect($state['military'][0]['units'])->firstWhere('unit', 'spear')['seconds'])->toBe((int) ceil($seconds / 1.2));
});
it('lets a military village defend a tenth harder', function () {
// A band of 40 swords: 1000 attack.
config([
'game.raids.enabled' => true,
'game.raids.attack' => ['base' => 1000, 'per_point' => 0],
'game.world.map.barbarians.garrison.profiles' => ['swordsmen' => ['sword' => 1.0]],
]);
$village = startVillage();
World::whereKey($village->world_id)->update(['config' => ['combat' => ['luck' => 0]]]);
$village->buildings()->where('type', 'farm')->update(['level' => 15]);
withBuildings($village, ['barracks', 'stable', 'workshop']);
$types = ['headquarters', 'storage', 'farm', 'timber_camp', 'clay_pit', 'iron_mine'];
$camp = app(VillageFactory::class)->create($village->world, null, 'Barbarian village', $village->x + 3, $village->y, array_fill_keys($types, 8));
Barbarians::of($camp)->fill();
$this->travel(3)->days();
$this->artisan('game:events --once')->assertSuccessful();
$raid = Movement::where('target_id', $village->id)->sole();
// Spears that lose to the band on their own (15 defence each) but hold with +10%.
$attack = $raid->units['sword'] * 25;
$spears = (int) ceil($attack / 16.5 + 0.01);
expect($spears * 15)->toBeLessThan($attack)->and($spears * 16.5)->toBeGreaterThan($attack);
$village->troops()->create(['home_village_id' => $village->id, 'unit' => 'spear', 'count' => $spears]);
$this->travelTo($raid->arrives_at);
$this->artisan('game:events --once')->assertSuccessful();
expect(Report::where('player_id', $village->player_id)->sole()->payload['won'])->toBeFalse();
});

View File

@ -87,8 +87,8 @@ it('adds building space for every headquarters level', function () {
$rules = new BuildingRules(gameConfig());
expect($rules->spaceMax(40, 1))->toBe(40)
->and($rules->spaceMax(40, 2))->toBe(60)
->and($rules->spaceMax(40, 30))->toBe(620);
->and($rules->spaceMax(40, 2))->toBe(45)
->and($rules->spaceMax(40, 30))->toBe(185);
});
it('lists what an instance does at a level', function () {
@ -98,7 +98,7 @@ it('lists what an instance does at a level', function () {
->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('headquarters', 3))->toBe([['key' => 'build_speed', 'value' => 10], ['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([]);
});

View File

@ -82,3 +82,14 @@ it('reports raids that never pause or that a beaten camp still sends', function
->toContain('[raids.scatter_below] must be above 0 and at most 1, or beating the camp would not stop its raid.')
->toContain('[raids.mode] is not a travel mode.');
});
it('reports roles that share buildings or can never be reached', function () {
$config = gameConfig(['world' => ['village' => ['specialisation' => [
'min_space' => 999,
'roles' => ['military' => ['buildings' => ['barracks', 'timber_camp', 'castle']]],
]]]]);
expect(ConfigLint::check($config))
->toContain('Role [military] counts unknown building [castle].')
->toContain('[timber_camp] counts for two roles, [resources] and [military].')
->toContain('[specialisation.min_space] is more than a village has room for.');
});

View File

@ -0,0 +1,44 @@
<?php
use App\Game\Buildings\Specialisation;
$start = ['headquarters', 'storage', 'farm'];
it('has no role until one kind of building fills enough space', function () use ($start) {
$spec = new Specialisation(gameConfig());
// Three camps take 12 space, short of 16.
expect($spec->role($start))->toBeNull()
->and($spec->role([...$start, 'timber_camp', 'clay_pit', 'iron_mine']))->toBeNull()
->and($spec->role([...$start, 'timber_camp', 'clay_pit', 'iron_mine', 'timber_camp']))->toBe('resources');
});
it('loses the role when the other kind takes more than 30% of the role space', function () use ($start) {
$spec = new Specialisation(gameConfig());
$camps = ['timber_camp', 'clay_pit', 'iron_mine', 'timber_camp', 'clay_pit'];
// 20 of 26 is 77%; 20 of 32 is 63%.
expect($spec->role([...$start, ...$camps, 'barracks']))->toBe('resources')
->and($spec->role([...$start, ...$camps, 'barracks', 'stable']))->toBeNull()
->and($spec->space([...$start, ...$camps, 'barracks', 'stable']))->toBe(['resources' => 20, 'military' => 12]);
});
it('makes a military village of barracks, stable and workshop beside one camp', function () use ($start) {
$spec = new Specialisation(gameConfig());
// 18 of 22 is 82%.
expect($spec->role([...$start, 'timber_camp', 'barracks', 'stable', 'workshop']))->toBe('military')
->and($spec->recruitBonus('military'))->toBe(0.2)
->and($spec->defenseBonus('military'))->toBe(0.1)
->and($spec->recruitBonus('resources'))->toBe(0.0)
->and($spec->recruitBonus(null))->toBe(0.0);
});
it('raises only the role buildings output in a resource village', function () {
$spec = new Specialisation(gameConfig());
expect($spec->productionBonus('resources', 'timber_camp'))->toBe(0.2)
->and($spec->productionBonus('resources', 'farm'))->toBe(0.0)
->and($spec->productionBonus('military', 'timber_camp'))->toBe(0.0)
->and($spec->bonuses('military'))->toBe(['recruit_speed' => 0.2, 'defense' => 0.1]);
});