2026-10-28 18:17:34 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
use App\Game\Economy\Population;
|
|
|
|
|
|
|
2026-10-28 20:28:16 +00:00
|
|
|
|
it('feeds villagers from the share of farm output, leaving a surplus', function () {
|
2026-10-28 18:17:34 +00:00
|
|
|
|
$population = new Population(gameConfig());
|
2026-10-28 21:26:25 +00:00
|
|
|
|
$workforce = $population->workforce([building(1, 'farm'), building(2, 'farm', 2)]);
|
2026-10-28 18:17:34 +00:00
|
|
|
|
|
2026-10-31 09:56:59 +00:00
|
|
|
|
// Budget 37.5 from the level 2 farm and half of the copy's 30 = 52.5 food/h;
|
|
|
|
|
|
// villagers fill 80% of it.
|
|
|
|
|
|
expect($workforce->foodBudget)->toBe(30 * 1.25 + 30 * 0.5)
|
|
|
|
|
|
->and($workforce->villagers)->toBe(42)
|
|
|
|
|
|
->and($workforce->upkeep)->toEqual(42);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('counts a copy farm at its share in the budget, but staffs it in full', function () {
|
|
|
|
|
|
$population = new Population(gameConfig());
|
|
|
|
|
|
$one = $population->workforce([building(1, 'farm', 10)]);
|
|
|
|
|
|
$two = $population->workforce([building(1, 'farm', 10), building(2, 'farm', 10)]);
|
|
|
|
|
|
|
|
|
|
|
|
expect($two->foodBudget)->toBe($one->foodBudget * 1.5)
|
|
|
|
|
|
->and($two->required)->toBe([1 => 5, 2 => 5])
|
|
|
|
|
|
->and($two->assigned)->toBe([1 => 5, 2 => 5]);
|
2026-10-28 18:17:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-28 20:28:16 +00:00
|
|
|
|
it('leaves soldiers upkeep out of the villagers share', function () {
|
2026-10-28 18:17:34 +00:00
|
|
|
|
$workforce = (new Population(gameConfig()))->workforce([building(1, 'farm')], soldierUpkeep: 10);
|
|
|
|
|
|
|
2026-10-28 20:28:16 +00:00
|
|
|
|
expect($workforce->villagers)->toBe(14)
|
|
|
|
|
|
->and($workforce->upkeep)->toEqual(24);
|
2026-10-28 18:17:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-28 20:55:44 +00:00
|
|
|
|
it('keeps drafted militia out of work, but they still eat', function () {
|
|
|
|
|
|
// 24 villagers; 20 drafted leave 4, which go to the farm (2) first.
|
|
|
|
|
|
$buildings = [building(1, 'clay_pit', 30), building(2, 'farm')];
|
|
|
|
|
|
$workforce = (new Population(gameConfig()))->workforce($buildings, militia: 20);
|
|
|
|
|
|
|
|
|
|
|
|
expect($workforce->assigned)->toBe([1 => 2, 2 => 2])
|
|
|
|
|
|
->and($workforce->militia)->toBe(20)
|
|
|
|
|
|
->and($workforce->undrafted())->toBe(4)
|
|
|
|
|
|
->and($workforce->upkeep)->toEqual(24);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('drafts no more militia than there are villagers', function () {
|
|
|
|
|
|
$workforce = (new Population(gameConfig()))->workforce([building(1, 'farm')], soldierUpkeep: 20, militia: 10);
|
|
|
|
|
|
|
|
|
|
|
|
expect($workforce->villagers)->toBe(4)
|
|
|
|
|
|
->and($workforce->militia)->toBe(4)
|
|
|
|
|
|
->and($workforce->workers())->toBe(0);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-28 18:17:34 +00:00
|
|
|
|
it('staffs farms first, then by priority', function () {
|
2026-10-28 21:26:25 +00:00
|
|
|
|
// A level 1 farm makes 30 food, so 24 villagers: the farm takes 2, priority 9 the other 22.
|
2026-10-28 18:17:34 +00:00
|
|
|
|
$buildings = [
|
|
|
|
|
|
building(1, 'timber_camp', 30, priority: 1),
|
|
|
|
|
|
building(2, 'clay_pit', 30, priority: 9),
|
2026-10-28 21:26:25 +00:00
|
|
|
|
building(3, 'farm', 1, priority: 0),
|
2026-10-28 18:17:34 +00:00
|
|
|
|
];
|
|
|
|
|
|
$workforce = (new Population(gameConfig()))->workforce($buildings);
|
|
|
|
|
|
|
2026-10-28 20:28:16 +00:00
|
|
|
|
expect($workforce->assigned)->toBe([1 => 0, 2 => 22, 3 => 2])
|
|
|
|
|
|
->and($workforce->workers())->toBe(24);
|
2026-10-28 18:17:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('splits villagers evenly between buildings of equal priority', function () {
|
2026-10-28 21:26:25 +00:00
|
|
|
|
// 24 villagers: farm takes 2, the two level-21 camps (19 each) share 22.
|
2026-10-28 18:17:34 +00:00
|
|
|
|
$buildings = [
|
|
|
|
|
|
building(1, 'farm'),
|
2026-10-28 21:26:25 +00:00
|
|
|
|
building(2, 'timber_camp', 21),
|
|
|
|
|
|
building(3, 'clay_pit', 21),
|
2026-10-28 18:17:34 +00:00
|
|
|
|
];
|
|
|
|
|
|
$workforce = (new Population(gameConfig()))->workforce($buildings);
|
|
|
|
|
|
|
2026-10-28 20:28:16 +00:00
|
|
|
|
expect($workforce->assigned)->toBe([1 => 2, 2 => 11, 3 => 11])
|
|
|
|
|
|
->and($workforce->ratio(2))->toBe(11 / 19);
|
2026-10-28 18:17:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('counts buildings that need nobody as fully staffed', function () {
|
|
|
|
|
|
$workforce = (new Population(gameConfig()))->workforce([building(1, 'hiding_place')]);
|
|
|
|
|
|
|
|
|
|
|
|
expect($workforce->villagers)->toBe(0)
|
|
|
|
|
|
->and($workforce->ratio(1))->toBe(1.0);
|
|
|
|
|
|
});
|
2026-11-03 08:38:20 +00:00
|
|
|
|
|
|
|
|
|
|
it('counts idle villagers: not drafted, not needed by the buildings, not reserved', function () {
|
|
|
|
|
|
// 24 villagers; headquarters 2, storage 1 and farm 2 need 5.
|
|
|
|
|
|
$buildings = [building(1, 'headquarters'), building(2, 'storage'), building(3, 'farm')];
|
|
|
|
|
|
$population = new Population(gameConfig());
|
|
|
|
|
|
$workforce = $population->workforce($buildings);
|
|
|
|
|
|
$drafted = $population->workforce($buildings, militia: 20);
|
|
|
|
|
|
// A level 30 camp needs 53 alone: understaffed, and nobody is idle.
|
|
|
|
|
|
$short = $population->workforce([...$buildings, building(4, 'timber_camp', 30)]);
|
|
|
|
|
|
|
|
|
|
|
|
expect($workforce->idle())->toBe(19)
|
|
|
|
|
|
->and($workforce->idle(4))->toBe(15)
|
|
|
|
|
|
->and($workforce->idle(30))->toBe(0)
|
|
|
|
|
|
->and($drafted->idle())->toBe(0)
|
|
|
|
|
|
->and($short->idle())->toBe(0);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('holds the same heads on every world speed', function () {
|
|
|
|
|
|
$buildings = [building(1, 'farm', 5), building(2, 'headquarters', 3)];
|
|
|
|
|
|
$slow = (new Population(gameConfig()))->workforce($buildings, soldierUpkeep: 12);
|
|
|
|
|
|
$fast = (new Population(gameConfig(['world' => ['speed' => 100]])))->workforce($buildings, soldierUpkeep: 12);
|
|
|
|
|
|
|
|
|
|
|
|
// Farm 5 feeds 30 × 1.25^4 = 73.24 heads; 80% is 58.6, soldiers take 12.
|
|
|
|
|
|
expect($fast->foodBudget)->toBe($slow->foodBudget)
|
|
|
|
|
|
->and($fast->foodBudget)->toEqualWithDelta(73.24, 0.01)
|
|
|
|
|
|
->and($fast->villagers)->toBe($slow->villagers)
|
|
|
|
|
|
->and($fast->villagers)->toBe(46)
|
|
|
|
|
|
->and($fast->upkeep)->toEqual(46 + 12);
|
|
|
|
|
|
});
|