function show_owned_convoys($user_id) { assert(is_numeric($user_id)); echo "<table border=1 align=center>"; echo " <tr>"; echo " <th>Convoy Name</th>"; echo " <th>Flag Ship</th>"; echo " <th>Ships</th>"; echo " <th>Status</th>"; echo " </tr>"; $result = sql_query("SELECT c.* FROM s_convoys c, s_vessels v WHERE c.vessel_id=v.id AND v.user_id=" . $user_id); while ($convoy = sql_fetchrow($result)) { // Get the flag ship of the convoy $vesseltype = vessel_get_vessel_type($convoy['id']); // Count the number of ships $result2 = sql_query("SELECT c.* FROM s_convoys c, s_vessels v WHERE c.vessel_id=v.id AND v.user_id=" . $user_id); $tmp = csl_create_array($result2, "vessel_ids"); $shipcount = count($tmp); // Get the status of the convoy $status = $convoy['status']; echo "<tr>"; echo "<td> " . $convoy['name'] . " </td>"; echo "<td> " . $vesseltype['name'] . " </td>"; echo "<td> " . $shipcount . " </td>"; echo "<td> " . $status . " </td>"; echo "</tr>"; } echo "</table>"; }
function conview_show_all_sectors($user_id) { assert(is_numeric($user_id)); // Get all sectors that we can see $result = sql_query("SELECT * FROM g_sectors WHERE user_id=" . $user_id); $sectors = csl_create_array($result, "csl_sector_id"); $user = user_get_user($user_id); $tmp = user_get_all_anomalies_from_user($user_id); $anomalies = csl($tmp['csl_discovered_id']); foreach ($sectors as $sector_id) { conview_show_sector($user_id, $sector_id, $anomalies); exit; } }
function upgrade_speed($_USER, $vessel_id) { // Get global information $user = user_get_user($_USER['id']); $result = sql_query("SELECT * FROM g_flags WHERE user_id=" . $_USER['id']); $flags = sql_fetchrow($result); $vessel = vessel_get_vessel($vessel_id); // Show Ship and User Capabilities echo "<table align=center border=1>"; echo "<tr><td>"; echo "<table width=100% border=0 cellpadding=0 cellspacing=0>"; echo "<tr><th colspan=2>Current Ship Capabilities</th></tr>"; echo "<tr><td>Impulse Speed: </td><td>" . $vessel['impulse'] . "%</td></tr>"; echo "<tr><td>Warp Speed: </td><td>" . number_format($vessel['warp'] / 10, 1) . "</td></tr>"; echo "<tr><td> </td><td> </td></tr>"; echo "</table>"; echo "</td><td>"; echo "<table width=100% border=0 cellpadding=0 cellspacing=0>"; echo "<tr><th colspan=2>User Statistics</th></tr>"; echo "<tr><td>Credits:</td><td>" . $user['credits'] . "</td></tr>"; echo "<tr><td> </td><td> </td></tr>"; echo "<tr><td> </td><td> </td></tr>"; echo "</table>"; echo "</td></tr>"; echo "</table>"; echo "<br>"; echo "<br>"; if ($vessel['impulse'] == $user['impulse'] and $vessel['warp'] == $user['warp']) { echo " <table align=center>"; echo " <tr><td>Ship Name: </td><td>" . $vessel['name'] . "</td></tr>"; echo " <tr><td> </td><td>No upgrade Possible</td></tr>"; echo " </table>"; } // Stage 1: Create Ship and ship name if (!isset($stage) || $stage == 1) { form_start(); echo "<input type=hidden name=vid value={$vid}>"; echo " <table align=center>"; echo " <tr><td>Ship Name: </td><td>" . $vessel['name'] . "</td></tr>"; echo " <tr><td colspan=2></td></tr>"; echo " <tr><td>Impulse speed: </td><td>"; if ($flags['can_warp'] == 1) { echo "<input type=hidden name=impulse value=100>100 % (" . $config['s_impulse_costs'] * 100 . " Credits)"; } else { echo " <select name='impulse'>"; for ($i = $vessel['impulse'] + 1; $i != $user['impulse'] + 1; $i++) { echo "<option value=" . $i . ">" . $i . " % (" . ($i - $vessel['impulse']) * $config['s_impulse_costs'] . " Credits)</option>"; } echo " </select>"; } echo " </td></tr>"; echo " <tr><td>Warp Speed: </td><td>"; if ($flags['can_warp'] == 1) { echo " <select name=warp>"; for ($i = $vessel['warp'] + 1; $i != $user['warp'] + 1; $i++) { echo "<option value=" . $i . "> Warp " . number_format($i / 10, 1) . " (" . ($i - $vessel['warp']) * $config['s_warp_costs'] . " Credits)</option>"; } echo " </select>"; } else { echo "<input type=hidden name=warp value=0>"; echo "None"; } echo " </td></tr>"; echo " <tr><td> </td><td><input type=submit name=submit value=\"Upgrade Ship\"></td></tr>"; echo " </table>"; form_end(); } // Stage 2: Add or Delete weaponary if ($stage == 2 and ($vessel['type'] == VESSEL_TYPE_TRADE or $vessel['type'] == VESSEL_TYPE_EXPLORE)) { $stage = 3; } if ($stage == 2) { // Get all weapons we can view $visible_weapons = array(); $result = sql_query("SELECT * FROM g_weapons WHERE user_id=" . $_USER['id']); $visible_weapons = csl_create_array($result, "csl_weapon_id"); // And dump them into the table echo "<table border=1 align=center>"; echo "<tr><th colspan=8>Weaponary</th></tr>"; echo "<tr>"; echo "<th>Name</th>"; echo "<th>Costs</th>"; echo "<th>Power</th>"; echo "<th>Attack</th>"; echo "<th>Defense</th>"; echo "<th>Qty</th>"; echo "<th colspan=2>Action</th>"; echo "</tr>"; reset($visible_weapons); while (list($key, $weapon_id) = each($visible_weapons)) { $result = sql_query("SELECT * FROM s_weapons WHERE id=" . $weapon_id); $weapon = sql_fetchrow($result); echo "<tr>"; echo "<td>" . $weapon['name'] . "</td>"; echo "<td>" . $weapon['costs'] . "</td>"; echo "<td>" . $weapon['power'] . "</td>"; echo "<td>" . $weapon['attack'] . "</td>"; echo "<td>" . $weapon['defense'] . "</td>"; echo "<td><input type=text size=3 maxlength=3 value=0 name=T1></td>"; echo "<td><b>Add</b></td>"; echo "<td><b>Delete</b></td>"; echo "</tr>"; } echo "</table>"; echo "<br><br>"; } if ($stage == 3) { $ok = "Vessel upgrade in process..\n"; $errors['PARAMS'] = "Incorrect parameters specified...\n"; $errors['SPEED'] = "Incorrect speed settings...\n"; $errors['CREDITS'] = "Not enough credits...\n"; $data['impulse'] = $_POST['impulse']; $data['warp'] = $_POST['warp']; $data['vid'] = decrypt_get_vars($_POST['vid']); comm_send_to_server("VESSELUPGRADE", $data, $ok, $errors); } }
function show_participated_convoys($_USER) { echo "<table border=1 align=center>"; echo " <tr><th colspan=5>All participated convoys</th></tr>"; echo " <tr>"; echo " <th>Vessel Name</th>"; echo " <th>Convoy Name</th>"; echo " <th>Flag Ship</th>"; echo " <th>Ships</th>"; echo " <th>Status</th>"; echo " </tr>"; $result = sql_query("SELECT * FROM g_vessels WHERE user_id=" . $_USER['id']); while ($vessel = sql_fetchrow($result)) { if ($vessel['convoy_id'] == 0) { continue; } $result2 = sql_query("SELECT * FROM s_convoys WHERE id=" . $vessel['convoy_id']); $convoy = sql_fetchrow($result2); // Get the flag ship of the convoy $flagvessel = vessel_get_vessel($convoy['vessel_id']); // Count the number of ships $result2 = sql_query("SELECT c.* FROM s_convoys c, g_vessels v WHERE c.vessel_id=v.id AND v.user_id=" . $_USER['id']); $tmp = csl_create_array($result2, "csl_vessel_id"); $shipcount = count($tmp); // Get the status of the convoy $status = $convoy['status']; echo "<tr>"; echo "<td> " . $vessel['name'] . " </td>"; echo "<td> " . $convoy['name'] . " </td>"; echo "<td> " . $flagvessel['name'] . " </td>"; echo "<td> " . $shipcount . " </td>"; echo "<td> " . $status . " </td>"; echo "</tr>"; } echo "</table>"; }
function vessel_show_cargo($vessel_id) { assert(is_numeric($vessel_id)); global $_GALAXY; $vessel = vessel_get_vessel($vessel_id); // Get all buildings that are currently build on the planet $result = sql_query("SELECT * FROM i_vessels WHERE vessel_id=" . $vessel_id); $vessel_cargo = csl_create_array($result, "csl_cargo_id"); $vessel_cargo = array_count_values($vessel_cargo); // Find out if we just travelled through a wormhole, or if we are nearby a wormhole. $located_in_wormhole = false; $result = sql_query("SELECT * FROM w_wormhole"); while ($wormhole = sql_fetchrow($result)) { if ($vessel['distance'] == $wormhole['distance'] and $vessel['angle'] == $wormhole['angle']) { $located_in_wormhole = true; } } // Do not show the array when it's empty... if (count($vessel_cargo) == 0) { // echo "<table align=center border=0 width=75%>"; // echo "<tr class=wb><th colspan=2>No items on board</th></tr>"; // echo "</table>"; // echo "<br><br>"; } else { echo "<table align=center border=0 width=75%>"; echo "<tr class=wb><th colspan=3>Vessel Items</th></tr>"; echo "<tr class=bl>"; echo "<th>Quantity</th>"; echo "<th width=100%>Name</th>"; echo "<th> </th>"; echo "</tr>"; reset($vessel_cargo); while (list($cargo_id, $q) = each($vessel_cargo)) { $invention = item_get_item($cargo_id); if (invention_is_active_on_vessel($invention, $vessel)) { $activeimg = "alt=Active src=" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/general/active.gif"; } else { $activeimg = "alt=Inactive src=" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/general/inactive.gif"; } echo "<tr class=bl>"; echo " <td> " . $q . " </td>"; echo " <td> <img " . $activeimg . "> " . $invention['name'] . " </td>"; if ($vessel['planet_id'] == 0) { echo " <td nowrap> </td>"; } else { echo " <td nowrap> <a href=vessel.php?cmd=" . encrypt_get_vars("load_v2p") . "&vid=" . encrypt_get_vars($vessel['id']) . "&aid=" . encrypt_get_vars($vessel['planet_id']) . "&iid=" . encrypt_get_vars($invention['id']) . ">Move to planet</a> </td>"; } echo "</tr>"; } echo "</table>"; echo "<br><br>"; } // Only show planet cargo when there we are orbitting a planet. if ($vessel['planet_id'] == 0) { return; } // Get all buildings that are currently build on the planet $surface = planet_get_surface($vessel['planet_id']); $planet_cargo = csl($surface['csl_cargo_id']); $planet_cargo = array_count_values($planet_cargo); // Do not show the array when it's empty... if (count($planet_cargo) == 0) { // echo "<table align=center border=0 width=75%>\n"; // echo " <tr class=wb><th colspan=3>No items on planet</th></tr>\n"; // echo "</table>\n"; // echo "<br><br>\n"; } else { form_start(); echo "<table align=center border=0 width=75%>\n"; echo " <tr class=wb><th colspan=3>Planet Items</th></tr>\n"; echo " <tr class=bl>"; echo "<th>Qty</th>"; echo "<th width=100%>Name</th>"; echo "<th> </th>"; echo "</tr>\n"; reset($planet_cargo); while (list($cargo_id, $q) = each($planet_cargo)) { $invention = item_get_item($cargo_id); if (invention_is_active_on_planet($invention)) { $activeimg = "alt=Active src=" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/general/active.gif"; } else { $activeimg = "alt=Inactive src=" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/general/inactive.gif"; } echo " <tr class=bl>\n"; echo " <td> " . $q . " </td>\n"; echo " <td> <img " . $activeimg . "> " . $invention['name'] . " </td>\n"; echo " <td nowrap> <a href=vessel.php?cmd=" . encrypt_get_vars("load_p2v") . "&vid=" . encrypt_get_vars($vessel['id']) . "&aid=" . encrypt_get_vars($vessel['planet_id']) . "&iid=" . encrypt_get_vars($invention['id']) . ">Move to vessel</a> </td>\n"; echo " </tr>\n"; } echo "</table>\n"; form_end(); echo "<br><br>\n"; } }
function vessel_calc_extra_attack_and_defense_points($vessel_id) { assert(is_numeric($vessel_id)); $result = sql_query("SELECT * FROM i_vessels WHERE vessel_id=" . $vessel_id); $current_items = csl_create_array($result, "csl_weapon_id"); $current_items = array_count_values($current_items); $total_attack = 0; $total_defense = 0; reset($current_items); while (list($item_id, $quantity) = each($current_items)) { $invention = item_get_item($item_id); $total_attack += $invention['attack'] * $quantity; $total_defense += $invention['defense'] * $quantity; } return array(floor($total_attack / 100), floor($total_defense / 100)); }
function trade_create_route($user_id) { assert(is_numeric($user_id)); $found_at_least_one_ship = false; $result = sql_query("SELECT g.* FROM g_vessels AS g, s_vessels AS s WHERE g.user_id={$user_id} AND s.id = g.vessel_id AND s.type='" . VESSEL_TYPE_TRADE . "'"); while ($vessel = sql_fetchrow($result)) { if (!vessel_in_traderoute($vessel['id'])) { $found_at_least_one_ship = true; } } if ($found_at_least_one_ship == false) { print_line("You do not have any tradeships currently available for setting up a traderoute"); return; } print_remark("Create form"); form_start(); echo " <input type=hidden name=cmd value=" . encrypt_get_vars("create2") . ">\n"; echo " <table align=center>\n"; echo " <tr>\n"; echo " <td> Vessel: </td>\n"; echo " <td>\n"; echo " <select name=vid>\n"; $result = sql_query("SELECT g.* FROM g_vessels AS g, s_vessels AS s WHERE g.user_id={$user_id} AND s.id = g.vessel_id AND s.type='" . VESSEL_TYPE_TRADE . "'"); while ($vessel = sql_fetchrow($result)) { if (!trade_is_vessel_in_route($vessel['id'])) { echo " <option value=" . encrypt_get_vars($vessel['id']) . ">" . $vessel['name'] . "</option>\n"; } } echo " </select>\n"; echo " </td>\n"; echo " </tr>\n"; echo " <tr><td> </td></tr>\n"; echo " <tr>\n"; echo " <td> Source Planet: </td>\n"; echo " <td>\n"; echo " <select name=src_pid>\n"; $result = sql_query("SELECT a.*,s.name AS sectorname FROM s_anomalies AS a, s_sectors AS s WHERE a.user_id={$user_id} AND a.type='P' AND a.sector_id = s.id"); while ($planet = sql_fetchrow($result)) { if (anomaly_is_planet($planet['id']) and planet_is_minable($planet['id'])) { echo " <option value=" . encrypt_get_vars($planet['id']) . ">" . $planet['sectorname'] . " / " . $planet['name'] . "</option>\n"; } } echo " </select>\n"; echo " </td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td> Ores: </td>\n"; echo " <td>"; echo " <table border=0 cellspacing=0 colspacing=0>\n"; echo " <tr>"; for ($i = 0; $i != ore_get_ore_count(); $i++) { if ($i % 3 == 0) { echo " </tr>\n"; echo " <tr>\n"; } echo " <td><input type=checkbox name=src_ore_" . $i . ">" . ore_get_ore_name($i) . "</td>\n"; } echo " </tr>\n"; echo " </table>\n"; echo " </td>\n"; echo " </tr>\n"; echo " <tr><td colspan=2> </td></tr>\n"; echo " <tr>\n"; echo " <td> Destination Planet: </td>\n"; echo " <td>\n"; echo " <select name=dst_pid>\n"; $result = sql_query("SELECT * FROM g_anomalies WHERE user_id={$user_id}"); $planetlist = csl_create_array($result, 'csl_discovered_id'); // Get all planets which we own... foreach ($planetlist as $planet_id) { $planet = anomaly_get_anomaly($planet_id); if ($planet['user_id'] == 0) { continue; } if ($planet['user_id'] != $user_id) { continue; } if (user_is_mutual_friend($user_id, $planet['user_id']) and anomaly_is_planet($planet['id']) and planet_is_minable($planet['id'])) { $sector = sector_get_sector($planet['sector_id']); echo " <option value=" . encrypt_get_vars($planet['id']) . ">" . $sector['name'] . " / " . $planet['name'] . "</option>\n"; } } // And now, all other planets with a different user_id foreach ($planetlist as $planet_id) { $planet = anomaly_get_anomaly($planet_id); if ($planet['user_id'] == 0) { continue; } if ($planet['user_id'] == $user_id) { continue; } if (user_is_mutual_friend($user_id, $planet['user_id']) and anomaly_is_planet($planet['id']) and planet_is_minable($planet)) { $sector = sector_get_sector($planet['sector_id']); $race = user_get_race($planet['user_id']); echo " <option value=" . encrypt_get_vars($planet['id']) . ">(" . $race . ") " . $sector['name'] . " / " . $planet['name'] . "</option>\n"; } } echo " </select>\n"; echo " </td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td> Ores: </td>\n"; echo " <td>\n"; echo " <table border=0 cellspacing=0 colspacing=0>\n"; echo " <tr>\n"; for ($i = 0; $i != ore_get_ore_count(); $i++) { if ($i % 3 == 0) { echo " </tr>\n"; echo " <tr>\n"; } echo " <td><input type=checkbox name=dst_ore_" . $i . ">" . ore_get_ore_name($i) . "</td>\n"; } echo " </tr>\n"; echo " </table>\n"; echo " </td>\n"; echo " </tr>\n"; echo " <tr><td colspan=2> </td></tr>\n"; echo " <tr><td></td><td><input type=submit name=submit value='create traderoute'></td></tr>\n"; echo " </table>\n"; form_end(); }
function planet_has_vesselbuilding_capability($planet_id) { assert(is_numeric($planet_id)); $result = sql_query("SELECT * FROM g_surface WHERE planet_id=" . $planet_id); $buildings = csl_create_array($result, "csl_building_id"); reset($buildings); while (list($key, $building_id) = each($buildings)) { if (!building_is_active($building_id)) { continue; } if ($building_id == BUILDING_SPACEDOCK or $building_id == BUILDING_VESSEL_STATION) { return true; } } return false; }
function show_sector($vessel_id, $unknowns_too) { assert(is_numeric($vessel_id)); assert(is_string($unknowns_too)); // Get sector information $vessel = vessel_get_vessel($vessel_id); $user = user_get_user($vessel['user_id']); $sector = sector_get_sector($vessel['sector_id']); $result = sql_query("SELECT * FROM g_anomalies WHERE user_id=" . $vessel['user_id']); $anomalies = csl_create_array($result, "csl_discovered_id"); if ($unknowns_too == "Y") { $undiscovered_anomalies = csl_create_array($result, "csl_undiscovered_id"); $anomalies = csl_merge_fields($anomalies, $undiscovered_anomalies); } else { $undiscovered_anomalies = ""; } // Get planet information for all planets in the sector $result = sql_query("SELECT * FROM s_anomalies WHERE sector_id=" . $sector['id'] . " ORDER BY distance"); while ($anomaly = sql_fetchrow($result)) { // If we can't view the planet, then don't show it... if (!in_array($anomaly['id'], $anomalies)) { continue; } $ticks = calc_planet_ticks($anomaly['distance'], $sector['angle'], $vessel['sun_distance'], $vessel['angle'], $vessel['impulse'], $vessel['warp']); // Check if ticks = 0 and the id of the planet is not the same as the // id of the planet we're curently orbitting... // If that's the case, the planet is really nearby, and we give it at // least 1 tick... if ($ticks == 0 && $anomaly['id'] != $vessel['planet_id']) { $ticks = 1; } // Don't show planet if it's 0 tick away (which means: it's our orbit) if ($ticks == 0) { continue; } // Thread undiscovered planets different... if (in_array($planet['id'], $undiscovered_anomalies)) { echo "<option value=" . encrypt_get_vars($anomaly['id']) . ">" . $sector['name'] . " / Unknown ({$ticks} ticks)</option>"; } else { echo "<option value=" . encrypt_get_vars($anomaly['id']) . ">" . $sector['name'] . " / " . $anomaly['name'] . " ({$ticks} ticks)</option>"; } } }