getAllUnits($village->wid, true, 1); /** * Cache unit list to avoid repeated calls */ $unitNameCache = array(); $troopsPresent = false; /** * --------------------------------------------------------- * Loop all possible units (Travian standard max 50) * --------------------------------------------------------- */ for ($i = 1; $i <= 50; $i++) { $unitKey = 'u' . $i; if (!empty($troops[$unitKey])) { /** * Cache unit name (avoid repeated calls) */ if (!isset($unitNameCache[$i])) { $unitNameCache[$i] = $technology->getUnitName($i); } $unitName = $unitNameCache[$i]; echo ' '; $troopsPresent = true; } } /** * --------------------------------------------------------- * Hero handling * --------------------------------------------------------- */ if (!empty($troops['hero'])) { echo ' '; $troopsPresent = true; } /** * --------------------------------------------------------- * Empty state * --------------------------------------------------------- */ if (!$troopsPresent) { echo ''; } ?>
' . $unitName . ' ' . $troops[$unitKey] . ' ' . $unitName . '
Hero ' . (int)$troops['hero'] . ' Hero
none