summaryrefslogtreecommitdiff
path: root/src/Model/Unit.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Unit.php')
-rw-r--r--src/Model/Unit.php43
1 files changed, 23 insertions, 20 deletions
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'];