getBuilding()->level ?: 1)) * $amount); } public function getPopulationDemand(): int { return $this->getPopulationDemandForAmount($this->amount); } public function getPopulationDemandForAmount(int $amount): int { return $amount * $this->populationDemandFactor; } /* Relations */ public function getBuilding(): ?Building { return Village::getBuilding($this->homeVillageId, $this->buildingType); } public function cast(): Unit { $class = Unit::resolveType($this->type); return Model::castToType($this, Unit::resolveType($this->type)); } public static function resolveType(string $type): string { return __NAMESPACE__ . '\\Unit\\' . $type; } /* Static */ 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', ['type' => $unitType, 'id' => $villageId] ); $result = $statement->fetch()['sum']; return intval($result); } }