function flt_mission_colonize(&$mission_data)
{
    $fleet_row =& $mission_data['fleet'];
    $src_user_row =& $mission_data['src_user'];
    global $lang;
    $TargetAdress = sprintf($lang['sys_adress_planet'], $fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet']);
    $fleet_array = sys_unit_str2arr($fleet_row['fleet_array']);
    $TheMessage = $lang['sys_colo_no_colonizer'];
    if ($fleet_array[SHIP_COLONIZER] >= 1) {
        $TheMessage = $lang['sys_colo_notfree'];
        if (!$mission_data['dst_planet'] || empty($mission_data['dst_planet'])) {
            $iPlanetCount = get_player_current_colonies($src_user_row);
            // Can we colonize more planets?
            $TheMessage = $lang['sys_colo_maxcolo'];
            if ($iPlanetCount < get_player_max_colonies($src_user_row)) {
                // Yes, we can colonize
                $TheMessage = $lang['sys_colo_badpos'];
                $NewOwnerPlanet = uni_create_planet($fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet'], $fleet_row['fleet_owner'], "{$lang['sys_colo_defaultname']} {$iPlanetCount}", false, array('user_row' => $src_user_row));
                if ($NewOwnerPlanet) {
                    $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_allisok'];
                    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
                    $fleet_array[SHIP_COLONIZER]--;
                    $fleet_row['fleet_amount']--;
                    $fleet_row['fleet_array'] = sys_unit_arr2str($fleet_array);
                    return RestoreFleetToPlanet($fleet_row, false);
                }
            }
        }
    }
    doquery("UPDATE `{{fleets}}` SET `fleet_mess` = '1' WHERE `fleet_id` = '{$fleet_row['fleet_id']}' LIMIT 1;");
    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], "{$lang['sys_colo_arrival']}{$TargetAdress}{$TheMessage}");
    return CACHE_FLEET;
}
function flt_mission_colonize($mission_data)
{
    $fleet_row = $mission_data['fleet'];
    $src_user_row = $mission_data['src_user'];
    $destination_planet = $mission_data['dst_planet'];
    global $lang;
    $TargetAdress = sprintf($lang['sys_adress_planet'], $fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet']);
    $fleet_array = sys_unit_str2arr($fleet_row['fleet_array']);
    $TheMessage = $lang['sys_colo_no_colonizer'];
    if ($fleet_array[SHIP_COLONIZER] >= 1) {
        $TheMessage = $lang['sys_colo_notfree'];
        if (!$destination_planet) {
            $iMaxColo = $src_user_row['colonisation_tech'] + 1;
            $iPlanetCount = doquery("SELECT count(*) as `planet_count` FROM `{{planets}}` WHERE `id_owner` = '{$fleet_row['fleet_owner']}' AND `planet_type` = '1';", '', true);
            $iPlanetCount = $iPlanetCount['planet_count'];
            // Can we colonize more planets?
            $TheMessage = $lang['sys_colo_maxcolo'];
            if ($iPlanetCount < $iMaxColo && $iPlanetCount < $GLOBALS['config']->player_max_colonies + 1) {
                // Yes, we can colonize
                $TheMessage = $lang['sys_colo_badpos'];
                $NewOwnerPlanet = uni_create_planet($fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet'], $fleet_row['fleet_owner'], "{$lang['sys_colo_defaultname']} ¹{$iPlanetCount}");
                if ($NewOwnerPlanet) {
                    $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_allisok'];
                    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
                    $fleet_array[SHIP_COLONIZER]--;
                    $fleet_row['fleet_amount']--;
                    $fleet_row['fleet_array'] = sys_unit_arr2str($fleet_array);
                    if ($fleet_row['fleet_array']) {
                        $GLOBALS['debug']->warning("Sending several type of ships with colonizer leads to resource duplication. Resource duplicate X time where X - number of ship type<br>Fleet: {$fleet_row['fleet_array']}", 'Colonization With Fleet', 304);
                    }
                    return RestoreFleetToPlanet($fleet_row, false);
                }
            }
        }
    }
    doquery("UPDATE `{{fleets}}` SET `fleet_mess` = '1' WHERE `fleet_id` = '{$fleet_row['fleet_id']}' LIMIT 1;");
    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], "{$lang['sys_colo_arrival']}{$TargetAdress}{$TheMessage}");
    return CACHE_FLEET;
}
Beispiel #3
0
         $que_item = explode(',', $que_item);
         $unit_id = $que_item[0];
         $build_destroy_divisor = $que_item[3] == BUILD_CREATE ? 1 : 2;
         $unit_level = isset($units_levels[$unit_id]) ? $units_levels[$unit_id] : 0;
         $unit_cost = $units_info[$unit_id][P_COST];
         $unit_factor = $unit_cost[P_FACTOR] ? $unit_cost[P_FACTOR] : 1;
         $price_increase = pow($unit_factor, $unit_level);
         // $unit_time = 0;
         foreach ($unit_cost as $resource_id => &$resource_amount) {
             if (!in_array($resource_id, $group_resource_loot)) {
                 unset($unit_cost[$resource_id]);
                 continue;
             }
             $resource_amount = floor($resource_amount * $price_increase / $build_destroy_divisor);
         }
         $unit_cost = sys_unit_arr2str($unit_cost);
         $units_levels[$unit_id] += $que_item[3];
         $que_data[] = "({$user_id},{$planet_id},{$planet_id},1,{$que_item[2]},{$unit_id},1,{$que_item[3]},{$units_levels[$unit_id]},{$que_item[2]},'{$unit_cost}')";
     }
 }
 // Конвертируем очередь верфи
 if ($row['b_hangar_id']) {
     $return_resources = array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0);
     $hangar_units = sys_unit_str2arr($row['b_hangar_id']);
     foreach ($hangar_units as $unit_id => $unit_count) {
         if ($unit_count <= 0) {
             continue;
         }
         foreach ($units_info[$unit_id][P_COST] as $resource_id => $resource_amount) {
             if (!in_array($resource_id, $group_resource_loot)) {
                 continue;
Beispiel #4
0
function que_add_unit($unit_id, $user = array(), $planet = array(), $build_data, $unit_level = 0, $unit_amount = 1, $build_mode = BUILD_CREATE)
{
    // TODO Унифицировать проверки
    // TODO que_process() тут
    sn_db_transaction_check(true);
    $build_mode = $build_mode == BUILD_CREATE ? BUILD_CREATE : BUILD_DESTROY;
    // TODO: Some checks
    db_change_units($user, $planet, array(RES_METAL => -$build_data[$build_mode][RES_METAL] * $unit_amount, RES_CRYSTAL => -$build_data[$build_mode][RES_CRYSTAL] * $unit_amount, RES_DEUTERIUM => -$build_data[$build_mode][RES_DEUTERIUM] * $unit_amount));
    $que_type = que_get_unit_que($unit_id);
    $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL';
    $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin;
    if (is_numeric($planet_id)) {
        db_planet_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())");
    } elseif (is_numeric($user['id'])) {
        db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
    }
    $resource_list = sys_unit_arr2str($build_data[$build_mode]);
    db_que_set_insert("`que_player_id` = {$user['id']},\n      `que_planet_id` = {$planet_id},\n      `que_planet_id_origin` = {$planet_id_origin},\n      `que_type` = {$que_type},\n      `que_time_left` = {$build_data[RES_TIME][$build_mode]},\n      `que_unit_id` = {$unit_id},\n      `que_unit_amount` = {$unit_amount},\n      `que_unit_mode` = {$build_mode},\n      `que_unit_level` = {$unit_level},\n      `que_unit_time` = {$build_data[RES_TIME][$build_mode]},\n      `que_unit_price` = '{$resource_list}'");
}
function flt_mission_explore(&$mission_data)
{
    if (!isset($mission_data['fleet_event']) || $mission_data['fleet_event'] != EVENT_FLT_ACOMPLISH) {
        return CACHE_NONE;
    }
    global $lang, $config;
    static $ship_data, $rates;
    $result = array('$mission_data' => $mission_data, '$outcome_list' => array(), '$mission_outcome' => FLT_EXPEDITION_OUTCOME_NONE, '$outcome_value' => 0, '$outcome_percent' => 0, '$outcome_mission_sub' => -1, '$fleet' => array(), '$fleet_lost' => array(), '$found_dark_matter' => 0, '$fleet_metal_points' => 0);
    $fleet =& $result['$fleet'];
    //  $fleet_left = &$result['$fleet_left'];
    $fleet_lost =& $result['$fleet_lost'];
    $outcome_mission_sub =& $result['$outcome_mission_sub'];
    $outcome_percent =& $result['$outcome_percent'];
    $found_dark_matter =& $result['$found_dark_matter'];
    $mission_outcome =& $result['$mission_outcome'];
    $outcome_value =& $result['$outcome_value'];
    $outcome_list =& $result['$outcome_list'];
    $fleet_metal_points =& $result['$fleet_metal_points'];
    if (!$ship_data) {
        foreach (sn_get_groups('fleet') as $unit_id) {
            $unit_info = get_unit_param($unit_id);
            if ($unit_info[P_UNIT_TYPE] != UNIT_SHIPS || !isset($unit_info['engine'][0]['speed']) || !$unit_info['engine'][0]['speed']) {
                continue;
            }
            $ship_data[$unit_id][P_COST_METAL] = get_unit_cost_in($unit_info[P_COST]);
        }
        $rates = get_resource_exchange();
    }
    $fleet_row = $mission_data['fleet'];
    $fleet = sys_unit_str2arr($fleet_row['fleet_array']);
    $fleet_capacity = 0;
    $fleet_metal_points = 0;
    foreach ($fleet as $ship_id => $ship_amount) {
        $unit_info = get_unit_param($ship_id);
        $fleet_capacity += $ship_amount * $unit_info[P_CAPACITY];
        $fleet_metal_points += $ship_amount * $ship_data[$ship_id][P_COST_METAL];
    }
    $fleet_capacity = max(0, $fleet_capacity - $fleet_row['fleet_resource_metal'] + $fleet_row['fleet_resource_crystal'] + $fleet_row['fleet_resource_deuterium']);
    $flt_stay_hours = ($fleet_row['fleet_end_stay'] - $fleet_row['fleet_start_time']) / 3600 * ($config->game_speed_expedition ? $config->game_speed_expedition : 1);
    $outcome_list = sn_get_groups('mission_explore_outcome_list');
    $outcome_list[FLT_EXPEDITION_OUTCOME_NONE]['chance'] = ceil(200 / pow($flt_stay_hours, 1 / 1.7));
    $chance_max = 0;
    foreach ($outcome_list as $key => &$value) {
        if (!$value['chance']) {
            unset($outcome_list[$key]);
            continue;
        }
        $value['value'] = $chance_max = $value['chance'] + $chance_max;
    }
    $outcome_value = mt_rand(0, $chance_max);
    // $outcome_value = 409;
    $outcome_description =& $outcome_list[$mission_outcome = FLT_EXPEDITION_OUTCOME_NONE];
    foreach ($outcome_list as $key => &$value) {
        if (!$value['chance']) {
            continue;
        }
        $mission_outcome = $key;
        $outcome_description = $value;
        if ($outcome_value <= $outcome_description['value']) {
            break;
        }
    }
    // Вычисляем вероятность выпадения данного числа в общем пуле
    $msg_sender = $lang['flt_mission_expedition']['msg_sender'];
    $msg_title = $lang['flt_mission_expedition']['msg_title'];
    $outcome_percent = ($outcome_description['value'] - $outcome_value) / $outcome_description['chance'];
    $msg_text = '';
    $msg_text_addon = '';
    $found_dark_matter = 0;
    //  $outcome_mission_sub = -1;
    switch ($mission_outcome) {
        //  switch(FLT_EXPEDITION_OUTCOME_LOST_FLEET) { // TODO DEBUG!
        case FLT_EXPEDITION_OUTCOME_LOST_FLEET:
            flt_mission_explore_outcome_lost_fleet($result);
            //      // $fleet_left = 1 - mt_rand(1, 3) * 0.25;// * 0.25;
            //      $fleet_left = 1 - mt_rand(1, 3) * mt_rand(200000, 300000) / 1000000;
            //      $fleet_lost = array();
            //      foreach($fleet as $unit_id => &$unit_amount) {
            //        $ships_left = floor($unit_amount * $fleet_left);
            //        $fleet_lost[$unit_id] = $unit_amount - $ships_left;
            //        $unit_amount = $ships_left;
            //        if(!$unit_amount) {
            //          unset($fleet[$unit_id]);
            //        }
            //      }
            break;
        case FLT_EXPEDITION_OUTCOME_LOST_FLEET_ALL:
            flt_mission_explore_outcome_lost_fleet_all($result);
            //      $fleet_lost = $fleet;
            //      $fleet = array();
            break;
        case FLT_EXPEDITION_OUTCOME_FOUND_FLEET:
            $outcome_mission_sub = $outcome_percent >= 0.99 ? 0 : ($outcome_percent >= 0.9 ? 1 : 2);
            $outcome_percent = $outcome_description['percent'][$outcome_mission_sub];
            // Рассчитываем эквивалент найденного флота в метале
            // $found_in_metal = min($outcome_percent * $fleet_metal_points, $config->resource_multiplier * 10000000); // game_speed
            $found_in_metal = min($outcome_percent * $fleet_metal_points, game_resource_multiplier(true) * 10000000);
            // game_speed
            //  13 243 754 000 g x1
            //  60 762 247 000 a x10
            // 308 389 499 488 000 b x500
            // Рассчитываем стоимость самого дорого корабля в металле
            $max_metal_cost = 0;
            foreach ($fleet as $ship_id => $ship_amount) {
                $max_metal_cost = max($max_metal_cost, $ship_data[$ship_id]['metal_cost']);
            }
            // Ограничиваем корабли только теми, чья стоимость в металле меньше или равно стоимости самого дорогого корабля
            $can_be_found = array();
            foreach ($ship_data as $ship_id => $ship_info) {
                if ($ship_info['metal_cost'] < $max_metal_cost) {
                    $can_be_found[$ship_id] = $ship_info['metal_cost'];
                }
            }
            // Убираем колонизаторы и шпионов - миллиарды шпионов и колонизаторов нам не нужны
            unset($can_be_found[SHIP_COLONIZER]);
            unset($can_be_found[SHIP_SPY]);
            $fleet_found = array();
            while (count($can_be_found) && $found_in_metal >= max($can_be_found)) {
                $found_index = mt_rand(1, count($can_be_found)) - 1;
                $found_ship = array_slice($can_be_found, $found_index, 1, true);
                $found_ship_cost = reset($found_ship);
                $found_ship_id = key($found_ship);
                if ($found_ship_cost > $found_in_metal) {
                    unset($can_be_found[$found_ship_id]);
                } else {
                    $found_ship_count = mt_rand(1, floor($found_in_metal / $found_ship_cost));
                    $fleet_found[$found_ship_id] += $found_ship_count;
                    $found_in_metal -= $found_ship_count * $found_ship_cost;
                }
            }
            if (empty($fleet_found)) {
                $msg_text_addon = $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['no_result'];
            } else {
                foreach ($fleet_found as $unit_id => $unit_amount) {
                    $fleet[$unit_id] += $unit_amount;
                }
            }
            break;
        case FLT_EXPEDITION_OUTCOME_FOUND_RESOURCES:
            $outcome_mission_sub = $outcome_percent >= 0.99 ? 0 : ($outcome_percent >= 0.9 ? 1 : 2);
            $outcome_percent = $outcome_description['percent'][$outcome_mission_sub];
            // Рассчитываем количество найденных ресурсов
            $found_in_metal = ceil(min($outcome_percent * $fleet_metal_points, game_resource_multiplier(true) * 10000000, $fleet_capacity) * mt_rand(950000, 1050000) / 1000000);
            // game_speed
            $resources_found[RES_METAL] = floor(mt_rand(300000, 700000) / 1000000 * $found_in_metal);
            $found_in_metal -= $resources_found[RES_METAL];
            $found_in_metal = floor($found_in_metal * $rates[RES_METAL] / $rates[RES_CRYSTAL]);
            $resources_found[RES_CRYSTAL] = floor(mt_rand(500000, 1000000) / 1000000 * $found_in_metal);
            $found_in_metal -= $resources_found[RES_CRYSTAL];
            $found_in_metal = floor($found_in_metal * $rates[RES_CRYSTAL] / $rates[RES_DEUTERIUM]);
            $resources_found[RES_DEUTERIUM] = $found_in_metal;
            $fleet_row['fleet_resource_metal'] += $resources_found[RES_METAL];
            $fleet_row['fleet_resource_crystal'] += $resources_found[RES_CRYSTAL];
            $fleet_row['fleet_resource_deuterium'] += $resources_found[RES_DEUTERIUM];
            if (array_sum($resources_found) == 0) {
                $msg_text_addon = $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['no_result'];
            }
            break;
        case FLT_EXPEDITION_OUTCOME_FOUND_DM:
            $outcome_mission_sub = $outcome_percent >= 0.99 ? 0 : ($outcome_percent >= 0.9 ? 1 : 2);
            $outcome_percent = $outcome_description['percent'][$outcome_mission_sub];
            // Рассчитываем количество найденной ТМ
            $found_dark_matter = floor(min($outcome_percent * $fleet_metal_points / $rates[RES_DARK_MATTER], 10000) * mt_rand(750000, 1000000) / 1000000);
            if (!$found_dark_matter) {
                $msg_text_addon = $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['no_result'];
            }
            break;
        case FLT_EXPEDITION_OUTCOME_FOUND_ARTIFACT:
            break;
        default:
            break;
    }
    flt_mission_explore_addon($result);
    $query_data = array();
    if ($found_dark_matter) {
        rpg_points_change($fleet_row['fleet_owner'], RPG_EXPEDITION, $found_dark_matter, 'Expedition Bonus');
        $msg_text_addon = sprintf($lang['flt_mission_expedition']['found_dark_matter'], $found_dark_matter);
    }
    if (!empty($fleet_lost)) {
        $msg_text_addon = $lang['flt_mission_expedition']['lost_fleet'];
        foreach ($fleet_lost as $ship_id => $ship_amount) {
            $msg_text_addon .= $lang['tech'][$ship_id] . ' - ' . $ship_amount . "\r\n";
        }
    }
    $fleet_row['fleet_amount'] = array_sum($fleet);
    if (!empty($fleet) && $fleet_row['fleet_amount']) {
        if (!empty($fleet_found)) {
            $msg_text_addon = $lang['flt_mission_expedition']['found_fleet'];
            foreach ($fleet_found as $ship_id => $ship_amount) {
                $msg_text_addon .= $lang['tech'][$ship_id] . ' - ' . $ship_amount . "\r\n";
            }
        }
        if (!empty($resources_found) && array_sum($resources_found) > 0) {
            $msg_text_addon = $lang['flt_mission_expedition']['found_resources'];
            foreach ($resources_found as $ship_id => $ship_amount) {
                $msg_text_addon .= $lang['tech'][$ship_id] . ' - ' . $ship_amount . "\r\n";
            }
            $query_data[] = "`fleet_resource_metal` = `fleet_resource_metal` + {$resources_found[RES_METAL]}";
            $query_data[] = "`fleet_resource_crystal` = `fleet_resource_crystal` + {$resources_found[RES_CRYSTAL]}";
            $query_data[] = "`fleet_resource_deuterium` = `fleet_resource_deuterium` + {$resources_found[RES_DEUTERIUM]}";
        }
        if (!empty($fleet_lost) || !empty($fleet_found)) {
            $fleet_row['fleet_array'] = sys_unit_arr2str($fleet);
            $query_data[] = "`fleet_amount` = {$fleet_row['fleet_amount']}";
            $query_data[] = "`fleet_array` = '{$fleet_row['fleet_array']}'";
        }
        $query_data[] = '`fleet_mess` = 1';
        $query_data = "UPDATE {{fleets}} SET " . implode(',', $query_data);
    } else {
        // Удалить флот
        $query_data = "DELETE FROM {{fleets}}";
    }
    $query_data .= " WHERE `fleet_id` = {$fleet_row['fleet_id']} LIMIT 1";
    doquery($query_data);
    db_user_set_by_id($fleet_row['fleet_owner'], "`player_rpg_explore_xp` = `player_rpg_explore_xp` + 1");
    if (!$msg_text) {
        $messages =& $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['messages'];
        if ($outcome_mission_sub >= 0 && is_array($messages)) {
            $messages =& $messages[$outcome_mission_sub];
        }
        $msg_text = is_string($messages) ? $messages : (is_array($messages) ? $messages[mt_rand(0, count($messages) - 1)] : '');
    }
    $msg_text = sprintf($msg_text, $fleet_row['fleet_id'], uni_render_coordinates($fleet_row, 'fleet_end_')) . ($msg_text_addon ? "\r\n" . $msg_text_addon : '');
    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_end_stay'], MSG_TYPE_EXPLORE, $msg_sender, $msg_title, $msg_text);
    return CACHE_FLEET | CACHE_USER_SRC;
}
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]);
}