function alliance_discovered_a_member($user_id, $alliance_id) { assert(is_numeric($user_id)); assert(is_numeric($alliance_id)); $tmp = user_get_knownspecies($user_id); $knownusers = csl_merge_fields("", $tmp['csl_friend_id']); $knownusers = csl_merge_fields($knownusers, $tmp['csl_neutral_id']); $knownusers = csl_merge_fields($knownusers, $tmp['csl_enemy_id']); sort($knownusers, SORT_NUMERIC); $result = sql_query("SELECT * FROM g_users WHERE alliance_id=" . $alliance_id); $user = sql_fetchrow($result); if (in_array($user['user_id'], $knownusers)) { return true; } return false; }
function sector_show_sector($sector_id, $user_id) { assert(!empty($sector_id)); assert(!empty($user_id)); global $_RUN; // Create the submenu where we can easily move between sectors $result = sql_query("SELECT * FROM g_sectors WHERE user_id = " . $user_id); $tmp = sql_fetchrow($result); $sectors = csl($tmp['csl_sector_id']); $idx = array_search($sector_id, $sectors); $first = reset($sectors); $last = end($sectors); if ($idx == 0) { $prev = $sectors[$idx]; } else { $prev = $sectors[$idx - 1]; } if ($idx == count($sectors) - 1) { $next = $sectors[$idx]; } else { $next = $sectors[$idx + 1]; } create_submenu(array("First Sector" => "sector.php?cmd=" . encrypt_get_vars("show") . "&sid=" . encrypt_get_vars($first), "Previous Sector" => "sector.php?cmd=" . encrypt_get_vars("show") . "&sid=" . encrypt_get_vars($prev), "Next Sector" => "sector.php?cmd=" . encrypt_get_vars("show") . "&sid=" . encrypt_get_vars($next), "Last Sector" => "sector.php?cmd=" . encrypt_get_vars("show") . "&sid=" . encrypt_get_vars($last))); $sector = sector_get_sector($sector_id); $template = new Smarty(); $template->debugging = true; help_set_template_vars($template); $template->assign("sector_id", $sector['sector']); $template->assign("sector_name", $sector['name']); $template->assign("sector_coordinate", $sector['distance'] . " / " . $sector['angle']); if ($sector['user_id'] == UID_NOBODY) { $template->assign("rename_form_visible", "true"); } else { $template->assign("rename_form_visible", "false"); } // And now, do all anomalies $tmp = user_get_all_anomalies_from_user($user_id); $anomalies = csl($tmp['csl_discovered_id']); $undiscovered_anomalies = csl($tmp['csl_undiscovered_id']); $anomalies = csl_merge_fields($anomalies, $tmp['csl_undiscovered_id']); // We didn't find any discovered anomalies in this sector per default $i = 0; $tmpvar = array(); // Get anomaly information for all anomalies in the sector $result = sql_query("SELECT * FROM s_anomalies WHERE sector_id=" . $sector_id . " ORDER BY distance"); while ($anomaly = sql_fetchrow($result)) { // We didn't discover this anomaly yet, continue with another if (!in_array($anomaly['id'], $anomalies)) { continue; } // Thread undiscovered planets different... if (in_array($anomaly['id'], $undiscovered_anomalies)) { $tmp['name'] = "Unknown"; $tmp['class'] = ""; $tmp['population'] = ""; $tmp['owner'] = ""; $tmp['status'] = ""; $tmp['radius'] = $anomaly['radius']; $tmp['distance'] = $anomaly['distance']; $tmpvar[] = $tmp; continue; } // If we are here, we have found an anomaly with we already // discovered and explored, show all the info about it... $state = sql_get_state($anomaly['state_id']); if ($anomaly['user_id'] != 0) { $race = user_get_race($anomaly['user_id']); } else { $race = "Nobody"; } // Show the population status in a different color if ($anomaly['population_capacity'] == 0) { $p = 0; } else { $p = $anomaly['population'] / $anomaly['population_capacity'] * 100; } $popcol = 'people_class1'; if ($p > 50) { $popcol = 'people_class2'; } if ($p > 75) { $popcol = 'people_class3'; } if ($p > 99) { $popcol = 'people_class4'; } if (!anomaly_is_planet($anomaly['id'])) { $anomaly['class'] = ""; $anomaly['population'] = ""; } // Show the class in different colors, A..J are orange... K..M are white... L..Z are red $classcol = "class_normal"; if (planet_is_habitable($anomaly['id'])) { $classcol = 'class_habitable'; } elseif (planet_is_minable($anomaly['id'])) { $classcol = 'class_minable'; } else { $classcol = 'class_unusable'; } $tmp = array(); $tmp['name_href'] = "anomaly.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($anomaly['id']); $tmp['name'] = $anomaly['name']; $tmp['class'] = $anomaly['class']; $tmp['class_class'] = $classcol; if (planet_is_habitable($anomaly['id'])) { $tmp['population'] = $anomaly['population']; } else { $tmp['population'] = "---"; } $tmp['population_class'] = $popcol; $tmp['owner'] = $race; $tmp['status'] = $state; $tmp['radius'] = $anomaly['radius']; $tmp['distance'] = $anomaly['distance']; $tmpvar[] = $tmp; } $template->assign("anomalies", $tmpvar); $template->display($_RUN['theme_path'] . "/sectors-item.tpl"); }
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>"; } } }