function tpl_parse_planet($planet, $que) { global $lang, $config, $time_now; $fleet_list = flt_get_fleets_to_planet($planet); $hangar = explode(';', $planet['b_hangar_id']); foreach ($hangar as $hangar_row) { if ($hangar_row) { $hangar_row = explode(',', $hangar_row); $hangar_que['que'][] = array('id' => $hangar_row[0], 'count' => $hangar_row[1]); $hangar_que[$hangar_row[0]] += $hangar_row[1]; } } $hangar_build_tip = $hangar_que['que'][0]['id'] ? $lang[tech][$hangar_que['que'][0]['id']] : ''; $result = array('ID' => $planet['id'], 'NAME' => $planet['name'], 'IMAGE' => $planet['image'], 'GALAXY' => $planet['galaxy'], 'SYSTEM' => $planet['system'], 'PLANET' => $planet['planet'], 'TYPE' => $planet['planet_type'], 'COORDINATES' => uni_render_coordinates($planet), 'METAL_PERCENT' => $planet['metal_mine_porcent'] * 10, 'CRYSTAL_PERCENT' => $planet['crystal_mine_porcent'] * 10, 'DEUTERIUM_PERCENT' => $planet['deuterium_sintetizer_porcent'] * 10, 'TECH' => $planet['b_tech'] ? $lang['tech'][$planet['b_tech_id']] . ' ' . pretty_time($planet['b_tech'] - $time_now) : 0, 'HANGAR' => $hangar_build_tip, 'hangar_que' => $hangar_que, 'FIELDS_CUR' => $planet['field_current'], 'FIELDS_MAX' => eco_planet_fields_max($planet), 'FILL' => min(100, floor($planet['field_current'] / eco_planet_fields_max($planet) * 100)), 'FLEET_OWN' => $fleet_list['own']['count'], 'FLEET_ENEMY' => $fleet_list['enemy']['count'], 'FLEET_NEUTRAL' => $fleet_list['neutral']['count'], 'fleet_list' => $fleet_list); if (!empty($que)) { $que_item = $que['que'][QUE_STRUCTURES][0]; if ($que_item) { $result['BUILDING_ID'] = $que_item['ID']; $result['BUILDING_TIP'] = $que_item['NAME']; $result['BUILDING'] = int_buildCounter($planet, 'building', $planet['id'], $que); } } return $result; }
$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; }
function sn_imperium_view($template = null) { global $user, $lang; $planets = array(); $ques = array(); $sn_group_factories = sn_get_groups('factories'); $planet_density = sn_get_groups('planet_density'); if (sys_get_param('save_production')) { $production = sys_get_param('percent'); if (is_array($production) && !empty($production)) { // sn_db_transaction_start(); $query = array(); $planet_row_list = db_planet_list_sorted($user, false, '*'); // while($planet = db_fetch($planet_row_list)) foreach ($planet_row_list as $planet) { foreach ($sn_group_factories as $factory_unit_id) { $unit_db_name_porcent = pname_factory_production_field_name($factory_unit_id); if (get_unit_param($factory_unit_id, P_MINING_IS_MANAGED) && isset($production[$factory_unit_id][$planet['id']]) && ($actual_porcent = intval($production[$factory_unit_id][$planet['id']] / 10)) >= 0 && $actual_porcent <= 10 && $actual_porcent != $planet[$unit_db_name_porcent]) { $query[$planet['id']][] = "{$unit_db_name_porcent} = {$actual_porcent}"; } } } foreach ($query as $planet_id => $query_data) { db_planet_set_by_id($planet_id, implode(',', $query_data)); } // sn_db_transaction_commit(); } } $planet_row_list = db_planet_list_sorted($user); // while ($planet = db_fetch($planet_row_list)) foreach ($planet_row_list as $planet) { sn_db_transaction_start(); $global_data = sys_o_get_updated($user, $planet['id'], SN_TIME_NOW, false, true); $planets[$planet['id']] = $global_data['planet']; // $ques[$planet['id']] = que_get($user['id'], $planet['id'], false); $ques[$planet['id']] = $global_data['que']; sn_db_transaction_commit(); } $template = gettemplate('imperium', $template); $template->assign_var('amount', count($planets) + 2); for ($i = 100; $i >= 0; $i -= 10) { $template->assign_block_vars('percent', array('PERCENT' => $i)); } $fleet_id = 1; $fleets = array(); $total['temp_min'] = 1000; $total['temp_max'] = -999; foreach ($planets as $planet_index => &$planet) { $list_planet_que = $ques[$planet_index]; $planet_template = tpl_parse_planet($planet); $planet_fleet_id = 0; $fleet_list = $planet_template['fleet_list']; //flt_get_fleets_to_planet($planet); if ($fleet_list['own']['count']) { $planet_fleet_id = "p{$fleet_id}"; $fleets[] = tpl_parse_fleet_sn($fleet_list['own']['total'], $planet_fleet_id); $fleet_id++; } $template->assign_block_vars('planet', array_merge($planet_template, array('PLANET_FLEET_ID' => $planet_fleet_id, 'METAL_CUR' => pretty_number($planet['metal'], true, $planet['caps']['total_storage'][RES_METAL]), 'METAL_PROD' => pretty_number($planet['caps']['total'][RES_METAL]), 'CRYSTAL_CUR' => pretty_number($planet['crystal'], true, $planet['caps']['total_storage'][RES_CRYSTAL]), 'CRYSTAL_PROD' => pretty_number($planet['caps']['total'][RES_CRYSTAL]), 'DEUTERIUM_CUR' => pretty_number($planet['deuterium'], true, $planet['caps']['total_storage'][RES_DEUTERIUM]), 'DEUTERIUM_PROD' => pretty_number($planet['caps']['total'][RES_DEUTERIUM]), 'ENERGY_CUR' => pretty_number($planet['caps'][RES_ENERGY][BUILD_CREATE] - $planet['caps'][RES_ENERGY][BUILD_DESTROY], true, true), 'ENERGY_MAX' => pretty_number($planet['caps'][RES_ENERGY][BUILD_CREATE]), 'TEMP_MIN' => $planet['temp_min'], 'TEMP_MAX' => $planet['temp_max'], 'DENSITY_CLASS' => $planet['density_index'], 'DENSITY_RICHNESS' => $planet_density[$planet['density_index']][UNIT_PLANET_DENSITY_RICHNESS], 'DENSITY_CLASS_TEXT' => $lang['uni_planet_density_types'][$planet['density_index']]))); $planet['fleet_list'] = $planet_template['fleet_list']; $planet['BUILDING_ID'] = $planet_template['BUILDING_ID']; $planet['hangar_que'] = $planet_template['hangar_que']; $planet['full_que'] = $list_planet_que; $total['fields'] += $planet['field_current']; $total['metal'] += $planet['metal']; $total['crystal'] += $planet['crystal']; $total['deuterium'] += $planet['deuterium']; $total['energy'] += $planet['energy_max'] - $planet['energy_used']; $total['fields_max'] += eco_planet_fields_max($planet); $total['metal_perhour'] += $planet['caps']['total'][RES_METAL]; $total['crystal_perhour'] += $planet['caps']['total'][RES_CRYSTAL]; $total['deuterium_perhour'] += $planet['caps']['total'][RES_DEUTERIUM]; $total['energy_max'] += $planet['caps'][RES_ENERGY][BUILD_CREATE]; $total['temp_min'] = min($planet['temp_min'], $total['temp_min']); $total['temp_max'] = max($planet['temp_max'], $total['temp_max']); } tpl_assign_fleet($template, $fleets); unset($planet); $show_groups = array(UNIT_STRUCTURES => 'structures', UNIT_STRUCTURES_SPECIAL => 'structures', UNIT_SHIPS => 'fleet', UNIT_DEFENCE => 'defense'); foreach ($show_groups as $unit_group_id => $mode) { $template->assign_block_vars('prods', array('NAME' => $lang['tech'][$unit_group_id])); $unit_group = get_unit_param('techtree', $unit_group_id); foreach ($unit_group as $unit_id) { $unit_count = $unit_count_abs = 0; $block_vars = array(); $unit_is_factory = in_array($unit_id, $sn_group_factories) && get_unit_param($unit_id, P_MINING_IS_MANAGED); // $unit_db_name = pname_resource_name($unit_id); foreach ($planets as $planet) { $unit_level_plain = mrc_get_level($user, $planet, $unit_id, false, true); $level_plus['FACTORY'] = $unit_is_factory; $level_plus['LEVEL_PLUS_YELLOW'] = 0; $level_plus['LEVEL_PLUS_GREEN'] = 0; $level_plus['PERCENT'] = $unit_is_factory ? $unit_level_plain ? $planet[pname_factory_production_field_name($unit_id)] * 10 : -1 : -1; switch ($mode) { /* case 'structures': $level_plus_build = $ques[$planet['id']]['in_que'][que_get_unit_que($unit_id)][$user['id']][$planet['id']][$unit_id]; if($level_plus_build) { $level_plus['LEVEL_PLUS_GREEN'] = $level_plus_build < 0 ? $level_plus_build : "+{$level_plus_build}"; $total['units'][$unit_id]['LEVEL_PLUS_GREEN'] += $level_plus['LEVEL_PLUS_GREEN']; } break; */ /** @noinspection PhpMissingBreakStatementInspection */ case 'fleet': $level_plus['LEVEL_PLUS_YELLOW'] = $planet['fleet_list']['own']['total'][$unit_id] <= 0 ? $planet['fleet_list']['own']['total'][$unit_id] : "+{$planet['fleet_list']['own']['total'][$unit_id]}"; $total['units'][$unit_id]['LEVEL_PLUS_YELLOW'] += $level_plus['LEVEL_PLUS_YELLOW']; case 'structures': case 'defense': $level_plus_build = $ques[$planet['id']]['in_que'][que_get_unit_que($unit_id)][$user['id']][$planet['id']][$unit_id]; if ($level_plus_build) { $level_plus['LEVEL_PLUS_GREEN'] = $level_plus_build < 0 ? $level_plus_build : "+{$level_plus_build}"; // $level_plus['LEVEL_PLUS_GREEN'] = "+{$level_plus_build}"; $total['units'][$unit_id]['LEVEL_PLUS_GREEN'] += $level_plus['LEVEL_PLUS_GREEN']; } break; default: break; } $block_vars[] = array_merge($level_plus, array('ID' => $planet['id'], 'TYPE' => $planet['planet_type'], 'LEVEL' => $unit_level_plain == 0 && !$level_plus['LEVEL_PLUS_YELLOW'] && !$level_plus['LEVEL_PLUS_GREEN'] ? '-' : $unit_level_plain)); $unit_count += $unit_level_plain; $unit_count_abs += $unit_level_plain + abs($level_plus['LEVEL_PLUS_YELLOW']) + abs($level_plus['LEVEL_PLUS_GREEN']); } if ($unit_count_abs) { $template->assign_block_vars('prods', array('ID' => $unit_id, 'FIELD' => 'unit_' . $unit_id, 'NAME' => $lang['tech'][$unit_id], 'MODE' => $mode)); foreach ($block_vars as $block_var) { $template->assign_block_vars('prods.planet', $block_var); } $unit_green = $total['units'][$unit_id]['LEVEL_PLUS_GREEN']; $unit_yellow = $total['units'][$unit_id]['LEVEL_PLUS_YELLOW']; $template->assign_block_vars('prods.planet', array('ID' => 0, 'LEVEL' => $unit_count, 'LEVEL_PLUS_GREEN' => $unit_green == 0 ? '' : ($unit_green > 0 ? "+{$unit_green}" : $unit_green), 'LEVEL_PLUS_YELLOW' => $unit_yellow == 0 ? '' : ($unit_yellow > 0 ? "+{$unit_yellow}" : $unit_yellow), 'PERCENT' => $unit_is_factory ? '' : -1, 'FACTORY' => $unit_is_factory)); } } } $template->assign_block_vars('planet', array_merge(array('ID' => 0, 'NAME' => $lang['sys_total'], 'FIELDS_CUR' => $total['fields'], 'FIELDS_MAX' => $total['fields_max'], 'METAL_CUR' => pretty_number($total['metal']), 'METAL_PROD' => pretty_number($total['metal_perhour']), 'CRYSTAL_CUR' => pretty_number($total['crystal']), 'CRYSTAL_PROD' => pretty_number($total['crystal_perhour']), 'DEUTERIUM_CUR' => pretty_number($total['deuterium']), 'DEUTERIUM_PROD' => pretty_number($total['deuterium_perhour']), 'ENERGY_CUR' => pretty_number($total['energy']), 'ENERGY_MAX' => pretty_number($total['energy_max']), 'TEMP_MIN' => $total['temp_min'], 'TEMP_MAX' => $total['temp_max']))); $template->assign_vars(array('COLONIES_CURRENT' => get_player_current_colonies($user), 'COLONIES_MAX' => get_player_max_colonies($user), 'EXPEDITIONS_CURRENT' => get_player_current_expeditions($user), 'EXPEDITIONS_MAX' => get_player_max_expeditons($user), 'PLANET_DENSITY_RICHNESS_NORMAL' => PLANET_DENSITY_RICHNESS_NORMAL, 'PLANET_DENSITY_RICHNESS_AVERAGE' => PLANET_DENSITY_RICHNESS_AVERAGE, 'PLANET_DENSITY_RICHNESS_GOOD' => PLANET_DENSITY_RICHNESS_GOOD, 'PLANET_DENSITY_RICHNESS_PERFECT' => PLANET_DENSITY_RICHNESS_PERFECT)); //$template->assign_recursive($template_result); return $template; }
/** * 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_build($user, $planet, $build_mode = BUILD_CREATE, $redirect = true) { global $lang; $unit_amount_qued = 0; try { if (!$user['id']) { throw new exception('{Нет идентификатора пользователя - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION } $unit_id = sys_get_param_int('unit_id'); /* if(!$unit_id && is_array($unit_list = sys_get_param('fmenge'))) { foreach($unit_list as $unit_id => $unit_amount) if($unit_amount) break; } */ if (!$unit_id) { throw new exception('{Нет идентификатора юнита - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION } $que_id = que_get_unit_que($unit_id); if (!$que_id) { throw new exception('{Неправильный тип очереди - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION } if ($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { throw new exception('{Уничтожать можно только здания на планете}', ERR_ERROR); // TODO EXCEPTION } $que_data = sn_get_groups('ques'); $que_data = $que_data[$que_id]; // die(); // TODO Переделать под подочереди if ($que_id == QUE_STRUCTURES) { $sn_groups_build_allow = sn_get_groups('build_allow'); $que_data['unit_list'] = $sn_groups_build_allow[$planet['planet_type']]; if (!isset($que_data['unit_list'][$unit_id])) { throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION } } /* // TODO Разделить очереди для Верфи и Обороны elseif($que_id == QUE_HANGAR) { $que_data['mercenary'] = in_array($unit_id, sn_get_groups('defense')) ? MRC_FORTIFIER : MRC_ENGINEER; } elseif($que_id == QUE_HANGAR) { $que_data['mercenary'] = in_array($unit_id, sn_get_groups('defense')) ? MRC_FORTIFIER : MRC_ENGINEER; } */ sn_db_transaction_start(); // Это нужно, что бы заблокировать пользователя и работу с очередями $user = db_user_by_id($user['id']); // Это нужно, что бы заблокировать планету от списания ресурсов if (isset($planet['id']) && $planet['id']) { $planet = db_planet_by_id($planet['id'], true); } else { $planet['id'] = 0; } $planet_id = $que_id == QUE_RESEARCH ? 0 : intval($planet['id']); $que = que_get($user['id'], $planet['id'], $que_id, true); $in_que =& $que['in_que'][$que_id][$user['id']][$planet_id]; $que_max_length = que_get_max_que_length($user, $planet, $que_id, $que_data); // TODO Добавить вызовы функций проверок текущей и максимальной длин очередей if (count($in_que) >= $que_max_length) { throw new exception('{Все слоты очереди заняты}', ERR_ERROR); // TODO EXCEPTION } // TODO Отдельно посмотреть на уничтожение зданий - что бы можно было уничтожать их без планов switch (eco_can_build_unit($user, $planet, $unit_id)) { case BUILD_ALLOWED: break; case BUILD_UNIT_BUSY: throw new exception('{Строение занято}', ERR_ERROR); break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading // case BUILD_REQUIRE_NOT_MEET: // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading // case BUILD_REQUIRE_NOT_MEET: default: if ($build_mode == BUILD_CREATE) { throw new exception('{Требования не удовлетворены}', ERR_ERROR); } break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet } $unit_amount = floor(sys_get_param_float('unit_amount', 1)); $unit_amount_qued = $unit_amount; $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0; $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued; if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { if ($unit_level >= $unit_max) { throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION } $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level)); } if ($unit_amount < 1) { throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION } /* if($unit_max && $unit_level + $unit_amount > $unit_max) { throw new exception("Постройка {$unit_amount} {$lang['tech'][$unit_id]} приведет к привышению максимально возможного количества юнитов данного типа", ERR_ERROR); // TODO EXCEPTION } */ // TODO Переделать eco_unit_busy для всех типов зданий // if(eco_unit_busy($user, $planet, $que, $unit_id)) // { // die('Unit busy'); // TODO EXCEPTION // } if (get_unit_param($unit_id, P_STACKABLE)) { // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь if (in_array($unit_id, $group_missile = sn_get_groups('missile'))) { // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита $used_silo = 0; foreach ($group_missile as $missile_id) { $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0; $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE); } $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo; if ($free_silo <= 0) { throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION } $unit_size = get_unit_param($unit_id, P_UNIT_SIZE); if ($free_silo < $unit_size) { throw new exception("{В ракетной шахте нет места для {$lang['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION } $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size))); } $unit_level = $new_unit_level = 0; } else { $unit_amount = 1; if ($que_id == QUE_STRUCTURES) { // if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $que['sectors'][$planet['id']] <= 0) $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0; if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) { throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION } // И что это я такое написал? Зачем? //if($build_mode == BUILD_DESTROY && $planet['field_current'] <= $que['amounts'][$que_id]) //{ // die('Too much buildings'); // TODO EXCEPTION //} } $build_multiplier = $build_mode == BUILD_CREATE ? 1 : -1; $new_unit_level = $unit_level + $unit_amount * $build_multiplier; } $build_data = eco_get_build_data($user, $planet, $unit_id, $unit_level); $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount); if ($unit_amount < 0) { throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION } if ($new_unit_level < 0) { throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION } if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION } // $unit_amount = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW); $unit_amount_qued = 0; while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW); que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode); $unit_amount -= $place; $que = que_get($user['id'], $planet['id'], $que_id, true); $unit_amount_qued += $place; } // pdump($que); /* pdump($que = que_get($user['id'], $planet['id'], $que_id, true)); */ // die(); // if(count($que['ques'][$que_id][$user['id']][$planet_id]) >= $que_max_length) sn_db_transaction_commit(); if ($redirect) { sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id')); die; } $operation_result = array('STATUS' => ERR_NONE, 'MESSAGE' => '{Строительство начато}'); } catch (exception $e) { sn_db_transaction_rollback(); $operation_result = array('STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, 'MESSAGE' => $e->getMessage()); } if (!empty($operation_result['MESSAGE'])) { $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . $lang['tech'][$unit_id] . ']' . (isset($planet['id']) ? ' на ' . $planet['name'] : '') . '}'; } return $operation_result; }
function tpl_parse_planet($planet) { global $lang; $fleet_list = flt_get_fleets_to_planet($planet); $que = que_get($planet['id_owner'], $planet['id'], false); $structure_que = tpl_parse_planet_que($que, $planet, QUE_STRUCTURES); // TODO Заменить на que_tpl_parse_element($que_element); $structure_que_first = is_array($structure_que['que']) ? reset($structure_que['que']) : array(); $hangar_que = tpl_parse_planet_que($que, $planet, SUBQUE_FLEET); // TODO Заменить на que_tpl_parse_element($que_element); $hangar_que_first = is_array($hangar_que['que']) ? reset($hangar_que['que']) : array(); $defense_que = tpl_parse_planet_que($que, $planet, SUBQUE_DEFENSE); // TODO Заменить на que_tpl_parse_element($que_element); $defense_que_first = is_array($defense_que['que']) ? reset($defense_que['que']) : array(); $result = array('ID' => $planet['id'], 'NAME' => $planet['name'], 'IMAGE' => $planet['image'], 'GALAXY' => $planet['galaxy'], 'SYSTEM' => $planet['system'], 'PLANET' => $planet['planet'], 'TYPE' => $planet['planet_type'], 'COORDINATES' => uni_render_coordinates($planet), 'METAL_PERCENT' => $planet['metal_mine_porcent'] * 10, 'CRYSTAL_PERCENT' => $planet['crystal_mine_porcent'] * 10, 'DEUTERIUM_PERCENT' => $planet['deuterium_sintetizer_porcent'] * 10, 'STRUCTURE' => isset($structure_que_first['id']) ? $lang['tech'][$structure_que_first['id']] : '', 'HANGAR' => isset($hangar_que_first['id']) ? $lang['tech'][$hangar_que_first['id']] : '', 'hangar_que' => $hangar_que, 'DEFENSE' => isset($defense_que_first['id']) ? $lang['tech'][$defense_que_first['id']] : '', 'defense_que' => $defense_que, 'FIELDS_CUR' => $planet['field_current'], 'FIELDS_MAX' => eco_planet_fields_max($planet), 'FILL' => min(100, floor($planet['field_current'] / eco_planet_fields_max($planet) * 100)), 'FLEET_OWN' => $fleet_list['own']['count'], 'FLEET_ENEMY' => $fleet_list['enemy']['count'], 'FLEET_NEUTRAL' => $fleet_list['neutral']['count'], 'fleet_list' => $fleet_list, 'PLANET_GOVERNOR_ID' => $planet['PLANET_GOVERNOR_ID'], 'PLANET_GOVERNOR_NAME' => $lang['tech'][$planet['PLANET_GOVERNOR_ID']], 'PLANET_GOVERNOR_LEVEL' => $planet['PLANET_GOVERNOR_LEVEL'], 'PLANET_GOVERNOR_LEVEL_MAX' => get_unit_param($planet['PLANET_GOVERNOR_ID'], P_MAX_STACK)); if (!empty($que['ques'][QUE_STRUCTURES][$planet['id_owner']][$planet['id']])) { $result['building_que'] = array(); $building_que =& $que['ques'][QUE_STRUCTURES][$planet['id_owner']][$planet['id']]; foreach ($building_que as $que_element) { $result['building_que'][] = que_tpl_parse_element($que_element); } } return $result; }
while ($result = mysql_fetch_assoc($mess)) { //$str = substr($result['message'], 0, 85); $str = $result['message']; $usr = $result['user']; $msg .= "<tr><td align=\"left\">".$usr.":</td><td>".$str."</td></tr>"; } $msg .= '</table>'; */ $recyclers_send = min(ceil(($planetrow['debris_metal'] + $planetrow['debris_crystal']) / $sn_data[SHIP_RECYCLER]['capacity']), $planetrow[$sn_data[SHIP_RECYCLER]['name']]); int_planet_pretemplate($planetrow, $template); foreach (array(QUE_STRUCTURES => $sn_data['groups']['ques'][QUE_STRUCTURES]) as $que_id => $que_type_data) { $template->assign_block_vars('ques', array(ID => $que_id, NAME => $lang['sys_ques'][$que_id], LENGTH => count($que['que'][$que_id]))); if ($que['que'][$que_id]) { foreach ($que['que'][$que_id] as $que_item) { $template->assign_block_vars('que', $que_item); } } } $que_hangar_length = tpl_assign_hangar(QUE_HANGAR, $planetrow, $template); $template->assign_block_vars('ques', array(ID => QUE_HANGAR, NAME => $lang['sys_ques'][QUE_HANGAR], LENGTH => $que_hangar_length)); $unit_id = intval($planetrow['b_tech_id']); $time_rest = $planetrow['b_tech'] - $time_now; $time_rest = $time_rest >= 0 ? $time_rest : 0; $template->assign_block_vars('ques', array(ID => QUE_RESEARCH, NAME => $lang['sys_ques'][QUE_RESEARCH], LENGTH => $unit_id && $time_rest ? 1 : 0)); if ($unit_id && $time_rest) { $template->assign_block_vars('que', array('ID' => $unit_id, 'QUE' => QUE_RESEARCH, 'NAME' => $lang['tech'][$unit_id], 'TIME' => $time_rest, 'TIME_FULL' => $time_rest, 'AMOUNT' => 1, 'LEVEL' => $user[$sn_data[$unit_id]['name']] + 1)); } $template->assign_vars(array('TIME_NOW' => $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']), 'RECYCLERS_SEND' => $recyclers_send, 'planet_temp_min' => $planetrow['temp_min'], 'planet_temp_max' => $planetrow['temp_max'], 'ADMIN_EMAIL' => $config->game_adminEmail)); display(parsetemplate($template, $parse), "{$lang['ov_overview']} - {$lang['sys_planet_type'][$planetrow['planet_type']]} {$planetrow['name']} [{$planetrow['galaxy']}:{$planetrow['system']}:{$planetrow['planet']}]"); break; }
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'] }
function eco_que_add($user, &$planet, $que, $que_id, $unit_id, $unit_amount = 1, $build_mode = BUILD_CREATE) { global $lang, $time_now, $sn_data; $que_types = $sn_data['groups']['ques']; $que_types[QUE_STRUCTURES]['unit_list'] = $sn_data['groups']['build_allow'][$planet['planet_type']]; $que_data =& $que_types[$que_id]; // We do not work with negaitve unit_amounts - hack or cheat if ($unit_amount < 1 || !in_array($unit_id, $que_data['unit_list']) || count($que['que'][$que_id]) >= $que_data['length']) { return $que; } doquery('START TRANSACTION;'); $planet = doquery("SELECT * FROM `{{planets}}` WHERE `id` = {$planet['id']} LIMIT 1 FOR UPDATE;", '', true); if (!eco_can_build_unit($user, $planet, $unit_id) || eco_unit_busy($user, $planet, $que, $unit_id) || $que_id == QUE_STRUCTURES && ($build_mode == BUILD_CREATE && max(0, eco_planet_fields_max($planet) - $planet['field_current'] - $que['amounts'][$que_id]) <= 0 || $build_mode == BUILD_DESTROY && $planet['field_current'] <= $que['amounts'][$que_id])) { doquery('ROLLBACK;'); return $que; } if ($que === false) { $que = array(); } $build_mode = $build_mode == BUILD_CREATE ? 1 : -1; $unit_db_name = $sn_data[$unit_id]['name']; $unit_level = ($planet[$unit_db_name] ? $planet[$unit_db_name] : 0) + $que['in_que'][$unit_id]; $build_data = eco_get_build_data($user, $planet, $unit_id, $unit_level); $unit_level += $build_mode * $unit_amount; if ($build_data['CAN'][$build_mode] >= $unit_amount && $unit_level >= 0) { $unit_time = $build_data[$build_mode][RES_TIME]; $que_item_string = "{$unit_id},{$unit_amount},{$unit_time},{$build_mode},{$que_id};"; $que['que'][$que_id][] = array('ID' => $unit_id, 'AMOUNT' => $unit_amount, 'TIME' => $unit_time, 'TIME_FULL' => $unit_time, 'MODE' => $build_mode, 'NAME' => $lang['tech'][$unit_id], 'QUE' => $que_id, 'STRING' => $que_item_string, 'LEVEL' => $unit_level); $que['in_que'][$unit_id] += $unit_amount * $build_mode; $que['in_que_abs'][$unit_id] += $unit_amount; $que['amounts'][$que_id] += $unit_amount * $build_mode; $que['string'] .= $que_item_string; $que['query'] = "`que` = '{$que['string']}'"; $planet['que'] = $que['string']; foreach ($sn_data['groups']['resources_loot'] as $resource_id) { $resource_db_name = $sn_data[$resource_id]['name']; $resource_change = $build_data[$build_mode][$resource_id] * $unit_amount; $planet[$resource_db_name] -= $resource_change; $que['query'] = "`{$resource_db_name}` = `{$resource_db_name}` - '{$resource_change}',{$que['query']}"; } doquery("UPDATE {{planets}} SET {$que['query']} WHERE `id` = '{$planet['id']}' LIMIT 1;"); } doquery('COMMIT'); return $que; }