function vessel_get_current_status($vessel_id, $create_hyperlink = true) { assert(is_numeric($vessel_id)); assert(is_bool($create_hyperlink)); $vessel = vessel_get_vessel($vessel_id); $status = "Unknown status"; // Are we in orbit? if (vessel_is_in_orbit($vessel_id)) { $anomaly = anomaly_get_anomaly($vessel['planet_id']); if (anomaly_is_planet($anomaly['id'])) { if ($create_hyperlink) { $status = "Orbiting planet <a href=anomaly.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($anomaly['id']) . ">" . $anomaly['name'] . "</a>"; } else { $status = "Orbiting planet " . $anomaly['name']; } } if (anomaly_is_nebula($anomaly['id'])) { if ($create_hyperlink) { $status = "Hiding in nebula <a href=anomaly.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($anomaly['id']) . ">" . $anomaly['name'] . "</a>"; } else { $status = "Hiding in nebula " . $anomaly['name']; } } if (anomaly_is_starbase($anomaly['id'])) { if ($create_hyperlink) { $status = "Docking at starbase <a href=anomaly.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($anomaly['id']) . ">" . $anomaly['name'] . "</a>"; } else { $status = "Docking at starbase " . $anomaly['name']; } } } // Is the vessel flying? if (vessel_is_flying($vessel_id)) { if ($vessel['dst_planet_id'] == 0) { // Are we flying to a sector or deep space? if ($vessel['dst_sector_id'] == 0) { $status = "Flying to " . $vessel['dst_distance'] . " / " . $vessel['dst_angle']; } else { $tmp = sector_get_sector($vessel['dst_sector_id']); if ($create_hyperlink) { $status = "Flying to sector <a href=sector.php?id=" . encrypt_get_vars($tmp['id']) . ">" . $tmp['name'] . "</a>"; } else { $status = "Flying to sector " . $tmp['name']; } } } else { // Are we flying to a planet? $tmp_anomaly = anomaly_get_anomaly($vessel['dst_planet_id']); if (anomaly_is_planet($tmp_anomaly['id'])) { if (anomaly_is_discovered_by_user($tmp_anomaly['id'], user_ourself())) { if ($create_hyperlink) { $status = "Flying to planet <a href=anomaly.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($tmp_anomaly['id']) . ">" . $tmp_anomaly['name'] . "</a>"; } else { $status = "Flying to planet " . $tmp_anomaly['name']; } } else { $status = "Flying to an unknown anomaly."; } } if (anomaly_is_starbase($tmp_anomaly['id'])) { $status = "Flying to starbase " . $tmp_anomaly['name']; } if (anomaly_is_nebula($tmp_anomaly['id'])) { $status = "Flying to nebula " . $tmp_anomaly['name']; } if (anomaly_is_wormhole($tmp_anomaly['id'])) { $status = "Flying to wormhole " . $tmp_anomaly['name']; } } } // Are we halted in deep space? if (vessel_is_in_space($vessel_id) and $vessel['sector_id'] == 0) { $status = "Located in deep space (" . $vessel['distance'] . " / " . $vessel['angle'] . ")"; } // Or are we bordering a sector? if (vessel_is_in_space($vessel_id) and $vessel['sector_id'] != 0) { $sector = sector_get_sector($vessel['sector_id']); $status = "Bordering sector " . $sector['name']; } if (vessel_in_traderoute($vessel_id)) { $status = "Part of traderoute."; } // TODO: change this into vessel_is_in_convoy ($vessel_id) if ($vessel['status'] == "CONVOY") { $result = sql_query("SELECT * FROM s_convoys WHERE id=" . $vessel['convoy_id']); $tmp = sql_fetchrow($result); if ($create_hyperlink) { $status = "Part of convoy <a href=convoy.php?id=" . encrypt_get_vars($tmp['id']) . ">" . $tmp['name'] . "</a>"; } else { $status = "Part of convoy " . $tmp['name']; } } return $status; }
function vessel_show_trade_details($vessel_id) { assert(is_numeric($vessel_id)); $vessel = vessel_get_vessel($vessel_id); // Default action is not to show anything from a planet, // since we can be in flight for ($i = 0; $i != ore_get_ore_count(); $i++) { $planet_stock_ores[$i] = '?'; } $status = vessel_get_current_status($vessel_id); if (vessel_is_in_orbit($vessel_id)) { $result = sql_query("SELECT * FROM g_ores WHERE planet_id=" . $vessel['planet_id']); $tmp = sql_fetchrow($result); $planet_stock_ores = ore_csl_to_list($tmp['stock_ores']); } $result = sql_query("SELECT * FROM i_vessels WHERE vessel_id=" . $vessel['id']); $tmp = sql_fetchrow($result); $vessel_stock_ores = ore_csl_to_list($tmp['ores']); echo "<table border=0 width=75% align=center>\n"; echo " <tr class=wb><th colspan=2>Trade vessel: " . $vessel['name'] . "</th></tr>\n"; echo " <tr><td>\n"; echo " <table border=0 width=100% cellpading=0 cellspacing=0>\n"; echo " <tr class=bl><th colspan=2>Ores on planet:</th></tr>\n"; for ($i = 0; $i != ore_get_ore_count(); $i++) { echo " <tr class=bl><td>" . ore_get_ore_name($i) . "</td> <td>" . $planet_stock_ores[$i] . "</td></tr>\n"; } echo " </table>\n"; echo " </td><td>\n"; echo " <table border=0 width=100% cellpading=0 cellspacing=0>\n"; echo " <tr class=bl><th colspan=2>Ores on trader:</th></tr>\n"; for ($i = 0; $i != ore_get_ore_count(); $i++) { echo " <tr class=bl><td>" . ore_get_ore_name($i) . "</td> <td>" . $vessel_stock_ores[$i] . "</td></tr>\n"; } echo " </table>\n"; echo " </td></tr>\n"; // Don't load/unload when we are in a trade route if (vessel_in_traderoute($vessel_id)) { echo " <tr class=wb><th colspan=2>Cannot load/unload because vessel is part of a trade route.</th></tr>"; } // TODO: Don't load/unload when it's not our planet :) if (vessel_is_in_orbit($vessel_id)) { $planet = anomaly_get_anomaly($vessel['planet_id']); echo " <tr class=bl align=center><td colspan=2>"; form_start(); echo " <input type=hidden name=vid value=" . encrypt_get_vars($vessel['id']) . ">\n"; echo " <input type=hidden name=pid value=" . encrypt_get_vars($vessel['planet_id']) . ">\n"; echo " <select name=sl>\n"; echo " <option value=dump>Unload from vessel</option>\n"; echo " <option value=store>Load into vessel</option>\n"; echo " </select> \n"; echo " <select name=pc>\n"; echo " <option value=5>5%</option>\n"; echo " <option value=10>10%</option>\n"; echo " <option value=25>25%</option>\n"; echo " <option value=50>50%</option>\n"; echo " <option value=75>75%</option>\n"; echo " <option value=100>100%</option>\n"; echo " </select> \n"; echo " <select name=sp>\n"; for ($i = 0; $i != ore_get_ore_count(); $i++) { echo " <option value={$i}>" . ore_get_ore_name($i) . "</option>\n"; } echo " <option value=" . ORE_ALL . ">All ores</option>\n"; echo " </select> \n"; echo " <input type=submit name=submit value=go>\n"; form_end(); echo " </td></tr>\n"; } echo "</table>"; echo "<br><br>\n\n\n"; }
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(); }