/** * method add_to_queue * param $building * param $AddMode * return (int) the queue ID */ private function add_to_queue($building, $AddMode = TRUE) { $resource = $this->_objects->get_objects(); $CurrentQueue = $this->_current_planet['planet_b_building_id']; $queue = $this->show_queue(); $max_fields = Developments_Lib::max_fields($this->_current_planet); if ($this->_current_planet['planet_field_current'] >= $max_fields - $queue['lenght']) { Functions_Lib::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 && Developments_Lib::is_development_allowed($this->_current_user, $this->_current_planet, $building)) { if ($QueueID <= 1) { if (Developments_Lib::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 = Developments_Lib::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 = Developments_Lib::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 = Developments_Lib::development_time($this->_current_user, $this->_current_planet, $building); } else { $BuildLevel = $ActualLevel - 1; $BuildTime = Developments_Lib::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; }
public function build_page() { $parse = $this->_lang; if (isset($_POST['fmenge'])) { $Missiles[502] = $this->_current_planet[$this->_resource[502]]; $Missiles[503] = $this->_current_planet[$this->_resource[503]]; $SiloSize = $this->_current_planet[$this->_resource[44]]; $MaxMissiles = $SiloSize * 10; $BuildQueue = $this->_current_planet['planet_b_hangar_id']; $BuildArray = explode(";", $BuildQueue); $totalCount = 0; for ($QElement = 0; $QElement < count($BuildArray); $QElement++) { $ElmentArray = explode(",", $BuildArray[$QElement]); if ($ElmentArray[0] == 502) { $Missiles[502] += $ElmentArray[1]; } elseif ($ElmentArray[0] == 503) { $Missiles[503] += $ElmentArray[1]; } } foreach ($_POST['fmenge'] as $Element => $Count) { if ($Element < 300 or $Element > 550) { 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 ($Element == 407 or $Element == 408) { if (!$this->is_shield_in_queue($BuildQueue, $Element)) { $Count = 1; } else { $Count = 0; } } if (Developments_Lib::is_development_allowed($this->_current_user, $this->_current_planet, $Element)) { $MaxElements = $this->GetMaxConstructibleElements($Element, $this->_current_planet); if ($Element == 502 || $Element == 503) { $ActuMissiles = $Missiles[502] + 2 * $Missiles[503]; $MissilesSpace = $MaxMissiles - $ActuMissiles; if ($Element == 502) { if ($Count > $MissilesSpace) { $Count = $MissilesSpace; } } else { if ($Count > floor($MissilesSpace / 2)) { $Count = floor($MissilesSpace / 2); } } if ($Count > $MaxElements) { $Count = $MaxElements; } $Missiles[$Element] += $Count; } else { 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\r\n\t\t\t\t\t\t\t\t\t\tp.`planet_b_hangar_id` = '" . $this->_current_planet['planet_b_hangar_id'] . "',\r\n\t\t\t\t\t\t\t\t\t\tp.`planet_metal` = '" . $this->_current_planet['planet_metal'] . "',\r\n\t\t\t\t\t\t\t\t\t\tp.`planet_crystal` = '" . $this->_current_planet['planet_crystal'] . "',\r\n\t\t\t\t\t\t\t\t\t\tp.`planet_deuterium` = '" . $this->_current_planet['planet_deuterium'] . "'\r\n\t\t\t\t\t\t\t\t\t\tWHERE p.`planet_id` = '" . $this->_current_planet['planet_id'] . "';"); } Functions_Lib::redirect('game.php?page=defense'); } if ($this->_current_planet[$this->_resource[21]] == 0) { Functions_Lib::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 > 400 && $Element <= 599) { if (Developments_Lib::is_development_allowed($this->_current_user, $this->_current_planet, $Element)) { $CanBuildOne = Developments_Lib::is_development_payable($this->_current_user, $this->_current_planet, $Element, FALSE); $BuildOneElementTime = Developments_Lib::development_time($this->_current_user, $this->_current_planet, $Element); $ElementCount = $this->_current_planet[$this->_resource[$Element]]; $ElementNbre = $ElementCount == 0 ? "" : " (" . $this->_lang['bd_available'] . Format_Lib::pretty_number($ElementCount) . ")"; $parse['add_element'] = ''; $parse['dpath'] = DPATH; $parse['element'] = $Element; $parse['element_name'] = $ElementName; $parse['element_description'] = $this->_lang['res']['descriptions'][$Element]; $parse['element_price'] = Developments_Lib::formated_development_price($this->_current_user, $this->_current_planet, $Element, FALSE); $parse['building_time'] = Developments_Lib::formated_development_time($BuildOneElementTime); $parse['element_nbre'] = $ElementNbre; if ($CanBuildOne && !parent::$users->is_on_vacations($this->_current_user)) { $InQueue = strpos($this->_current_planet['planet_b_hangar_id'], $Element . ","); $IsBuildp = $this->_current_planet[$this->_resource[407]] >= 1 ? TRUE : FALSE; $IsBuildg = $this->_current_planet[$this->_resource[408]] >= 1 ? TRUE : FALSE; $BuildIt = TRUE; if ($Element == 407 || $Element == 408) { $BuildIt = FALSE; if ($Element == 407 && !$IsBuildp && $InQueue === FALSE) { $BuildIt = TRUE; } if ($Element == 408 && !$IsBuildg && $InQueue === FALSE) { $BuildIt = TRUE; } } if (!$BuildIt) { $parse['add_element'] = '<font color="red">' . $this->_lang['bd_protection_shield_only_one'] . '</font>'; } elseif ($NotBuilding) { $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_defenses'] = '<tr><td class="c" colspan="2" align="center"><input type="submit" value="' . $this->_lang['bd_build_defenses'] . '"></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('defenses'); } $parse['buildlist'] = $PageTable; $parse['buildinglist'] = $BuildQueue; parent::$page->display(parent::$page->parse_template(parent::$page->get_template('buildings/buildings_defense'), $parse)); }
/** * 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 = Developments_Lib::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 (Developments_Lib::is_development_allowed($this->_current_user, $working_planet, $technology) && Developments_Lib::is_development_payable($this->_current_user, $working_planet, $technology) && !parent::$users->is_on_vacations($this->_current_user)) { $costs = Developments_Lib::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() + Developments_Lib::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\r\n\t\t\t\t\t\t\t\t\t\t\tp.`planet_b_tech_id` = '" . $working_planet['planet_b_tech_id'] . "',\r\n\t\t\t\t\t\t\t\t\t\t\tp.`planet_b_tech` = '" . $working_planet['planet_b_tech'] . "',\r\n\t\t\t\t\t\t\t\t\t\t\tp.`planet_metal` = '" . $working_planet['planet_metal'] . "',\r\n\t\t\t\t\t\t\t\t\t\t\tp.`planet_crystal` = '" . $working_planet['planet_crystal'] . "',\r\n\t\t\t\t\t\t\t\t\t\t\tp.`planet_deuterium` = '" . $working_planet['planet_deuterium'] . "',\r\n\t\t\t\t\t\t\t\t\t\t\tr.`research_current_research` = '" . $this->_current_user['research_current_research'] . "'\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE p.`planet_id` = '" . $working_planet['planet_id'] . "'\r\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; } } } Functions_Lib::redirect('game.php?page=research'); } }