diff --git a/app/Presenters/VillagePresenter.php b/app/Presenters/VillagePresenter.php index c751075..2e38126 100644 --- a/app/Presenters/VillagePresenter.php +++ b/app/Presenters/VillagePresenter.php @@ -125,6 +125,8 @@ final class VillagePresenter 'target_level' => $o->target_level, 'space' => $rules->space($o->type), '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, 'builder' => $o->builder, 'starts_at' => $o->starts_at ? self::iso($o->starts_at) : null, diff --git a/docs/architecture.md b/docs/architecture.md index 3ef7bf2..11ffb55 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -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 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. -- 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 diff --git a/tests/Feature/VillagersTest.php b/tests/Feature/VillagersTest.php index e8b0bae..b8ab828 100644 --- a/tests/Feature/VillagersTest.php +++ b/tests/Feature/VillagersTest.php @@ -91,6 +91,7 @@ it('refuses a new building without idle villagers for its workers, and the queue $state = shown($village); $options = collect($state['buildable'])->keyBy('type'); expect($state['population'])->toMatchArray(['idle' => 0, 'reserved' => 2]) + ->and($state['queue'][0]['villagers'])->toBe(2) ->and($options['clay_pit']['blocked'])->toBe('villagers') ->and($options['farm']['blocked'])->toBeNull() ->and(rule(fn () => app(QueueBuild::class)(owner($village), $village->id, 'clay_pit')))->toBe('villagers');