feat: levels start at 1, like Die Stämme; level 1 has the base values

Every per-level formula uses level - 1 as its exponent, so a building at level n
costs, makes and scores what it did at level n - 1. The migration shifts stored
levels and queued orders up by one; removing an instance now targets level 0.
Building space: 40 at HQ level 1, plus 20 per level above.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-28 22:26:25 +01:00
parent 65a4e4b5d4
commit 8877c6f505
22 changed files with 135 additions and 103 deletions

View File

@ -27,7 +27,7 @@ final class JoinWorld
$taken = VillageFactory::takenSpots($world); $taken = VillageFactory::takenSpots($world);
[$x, $y] = VillageFactory::spawnSpot($world, $taken); [$x, $y] = VillageFactory::spawnSpot($world, $taken);
$levels = array_fill_keys($world->gameConfig()->get('world.village.start_buildings'), 0); $levels = array_fill_keys($world->gameConfig()->get('world.village.start_buildings'), 1);
return $this->villages->create($world, $player, "{$user->name}'s village", $x, $y, $levels); return $this->villages->create($world, $player, "{$user->name}'s village", $x, $y, $levels);
}); });

View File

@ -9,7 +9,7 @@ use App\Models\User;
use App\Models\Village; use App\Models\Village;
use Carbon\CarbonImmutable; use Carbon\CarbonImmutable;
/** Queue a new instance at level 0 if its building space is free. Pays up front. */ /** Queue a new instance at level 1 if its building space is free. Pays up front. */
final class QueueBuild extends VillageAction final class QueueBuild extends VillageAction
{ {
public function __invoke(User $user, int $villageId, string $type): Village public function __invoke(User $user, int $villageId, string $type): Village
@ -30,13 +30,13 @@ final class QueueBuild extends VillageAction
throw new GameRuleViolation('no_space', 'Not enough building space.'); throw new GameRuleViolation('no_space', 'Not enough building space.');
} }
$cost = $rules->cost($type, 0, $sim->instanceIndex($type)); $cost = $rules->cost($type, 1, $sim->instanceIndex($type));
$sim->pay($cost); $sim->pay($cost);
$sim->enqueue([ $sim->enqueue([
'building_id' => null, 'building_id' => null,
'type' => $type, 'type' => $type,
'action' => BuildOrder::BUILD, 'action' => BuildOrder::BUILD,
'target_level' => 0, 'target_level' => 1,
'cost' => $cost, 'cost' => $cost,
], $now); ], $now);
}); });

View File

