<?php

$sectorArr = $sectorConn->getSectorByCoordinates($coordinateX, $coordinateY);
$sector = new Sector($sectorArr[0], $sectorArr[1], $sectorArr[2], $sectorArr[3], $sectorArr[4], $sectorArr[5], $sectorArr[6], $sectorArr[7], explode(",", $sectorArr[8]), explode(",", $sectorArr[9]), $sectorArr[10]);
$distanceFromCapitol = $sector->getDistanceFromCapitolSector($playerId, $sectorConn);
if (!$distanceFromCapitol) {
    if (!isset($staticData)) {
        require_once HOME . 'controllers/StaticData/initStaticData.php';
    }
    if (!$staticData->getSectors()) {
        $sectorsArr = $sectorConn->getAllSectors();
        foreach ($sectorsArr as $sectorArr) {
            $allSectors[] = new Sector($sectorArr[0], $sectorArr[1], $sectorArr[2], $sectorArr[3], $sectorArr[4], $sectorArr[5], $sectorArr[6], $sectorArr[7], explode(",", $sectorArr[8]), explode(",", $sectorArr[9]), $sectorArr[10]);
        }
        $staticData->setSectors($allSectors);
    }
    $ownedSectors = Sector::getOwnedSectors($staticData->getSectors(), $playerId);
    $distanceFromCapitol = Sector::getMaxDistance($ownedSectors);
}
if (!isset($allManteinances)) {
    $unitsArr = $unitConn->getAllUnits();
    $allManteinances = array();
    foreach ($unitsArr as $unitArr) {
        $unit = new Unit($unitArr[0], $unitArr[1], $unitArr[2], $unitArr[3], $unitArr[4], $unitArr[5], $unitArr[6], $unitArr[7], $unitArr[8], explode(",", $unitArr[9]), explode(",", $unitArr[10]), explode(",", $unitArr[11]), $unitArr[12], $unitArr[13], $unitArr[14], $unitArr[15]);
        $unitId = $unitArr[0];
        $manteinance = $unit->getEfectiveManteinanceCosts($distanceFromCapitol);
        $allManteinances[$unitId] = $manteinance;
    }
}
$unitQueueArr = $sectorConn->getUnitQueueLists($coordinateX, $coordinateY, $playerId);
$queuedUnits = explode(",", $unitQueueArr[0]);