public function build_page() { $parse = $this->_lang; if (isset($_POST['fmenge'])) { $AddedInQueue = FALSE; $totalCount = 0; foreach ($_POST['fmenge'] as $Element => $Count) { if ($Element < 200 or $Element > 300) { continue; } $Element = (int) $Element; $Count = (int) $Count; $totalCount += $Count; if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) { $Count = MAX_FLEET_OR_DEFS_PER_ROW; } if ($Count != 0) { if (DevelopmentsLib::is_development_allowed($this->_current_user, $this->_current_planet, $Element)) { $MaxElements = $this->GetMaxConstructibleElements($Element, $this->_current_planet); if ($Count > $MaxElements) { $Count = $MaxElements; } $Ressource = $this->GetElementRessources($Element, $Count); if ($Count >= 1) { $this->_current_planet['planet_metal'] -= $Ressource['metal']; $this->_current_planet['planet_crystal'] -= $Ressource['crystal']; $this->_current_planet['planet_deuterium'] -= $Ressource['deuterium']; $this->_current_planet['planet_b_hangar_id'] .= '' . $Element . ',' . $Count . ';'; } } } } if ($totalCount > 0) { parent::$db->query("UPDATE " . PLANETS . " AS p SET\n p.`planet_b_hangar_id` = '" . $this->_current_planet['planet_b_hangar_id'] . "',\n p.`planet_metal` = '" . $this->_current_planet['planet_metal'] . "',\n p.`planet_crystal` = '" . $this->_current_planet['planet_crystal'] . "',\n p.`planet_deuterium` = '" . $this->_current_planet['planet_deuterium'] . "'\n WHERE p.`planet_id` = '" . $this->_current_planet['planet_id'] . "';"); } FunctionsLib::redirect('game.php?page=shipyard'); } if ($this->_current_planet[$this->_resource[21]] == 0) { FunctionsLib::message($this->_lang['bd_shipyard_required'], '', '', TRUE); } $NotBuilding = TRUE; if ($this->_current_planet['planet_b_building_id'] != 0) { $CurrentQueue = $this->_current_planet['planet_b_building_id']; if (strpos($CurrentQueue, ";")) { // FIX BY LUCKY - IF THE SHIPYARD IS IN QUEUE THE USER CANT RESEARCH ANYTHING... $QueueArray = explode(";", $CurrentQueue); for ($i = 0; $i < MAX_BUILDING_QUEUE_SIZE; $i++) { $ListIDArray = explode(",", $QueueArray[$i]); $Element = $ListIDArray[0]; if ($Element == 21 or $Element == 14 or $Element == 15) { break; } } // END - FIX } else { $CurrentBuilding = $CurrentQueue; } if ($CurrentBuilding == 21 or $CurrentBuilding == 14 or $CurrentBuilding == 15 or ($Element == 21 or $Element == 14 or $Element == 15)) { $parse['message'] = "<font color=\"red\">" . $this->_lang['bd_building_shipyard'] . "</font>"; $NotBuilding = FALSE; } } $TabIndex = 0; $PageTable = ''; $BuildQueue = ''; foreach ($this->_lang['tech'] as $Element => $ElementName) { if ($Element > 201 && $Element <= 399) { if (DevelopmentsLib::is_development_allowed($this->_current_user, $this->_current_planet, $Element)) { $CanBuildOne = DevelopmentsLib::is_development_payable($this->_current_user, $this->_current_planet, $Element, FALSE); $BuildOneElementTime = DevelopmentsLib::development_time($this->_current_user, $this->_current_planet, $Element); $ElementCount = $this->_current_planet[$this->_resource[$Element]]; $ElementNbre = $ElementCount == 0 ? "" : " (" . $this->_lang['bd_available'] . FormatLib::pretty_number($ElementCount) . ")"; $parse['dpath'] = DPATH; $parse['add_element'] = ''; $parse['element'] = $Element; $parse['element_name'] = $ElementName; $parse['element_description'] = $this->_lang['res']['descriptions'][$Element]; $parse['element_price'] = DevelopmentsLib::formated_development_price($this->_current_user, $this->_current_planet, $Element, FALSE); $parse['building_time'] = DevelopmentsLib::formated_development_time($BuildOneElementTime); $parse['element_nbre'] = $ElementNbre; if ($CanBuildOne && $NotBuilding && !parent::$users->is_on_vacations($this->_current_user)) { $TabIndex++; $parse['add_element'] = '<input type=text name=fmenge[' . $Element . '] alt="' . $this->_lang['tech'][$Element] . '" size=6 maxlength=6 value=0 tabindex=' . $TabIndex . '>'; } if ($NotBuilding) { $parse['build_fleet'] = '<tr><td class="c" colspan="2" align="center"><input type="submit" value="' . $this->_lang['bd_build_ships'] . '"></td></tr>'; } $PageTable .= parent::$page->parse_template(parent::$page->get_template('buildings/buildings_fleet_row'), $parse); } } } if ($this->_current_planet['planet_b_hangar_id'] != '') { $BuildQueue .= $this->ElementBuildListBox('shipyard'); } $parse['buildlist'] = $PageTable; $parse['buildinglist'] = $BuildQueue; parent::$page->display(parent::$page->parse_template(parent::$page->get_template('buildings/buildings_fleet'), $parse)); }
/** * method add_to_queue * param $building * param $AddMode * return (int) the queue ID */ private function add_to_queue($building, $AddMode = TRUE) { $resource = $this->_objects->getObjects(); $CurrentQueue = $this->_current_planet['planet_b_building_id']; $queue = $this->show_queue(); $max_fields = DevelopmentsLib::max_fields($this->_current_planet); if ($this->_current_planet['planet_field_current'] >= $max_fields - $queue['lenght']) { FunctionsLib::redirect('game.php?page=' . $this->_current_page); } if ($CurrentQueue != 0) { $QueueArray = explode(";", $CurrentQueue); $ActualCount = count($QueueArray); } else { $QueueArray = ""; $ActualCount = 0; } if ($AddMode == TRUE) { $BuildMode = 'build'; } else { $BuildMode = 'destroy'; } if ($ActualCount < MAX_BUILDING_QUEUE_SIZE) { $QueueID = $ActualCount + 1; } else { $QueueID = FALSE; } $continue = FALSE; if ($QueueID != FALSE && DevelopmentsLib::is_development_allowed($this->_current_user, $this->_current_planet, $building)) { if ($QueueID <= 1) { if (DevelopmentsLib::is_development_payable($this->_current_user, $this->_current_planet, $building, TRUE, FALSE) && !parent::$users->is_on_vacations($this->_current_user)) { $continue = TRUE; } } else { $continue = TRUE; } if ($continue) { if ($QueueID > 1) { $InArray = 0; for ($QueueElement = 0; $QueueElement < $ActualCount; $QueueElement++) { $QueueSubArray = explode(",", $QueueArray[$QueueElement]); if ($QueueSubArray[0] == $building) { $InArray++; } } } else { $InArray = 0; } if ($InArray != 0) { $ActualLevel = $this->_current_planet[$resource[$building]]; if ($AddMode == TRUE) { $BuildLevel = $ActualLevel + 1 + $InArray; $this->_current_planet[$resource[$building]] += $InArray; $BuildTime = DevelopmentsLib::development_time($this->_current_user, $this->_current_planet, $building); $this->_current_planet[$resource[$building]] -= $InArray; } else { $BuildLevel = $ActualLevel - 1 - $InArray; $this->_current_planet[$resource[$building]] -= $InArray; $BuildTime = DevelopmentsLib::development_time($this->_current_user, $this->_current_planet, $building) / 2; $this->_current_planet[$resource[$building]] += $InArray; } } else { $ActualLevel = $this->_current_planet[$resource[$building]]; if ($AddMode == TRUE) { $BuildLevel = $ActualLevel + 1; $BuildTime = DevelopmentsLib::development_time($this->_current_user, $this->_current_planet, $building); } else { $BuildLevel = $ActualLevel - 1; $BuildTime = DevelopmentsLib::development_time($this->_current_user, $this->_current_planet, $building) / 2; } } if ($QueueID == 1) { $BuildEndTime = time() + $BuildTime; } else { $PrevBuild = explode(",", $QueueArray[$ActualCount - 1]); $BuildEndTime = $PrevBuild[3] + $BuildTime; } $QueueArray[$ActualCount] = $building . "," . $BuildLevel . "," . $BuildTime . "," . $BuildEndTime . "," . $BuildMode; $NewQueue = implode(";", $QueueArray); $this->_current_planet['planet_b_building_id'] = $NewQueue; } } return $QueueID; }
/** * method do_command * param * return void */ private function do_command() { $cmd = isset($_GET['cmd']) ? $_GET['cmd'] : NULL; if (!is_null($cmd)) { $technology = (int) $_GET['tech']; if (in_array($technology, $this->_reslist['tech'])) { if (is_array($this->_is_working['working_on'])) { $working_planet = $this->_is_working['working_on']; } else { $working_planet = $this->_current_planet; } switch ($cmd) { // cancel a research case 'cancel': if ($this->_is_working['working_on']['planet_b_tech_id'] == $technology) { $costs = DevelopmentsLib::development_price($this->_current_user, $working_planet, $technology); $working_planet['planet_metal'] += $costs['metal']; $working_planet['planet_crystal'] += $costs['crystal']; $working_planet['planet_deuterium'] += $costs['deuterium']; $working_planet['planet_b_tech_id'] = 0; $working_planet['planet_b_tech'] = 0; $this->_current_user['research_current_research'] = 0; $update_data = TRUE; $this->_is_working['is_working'] = FALSE; } break; // start a research // start a research case 'search': if (DevelopmentsLib::is_development_allowed($this->_current_user, $working_planet, $technology) && DevelopmentsLib::is_development_payable($this->_current_user, $working_planet, $technology) && !parent::$users->is_on_vacations($this->_current_user)) { $costs = DevelopmentsLib::development_price($this->_current_user, $working_planet, $technology); $working_planet['planet_metal'] -= $costs['metal']; $working_planet['planet_crystal'] -= $costs['crystal']; $working_planet['planet_deuterium'] -= $costs['deuterium']; $working_planet['planet_b_tech_id'] = $technology; $working_planet['planet_b_tech'] = time() + DevelopmentsLib::development_time($this->_current_user, $working_planet, $technology, FALSE, $this->_lab_level); $this->_current_user['research_current_research'] = $working_planet['id']; $update_data = TRUE; $this->_is_working['is_working'] = TRUE; } break; } if ($update_data == TRUE) { parent::$db->query("UPDATE " . PLANETS . " AS p, " . RESEARCH . " AS r SET\n\t\t\t\t\t\t\t\t\t\t\tp.`planet_b_tech_id` = '" . $working_planet['planet_b_tech_id'] . "',\n\t\t\t\t\t\t\t\t\t\t\tp.`planet_b_tech` = '" . $working_planet['planet_b_tech'] . "',\n\t\t\t\t\t\t\t\t\t\t\tp.`planet_metal` = '" . $working_planet['planet_metal'] . "',\n\t\t\t\t\t\t\t\t\t\t\tp.`planet_crystal` = '" . $working_planet['planet_crystal'] . "',\n\t\t\t\t\t\t\t\t\t\t\tp.`planet_deuterium` = '" . $working_planet['planet_deuterium'] . "',\n\t\t\t\t\t\t\t\t\t\t\tr.`research_current_research` = '" . $this->_current_user['research_current_research'] . "'\n\t\t\t\t\t\t\t\t\t\t\tWHERE p.`planet_id` = '" . $working_planet['planet_id'] . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND r.`research_user_id` = '" . $this->_current_user['user_id'] . "';"); } $this->_current_planet = $working_planet; if (is_array($this->_is_working['working_on'])) { $this->_is_working['working_on'] = $working_planet; } else { $this->_current_planet = $working_planet; if ($cmd == 'search') { $this->_is_working['working_on'] = $this->_current_planet; } } } FunctionsLib::redirect('game.php?page=research'); } }