public function show()
 {
     global $USER, $PLANET, $resource, $reslist, $LNG, $pricelist;
     $updateID = HTTP::_GP('id', 0);
     if (!empty($updateID) && $_SERVER['REQUEST_METHOD'] === 'POST' && $USER['urlaubs_modus'] == 0) {
         if (isModulAvalible(MODULE_OFFICIER) && in_array($updateID, $reslist['officier'])) {
             $this->UpdateOfficier($updateID);
         } elseif (isModulAvalible(MODULE_DMEXTRAS) && in_array($updateID, $reslist['dmfunc'])) {
             $this->UpdateExtra($updateID);
         }
     }
     $darkmatterList = array();
     $officierList = array();
     if (isModulAvalible(MODULE_DMEXTRAS)) {
         foreach ($reslist['dmfunc'] as $Element) {
             if ($USER[$resource[$Element]] > TIMESTAMP) {
                 $this->tplObj->execscript("GetOfficerTime(" . $Element . ", " . ($USER[$resource[$Element]] - TIMESTAMP) . ");");
             }
             $costResources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
             $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costResources);
             $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costResources);
             $elementBonus = BuildFunctions::getAvalibleBonus($Element);
             $darkmatterList[$Element] = array('timeLeft' => max($USER[$resource[$Element]] - TIMESTAMP, 0), 'costResources' => $costResources, 'buyable' => $buyable, 'time' => $pricelist[$Element]['time'], 'costOverflow' => $costOverflow, 'elementBonus' => $elementBonus);
         }
     }
     if (isModulAvalible(MODULE_OFFICIER)) {
         foreach ($reslist['officier'] as $Element) {
             if (!BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element)) {
                 continue;
             }
             $costResources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
             $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costResources);
             $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costResources);
             $elementBonus = BuildFunctions::getAvalibleBonus($Element);
             $officierList[$Element] = array('level' => $USER[$resource[$Element]], 'maxLevel' => $pricelist[$Element]['max'], 'costResources' => $costResources, 'buyable' => $buyable, 'costOverflow' => $costOverflow, 'elementBonus' => $elementBonus);
         }
     }
     $this->assign(array('officierList' => $officierList, 'darkmatterList' => $darkmatterList, 'of_dm_trade' => sprintf($LNG['of_dm_trade'], $LNG['tech'][921])));
     $this->display('page.officier.default.tpl');
 }
 public function show()
 {
     global $USER, $PLANET, $LNG, $resource, $dpath, $reslist, $requeriments, $CONF;
     $fmenge = isset($_POST['fmenge']) ? $_POST['fmenge'] : array();
     $action = HTTP::_GP('action', '');
     $NotBuilding = true;
     if (!empty($PLANET['b_building_id'])) {
         $CurrentQueue = unserialize($PLANET['b_building_id']);
         foreach ($CurrentQueue as $ElementArray) {
             if ($ElementArray[0] == 21 || $ElementArray[0] == 15) {
                 $NotBuilding = false;
                 break;
             }
         }
     }
     $ElementQueue = unserialize($PLANET['b_hangar_id']);
     if (empty($ElementQueue)) {
         $Count = 0;
     } else {
         $Count = count($ElementQueue);
     }
     if ($USER['urlaubs_modus'] == 0) {
         if (!empty($fmenge) && $NotBuilding == true) {
             if (Config::get('max_elements_ships') != 0 && $Count >= Config::get('max_elements_ships')) {
                 $this->printMessage(sprintf($LNG['bd_max_builds'], Config::get('max_elements_ships')));
                 exit;
             }
             $this->BuildAuftr($fmenge);
         }
         if ($action == "delete") {
             $this->CancelAuftr();
         }
     }
     $elementInQueue = array();
     $ElementQueue = unserialize($PLANET['b_hangar_id']);
     $Buildlist = array();
     if (!empty($ElementQueue)) {
         $Shipyard = array();
         $QueueTime = 0;
         foreach ($ElementQueue as $Element) {
             if (empty($Element)) {
                 continue;
             }
             $elementInQueue[$Element[0]] = true;
             $ElementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element[0]);
             $QueueTime += $ElementTime * $Element[1];
             $Shipyard[] = array($LNG['tech'][$Element[0]], $Element[1], $ElementTime, $Element[0]);
         }
         $this->tplObj->loadscript('bcmath.js');
         $this->tplObj->execscript('ShipyardInit();');
         $Buildlist = array('Queue' => $Shipyard, 'b_hangar_id_plus' => $PLANET['b_hangar'], 'pretty_time_b_hangar' => pretty_time(max($QueueTime - $PLANET['b_hangar'], 0)));
     }
     $mode = HTTP::_GP('mode', 'fleet');
     if ($mode != 'defense' && $PLANET['planet_type'] == 4) {
         $this->printMessage("You cant acces this page on a fortress");
     }
     if ($mode == 'defense' && $CONF['fleetconf'] == 1 && $CONF['purchase_bonus_timer'] > TIMESTAMP) {
         $elementALL = array(401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 416, 417, 418, 419, 420, 421, 422, 502, 503);
         $elementIDs = array(407, 408, 409, 411, 502, 503);
         $elementIDd = array(401, 402, 403, 420);
         $elementIDa = array(405, 404, 406, 416, 417, 421);
         $elementIDq = array(418, 412, 410, 413, 419, 414, 422, 415);
     } elseif ($mode == 'defense') {
         $elementALL = array(401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 416, 417, 418, 419, 420, 421, 422, 502, 503);
         $elementIDs = array(407, 408, 409, 411, 502, 503);
         $elementIDd = array(401, 402, 403);
         $elementIDa = array(405, 404, 406, 416, 417);
         $elementIDq = array(418, 412, 410, 413, 419, 414, 415);
     } elseif ($mode == 'fleet' && $CONF['fleetconf'] == 1 && $CONF['purchase_bonus_timer'] > TIMESTAMP) {
         $elementALL = array(202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230);
         $elementIDs = array(208, 210, 220, 223);
         $elementIDd = array(212, 202, 203, 204, 205, 229);
         $elementIDa = array(209, 206, 207, 217, 215, 213, 211, 219, 224);
         $elementIDq = array(225, 226, 214, 216, 230, 227, 228, 222, 218, 221);
     } elseif ($mode == 'fleet') {
         $elementALL = array(202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230);
         $elementIDs = array(208, 210, 220, 223);
         $elementIDd = array(212, 202, 203, 204, 205);
         $elementIDa = array(209, 206, 207, 217, 215, 213, 211, 219);
         $elementIDq = array(225, 226, 214, 216, 227, 228, 222, 218, 221);
     }
     $Missiles = array();
     $Domes = array();
     $Orbits = array();
     foreach ($reslist['missile'] as $elementID) {
         $Missiles[$elementID] = $PLANET[$resource[$elementID]];
     }
     foreach ($reslist['defense'] as $elementID) {
         $Domes[$elementID] = $PLANET[$resource[$elementID]];
         $Orbits[$elementID] = $PLANET[$resource[$elementID]];
     }
     $MaxMissiles = BuildFunctions::getMaxConstructibleRockets($USER, $PLANET, $Missiles);
     $MaxDomes = BuildFunctions::getMaxConstructibleDomes($USER, $PLANET, $Domes);
     $MaxOrbits = BuildFunctions::getMaxConstructibleOrbits($USER, $PLANET, $Orbits);
     foreach ($elementALL as $Element) {
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         if (isset($MaxDomes[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxDomes[$Element]);
         }
         if (isset($MaxOrbits[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxOrbits[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementListall[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDs as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         if (isset($MaxDomes[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxDomes[$Element]);
         }
         if (isset($MaxOrbits[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxOrbits[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementList[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDq as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         if (isset($MaxDomes[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxDomes[$Element]);
         }
         if (isset($MaxOrbits[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxOrbits[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementListq[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDa as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         if (isset($MaxDomes[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxDomes[$Element]);
         }
         if (isset($MaxOrbits[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxOrbits[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementLista[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDd as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         if (isset($MaxDomes[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxDomes[$Element]);
         }
         if (isset($MaxOrbits[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxOrbits[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementListd[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     $manual_step_9 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 9 && ($PLANET['misil_launcher'] < 25 || $PLANET['small_laser'] < 10)) {
         $manual_step_9 = 0;
     }
     $manual_step_10 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 9 && $PLANET['misil_launcher'] >= 25 && $PLANET['small_laser'] >= 10) {
         $manual_step_10 = 0;
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `training_step` = '11' WHERE `id` = " . $USER['id'] . ";");
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `experience_peace` = `experience_peace` + '650' WHERE `id` = '" . $USER['id'] . "';");
         require_once 'includes/classes/class.FleetFunctions.php';
         $rawfleetarray = array(204 => 8, 205 => 5, 206 => 3);
         $fleetRessource = array(901 => 0, 902 => 0, 903 => 0);
         FleetFunctions::sendFleet($rawfleetarray, '1', 1, 1, 1, 1, 1, 1, $PLANET['id_owner'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $fleetRessource, TIMESTAMP + 58, TIMESTAMP + 58, TIMESTAMP + 116, 0);
     }
     $manual_step_16 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 16) {
         $manual_step_16 = 0;
     }
     if ($USER['training'] == 0 && $USER['training_step'] == 16 && $PLANET['recycler'] >= 5) {
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `training_step` = '17' WHERE `id` = " . $USER['id'] . ";");
     }
     $this->tplObj->loadscript('shipyard.js');
     $this->tplObj->assign_vars(array('manual_step_16' => $manual_step_16, 'manual_step_10' => $manual_step_10, 'manual_step_9' => $manual_step_9, 'elementListall' => $elementListall, 'elementList' => $elementList, 'elementListd' => $elementListd, 'elementLista' => $elementLista, 'elementListq' => $elementListq, 'NotBuilding' => $NotBuilding, 'BuildList' => $Buildlist, 'maxlength' => strlen(Config::get('max_fleet_per_build')), 'mode' => $mode));
     $this->display('page.shipyard.default.tpl');
 }
 public function show()
 {
     global $ProdGrid, $LNG, $resource, $reslist, $PLANET, $USER, $pricelist;
     $TheCommand = HTTP::_GP('cmd', '');
     // wellformed buildURLs
     if (!empty($TheCommand) && $_SERVER['REQUEST_METHOD'] === 'POST' && $USER['urlaubs_modus'] == 0) {
         $Element = HTTP::_GP('building', 0);
         $ListID = HTTP::_GP('listid', 0);
         switch ($TheCommand) {
             case 'cancel':
                 $this->CancelBuildingFromQueue();
                 break;
             case 'remove':
                 $this->RemoveBuildingFromQueue($ListID);
                 break;
             case 'insert':
                 $this->AddBuildingToQueue($Element, true);
                 break;
             case 'destroy':
                 $this->AddBuildingToQueue($Element, false);
                 break;
         }
         $this->redirectTo('game.php?page=buildings');
     }
     $config = Config::get();
     $queueData = $this->getQueueData();
     $Queue = $queueData['queue'];
     $QueueCount = count($Queue);
     $CanBuildElement = isVacationMode($USER) || $config->max_elements_build == 0 || $QueueCount < $config->max_elements_build;
     $CurrentMaxFields = CalculateMaxPlanetFields($PLANET);
     $RoomIsOk = $PLANET['field_current'] < $CurrentMaxFields - $QueueCount;
     $BuildEnergy = $USER[$resource[113]];
     $BuildLevelFactor = 10;
     $BuildTemp = $PLANET['temp_max'];
     $BuildInfoList = array();
     $Elements = $reslist['allow'][$PLANET['planet_type']];
     foreach ($Elements as $Element) {
         if (!BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element)) {
             continue;
         }
         $infoEnergy = "";
         if (isset($queueData['quickinfo'][$Element])) {
             $levelToBuild = $queueData['quickinfo'][$Element];
         } else {
             $levelToBuild = $PLANET[$resource[$Element]];
         }
         if (in_array($Element, $reslist['prod'])) {
             $BuildLevel = $PLANET[$resource[$Element]];
             $Need = eval(ResourceUpdate::getProd($ProdGrid[$Element]['production'][911]));
             $BuildLevel = $levelToBuild + 1;
             $Prod = eval(ResourceUpdate::getProd($ProdGrid[$Element]['production'][911]));
             $requireEnergy = $Prod - $Need;
             $requireEnergy = round($requireEnergy * $config->energySpeed);
             if ($requireEnergy < 0) {
                 $infoEnergy = sprintf($LNG['bd_need_engine'], pretty_number(abs($requireEnergy)), $LNG['tech'][911]);
             } else {
                 $infoEnergy = sprintf($LNG['bd_more_engine'], pretty_number(abs($requireEnergy)), $LNG['tech'][911]);
             }
         }
         $costResources = BuildFunctions::getElementPrice($USER, $PLANET, $Element, false, $levelToBuild);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costResources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costResources);
         $destroyResources = BuildFunctions::getElementPrice($USER, $PLANET, $Element, true);
         $destroyTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $destroyResources);
         $destroyOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $destroyResources);
         $buyable = $QueueCount != 0 || BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costResources);
         $BuildInfoList[$Element] = array('level' => $PLANET[$resource[$Element]], 'maxLevel' => $pricelist[$Element]['max'], 'infoEnergy' => $infoEnergy, 'costResources' => $costResources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'destroyResources' => $destroyResources, 'destroyTime' => $destroyTime, 'destroyOverflow' => $destroyOverflow, 'buyable' => $buyable, 'levelToBuild' => $levelToBuild);
     }
     if ($QueueCount != 0) {
         $this->tplObj->loadscript('buildlist.js');
     }
     $this->assign(array('BuildInfoList' => $BuildInfoList, 'CanBuildElement' => $CanBuildElement, 'RoomIsOk' => $RoomIsOk, 'Queue' => $Queue, 'isBusy' => array('shipyard' => !empty($PLANET['b_hangar_id']), 'research' => $USER['b_tech_planet'] != 0), 'HaveMissiles' => (bool) $PLANET[$resource[503]] + $PLANET[$resource[502]]));
     $this->display('page.buildings.default.tpl');
 }
 public function show()
 {
     global $USER, $CONF, $PLANET, $resource, $reslist, $LNG, $pricelist;
     $updateID = HTTP::_GP('id', 0);
     if (!empty($updateID) && $_SERVER['REQUEST_METHOD'] === 'POST' && $USER['urlaubs_modus'] == 0) {
         if (isModulAvalible(MODULE_OFFICIER) && in_array($updateID, $reslist['officier'])) {
             $this->UpdateOfficier($updateID);
         } elseif (isModulAvalible(MODULE_DMEXTRAS) && in_array($updateID, $reslist['dmfunc'])) {
             $this->UpdateExtra($updateID);
         }
     }
     $this->tplObj->loadscript('officier.js');
     $darkmatterList = array();
     $officierList = array();
     if (isModulAvalible(MODULE_DMEXTRAS)) {
         foreach ($reslist['dmfunc'] as $Element) {
             if ($USER[$resource[$Element]] > TIMESTAMP) {
                 $this->tplObj->execscript("GetOfficerTime(" . $Element . ", " . ($USER[$resource[$Element]] - TIMESTAMP) . ");");
             }
             $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
             $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
             $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
             $elementBonus = BuildFunctions::getAvalibleBonus($Element);
             $darkmatterList[$Element] = array('timeLeft' => max($USER[$resource[$Element]] - TIMESTAMP, 0), 'costRessources' => $costRessources, 'buyable' => $buyable, 'time' => $pricelist[$Element]['time'], 'costOverflow' => $costOverflow, 'elementBonus' => $elementBonus);
         }
     }
     if (isModulAvalible(MODULE_OFFICIER)) {
         foreach ($reslist['officier'] as $Element) {
             $AllTech = array();
             $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
             if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
                 while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                     $AllTech[] = $x;
                 }
             }
             $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
             $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
             $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
             $elementBonus = BuildFunctions::getAvalibleBonus($Element);
             $officierList[$Element] = array('level' => $USER[$resource[$Element]], 'maxLevel' => $pricelist[$Element]['max'], 'costRessources' => $costRessources, 'buyable' => $buyable, 'costOverflow' => $costOverflow, 'elementBonus' => $elementBonus, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
         }
     }
     $close_to = 1;
     if ($USER['rpg_geologue'] >= 1 && $USER['rpg_amiral'] >= 1 && $USER['training_step'] == 23) {
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `training_step` = '24' WHERE `id` = " . $USER['id'] . ";");
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `experience_peace` = `experience_peace` + '24' WHERE `id` = " . $USER['id'] . ";");
         $close_to = 0;
     }
     $manual_23_step = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 23 && $close_to == 1) {
         $manual_23_step = 0;
     }
     $this->tplObj->assign_vars(array('manual_23_step' => $manual_23_step, 'close_to' => $close_to, 'officierList' => $officierList, 'darkmatterList' => $darkmatterList, 'of_dm_trade' => sprintf($LNG['of_dm_trade'], $LNG['tech'][921])));
     $this->display('page.officier.default.tpl');
 }
 public function show()
 {
     global $PLANET, $USER, $LNG, $resource, $reslist, $pricelist;
     if ($PLANET[$resource[31]] == 0) {
         $this->printMessage($LNG['bd_lab_required']);
     }
     $TheCommand = HTTP::_GP('cmd', '');
     $elementId = HTTP::_GP('tech', 0);
     $ListID = HTTP::_GP('listid', 0);
     $PLANET[$resource[31] . '_inter'] = ResourceUpdate::getNetworkLevel($USER, $PLANET);
     if (!empty($TheCommand) && $_SERVER['REQUEST_METHOD'] === 'POST' && $USER['urlaubs_modus'] == 0) {
         switch ($TheCommand) {
             case 'cancel':
                 $this->CancelBuildingFromQueue();
                 break;
             case 'remove':
                 $this->RemoveBuildingFromQueue($ListID);
                 break;
             case 'insert':
                 $this->AddBuildingToQueue($elementId, true);
                 break;
             case 'destroy':
                 $this->AddBuildingToQueue($elementId, false);
                 break;
         }
         $this->redirectTo('game.php?page=research');
     }
     $bContinue = $this->CheckLabSettingsInQueue($PLANET);
     $queueData = $this->getQueueData();
     $TechQueue = $queueData['queue'];
     $QueueCount = count($TechQueue);
     $ResearchList = array();
     foreach ($reslist['tech'] as $elementId) {
         if (!BuildFunctions::isTechnologieAccessible($USER, $PLANET, $elementId)) {
             continue;
         }
         if (isset($queueData['quickinfo'][$elementId])) {
             $levelToBuild = $queueData['quickinfo'][$elementId];
         } else {
             $levelToBuild = $USER[$resource[$elementId]];
         }
         $costResources = BuildFunctions::getElementPrice($USER, $PLANET, $elementId, false, $levelToBuild);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $elementId, $costResources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $elementId, $costResources);
         $buyable = $QueueCount != 0 || BuildFunctions::isElementBuyable($USER, $PLANET, $elementId, $costResources);
         $ResearchList[$elementId] = array('id' => $elementId, 'level' => $USER[$resource[$elementId]], 'maxLevel' => $pricelist[$elementId]['max'], 'costResources' => $costResources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'levelToBuild' => $levelToBuild);
     }
     $this->assign(array('ResearchList' => $ResearchList, 'IsLabinBuild' => !$bContinue, 'IsFullQueue' => Config::get()->max_elements_tech == 0 || Config::get()->max_elements_tech == count($TechQueue), 'Queue' => $TechQueue));
     $this->display('page.research.default.tpl');
 }
 public function show()
 {
     global $ProdGrid, $LNG, $resource, $reslist, $CONF, $PLANET, $USER, $pricelist;
     $buscarTick = $GLOBALS['DATABASE']->query("SELECT tick FROM " . CONFIG . "");
     $tickinicial = $GLOBALS['DATABASE']->fetch_array($buscarTick);
     $tickinicial = $tickinicial['tick'];
     $TheCommand = HTTP::_GP('cmd', '');
     // wellformed buildURLs
     if (!empty($TheCommand) && $_SERVER['REQUEST_METHOD'] === 'POST' && $USER['urlaubs_modus'] == 0) {
         $Element = HTTP::_GP('building', 0);
         $ListID = HTTP::_GP('listid', 0);
         $lvlup1 = HTTP::_GP('lvlup1', 0);
         switch ($TheCommand) {
             case 'cancel':
                 $this->CancelBuildingFromQueue();
                 break;
             case 'remove':
                 $this->RemoveBuildingFromQueue($ListID);
                 break;
             case 'insert':
                 $this->AddBuildingToQueue($Element, $lvlup1, true);
                 break;
             case 'destroy':
                 $this->DoAddBuildingToQueue($Element, false);
                 break;
         }
         $this->redirectTo('game.php?page=buildings');
     }
     $premium_stage = 0;
     if ($USER['premium_reward_stage'] > 0 && $USER['premium_reward_stage_days'] > TIMESTAMP) {
         $premium_stage = $USER['premium_reward_stage'];
     }
     $queueData = $this->getQueueData();
     $Queue = $queueData['queue'];
     $QueueCount = count($Queue);
     $CanBuildElement = isVacationMode($USER) || Config::get('max_elements_build') - 1 == 0 || $QueueCount < Config::get('max_elements_build') - 1 + $premium_stage;
     $CurrentMaxFields = CalculateMaxPlanetFields($PLANET);
     $RoomIsOk = $PLANET['field_current'] < $CurrentMaxFields - $QueueCount;
     $BuildEnergy = $USER[$resource[113]];
     $BuildLevelFactor = 10;
     $BuildTemp = $PLANET['temp_max'];
     $BuildInfoList = array();
     $Elements = $reslist['allow'][$PLANET['planet_type']];
     foreach ($Elements as $ID => $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $infoEnergy = "";
         if (isset($queueData['quickinfo'][$Element])) {
             $levelToBuild = $queueData['quickinfo'][$Element];
         } else {
             $levelToBuild = $PLANET[$resource[$Element]];
         }
         if (in_array($Element, $reslist['prod'])) {
             $peacefull_resource = 0;
             if ($USER['experience_peace_level'] > 0) {
                 $peacefull_resource = $USER['experience_peace_level'];
             }
             $peacefull_resource = $peacefull_resource;
             $premium_resource = 0;
             if ($USER['premium_reward_extraction'] > 0 && $USER['premium_reward_extraction_days'] > TIMESTAMP) {
                 $premium_resource = $USER['premium_reward_extraction'];
             }
             $premium_resource = $premium_resource;
             $combat_collider = 0;
             if ($USER['combat_reward_collider'] > 0) {
                 $combat_collider = $USER['combat_reward_collider'];
             }
             $combat_collider = $combat_collider;
             $academy_mines = 0;
             if ($USER['academy_1201'] > 0) {
                 $academy_mines = getbonusOneBis(1201, $USER['academy_1201']);
             }
             $academy_mines = $academy_mines;
             $daily_prod_bonus = 0;
             if ($USER['daily_produ'] > TIMESTAMP) {
                 $daily_prod_bonus = 30;
             }
             $daily_prod_bonus = $daily_prod_bonus;
             $academy_energy = 0;
             if ($USER['academy_1202'] > 0) {
                 $academy_energy = getbonusOneBis(1202, $USER['academy_1202']);
             }
             $academy_energy = $academy_energy;
             $academy_fusion = 0;
             if ($USER['academy_1209'] > 0) {
                 $academy_fusion = getbonusOneBis(1209, $USER['academy_1209']);
             }
             $academy_fusion = $academy_fusion;
             $academy_solar = 0;
             if ($USER['academy_1210'] > 0) {
                 $academy_solar = getbonusOneBis(1210, $USER['academy_1210']);
             }
             $academy_solar = $academy_solar;
             $allyInfo = $GLOBALS['DATABASE']->query("SELECT alliance_prod FROM `uni1_alliance` WHERE id = " . $USER['ally_id'] . ";");
             $allyInfo = $GLOBALS['DATABASE']->fetch_array($allyInfo);
             $alliance_prod = 0;
             if ($allyInfo['alliance_prod'] > 0) {
                 $alliance_prod = $allyInfo['alliance_prod'];
             }
             $alliance_prod = $alliance_prod;
             $BuildLevel = $PLANET[$resource[$Element]];
             $Need = round(eval(ResourceUpdate::getProd($ProdGrid[$Element]['production'][911])));
             $BuildLevel = $levelToBuild + 1;
             $Prod = round(eval(ResourceUpdate::getProd($ProdGrid[$Element]['production'][911])));
             $requireEnergy = $Prod - $Need;
             if ($requireEnergy < 0) {
                 $infoEnergy = sprintf($LNG['bd_need_engine'], pretty_number(abs($requireEnergy)), $LNG['tech'][911]);
             } else {
                 $infoEnergy = sprintf($LNG['bd_more_engine'], pretty_number(abs($requireEnergy)), $LNG['tech'][911]);
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element, false, $levelToBuild);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $destroyRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element, true);
         $destroyTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $destroyRessources);
         $destroyOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $destroyRessources);
         $buyable = $QueueCount != 0 || BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $BuildInfoList[$Element] = array('level' => $PLANET[$resource[$Element]], 'maxLevel' => $pricelist[$Element]['max'], 'factor' => $pricelist[$Element]['factor'], 'infoEnergy' => $infoEnergy, 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'destroyRessources' => $destroyRessources, 'destroyTime' => $destroyTime, 'destroyOverflow' => $destroyOverflow, 'buyable' => $buyable, 'levelToBuild' => $levelToBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     $this->tplObj->loadscript('buildlist.js');
     $manual_step_2 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 2 && $PLANET['solar_plant'] < 1) {
         $manual_step_2 = 0;
     }
     $manual_step_2_1 = 1;
     if ($USER['training'] == 0 && $PLANET['solar_plant'] >= 1 && $USER['training_step'] == 2 && ($PLANET['metal_mine'] < 3 || $PLANET['crystal_mine'] < 2 || $PLANET['deuterium_sintetizer'] < 1)) {
         $manual_step_2_1 = 0;
     }
     $manual_step_2_2 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 2 && $PLANET['metal_mine'] >= 3 && $PLANET['crystal_mine'] >= 2 && $PLANET['deuterium_sintetizer'] >= 1 && $PLANET['solar_plant'] < 4) {
         $manual_step_2_2 = 0;
     }
     $manual_step_2_3 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 2 && $PLANET['metal_mine'] >= 3 && $PLANET['crystal_mine'] >= 2 && $PLANET['deuterium_sintetizer'] >= 1 && $PLANET['solar_plant'] >= 4) {
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `training_step` = '3' WHERE `id` = " . $USER['id'] . ";");
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `experience_peace` = `experience_peace` + '650' WHERE `id` = " . $USER['id'] . ";");
         $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET spy_sonde = spy_sonde + 5 WHERE id = 1;");
         // SEND PROBES FUNCTION HERE
         $rawfleetarray = array(210 => 5);
         $fleetRessource = array(901 => 0, 902 => 0, 903 => 0);
         if (1 == $PLANET['system']) {
             $tickfinal = $tickinicial + 9;
         } else {
             $tickfinal = $tickinicial + 11;
         }
         FleetFunctions::sendFleet($rawfleetarray, '6', 1, 1, 1, 1, 1, 1, $PLANET['id_owner'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $fleetRessource, TIMESTAMP + 40, TIMESTAMP + 40, TIMESTAMP + 80, $tickinicial, $tickfinal, 0);
         $manual_step_2_3 = 0;
     }
     $manual_step_5 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 5) {
         $manual_step_5 = 0;
     }
     $manual_step_9 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 9) {
         $manual_step_9 = 0;
     }
     $manual_step_16 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 16) {
         $manual_step_16 = 0;
     }
     if ($USER['training'] == 0 && $USER['training_step'] == 5 && $PLANET['laboratory'] >= 3) {
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `training_step` = '6' WHERE `id` = " . $USER['id'] . ";");
     }
     $this->tplObj->assign_vars(array('manual_step_16' => $manual_step_16, 'manual_step_9' => $manual_step_9, 'manual_step_2' => $manual_step_2, 'manual_step_2_1' => $manual_step_2_1, 'manual_step_2_2' => $manual_step_2_2, 'manual_step_2_3' => $manual_step_2_3, 'manual_step_5' => $manual_step_5, 'BuildInfoList' => $BuildInfoList, 'CanBuildElement' => $CanBuildElement, 'RoomIsOk' => $RoomIsOk, 'Planetas' => $PLANET, 'Queue' => $Queue, 'isBusy' => array('shipyard' => !empty($PLANET['b_hangar_id']), 'research' => $USER['b_tech_planet'] != 0), 'HaveMissiles' => (bool) $PLANET[$resource[503]] + $PLANET[$resource[502]], 'HaveMissiles' => (bool) $PLANET[$resource[503]] + $PLANET[$resource[502]], 'field_used' => $PLANET['field_current'], 'field_max' => CalculateMaxPlanetFields($PLANET), 'field_left' => CalculateMaxPlanetFields($PLANET) - $PLANET['field_current'], 'field_percent' => $PLANET['field_current'] * 100 / CalculateMaxPlanetFields($PLANET)));
     $this->display('page.buildings.default.tpl');
 }
 public function show()
 {
     global $PLANET, $USER, $LNG, $resource, $reslist, $CONF, $pricelist;
     $TheCommand = HTTP::_GP('cmd', '');
     $Element = HTTP::_GP('tech', 0);
     $ListID = HTTP::_GP('listid', 0);
     $lvlup1 = HTTP::_GP('lvlup1', 0);
     $PLANET[$resource[31] . '_inter'] = ResourceUpdate::getNetworkLevel($USER, $PLANET);
     if (!empty($TheCommand) && $_SERVER['REQUEST_METHOD'] === 'POST' && $USER['urlaubs_modus'] == 0) {
         switch ($TheCommand) {
             case 'cancel':
                 $this->CancelBuildingFromQueue();
                 break;
             case 'remove':
                 $this->RemoveBuildingFromQueue($ListID);
                 break;
             case 'instant':
                 $this->InstantBuildingFromQueue();
                 break;
             case 'insert':
                 $this->AddBuildingToQueue($Element, $lvlup1, true);
                 break;
             case 'destroy':
                 $this->DoAddBuildingToQueue($Element, false);
                 break;
         }
         $this->redirectTo('game.php?page=research');
     }
     $bContinue = $this->CheckLabSettingsInQueue($PLANET);
     $queueData = $this->getQueueData();
     $TechQueue = $queueData['queue'];
     $QueueCount = count($TechQueue);
     $ResearchList = array();
     foreach ($reslist['tech'] as $ID => $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         if (isset($queueData['quickinfo'][$Element])) {
             $levelToBuild = $queueData['quickinfo'][$Element];
         } else {
             $levelToBuild = $USER[$resource[$Element]];
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element, false, $levelToBuild);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = $QueueCount != 0 || BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $ResearchList[$Element] = array('id' => $Element, 'level' => $USER[$resource[$Element]], 'factor' => $pricelist[$Element]['factor'], 'maxLevel' => $pricelist[$Element]['max'], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'levelToBuild' => $levelToBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     $this->tplObj->loadscript('research.js');
     $premium_stage = 0;
     if ($USER['premium_reward_stage'] > 0 && $USER['premium_reward_stage_days'] > TIMESTAMP) {
         $premium_stage = $USER['premium_reward_stage'];
     }
     $manual_step_5 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 5 && $PLANET['laboratory'] < 3) {
         $manual_step_5 = 0;
     }
     $manual_step_5_1 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 5 && $PLANET['laboratory'] >= 3) {
         $manual_step_5_1 = 0;
     }
     $manual_step_6 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 6) {
         $manual_step_6 = 0;
     }
     $manual_step_6_1 = 1;
     $manual_step_7 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 6 && $USER['spy_tech'] >= 3) {
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `training_step` = '8' WHERE `id` = " . $USER['id'] . ";");
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `experience_peace` = `experience_peace` + '650' WHERE `id` = " . $USER['id'] . ";");
         $manual_step_7 = 0;
     }
     $manual_step_9 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 9) {
         $manual_step_9 = 0;
     }
     $manual_step_16 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 16) {
         $manual_step_16 = 0;
     }
     $this->tplObj->assign_vars(array('manual_step_5_1' => $manual_step_5_1, 'manual_step_16' => $manual_step_16, 'manual_step_5' => $manual_step_5, 'manual_step_9' => $manual_step_9, 'manual_step_6' => $manual_step_6, 'dmavaible' => $USER['darkmatter'], 'modinstant' => $CONF['modinstant'], 'mod_research_cost' => $CONF['modinstantresearch'], 'modinstantresen' => $CONF['modinstantresen'], 'manual_step_7' => $manual_step_7, 'ResearchList' => $ResearchList, 'IsLabinBuild' => !$bContinue, 'IsFullQueue' => Config::get('max_elements_tech') == 0 || Config::get('max_elements_tech') + $premium_stage == count($TechQueue), 'Queue' => $TechQueue));
     $this->display('page.research.default.tpl');
 }
 public function show()
 {
     global $USER, $PLANET, $LNG, $resource, $reslist;
     if ($PLANET[$resource[21]] == 0) {
         $this->printMessage($LNG['bd_shipyard_required']);
     }
     $buildTodo = HTTP::_GP('fmenge', array());
     $action = HTTP::_GP('action', '');
     $NotBuilding = true;
     if (!empty($PLANET['b_building_id'])) {
         $CurrentQueue = unserialize($PLANET['b_building_id']);
         foreach ($CurrentQueue as $ElementArray) {
             if ($ElementArray[0] == 21 || $ElementArray[0] == 15) {
                 $NotBuilding = false;
                 break;
             }
         }
     }
     $ElementQueue = unserialize($PLANET['b_hangar_id']);
     if (empty($ElementQueue)) {
         $Count = 0;
     } else {
         $Count = count($ElementQueue);
     }
     if ($USER['urlaubs_modus'] == 0 && $NotBuilding == true) {
         if (!empty($buildTodo)) {
             $maxBuildQueue = Config::get()->max_elements_ships;
             if ($maxBuildQueue != 0 && $Count >= $maxBuildQueue) {
                 $this->printMessage(sprintf($LNG['bd_max_builds'], $maxBuildQueue));
             }
             $this->BuildAuftr($buildTodo);
             $ElementQueue = unserialize($PLANET['b_hangar_id']);
         }
         if ($action == "delete") {
             $this->CancelAuftr();
         }
     }
     $elementInQueue = array();
     $buildList = array();
     $elementList = array();
     if (!empty($ElementQueue)) {
         $Shipyard = array();
         $QueueTime = 0;
         foreach ($ElementQueue as $Element) {
             if (empty($Element)) {
                 continue;
             }
             $elementInQueue[$Element[0]] = true;
             $ElementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element[0]);
             $QueueTime += $ElementTime * $Element[1];
             $Shipyard[] = array($LNG['tech'][$Element[0]], $Element[1], $ElementTime, $Element[0]);
         }
         $buildList = array('Queue' => $Shipyard, 'b_hangar_id_plus' => $PLANET['b_hangar'], 'pretty_time_b_hangar' => pretty_time(max($QueueTime - $PLANET['b_hangar'], 0)));
     }
     $mode = HTTP::_GP('mode', 'fleet');
     if ($mode == 'defense') {
         $elementIDs = array_merge($reslist['defense'], $reslist['missile']);
     } else {
         $elementIDs = $reslist['fleet'];
     }
     $Missiles = array();
     foreach ($reslist['missile'] as $elementID) {
         $Missiles[$elementID] = $PLANET[$resource[$elementID]];
     }
     $MaxMissiles = BuildFunctions::getMaxConstructibleRockets($USER, $PLANET, $Missiles);
     foreach ($elementIDs as $Element) {
         if (!BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element)) {
             continue;
         }
         $costResources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costResources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costResources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costResources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costResources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementList[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costResources' => $costResources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild);
     }
     $this->assign(array('elementList' => $elementList, 'NotBuilding' => $NotBuilding, 'BuildList' => $buildList, 'maxlength' => strlen(Config::get()->max_fleet_per_build), 'mode' => $mode));
     $this->display('page.shipyard.default.tpl');
 }
 public function show()
 {
     global $USER, $UNI, $PLANET, $LNG, $resource, $dpath, $reslist, $pricelist, $requeriments, $CONF;
     if ($CONF['dmenabled'] == 0) {
         $this->printMessage("This add-on is disabled", true, array('game.php?page=overview', 2));
         die;
     }
     $fmenge = isset($_POST['fmenge']) ? $_POST['fmenge'] : array();
     $action = HTTP::_GP('action', '');
     $NotBuilding = true;
     if (!empty($PLANET['b_building_id'])) {
         $CurrentQueue = unserialize($PLANET['b_building_id']);
         foreach ($CurrentQueue as $ElementArray) {
             if ($ElementArray[0] == 21 || $ElementArray[0] == 15) {
                 $NotBuilding = false;
                 break;
             }
         }
     }
     $ElementQueue = unserialize($PLANET['b_hangar_id']);
     if (empty($ElementQueue)) {
         $Count = 0;
     } else {
         $Count = count($ElementQueue);
     }
     if ($USER['urlaubs_modus'] == 0) {
         if (!empty($fmenge) && $NotBuilding == true) {
             if (Config::get('max_elements_ships') != 0 && $Count >= Config::get('max_elements_ships')) {
                 $this->printMessage(sprintf($LNG['bd_max_builds'], Config::get('max_elements_ships')));
                 exit;
             }
             $this->BuildAuftr($fmenge);
         }
         if ($action == "delete") {
             $this->CancelAuftr();
         }
     }
     $elementInQueue = array();
     $ElementQueue = unserialize($PLANET['b_hangar_id']);
     $Buildlist = array();
     if (!empty($ElementQueue)) {
         $Shipyard = array();
         $QueueTime = 0;
         foreach ($ElementQueue as $Element) {
             if (empty($Element)) {
                 continue;
             }
             $elementInQueue[$Element[0]] = true;
             $ElementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element[0]);
             $QueueTime += $ElementTime * $Element[1];
             $Shipyard[] = array($LNG['tech'][$Element[0]], $Element[1], $ElementTime, $Element[0]);
         }
         $this->tplObj->loadscript('bcmath.js');
         $this->tplObj->execscript('ShipyardInit();');
         $Buildlist = array('Queue' => $Shipyard, 'b_hangar_id_plus' => $PLANET['b_hangar'], 'pretty_time_b_hangar' => pretty_time(max($QueueTime - $PLANET['b_hangar'], 0)));
     }
     $mode = HTTP::_GP('mode', 'fleet');
     if ($mode == 'defense' && $CONF['fleetconf'] > TIMESTAMP) {
         $elementALL = array(401, 402, 403, 404, 405, 406, 410, 412, 413, 414, 416, 417, 418, 419, 420, 421, 422);
         $elementIDs = array(411, 502, 503);
         $elementIDd = array(401, 402, 403, 420);
         $elementIDa = array(405, 404, 406, 416, 417, 421);
         $elementIDq = array(418, 412, 410, 413, 419, 414);
     } elseif ($mode == 'defense' && $CONF['fleetconf'] < TIMESTAMP) {
         $elementALL = array(401, 402, 403, 404, 405, 406, 410, 412, 413, 414, 416, 417, 418, 419, 420, 421, 422);
         $elementIDs = array(411, 502, 503);
         $elementIDd = array(401, 402, 403);
         $elementIDa = array(405, 404, 406, 416, 417);
         $elementIDq = array(418, 412, 410, 413, 422, 419, 414, 422);
     } elseif ($mode == 'fleet' && $CONF['fleetconf'] > TIMESTAMP) {
         $elementALL = array(202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230);
         $elementIDs = array(208, 210, 223);
         $elementIDd = array(212, 202, 203, 204, 205, 229);
         $elementIDa = array(209, 206, 207, 217, 215, 213, 211, 219, 224);
         $elementIDq = array(225, 226, 214, 216, 230, 227, 228, 222, 218, 221);
     } elseif ($mode == 'fleet' && $CONF['fleetconf'] < TIMESTAMP) {
         $elementALL = array(202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230);
         $elementIDs = array(208, 210, 223);
         $elementIDd = array(212, 202, 203, 204, 205);
         $elementIDa = array(209, 206, 207, 217, 215, 213, 211, 219);
         $elementIDq = array(225, 226, 214, 216, 230, 227, 228, 222, 218, 221);
     }
     foreach ($elementALL as $Element) {
         $AllPrice = array();
         $GetAllPrice = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAllPrice) > 0) {
             while ($k = $GLOBALS['DATABASE']->fetch_array($GetAllPrice)) {
                 $AllPrice[] = $k;
             }
         }
         $costRessources = $k;
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = 0;
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElementsDM($USER, $PLANET, $Element, $costRessources);
         $elementListall[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AllPrice' => $AllPrice, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDs as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $AllPrice = array();
         $GetAllPrice = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAllPrice) > 0) {
             while ($k = $GLOBALS['DATABASE']->fetch_array($GetAllPrice)) {
                 $AllPrice[] = $k;
             }
         }
         $costRessources = $k;
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = 0;
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElementsDM($USER, $PLANET, $Element, $costRessources);
         $elementList[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AllPrice' => $AllPrice, 'AllTech' => $AllTech, 'AllPrice' => $AllPrice, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDq as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $AllPrice = array();
         $GetAllPrice = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAllPrice) > 0) {
             while ($k = $GLOBALS['DATABASE']->fetch_array($GetAllPrice)) {
                 $AllPrice[] = $k;
             }
         }
         $costRessources = $k;
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = 0;
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElementsDM($USER, $PLANET, $Element, $costRessources);
         $elementListq[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AllTech' => $AllTech, 'AllPrice' => $AllPrice, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDa as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $AllPrice = array();
         $GetAllPrice = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAllPrice) > 0) {
             while ($k = $GLOBALS['DATABASE']->fetch_array($GetAllPrice)) {
                 $AllPrice[] = $k;
             }
         }
         $costRessources = $k;
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = 0;
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElementsDM($USER, $PLANET, $Element, $costRessources);
         $elementLista[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AllTech' => $AllTech, 'AllPrice' => $AllPrice, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDd as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $AllPrice = array();
         $GetAllPrice = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAllPrice) > 0) {
             while ($k = $GLOBALS['DATABASE']->fetch_array($GetAllPrice)) {
                 $AllPrice[] = $k;
             }
         }
         $costRessources = $k;
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = 0;
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElementsDM($USER, $PLANET, $Element, $costRessources);
         $elementListd[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AllTech' => $AllTech, 'AllPrice' => $AllPrice, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     $this->tplObj->loadscript('shipyard.js');
     $this->tplObj->assign_vars(array('elementListall' => $elementListall, 'elementList' => $elementList, 'elementListd' => $elementListd, 'elementLista' => $elementLista, 'elementListq' => $elementListq, 'NotBuilding' => $NotBuilding, 'BuildList' => $Buildlist, 'maxlength' => strlen(Config::get('max_fleet_per_build')), 'mode' => $mode, 'instant_fleet' => pretty_number(40000000 - $USER['instant_fleet'])));
     $this->display('page.dmship.default.tpl');
 }
Example #10
0
 public function show()
 {
     global $USER, $PLANET, $LNG, $resource, $dpath, $reslist, $CONF;
     $fmenge = isset($_POST['fmenge']) ? $_POST['fmenge'] : array();
     $action = HTTP::_GP('action', '');
     $NotBuilding = true;
     if (!empty($PLANET['b_building_id'])) {
         $CurrentQueue = unserialize($PLANET['b_building_id']);
         foreach ($CurrentQueue as $ElementArray) {
             if ($ElementArray[0] == 21 || $ElementArray[0] == 15) {
                 $NotBuilding = false;
                 break;
             }
         }
     }
     $ElementQueue = unserialize($PLANET['b_hangar_id']);
     if (empty($ElementQueue)) {
         $Count = 0;
     } else {
         $Count = count($ElementQueue);
     }
     if ($USER['urlaubs_modus'] == 0) {
         if (!empty($fmenge) && $NotBuilding == true) {
             if (Config::get('max_elements_ships') != 0 && $Count >= Config::get('max_elements_ships')) {
                 $this->printMessage(sprintf($LNG['bd_max_builds'], Config::get('max_elements_ships')));
                 exit;
             }
             $this->BuildAuftr($fmenge);
         }
         if ($action == "delete") {
             $this->CancelAuftr();
         }
     }
     $elementInQueue = array();
     $ElementQueue = unserialize($PLANET['b_hangar_id']);
     $Buildlist = array();
     if (!empty($ElementQueue)) {
         $Shipyard = array();
         $QueueTime = 0;
         foreach ($ElementQueue as $Element) {
             if (empty($Element)) {
                 continue;
             }
             $elementInQueue[$Element[0]] = true;
             $ElementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element[0]);
             $QueueTime += $ElementTime * $Element[1];
             $Shipyard[] = array($LNG['tech'][$Element[0]], $Element[1], $ElementTime, $Element[0]);
         }
         $this->tplObj->loadscript('bcmath.js');
         $this->tplObj->loadscript('shipyard.js');
         $this->tplObj->execscript('ShipyardInit();');
         $Buildlist = array('Queue' => $Shipyard, 'b_hangar_id_plus' => $PLANET['b_hangar'], 'pretty_time_b_hangar' => pretty_time(max($QueueTime - $PLANET['b_hangar'], 0)));
     }
     $mode = HTTP::_GP('mode', 'fleet');
     if ($mode == 'defense') {
         $elementIDs = array(401, 402, 403, 404, 405, 406);
     } elseif ($mode == 'orbit') {
         $elementIDs = array(407, 408);
     } elseif ($mode == 'recy') {
         $elementIDs = array(209, 223, 219);
     } elseif ($mode == 'energy') {
         $elementIDs = array(221, 222);
     } elseif ($mode == 'combat') {
         $elementIDs = array(204, 205, 206, 207, 211, 214, 215, 216);
     } else {
         $elementIDs = array(202, 203, 210, 224);
     }
     $inmode = 0;
     if ($mode == 'recy' || $mode == 'energy' || $mode == 'combat' || $mode == 'fleet') {
         $inmode = 1;
     }
     $Missiles = array();
     foreach ($reslist['missile'] as $elementID) {
         $Missiles[$elementID] = $PLANET[$resource[$elementID]];
     }
     $MaxMissiles = BuildFunctions::getMaxConstructibleRockets($USER, $PLANET, $Missiles);
     foreach ($elementIDs as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementList[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     $this->tplObj->assign_vars(array('inmode' => $inmode, 'elementList' => $elementList, 'NotBuilding' => $NotBuilding, 'BuildList' => $Buildlist, 'maxlength' => strlen(Config::get('max_fleet_per_build')), 'mode' => $mode));
     $this->display('page.shipyard.default.tpl');
 }
Example #11
0
 public function show()
 {
     global $PLANET, $USER, $LNG, $resource, $reslist, $CONF, $pricelist;
     $TheCommand = HTTP::_GP('cmd', '');
     $Element = HTTP::_GP('tech', 0);
     $ListID = HTTP::_GP('listid', 0);
     $mode = HTTP::_GP('cmdd', 'physik');
     $PLANET[$resource[31] . '_inter'] = ResourceUpdate::getNetworkLevel($USER, $PLANET);
     if (!empty($TheCommand) && $_SERVER['REQUEST_METHOD'] === 'POST' && $USER['urlaubs_modus'] == 0) {
         switch ($TheCommand) {
             case 'cancel':
                 $this->CancelBuildingFromQueue();
                 break;
             case 'remove':
                 $this->RemoveBuildingFromQueue($ListID);
                 break;
             case 'insert':
                 $this->AddBuildingToQueue($Element, true);
                 break;
             case 'destroy':
                 $this->AddBuildingToQueue($Element, false);
                 break;
         }
         $this->redirectTo('game.php?page=research&cmdd=' . $mode . '');
     }
     $bContinue = $this->CheckLabSettingsInQueue($PLANET);
     $queueData = $this->getQueueData();
     $TechQueue = $queueData['queue'];
     $QueueCount = count($TechQueue);
     $ResearchList = array();
     if ($mode == 'space') {
         $elementIDs = array(109, 110, 111, 115, 117, 118);
     } elseif ($mode == 'militar') {
         $elementIDs = array(145, 106, 146, 147, 148, 149);
     } else {
         $elementIDs = array(113, 140, 141, 142, 143, 144);
     }
     foreach ($elementIDs as $ID => $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         if (isset($queueData['quickinfo'][$Element])) {
             $levelToBuild = $queueData['quickinfo'][$Element];
         } else {
             $levelToBuild = $USER[$resource[$Element]];
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element, false, $levelToBuild);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = $QueueCount != 0 || BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $ResearchList[$Element] = array('id' => $Element, 'level' => $USER[$resource[$Element]], 'maxLevel' => $pricelist[$Element]['max'], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'levelToBuild' => $levelToBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     if ($USER['b_tech_id'] != 0) {
         $this->tplObj->loadscript('research.js');
     }
     $max_build = Config::get('max_elements_tech');
     if ($USER['mode_chaine'] > TIMESTAMP) {
         $max_build += 2;
     }
     if ($mode == 'space') {
         $Tab = 'Space research';
     } elseif ($mode == 'militar') {
         $Tab = 'Military research';
     } else {
         $Tab = 'Theoretical Physics';
     }
     $this->tplObj->assign_vars(array('Tab' => $Tab, 'ResearchList' => $ResearchList, 'IsLabinBuild' => !$bContinue, 'IsFullQueue' => $max_build == 0 || $max_build == count($TechQueue), 'Queue' => $TechQueue, 'mode' => $mode));
     $this->display('page.research.default.tpl');
 }
 public function show()
 {
     global $ProdGrid, $LNG, $resource, $reslist, $CONF, $PLANET, $USER, $pricelist;
     $TheCommand = HTTP::_GP('cmd', '');
     $mode = HTTP::_GP('cmdd', 'build');
     // wellformed buildURLs
     if (!empty($TheCommand) && $_SERVER['REQUEST_METHOD'] === 'POST' && $USER['urlaubs_modus'] == 0) {
         $Element = HTTP::_GP('building', 0);
         $ListID = HTTP::_GP('listid', 0);
         switch ($TheCommand) {
             case 'cancel':
                 $this->CancelBuildingFromQueue();
                 break;
             case 'remove':
                 $this->RemoveBuildingFromQueue($ListID);
                 break;
             case 'insert':
                 $this->AddBuildingToQueue($Element, true);
                 break;
             case 'destroy':
                 $this->AddBuildingToQueue($Element, false);
                 break;
         }
         $this->redirectTo('game.php?page=buildings&cmdd=' . $mode . '');
     }
     $queueData = $this->getQueueData();
     $Queue = $queueData['queue'];
     $QueueCount = count($Queue);
     $max_build = Config::get('max_elements_build');
     if ($USER['mode_chaine'] > TIMESTAMP) {
         $max_build += 2;
     }
     $CanBuildElement = isVacationMode($USER) || $max_build == 0 || $QueueCount < $max_build;
     $CurrentMaxFields = CalculateMaxPlanetFields($PLANET);
     $RoomIsOk = $PLANET['field_current'] < $CurrentMaxFields - $QueueCount;
     $BuildEnergy = $USER[$resource[113]];
     $BuildLevelFactor = 10;
     $BuildTemp = $PLANET['temp_max'];
     $BuildInfoList = array();
     if ($mode == 'hangars') {
         $Elements = array(22, 23, 24, 25);
     } elseif ($mode == 'militar') {
         $Elements = array(45, 21, 46, 14, 31, 5, 33, 47);
     } else {
         $Elements = array(4, 10, 1, 2, 3, 48, 7, 8, 9, 11);
     }
     foreach ($Elements as $ID => $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $infoEnergy = "";
         if (isset($queueData['quickinfo'][$Element])) {
             $levelToBuild = $queueData['quickinfo'][$Element];
         } else {
             $levelToBuild = $PLANET[$resource[$Element]];
         }
         if (in_array($Element, $reslist['prod'])) {
             $BuildLevel = $PLANET[$resource[$Element]];
             $Need = round(eval(ResourceUpdate::getProd($ProdGrid[$Element]['production'][911])));
             $BuildLevel = $levelToBuild + 1;
             $Prod = round(eval(ResourceUpdate::getProd($ProdGrid[$Element]['production'][911])));
             $requireEnergy = $Prod - $Need;
             if ($requireEnergy < 0) {
                 $infoEnergy = sprintf($LNG['bd_need_engine'], pretty_number(abs($requireEnergy)), $LNG['tech'][911]);
             } else {
                 $infoEnergy = sprintf($LNG['bd_more_engine'], pretty_number(abs($requireEnergy)), $LNG['tech'][911]);
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element, false, $levelToBuild);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $destroyRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element, true);
         $destroyTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $destroyRessources);
         $destroyOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $destroyRessources);
         $buyable = $QueueCount != 0 || BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $BuildInfoList[$Element] = array('level' => $PLANET[$resource[$Element]], 'maxLevel' => $pricelist[$Element]['max'], 'infoEnergy' => $infoEnergy, 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'destroyRessources' => $destroyRessources, 'destroyTime' => $destroyTime, 'destroyOverflow' => $destroyOverflow, 'buyable' => $buyable, 'levelToBuild' => $levelToBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     if ($QueueCount != 0) {
         $this->tplObj->loadscript('buildlist.js');
     }
     $Tab = 'Energy & resources';
     if ($mode == 'build') {
         $Tab = 'Energy & resources';
     } elseif ($mode == 'hangars') {
         $Tab = 'Storages';
     } elseif ($mode == 'militar') {
         $Tab = 'Military & science';
     }
     $this->tplObj->assign_vars(array('Tab' => $Tab, 'BuildInfoList' => $BuildInfoList, 'CanBuildElement' => $CanBuildElement, 'RoomIsOk' => $RoomIsOk, 'Queue' => $Queue, 'isBusy' => array('shipyard' => !empty($PLANET['b_hangar_id']), 'research' => $USER['b_tech_planet'] != 0), 'HaveMissiles' => (bool) $PLANET[$resource[503]] + $PLANET[$resource[502]], 'mode' => $mode));
     $this->display('page.buildings.default.tpl');
 }