feat: building space grows with the headquarters: 40 plus 20 per level

villages.space becomes the base at HQ level 0 (existing villages 50 -> 40). A queued
HQ demolition counts already, and the HQ can't go below what stands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-28 22:16:45 +01:00
parent 5e30846ea6
commit 65a4e4b5d4
11 changed files with 93 additions and 12 deletions

View File

@ -18,6 +18,11 @@ final class QueueDemolish extends VillageAction
$building = $this->building($village, $buildingId); $building = $this->building($village, $buildingId);
$offer = $sim->demolishOffer($building) $offer = $sim->demolishOffer($building)
?? throw new GameRuleViolation('core_building', 'Core buildings cannot go below level 0.'); ?? throw new GameRuleViolation('core_building', 'Core buildings cannot go below level 0.');
// A smaller headquarters means less building space; what stands must still fit.
if ($building->type === 'headquarters'
&& $sim->spaceUsed() > $sim->rules()->spaceMax($village->space, $offer['target_level'])) {
throw new GameRuleViolation('no_space', 'The buildings would no longer fit.');
}
$sim->enqueue([ $sim->enqueue([
'building_id' => $building->id, 'building_id' => $building->id,
'type' => $building->type, 'type' => $building->type,

View File

@ -197,9 +197,21 @@ final class Simulation
]); ]);
} }
/**
* The village's building space, from its headquarters level. A queued demolition of
* the headquarters counts already, so nothing can be queued into space that goes away.
*/
public function spaceMax(): int
{
$hq = $this->village->buildings->firstWhere('type', 'headquarters');
$level = $hq ? min($hq->level, $this->queuedLevel($hq)) : 0;
return $this->rules->spaceMax($this->village->space, $level);
}
public function spaceFits(string $type): bool public function spaceFits(string $type): bool
{ {
return $this->spaceUsed() + $this->rules->space($type) <= $this->village->space; return $this->spaceUsed() + $this->rules->space($type) <= $this->spaceMax();
} }
/** The headquarters, and the last storage or farm, never go below level 0. */ /** The headquarters, and the last storage or farm, never go below level 0. */

View File

