Beispiel #1
0
 /**
  * Initializes the vv4a balance of the base.
  * 
  * This step takes into account:
  * 
  * 1) Possible production of vv4a according to buildings on the base.
  * 2) Configured production amount.
  * 3) Energy balance of the base.
  */
 private function initVv4aBalance()
 {
     $this->balanceVv4a = 0.0;
     // 1) Possible production of vv4a according to buildings on the base.
     $producibleVv4a = 0.0;
     foreach ($this->base->getBuildingCounters() as $id => $counter) {
         $building = $this->buildingFinder->getById($id);
         $producibleVv4a += $counter * $building->getBalanceVv4a();
     }
     // 2) Configured production amount.
     // null means "produce as much as possible"
     // If there is something configured, just make sure it's not more than what
     // is possible according to the production buildings.
     if ($this->base->produced_vv4a !== null) {
         $vv4aToProduce = intval($this->base->produced_vv4a);
         $producibleVv4a = min($producibleVv4a, $vv4aToProduce);
     }
     // 4) Energy balance of the base
     if ($this->balanceEnergy < $producibleVv4a && intval($this->base->stored_energy) === 0) {
         $producibleVv4a = max(0, $this->balanceEnergy);
     }
     $this->balanceEnergy -= $producibleVv4a;
     $this->balanceSteel -= 2 * $producibleVv4a;
     $this->balanceVv4a += $producibleVv4a;
 }
Beispiel #2
0
 /**
  * @TODO Currently, we can have more people employed than there are on the
  *       planet. Not sure how IW handled it, but maybe we can create strikes
  *       or drop production if there are less people than could be employed?
  */
 private function calculateEmployedPopulation()
 {
     $this->employedPopulation = 0;
     foreach ($this->base->getBuildingCounters() as $id => $counter) {
         /* @var $building \frontend\models\Building */
         $building = $this->buildingFinder->getById($id);
         if ($building->getBalancePeople() < 0) {
             $this->employedPopulation += $counter * \abs($building->getBalancePeople());
         }
     }
 }
 public function calculateBaseCapacity(Base $base)
 {
     $buildingCounters = $base->getBuildingCounters();
     $shelters = $this->buildingFinder->getByGroup('shelters');
     $baseCapacity = new Resources();
     foreach ($shelters as $id => $shelter) {
         $counter = $buildingCounters[$id];
         /* @var $shelter \frontend\behaviors\ShelterCapacityBehavior */
         $capacity = $shelter->calculateShelterCapacity($counter);
         $baseCapacity->chemicals += $capacity->chemicals;
         $baseCapacity->energy += $capacity->energy;
         $baseCapacity->ice += $capacity->ice;
         $baseCapacity->iron += $capacity->iron;
         $baseCapacity->population += $capacity->population;
         $baseCapacity->steel += $capacity->steel;
         $baseCapacity->vv4a += $capacity->vv4a;
         $baseCapacity->water += $capacity->water;
     }
     return $baseCapacity;
 }
Beispiel #4
0
 /**
  * @param \common\models\Base $base
  * @return \frontend\objects\Resources
  */
 public function calculateStorage(Base $base)
 {
     $energy = 0;
     $chemicals = 0;
     $iceAndWater = 0;
     $warehouses = $this->buildingFinder->getByGroup('warehouses');
     $buildingCounters = $base->getBuildingCounters();
     foreach ($warehouses as $id => $building) {
         $counter = $buildingCounters[$id];
         // TODO: Refactor. Each group of buildings could attach specific behaviors
         //       Those could extend the building with needed functionality.
         //       Warehouses: getStorageCapacity( $nWarehouses )
         //       Shelters: getShelterCapacity( $nWarehouses )
         for ($i = 1; i <= $counter; ++$i) {
             $energy += ($i * ($i - 2) + 2) * $building->getStorageEnergy();
             $chemicals += ($i * ($i - 2) + 2) * $building->getStorageChemicals();
             $iceAndWater += ($i * ($i - 2) + 2) * $building->getStorageIceAndWater();
         }
     }
     return new Resources(['iron' => PHP_INT_MAX, 'steel' => PHP_INT_MAX, 'chemicals' => $chemicals, 'vv4a' => PHP_INT_MAX, 'population' => PHP_INT_MAX, 'ice' => $iceAndWater, 'water' => $iceAndWater, 'energy' => $energy, 'credits' => PHP_INT_MAX]);
 }