function ube_attack_prepare(&$mission_data)
{
    /*
    UBE_OPTIONS[UBE_LOADED]   
    UBE_OPTIONS[UBE_SIMULATOR]
    UBE_OPTIONS[UBE_EXCHANGE] 
    UBE_OPTIONS[UBE_MOON_WAS] 
    */
    $fleet_row =& $mission_data['fleet'];
    $destination_planet =& $mission_data['dst_planet'];
    $ube_time = $fleet_row['fleet_start_time'];
    $combat_data = array(UBE_TIME => $ube_time);
    // TODO: Не допускать атаки игроком своих же флотов - т.е. холд против атаки
    // Готовим инфу по атакуемой планете
    ube_attack_prepare_planet($combat_data, $destination_planet);
    // Готовим инфу по удержанию
    $fleets = doquery("SELECT * FROM {{fleets}} \n    WHERE\n      `fleet_end_galaxy` = {$fleet_row['fleet_end_galaxy']} AND `fleet_end_system` = {$fleet_row['fleet_end_system']} AND `fleet_end_planet` = {$fleet_row['fleet_end_planet']} AND `fleet_end_type` = {$fleet_row['fleet_end_type']}\n      AND `fleet_start_time` <= {$ube_time} AND `fleet_end_stay` >= {$ube_time}\n      AND `fleet_mess` = 0 FOR UPDATE");
    while ($fleet = db_fetch($fleets)) {
        ube_attack_prepare_fleet($combat_data, $fleet, false);
    }
    // Готовим инфу по атакующим
    if ($fleet_row['fleet_group']) {
        $fleets = doquery("SELECT * FROM {{fleets}} WHERE fleet_group= {$fleet_row['fleet_group']} FOR UPDATE");
        while ($fleet = db_fetch($fleets)) {
            ube_attack_prepare_fleet($combat_data, $fleet, true);
        }
    } else {
        ube_attack_prepare_fleet($combat_data, $fleet_row, true);
    }
    // Готовим опции
    $combat_data[UBE_OPTIONS][UBE_MOON_WAS] = $destination_planet['planet_type'] == PT_MOON || is_array(db_planet_by_parent($destination_planet['id'], true, '`id`'));
    $combat_data[UBE_OPTIONS][UBE_MISSION_TYPE] = $fleet_row['fleet_mission'];
    global $config;
    $combat_data[UBE_OPTIONS][UBE_METHOD] = $config->game_ube_method ? $config->game_ube_method : 0;
    return $combat_data;
}
Example #2
0
         continue;
     }
     $moon = db_planet_by_parent($UserPlanet['id']);
     if ($moon) {
         $moon_fill = min(100, floor($moon['field_current'] / eco_planet_fields_max($moon) * 100));
     } else {
         $moon_fill = 0;
     }
     $moon_fleets = flt_get_fleets_to_planet($moon);
     $template->assign_block_vars('planet', array_merge($template_planet, array('PLANET_FLEET_ID' => $planet_fleet_id, 'MOON_ID' => $moon['id'], 'MOON_NAME' => $moon['name'], 'MOON_IMG' => $moon['image'], 'MOON_FILL' => min(100, $moon_fill), 'MOON_ENEMY' => $moon_fleets['enemy']['count'], 'MOON_PLANET' => $moon['parent_planet'])));
     $planet_count++;
 }
 sn_db_transaction_commit();
 tpl_assign_fleet($template, $fleets_to_planet);
 tpl_assign_fleet($template, $fleets);
 $lune = $planetrow['planet_type'] == PT_PLANET ? db_planet_by_parent($planetrow['id']) : db_planet_by_id($planetrow['parent_planet']);
 if ($lune) {
     $template->assign_vars(array('MOON_ID' => $lune['id'], 'MOON_IMG' => $lune['image'], 'MOON_NAME' => $lune['name']));
 }
 $planet_fill = floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100);
 $planet_fill = $planet_fill > 100 ? 100 : $planet_fill;
 $planet_recyclers_orbiting = 0;
 foreach (sn_get_groups('flt_recyclers') as $recycler_id) {
     $planet_recyclers_orbiting += mrc_get_level($user, $planetrow, $recycler_id);
 }
 int_planet_pretemplate($planetrow, $template);
 $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)) {
Example #3
0
function art_use(&$user, &$planetrow, $unit_id)
{
    global $lang;
    if (!in_array($unit_id, sn_get_groups('artifacts'))) {
        return;
    }
    sn_db_transaction_start();
    $user = db_user_by_id($user['id'], true);
    $unit_level = $artifact_level_old = mrc_get_level($user, array(), $unit_id, true);
    if ($unit_level > 0) {
        $db_changeset = array();
        switch ($unit_id) {
            case ART_LHC:
            case ART_HOOK_SMALL:
            case ART_HOOK_MEDIUM:
            case ART_HOOK_LARGE:
                $has_moon = db_planet_by_parent($planetrow['id'], true, '`id`');
                if ($planetrow['planet_type'] == PT_PLANET && !$has_moon['id']) {
                    $unit_level--;
                    $moon_chance = $unit_id == ART_LHC ? uni_calculate_moon_chance($planetrow['debris_metal'] + $planetrow['debris_crystal']) : ($unit_id == ART_HOOK_MEDIUM ? mt_rand(1100, 8999) : ($unit_id == ART_HOOK_SMALL ? 1100 : 8999));
                    $random = $unit_id == ART_LHC ? mt_rand(1, 100) : $moon_chance;
                    if ($random <= $moon_chance) {
                        $new_moon_row = uni_create_moon($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'], $user['id'], $moon_chance);
                        $message = sprintf($lang['art_moon_create'][$unit_id], $new_moon_row['name'], uni_render_coordinates($planetrow), pretty_number($moon_chance));
                    } else {
                        $message = $lang['art_lhc_moon_fail'];
                    }
                    msg_send_simple_message($user['id'], 0, 0, MSG_TYPE_ADMIN, $lang['art_lhc_from'], $lang['art_lhc_subj'], $message);
                } else {
                    $message = $lang['art_moon_exists'];
                }
                break;
            case ART_RCD_SMALL:
            case ART_RCD_MEDIUM:
            case ART_RCD_LARGE:
                $planetrow = db_planet_by_id($planetrow['id'], true);
                if ($planetrow['planet_type'] != PT_PLANET) {
                    $message = $lang['art_rcd_err_moon'];
                    break;
                }
                $que = que_get($user['id'], $planetrow['id'], QUE_STRUCTURES, false);
                if (!empty($que['items'])) {
                    $message = $lang['art_rcd_err_que'];
                    break;
                }
                $artifact_deploy = get_unit_param($unit_id, P_DEPLOY);
                // $deployment_str = '';
                $sectors_used = 0;
                foreach ($artifact_deploy as $deploy_unit_id => $deploy_unit_level) {
                    if (!($levels_deployed = max(0, $deploy_unit_level - mrc_get_level($user, $planetrow, $deploy_unit_id, true, true)))) {
                        continue;
                    }
                    $sectors_used += $levels_deployed;
                    $db_changeset['unit'][] = sn_db_unit_changeset_prepare($deploy_unit_id, $levels_deployed, $user, $planetrow['id']);
                    //$deploy_unit_name = get_unit_param($deploy_unit_id, P_NAME);
                    //$deployment_str .= ",`{$deploy_unit_name}` = GREATEST(`{$deploy_unit_name}`, {$deploy_unit_level})";
                }
                if ($sectors_used == 0) {
                    $message = $lang['art_rcd_err_no_sense'];
                    break;
                }
                $unit_level--;
                db_planet_set_by_id($planetrow['id'], "`field_current` = `field_current` + {$sectors_used}");
                $message = sprintf($lang['art_rcd_ok'], $lang['tech'][$unit_id], $planetrow['name'], uni_render_coordinates($planetrow));
                msg_send_simple_message($user['id'], 0, 0, MSG_TYPE_QUE, $lang['art_rcd_subj'], $lang['art_rcd_subj'], $message);
                break;
            case ART_HEURISTIC_CHIP:
                $que_item = null;
                $que = que_get($user['id'], $planetrow['id'], QUE_RESEARCH, true);
                $current_que =& $que['ques'][QUE_RESEARCH][$user['id']][0];
                if (!empty($current_que)) {
                    reset($current_que);
                    $que_item =& $que['ques'][QUE_RESEARCH][$user['id']][0][key($current_que)];
                }
                if (!empty($que_item) && $que_item['que_time_left'] > 60) {
                    $unit_level--;
                    $old_time = $que_item['que_time_left'];
                    $que_item['que_time_left'] = $que_item['que_time_left'] > PERIOD_HOUR ? ceil($que_item['que_time_left'] / 2) : 0;
                    db_que_set_time_left_by_id($que_item['que_id'], $que_item['que_time_left']);
                    $message = sprintf($lang['art_heurestic_chip_ok'], $lang['tech'][$que_item['que_unit_id']], $que_item['que_unit_level'], sys_time_human($old_time - $que_item['que_time_left']));
                    msg_send_simple_message($user['id'], 0, 0, MSG_TYPE_QUE, $lang['art_heurestic_chip_subj'], $lang['art_heurestic_chip_subj'], $message);
                } else {
                    $message = $lang['art_heurestic_chip_no_research'];
                }
                break;
            case ART_NANO_BUILDER:
                $planetrow = db_planet_by_id($planetrow['id'], true);
                $que_item = null;
                $que = que_get($user['id'], $planetrow['id'], QUE_STRUCTURES, true);
                $current_que =& $que['ques'][QUE_STRUCTURES][$user['id']][$planetrow['id']];
                // $que_item = &$que['que'][QUE_STRUCTURES][0];
                if (!empty($current_que)) {
                    reset($current_que);
                    $que_item =& $que['ques'][QUE_STRUCTURES][$user['id']][$planetrow['id']][key($current_que)];
                }
                if (isset($que_item) && $que_item['que_time_left'] > 60) {
                    $unit_level--;
                    $old_time = $que_item['que_time_left'];
                    $que_item['que_time_left'] = $que_item['que_time_left'] > PERIOD_HOUR ? ceil($que_item['que_time_left'] / 2) : 0;
                    db_que_set_time_left_by_id($que_item['que_id'], $que_item['que_time_left']);
                    $message = sprintf($lang['art_nano_builder_ok'], $que_item['que_unit_mode'] == BUILD_CREATE ? $lang['art_nano_builder_build'] : $lang['art_nano_builder_destroy'], $lang['tech'][$que_item['que_unit_id']], $que_item['que_unit_level'], $planetrow['name'], uni_render_coordinates($planetrow), sys_time_human($old_time - $que_item['que_time_left']));
                    msg_send_simple_message($user['id'], 0, 0, MSG_TYPE_QUE, $lang['art_nano_builder_subj'], $lang['art_nano_builder_subj'], $message);
                } else {
                    $message = $lang['art_nano_builder_no_que'];
                }
                break;
        }
        if ($unit_level != $artifact_level_old) {
            $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_level - $artifact_level_old, $user);
            db_changeset_apply($db_changeset);
        }
    } else {
        $message = $lang['art_err_no_artifact'];
    }
    sn_db_transaction_commit();
    message($message, "{$lang['tech'][UNIT_ARTIFACTS]} - {$lang['tech'][$unit_id]}", ($request_uri = sys_get_param_str_unsafe('REQUEST_URI')) ? $request_uri : 'artifacts' . DOT_PHP_EX . '#' . $unit_id, 5);
}