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) ->and($rates['food'])->toBe(30.0 - 24); }); 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); }); it('makes less in an understaffed building', function () { $config = gameConfig(); // 24 villagers (80% of 30 food) for a level 30 timber camp needing round(2 × 1.12^29) = 53. $buildings = [building(1, 'farm'), building(2, 'timber_camp', 30)]; $workforce = (new Population($config))->workforce($buildings); $production = new Production($config); $ratio = 22 / 53; expect($workforce->ratio(2))->toBe($ratio) ->and($production->output($buildings[1], $workforce)['per_hour']) ->toEqualWithDelta(30 * 1.163 ** 29 * exp(2.3 * ($ratio - 1)), 1e-6); }); 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]); }); 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); });