function sn_tpl_parse_fleet_db($fleet, $index, $user_data = false, &$result) { global $lang, $user; if (!$user_data) { $user_data = $user; } if ($fleet['fleet_mess'] == 0 && $fleet['fleet_mission'] == MT_AKS) { $aks = doquery("SELECT * FROM {{aks}} WHERE id={$fleet['fleet_group']} LIMIT 1;", true); } $spy_level = $user['id'] == $fleet['fleet_owner'] ? 100 : GetSpyLevel($user); $result['fleet'] = isset($result['fleet']) ? $result['fleet'] : array(); $result['fleet'] = array('NUMBER' => $index, 'ID' => $fleet['fleet_id'], 'OWNER' => $fleet['fleet_owner'], 'TARGET_OWNER' => $fleet['fleet_target_owner'], 'MESSAGE' => $fleet['fleet_mess'], 'MISSION' => $fleet['fleet_mission'], 'MISSION_NAME' => $lang['type_mission'][$fleet['fleet_mission']], 'ACS' => $aks['name'], 'AMOUNT' => $spy_level >= 4 ? pretty_number($fleet['fleet_amount']) . ($fleet['fleet_resource_metal'] + $fleet['fleet_resource_crystal'] + $fleet['fleet_resource_deuterium'] ? '+' : '') : '?', 'METAL' => $spy_level >= 8 ? $fleet['fleet_resource_metal'] : 0, 'CRYSTAL' => $spy_level >= 8 ? $fleet['fleet_resource_crystal'] : 0, 'DEUTERIUM' => $spy_level >= 8 ? $fleet['fleet_resource_deuterium'] : 0, 'START_TYPE_TEXT_SH' => $lang['sys_planet_type_sh'][$fleet['fleet_start_type']], 'START_COORDS' => "[{$fleet['fleet_start_galaxy']}:{$fleet['fleet_start_system']}:{$fleet['fleet_start_planet']}]", 'START_TIME_TEXT' => date(FMT_DATE_TIME, $fleet['fleet_end_time'] + SN_CLIENT_TIME_DIFF), 'START_LEFT' => floor($fleet['fleet_end_time'] + 1 - SN_TIME_NOW), 'START_URL' => uni_render_coordinates_href($fleet, 'fleet_start_', 3), 'START_NAME' => $fleet['fleet_start_name'], 'END_TYPE_TEXT_SH' => $lang['sys_planet_type_sh'][$fleet['fleet_end_type']], 'END_COORDS' => "[{$fleet['fleet_end_galaxy']}:{$fleet['fleet_end_system']}:{$fleet['fleet_end_planet']}]", 'END_TIME_TEXT' => date(FMT_DATE_TIME, $fleet['fleet_start_time'] + SN_CLIENT_TIME_DIFF), 'END_LEFT' => floor($fleet['fleet_start_time'] + 1 - SN_TIME_NOW), 'END_URL' => uni_render_coordinates_href($fleet, 'fleet_end_', 3), 'END_NAME' => $fleet['fleet_end_name'], 'STAY_TIME' => date(FMT_DATE_TIME, $fleet['fleet_end_stay'] + SN_CLIENT_TIME_DIFF), 'STAY_LEFT' => floor($fleet['fleet_end_stay'] + 1 - SN_TIME_NOW), 'OV_LABEL' => $fleet['ov_label'], 'EVENT_TIME_TEXT' => date(FMT_DATE_TIME, $fleet['event_time'] + SN_CLIENT_TIME_DIFF), 'OV_LEFT' => floor($fleet['event_time'] + 1 - SN_TIME_NOW), 'OV_THIS_PLANET' => $fleet['ov_this_planet']); $ship_list = explode(';', $fleet['fleet_array']); if ($spy_level >= 6) { foreach ($ship_list as $ship_record) { if ($ship_record) { $ship_data = explode(',', $ship_record); if ($spy_level >= 10) { $single_ship_data = get_ship_data($ship_data[0], $user_data); $result['ships'][$ship_data[0]] = array('ID' => $ship_data[0], 'NAME' => $lang['tech'][$ship_data[0]], 'AMOUNT' => $ship_data[1], 'AMOUNT_TEXT' => pretty_number($ship_data[1]), 'CONSUMPTION' => $single_ship_data['consumption'], 'SPEED' => $single_ship_data['speed'], 'CAPACITY' => $single_ship_data['capacity']); } else { $result['ships'][$ship_data[0]] = array('ID' => $ship_id++, 'NAME' => $lang['tech'][UNIT_SHIPS], 'AMOUNT' => $ship_data[1], 'AMOUNT_TEXT' => pretty_number($ship_data[1]), 'CONSUMPTION' => 0, 'SPEED' => 0, 'CAPACITY' => 0); } } } } return $result; }
function CreateFleetPopupedFleetLink($FleetRow, $Texte, $FleetType, $Owner) { global $lang, $user; $spy_tech = GetSpyLevel($user); $admin = $user['authlevel']; $FleetRec = explode(";", $FleetRow['fleet_array']); $FleetPopup = "<span onmouseover=\"popup_show('"; $FleetPopup .= "<table width=200>"; if (!$Owner && $spy_tech < 2) { $FleetPopup .= "<tr><td width=80% align=left><font color=white>" . $lang['ov_spy_failed'] . "<font></td><td width=20% align=right> </td></tr>"; } elseif (!$Owner && $spy_tech < 4) { $FleetPopup .= "<tr><td width=80% align=left><font color=white>" . $lang['ov_total'] . ":<font></td><td width=20% align=right><font color=white>" . pretty_number(count($FleetRec)) . "<font></td></tr>"; } foreach ($FleetRec as $Item => $Group) { if ($Group != '') { $Ship = explode(",", $Group); if (!$Owner && $spy_tech >= 4 && $spy_tech < 8) { $FleetPopup .= "<tr><td width=80% align=left><font color=white>" . $lang['tech'][$Ship[0]] . "<font></td><td width=20% align=right> </td></tr>"; } elseif (!$Owner && $spy_tech >= 8 || $Owner) { $FleetPopup .= "<tr><td width=80% align=left><font color=white>" . $lang['tech'][$Ship[0]] . ":<font></td><td width=20% align=right><font color=white>" . pretty_number($Ship[1]) . "<font></td></tr>"; } } } if (!$Owner && $admin == 3) { $FleetPopup .= "<tr><td width=80% align=left><font color=white>" . $lang['tech'][$Ship[0]] . ":<font></td><td width=20% align=right><font color=white>" . pretty_number($Ship[1]) . "<font></td></tr>"; $FleetPopup .= "<td width=100% align=center><font color=red>Все видящее Админское око :-D<font></td>"; } $FleetPopup .= "</table>"; $FleetPopup .= "');\" onmouseout=\"popup_hide();\" class=\"" . $FleetType . "\">" . $Texte . "</span>"; return $FleetPopup; }
function flt_mission_spy($mission_data) { global $time_now; $fleet_row = $mission_data['fleet']; $target_user_row = $mission_data['dst_user']; $target_planet_row = $mission_data['dst_planet']; $spying_user_row = $mission_data['src_user']; $spying_planet_row = $mission_data['src_planet']; if (!$target_user_row || !$target_planet_row || !is_array($target_user_row) || !is_array($target_planet_row)) { doquery("UPDATE {{fleets}} SET `fleet_mess` = 1 WHERE `fleet_id` = {$fleet_row['fleet_id']} LIMIT 1;"); return; } $fleet_array = sys_unit_str2arr($fleet_row['fleet_array']); if ($fleet_array[SHIP_SPY] > 0) { $TargetSpyLvl = GetSpyLevel($target_user_row); //mrc_modify_value($target_user_row, $target_planet_row, MRC_SPY, GetSpyLevel($target_user_row)); $CurrentSpyLvl = GetSpyLevel($spying_user_row); //mrc_modify_value($spying_user_row, $spying_planet_row, MRC_SPY, GetSpyLevel($spying_user_row)); $spy_probes = $fleet_array[SHIP_SPY]; $spy_diff = $CurrentSpyLvl + sqrt($spy_probes) - 1 - $TargetSpyLvl; /* pdump($spy_probes, '$spy_probes'); pdump($CurrentSpyLvl, '$CurrentSpyLvl'); pdump($TargetSpyLvl, '$TargetSpyLvl'); pdump(sqrt($spy_probes), 'sqrt($spy_probes)'); pdump($spy_diff, '$spy_diff'); */ global $lang, $sn_data; $spy_resources = flt_spy_scan($target_planet_row, 0, $lang['sys_spy_maretials'], $target_user_row['username']); $spy_info = flt_spy_scan($target_planet_row, 1, $lang['sys_spy_fleet']); $spy_fleet = "<div class='spy_medium'>{$spy_info}</div>"; $spy_info = flt_spy_scan($target_planet_row, 2, $lang['sys_spy_defenses']); $spy_defence = "<div class='spy_medium'>{$spy_info}</div>"; $spy_info = flt_spy_scan($target_planet_row, 3, $lang['tech'][0]); $spy_buildings = "<div class='spy_long'>{$spy_info}</div>"; $combat_pack[0] = array(RES_METAL => $target_planet_row['metal'], RES_CRYSTAL => $target_planet_row['crystal'], RES_DEUTERIUM => $target_planet_row['deuterium']); $spy_message = $spy_resources; if ($spy_diff >= 2) { $spy_message .= $spy_fleet; coe_compress_add_units($sn_data['groups']['fleet'], $target_planet_row, $combat_pack[0]); } if ($spy_diff >= 3) { $spy_message .= $spy_defence; coe_compress_add_units($sn_data['groups']['defense_active'], $target_planet_row, $combat_pack[0]); } if ($spy_diff >= 5) { $spy_message .= $spy_buildings; } if ($spy_diff >= 7) { $spy_info = flt_spy_scan($target_user_row, 4, $lang['tech'][TECH_TECHNOLOGY]); $spy_tech = "<div class='spy_long'>{$spy_info}</div>"; $spy_message .= $spy_tech; coe_compress_add_units(array(TECH_WEAPON, TECH_SHIELD, TECH_ARMOR), $target_user_row, $combat_pack[0]); } $simulator_link = eco_sym_encode_replay($combat_pack, 'D'); $target_unit_list = 0; foreach ($sn_data['groups']['fleet'] as $unit_id) { $target_unit_list += max(0, $target_planet_row[$sn_data[$unit_id]['name']]); } $spy_detected = $spy_probes * $target_unit_list / 4 * pow(2, $TargetSpyLvl - $CurrentSpyLvl); if (mt_rand(0, 99) > $spy_detected) { $DestProba = sprintf($lang['sys_mess_spy_detect_chance'], $spy_detected); $spy_detected = false; } else { $DestProba = $lang['sys_mess_spy_destroyed']; $spy_detected = true; } $spy_message .= "<br /><center><a href=\"fleet.php?target_mission=1&planet_type={$fleet_row['fleet_end_type']}&galaxy={$fleet_row['fleet_end_galaxy']}"; $spy_message .= "&system={$fleet_row['fleet_end_system']}&planet={$fleet_row['fleet_end_planet']} \">{$lang['type_mission'][1]}</a></center>"; $spy_message .= "<center><a href=\"simulator.php?replay={$simulator_link}\">{$lang['COE_combatSimulator']}</a></center><br />"; $spy_message .= "<center>" . $DestProba . "</center>"; // End of link generation msg_send_simple_message($spying_user_row['id'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_mess_qg'], $lang['sys_mess_spy_report'], $spy_message); $TargetMessage = $lang['sys_mess_spy_ennemyfleet'] . " " . $spying_planet_row['name']; $TargetMessage .= "<a href=\"galaxy.php?mode=3&galaxy=" . $spying_planet_row["galaxy"] . "&system=" . $spying_planet_row["system"] . "\">"; $TargetMessage .= "[" . $spying_planet_row["galaxy"] . ":" . $spying_planet_row["system"] . ":" . $spying_planet_row["planet"] . "]</a> "; $TargetMessage .= $lang['sys_mess_spy_seen_at'] . " " . $target_planet_row['name']; $TargetMessage .= " [" . $target_planet_row["galaxy"] . ":" . $target_planet_row["system"] . ":" . $target_planet_row["planet"] . "]."; $target_user_id = $fleet_row['fleet_target_owner']; if ($spy_detected) { doquery("DELETE FROM {{fleets}} WHERE `fleet_id` = '{$fleet_row['fleet_id']}' LIMIT 1;"); if ($target_planet_row['planet_type'] == PT_PLANET) { $debris_planet_id = $target_planet_row['id']; } else { $debris_planet_id = $target_planet_row['parent_planet']; } $QryUpdateGalaxy = "UPDATE {{planets}} SET "; $QryUpdateGalaxy .= "`debris_metal` = `debris_metal` + '" . floor($spy_probes * $sn_data[SHIP_SPY]['metal'] * 0.3) . "', "; $QryUpdateGalaxy .= "`debris_crystal` = `debris_crystal` + '" . floor($spy_probes * $sn_data[SHIP_SPY]['crystal'] * 0.3) . "' "; $QryUpdateGalaxy .= "WHERE `id` = '{$debris_planet_id}' LIMIT 1;"; doquery($QryUpdateGalaxy); $TargetMessage .= "<br />{$lang['sys_mess_spy_destroyed_enemy']}"; // msg_send_simple_message ( $target_user_id, '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_mess_spy_control'], $lang['sys_mess_spy_activity'], $TargetMessage . ); $result = CACHE_FLEET | CACHE_PLANET_DST; } else { $result = CACHE_FLEET; } msg_send_simple_message($target_user_id, '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_mess_spy_control'], $lang['sys_mess_spy_activity'], $TargetMessage); } if (!$spy_detected) { doquery("UPDATE {{fleets}} SET `fleet_mess` = '1' WHERE `fleet_id` = '{$fleet_row['fleet_id']}' LIMIT 1;"); } return $result; }
function flt_mission_spy(&$mission_data) { global $lang; $fleet_row =& $mission_data['fleet']; $target_user_row =& $mission_data['dst_user']; $target_planet_row =& $mission_data['dst_planet']; $spying_user_row =& $mission_data['src_user']; $spying_planet_row =& $mission_data['src_planet']; if (!isset($target_user_row['id']) || !isset($target_planet_row['id']) || !isset($spying_user_row['id'])) { doquery("UPDATE {{fleets}} SET `fleet_mess` = 1 WHERE `fleet_id` = {$fleet_row['fleet_id']} LIMIT 1;"); return; } $fleet_array = sys_unit_str2arr($fleet_row['fleet_array']); if ($fleet_array[SHIP_SPY] > 0) { $TargetSpyLvl = GetSpyLevel($target_user_row); $CurrentSpyLvl = GetSpyLevel($spying_user_row); $spy_diff_empire = $CurrentSpyLvl - $TargetSpyLvl; $spy_probes = $fleet_array[SHIP_SPY]; $spy_diff = $spy_diff_empire + sqrt($spy_probes) - 1; $combat_pack[0] = array(RES_METAL => $target_planet_row['metal'], RES_CRYSTAL => $target_planet_row['crystal'], RES_DEUTERIUM => $target_planet_row['deuterium']); $spy_message = "<table width=\"440\" cellspacing = \"1\"><tr><td class=\"c\" colspan=\"4\">{$lang['sys_spy_maretials']} {$target_planet_row['name']} "; $spy_message .= uni_render_coordinates_href($target_planet_row, '', 3); $spy_message .= " ({$lang['Player_']} '{$target_user_row['username']}') {$lang['On_']} "; $spy_message .= date(FMT_DATE_TIME, $fleet_row['fleet_end_time']); $spy_message .= "</td></tr><tr>"; $spy_message .= "<td width=220>{$lang['sys_metal']}</td><td width=220 align=right>" . pretty_number($target_planet_row['metal']) . "</td>"; $spy_message .= "<td width=220>{$lang['sys_crystal']}</td></td><td width=220 align=right>" . pretty_number($target_planet_row['crystal']) . "</td>"; $spy_message .= "</tr><tr>"; $spy_message .= "<td width=220>{$lang['sys_deuterium']}</td><td width=220 align=right>" . pretty_number($target_planet_row['deuterium']) . "</td>"; $spy_message .= "<td width=220>{$lang['sys_energy']}</td><td width=220 align=right>" . pretty_number($target_planet_row['energy_max']) . "</td>"; $spy_message .= "</tr>"; if ($spy_diff >= 2) { $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'fleet', $lang['tech'][UNIT_SHIPS], $target_user_row) . "</div>"; coe_compress_add_units(sn_get_groups('fleet'), $target_planet_row, $combat_pack[0]); } if ($spy_diff >= 3) { $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'defense', $lang['tech'][UNIT_DEFENCE], $target_user_row) . "</div>"; coe_compress_add_units(sn_get_groups('defense_active'), $target_planet_row, $combat_pack[0]); } if ($spy_diff >= 5) { $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'structures', $lang['tech'][UNIT_STRUCTURES], $target_user_row) . "</div>"; } if ($spy_diff_empire >= 0) { $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'tech', $lang['tech'][UNIT_TECHNOLOGIES], $target_user_row) . "</div>"; coe_compress_add_units(array(TECH_WEAPON, TECH_SHIELD, TECH_ARMOR), $target_planet_row, $combat_pack[0], $target_user_row); } // TODO: Наемники, губернаторы, артефакты и прочее имперское $simulator_link = sn_ube_simulator_encode_replay($combat_pack, 'D'); $target_unit_list = 0; foreach (sn_get_groups('fleet') as $unit_id) { $target_unit_list += max(0, mrc_get_level($target_user_row, $target_planet_row, $unit_id, false, true)); } $spy_detected = $spy_probes * $target_unit_list / 4 * pow(2, $TargetSpyLvl - $CurrentSpyLvl); if (mt_rand(0, 99) > $spy_detected) { $spy_outcome_str = sprintf($lang['sys_mess_spy_detect_chance'], $spy_detected); $spy_detected = false; } else { $spy_outcome_str = $lang['sys_mess_spy_destroyed']; $spy_detected = true; } $spy_message .= "<tr><th class=\"c_c\" colspan=4>"; $spy_message .= "{$spy_outcome_str}<br />"; $spy_message .= "<a href=\"fleet.php?target_mission=1&planet_type={$fleet_row['fleet_end_type']}&galaxy={$fleet_row['fleet_end_galaxy']}&system={$fleet_row['fleet_end_system']}&planet={$fleet_row['fleet_end_planet']} \">{$lang['type_mission'][1]}</a><br />"; $spy_message .= "<a href=\"simulator.php?replay={$simulator_link}\">{$lang['COE_combatSimulator']}</a><br />"; $spy_message .= "</th></tr></table>"; // End of link generation msg_send_simple_message($spying_user_row['id'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_mess_qg'], $lang['sys_mess_spy_report'], $spy_message); $target_message = "{$lang['sys_mess_spy_ennemyfleet']} {$spying_planet_row['name']} " . uni_render_coordinates_href($spying_planet_row, '', 3); $target_message .= " {$lang['sys_mess_spy_seen_at']} {$target_planet_row['name']} " . uni_render_coordinates($target_planet_row); $target_user_id = $fleet_row['fleet_target_owner']; if ($spy_detected) { doquery("DELETE FROM {{fleets}} WHERE `fleet_id` = '{$fleet_row['fleet_id']}' LIMIT 1;"); $debris_planet_id = $target_planet_row['planet_type'] == PT_PLANET ? $target_planet_row['id'] : $target_planet_row['parent_planet']; $spy_cost = get_unit_param(SHIP_SPY, P_COST); db_planet_set_by_id($debris_planet_id, "`debris_metal` = `debris_metal` + " . floor($spy_probes * $spy_cost[RES_METAL] * 0.3) . ", `debris_crystal` = `debris_crystal` + " . floor($spy_probes * $spy_cost[RES_CRYSTAL] * 0.3)); $target_message .= "<br />{$lang['sys_mess_spy_destroyed_enemy']}"; $result = CACHE_FLEET | CACHE_PLANET_DST; } else { $result = CACHE_FLEET; } msg_send_simple_message($target_user_id, '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_mess_spy_control'], $lang['sys_mess_spy_activity'], $target_message); } if (!$spy_detected) { doquery("UPDATE {{fleets}} SET `fleet_mess` = '1' WHERE `fleet_id` = '{$fleet_row['fleet_id']}' LIMIT 1;"); } return $result; }