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/Unit.php | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'src/Model/Unit.php') 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']; -- cgit v1.2.3