feat: basic buildings have no requirements; build options list what is missing
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4fa6b46f62
commit
0aa8a3abfc
|
|
@ -199,13 +199,24 @@ final class Simulation
|
||||||
|
|
||||||
public function meetsRequirements(string $type): bool
|
public function meetsRequirements(string $type): bool
|
||||||
{
|
{
|
||||||
|
return $this->missingRequirements($type) === [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requirements of a type that no building in the village meets yet.
|
||||||
|
*
|
||||||
|
* @return list<array{type: string, level: int}>
|
||||||
|
*/
|
||||||
|
public function missingRequirements(string $type): array
|
||||||
|
{
|
||||||
|
$missing = [];
|
||||||
foreach ($this->rules->requires($type) as $needed => $level) {
|
foreach ($this->rules->requires($type) as $needed => $level) {
|
||||||
if (! $this->village->buildings->where('type', $needed)->where('level', '>=', $level)->count()) {
|
if (! $this->village->buildings->where('type', $needed)->where('level', '>=', $level)->count()) {
|
||||||
return false;
|
$missing[] = ['type' => $needed, 'level' => $level];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return $missing;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array{target_level: int, cost: array<string, int>, seconds: int, blocked: null}|null */
|
/** @return array{target_level: int, cost: array<string, int>, seconds: int, blocked: null}|null */
|
||||||
|
|
@ -247,7 +258,7 @@ final class Simulation
|
||||||
$max = $this->rules->maxPerVillage($type);
|
$max = $this->rules->maxPerVillage($type);
|
||||||
$blocked = match (true) {
|
$blocked = match (true) {
|
||||||
$max !== null && $this->instances($type) >= $max => 'max_per_village',
|
$max !== null && $this->instances($type) >= $max => 'max_per_village',
|
||||||
! $this->meetsRequirements($type) => 'requires',
|
$this->missingRequirements($type) !== [] => 'requires',
|
||||||
! $this->spaceFits($type) => 'no_space',
|
! $this->spaceFits($type) => 'no_space',
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
|
|
@ -259,6 +270,8 @@ final class Simulation
|
||||||
'cost' => $this->rules->cost($type, 0, $this->instanceIndex($type)),
|
'cost' => $this->rules->cost($type, 0, $this->instanceIndex($type)),
|
||||||
'seconds' => $this->rules->buildSeconds($type, 0, $this->hqLevel(), $this->hqStaffing()),
|
'seconds' => $this->rules->buildSeconds($type, 0, $this->hqLevel(), $this->hqStaffing()),
|
||||||
'blocked' => $blocked,
|
'blocked' => $blocked,
|
||||||
|
// What is still missing, for the "not yet available" list.
|
||||||
|
'requires' => $this->missingRequirements($type),
|
||||||
];
|
];
|
||||||
}, $this->config->buildingTypes());
|
}, $this->config->buildingTypes());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ return [
|
||||||
'production' => null,
|
'production' => null,
|
||||||
'instance_cost_factor' => 1.0,
|
'instance_cost_factor' => 1.0,
|
||||||
'points' => ['base' => 8, 'factor' => 1.2],
|
'points' => ['base' => 8, 'factor' => 1.2],
|
||||||
'requires' => ['headquarters' => 1],
|
'requires' => [],
|
||||||
],
|
],
|
||||||
'rally_point' => [
|
'rally_point' => [
|
||||||
'space' => 1,
|
'space' => 1,
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ When upkeep exceeds income, food stock drains. The engine computes the exact mom
|
||||||
- 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.
|
||||||
- Multiple instances per type are allowed. `max_per_village` limits types that must stay unique (HQ, rally point, wall). `instance_cost_factor` makes the n-th instance of a type more expensive, so many cheap copies don't beat upgrading.
|
- Multiple instances per type are allowed. `max_per_village` limits types that must stay unique (HQ, rally point, wall). `instance_cost_factor` makes the n-th instance of a type more expensive, so many cheap copies don't beat upgrading.
|
||||||
|
- 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). Below level 0 the instance is removed and its space is freed.
|
- Demolishing goes through the build queue. It lowers an instance by one level and refunds `demolish_refund` × that level's cost (default 0.5). Below level 0 the instance is removed and its space is freed.
|
||||||
- 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.
|
||||||
|
|
@ -115,7 +116,7 @@ A building entry looks like this (numbers start TW-like):
|
||||||
'build_time' => ['base' => 900, 'factor' => 1.2], // seconds at world speed 1
|
'build_time' => ['base' => 900, 'factor' => 1.2], // seconds at world speed 1
|
||||||
'workers' => ['base' => 2, 'factor' => 1.12],
|
'workers' => ['base' => 2, 'factor' => 1.12],
|
||||||
'production' => ['resource' => 'wood', 'base' => 30, 'factor' => 1.163],
|
'production' => ['resource' => 'wood', 'base' => 30, 'factor' => 1.163],
|
||||||
'requires' => ['headquarters' => 1],
|
'requires' => [],
|
||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ Each milestone ends with tests green, `ConfigLint` green, and something playable
|
||||||
## M3: Units, upkeep, starvation
|
## M3: Units, upkeep, starvation
|
||||||
|
|
||||||
- [ ] `config/game/units.php`: spear, sword, archer, light cav, heavy cav, ram, catapult, nobleman, with food upkeep
|
- [ ] `config/game/units.php`: spear, sword, archer, light cav, heavy cav, ram, catapult, nobleman, with food upkeep
|
||||||
- [ ] Barracks, stable, workshop, academy as building instances (several barracks run parallel recruit queues)
|
- [ ] Barracks, stable, workshop, academy as building instances (several barracks run parallel recruit queues); only these advanced buildings get requirements, e.g. academy needs headquarters + barracks
|
||||||
- [ ] Recruiting turns villagers into soldiers; lazy per-unit completion
|
- [ ] Recruiting turns villagers into soldiers; lazy per-unit completion
|
||||||
- [ ] Levy: draft workers as militia, automatic return
|
- [ ] Levy: draft workers as militia, automatic return
|
||||||
- [ ] Starvation: zero-crossing event, grace timer, desertion order
|
- [ ] Starvation: zero-crossing event, grace timer, desertion order
|
||||||
|
|
|
||||||
|
|
@ -64,15 +64,26 @@ it('refuses a building that does not fit the free building space', function () {
|
||||||
->and(collect($state['buildable'])->firstWhere('type', 'hiding_place')['blocked'])->toBe('no_space');
|
->and(collect($state['buildable'])->firstWhere('type', 'hiding_place')['blocked'])->toBe('no_space');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('refuses a second headquarters, a wall without HQ 1 and what it cannot pay', function () {
|
it('refuses a second headquarters and what it cannot pay, but lets the wall be built right away', function () {
|
||||||
$village = startVillage();
|
$village = startVillage();
|
||||||
$village->update(['wood' => 10]);
|
|
||||||
|
|
||||||
|
expect(collect(shown($village)['buildable'])->firstWhere('type', 'wall'))->toMatchArray(['blocked' => null, 'requires' => []]);
|
||||||
|
|
||||||
|
$village->update(['wood' => 10]);
|
||||||
expect(rule(fn () => app(QueueBuild::class)(owner($village), $village->id, 'headquarters')))->toBe('max_per_village')
|
expect(rule(fn () => app(QueueBuild::class)(owner($village), $village->id, 'headquarters')))->toBe('max_per_village')
|
||||||
->and(rule(fn () => app(QueueBuild::class)(owner($village), $village->id, 'wall')))->toBe('requires')
|
|
||||||
->and(rule(fn () => app(QueueBuild::class)(owner($village), $village->id, 'storage')))->toBe('resources');
|
->and(rule(fn () => app(QueueBuild::class)(owner($village), $village->id, 'storage')))->toBe('resources');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('lists the requirements an advanced building still misses', function () {
|
||||||
|
// No M1 building has requirements; advanced ones (barracks, academy) will.
|
||||||
|
config(['game.buildings.rally_point.requires' => ['headquarters' => 3, 'storage' => 0]]);
|
||||||
|
$village = startVillage();
|
||||||
|
|
||||||
|
expect(collect(shown($village)['buildable'])->firstWhere('type', 'rally_point'))
|
||||||
|
->toMatchArray(['blocked' => 'requires', 'requires' => [['type' => 'headquarters', 'level' => 3]]])
|
||||||
|
->and(rule(fn () => app(QueueBuild::class)(owner($village), $village->id, 'rally_point')))->toBe('requires');
|
||||||
|
});
|
||||||
|
|
||||||
it('makes a later instance of a type cost more', function () {
|
it('makes a later instance of a type cost more', function () {
|
||||||
$village = startVillage();
|
$village = startVillage();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,6 @@ it('shows a start village to its owner only', function () {
|
||||||
->and($state['population'])->toEqual(['food_budget' => 30, 'upkeep' => 30, 'villagers' => 30, 'workers' => 5, 'soldiers' => 0])
|
->and($state['population'])->toEqual(['food_budget' => 30, 'upkeep' => 30, 'villagers' => 30, 'workers' => 5, 'soldiers' => 0])
|
||||||
->and($state['builders'])->toBe(2)
|
->and($state['builders'])->toBe(2)
|
||||||
->and(collect($state['buildable'])->firstWhere('type', 'headquarters')['blocked'])->toBe('max_per_village')
|
->and(collect($state['buildable'])->firstWhere('type', 'headquarters')['blocked'])->toBe('max_per_village')
|
||||||
->and(collect($state['buildable'])->firstWhere('type', 'wall')['blocked'])->toBe('requires')
|
->and(collect($state['buildable'])->firstWhere('type', 'wall')['blocked'])->toBeNull()
|
||||||
->and(rule(fn () => app(ShowVillage::class)(User::factory()->create(), $village->id)))->toBe('not_found');
|
->and(rule(fn () => app(ShowVillage::class)(User::factory()->create(), $village->id)))->toBe('not_found');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue