From 82875448c485d26375ed6dea4e64e940f6e10f74 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 8 Jan 2024 15:10:10 +0100 Subject: gemini --- src/Model/Building.php | 16 +++++++++----- src/Model/Building/ClayPit.php | 7 ++++++- src/Model/Building/Embassy.php | 7 ++++++- src/Model/Building/Farm.php | 9 ++++++-- src/Model/Building/IronMine.php | 7 ++++++- src/Model/Building/Marketplace.php | 7 ++++++- src/Model/Building/Storage.php | 7 ++++++- src/Model/Building/TownHall.php | 7 ++++++- src/Model/Building/WoodCutter.php | 7 ++++++- src/Model/Unit.php | 43 ++++++++++++++++++++------------------ src/Model/Unit/Diplomat.php | 9 +++++++- src/Model/Unit/Farmer.php | 9 +++++++- src/Model/Unit/Merchant.php | 9 +++++++- src/Model/Unit/Miner.php | 9 +++++++- src/Model/Unit/PitWorker.php | 9 +++++++- src/Model/Unit/WoodCutter.php | 9 +++++++- 16 files changed, 131 insertions(+), 40 deletions(-) (limited to 'src/Model') diff --git a/src/Model/Building.php b/src/Model/Building.php index eefb4df..e42af03 100644 --- a/src/Model/Building.php +++ b/src/Model/Building.php @@ -18,7 +18,8 @@ class Building public string $unitType; public int $buildTimeFactor; - public array $resourceRequirements; + public array $resourceRequirementsBase; + public array $resourceRequirementsFactor; public array $buildingRequirements; public array $techRequirements; public int $maxLevel; @@ -104,10 +105,15 @@ class Building */ public function getResourceRequirementsForLevel(int $level): array { - return array_map( - fn ($resourceRequirement) => ceil(log($level * 2) * $resourceRequirement * $_ENV['BASE_BUILDING_RESOURCE_REQUIREMENT_FACTOR'] * $level), - $this->resourceRequirements - ); + $resourceRequirements = []; + foreach (['wood', 'clay', 'iron'] as $resourceType) { + $base = $this->resourceRequirementsBase[$resourceType]; + $factor = $this->resourceRequirementsFactor[$resourceType]; + + $resourceRequirements[$resourceType] = $base + ceil(log($level * 2) * $factor * $_ENV['BASE_BUILDING_RESOURCE_REQUIREMENT_FACTOR'] * $level); + } + + return $resourceRequirements; } diff --git a/src/Model/Building/ClayPit.php b/src/Model/Building/ClayPit.php index b4905eb..dfead72 100644 --- a/src/Model/Building/ClayPit.php +++ b/src/Model/Building/ClayPit.php @@ -8,7 +8,12 @@ class ClayPit extends ResourceGenerator public int $buildTimeFactor = 1; public int $maxLevel = 25; - public array $resourceRequirements = [ + public array $resourceRequirementsBase = [ + 'wood' => 100, + 'clay' => 200, + 'iron' => 100, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 1.0, 'clay' => 2.0, 'iron' => 1.0, diff --git a/src/Model/Building/Embassy.php b/src/Model/Building/Embassy.php index 3be1f7f..a8a1ec4 100644 --- a/src/Model/Building/Embassy.php +++ b/src/Model/Building/Embassy.php @@ -9,7 +9,12 @@ class Embassy extends Building public int $buildTimeFactor = 1; public int $maxLevel = 25; - public array $resourceRequirements = [ + public array $resourceRequirementsBase = [ + 'wood' => 2500, + 'clay' => 2500, + 'iron' => 3000, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 25.0, 'clay' => 25.0, 'iron' => 30.0, diff --git a/src/Model/Building/Farm.php b/src/Model/Building/Farm.php index 222d8cd..1a69c89 100644 --- a/src/Model/Building/Farm.php +++ b/src/Model/Building/Farm.php @@ -11,7 +11,12 @@ class Farm extends ResourceGenerator public int $buildTimeFactor = 1; public int $maxLevel = 25; - public array $resourceRequirements = [ + public array $resourceRequirementsBase = [ + 'wood' => 100, + 'clay' => 100, + 'iron' => 100, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 1.0, 'clay' => 1.0, 'iron' => 1.0, @@ -22,7 +27,7 @@ class Farm extends ResourceGenerator public function getResourceIncrementor(): int { $populationDemand = array_reduce( - Village::getUnits($this->villageId, Village::FETCH_UNIT_RESIDENCE), + Village::getUnits($this->villageId, Village::FETCH_UNIT_RESIDENCE, Village::RETURN_UNIT_EXISTING), function ($carry, Unit $unit) { return $carry + $unit->getPopulationDemand(); } diff --git a/src/Model/Building/IronMine.php b/src/Model/Building/IronMine.php index d240e3a..8e70ee0 100644 --- a/src/Model/Building/IronMine.php +++ b/src/Model/Building/IronMine.php @@ -8,7 +8,12 @@ class IronMine extends ResourceGenerator public int $buildTimeFactor = 1; public int $maxLevel = 25; - public array $resourceRequirements = [ + public array $resourceRequirementsBase = [ + 'wood' => 100, + 'clay' => 100, + 'iron' => 200, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 1.0, 'clay' => 1.0, 'iron' => 2.0, diff --git a/src/Model/Building/Marketplace.php b/src/Model/Building/Marketplace.php index 714de0d..2d87379 100644 --- a/src/Model/Building/Marketplace.php +++ b/src/Model/Building/Marketplace.php @@ -9,7 +9,12 @@ class Marketplace extends Building public int $buildTimeFactor = 1; public int $maxLevel = 25; - public array $resourceRequirements = [ + public array $resourceRequirementsBase = [ + 'wood' => 1000, + 'clay' => 1000, + 'iron' => 800, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 10.0, 'clay' => 10.0, 'iron' => 8.0, diff --git a/src/Model/Building/Storage.php b/src/Model/Building/Storage.php index de2df92..d75b80d 100644 --- a/src/Model/Building/Storage.php +++ b/src/Model/Building/Storage.php @@ -10,7 +10,12 @@ class Storage extends Building public int $buildTimeFactor = 1; public int $maxLevel = 25; - public array $resourceRequirements = [ + public array $resourceRequirementsBase = [ + 'wood' => 250, + 'clay' => 250, + 'iron' => 250, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 1.0, 'clay' => 1.0, 'iron' => 1.0, diff --git a/src/Model/Building/TownHall.php b/src/Model/Building/TownHall.php index 608f083..33fd105 100644 --- a/src/Model/Building/TownHall.php +++ b/src/Model/Building/TownHall.php @@ -9,7 +9,12 @@ class TownHall extends Building public int $buildTimeFactor = 1; public int $maxLevel = 25; - public array $resourceRequirements = [ + public array $resourceRequirementsBase = [ + 'wood' => 250, + 'clay' => 250, + 'iron' => 250, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 1.0, 'clay' => 1.0, 'iron' => 1.0, diff --git a/src/Model/Building/WoodCutter.php b/src/Model/Building/WoodCutter.php index 726cdbc..6e1ce8c 100644 --- a/src/Model/Building/WoodCutter.php +++ b/src/Model/Building/WoodCutter.php @@ -8,7 +8,12 @@ class WoodCutter extends ResourceGenerator public int $buildTimeFactor = 1; public int $maxLevel = 25; - public array $resourceRequirements = [ + public array $resourceRequirementsBase = [ + 'wood' => 200, + 'clay' => 100, + 'iron' => 100, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 2.0, 'clay' => 1.0, 'iron' => 1.0, diff --git a/src/Model/Unit.php b/src/Model/Unit.php index d563682..206f5dd 100644 --- a/src/Model/Unit.php +++ b/src/Model/Unit.php @@ -22,7 +22,8 @@ class Unit public string $buildingType; public int $travelTime; public int $populationDemandFactor; - public array $resourceRequirements = []; + public array $resourceRequirementsBase = []; + public array $resourceRequirementsFactor = []; public static function getEmpty(int $villageId, string $unitType): Unit @@ -75,27 +76,29 @@ class Unit ['type' => $unit->type, 'id' => $unit->homeVillageId] )->fetchColumn(); - - return array_map( - function ($resourceRequirement) use ($amount, $currentAmount, $building) { - $r = 0; - for ($i = 0; $i <= $amount; $i++) { - $r += ceil( - ( - pow( - $_ENV['BASE_UNIT_RESOURCE_REQUIREMENT_BASE'], - $currentAmount + 1 - ) - * $resourceRequirement * $_ENV['BASE_UNIT_RESOURCE_REQUIREMENT_FACTOR'] + $resourceRequirements = []; + foreach (['wood', 'clay', 'iron', 'food'] as $resourceType) { + $base = $unit->resourceRequirementsBase[$resourceType]; + $factor = $unit->resourceRequirementsFactor[$resourceType]; + + $r = $base; + for ($i = 0; $i <= $amount; $i++) { + $r += ceil( + ( + pow( + $_ENV['BASE_UNIT_RESOURCE_REQUIREMENT_BASE'], + $currentAmount + 1 ) + * $factor * $_ENV['BASE_UNIT_RESOURCE_REQUIREMENT_FACTOR'] + ) / ($building->level ?? 1) - ); - } + ); + } - return $r; - }, - $unit->resourceRequirements - ); + $resourceRequirements[$resourceType] = $r; + } + + return $resourceRequirements; } public function getPopulationDemand(): int @@ -144,7 +147,7 @@ class Unit public static function getAmountResiding(string $unitType, int $villageId): int { $statement = DB::query( - 'select SUM(amount) from village_units where type=:type and residence_village_id=:id', + 'select SUM(amount) from village_units where type=:type and residence_village_id=:id and is_traveling=false', ['type' => $unitType, 'id' => $villageId] ); $result = $statement->fetch()['sum']; diff --git a/src/Model/Unit/Diplomat.php b/src/Model/Unit/Diplomat.php index e263cd3..baee88a 100644 --- a/src/Model/Unit/Diplomat.php +++ b/src/Model/Unit/Diplomat.php @@ -9,7 +9,14 @@ class Diplomat extends Unit public string $buildingType = 'Embassy'; public int $travelTime = 1; public int $populationDemandFactor = 1; - public array $resourceRequirements = [ + + public array $resourceRequirementsBase = [ + 'wood' => 500, + 'clay' => 500, + 'iron' => 500, + 'food' => 500, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 5.0, 'clay' => 5.0, 'iron' => 5.0, diff --git a/src/Model/Unit/Farmer.php b/src/Model/Unit/Farmer.php index 8e3c1ea..5256bf1 100644 --- a/src/Model/Unit/Farmer.php +++ b/src/Model/Unit/Farmer.php @@ -9,7 +9,14 @@ class Farmer extends Unit public string $buildingType = 'Farm'; public int $travelTime = 1; public int $populationDemandFactor = 1; - public array $resourceRequirements = [ + + public array $resourceRequirementsBase = [ + 'wood' => 100, + 'clay' => 100, + 'iron' => 100, + 'food' => 0, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 1.0, 'clay' => 1.0, 'iron' => 1.0, diff --git a/src/Model/Unit/Merchant.php b/src/Model/Unit/Merchant.php index 61e2090..8958d27 100644 --- a/src/Model/Unit/Merchant.php +++ b/src/Model/Unit/Merchant.php @@ -9,7 +9,14 @@ class Merchant extends Unit public string $buildingType = 'Marketplace'; public int $travelTime = 1; public int $populationDemandFactor = 1; - public array $resourceRequirements = [ + + public array $resourceRequirementsBase = [ + 'wood' => 200, + 'clay' => 200, + 'iron' => 200, + 'food' => 200, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 2.0, 'clay' => 2.0, 'iron' => 2.0, diff --git a/src/Model/Unit/Miner.php b/src/Model/Unit/Miner.php index 2d246ef..06c6dda 100644 --- a/src/Model/Unit/Miner.php +++ b/src/Model/Unit/Miner.php @@ -9,7 +9,14 @@ class Miner extends Unit public string $buildingType = 'IronMine'; public int $travelTime = 1; public int $populationDemandFactor = 1; - public array $resourceRequirements = [ + + public array $resourceRequirementsBase = [ + 'wood' => 100, + 'clay' => 100, + 'iron' => 200, + 'food' => 200, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 1.0, 'clay' => 1.0, 'iron' => 2.0, diff --git a/src/Model/Unit/PitWorker.php b/src/Model/Unit/PitWorker.php index d2a52c3..f2a27b6 100644 --- a/src/Model/Unit/PitWorker.php +++ b/src/Model/Unit/PitWorker.php @@ -9,7 +9,14 @@ class PitWorker extends Unit public string $buildingType = 'ClayPit'; public int $travelTime = 1; public int $populationDemandFactor = 1; - public array $resourceRequirements = [ + + public array $resourceRequirementsBase = [ + 'wood' => 100, + 'clay' => 200, + 'iron' => 100, + 'food' => 200, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 1.0, 'clay' => 2.0, 'iron' => 1.0, diff --git a/src/Model/Unit/WoodCutter.php b/src/Model/Unit/WoodCutter.php index d8c2c42..02aea85 100644 --- a/src/Model/Unit/WoodCutter.php +++ b/src/Model/Unit/WoodCutter.php @@ -9,7 +9,14 @@ class WoodCutter extends Unit public string $buildingType = 'WoodCutter'; public int $travelTime = 1; public int $populationDemandFactor = 1; - public array $resourceRequirements = [ + + public array $resourceRequirementsBase = [ + 'wood' => 200, + 'clay' => 100, + 'iron' => 100, + 'food' => 200, + ]; + public array $resourceRequirementsFactor = [ 'wood' => 2.0, 'clay' => 1.0, 'iron' => 1.0, -- cgit v1.2.3