From 94a3dd52da3ae180af37c6fd0e8c24b3562da388 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 4 Oct 2023 11:32:04 +0200 Subject: initial commit 2 --- src/Model/Village.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/Model/Village.php') diff --git a/src/Model/Village.php b/src/Model/Village.php index cd1c749..b1ab19e 100644 --- a/src/Model/Village.php +++ b/src/Model/Village.php @@ -41,6 +41,18 @@ class Village return true; } + public static function canTrain(Village $village, Unit $unit, int $amount): bool + { + $resourceRequirements = Unit::getResourceRequirements($unit, $amount); + foreach ($resourceRequirements as $resourceType => $requirement) { + if ($village->$resourceType < $requirement) { + return false; + } + } + + return true; + } + /* DB - Actions */ public static function get(int $id): ?Village @@ -61,6 +73,11 @@ class Village ); } + public static function getDistance(int $x, int $y, int $dx, int $dy): int + { + return abs($x - $dx) + abs($y - $dy); + } + /* DB - Relations */ public static function getBuildings(int $villageId): array -- cgit v1.2.3