function eco_bld_tech($que_type, &$user, &$planet) { global $config, $lang; lng_include('buildings'); lng_include('infos'); if (!mrc_get_level($user, $planet, STRUC_LABORATORY)) { message($lang['no_laboratory'], $lang['tech'][UNIT_TECHNOLOGIES]); } if (eco_unit_busy($user, $planet, UNIT_TECHNOLOGIES)) { message($lang['eco_bld_msg_err_laboratory_upgrading'], $lang['tech'][UNIT_TECHNOLOGIES]); } switch ($action = sys_get_param_escaped('action')) { case 'build': $operation_result = que_build($user, $planet); break; case 'trim': que_delete(QUE_RESEARCH, $user, $planet, false); break; case 'clear': que_delete(QUE_RESEARCH, $user, $planet, true); break; //case 'build':$operation_result = eco_bld_tech_research($user, $planet);break; } $template = gettemplate('buildings_research', true); if (!empty($operation_result)) { $template->assign_block_vars('result', $operation_result); } $fleet_list = flt_get_fleets_to_planet($planet); $ques = que_get($user['id'], QUE_RESEARCH); $que =& $ques['ques'][QUE_RESEARCH][$user['id']][0]; que_tpl_parse($template, QUE_RESEARCH, $user, null, $que); $in_que =& $ques['in_que'][QUE_RESEARCH][$user['id']][0]; foreach (sn_get_groups('tech') as $unit_id) { if (eco_can_build_unit($user, $planet, $unit_id) != BUILD_ALLOWED) { continue; } $level_base = mrc_get_level($user, '', $unit_id, false, true); $level_effective = mrc_get_level($user, '', $unit_id); $level_in_que = $in_que[$unit_id]; $level_bonus = max(0, $level_effective - $level_base); $level_base_and_que = $level_base + $level_in_que; $build_data = eco_get_build_data($user, $planet, $unit_id, $level_base_and_que); $temp[RES_METAL] = floor($planet['metal'] - $build_data[BUILD_CREATE][RES_METAL]); $temp[RES_CRYSTAL] = floor($planet['crystal'] - $build_data[BUILD_CREATE][RES_CRYSTAL]); $temp[RES_DEUTERIUM] = floor($planet['deuterium'] - $build_data[BUILD_CREATE][RES_DEUTERIUM]); $template->assign_block_vars('production', array('ID' => $unit_id, 'NAME' => $lang['tech'][$unit_id], 'DESCRIPTION' => $lang['info'][$unit_id]['description_short'], 'LEVEL_OLD' => $level_base, 'LEVEL_BONUS' => $level_bonus, 'LEVEL_NEXT' => $level_base + $level_in_que + 1, 'LEVEL_QUED' => $level_in_que, 'LEVEL' => $level_base_and_que, 'BUILD_CAN' => $build_data['CAN'][BUILD_CREATE], 'TIME' => pretty_time($build_data[RES_TIME][BUILD_CREATE]), 'METAL' => $build_data[BUILD_CREATE][RES_METAL], 'CRYSTAL' => $build_data[BUILD_CREATE][RES_CRYSTAL], 'DEUTERIUM' => $build_data[BUILD_CREATE][RES_DEUTERIUM], 'METAL_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_METAL], true, $planet['metal']), 'CRYSTAL_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_CRYSTAL], true, $planet['crystal']), 'DEUTERIUM_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_DEUTERIUM], true, $planet['deuterium']), 'METAL_REST' => pretty_number($temp[RES_METAL], true, true), 'CRYSTAL_REST' => pretty_number($temp[RES_CRYSTAL], true, true), 'DEUTERIUM_REST' => pretty_number($temp[RES_DEUTERIUM], true, true), 'METAL_REST_NUM' => $temp[RES_METAL], 'CRYSTAL_REST_NUM' => $temp[RES_CRYSTAL], 'DEUTERIUM_REST_NUM' => $temp[RES_DEUTERIUM], 'METAL_FLEET' => pretty_number($temp[RES_METAL] + $fleet_list['own']['total'][RES_METAL], true, true), 'CRYSTAL_FLEET' => pretty_number($temp[RES_CRYSTAL] + $fleet_list['own']['total'][RES_CRYSTAL], true, true), 'DEUTERIUM_FLEET' => pretty_number($temp[RES_DEUTERIUM] + $fleet_list['own']['total'][RES_DEUTERIUM], true, true), 'BUILD_CAN2' => $build_data['CAN'][BUILD_CREATE])); } // if(count($que['ques'][$que_id][$user['id']][$planet_id]) >= que_get_max_que_length($user, $planet, $que_id, $que_data)) $template->assign_vars(array('QUE_ID' => QUE_RESEARCH, 'FLEET_OWN_COUNT' => $fleet_list['own']['count'], 'ARTIFACT_ID' => ART_HEURISTIC_CHIP, 'ARTIFACT_LEVEL' => mrc_get_level($user, array(), ART_HEURISTIC_CHIP), 'ARTIFACT_NAME' => $lang['tech'][ART_HEURISTIC_CHIP], 'REQUEST_URI' => $_SERVER['REQUEST_URI'], 'PAGE_HEADER' => $page_header = $lang['tech'][UNIT_TECHNOLOGIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : ''), 'CONFIG_RESEARCH_QUE' => $config->server_que_length_research)); display(parsetemplate($template), $page_header); }
$sn_group_ques = sn_get_groups('ques'); foreach (array(QUE_STRUCTURES => $sn_group_ques[QUE_STRUCTURES]) as $que_id => $que_type_data) { $this_que = $que['ques'][$que_id][$user['id']][$planetrow['id']]; $template->assign_block_vars('ques', array('ID' => $que_id, 'NAME' => $lang['sys_ques'][$que_id], 'LENGTH' => empty($this_que) ? 0 : count($this_que))); if (!empty($this_que)) { foreach ($this_que as $que_item) { $template->assign_block_vars('que', que_tpl_parse_element($que_item)); } } } $que_hangar_length = tpl_assign_hangar($template, $planetrow, SUBQUE_FLEET); $template->assign_block_vars('ques', array('ID' => QUE_HANGAR, 'NAME' => $lang['sys_ques'][QUE_HANGAR], 'LENGTH' => $que_hangar_length)); $que_hangar_length = tpl_assign_hangar($template, $planetrow, SUBQUE_DEFENSE); $template->assign_block_vars('ques', array('ID' => SUBQUE_DEFENSE, 'NAME' => $lang['sys_ques'][SUBQUE_DEFENSE], 'LENGTH' => $que_hangar_length)); $overview_planet_rows = $user['opt_int_overview_planet_rows']; $overview_planet_columns = $user['opt_int_overview_planet_columns']; if ($overview_planet_rows <= 0 && $overview_planet_columns <= 0) { $overview_planet_rows = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_rows']; $overview_planet_columns = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_columns']; } if ($overview_planet_rows > 0 && $overview_planet_columns <= 0) { $overview_planet_columns = ceil($planet_count / $overview_planet_rows); } $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true); $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER]; $governor_level = $planetrow['PLANET_GOVERNOR_ID'] ? mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID'], false, true) : 0; $template->assign_vars(array('TIME_NOW' => SN_TIME_NOW, 'USER_ID' => $user['id'], 'user_username' => $user['username'], 'USER_AUTHLEVEL' => $user['authlevel'], 'NEW_MESSAGES' => $user['new_message'], 'NEW_LEVEL_MINER' => $level_miner, 'NEW_LEVEL_RAID' => $level_raid, 'planet_diameter' => pretty_number($planetrow['diameter']), 'planet_field_current' => $planetrow['field_current'], 'planet_field_max' => eco_planet_fields_max($planetrow), 'PLANET_FILL' => floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100), 'PLANET_FILL_BAR' => $planet_fill, 'metal_debris' => pretty_number($planetrow['debris_metal']), 'crystal_debris' => pretty_number($planetrow['debris_crystal']), 'PLANET_RECYCLERS' => $planet_recyclers_orbiting, 'planet_image' => $planetrow['image'], 'planet_temp_min' => $planetrow['temp_min'], 'planet_temp_avg' => round(($planetrow['temp_min'] + $planetrow['temp_max']) / 2), 'planet_temp_max' => $planetrow['temp_max'], 'planet_density' => $planetrow['density'], 'planet_density_index' => $planetrow['density_index'], 'planet_density_text' => $lang['uni_planet_density_types'][$planetrow['density_index']], 'GATE_LEVEL' => mrc_get_level($user, $planetrow, STRUC_MOON_GATE), 'GATE_JUMP_REST_TIME' => uni_get_time_to_jump($planetrow), 'ADMIN_EMAIL' => $config->game_adminEmail, 'PLANET_GOVERNOR_ID' => $planetrow['PLANET_GOVERNOR_ID'], 'PLANET_GOVERNOR_LEVEL' => $governor_level, 'PLANET_GOVERNOR_LEVEL_PLUS' => $governor_level ? mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID']) - $governor_level : 0, 'PLANET_GOVERNOR_NAME' => $lang['tech'][$planetrow['PLANET_GOVERNOR_ID']], 'LIST_ROW_COUNT' => $overview_planet_rows, 'LIST_COLUMN_COUNT' => $overview_planet_columns, 'SECTOR_CAN_BUY' => $sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER), 'SECTOR_COST' => $sector_cost, 'SECTOR_COST_TEXT' => pretty_number($sector_cost))); tpl_set_resource_info($template, $planetrow, $fleets_to_planet, 2); display($template, "{$lang['ov_overview']} - {$lang['sys_planet_type'][$planetrow['planet_type']]} {$planetrow['name']} [{$planetrow['galaxy']}:{$planetrow['system']}:{$planetrow['planet']}]"); break; }
/** * eco_build.php * * @version 1.5 - Using PTE (not everywhere) by Gorlum for http://supernova.ws * @version 1.4 - Complying with PCG by Gorlum for http://supernova.ws * @version 1.3 - Security checked for SQL-injection by Gorlum for http://supernova.ws // 1.0 Mise en module initiale (creation) // 1.1 FIX interception cheat +1 // 1.2 FIX interception cheat destruction a -1 * @version 1.1 * @copyright 2008 by Chlorel for XNova */ function eco_build($que_type, $user, &$planet, $que) { global $sn_data, $lang, $config, $time_now; // start transaction here $template = gettemplate('buildings_builds', true); // Caching values that used more then one time into local variables $config_resource_multiplier = $config->resource_multiplier; $planet_type_structs = $sn_data['groups']['build_allow'][$planet['planet_type']]; // Getting parameters $action = sys_get_param_escaped('action'); $unit_id = sys_get_param_int('unit_id'); $unit_level = sys_get_param_int('unit_level'); $GET_listid = $_GET['listid']; $que_type = $que_type == SUBQUE_FLEET || $que_type == SUBQUE_DEFENSE ? QUE_HANGAR : $que_type; CheckPlanetUsedFields($planet); if ($action) { switch ($action) { case 'create': // Add unit to que for build $que = eco_que_add($user, $planet, $que, QUE_STRUCTURES, $unit_id); break; case 'destroy': // Add unit to que for remove $que = eco_que_add($user, $planet, $que, QUE_STRUCTURES, $unit_id, 1, BUILD_DESTROY); break; case 'trim': // Cancel unit from que $que = eco_que_clear($user, $planet, $que, QUE_STRUCTURES, true); break; case 'clear': // Clear que $que = eco_que_clear($user, $planet, $que, QUE_STRUCTURES); break; } header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}"); } /* // Code for fully working new que system $hangar_busy = count($que['que'][QUE_HANGAR]); $lab_busy = count($que['que'][QUE_RESEARCH]) && !$config->BuildLabWhileRun; */ $que_length = count($que['que'][$que_type]); $can_que_element = $que_length < MAX_BUILDING_QUEUE_SIZE; $fleet_list = flt_get_fleets_to_planet($planet); $caps = ECO_getPlanetCaps($user, &$planet); $planet_fields_max = eco_planet_fields_max($planet); $planet_fields_current = $planet['field_current']; $planet_fields_que = -$que['amounts'][$que_type]; $planet_fields_free = max(0, $planet_fields_max - $planet_fields_current + $planet_fields_que); $planet_fields_queable = $planet_fields_free > 0; $planet_temp_max = $planet['temp_max']; $GLOBALS['user_tech_energy'] = $user['energy_tech']; foreach ($planet_type_structs as $Element) { if (eco_can_build_unit($user, $planet, $Element)) { $element_name = $lang['tech'][$Element]; $element_sn_data =& $sn_data[$Element]; $element_level = $planet[$sn_data[$Element]['name']] + $que['in_que'][$Element]; // show energy on BuildingPage //================================ if ($element_sn_data['production']) { $element_production_energy = $element_sn_data['production'][RES_ENERGY]; $energy_current = floor($element_production_energy($element_level, 10, $planet_temp_max)); $energy_next = floor($element_production_energy($element_level + 1, 10, $planet_temp_max)); if ($Element == STRUC_MINE_SOLAR || $Element == STRUC_MINE_FUSION) { $energy_current = floor(mrc_modify_value($user, $planet, array(MRC_POWERMAN), $energy_current)); $energy_next = floor(mrc_modify_value($user, $planet, array(MRC_POWERMAN), $energy_next)); } $energy_balance = floor($energy_next - $energy_current); } else { $energy_balance = 0; } //================================ $build_data = eco_get_build_data($user, $planet, $Element, $element_level); $temp[RES_METAL] = floor($planet['metal'] + $fleet_list['own']['total'][RES_METAL] - $build_data[BUILD_CREATE][RES_METAL]); $temp[RES_CRYSTAL] = floor($planet['crystal'] + $fleet_list['own']['total'][RES_CRYSTAL] - $build_data[BUILD_CREATE][RES_CRYSTAL]); $temp[RES_DEUTERIUM] = floor($planet['deuterium'] + $fleet_list['own']['total'][RES_DEUTERIUM] - $build_data[BUILD_CREATE][RES_DEUTERIUM]); $template->assign_block_vars('production', array('ID' => $Element, 'NAME' => $element_name, 'DESCRIPTION' => $lang['info'][$Element]['description_short'], 'LEVEL' => $element_level, 'LEVEL_OLD' => $planet[$sn_data[$Element]['name']], 'LEVEL_CHANGE' => $que['in_que'][$Element], 'BUILD_CAN' => $build_data['CAN'][BUILD_CREATE], 'TIME' => pretty_time($build_data[BUILD_CREATE][RES_TIME]), 'METAL' => $build_data[BUILD_CREATE][RES_METAL], 'CRYSTAL' => $build_data[BUILD_CREATE][RES_CRYSTAL], 'DEUTERIUM' => $build_data[BUILD_CREATE][RES_DEUTERIUM], 'DESTROY_CAN' => $build_data['CAN'][BUILD_DESTROY], 'DESTROY_TIME' => pretty_time($build_data[BUILD_DESTROY][RES_TIME]), 'DESTROY_METAL' => $build_data[BUILD_DESTROY][RES_METAL], 'DESTROY_CRYSTAL' => $build_data[BUILD_DESTROY][RES_CRYSTAL], 'DESTROY_DEUTERIUM' => $build_data[BUILD_DESTROY][RES_DEUTERIUM], 'METAL_REST' => pretty_number($temp[RES_METAL], true, true), 'CRYSTAL_REST' => pretty_number($temp[RES_CRYSTAL], true, true), 'DEUTERIUM_REST' => pretty_number($temp[RES_DEUTERIUM], true, true), 'METAL_REST_NUM' => $temp[RES_METAL], 'CRYSTAL_REST_NUM' => $temp[RES_CRYSTAL], 'DEUTERIUM_REST_NUM' => $temp[RES_DEUTERIUM], 'METAL_BALANCE' => $caps['metal_perhour'][$Element], 'CRYSTAL_BALANCE' => $caps['crystal_perhour'][$Element], 'DEUTERIUM_BALANCE' => $caps['deuterium_perhour'][$Element], 'ENERGY_BALANCE' => $energy_balance, 'UNIT_BUSY' => eco_unit_busy($user, $planet, $que, $Element))); } } if (is_array($que['que'][$que_type])) { foreach ($que['que'][$que_type] as $que_element) { $template->assign_block_vars('que', $que_element); } } $template->assign_vars(array('TIME_NOW' => $time_now, 'QUE_ID' => $que_type, 'METAL' => $planet['metal'], 'CRYSTAL' => $planet['crystal'], 'DEUTERIUM' => $planet['deuterium'], 'METAL_INCOMING' => $fleet_list['own']['total'][RES_METAL], 'CRYSTAL_INCOMING' => $fleet_list['own']['total'][RES_CRYSTAL], 'DEUTERIUM_INCOMING' => $fleet_list['own']['total'][RES_DEUTERIUM], 'FIELDS_CURRENT' => $planet_fields_current, 'FIELDS_MAX' => $planet_fields_max, 'FIELDS_FREE' => $planet_fields_free, 'FIELDS_QUE' => $planet_fields_que == 0 ? '' : $planet_fields_que > 0 ? "+{$planet_fields_que}" : $planet_fields_que, 'QUE_HAS_PLACE' => $can_que_element, 'QUE_HAS_FIELDS' => $planet_fields_queable, 'FLEET_OWN' => $fleet_list['own']['count'], 'PAGE_HINT' => $lang['eco_bld_page_hint'])); display(parsetemplate($template), $lang['Builds']); }
function que_process(&$user, $planet = null, $on_time = SN_TIME_NOW) { sn_db_transaction_check(true); $que = array(); // Блокируем пользователя. Собственно, запись о нём нам не нужна - будем использовать старую $user = db_user_by_id($user['id'], true); $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']); if ($planet === null && !$time_left[$user['id']][0]) { // TODO return $que; } // Определяем, какие очереди нам нужны и получаем их $que_type_id = $planet === null ? QUE_RESEARCH : false; $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false $que = que_get($user['id'], $planet, $que_type_id, true); //pdump($que); if (empty($que['items'])) { return $que; } $planet_list = array(); if ($planet !== null) { // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них // TODO - от них не надо ничего, кроме ID и que_processed // $planet_query = db_planet_list_by_user_or_planet($user['id'], $planet); // foreach($planet_query as $planet_row) $planet_row = db_planet_list_by_user_or_planet($user['id'], $planet); $planet_list[$planet_row['id']] = $planet_row; $time_left[$planet_row['id_owner']][$planet_row['id']] = max(0, $on_time - $planet_row['que_processed']); } // pdump($time_left); // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты if (array_sum($time_left[$user['id']]) == 0) { return $que; } // pdump($que); $db_changeset = array(); $unit_changes = array(); foreach ($que['items'] as &$que_item) { $que_player_id =& $que_item['que_player_id']; $que_planet_id = intval($que_item['que_planet_id']); // $que_type = &$que_item['que_type']; $que_time_left =& $que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']]; if (!isset($que_time_left)) { $que_time_left = $time_left[$que_player_id][$que_planet_id]; } if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { continue; } // Дальше мы идем, если только осталось время в очереди И юниты к постройке // Вычисляем, сколько целых юнитов будет построено - от 0 до количества юнитов в очереди $unit_processed = min($que_item['que_unit_amount'] - 1, floor($que_time_left / $que_item['que_unit_time'])); // Вычитаем это время из остатков $que_time_left -= $unit_processed * $que_item['que_unit_time']; // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит if ($que_time_left >= $que_item['que_time_left']) { // Увеличиваем количество отстроенных юнитов $unit_processed++; // Вычитаем из времени очереди потраченное на постройку время $que_time_left -= $que_item['que_time_left']; // Полное время юнита равно времени нового юнита $que_item['que_time_left'] = $que_item['que_unit_time']; // Тут у нас может остатся время очереди - если постройка была не последняя } // Изменяем количество оставшихся юнитов $que_item['que_unit_amount'] -= $unit_processed; // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита if ($que_item['que_unit_amount'] > 0) { $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left; $que_time_left = 0; } if ($que_item['que_unit_amount'] <= 0) { $db_changeset['que'][] = array('action' => SQL_OP_DELETE, P_VERSION => 1, 'where' => array("que_id" => $que_item['que_id'])); } else { $db_changeset['que'][] = array('action' => SQL_OP_UPDATE, P_VERSION => 1, 'where' => array("que_id" => $que_item['que_id']), 'fields' => array('que_unit_amount' => array('delta' => -$unit_processed), 'que_time_left' => array('set' => $que_item['que_time_left']))); } if ($unit_processed) { $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1); $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta; } } foreach ($time_left as $player_id => $planet_data) { foreach ($planet_data as $planet_id => $time_on_planet) { $table = $planet_id ? 'planets' : 'users'; $id = $planet_id ? $planet_id : $player_id; $db_changeset[$table][] = array('action' => SQL_OP_UPDATE, P_VERSION => 1, 'where' => array("id" => $id), 'fields' => array('que_processed' => array('set' => $on_time))); if (is_array($unit_changes[$player_id][$planet_id])) { foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null); } } } } //pdump($db_changeset, '$db_changeset'); $que = que_recalculate($que); //pdump($que, '$que'); // TODO: Re-enable quests for Alliances if (!empty($unit_changes) && !$user['user_as_ally']) { $quest_list = qst_get_quests($user['id']); $quest_triggers = qst_active_triggers($quest_list); $quest_rewards = array(); $xp_incoming = array(); foreach ($unit_changes as $user_id => $planet_changes) { foreach ($planet_changes as $planet_id => $changes) { $planet_this = $planet_id ? classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id) : array(); foreach ($changes as $unit_id => $unit_value) { $que_id = que_get_unit_que($unit_id); $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value; if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1); $build_data = $build_data[BUILD_CREATE]; foreach (sn_get_groups('resources_loot') as $resource_id) { $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена } } if (is_array($quest_triggers)) { // TODO: Check mutiply condition quests $quest_trigger_list = array_keys($quest_triggers, $unit_id); if (is_array($quest_trigger_list)) { foreach ($quest_trigger_list as $quest_id) { if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $unit_level_new) { $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list']; $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE; } } } } } } } // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч qst_reward($user, $quest_rewards, $quest_list); foreach ($xp_incoming as $que_id => $xp) { rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000); } } db_changeset_apply($db_changeset); // TODO Сообщения о постройке // $user = db_user_by_id($user['id'], true); return $que; /* // $local_que['time_left'][QUE_RESEARCH][0] = $time_left[QUE_RESEARCH][0]; //pdump($user_time_left, '$user_time_left'); print('1'); //foreach($local_que as $que_id => &$que_data) //{ // if(!intval($que_id))continue; foreach(sn_get_groups('que') as $que_id => $que_info) { if(!isset($que['ques'][$que_id]))continue; foreach($que_data as $owner_id => &$que_items) { foreach($que_items as &$que_item) { // Вычисляем, сколько целых юнитов будет построено - от 0 до количества юнитов в очереди $unit_processed = min($que_item['que_unit_amount'] - 1, floor($local_que['time_left'][$que_id][$owner_id] / $que_item['que_unit_time'])); // Вычитаем это время из остатков $local_que['time_left'][$que_id][$owner_id] -= $unit_processed * $que_item['que_unit_time']; // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля // Вычитаем остаток времени работы очереди с времени постройки юнита if($que_item['que_time_left'] <= $local_que['time_left'][$que_id][$owner_id]) { // Если время постройки - неположительное, значит мы достроили юнит // Увеличиваем количество отстроенных юнитов $unit_processed++; // Вычитаем из времени очереди потраченное на постройку время $local_que['time_left'][$que_id][$owner_id] -= $que_item['que_time_left']; $que_item['que_time_left'] = $que_item['que_unit_time']; // Тут у нас может остатся время очереди - если постройка была не последняя } // Изменяем количество оставшихся юнитов $que_item['que_unit_amount'] -= $unit_processed; if($que_item['que_unit_amount']) { $que_item['que_time_left'] = $que_item['que_time_left'] - $local_que['time_left'][$que_id][$owner_id]; $local_que['time_left'][$que_id][$owner_id] = 0; } if(!$que_item['que_unit_amount']) { $db_changeset['que'][$que_item['que_id']] = array( 'action' => SQL_OP_DELETE, 'where' => array( "`que_id` = {$que_item['que_id']}", ), ); } else { $db_changeset['que'][$que_item['que_id']] = array( 'action' => SQL_OP_UPDATE, 'where' => array( "`que_id` = {$que_item['que_id']}", ), 'fields' => array( 'que_unit_amount' => array( 'delta' => -$unit_processed ), 'que_time_left' => array( 'set' => $que_item['que_time_left'] ), ), ); } if($unit_processed) { $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1); $unit_changes[$owner_id][$que_item['que_unit_id']] += $unit_processed_delta; } // Если на очереди времени не осталось - выходим if(!$local_que['time_left'][$que_id][$owner_id]) { break; } } } } die(); // TODO: Re-enable quests for Alliances if(!empty($unit_changes) && !$user['user_as_ally'] && $user['id_planet']) { $planet = db_planet_by_id($user['id_planet'], true); $quest_list = qst_get_quests($user['id']); $quest_triggers = qst_active_triggers($quest_list); } else { $planet = array(); } $quest_rewards = array(); $xp_incoming = 0; foreach($unit_changes as $owner_id => $changes) { // $user_id_sql = $owner_id ? $owner_id : $user['id']; $planet_id_sql = $owner_id ? $owner_id : null; foreach($changes as $unit_id => $unit_value) { $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_value, $user, $planet_id_sql); // TODO: Изменить согласно типу очереди $unit_level_new = mrc_get_level($user, array(), $unit_id, false, true) + $unit_value; $build_data = eco_get_build_data($user, array(), $unit_id, $unit_level_new - 1); $build_data = $build_data[BUILD_CREATE]; foreach(sn_get_groups('resources_loot') as $resource_id) { $xp_incoming += $build_data[$resource_id]; } if($planet['id']) { // TODO: Check mutiply condition quests $quest_trigger_list = array_keys($quest_triggers, $unit_id); foreach($quest_trigger_list as $quest_id) { if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $unit_level_new) { $quest_rewards[$quest_id] = $quest_list[$quest_id]['quest_rewards']; $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE; } } } } } // TODO: Изменить согласно типу очереди rpg_level_up($user, RPG_TECH, $xp_incoming / 1000); // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч qst_reward($user, $planet, $quest_rewards, $quest_list); db_changeset_apply($db_changeset); // Сообщения о постройке $user = db_user_by_id($user['id'], true); // TODO Так же пересчитывать планеты // sn_db_transaction_commit(); // TODO поменять que_processed у планеты и юзера return $local_que; */ }
function tpl_assign_hangar($que_type, $planet, &$template) { global $user, $lang; $que_length = 0; $hangar_que_strings = explode(';', $planet['b_hangar_id']); foreach ($hangar_que_strings as $hangar_que_string_id => $hangar_que_string) { if (!$hangar_que_string) { continue; } list($unit_id, $unit_amount) = explode(',', $hangar_que_string); $unit_data = eco_get_build_data($user, $planet, $unit_id, 0); $template->assign_block_vars('que', array('ID' => $unit_id, 'QUE' => $que_type, 'NAME' => $lang['tech'][$unit_id], 'TIME' => $unit_data[BUILD_CREATE][RES_TIME] - ($hangar_que_string_id ? 0 : $planet['b_hangar']), 'TIME_FULL' => $unit_data[BUILD_CREATE][RES_TIME], 'AMOUNT' => $unit_amount, 'LEVEL' => 0)); $que_length++; } return $que_length; }
function sn_sys_sector_buy($redirect = 'overview.php') { global $lang, $user, $planetrow; if (!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) { return; } sn_db_transaction_start(); $user = db_user_by_id($user['id'], true, '*'); $planetrow = db_planet_by_id($planetrow['id'], true, '*'); // Тут не надо делать обсчет - ресурсы мы уже посчитали, очередь (и количество зданий) - тоже // $planetrow = sys_o_get_updated($user, $planetrow, SN_TIME_NOW); // $user = $planetrow['user']; // $planetrow = $planetrow['planet']; $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true); $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER]; if ($sector_cost <= $user[get_unit_param(RES_DARK_MATTER, P_NAME)]) { $planet_name_text = uni_render_planet($planetrow); if (rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf($lang['sys_sector_purchase_log'], $user['username'], $user['id'], $planet_name_text, $lang['sys_planet_type'][$planetrow['planet_type']], $planetrow['id'], $sector_cost))) { $sector_db_name = pname_resource_name(UNIT_SECTOR); db_planet_set_by_id($planetrow['id'], "{$sector_db_name} = {$sector_db_name} + 1"); } else { sn_db_transaction_rollback(); } } sn_db_transaction_commit(); sys_redirect($redirect); }
function sn_eco_build($que_type, &$auser, &$planet) { global $lang, $config; if ($ally_id = sys_get_param_id('ally_id')) { define('SN_IN_ALLY', true); $ranks = ally_get_ranks($auser['ally']); if ($ranks[$auser['ally_rank_id']]['admin'] || $auser['ally']['ally_owner'] == $auser['id']) { $user =& $auser['ally']['player']; $planet = array('metal' => $user['metal'], 'crystal' => $user['crystal'], 'deuterium' => $user['deuterium']); } } if (!$user) { $user =& $auser; } switch ($action = sys_get_param_escaped('action')) { case 'create': // Add unit to que for build // Add unit to que for build case 'destroy': // Add unit to que for remove $operation_result = que_build($user, $planet, $action == 'destroy' ? BUILD_DESTROY : BUILD_CREATE); break; case 'trim': que_delete($que_type, $user, $planet, false); break; case 'clear': que_delete($que_type, $user, $planet, true); break; } $group_missile = sn_get_groups('missile'); $silo_capacity_free = 0; if ($que_type == QUE_STRUCTURES) { $build_unit_list = sn_get_groups('build_allow'); $build_unit_list = $build_unit_list[$planet['planet_type']]; $artifact_id = ART_NANO_BUILDER; $page_header = $lang['tech'][UNIT_STRUCTURES]; } elseif ($que_type == QUE_RESEARCH) { if (!mrc_get_level($user, $planet, STRUC_LABORATORY)) { message($lang['no_laboratory'], $lang['tech'][UNIT_TECHNOLOGIES]); } if (eco_unit_busy($user, $planet, UNIT_TECHNOLOGIES)) { message($lang['eco_bld_msg_err_laboratory_upgrading'], $lang['tech'][UNIT_TECHNOLOGIES]); } $build_unit_list = sn_get_groups('tech'); $artifact_id = ART_HEURISTIC_CHIP; $page_header = $lang['tech'][UNIT_TECHNOLOGIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : ''); } elseif ($que_type == QUE_MERCENARY) { // if(!mrc_get_level($user, $planet, STRUC_LABORATORY)) { // message($lang['no_laboratory'], $lang['tech'][UNIT_TECHNOLOGIES]); // } // if(eco_unit_busy($user, $planet, UNIT_TECHNOLOGIES)) { // message($lang['eco_bld_msg_err_laboratory_upgrading'], $lang['tech'][UNIT_TECHNOLOGIES]); // } $build_unit_list = sn_get_groups('mercenaries'); $artifact_id = 0; $page_header = $lang['tech'][UNIT_MERCENARIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : ''); } else { if (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) == 0) { message($lang['need_hangar'], $lang['tech'][STRUC_FACTORY_HANGAR]); } $build_unit_list = sn_get_groups($page_mode = $que_type == SUBQUE_FLEET ? 'fleet' : 'defense'); $page_header = $lang[$page_mode]; $artifact_id = 0; $silo_capacity_free = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY); foreach ($group_missile as $unit_id) { $silo_capacity_free -= (mrc_get_level($user, $planet, $unit_id, false, true) + (isset($in_que[$unit_id]) && $in_que[$unit_id] ? $in_que[$unit_id] : 0)) * get_unit_param($unit_id, P_UNIT_SIZE); } $silo_capacity_free = max(0, $silo_capacity_free); } // Caching values that used more then one time into local variables // $config_resource_multiplier = $config->resource_multiplier; $config_resource_multiplier = game_resource_multiplier(); /* // Code for fully working new que system $hangar_busy = count($que['que'][QUE_HANGAR]); $lab_busy = count($que['que'][QUE_RESEARCH]) && !$config->BuildLabWhileRun; */ $template = gettemplate('buildings_builds', true); if (!empty($operation_result)) { $template->assign_block_vars('result', $operation_result); } $planet_id = $que_type == QUE_RESEARCH || $que_type == QUE_MERCENARY ? 0 : $planet['id']; $ques = que_get($user['id'], $planet_id, $que_type); $in_que =& $ques['in_que'][$que_type][$user['id']][$planet_id]; $que =& $ques['ques'][$que_type][$user['id']][$planet_id]; que_tpl_parse($template, $que_type, $user, $planet, $que); $que_length = count($que); $can_que_element = $que_length < que_get_max_que_length($user, $planet, $que_type); $fleet_list = flt_get_fleets_to_planet($planet); $planet_fields_max = eco_planet_fields_max($planet); $planet_fields_current = $planet['field_current']; $planet_fields_que = is_array($in_que) ? -array_sum($in_que) : 0; $planet_fields_free = max(0, $planet_fields_max - $planet_fields_current + $planet_fields_que); $planet_fields_queable = $que_type != QUE_STRUCTURES || $planet_fields_free > 0; //$planet_temp_max = $planet['temp_max']; $sn_modifiers_resource = sn_get_groups('modifiers'); $sn_modifiers_resource = $sn_modifiers_resource[MODIFIER_RESOURCE_PRODUCTION]; $sn_groups_density = sn_get_groups('planet_density'); $density_info = $sn_groups_density[$planet['density_index']][UNIT_RESOURCES]; $user_dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); foreach ($build_unit_list as $unit_id) { $level_base = mrc_get_level($user, $planet, $unit_id, false, true); $level_effective = mrc_get_level($user, $planet, $unit_id); $level_in_que = $in_que[$unit_id]; $level_bonus = max(0, $level_effective - $level_base); $level_base_and_que = $level_base + $level_in_que; $unit_info = get_unit_param($unit_id); // pdump($unit_info, '$unit_info'); $unit_stackable = isset($unit_info[P_STACKABLE]) && $unit_info[P_STACKABLE]; $build_data = eco_get_build_data($user, $planet, $unit_id, $level_base_and_que); // pdump($build_data, '$build_data'); $temp[RES_METAL] = floor($planet['metal'] + $fleet_list['own']['total'][RES_METAL] - $build_data[BUILD_CREATE][RES_METAL]); $temp[RES_CRYSTAL] = floor($planet['crystal'] + $fleet_list['own']['total'][RES_CRYSTAL] - $build_data[BUILD_CREATE][RES_CRYSTAL]); $temp[RES_DEUTERIUM] = floor($planet['deuterium'] + $fleet_list['own']['total'][RES_DEUTERIUM] - $build_data[BUILD_CREATE][RES_DEUTERIUM]); $temp[RES_DARK_MATTER] = floor($user_dark_matter - $build_data[BUILD_CREATE][RES_DARK_MATTER]); $build_data['RESULT'][BUILD_CREATE] = $build_data['RESULT'][BUILD_CREATE] == BUILD_ALLOWED && !$can_que_element ? BUILD_QUE_FULL : $build_data['RESULT'][BUILD_CREATE]; // Restricting $can_build by resources on planet and (where applicable) with max count per unit $can_build = $unit_info[P_MAX_STACK] ? max(0, $unit_info[P_MAX_STACK] - $level_in_que - $level_effective) : $build_data['CAN'][BUILD_CREATE]; // Restricting $can_build by free silo capacity $can_build = ($unit_is_missile = in_array($unit_id, $group_missile)) ? min($can_build, floor($silo_capacity_free / $unit_info[P_UNIT_SIZE])) : $can_build; if (!$can_build) { if (!$build_data['CAN'][BUILD_CREATE]) { $build_data['RESULT'][BUILD_CREATE] = BUILD_NO_RESOURCES; } elseif ($unit_is_missile && $silo_capacity_free < $unit_info[P_UNIT_SIZE]) { $build_data['RESULT'][BUILD_CREATE] = BUILD_SILO_FULL; } elseif ($unit_info[P_MAX_STACK]) { $build_data['RESULT'][BUILD_CREATE] = BUILD_MAX_REACHED; } } $build_result_text = $lang['sys_build_result'][$build_data['RESULT'][BUILD_CREATE]]; $build_result_text = !is_array($build_result_text) ? $build_result_text : (isset($build_result_text[$unit_id]) ? $build_result_text[$unit_id] : $build_result_text[0]); $template->assign_block_vars('production', array('ID' => $unit_id, 'NAME' => $lang['tech'][$unit_id], 'DESCRIPTION' => $lang['info'][$unit_id]['description_short'], 'LEVEL_OLD' => $level_base, 'LEVEL_BONUS' => $level_bonus, 'LEVEL_NEXT' => $level_base + $level_in_que + 1, 'LEVEL_QUED' => $level_in_que, 'LEVEL' => $level_base_and_que, 'CAN_BUILD' => $can_build, 'BUILD_CAN' => $build_data['CAN'][BUILD_CREATE], 'TIME' => pretty_time($build_data[RES_TIME][BUILD_CREATE]), 'TIME_SECONDS' => $build_data[RES_TIME][BUILD_CREATE], 'METAL' => $build_data[BUILD_CREATE][RES_METAL], 'METAL_TEXT' => pretty_number($build_data[BUILD_CREATE][RES_METAL], true, $planet['metal']), 'CRYSTAL' => $build_data[BUILD_CREATE][RES_CRYSTAL], 'CRYSTAL_TEXT' => pretty_number($build_data[BUILD_CREATE][RES_CRYSTAL], true, $planet['crystal']), 'DEUTERIUM' => $build_data[BUILD_CREATE][RES_DEUTERIUM], 'DEUTERIUM_TEXT' => pretty_number($build_data[BUILD_CREATE][RES_DEUTERIUM], true, $planet['deuterium']), 'ENERGY' => $build_data[BUILD_CREATE][RES_ENERGY], 'DARK_MATTER' => $build_data[BUILD_CREATE][RES_DARK_MATTER], 'DARK_MATTER_ONLY' => $build_data[P_OPTIONS][P_ONLY_DARK_MATTER], 'BUILD_RESULT' => $build_data['RESULT'][BUILD_CREATE], 'BUILD_RESULT_TEXT' => $build_result_text, 'DESTROY_RESULT' => $build_data['RESULT'][BUILD_DESTROY], 'DESTROY_CAN' => $build_data['CAN'][BUILD_DESTROY], 'DESTROY_TIME' => pretty_time($build_data[RES_TIME][BUILD_DESTROY]), 'DESTROY_METAL' => $build_data[BUILD_DESTROY][RES_METAL], 'DESTROY_CRYSTAL' => $build_data[BUILD_DESTROY][RES_CRYSTAL], 'DESTROY_DEUTERIUM' => $build_data[BUILD_DESTROY][RES_DEUTERIUM], 'METAL_REST' => pretty_number($temp[RES_METAL], true, true), 'CRYSTAL_REST' => pretty_number($temp[RES_CRYSTAL], true, true), 'DEUTERIUM_REST' => pretty_number($temp[RES_DEUTERIUM], true, true), 'DARK_MATTER_REST' => pretty_number($temp[RES_DARK_MATTER], true, true), 'METAL_REST_NUM' => $temp[RES_METAL], 'CRYSTAL_REST_NUM' => $temp[RES_CRYSTAL], 'DEUTERIUM_REST_NUM' => $temp[RES_DEUTERIUM], 'DARK_MATTER_REST_NUM' => $temp[RES_DARK_MATTER], 'UNIT_BUSY' => eco_unit_busy($user, $planet, $que, $unit_id), 'MAP_IS_RESOURCE' => !empty($unit_info['production']))); if ($unit_stackable) { $level_production_base = array('ACTUAL_SHIELD' => pretty_number(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_SHIELD), $unit_info['shield'])), 'ACTUAL_ARMOR' => pretty_number(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_ARMOR), $unit_info['armor'])), 'ACTUAL_WEAPON' => pretty_number(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_WEAPON), $unit_info['attack']))); if ($unit_info[P_UNIT_TYPE] == UNIT_SHIPS) { $ship_data = get_ship_data($unit_id, $user); $level_production_base += array('ACTUAL_SPEED' => pretty_number($ship_data['speed']), 'ACTUAL_CONSUMPTION' => pretty_number($ship_data['consumption']), 'ACTUAL_CAPACITY' => pretty_number($ship_data['capacity'])); } if ($unit_info['production']) { foreach ($unit_info['production'] as $resource_id => $resource_calc) { if ($resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc(1, 10, $user, $planet) * $config_resource_multiplier * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1)))) { $level_production_base['R' . $resource_id] = $resource_income; } } } $template->assign_block_vars('production.resource', $level_production_base); } elseif ($unit_info['production']) { $level_production_base = array(); $element_level_start = $level_effective + $in_que[$unit_id]; foreach ($unit_info['production'] as $resource_id => $resource_calc) { if ($resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($element_level_start, 10, $user, $planet) * $config_resource_multiplier * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1)))) { $level_production_base[$resource_id] = $resource_income; } } $level_start = $level_base_and_que > 1 ? $level_effective + $level_in_que - 1 : 1; for ($i = 0; $i < 6; $i++) { $level_production = array('LEVEL' => $level_start + $i); foreach ($unit_info['production'] as $resource_id => $resource_calc) { if ($resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($level_start + $i, 10, $user, $planet) * $config_resource_multiplier * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1)))) { $level_production['R' . $resource_id] = $resource_income; $level_production['D' . $resource_id] = $resource_income - $level_production_base[$resource_id]; } } $template->assign_block_vars('production.resource', $level_production); } } elseif ($unit_id == TECH_ASTROTECH) { $element_level_start = $level_effective + $in_que[$unit_id]; /* foreach($unit_info['production'] as $resource_id => $resource_calc) { if($resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($element_level_start, 10, $user, $planet) * $config_resource_multiplier * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1)))) { $level_production_base[$resource_id] = $resource_income; } } */ $level_production_base = array(UNIT_PLAYER_EXPEDITIONS_MAX => get_player_max_expeditons($user, $element_level_start), UNIT_PLAYER_COLONIES_MAX => get_player_max_colonies($user, $element_level_start)); $level_start = $level_base_and_que > 1 ? $level_effective + $level_in_que - 1 : 1; for ($i = 0; $i < 6; $i++) { $level_production = array('LEVEL' => $level_start + $i); $level_production['R' . UNIT_PLAYER_EXPEDITIONS_MAX] = get_player_max_expeditons($user, $level_start + $i); $level_production['D' . UNIT_PLAYER_EXPEDITIONS_MAX] = $level_production['R' . UNIT_PLAYER_EXPEDITIONS_MAX] - $level_production_base[UNIT_PLAYER_EXPEDITIONS_MAX]; $level_production['R' . UNIT_PLAYER_COLONIES_MAX] = get_player_max_colonies($user, $level_start + $i); $level_production['D' . UNIT_PLAYER_COLONIES_MAX] = $level_production['R' . UNIT_PLAYER_COLONIES_MAX] - $level_production_base[UNIT_PLAYER_COLONIES_MAX]; /* foreach($unit_info['production'] as $resource_id => $resource_calc) { if($resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($level_start + $i, 10, $user, $planet) * $config_resource_multiplier * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1)))) { $level_production['R'.$resource_id] = $resource_income; $level_production['D'.$resource_id] = $resource_income - $level_production_base[$resource_id]; } } $template->assign_block_vars('production.resource', $level_production); */ $template->assign_block_vars('production.resource', $level_production); $level_production_base = array(UNIT_PLAYER_EXPEDITIONS_MAX => $level_production['R' . UNIT_PLAYER_EXPEDITIONS_MAX], UNIT_PLAYER_COLONIES_MAX => $level_production['R' . UNIT_PLAYER_COLONIES_MAX]); } } //pdump(unit_requirements_render($user, $planet, $unit_id)); foreach (unit_requirements_render($user, $planet, $unit_id) as $requirement) { $template->assign_block_vars('production.require', $requirement); } } $sector_cost = eco_get_build_data($user, $planet, UNIT_SECTOR, mrc_get_level($user, $planet, UNIT_SECTOR), true); $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER]; $template->assign_vars(array('ALLY_ID' => $user['user_as_ally'], 'QUE_ID' => $que_type, 'SHOW_SECTORS' => $que_type == QUE_STRUCTURES, 'FLEET_OWN_COUNT' => $fleet_list['own']['count'], 'ARTIFACT_ID' => $artifact_id, 'ARTIFACT_LEVEL' => mrc_get_level($user, array(), $artifact_id), 'ARTIFACT_NAME' => $lang['tech'][$artifact_id], 'REQUEST_URI' => urlencode($_SERVER['REQUEST_URI']), 'PAGE_HEADER' => $page_header, 'TIME_NOW' => SN_TIME_NOW, 'PLN_ID' => $planet['id'], 'METAL' => $planet['metal'], 'CRYSTAL' => $planet['crystal'], 'DEUTERIUM' => $planet['deuterium'], 'DARK_MATTER' => $user_dark_matter, 'METAL_INCOMING' => $fleet_list['own']['total'][RES_METAL], 'CRYSTAL_INCOMING' => $fleet_list['own']['total'][RES_CRYSTAL], 'DEUTERIUM_INCOMING' => $fleet_list['own']['total'][RES_DEUTERIUM], 'FIELDS_CURRENT' => $planet_fields_current, 'FIELDS_MAX' => $planet_fields_max, 'FIELDS_FREE' => $planet_fields_free, 'FIELDS_QUE' => $planet_fields_que == 0 ? '' : $planet_fields_que > 0 ? "+{$planet_fields_que}" : $planet_fields_que, 'QUE_HAS_PLACE' => $can_que_element, 'QUE_HAS_FIELDS' => $planet_fields_queable, 'PAGE_HINT' => $lang['eco_bld_page_hint'], 'PLANET_TYPE' => $planet['planet_type'], 'SECTOR_CAN_BUY' => $sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER), 'SECTOR_COST' => $sector_cost, 'SECTOR_COST_TEXT' => pretty_number($sector_cost), 'STACKABLE' => $unit_stackable, 'TEMPORARY' => intval($config->empire_mercenary_temporary && $que_type == QUE_MERCENARY), 'STRING_CREATE' => $que_type == QUE_MERCENARY ? $lang['bld_hire'] : ($que_type == QUE_RESEARCH ? $lang['bld_research'] : $lang['bld_create']), 'STRING_BUILD_TIME' => $que_type == QUE_RESEARCH ? $lang['ResearchTime'] : $lang['ConstructionTime'], 'U_opt_int_struc_vertical' => $user['option_list'][OPT_INTERFACE]['opt_int_struc_vertical'])); display(parsetemplate($template)); // , $lang['Builds'] }
} sn_db_transaction_rollback(); break; case ACTION_USE: art_use($user, $planetrow, $unit_id); header("Location: artifacts.php#{$unit_id}"); ob_end_flush(); die; break; } message($Message, $lang['tech'][UNIT_ARTIFACTS], 'artifacts.' . PHP_EX, 5); } $template = gettemplate('artifacts', true); foreach ($sn_group_artifacts as $artifact_id) { $artifact_level = mrc_get_level($user, array(), $artifact_id, true); $build_data = eco_get_build_data($user, $planetrow, $artifact_id, $artifact_level); $artifact_data = get_unit_param($artifact_id); $artifact_data_bonus = $artifact_data['bonus']; $artifact_data_bonus = $artifact_data_bonus >= 0 ? "+{$artifact_data_bonus}" : "{$artifact_data_bonus}"; switch ($artifact_data['bonus_type']) { case BONUS_PERCENT: $artifact_data_bonus = "{$artifact_data_bonus}% "; break; case BONUS_ADD: break; case BONUS_ABILITY: $artifact_data_bonus = ''; break; default: break; }
function eco_que_trim($user, &$planet, &$que, $que_id, $que_item, &$resource_change) { global $sn_data; $sn_data_groups_resources_loot = $sn_data['groups']['resources_loot']; $unit_id = $que_item['ID']; $build_mode = $que_item['MODE']; $build_data = eco_get_build_data($user, $planet, $unit_id, $que_item['LEVEL'] - $build_mode); $unit_amount = $que_item['AMOUNT']; foreach ($sn_data_groups_resources_loot as $resource_id) { $resource_change[$resource_id] += $build_data[$build_mode][$resource_id] * $unit_amount; } $que['in_que'][$unit_id] -= $build_mode * $unit_amount; $que['in_que_abs'][$unit_id] -= $unit_amount; $que['amounts'][$que_id] -= $build_mode * $unit_amount; }
function eco_bld_hangar($que_type, $user, &$planet) { global $lang; if (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) == 0) { message($lang['need_hangar'], $lang['tech'][STRUC_FACTORY_HANGAR]); } $page_mode = $que_type == SUBQUE_FLEET ? 'fleet' : 'defense'; switch (sys_get_param_str('action')) { case 'clear': que_delete($que_type, $user, $planet, true); break; case 'trim': que_delete($que_type, $user, $planet, false); break; //case 'build':$operation_result = que_build($user, $planet);break; //case 'build':$operation_result = eco_bld_tech_research($user, $planet);break; } $template = gettemplate("buildings_hangar", true); if (sys_unit_arr2str(sys_get_param('fmenge'))) { $operation_result = que_build($user, $planet); } if (!empty($operation_result)) { $template->assign_block_vars('result', $operation_result); } $page_error = ''; $sn_data_group = sn_get_groups($page_mode); $ques = que_get($user['id'], $planet['id'], $que_type); $que =& $ques['ques'][$que_type][$user['id']][$planet['id']]; $in_que =& $ques['in_que'][$que_type][$user['id']][$planet['id']]; $silo_capacity_free = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY); $group_missile = sn_get_groups('missile'); foreach ($group_missile as $unit_id) { $silo_capacity_free -= (mrc_get_level($user, $planet, $unit_id, false, true) + (isset($in_que[$unit_id]) && $in_que[$unit_id] ? $in_que[$unit_id] : 0)) * get_unit_param($unit_id, P_UNIT_SIZE); } $silo_capacity_free = max(0, $silo_capacity_free); $TabIndex = 0; foreach ($sn_data_group as $unit_id) { $unit_info = get_unit_param($unit_id); $build_data = eco_get_build_data($user, $planet, $unit_id); if ($build_data['RESULT'][BUILD_CREATE] == BUILD_REQUIRE_NOT_MEET) { continue; } $unit_message = ''; $ElementCount = mrc_get_level($user, $planet, $unit_id); // Restricting $can_build by resources on planet and (where applicable) with max count per unit $can_build = $unit_info[P_MAX_STACK] ? max(0, $unit_info[P_MAX_STACK] - $in_que[$unit_id] - $ElementCount) : $build_data['CAN'][BUILD_CREATE]; // Restricting $can_build by free silo capacity $can_build = ($unit_is_missile = in_array($unit_id, $group_missile)) ? min($can_build, floor($silo_capacity_free / $unit_info[P_UNIT_SIZE])) : $can_build; if (!$can_build) { if (!$build_data['CAN'][BUILD_CREATE]) { $unit_message = $lang['sys_build_result'][BUILD_NO_RESOURCES]; } elseif ($unit_is_missile && $silo_capacity_free < $unit_info[P_UNIT_SIZE]) { $unit_message = $lang['b_no_silo_space']; } elseif ($unit_info[P_MAX_STACK]) { $unit_message = $lang['only_one']; } } else { $TabIndex++; } $temp[RES_METAL] = floor($planet['metal'] - $build_data[BUILD_CREATE][RES_METAL]); // + $fleet_list['own']['total'][RES_METAL] $temp[RES_CRYSTAL] = floor($planet['crystal'] - $build_data[BUILD_CREATE][RES_CRYSTAL]); // + $fleet_list['own']['total'][RES_CRYSTAL] $temp[RES_DEUTERIUM] = floor($planet['deuterium'] - $build_data[BUILD_CREATE][RES_DEUTERIUM]); // + $fleet_list['own']['total'][RES_DEUTERIUM] $template->assign_block_vars('production', array('ID' => $unit_id, 'NAME' => $lang['tech'][$unit_id], 'DESCRIPTION' => $lang['info'][$unit_id]['description_short'], 'LEVEL' => $ElementCount, 'LEVEL_OLD' => mrc_get_level($user, $planet, $unit_id), 'LEVEL_CHANGE' => $que['in_que'][$unit_id], 'BUILD_CAN' => $can_build, 'TIME' => pretty_time($build_data[RES_TIME][BUILD_CREATE]), 'METAL' => $build_data[BUILD_CREATE][RES_METAL], 'CRYSTAL' => $build_data[BUILD_CREATE][RES_CRYSTAL], 'DEUTERIUM' => $build_data[BUILD_CREATE][RES_DEUTERIUM], 'METAL_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_METAL], true, $planet['metal']), 'CRYSTAL_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_CRYSTAL], true, $planet['crystal']), 'DEUTERIUM_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_DEUTERIUM], true, $planet['deuterium']), 'DESTROY_CAN' => $build_data['CAN'][BUILD_DESTROY], 'DESTROY_TIME' => pretty_time($build_data[RES_TIME][BUILD_DESTROY]), 'DESTROY_METAL' => $build_data[BUILD_DESTROY][RES_METAL], 'DESTROY_CRYSTAL' => $build_data[BUILD_DESTROY][RES_CRYSTAL], 'DESTROY_DEUTERIUM' => $build_data[BUILD_DESTROY][RES_DEUTERIUM], 'METAL_REST' => pretty_number($temp[RES_METAL], true, true), 'CRYSTAL_REST' => pretty_number($temp[RES_CRYSTAL], true, true), 'DEUTERIUM_REST' => pretty_number($temp[RES_DEUTERIUM], true, true), 'METAL_REST_NUM' => $temp[RES_METAL], 'CRYSTAL_REST_NUM' => $temp[RES_CRYSTAL], 'DEUTERIUM_REST_NUM' => $temp[RES_DEUTERIUM], 'ARMOR' => pretty_number($unit_info[P_ARMOR]), 'SHIELD' => pretty_number($unit_info[P_SHIELD]), 'WEAPON' => pretty_number($unit_info[P_ATTACK]), 'TABINDEX' => $TabIndex, 'MESSAGE' => $unit_message)); } //$hangar_busy $template->assign_vars(array('noresearch' => $NoFleetMessage, 'error_msg' => $page_error, 'MODE' => $que_type, 'QUE_ID' => $que_type, 'TIME_NOW' => SN_TIME_NOW, 'HANGAR_BUSY' => eco_hangar_is_building($que), 'QUE_HAS_PLACE' => empty($que) || count($que) < que_get_max_que_length($user, $planet, $que_type))); // tpl_assign_hangar($que_type, $planet, $template); // $ques = que_get($que_type, $user['id'], $planet['id']); que_tpl_parse($template, $que_type, $user, $planet); display(parsetemplate($template), $lang[$page_mode]); }
function ResearchBuildingPage(&$user, &$planet, $que) { global $config, $sn_data, $lang, $time_now; if (!$planet[$sn_data[31]['name']]) { message($lang['no_laboratory'], $lang['tech'][TECH_TECHNOLOGY]); } $build_planet = !$user['b_tech_planet'] || $user['b_tech_planet'] == $planet['id'] ? $planet : doquery("SELECT * FROM {{planets}} WHERE `id` = {$user['b_tech_planet']} LIMIT 1;", '', true); $message = ''; switch (sys_get_param_str('action')) { case 'clear': case 'trim': $tech_id = $build_planet['b_tech_id']; if ($tech_id) { $build_data = eco_get_build_data($user, $build_planet, $tech_id, $user[$sn_data[$tech_id]['name']]); doquery("UPDATE {{planets}} SET `b_tech_id` = '0', `b_tech` = '0', \r\n `metal` = `metal` + {$build_data[BUILD_CREATE][RES_METAL]}, `crystal` = `crystal` + '{$build_data[BUILD_CREATE][RES_CRYSTAL]}', `deuterium` = `deuterium` + '{$build_data[BUILD_CREATE][RES_DEUTERIUM]}' \r\n WHERE `id` = '{$build_planet['id']}' LIMIT 1;"); doquery("UPDATE {{users}} SET `b_tech_planet` = '0' WHERE `id` = '{$user['id']}' LIMIT 1;"); header("Location: {$_SERVER['PHP_SELF']}?mode=" . QUE_RESEARCH); die; } break; case 'build': $tech_id = sys_get_param_int('tech'); if ($build_planet['b_tech_id']) { $message = $lang['build_research_in_progress']; } elseif (!eco_lab_is_building($que) && in_array($tech_id, $sn_data['groups']['tech']) && eco_can_build_unit($user, $planet, $tech_id) && IsElementBuyable($user, $planet, $tech_id)) { $build_data = eco_get_build_data($user, $planet, $tech_id, $user[$sn_data[$tech_id]['name']]); $build_time_end = $build_data[BUILD_CREATE][RES_TIME] + $time_now; doquery("UPDATE {{planets}} SET `b_tech_id` = '{$tech_id}', `b_tech` = '{$build_time_end}', \r\n `metal` = `metal` - {$build_data[BUILD_CREATE][RES_METAL]}, `crystal` = `crystal` - '{$build_data[BUILD_CREATE][RES_CRYSTAL]}', `deuterium` = `deuterium` - '{$build_data[BUILD_CREATE][RES_DEUTERIUM]}' \r\n WHERE `id` = '{$planet['id']}' LIMIT 1;"); doquery("UPDATE {{users}} SET `b_tech_planet` = '{$planet['id']}' WHERE `id` = '{$user['id']}' LIMIT 1;"); header("Location: {$_SERVER['PHP_SELF']}?mode=" . QUE_RESEARCH); die; } break; } $message = $message ? $message : (eco_lab_is_building($que) ? $lang['labo_on_update'] : ''); $template = gettemplate('buildings_research', true); $fleet_list = flt_get_fleets_to_planet($planet); foreach ($sn_data['groups']['tech'] as $Tech) { if (!eco_can_build_unit($user, $planet, $Tech)) { continue; } $building_level = $user[$sn_data[$Tech]['name']]; $build_data = eco_get_build_data($user, $planet, $Tech, $building_level); $temp[RES_METAL] = floor($planet['metal'] - $build_data[BUILD_CREATE][RES_METAL]); // + $fleet_list['own']['total'][RES_METAL] $temp[RES_CRYSTAL] = floor($planet['crystal'] - $build_data[BUILD_CREATE][RES_CRYSTAL]); // + $fleet_list['own']['total'][RES_CRYSTAL] $temp[RES_DEUTERIUM] = floor($planet['deuterium'] - $build_data[BUILD_CREATE][RES_DEUTERIUM]); // + $fleet_list['own']['total'][RES_DEUTERIUM] $template->assign_block_vars('production', array('ID' => $Tech, 'NAME' => $lang['tech'][$Tech], 'LEVEL' => $building_level, 'LEVEL_NEXT' => $building_level + 1, 'DESCRIPTION' => $lang['info'][$Tech]['description_short'], 'BUILD_CAN' => $build_data['CAN'][BUILD_CREATE], 'TIME' => pretty_time($build_data[BUILD_CREATE][RES_TIME]), 'METAL' => $build_data[BUILD_CREATE][RES_METAL], 'CRYSTAL' => $build_data[BUILD_CREATE][RES_CRYSTAL], 'DEUTERIUM' => $build_data[BUILD_CREATE][RES_DEUTERIUM], 'ENERGY' => $build_data[BUILD_CREATE][RES_ENERGY], 'METAL_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_METAL], true, $planet['metal']), 'CRYSTAL_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_CRYSTAL], true, $planet['crystal']), 'DEUTERIUM_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_DEUTERIUM], true, $planet['deuterium']), 'ENERGY_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_ENERGY], true, $planet['energy_max']), 'METAL_REST' => pretty_number($temp[RES_METAL], true, true), 'CRYSTAL_REST' => pretty_number($temp[RES_CRYSTAL], true, true), 'DEUTERIUM_REST' => pretty_number($temp[RES_DEUTERIUM], true, true), 'METAL_REST_NUM' => $temp[RES_METAL], 'CRYSTAL_REST_NUM' => $temp[RES_CRYSTAL], 'DEUTERIUM_REST_NUM' => $temp[RES_DEUTERIUM], 'METAL_FLEET' => pretty_number($temp[RES_METAL] + $fleet_list['own']['total'][RES_METAL], true, true), 'CRYSTAL_FLEET' => pretty_number($temp[RES_CRYSTAL] + $fleet_list['own']['total'][RES_CRYSTAL], true, true), 'DEUTERIUM_FLEET' => pretty_number($temp[RES_DEUTERIUM] + $fleet_list['own']['total'][RES_DEUTERIUM], true, true), 'BUILD_CAN2' => IsElementBuyable($user, $planet, $Tech) && !eco_lab_is_building($que))); } $que_length = 0; if ($build_planet['b_tech_id']) { $unit_id = $build_planet['b_tech_id']; $unit_data = eco_get_build_data($user, $build_planet, $unit_id, $user[$sn_data[$unit_id]['name']]); $template->assign_block_vars('que', array('ID' => $unit_id, 'QUE' => QUE_RESEARCH, 'NAME' => $lang['tech'][$unit_id], 'TIME' => $build_planet['b_tech'] - $time_now, 'TIME_FULL' => $unit_data[BUILD_CREATE][RES_TIME], 'AMOUNT' => 1, 'LEVEL' => $user[$sn_data[$unit_id]['name']] + 1)); $que_length++; } $template->assign_vars(array('PAGE_HEADER' => $lang['tech'][TECH_TECHNOLOGY], 'MESSAGE' => $message, 'FLEET_OWN_COUNT' => $fleet_list['own']['count'], 'QUE_ID' => QUE_RESEARCH, 'RESEARCH_ONGOING' => $build_planet['b_tech_id'], 'RESEARCH_TECH' => $build_planet['b_tech_id'], 'RESEARCH_TIME' => $build_planet['b_tech'] - $time_now, 'RESEARCH_HOME_ID' => $build_planet['id'], 'RESEARCH_HOME_NAME' => $build_planet['id'] != $planet['id'] ? $build_planet['name'] : '')); display(parsetemplate($template), $lang['tech'][TECH_TECHNOLOGY]); }