feat: every queued order carries the villagers it holds back, so the client can free them on cancel

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-11-03 09:44:25 +01:00
parent 75c3d49b04
commit 902ec8230f
3 changed files with 4 additions and 1 deletions

View File

@ -125,6 +125,8 @@ final class VillagePresenter
'target_level' => $o->target_level, 'target_level' => $o->target_level,
'space' => $rules->space($o->type), 'space' => $rules->space($o->type),
'cost' => $o->cost, 'cost' => $o->cost,
// Idle villagers the order holds back until it finishes (none for a demolition).
'villagers' => $o->action === BuildOrder::DEMOLISH ? 0 : $rules->extraWorkers($o->type, $o->target_level),
'position' => ++$position, 'position' => ++$position,
'builder' => $o->builder, 'builder' => $o->builder,
'starts_at' => $o->starts_at ? self::iso($o->starts_at) : null, 'starts_at' => $o->starts_at ? self::iso($o->starts_at) : null,

View File

@ -73,7 +73,7 @@ Population counts in heads. A head is one food per hour at world speed 1. Farms
- **A level needs villagers.** Queuing a new instance or an upgrade is refused (`villagers`) unless enough idle villagers stand ready for the workers it adds: workers(target) − workers(target − 1), all of level 1's for a new instance (`BuildingRules::extraWorkers`). Idle villagers are the villagers not drafted by a levy, minus the workers every standing building needs, minus what queued orders reserved, never below 0 (`Workforce::idle`). - **A level needs villagers.** Queuing a new instance or an upgrade is refused (`villagers`) unless enough idle villagers stand ready for the workers it adds: workers(target) − workers(target − 1), all of level 1's for a new instance (`BuildingRules::extraWorkers`). Idle villagers are the villagers not drafted by a levy, minus the workers every standing building needs, minus what queued orders reserved, never below 0 (`Workforce::idle`).
- A queued new instance or upgrade reserves its extra workers until it finishes or is cancelled, the way a new instance reserves its space. A demolition frees its workers when it finishes. - A queued new instance or upgrade reserves its extra workers until it finishes or is cancelled, the way a new instance reserves its space. A demolition frees its workers when it finishes.
- Farms are exempt: they need no idle villagers and reserve none. A farm brings more heads than it employs (lint), and without the exemption a full village could never grow. - Farms are exempt: they need no idle villagers and reserve none. A farm brings more heads than it employs (lint), and without the exemption a full village could never grow.
- Build options and upgrade offers carry `villagers` (the idle villagers they need, 0 for farms) and `blocked: 'villagers'` when there aren't enough. `population.idle` and `population.reserved` give the numbers. - Build options and upgrade offers carry `villagers` (the idle villagers they need, 0 for farms) and `blocked: 'villagers'` when there aren't enough. Every queued order carries the `villagers` it holds back. `population.idle` and `population.reserved` give the numbers.
### Copies ### Copies

View File

@ -91,6 +91,7 @@ it('refuses a new building without idle villagers for its workers, and the queue
$state = shown($village); $state = shown($village);
$options = collect($state['buildable'])->keyBy('type'); $options = collect($state['buildable'])->keyBy('type');
expect($state['population'])->toMatchArray(['idle' => 0, 'reserved' => 2]) expect($state['population'])->toMatchArray(['idle' => 0, 'reserved' => 2])
->and($state['queue'][0]['villagers'])->toBe(2)
->and($options['clay_pit']['blocked'])->toBe('villagers') ->and($options['clay_pit']['blocked'])->toBe('villagers')
->and($options['farm']['blocked'])->toBeNull() ->and($options['farm']['blocked'])->toBeNull()
->and(rule(fn () => app(QueueBuild::class)(owner($village), $village->id, 'clay_pit')))->toBe('villagers'); ->and(rule(fn () => app(QueueBuild::class)(owner($village), $village->id, 'clay_pit')))->toBe('villagers');