summaryrefslogtreecommitdiff
path: root/src/Model
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model')
-rw-r--r--src/Model/Building/Farm.php8
-rw-r--r--src/Model/Village.php11
2 files changed, 12 insertions, 7 deletions
diff --git a/src/Model/Building/Farm.php b/src/Model/Building/Farm.php
index 1a69c89..7957dca 100644
--- a/src/Model/Building/Farm.php
+++ b/src/Model/Building/Farm.php
@@ -2,7 +2,6 @@
namespace App\Model\Building;
-use App\Model\Unit;
use App\Model\Village;
class Farm extends ResourceGenerator
@@ -26,12 +25,7 @@ class Farm extends ResourceGenerator
public function getResourceIncrementor(): int
{
- $populationDemand = array_reduce(
- Village::getUnits($this->villageId, Village::FETCH_UNIT_RESIDENCE, Village::RETURN_UNIT_EXISTING),
- function ($carry, Unit $unit) {
- return $carry + $unit->getPopulationDemand();
- }
- );
+ $populationDemand = Village::getPopulationDemand($this->villageId);
return parent::getResourceIncrementor() - $populationDemand;
}
diff --git a/src/Model/Village.php b/src/Model/Village.php
index 03a57b7..ff0b7e8 100644
--- a/src/Model/Village.php
+++ b/src/Model/Village.php
@@ -143,6 +143,17 @@ class Village
return $results[0] ?? null;
}
+ public static function getPopulationDemand(int $villageId): int
+ {
+ return array_reduce(
+ Village::getUnits($villageId, Village::FETCH_UNIT_RESIDENCE, Village::RETURN_UNIT_EXISTING),
+ function ($carry, Unit $unit) {
+ return $carry + $unit->getPopulationDemand();
+ },
+ 0
+ );
+ }
+
public const FETCH_UNIT_HOME_AT_HOME = 1;
public const FETCH_UNIT_HOME_AT_SUPPORT = 2;
public const FETCH_UNIT_SUPPORT_AT_HOME = 3;