@ -104,6 +104,12 @@ final class BuildingRules
return $this->config->building($type)['space']; return $this->config->building($type)['space'];
} }
/** A village's building space with its headquarters at this level; $base is the village's own. */
public function spaceMax(int $base, int $hqLevel): int
{
return $base + $this->config->get('world.village.space_per_hq_level', 0) * max(0, $hqLevel);
}
/** /**
* Space taken by these building types together. * Space taken by these building types together.
* *

View File

@ -49,7 +49,11 @@ final class ConfigLint
*/ */
private static function startVillageFits(WorldConfig $config, BuildingRules $rules): array private static function startVillageFits(WorldConfig $config, BuildingRules $rules): array
{ {
// The headquarters starts at level 0, so the start village has the base space.
$max = $config->get('world.village.space'); $max = $config->get('world.village.space');
if ($config->get('world.village.space_per_hq_level', 0) < 0) {
return ['[world.village.space_per_hq_level] cannot be negative, or upgrading the headquarters would squeeze the village.'];
}
$start = $config->get('world.village.start_buildings', []); $start = $config->get('world.village.start_buildings', []);
$problems = []; $problems = [];
foreach ($start as $type) { foreach ($start as $type) {

View File

@ -37,7 +37,7 @@ final class VillagePresenter
'y' => $village->y, 'y' => $village->y,
'continent' => Continent::of($village->x, $village->y), 'continent' => Continent::of($village->x, $village->y),
'points' => $village->points, 'points' => $village->points,
'space' => ['used' => $sim->spaceUsed(), 'max' => $village->space], 'space' => ['used' => $sim->spaceUsed(), 'max' => $sim->spaceMax()],
'resources' => array_map(fn (float $n) => round($n, 4), $village->resources()), 'resources' => array_map(fn (float $n) => round($n, 4), $village->resources()),
'resources_at' => self::iso($village->resources_at), 'resources_at' => self::iso($village->resources_at),
'rates' => array_map(fn (float $n) => round($n, 4), $sim->rates()), 'rates' => array_map(fn (float $n) => round($n, 4), $sim->rates()),

View File

@ -7,8 +7,10 @@ return [
'speed' => 1.0, 'speed' => 1.0,
'village' => [ 'village' => [
// Building space: the sum of the buildings' `space` may not exceed it. // Building space: the sum of the buildings' `space` may not exceed
'space' => 50, // space + space_per_hq_level × headquarters level (40 at level 0, 60 at 1, ...).
'space' => 40,
'space_per_hq_level' => 20,
'start_resources' => ['wood' => 500, 'clay' => 500, 'iron' => 500, 'food' => 300], 'start_resources' => ['wood' => 500, 'clay' => 500, 'iron' => 500, 'food' => 300],
// Auto-placed at level 0 in this order. // Auto-placed at level 0 in this order.
'start_buildings' => ['headquarters', 'storage', 'farm'], 'start_buildings' => ['headquarters', 'storage', 'farm'],

View File

@ -0,0 +1,19 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
// villages.space is now the base at headquarters level 0; each HQ level adds
// world.village.space_per_hq_level on top. The old flat default was 50.
public function up(): void
{
DB::table('villages')->where('space', 50)->update(['space' => 40]);
}
public function down(): void
{
DB::table('villages')->where('space', 40)->update(['space' => 50]);
}
};

View File

@ -73,7 +73,7 @@ A wave takes the fewest units that make income cover upkeep again: foreign suppo
## Village space ## Village space
- Each village has a building space budget. The world config sets the default (`village.space`, 50). The village row stores its own `space`, so terrain or specials can change it per village later. - Each village has a building space budget that grows with its headquarters: `space + village.space_per_hq_level × HQ level` (defaults 40 and 20, so 40 at level 0, 60 at level 1). 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. - 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. - 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 0. Level 0 is a real, primitive state: the HQ is a tent, storage is open ground, and the farm is gatherers. A new instance is built at level 0. - Levels start at 0. Level 0 is a real, primitive state: the HQ is a tent, storage is open ground, and the farm is gatherers. A new instance is built at level 0.

View File

@ -27,7 +27,7 @@ it('pays up front, reserves the space and finishes on time', function () {
app(QueueBuild::class)(owner($village), $village->id, 'timber_camp'); app(QueueBuild::class)(owner($village), $village->id, 'timber_camp');
$state = shown($village); $state = shown($village);
expect($state['resources']['wood'])->toBe(450.0) expect($state['resources']['wood'])->toBe(450.0)
->and($state['space'])->toBe(['used' => 21, 'max' => 50]) ->and($state['space'])->toBe(['used' => 21, 'max' => 40])
->and($state['queue'][0])->toMatchArray([ ->and($state['queue'][0])->toMatchArray([
'type' => 'timber_camp', 'action' => 'build', 'space' => 4, 'builder' => 1, '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:01:30.000Z',
@ -45,11 +45,11 @@ it('pays up front, reserves the space and finishes on time', function () {
}); });
it('refuses a building that does not fit the free building space', function () { it('refuses a building that does not fit the free building space', function () {
// Start buildings take 17 of 50; five timber camps and twelve hiding places bring it to 49. // Start buildings take 17 of 40; four timber camps and six hiding places bring it to 39.
$village = startVillage(); $village = startVillage();
$village->buildings()->createMany([ $village->buildings()->createMany([
...array_fill(0, 5, ['type' => 'timber_camp', 'level' => 0]), ...array_fill(0, 4, ['type' => 'timber_camp', 'level' => 0]),
...array_fill(0, 12, ['type' => 'hiding_place', 'level' => 0]), ...array_fill(0, 6, ['type' => 'hiding_place', 'level' => 0]),
]); ]);
$options = collect(shown($village)['buildable'])->keyBy('type'); $options = collect(shown($village)['buildable'])->keyBy('type');
@ -60,7 +60,7 @@ it('refuses a building that does not fit the free building space', function () {
// Queuing reserves the space right away. // Queuing reserves the space right away.
app(QueueBuild::class)(owner($village), $village->id, 'rally_point'); app(QueueBuild::class)(owner($village), $village->id, 'rally_point');
$state = shown($village); $state = shown($village);
expect($state['space'])->toBe(['used' => 50, 'max' => 50]) expect($state['space'])->toBe(['used' => 40, 'max' => 40])
->and(collect($state['buildable'])->firstWhere('type', 'hiding_place')['blocked'])->toBe('no_space'); ->and(collect($state['buildable'])->firstWhere('type', 'hiding_place')['blocked'])->toBe('no_space');
}); });
@ -187,3 +187,28 @@ it('lets the worker finish orders of idle villages', function () {
expect($village->buildings()->where('type', 'timber_camp')->exists())->toBeTrue() expect($village->buildings()->where('type', 'timber_camp')->exists())->toBeTrue()
->and(GameEvent::whereNull('processed_at')->count())->toBe(0); ->and(GameEvent::whereNull('processed_at')->count())->toBe(0);
}); });
it('grows the building space by 20 with every headquarters level', function () {
$village = startVillage();
$hq = $village->buildings->firstWhere('type', 'headquarters');
app(QueueUpgrade::class)(owner($village), $village->id, $hq->id);
// Space comes with the finished level, not the queued one.
expect(shown($village)['space']['max'])->toBe(40);
$this->travel(1)->hours();
expect(shown($village)['space']['max'])->toBe(60);
});
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' => 2]);
// 17 + 7 × 4 = 45 of 80: level 1 (60) still fits, level 0 (40) would not.
$village->buildings()->createMany(array_fill(0, 7, ['type' => 'timber_camp', 'level' => 0]));
app(QueueDemolish::class)(owner($village), $village->id, $hq->id);
$state = shown($village);
expect($state['space'])->toBe(['used' => 45, 'max' => 60])
->and(rule(fn () => app(QueueDemolish::class)(owner($village), $village->id, $hq->id)))->toBe('no_space');
});

View File

@ -12,7 +12,7 @@ it('starts a village with HQ, storage and farm at level 0', function () {
// On the spawn ring: start radius 6 ± 2 around 500|500. // On the spawn ring: start radius 6 ± 2 around 500|500.
expect(hypot($village->x - 500, $village->y - 500))->toBeBetween(3.0, 9.0) expect(hypot($village->x - 500, $village->y - 500))->toBeBetween(3.0, 9.0)
->and($village->only('space', 'points'))->toBe(['space' => 50, 'points' => 21]) ->and($village->only('space', 'points'))->toBe(['space' => 40, 'points' => 21])
->and($village->resources())->toBe(['wood' => 500.0, 'clay' => 500.0, 'iron' => 500.0, 'food' => 300.0]) ->and($village->resources())->toBe(['wood' => 500.0, 'clay' => 500.0, 'iron' => 500.0, 'food' => 300.0])
->and($village->buildings->map->only('type', 'level')->all())->toBe([ ->and($village->buildings->map->only('type', 'level')->all())->toBe([
['type' => 'headquarters', 'level' => 0], ['type' => 'headquarters', 'level' => 0],
@ -53,7 +53,7 @@ it('shows a start village to its owner only', function () {
$village = startVillage(); $village = startVillage();
$state = shown($village); $state = shown($village);
expect($state['space'])->toBe(['used' => 17, 'max' => 50]) expect($state['space'])->toBe(['used' => 17, 'max' => 40])
->and($state['continent'])->toBe(Continent::of($village->x, $village->y)) ->and($state['continent'])->toBe(Continent::of($village->x, $village->y))
->and($state['rates'])->toBe(['wood' => 5.0, 'clay' => 5.0, 'iron' => 5.0, 'food' => 6.0]) ->and($state['rates'])->toBe(['wood' => 5.0, 'clay' => 5.0, 'iron' => 5.0, 'food' => 6.0])
->and($state['storage_cap'])->toEqual(1000) ->and($state['storage_cap'])->toEqual(1000)

View File

@ -82,3 +82,11 @@ it('adds builders at the configured headquarters levels', function () {
->and($rules->builders(10))->toBe(3) ->and($rules->builders(10))->toBe(3)
->and($rules->builders(20))->toBe(4); ->and($rules->builders(20))->toBe(4);
}); });
it('adds building space for every headquarters level', function () {
$rules = new BuildingRules(gameConfig());
expect($rules->spaceMax(40, 0))->toBe(40)
->and($rules->spaceMax(40, 1))->toBe(60)
->and($rules->spaceMax(40, 30))->toBe(640);
});