@ -17,7 +17,7 @@ final class QueueDemolish extends VillageAction
return $this->mutate($user, $villageId, function (Simulation $sim, Village $village, CarbonImmutable $now) use ($buildingId) { return $this->mutate($user, $villageId, function (Simulation $sim, Village $village, CarbonImmutable $now) use ($buildingId) {
$building = $this->building($village, $buildingId); $building = $this->building($village, $buildingId);
$offer = $sim->demolishOffer($building) $offer = $sim->demolishOffer($building)
?? throw new GameRuleViolation('core_building', 'Core buildings cannot go below level 0.'); ?? throw new GameRuleViolation('core_building', 'Core buildings cannot go below level 1.');
// A smaller headquarters means less building space; what stands must still fit. // A smaller headquarters means less building space; what stands must still fit.
if ($building->type === 'headquarters' if ($building->type === 'headquarters'
&& $sim->spaceUsed() > $sim->rules()->spaceMax($village->space, $offer['target_level'])) { && $sim->spaceUsed() > $sim->rules()->spaceMax($village->space, $offer['target_level'])) {

View File

@ -66,7 +66,7 @@ final class SeedBarbarians
$taken["$x|$y"] = true; $taken["$x|$y"] = true;
$levels = []; $levels = [];
foreach (self::BUILDINGS as $type) { foreach (self::BUILDINGS as $type) {
$levels[$type] = mt_rand(0, $config['max_level']); $levels[$type] = mt_rand(1, $config['max_level']);
} }
$this->villages->create($world, null, 'Barbarian village', $x, $y, $levels); $this->villages->create($world, null, 'Barbarian village', $x, $y, $levels);
$created++; $created++;

View File

@ -182,7 +182,7 @@ final class Simulation
return $this->village->buildings->where('type', $type)->where('id', '<', $building->id)->count(); return $this->village->buildings->where('type', $type)->where('id', '<', $building->id)->count();
} }
/** Level after everything already queued for this instance; -1 if it is being removed. */ /** Level after everything already queued for this instance; 0 if it is being removed. */
public function queuedLevel(Building $building): int public function queuedLevel(Building $building): int
{ {
return $this->village->orders->where('building_id', $building->id)->last()?->target_level ?? $building->level; return $this->village->orders->where('building_id', $building->id)->last()?->target_level ?? $building->level;
@ -214,7 +214,7 @@ final class Simulation
return $this->spaceUsed() + $this->rules->space($type) <= $this->spaceMax(); return $this->spaceUsed() + $this->rules->space($type) <= $this->spaceMax();
} }
/** The headquarters, and the last storage or farm, never go below level 0. */ /** The headquarters, and the last storage or farm, never go below level 1. */
public function isCore(Building $building): bool public function isCore(Building $building): bool
{ {
if ($building->type === 'headquarters') { if ($building->type === 'headquarters') {
@ -251,7 +251,7 @@ final class Simulation
public function upgradeOffer(Building $building): ?array public function upgradeOffer(Building $building): ?array
{ {
$current = $this->queuedLevel($building); $current = $this->queuedLevel($building);
if ($current < 0 || $current >= $this->rules->maxLevel($building->type)) { if ($current < 1 || $current >= $this->rules->maxLevel($building->type)) {
return null; return null;
} }
$target = $current + 1; $target = $current + 1;
@ -268,7 +268,7 @@ final class Simulation
public function demolishOffer(Building $building): ?array public function demolishOffer(Building $building): ?array
{ {
$current = $this->queuedLevel($building); $current = $this->queuedLevel($building);
if ($current < 0 || ($current === 0 && $this->isCore($building))) { if ($current < 1 || ($current === 1 && $this->isCore($building))) {
return null; return null;
} }
@ -294,9 +294,9 @@ final class Simulation
return [ return [
'type' => $type, 'type' => $type,
'space' => $this->rules->space($type), 'space' => $this->rules->space($type),
'target_level' => 0, 'target_level' => 1,
'cost' => $this->rules->cost($type, 0, $this->instanceIndex($type)), 'cost' => $this->rules->cost($type, 1, $this->instanceIndex($type)),
'seconds' => $this->rules->buildSeconds($type, 0, $this->hqLevel(), $this->hqStaffing()), 'seconds' => $this->rules->buildSeconds($type, 1, $this->hqLevel(), $this->hqStaffing()),
'blocked' => $blocked, 'blocked' => $blocked,
// What is still missing, for the "not yet available" list. // What is still missing, for the "not yet available" list.
'requires' => $this->missingRequirements($type), 'requires' => $this->missingRequirements($type),
@ -362,7 +362,7 @@ final class Simulation
$this->removeOrder($order); $this->removeOrder($order);
if ($order->action === BuildOrder::BUILD) { if ($order->action === BuildOrder::BUILD) {
$building = $this->village->buildings()->create(['type' => $order->type, 'level' => 0]); $building = $this->village->buildings()->create(['type' => $order->type, 'level' => 1]);
$this->village->buildings->push($building->refresh()); $this->village->buildings->push($building->refresh());
return; return;
@ -376,7 +376,7 @@ final class Simulation
$this->refund($this->rules->demolishRefund($building->type, $building->level, $this->instanceIndex($building->type, $building))); $this->refund($this->rules->demolishRefund($building->type, $building->level, $this->instanceIndex($building->type, $building)));
} }
$building->level = $order->target_level; $building->level = $order->target_level;
if ($building->level < 0) { if ($building->level < 1) {
// Units still in training there go back to being villagers, with a refund. // Units still in training there go back to being villagers, with a refund.
foreach ($this->village->recruits->where('building_id', $building->id) as $order) { foreach ($this->village->recruits->where('building_id', $building->id) as $order) {
$this->refund(array_map(fn (int $n) => $n * ($order->count - $order->done), $order->cost)); $this->refund(array_map(fn (int $n) => $n * ($order->count - $order->done), $order->cost));

View File

@ -4,11 +4,20 @@ namespace App\Game\Buildings;
use App\Game\WorldConfig; use App\Game\WorldConfig;
/** Cost, time, workers, output and capacity of a building type per level. */ /**
* Cost, time, workers, output and capacity of a building type per level. Levels start
* at 1: level 1 has the base values, and every level above multiplies by the factor.
*/
final class BuildingRules final class BuildingRules
{ {
public function __construct(private readonly WorldConfig $config) {} public function __construct(private readonly WorldConfig $config) {}
/** Levels above the first, the exponent of every per-level factor. */
public static function above(int $level): int
{
return max(0, $level - 1);
}
/** /**
* Cost of reaching $level for the $instance-th instance of the type (0-based). * Cost of reaching $level for the $instance-th instance of the type (0-based).
* *
@ -17,7 +26,7 @@ final class BuildingRules
public function cost(string $type, int $level, int $instance = 0): array public function cost(string $type, int $level, int $instance = 0): array
{ {
$cost = $this->config->building($type)['cost']; $cost = $this->config->building($type)['cost'];
$multiplier = $cost['factor'] ** $level * $this->instanceFactor($type) ** $instance; $multiplier = $cost['factor'] ** self::above($level) * $this->instanceFactor($type) ** $instance;
return [ return [
'wood' => (int) round($cost['wood'] * $multiplier), 'wood' => (int) round($cost['wood'] * $multiplier),
@ -33,15 +42,15 @@ final class BuildingRules
public function buildSeconds(string $type, int $level, int $hqLevel, float $hqStaffing): int public function buildSeconds(string $type, int $level, int $hqLevel, float $hqStaffing): int
{ {
$time = $this->config->building($type)['build_time']; $time = $this->config->building($type)['build_time'];
$seconds = $time['base'] * $time['factor'] ** $level $seconds = $time['base'] * $time['factor'] ** self::above($level)
/ $this->config->speed() / $this->config->speed()
/ (1 + $this->config->get('economy.hq_build_speed_per_level', 0) * $hqLevel) / (1 + $this->config->get('economy.hq_build_speed_per_level', 0) * self::above($hqLevel))
/ max($hqStaffing, 0.01); / max($hqStaffing, 0.01);
return max(1, (int) ceil($seconds)); return max(1, (int) ceil($seconds));
} }
/** Seconds to take $level down by one. */ /** Seconds to take $level down by one (level 1 down means removing the instance). */
public function demolishSeconds(string $type, int $level, int $hqLevel, float $hqStaffing): int public function demolishSeconds(string $type, int $level, int $hqLevel, float $hqStaffing): int
{ {
$factor = $this->config->get('economy.demolish_time_factor', 0.5); $factor = $this->config->get('economy.demolish_time_factor', 0.5);
@ -61,7 +70,7 @@ final class BuildingRules
{ {
$workers = $this->config->building($type)['workers']; $workers = $this->config->building($type)['workers'];
return (int) round($workers['base'] * $workers['factor'] ** $level); return (int) round($workers['base'] * $workers['factor'] ** self::above($level));
} }
/** /**
@ -78,7 +87,7 @@ final class BuildingRules
return [ return [
'resource' => $production['resource'], 'resource' => $production['resource'],
'per_hour' => $production['base'] * $production['factor'] ** $level * $this->config->speed(), 'per_hour' => $production['base'] * $production['factor'] ** self::above($level) * $this->config->speed(),
]; ];
} }
@ -87,7 +96,7 @@ final class BuildingRules
{ {
$capacity = $this->config->building($type)['capacity'] ?? null; $capacity = $this->config->building($type)['capacity'] ?? null;
return $capacity ? $capacity['base'] * $capacity['factor'] ** $level : 0.0; return $capacity ? $capacity['base'] * $capacity['factor'] ** self::above($level) : 0.0;
} }
/** Points an instance at this level adds to its village. */ /** Points an instance at this level adds to its village. */
@ -95,7 +104,7 @@ final class BuildingRules
{ {
$points = $this->config->building($type)['points']; $points = $this->config->building($type)['points'];
return (int) round($points['base'] * $points['factor'] ** $level); return (int) round($points['base'] * $points['factor'] ** self::above($level));
} }
/** Building space one instance takes, at every level. */ /** Building space one instance takes, at every level. */
@ -107,7 +116,7 @@ final class BuildingRules
/** A village's building space with its headquarters at this level; $base is the village's own. */ /** A village's building space with its headquarters at this level; $base is the village's own. */
public function spaceMax(int $base, int $hqLevel): int public function spaceMax(int $base, int $hqLevel): int
{ {
return $base + $this->config->get('world.village.space_per_hq_level', 0) * max(0, $hqLevel); return $base + $this->config->get('world.village.space_per_hq_level', 0) * self::above($hqLevel);
} }
/** /**

View File

@ -49,7 +49,7 @@ final class ConfigLint
*/ */
private static function startVillageFits(WorldConfig $config, BuildingRules $rules): array private static function startVillageFits(WorldConfig $config, BuildingRules $rules): array
{ {
// The headquarters starts at level 0, so the start village has the base space. // The headquarters starts at level 1, so the start village has the base space.
$max = $config->get('world.village.space'); $max = $config->get('world.village.space');
if ($config->get('world.village.space_per_hq_level', 0) < 0) { if ($config->get('world.village.space_per_hq_level', 0) < 0) {
return ['[world.village.space_per_hq_level] cannot be negative, or upgrading the headquarters would squeeze the village.']; return ['[world.village.space_per_hq_level] cannot be negative, or upgrading the headquarters would squeeze the village.'];
@ -94,10 +94,10 @@ final class ConfigLint
$problems = []; $problems = [];
$perVillager = $config->get('economy.upkeep.villager', 1); $perVillager = $config->get('economy.upkeep.villager', 1);
foreach ($config->buildingTypes() as $type) { foreach ($config->buildingTypes() as $type) {
if (($rules->output($type, 0)['resource'] ?? null) !== 'food') { if (($rules->output($type, 1)['resource'] ?? null) !== 'food') {
continue; continue;
} }
for ($level = 0; $level <= $rules->maxLevel($type); $level++) { for ($level = 1; $level <= $rules->maxLevel($type); $level++) {
$output = $rules->output($type, $level)['per_hour']; $output = $rules->output($type, $level)['per_hour'];
if ($output <= 0 || $rules->workers($type, $level) * $perVillager >= $output) { if ($output <= 0 || $rules->workers($type, $level) * $perVillager >= $output) {
$problems[] = "[$type] level $level feeds fewer people than it needs as workers."; $problems[] = "[$type] level $level feeds fewer people than it needs as workers.";
@ -114,21 +114,21 @@ final class ConfigLint
*/ */
private static function costsFitStorage(WorldConfig $config, BuildingRules $rules): array private static function costsFitStorage(WorldConfig $config, BuildingRules $rules): array
{ {
$storages = array_filter($config->buildingTypes(), fn (string $t) => $rules->capacity($t, 0) > 0); $storages = array_filter($config->buildingTypes(), fn (string $t) => $rules->capacity($t, 1) > 0);
if (! $storages) { if (! $storages) {
return ['No building type provides storage.']; return ['No building type provides storage.'];
} }
$problems = []; $problems = [];
$maxCap = max(array_map(fn (string $t) => $rules->capacity($t, $rules->maxLevel($t)), $storages)); $maxCap = max(array_map(fn (string $t) => $rules->capacity($t, $rules->maxLevel($t)), $storages));
foreach ($config->buildingTypes() as $type) { foreach ($config->buildingTypes() as $type) {
for ($level = 0; $level <= $rules->maxLevel($type); $level++) { for ($level = 1; $level <= $rules->maxLevel($type); $level++) {
if (max($rules->cost($type, $level)) > $maxCap) { if (max($rules->cost($type, $level)) > $maxCap) {
$problems[] = "[$type] level $level costs more than the largest storage holds."; $problems[] = "[$type] level $level costs more than the largest storage holds.";
} }
} }
} }
foreach ($storages as $type) { foreach ($storages as $type) {
for ($level = 0; $level < $rules->maxLevel($type); $level++) { for ($level = 1; $level < $rules->maxLevel($type); $level++) {
if (max($rules->cost($type, $level + 1)) > $rules->capacity($type, $level)) { if (max($rules->cost($type, $level + 1)) > $rules->capacity($type, $level)) {
$problems[] = "[$type] level ".($level + 1)." costs more than level $level holds."; $problems[] = "[$type] level ".($level + 1)." costs more than level $level holds.";
} }

View File

@ -2,6 +2,7 @@
namespace App\Game\Military; namespace App\Game\Military;
use App\Game\Buildings\BuildingRules;
use App\Game\WorldConfig; use App\Game\WorldConfig;
/** What units cost, eat and take to train, and where they are trained. */ /** What units cost, eat and take to train, and where they are trained. */
@ -51,7 +52,7 @@ final class UnitRules
{ {
$seconds = $this->unit($unit)['build_time'] $seconds = $this->unit($unit)['build_time']
/ $this->config->speed() / $this->config->speed()
/ (1 + $this->config->get('economy.recruit_speed_per_level', 0) * $buildingLevel) / (1 + $this->config->get('economy.recruit_speed_per_level', 0) * BuildingRules::above($buildingLevel))
/ max($staffing, 0.01); / max($staffing, 0.01);
return max(1, (int) ceil($seconds)); return max(1, (int) ceil($seconds));

View File

@ -2,7 +2,7 @@
// Units, with Die Stämme-like stats. A unit is trained from one villager at its building // Units, with Die Stämme-like stats. A unit is trained from one villager at its building
// type; while queued and after, it eats `upkeep` food per hour instead of that villager. // type; while queued and after, it eats `upkeep` food per hour instead of that villager.
// build_time is seconds per unit at world speed 1, building level 0 and full staffing. // build_time is seconds per unit at world speed 1, building level 1 and full staffing.
// speed is minutes per field (M4), carry is loot per unit (M4). // speed is minutes per field (M4), carry is loot per unit (M4).
return [ return [

View File

@ -8,11 +8,11 @@ return [
'village' => [ 'village' => [
// Building space: the sum of the buildings' `space` may not exceed // Building space: the sum of the buildings' `space` may not exceed
// space + space_per_hq_level × headquarters level (40 at level 0, 60 at 1, ...). // space + space_per_hq_level × (headquarters level − 1): 40 at level 1, 60 at 2, ...
'space' => 40, 'space' => 40,
'space_per_hq_level' => 20, 'space_per_hq_level' => 20,
'start_resources' => ['wood' => 500, 'clay' => 500, 'iron' => 500, 'food' => 300], 'start_resources' => ['wood' => 500, 'clay' => 500, 'iron' => 500, 'food' => 300],
// Auto-placed at level 0 in this order. // Auto-placed at level 1 in this order.
'start_buildings' => ['headquarters', 'storage', 'farm'], 'start_buildings' => ['headquarters', 'storage', 'farm'],
], ],

View File

@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
// Levels start at 1 now, and every formula treats level 1 the way it treated level 0,
// so shifting every stored level up by one keeps costs, output and points the same.
// Queued orders shift too: a new building targets 1, a removal targets 0 (was -1).
public function up(): void
{
DB::table('buildings')->increment('level');
DB::table('build_orders')->increment('target_level');
}
public function down(): void
{
DB::table('buildings')->decrement('level');
DB::table('build_orders')->decrement('target_level');
}
};

View File

@ -73,13 +73,13 @@ A wave takes the fewest units that make income cover upkeep again: foreign suppo
## Village space ## Village space
- Each village has a building space budget that grows with its headquarters: `space + village.space_per_hq_level × HQ level` (defaults 40 and 20, so 40 at level 0, 60 at level 1). The village row stores its own base `space`, so terrain or specials can change it per village later. The new space arrives when an HQ level finishes; a queued HQ demolition already counts, and the HQ can't be demolished below what stands. - Each village has a building space budget that grows with its headquarters: `space + village.space_per_hq_level × (HQ level − 1)` (defaults 40 and 20, so 40 at level 1, 60 at level 2). The village row stores its own base `space`, so terrain or specials can change it per village later. The new space arrives when an HQ level finishes; a queued HQ demolition already counts, and the HQ can't be demolished below what stands.
- Each building type takes a fixed `space` from config, for example HQ 9, barracks 6, resource buildings 4, and hiding place 1. The level changes only the look, never the space. A building fits when the space of all buildings plus new buildings still in the queue, plus its own, stays within the budget. The space is reserved when the order is queued. - Each building type takes a fixed `space` from config, for example HQ 9, barracks 6, resource buildings 4, and hiding place 1. The level changes only the look, never the space. A building fits when the space of all buildings plus new buildings still in the queue, plus its own, stays within the budget. The space is reserved when the order is queued.
- There are no tiles and no stored positions. The client draws the village as a low-poly isometric diorama and lays the buildings out itself (HQ in the centre, the rest around it), so where a building stands is presentation, not game state. - There are no tiles and no stored positions. The client draws the village as a low-poly isometric diorama and lays the buildings out itself (HQ in the centre, the rest around it), so where a building stands is presentation, not game state.
- Levels start at 0. Level 0 is a real, primitive state: the HQ is a tent, storage is open ground, and the farm is gatherers. A new instance is built at level 0. - Levels start at 1, as in Die Stämme, and a new instance is built at level 1. Every per-level formula uses `level − 1` as the exponent of its factor, so level 1 has the base values.
- Multiple instances per type are allowed. `max_per_village` limits types that must stay unique (HQ, rally point, wall). `instance_cost_factor` makes the n-th instance of a type more expensive, so many cheap copies don't beat upgrading. - Multiple instances per type are allowed. `max_per_village` limits types that must stay unique (HQ, rally point, wall). `instance_cost_factor` makes the n-th instance of a type more expensive, so many cheap copies don't beat upgrading.
- Basic buildings have no requirements: everything in the core set, the wall included, can be built from the start. Only advanced buildings get `requires` (type => minimum level of any instance), for example the academy (Adelshof) needs the headquarters and a barracks (Kaserne). A build option lists what is still missing. - Basic buildings have no requirements: everything in the core set, the wall included, can be built from the start. Only advanced buildings get `requires` (type => minimum level of any instance), for example the academy (Adelshof) needs the headquarters and a barracks (Kaserne). A build option lists what is still missing.
- Demolishing goes through the build queue. It lowers an instance by one level and refunds `demolish_refund` × that level's cost (default 0.5). Below level 0 the instance is removed and its space is freed. - Demolishing goes through the build queue. It lowers an instance by one level and refunds `demolish_refund` × that level's cost (default 0.5). Taking level 1 down removes the instance (an order with target level 0) and frees its space.
- The wall takes 0 space: it surrounds the village. - The wall takes 0 space: it surrounds the village.
- Each building level is worth `points` (config); a village's points are their sum, kept on the row when an order finishes and shown on the map. - Each building level is worth `points` (config); a village's points are their sum, kept on the row when an order finishes and shown on the map.
@ -103,7 +103,7 @@ A village may fail through war or bad play, but it must never get stuck. Every l
| No villagers, no food | Farm 0 (gatherers) has nominal output > 0, so capacity is never 0. Villagers fill instantly. Wood, clay, and iron trickle regardless of staffing. | | No villagers, no food | Farm 0 (gatherers) has nominal output > 0, so capacity is never 0. Villagers fill instantly. Wood, clay, and iron trickle regardless of staffing. |
| Farm, workers, and capacity feeding each other | Capacity uses nominal farm output, not actual output. Farms are staffed before every other building. Lint: each farm level's worker upkeep < its output. | | Farm, workers, and capacity feeding each other | Capacity uses nominal farm output, not actual output. Farms are staffed before every other building. Lint: each farm level's worker upkeep < its output. |
| Next upgrade costs more than storage holds | Lint: for every building and level, the cost fits the storage cap reachable without that building, and storage's own next level fits its current cap. | | Next upgrade costs more than storage holds | Lint: for every building and level, the cost fits the storage cap reachable without that building, and storage's own next level fits its current cap. |
| Building space full | Demolishing is always allowed, costs nothing, and refunds. Core buildings (HQ, one storage, one farm) cannot go below level 0. Lint: the start buildings fit the space, and every type fits next to them. | | Building space full | Demolishing is always allowed, costs nothing, and refunds. Core buildings (HQ, one storage, one farm) cannot go below level 1. Lint: the start buildings fit the space, and every type fits next to them. |
| Queue blocked | A free builder skips blocked orders. Every order can be cancelled with a refund. | | Queue blocked | A free builder skips blocked orders. Every order can be cancelled with a refund. |
| Building requirements | Lint: the requirement graph has no cycles, and every building and level is reachable from the start village. | | Building requirements | Lint: the requirement graph has no cycles, and every building and level is reachable from the start village. |
| Starvation spiral | Deserters leave in the order foreign support, soldiers, then the levy ends. Farms are staffed first, so food income recovers as soldiers leave. | | Starvation spiral | Deserters leave in the order foreign support, soldiers, then the levy ends. Farms are staffed first, so food income recovers as soldiers leave. |

View File

@ -39,7 +39,7 @@ it('pays up front, reserves the space and finishes on time', function () {
$this->travel(1)->seconds(); $this->travel(1)->seconds();
$state = shown($village); $state = shown($village);
expect($state['queue'])->toBe([]) expect($state['queue'])->toBe([])
->and(collect($state['buildings'])->firstWhere('type', 'timber_camp'))->toMatchArray(['level' => 0, 'space' => 4]) ->and(collect($state['buildings'])->firstWhere('type', 'timber_camp'))->toMatchArray(['level' => 1, 'space' => 4])
->and($state['rates']['wood'])->toBe(35.0) ->and($state['rates']['wood'])->toBe(35.0)
->and($state['points'])->toBe(27); ->and($state['points'])->toBe(27);
}); });
@ -48,8 +48,8 @@ it('refuses a building that does not fit the free building space', function () {
// Start buildings take 17 of 40; four timber camps and six hiding places bring it to 39. // Start buildings take 17 of 40; four timber camps and six hiding places bring it to 39.
$village = startVillage(); $village = startVillage();
$village->buildings()->createMany([ $village->buildings()->createMany([
...array_fill(0, 4, ['type' => 'timber_camp', 'level' => 0]), ...array_fill(0, 4, ['type' => 'timber_camp', 'level' => 1]),
...array_fill(0, 6, ['type' => 'hiding_place', 'level' => 0]), ...array_fill(0, 6, ['type' => 'hiding_place', 'level' => 1]),
]); ]);
$options = collect(shown($village)['buildable'])->keyBy('type'); $options = collect(shown($village)['buildable'])->keyBy('type');
@ -115,15 +115,15 @@ it('queues upgrades of one building one after another', function () {
app(QueueUpgrade::class)(owner($village), $village->id, $hq->id); app(QueueUpgrade::class)(owner($village), $village->id, $hq->id);
$state = shown($village); $state = shown($village);
expect(collect($state['queue'])->map(fn (array $o) => Arr::only($o, ['target_level', 'builder']))->all())->toBe([ expect(collect($state['queue'])->map(fn (array $o) => Arr::only($o, ['target_level', 'builder']))->all())->toBe([
['target_level' => 1, 'builder' => 1], ['target_level' => 2, 'builder' => 1],
['target_level' => 2, 'builder' => null], ['target_level' => 3, 'builder' => null],
]) ])
->and(collect($state['buildings'])->firstWhere('type', 'headquarters')['upgrade']['target_level'])->toBe(3) ->and(collect($state['buildings'])->firstWhere('type', 'headquarters')['upgrade']['target_level'])->toBe(4)
->and($state['resources']['wood'])->toBe(500.0 - 113 - 143); ->and($state['resources']['wood'])->toBe(500.0 - 113 - 143);
// HQ 1 takes 144 s; HQ 2 then builds with HQ 1's speed-up: 172.8 / 1.05 → 165 s. // HQ 2 takes 144 s; HQ 3 then builds with HQ 2's speed-up: 172.8 / 1.05 → 165 s.
$this->travel(144 + 165)->seconds(); $this->travel(144 + 165)->seconds();
expect(collect(shown($village)['buildings'])->firstWhere('type', 'headquarters')['level'])->toBe(2); expect(collect(shown($village)['buildings'])->firstWhere('type', 'headquarters')['level'])->toBe(3);
}); });
it('cancels an order, the orders that build on it, and refunds them in full', function () { it('cancels an order, the orders that build on it, and refunds them in full', function () {
@ -140,14 +140,14 @@ it('cancels an order, the orders that build on it, and refunds them in full', fu
->and(GameEvent::whereNull('processed_at')->count())->toBe(0); ->and(GameEvent::whereNull('processed_at')->count())->toBe(0);
}); });
it('demolishes with a refund on finish and removes a building below level 0', function () { it('demolishes with a refund on finish and removes a building taken down from level 1', function () {
$village = startVillage(); $village = startVillage();
app(QueueBuild::class)(owner($village), $village->id, 'timber_camp'); app(QueueBuild::class)(owner($village), $village->id, 'timber_camp');
$this->travel(90)->seconds(); $this->travel(90)->seconds();
$camp = collect(shown($village)['buildings'])->firstWhere('type', 'timber_camp'); $camp = collect(shown($village)['buildings'])->firstWhere('type', 'timber_camp');
app(QueueDemolish::class)(owner($village), $village->id, $camp['id']); app(QueueDemolish::class)(owner($village), $village->id, $camp['id']);
expect(shown($village)['queue'][0])->toMatchArray(['action' => 'demolish', 'target_level' => -1]); expect(shown($village)['queue'][0])->toMatchArray(['action' => 'demolish', 'target_level' => 0]);
$woodBefore = shown($village)['resources']['wood']; $woodBefore = shown($village)['resources']['wood'];
$this->travel(45)->seconds(); $this->travel(45)->seconds();
@ -156,7 +156,7 @@ it('demolishes with a refund on finish and removes a building below level 0', fu
->and($state['resources']['wood'])->toEqualWithDelta($woodBefore + 25 + 35 * 45 / 3600, 0.01); ->and($state['resources']['wood'])->toEqualWithDelta($woodBefore + 25 + 35 * 45 / 3600, 0.01);
}); });
it('keeps core buildings at level 0', function () { it('keeps core buildings at level 1', function () {
$village = startVillage(); $village = startVillage();
$hq = $village->buildings->firstWhere('type', 'headquarters'); $hq = $village->buildings->firstWhere('type', 'headquarters');
@ -165,14 +165,14 @@ it('keeps core buildings at level 0', function () {
}); });
it('moves workers to the buildings with the highest priority', function () { it('moves workers to the buildings with the highest priority', function () {
// 24 villagers: the farm takes 2, the clay pit at priority 9 the other 22. // 24 villagers: the farm takes 2, the clay pit at priority 9 the other 22 of its 53.
$village = startVillage(); $village = startVillage();
$village->buildings()->create(['type' => 'timber_camp', 'level' => 30]); $village->buildings()->create(['type' => 'timber_camp', 'level' => 30]);
$clay = $village->buildings()->create(['type' => 'clay_pit', 'level' => 30]); $clay = $village->buildings()->create(['type' => 'clay_pit', 'level' => 30]);
app(SetPriority::class)(owner($village), $village->id, $clay->id, 12); app(SetPriority::class)(owner($village), $village->id, $clay->id, 12);
$buildings = collect(shown($village)['buildings'])->keyBy('type'); $buildings = collect(shown($village)['buildings'])->keyBy('type');
expect($buildings['clay_pit']['workers'])->toBe(['assigned' => 22, 'required' => 60]) expect($buildings['clay_pit']['workers'])->toBe(['assigned' => 22, 'required' => 53])
->and($buildings['clay_pit']['priority'])->toBe(9) ->and($buildings['clay_pit']['priority'])->toBe(9)
->and($buildings['timber_camp']['workers']['assigned'])->toBe(0) ->and($buildings['timber_camp']['workers']['assigned'])->toBe(0)
->and($buildings['farm']['workers']['assigned'])->toBe(2); ->and($buildings['farm']['workers']['assigned'])->toBe(2);
@ -203,9 +203,9 @@ it('grows the building space by 20 with every headquarters level', function () {
it('keeps the headquarters from shrinking below what stands, and plans with a queued demolition', function () { it('keeps the headquarters from shrinking below what stands, and plans with a queued demolition', function () {
$village = startVillage(); $village = startVillage();
$hq = $village->buildings->firstWhere('type', 'headquarters'); $hq = $village->buildings->firstWhere('type', 'headquarters');
$hq->update(['level' => 2]); $hq->update(['level' => 3]);
// 17 + 7 × 4 = 45 of 80: level 1 (60) still fits, level 0 (40) would not. // 17 + 7 × 4 = 45 of 80: level 2 (60) still fits, level 1 (40) would not.
$village->buildings()->createMany(array_fill(0, 7, ['type' => 'timber_camp', 'level' => 0])); $village->buildings()->createMany(array_fill(0, 7, ['type' => 'timber_camp', 'level' => 1]));
app(QueueDemolish::class)(owner($village), $village->id, $hq->id); app(QueueDemolish::class)(owner($village), $village->id, $hq->id);
$state = shown($village); $state = shown($village);

View File

@ -7,7 +7,7 @@ use App\Game\Map\Continent;
use App\Models\User; use App\Models\User;
use App\Models\World; use App\Models\World;
it('starts a village with HQ, storage and farm at level 0', function () { it('starts a village with HQ, storage and farm at level 1', function () {
$village = startVillage(); $village = startVillage();
// On the spawn ring: start radius 6 ± 2 around 500|500. // On the spawn ring: start radius 6 ± 2 around 500|500.
@ -15,9 +15,9 @@ it('starts a village with HQ, storage and farm at level 0', function () {
->and($village->only('space', 'points'))->toBe(['space' => 40, 'points' => 21]) ->and($village->only('space', 'points'))->toBe(['space' => 40, 'points' => 21])
->and($village->resources())->toBe(['wood' => 500.0, 'clay' => 500.0, 'iron' => 500.0, 'food' => 300.0]) ->and($village->resources())->toBe(['wood' => 500.0, 'clay' => 500.0, 'iron' => 500.0, 'food' => 300.0])
->and($village->buildings->map->only('type', 'level')->all())->toBe([ ->and($village->buildings->map->only('type', 'level')->all())->toBe([
['type' => 'headquarters', 'level' => 0], ['type' => 'headquarters', 'level' => 1],
['type' => 'storage', 'level' => 0], ['type' => 'storage', 'level' => 1],
['type' => 'farm', 'level' => 0], ['type' => 'farm', 'level' => 1],
]); ]);
}); });

View File

@ -61,7 +61,7 @@ it('refuses a second levy, more than the villagers and nobody', function () {
it('trains soldiers only from villagers who are not drafted', function () { it('trains soldiers only from villagers who are not drafted', function () {
$village = startVillage(); $village = startVillage();
$barracks = $village->buildings()->create(['type' => 'barracks', 'level' => 0]); $barracks = $village->buildings()->create(['type' => 'barracks', 'level' => 1]);
$village->update(['wood' => 1000, 'clay' => 1000, 'iron' => 1000]); $village->update(['wood' => 1000, 'clay' => 1000, 'iron' => 1000]);
app(Levy::class)(owner($village), $village->id, 20); app(Levy::class)(owner($village), $village->id, 20);

View File

@ -9,11 +9,11 @@ use Carbon\CarbonImmutable;
beforeEach(fn () => $this->travelTo(CarbonImmutable::parse('2026-10-29 12:00:00'))); beforeEach(fn () => $this->travelTo(CarbonImmutable::parse('2026-10-29 12:00:00')));
/** A start village with a barracks at level 0 and a full storage. */ /** A start village with a barracks at level 1 and a full storage. */
function withBarracks(): array function withBarracks(): array
{ {
$village = startVillage(); $village = startVillage();
$barracks = $village->buildings()->create(['type' => 'barracks', 'level' => 0]); $barracks = $village->buildings()->create(['type' => 'barracks', 'level' => 1]);
$village->update(['wood' => 1000, 'clay' => 1000, 'iron' => 1000]); $village->update(['wood' => 1000, 'clay' => 1000, 'iron' => 1000]);
return [$village->fresh(), $barracks]; return [$village->fresh(), $barracks];
@ -79,7 +79,7 @@ it('queues orders at one barracks one after another, and moves them up on cancel
it('runs a queue per barracks, side by side', function () { it('runs a queue per barracks, side by side', function () {
[$village, $first] = withBarracks(); [$village, $first] = withBarracks();
$second = $village->buildings()->create(['type' => 'barracks', 'level' => 0]); $second = $village->buildings()->create(['type' => 'barracks', 'level' => 1]);
app(Recruit::class)(owner($village), $village->id, $first->id, 'spear', 2); app(Recruit::class)(owner($village), $village->id, $first->id, 'spear', 2);
app(Recruit::class)(owner($village), $village->id, $second->id, 'spear', 2); app(Recruit::class)(owner($village), $village->id, $second->id, 'spear', 2);
@ -110,7 +110,7 @@ it('says how many units fit, by resources and villagers', function () {
it('sends units in training back to work, refunded, when their barracks is torn down', function () { it('sends units in training back to work, refunded, when their barracks is torn down', function () {
[$village, $barracks] = withBarracks(); [$village, $barracks] = withBarracks();
app(Recruit::class)(owner($village), $village->id, $barracks->id, 'spear', 4); app(Recruit::class)(owner($village), $village->id, $barracks->id, 'spear', 4);
// Taking level 0 down removes it after 5 minutes, before the first spear (17 minutes) is done. // Taking level 1 down removes it after 5 minutes, before the first spear (17 minutes) is done.
app(QueueDemolish::class)(owner($village), $village->id, $barracks->id); app(QueueDemolish::class)(owner($village), $village->id, $barracks->id);
$this->travel(1)->hours(); $this->travel(1)->hours();

View File

@ -31,7 +31,7 @@ function gameConfig(array $overrides = []): WorldConfig
], $overrides); ], $overrides);
} }
function building(int $id, string $type, int $level = 0, int $priority = 5): BuildingState function building(int $id, string $type, int $level = 1, int $priority = 5): BuildingState
{ {
return new BuildingState($id, $type, $level, $priority); return new BuildingState($id, $type, $level, $priority);
} }

View File

@ -2,11 +2,11 @@
use App\Game\Buildings\BuildingRules; use App\Game\Buildings\BuildingRules;
it('costs the base at level 0 and grows by the factor per level', function () { it('costs the base at level 1 and grows by the factor per level', function () {
$rules = new BuildingRules(gameConfig()); $rules = new BuildingRules(gameConfig());
expect($rules->cost('timber_camp', 0))->toBe(['wood' => 50, 'clay' => 60, 'iron' => 40]) expect($rules->cost('timber_camp', 1))->toBe(['wood' => 50, 'clay' => 60, 'iron' => 40])
->and($rules->cost('timber_camp', 2))->toBe([ ->and($rules->cost('timber_camp', 3))->toBe([
'wood' => (int) round(50 * 1.25 ** 2), 'wood' => (int) round(50 * 1.25 ** 2),
'clay' => (int) round(60 * 1.25 ** 2), 'clay' => (int) round(60 * 1.25 ** 2),
'iron' => (int) round(40 * 1.25 ** 2), 'iron' => (int) round(40 * 1.25 ** 2),
@ -16,25 +16,25 @@ it('costs the base at level 0 and grows by the factor per level', function () {
it('makes later instances of a type more expensive', function () { it('makes later instances of a type more expensive', function () {
$rules = new BuildingRules(gameConfig()); $rules = new BuildingRules(gameConfig());
expect($rules->cost('farm', 0, 1))->toBe(['wood' => 68, 'clay' => 60, 'iron' => 45]) expect($rules->cost('farm', 1, 1))->toBe(['wood' => 68, 'clay' => 60, 'iron' => 45])
->and($rules->cost('headquarters', 0, 3))->toBe($rules->cost('headquarters', 0)); ->and($rules->cost('headquarters', 1, 3))->toBe($rules->cost('headquarters', 1));
}); });
it('divides build time by world speed, headquarters level and staffing', function () { it('divides build time by world speed, headquarters level and staffing', function () {
$rules = new BuildingRules(gameConfig()); $rules = new BuildingRules(gameConfig());
$fast = new BuildingRules(gameConfig(['world' => ['speed' => 100]])); $fast = new BuildingRules(gameConfig(['world' => ['speed' => 100]]));
expect($rules->buildSeconds('timber_camp', 0, 0, 1.0))->toBe(90) expect($rules->buildSeconds('timber_camp', 1, 1, 1.0))->toBe(90)
->and($rules->buildSeconds('timber_camp', 1, 0, 1.0))->toBe(108) ->and($rules->buildSeconds('timber_camp', 2, 1, 1.0))->toBe(108)
->and($rules->buildSeconds('timber_camp', 0, 10, 1.0))->toBe(60) ->and($rules->buildSeconds('timber_camp', 1, 11, 1.0))->toBe(60)
->and($rules->buildSeconds('timber_camp', 0, 0, 0.5))->toBe(180) ->and($rules->buildSeconds('timber_camp', 1, 1, 0.5))->toBe(180)
->and($fast->buildSeconds('timber_camp', 0, 0, 1.0))->toBe(1); ->and($fast->buildSeconds('timber_camp', 1, 1, 1.0))->toBe(1);
}); });
it('takes half the time and refunds half the cost when demolishing', function () { it('takes half the time and refunds half the cost when demolishing', function () {
$rules = new BuildingRules(gameConfig()); $rules = new BuildingRules(gameConfig());
expect($rules->demolishSeconds('timber_camp', 1, 0, 1.0))->toBe(54) expect($rules->demolishSeconds('timber_camp', 2, 1, 1.0))->toBe(54)
->and($rules->demolishRefund('timber_camp', 0))->toBe(['wood' => 25, 'clay' => 30, 'iron' => 20]); ->and($rules->demolishRefund('timber_camp', 0))->toBe(['wood' => 25, 'clay' => 30, 'iron' => 20]);
}); });
@ -42,19 +42,19 @@ it('rounds workers and scales output with world speed', function () {
$rules = new BuildingRules(gameConfig()); $rules = new BuildingRules(gameConfig());
$fast = new BuildingRules(gameConfig(['world' => ['speed' => 2]])); $fast = new BuildingRules(gameConfig(['world' => ['speed' => 2]]));
expect($rules->workers('timber_camp', 0))->toBe(2) expect($rules->workers('timber_camp', 1))->toBe(2)
->and($rules->workers('timber_camp', 10))->toBe((int) round(2 * 1.12 ** 10)) ->and($rules->workers('timber_camp', 11))->toBe((int) round(2 * 1.12 ** 10))
->and($rules->workers('hiding_place', 5))->toBe(0) ->and($rules->workers('hiding_place', 5))->toBe(0)
->and($rules->output('timber_camp', 0))->toBe(['resource' => 'wood', 'per_hour' => 30.0]) ->and($rules->output('timber_camp', 1))->toBe(['resource' => 'wood', 'per_hour' => 30.0])
->and($fast->output('farm', 0))->toBe(['resource' => 'food', 'per_hour' => 60.0]) ->and($fast->output('farm', 1))->toBe(['resource' => 'food', 'per_hour' => 60.0])
->and($rules->output('storage', 3))->toBeNull(); ->and($rules->output('storage', 3))->toBeNull();
}); });
it('gives storage capacity only to storage', function () { it('gives storage capacity only to storage', function () {
$rules = new BuildingRules(gameConfig()); $rules = new BuildingRules(gameConfig());
expect($rules->capacity('storage', 0))->toBe(1000.0) expect($rules->capacity('storage', 1))->toBe(1000.0)
->and($rules->capacity('storage', 1))->toBe(1230.0) ->and($rules->capacity('storage', 2))->toBe(1230.0)
->and($rules->capacity('farm', 1))->toBe(0.0); ->and($rules->capacity('farm', 1))->toBe(0.0);
}); });
@ -69,9 +69,9 @@ it('takes building space per type at every level, and none for the wall', functi
it('gives points per building level', function () { it('gives points per building level', function () {
$rules = new BuildingRules(gameConfig()); $rules = new BuildingRules(gameConfig());
expect($rules->points('headquarters', 0))->toBe(10) expect($rules->points('headquarters', 1))->toBe(10)
->and($rules->points('headquarters', 5))->toBe((int) round(10 * 1.2 ** 5)) ->and($rules->points('headquarters', 6))->toBe((int) round(10 * 1.2 ** 5))
->and($rules->points('rally_point', 0))->toBe(2); ->and($rules->points('rally_point', 1))->toBe(2);
}); });
it('adds builders at the configured headquarters levels', function () { it('adds builders at the configured headquarters levels', function () {
@ -86,7 +86,7 @@ it('adds builders at the configured headquarters levels', function () {
it('adds building space for every headquarters level', function () { it('adds building space for every headquarters level', function () {
$rules = new BuildingRules(gameConfig()); $rules = new BuildingRules(gameConfig());
expect($rules->spaceMax(40, 0))->toBe(40) expect($rules->spaceMax(40, 1))->toBe(40)
->and($rules->spaceMax(40, 1))->toBe(60) ->and($rules->spaceMax(40, 2))->toBe(60)
->and($rules->spaceMax(40, 30))->toBe(640); ->and($rules->spaceMax(40, 30))->toBe(620);
}); });

View File

@ -13,13 +13,13 @@ it('finds no locks in the dev world', function () {
it('reports a farm whose workers eat more than it makes', function () { it('reports a farm whose workers eat more than it makes', function () {
$config = gameConfig(['buildings' => ['farm' => ['workers' => ['base' => 40]]]]); $config = gameConfig(['buildings' => ['farm' => ['workers' => ['base' => 40]]]]);
expect(ConfigLint::check($config))->toContain('[farm] level 0 feeds fewer people than it needs as workers.'); expect(ConfigLint::check($config))->toContain('[farm] level 1 feeds fewer people than it needs as workers.');
}); });
it('reports a storage level that its predecessor cannot pay for', function () { it('reports a storage level that its predecessor cannot pay for', function () {
$config = gameConfig(['buildings' => ['storage' => ['cost' => ['wood' => 2000]]]]); $config = gameConfig(['buildings' => ['storage' => ['cost' => ['wood' => 2000]]]]);
expect(ConfigLint::check($config))->toContain('[storage] level 1 costs more than level 0 holds.'); expect(ConfigLint::check($config))->toContain('[storage] level 2 costs more than level 1 holds.');
}); });
it('reports requirement cycles and unknown requirements', function () { it('reports requirement cycles and unknown requirements', function () {

View File

@ -4,7 +4,7 @@ use App\Game\Economy\Population;
it('feeds villagers from the share of farm output, leaving a surplus', function () { it('feeds villagers from the share of farm output, leaving a surplus', function () {
$population = new Population(gameConfig()); $population = new Population(gameConfig());
$workforce = $population->workforce([building(1, 'farm'), building(2, 'farm', 1)]); $workforce = $population->workforce([building(1, 'farm'), building(2, 'farm', 2)]);
// Budget 30 + 35.1 = 65.1 food/h; villagers fill 80% of it. // Budget 30 + 35.1 = 65.1 food/h; villagers fill 80% of it.
expect($workforce->foodBudget)->toBe(30 + 30 * 1.17) expect($workforce->foodBudget)->toBe(30 + 30 * 1.17)
@ -39,11 +39,11 @@ it('drafts no more militia than there are villagers', function () {
}); });
it('staffs farms first, then by priority', function () { it('staffs farms first, then by priority', function () {
// Farm 0 makes 30 food, so 24 villagers: the farm takes 2, priority 9 the other 22. // A level 1 farm makes 30 food, so 24 villagers: the farm takes 2, priority 9 the other 22.
$buildings = [ $buildings = [
building(1, 'timber_camp', 30, priority: 1), building(1, 'timber_camp', 30, priority: 1),
building(2, 'clay_pit', 30, priority: 9), building(2, 'clay_pit', 30, priority: 9),
building(3, 'farm', 0, priority: 0), building(3, 'farm', 1, priority: 0),
]; ];
$workforce = (new Population(gameConfig()))->workforce($buildings); $workforce = (new Population(gameConfig()))->workforce($buildings);
@ -52,11 +52,11 @@ it('staffs farms first, then by priority', function () {
}); });
it('splits villagers evenly between buildings of equal priority', function () { it('splits villagers evenly between buildings of equal priority', function () {
// 24 villagers: farm takes 2, the two level-20 camps (19 each) share 22. // 24 villagers: farm takes 2, the two level-21 camps (19 each) share 22.
$buildings = [ $buildings = [
building(1, 'farm'), building(1, 'farm'),
building(2, 'timber_camp', 20), building(2, 'timber_camp', 21),
building(3, 'clay_pit', 20), building(3, 'clay_pit', 21),
]; ];
$workforce = (new Population(gameConfig()))->workforce($buildings); $workforce = (new Population(gameConfig()))->workforce($buildings);

View File

@ -26,15 +26,15 @@ it('adds buildings to the base trickle and nets food against upkeep', function (
it('makes less in an understaffed building', function () { it('makes less in an understaffed building', function () {
$config = gameConfig(); $config = gameConfig();
// 24 villagers (80% of 30 food) for a timber camp needing round(2 × 1.12^30) = 60. // 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)]; $buildings = [building(1, 'farm'), building(2, 'timber_camp', 30)];
$workforce = (new Population($config))->workforce($buildings); $workforce = (new Population($config))->workforce($buildings);
$production = new Production($config); $production = new Production($config);
$ratio = 22 / 60; $ratio = 22 / 53;
expect($workforce->ratio(2))->toBe($ratio) expect($workforce->ratio(2))->toBe($ratio)
->and($production->output($buildings[1], $workforce)['per_hour']) ->and($production->output($buildings[1], $workforce)['per_hour'])
->toEqualWithDelta(30 * 1.163 ** 30 * exp(2.3 * ($ratio - 1)), 1e-6); ->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 () { it('settles stored amounts by rate and elapsed hours within the cap', function () {

View File

@ -23,10 +23,10 @@ it('trains faster at a higher level and slower when understaffed', function () {
$units = new UnitRules(gameConfig()); $units = new UnitRules(gameConfig());
$fast = new UnitRules(gameConfig(['world' => ['speed' => 100]])); $fast = new UnitRules(gameConfig(['world' => ['speed' => 100]]));
expect($units->seconds('spear', 0, 1.0))->toBe(1020) expect($units->seconds('spear', 1, 1.0))->toBe(1020)
->and($units->seconds('spear', 10, 1.0))->toBe(680) ->and($units->seconds('spear', 11, 1.0))->toBe(680)
->and($units->seconds('spear', 0, 0.5))->toBe(2040) ->and($units->seconds('spear', 1, 0.5))->toBe(2040)
->and($fast->seconds('spear', 0, 1.0))->toBe(11); ->and($fast->seconds('spear', 1, 1.0))->toBe(11);
}); });
it('lints units that point at unknown buildings or eat nothing', function () { it('lints units that point at unknown buildings or eat nothing', function () {