summaryrefslogtreecommitdiff
path: root/src/Model/Building/Farm.php
blob: 1a69c898f87010d9b1000365f4325eb7f6df5e32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php

namespace App\Model\Building;

use App\Model\Unit;
use App\Model\Village;

class Farm extends ResourceGenerator
{
  public string $unitType = 'Farmer';
  public int $buildTimeFactor = 1;
  public int $maxLevel = 25;

  public array $resourceRequirementsBase = [
    'wood' => 100,
    'clay' => 100,
    'iron' => 100,
  ];
  public array $resourceRequirementsFactor = [
    'wood' => 1.0,
    'clay' => 1.0,
    'iron' => 1.0,
  ];

  public string $resourceType = 'food';

  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();
      }
    );

    return parent::getResourceIncrementor() - $populationDemand;
  }
}