2026-10-28 18:17:34 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
use App\Game\Economy\Population;
|
|
|
|
|
|
use App\Game\Economy\Production;
|
|
|
|
|
|
use App\Game\Economy\Settle;
|
|
|
|
|
|
|
|
|
|
|
|
it('gives full output at full staffing and about a tenth when empty', function () {
|
|
|
|
|
|
$production = new Production(gameConfig());
|
|
|
|
|
|
|
|
|
|
|
|
expect($production->staffingFactor(1.0))->toBe(1.0)
|
|
|
|
|
|
->and($production->staffingFactor(0.0))->toEqualWithDelta(0.1, 0.001)
|
|
|
|
|
|
->and($production->staffingFactor(0.5))->toEqualWithDelta(exp(-1.15), 1e-9);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('adds buildings to the base trickle and nets food against upkeep', function () {
|
|
|
|
|
|
$config = gameConfig();
|
|
|
|
|
|
$buildings = [building(1, 'headquarters'), building(2, 'storage'), building(3, 'farm'), building(4, 'timber_camp')];
|
|
|
|
|
|
$workforce = (new Population($config))->workforce($buildings);
|
|
|
|
|
|
$rates = (new Production($config))->rates($buildings, $workforce);
|
|
|
|
|
|
|
|
|
|
|
|
expect($rates['wood'])->toBe(5.0 + 30.0)
|
|
|
|
|
|
->and($rates['clay'])->toBe(5.0)
|
|
|
|
|
|
->and($rates['iron'])->toBe(5.0)
|
2026-10-28 20:28:16 +00:00
|
|
|
|
->and($rates['food'])->toBe(30.0 - 24);
|
2026-10-28 18:17:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-31 09:56:59 +00:00
|
|
|
|
it('makes half in a copy and a quarter in the copy after it', function () {
|
|
|
|
|
|
$config = gameConfig();
|
|
|
|
|
|
$buildings = [building(1, 'farm', 10), building(2, 'timber_camp', 2), building(3, 'timber_camp', 2), building(4, 'timber_camp', 3)];
|
|
|
|
|
|
$workforce = (new Population($config))->workforce($buildings);
|
|
|
|
|
|
$rates = (new Production($config))->rates($buildings, $workforce);
|
|
|
|
|
|
|
|
|
|
|
|
// The level 3 camp ranks first, then the older level 2 one.
|
|
|
|
|
|
expect($workforce->workers())->toBe(array_sum($workforce->required))
|
|
|
|
|
|
->and($rates['wood'])->toEqualWithDelta(5 + 30 * 1.163 ** 2 + 30 * 1.163 * 0.5 + 30 * 1.163 * 0.25, 1e-9)
|
|
|
|
|
|
->and((new Production($config))->output($buildings[2], $workforce, share: 0.25)['per_hour'])->toEqualWithDelta(30 * 1.163 * 0.25, 1e-9);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-28 18:17:34 +00:00
|
|
|
|
it('makes less in an understaffed building', function () {
|
|
|
|
|
|
$config = gameConfig();
|
2026-10-28 21:26:25 +00:00
|
|
|
|
// 24 villagers (80% of 30 food) for a level 30 timber camp needing round(2 × 1.12^29) = 53.
|
2026-10-28 18:17:34 +00:00
|
|
|
|
$buildings = [building(1, 'farm'), building(2, 'timber_camp', 30)];
|
|
|
|
|
|
$workforce = (new Population($config))->workforce($buildings);
|
|
|
|
|
|
$production = new Production($config);
|
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
|
$ratio = 22 / 53;
|
2026-10-28 18:17:34 +00:00
|
|
|
|
expect($workforce->ratio(2))->toBe($ratio)
|
|
|
|
|
|
->and($production->output($buildings[1], $workforce)['per_hour'])
|
2026-10-28 21:26:25 +00:00
|
|
|
|
->toEqualWithDelta(30 * 1.163 ** 29 * exp(2.3 * ($ratio - 1)), 1e-6);
|
2026-10-28 18:17:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('settles stored amounts by rate and elapsed hours within the cap', function () {
|
|
|
|
|
|
$stored = ['wood' => 100.0, 'clay' => 990.0, 'iron' => 5.0, 'food' => 50.0];
|
|
|
|
|
|
$rates = ['wood' => 30.0, 'clay' => 30.0, 'iron' => -20.0, 'food' => 0.0];
|
|
|
|
|
|
|
|
|
|
|
|
expect(Settle::advance($stored, $rates, 1000.0, 0.5))
|
|
|
|
|
|
->toBe(['wood' => 115.0, 'clay' => 1000.0, 'iron' => 0.0, 'food' => 50.0]);
|
|
|
|
|
|
});
|
2026-11-03 08:38:20 +00:00
|
|
|
|
|
|
|
|
|
|
it('scales the food rate with world speed, both what farms make and what heads eat', function () {
|
|
|
|
|
|
$config = gameConfig(['world' => ['speed' => 100]]);
|
|
|
|
|
|
$buildings = [building(1, 'headquarters'), building(2, 'storage'), building(3, 'farm')];
|
|
|
|
|
|
$workforce = (new Population($config))->workforce($buildings);
|
|
|
|
|
|
$rates = (new Production($config))->rates($buildings, $workforce);
|
|
|
|
|
|
|
|
|
|
|
|
// 24 villagers (heads) on every speed; the farm makes 3000 food/h and they eat 2400.
|
|
|
|
|
|
expect($workforce->villagers)->toBe(24)
|
|
|
|
|
|
->and($rates['food'])->toEqual((30 - 24) * 100)
|
|
|
|
|
|
->and($rates['wood'])->toEqual(5 * 100);
|
|
|
|
|
|
});
|