Example #1
0
function sector_show_all_sectors($user_id)
{
    assert(isset($user_id));
    global $_RUN;
    $homesector = sector_get_sector(user_get_home_sector($user_id));
    // Get all anomaly counts from the sectors the user has discovered. We DONT want to count
    // the anomalies that the user did not already discovered. Hence the big SQL statement :)
    $result = sql_query("SELECT a.sector_id, COUNT(*) AS qty FROM s_anomalies AS a, g_anomalies AS g WHERE g.user_id = " . $user_id . " AND ( FIND_IN_SET( a.id, g.csl_discovered_id ) OR FIND_IN_SET( a.id, g.csl_undiscovered_id) ) GROUP BY a.sector_id");
    while ($count = sql_fetchrow($result)) {
        $anomaly_count[$count['sector_id']] = $count['qty'];
    }
    $result = sql_query("SELECT s.* FROM s_sectors AS s, g_sectors AS g WHERE g.user_id = " . $user_id . " AND FIND_IN_SET(s.id, g.csl_sector_id)");
    while ($sector = sql_fetchrow($result)) {
        $distance = calc_distance($homesector['distance'], $homesector['angle'], $sector['distance'], $sector['angle']);
        if ($sector['user_id'] == 0) {
            $owner = '<font color=red>unclaimed</font>';
        } else {
            $tmp = user_get_user($sector['user_id']);
            $owner = $tmp['race'];
        }
        $tmp = array();
        $tmp['href'] = "sector.php?cmd=" . encrypt_get_vars("show") . "&sid=" . encrypt_get_vars($sector['id']);
        $tmp['id'] = $sector['sector'];
        $tmp['name'] = $sector['name'];
        $tmp['qty'] = $anomaly_count[$sector['id']];
        $tmp['owner'] = $owner;
        $tmp['coordinate'] = $sector['distance'] . " / " . $sector['angle'];
        $tmp['distance'] = round($distance);
        $tmp['unround_distance'] = $distance;
        $sector_rows[] = $tmp;
    }
    uasort($sector_rows, "show_all_sectors_cmp");
    print_subtitle("All known sectors and their planets");
    foreach ($sector_rows as $sector) {
        $tmp = array();
        $tmp['id'] = $sector['id'];
        $tmp['name'] = $sector['name'];
        $tmp['qty'] = $sector['qty'];
        $tmp['owner'] = $sector['owner'];
        $tmp['coordinate'] = $sector['coordinate'];
        $tmp['distance'] = $sector['distance'];
        $tmp['href'] = $sector['href'];
        $tmpvar[] = $tmp;
    }
    $template = new Smarty();
    $template->debugging = true;
    help_set_template_vars($template);
    $template->assign("sectors", $tmpvar);
    if (isset($_REQUEST['pager_pos'])) {
        $template->assign("pager_pos", $_REQUEST['pager_pos']);
    } else {
        $template->assign("pager_pos", 0);
    }
    $template->assign("theme_path", $_RUN['theme_path']);
    $template->display($_RUN['theme_path'] . "/sectors-all.tpl");
}
Example #2
0
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;
    }
}
Example #3
0
function show_alliance($user_id, $alliance_id)
{
    assert(is_numeric($user_id));
    assert(is_numeric($alliance_id) or empty($alliance_id));
    if ($alliance_id != "") {
        alliance_showinfo($alliance_id, $user_id);
        return;
    }
    $user = user_get_user($user_id);
    $result = sql_query("SELECT * FROM g_alliance");
    while ($alliance = sql_fetchrow($result)) {
        if ($user['alliance_id'] == $alliance['id']) {
            alliance_showinfo($alliance['id'], $user_id);
        }
        if (alliance_discovered_a_member($user_id, $alliance['id'])) {
            alliance_showinfo($alliance['id'], $user_id);
        }
    }
}
Example #4
0
function info_get_invention_statistics($user_id)
{
    assert(isset($user_id));
    $user = user_get_user($user_id);
    $result = sql_query("SELECT COUNT(*) FROM s_buildings");
    $row = sql_fetchrow($result);
    $tmp1 = $row['0'];
    $result = sql_query("SELECT COUNT(*) FROM s_buildings WHERE build_level <= " . $user['building_level']);
    $row = sql_fetchrow($result);
    $tmp2 = $row['0'];
    $building_percentage = round($tmp2 / $tmp1 * 100, 2);
    $result = sql_query("SELECT COUNT(*) FROM s_vessels");
    $row = sql_fetchrow($result);
    $tmp1 = $row['0'];
    $result = sql_query("SELECT COUNT(*) FROM s_vessels WHERE build_level <= " . $user['vessel_level']);
    $row = sql_fetchrow($result);
    $tmp2 = $row['0'];
    $vessel_percentage = round($tmp2 / $tmp1 * 100, 2);
    $result = sql_query("SELECT COUNT(*) FROM s_inventions");
    $row = sql_fetchrow($result);
    $tmp1 = $row['0'];
    $result = sql_query("SELECT COUNT(*) FROM s_inventions WHERE build_level <= " . $user['building_level']);
    $row = sql_fetchrow($result);
    $tmp2 = $row['0'];
    $item_percentage = round($tmp2 / $tmp1 * 100, 2);
    return array($building_percentage, $vessel_percentage, $item_percentage);
}
Example #5
0
function show_surface($planet_id)
{
    global $_GALAXY;
    // Get global information from the user
    $planet = anomaly_get_anomaly($planet_id);
    $user = user_get_user($planet['user_id']);
    $sector = sector_get_sector($planet['sector_id']);
    $totals = calc_planet_totals($planet_id);
    // Generate text color for the power
    if ($totals['power_out'] == 0) {
        $power_p = 0;
    } else {
        $power_p = $totals['power_in'] / $totals['power_out'] * 100;
    }
    $power_color = "white";
    if ($power_p > 50) {
        $power_color = "yellow";
    }
    if ($power_p > 75) {
        $power_color = "orange";
    }
    if ($power_p > 99) {
        $power_color = "red";
    }
    // Generate text color for the crew
    if ($planet['population_capacity'] == 0) {
        $crew_p = 0;
    } else {
        $crew_p = $planet['population'] / $planet['population_capacity'] * 100;
    }
    $crew_color = "white";
    if ($crew_p > 50) {
        $crew_color = "yellow";
    }
    if ($crew_p > 75) {
        $crew_color = "orange";
    }
    if ($crew_p > 99) {
        $crew_color = "red";
    }
    print_subtitle("Surface View on planet " . $planet['name']);
    // ------------------------------------------------------------------
    echo "<table width=75% align=center border=1>\n";
    echo "  <tr><th colspan=2>Global Information on<br>Sector " . $sector['name'] . " / Planet " . $planet['name'] . "</th></tr>\n";
    echo "  <tr><td>\n";
    echo "    <table width=100% border=0 cellpadding=0 cellspacing=0>\n";
    echo "      <tr><td>&nbsp;Power Generated&nbsp;</td><td>&nbsp;" . $totals['power_out'] . "&nbsp;</td></tr>\n";
    echo "      <tr><td>&nbsp;Power Needed&nbsp;</td><td>&nbsp;" . $totals['power_in'] . "&nbsp;</td></tr>\n";
    echo "      <tr><td>&nbsp;<font color={$power_color}><b>Power Left </b></font>&nbsp;</td><td>&nbsp;<font color={$power_color}><b>" . ($totals['power_out'] - $totals['power_in']) . "</b></font>&nbsp;</td></tr>\n";
    echo "    </table>\n";
    echo "  </td><td>\n";
    echo "    <table width=100% border=0 cellpadding=0 cellspacing=0>\n";
    echo "      <tr><td>&nbsp;<font color={$crew_color}>Inhabitants</font>&nbsp;</td><td>&nbsp;<font color={$crew_color}>" . $planet['population'] . "</font>&nbsp;</td></tr>\n";
    echo "      <tr><td>&nbsp;<font color={$crew_color}>Capacity</font>&nbsp;</td><td>&nbsp;<font color={$crew_color}>" . $planet['population_capacity'] . "</font>&nbsp;</td></tr>\n";
    echo "      <tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n";
    echo "    </table>\n";
    echo "  </td></tr>\n";
    echo "</table>\n";
    echo "<br>\n";
    echo "<br>\n";
    // Get all buildings and cargo on the planet
    $surface = planet_get_surface($planet_id);
    $current_buildings = csl($surface['csl_building_id']);
    $current_buildings = array_count_values($current_buildings);
    $current_cargo = csl($surface['csl_cargo_id']);
    $current_cargo = array_count_values($current_cargo);
    // ------------------------------------------------------------------
    // Show current buildings on the surface
    //  echo "<table width=75% align=center border=0 cellpadding=0 cellspacing=0>\n";
    echo "<table width=75% align=center border=0>\n";
    echo "  <tr class=wb><th colspan=5>Buildings on the planet</th></tr>\n";
    echo "  <tr class=bl>";
    echo "<th>Qty</th>";
    echo "<th>Name</th>";
    echo "<th>Power In</th>";
    echo "<th>Power Out</th>";
    echo "<th>Description</th>";
    echo "</tr>\n";
    reset($current_buildings);
    while (list($building_id, $quantity) = each($current_buildings)) {
        $building = building_get_building(building_active_or_inactive($building_id));
        if (building_is_active($building_id)) {
        } else {
        }
        if (building_is_active($building_id)) {
            $active = "<img alt=Active src=" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/general/active.gif>";
            echo "  <tr class=bl>\n";
            echo "    <td>&nbsp;" . $quantity . "&nbsp;</td>\n";
            echo "    <td>&nbsp;" . $active . "&nbsp;" . $building['name'] . "&nbsp;</td>\n";
            echo "    <td>&nbsp;" . $building['power_in'] . "&nbsp;</td>\n";
            echo "    <td>&nbsp;" . $building['power_out'] . "&nbsp;</td>\n";
            echo "    <td>&nbsp;" . $building['rule'] . "&nbsp;</td>\n";
            echo " </tr>\n";
        } else {
            $active = "<img alt=Inactive src=" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/general/inactive.gif>";
            echo "  <tr class=bl>\n";
            echo "    <td><font color=red>&nbsp;" . $quantity . "&nbsp;</font></td>\n";
            echo "    <td><font color=red>&nbsp;" . $active . "&nbsp;" . $building['name'] . "&nbsp;</font></td>\n";
            echo "    <td colspan=3><font color=red>&nbsp;Building not active&nbsp;</font></td>\n";
            echo " </tr>\n";
        }
    }
    echo "</table>\n";
    echo "<br><br>\n";
    // ------------------------------------------------------------------
    // Show current items on the surface
    echo "<table width=75% align=center border=0>\n";
    echo "  <tr class=wb><th colspan=5>Cargo and machines on planet</th></tr>\n";
    echo "  <tr class=bl>";
    echo "<th>Qty</th>";
    echo "<th>Name</th>";
    echo "<th>Description</th>";
    echo "</tr>\n";
    reset($current_cargo);
    while (list($item_id, $quantity) = each($current_cargo)) {
        $invention = item_get_item($item_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>&nbsp;" . $quantity . "&nbsp;</td>\n";
        echo "    <td>&nbsp;<img " . $activeimg . ">&nbsp;" . $invention['name'] . "&nbsp;</td>\n";
        echo "    <td>&nbsp;" . $invention['rule'] . "&nbsp;</td>\n";
        echo "  </tr>\n";
    }
    echo "</table>\n";
    echo "<br><br>\n";
}
Example #6
0
function stock_show_sector($sector_id, $user_id)
{
    assert(!empty($sector_id));
    assert(!empty($user_id));
    global $_CONFIG;
    // Check how many planets we own in this sector. If none, don't show anything...
    $result = sql_query("SELECT COUNT(*) AS count FROM s_anomalies WHERE sector_id = " . $sector_id . " AND user_id=" . $user_id);
    $tmp = sql_fetchrow($result);
    if ($tmp['count'] == 0) {
        return;
    }
    // Get sector information
    $sector = sector_get_sector($sector_id);
    // Only show a table if we got rows in it...
    $first_row = true;
    // Get planet information for all planets in the sector
    $result = sql_query("SELECT * from s_anomalies WHERE user_id=" . $user_id . " AND type='P' AND sector_id=" . $sector['id']);
    while ($planet = sql_fetchrow($result)) {
        $result2 = sql_query("SELECT * FROM g_ores WHERE planet_id=" . $planet['id']);
        $ores = sql_fetchrow($result2);
        $stock_ores = ore_csl_to_list($ores['stock_ores']);
        $upkeep_ores = ore_csl_to_list($planet['upkeep_ores']);
        for ($i = 0; $i != ore_get_ore_count(); $i++) {
            $fo = "ore" . $i . "c";
            ${$fo} = "white";
            if ($upkeep_ores[$i] == 0) {
                $ticks_left = 0;
            } else {
                $ticks_left = $stock_ores[$i] / $upkeep_ores[$i];
                if ($ticks_left < 50) {
                    ${$fo} = "yellow";
                }
                if ($ticks_left < 25) {
                    ${$fo} = "orange";
                }
                if ($ticks_left < 10) {
                    ${$fo} = "red";
                }
            }
        }
        $user = user_get_user($planet['user_id']);
        if ($user['science_ratio'] == 100 or $planet['happieness'] == 0) {
            $planet_income = 0;
        } else {
            $planet_income = $planet['population'] / (100 / (100 - $user['science_ratio']));
            $planet_income = $planet_income / $_CONFIG['h_credits_dividor'];
            $planet_income = $planet_income / (100 / $planet['happieness']);
        }
        $planet_upkeep = $planet['upkeep_costs'];
        $delta_upkeep = intval($planet_income - $planet_upkeep);
        // Only show a table if we have rows in it...
        if ($first_row) {
            $first_row = false;
            print_remark("Sector table");
            echo "<table align=center border=0>\n";
            echo "  <tr class=wb><td colspan=" . (ore_get_ore_count() + 2) . "><b><i>Sector " . $sector['sector'] . ": " . $sector['name'] . "</i></b></td></tr>\n";
            echo "  <tr class=bl><th colspan=2>Name</th>";
            for ($i = 0; $i != ore_get_ore_count(); $i++) {
                echo "<th>" . ore_get_ore_name($i) . "</th>";
            }
            echo "</tr>\n";
        }
        echo "  <tr class=bl>\n";
        echo "    <td rowspan=2 valign=top>\n";
        echo "      &nbsp;<a href=\"anomaly.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($planet['id']) . "\">Planet " . $planet['name'] . "</a>&nbsp;<br>\n";
        if ($delta_upkeep < 0) {
            echo "      &nbsp;<font color=red>Delta Upkeep: " . $delta_upkeep . "</font>&nbsp;\n";
        } else {
            echo "      &nbsp;Delta Upkeep: " . $delta_upkeep . "&nbsp;\n";
        }
        echo "    </td>\n";
        echo "<td>&nbsp;Current in stock&nbsp;</td>";
        for ($i = 0; $i != ore_get_ore_count(); $i++) {
            $fo = "ore" . $i . "c";
            echo "<td align=right><font color=" . ${$fo} . ">" . $stock_ores[$i] . "</font></td>";
        }
        echo "</tr>\n";
        echo "  <tr class=bl>";
        echo "<td>&nbsp;Upkeep per tick&nbsp;</td>";
        for ($i = 0; $i != ore_get_ore_count(); $i++) {
            $fo = "ore" . $i . "c";
            echo "<td align=right><font color=" . ${$fo} . ">" . $upkeep_ores[$i] . "</font></td>";
        }
        echo "</tr>\n";
    }
    // while
    if ($first_row == false) {
        echo "</table>\n";
        // Close last sector
        echo "<br><br>\n";
    }
}
function smt_upkeep_ores($cannot_build, $invention_id, $user_id, $stock_ores)
{
    assert(is_bool((bool) $cannot_build));
    assert(is_numeric($invention_id));
    assert(is_numeric($user_id));
    assert(is_array($stock_ores));
    $invention = item_get_item($invention_id);
    $invention_upkeep_ores = ore_csl_to_list($invention['upkeep_ores']);
    if ($user_id == 0) {
        $build_option = 0;
    } else {
        $build_option = 1;
        $user = user_get_user($user_id);
    }
    $class = "t";
    echo "<table border=0 cellpadding=0 cellspacing=0 width=100%>\n";
    echo "  <tr><th colspan=3>Upkeep costs</th></tr>";
    echo "  <tr>\n";
    echo "    <td class=" . $class . " width=33%> &nbsp;<strong>Credits</strong>&nbsp;</td>\n";
    echo "    <td class=" . $class . " width=1%>  &nbsp;<strong>:</strong>&nbsp;</td>\n";
    echo "    <td class=" . $class . " width=34%> &nbsp;" . $invention['upkeep_costs'] . " cr&nbsp;</td>\n";
    echo "  </tr>\n";
    // Do all ores
    for ($i = 0; $i != ore_get_ore_count(); $i++) {
        echo "  <tr>\n";
        echo "    <td class=" . $class . " width=33%>&nbsp;<strong>" . ore_get_ore_name($i) . "</strong>&nbsp;</td>\n";
        echo "    <td class=" . $class . " width=1%> &nbsp;<strong>:</strong>&nbsp;</td>\n";
        echo "    <td class=" . $class . " width=34%>&nbsp;" . $invention_upkeep_ores[$i] . " tons&nbsp;</td>\n";
        echo "  </tr>\n";
    }
    echo "</table>\n";
    return $cannot_build;
}
Example #8
0
function show_invention_levels($uid)
{
    $user = user_get_user($uid);
    print_remark("Invention table");
    echo "<table align=center border=0 width=75%>\n";
    echo "  <tr valign=top><td valign=top>\n";
    echo "    <table align=center border=0 width=100%>\n";
    echo "      <tr><td>General improvement: </td><td>" . $user['invention_level'] . " Points</td></tr>\n";
    echo "      <tr><td colspan=2 class=ylw>Invent new general inventions.</td></tr>\n";
    echo "      <tr><td colspan=2>&nbsp;</td></tr>\n";
    echo "      <tr><td>Building improvement: </td><td>" . $user['building_level'] . " Points</td></tr>\n";
    echo "      <tr><td colspan=2 class=ylw>Invent and improve buildings. Higher ratings will invent different types of buildings.</td></tr>\n";
    echo "      <tr><td colspan=2>&nbsp;</td></tr>\n";
    echo "    </table>\n";
    if ($user['impulse'] > 0) {
        echo "  </td><td>\n";
        echo "    <table align=center border=0 width=100%>\n";
        echo "      <tr><td>Vessel improvement: </td><td>" . $user['vessel_level'] . " Points</td></tr>\n";
        echo "      <tr><td colspan=2 class=ylw>Invent and improve vessels. Higher ratings will invent different types of vessels, faster possible speeds and weaponry.</td></tr>\n";
        echo "      <tr><td colspan=2>&nbsp;</td></tr>\n";
        echo "      <tr><td>Space exploration: </td><td>" . $user['explore_level'] . " Points</td></tr>\n";
        echo "      <tr><td colspan=2 class=ylw>Explore new regions of space. Higher ratings will discover more planets and sectors and can intercept messages from further away.</td></tr>\n";
        echo "      <tr><td colspan=2>&nbsp;</td></tr>\n";
        echo "    </table>\n";
    }
    echo "  </td></tr>\n";
    echo "</table>\n";
    echo "<br><br>\n";
}
Example #9
0
function show_constructions($anomaly_id)
{
    assert(is_numeric($anomaly_id));
    // Get global information stuff
    $planet = anomaly_get_anomaly($anomaly_id);
    $user = user_get_user($planet['user_id']);
    // And get the ores from the planet
    $result = sql_query("SELECT * FROM g_ores WHERE planet_id=" . $anomaly_id);
    $ores = sql_fetchrow($result);
    // Get all buildings that are currently build on the planet
    $surface = planet_get_surface($anomaly_id);
    $current_buildings = csl($surface['csl_building_id']);
    // If we've got an headquarter and it's inactive, we cannot build anything.. :(
    if (in_array(BUILDING_HEADQUARTER_INACTIVE, $current_buildings)) {
        print_line("Your headquarter is currently inactive due to insufficent resources for its upkeep. You cannot build anything on this planet until you replenish your resources.");
        $cannot_build = true;
        return;
    }
    print_subtitle("Construction on planet " . $planet['name']);
    // And get all buildings, compare wether or not we may build them...
    $result = sql_query("SELECT * FROM s_buildings ORDER BY id");
    while ($building = sql_fetchrow($result)) {
        // Default, we can build this
        $cannot_build = false;
        // Stage -1: Check planet class when we want to build a headquarter
        if ($building['id'] == BUILDING_HEADQUARTER) {
            if (!planet_is_habitable($anomaly_id)) {
                $cannot_build = true;
            }
        }
        // Stage 0: Check building_level
        if ($building['build_level'] > $user['building_level']) {
            $cannot_build = true;
        }
        // Stage 1: Building Count Check
        // Build counter check
        if ($building['max'] > 0) {
            $times_already_build = 0;
            for ($i = 0; $i != count($current_buildings); $i++) {
                if (building_active_or_inactive($current_buildings[$i]) == $building['id']) {
                    $times_already_build++;
                }
            }
            // Cannot build cause we already have MAX buildings of this kind.. :(
            // building['max'] = 0 means unlimited buildings...
            if ($times_already_build == $building['max']) {
                $cannot_build = true;
            }
        }
        // Stage 2: Dependency Check
        // Get all dependencies
        $buildings_needed = csl($building['csl_depends']);
        // Do we need them? If not, skip dependency-check.
        if (!empty($building['csl_depends'])) {
            $deps_found = count($buildings_needed);
            // Count to zero...
            while (list($key, $building_dep_id) = each($buildings_needed)) {
                if ($building_dep_id == "") {
                    $deps_found--;
                    continue;
                }
                // Get all dependencies
                if (in_array($building_dep_id, $current_buildings)) {
                    $deps_found--;
                    // Found in current_buildings?
                    // Decrease counter
                }
            }
        } else {
            // No need for deps
            $deps_found = 0;
            // Zero is good...
        }
        // Not all dependencies found, we cannot build it.. :(
        if ($deps_found > 0) {
            $cannot_build = true;
        }
        // Stage 3: Show building if we can build it..
        if ($cannot_build == false) {
            building_show_details($building['id'], $planet['id'], $user['user_id'], $ores['stock_ores']);
        }
    }
}
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>&nbsp;</td><td>&nbsp;</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>&nbsp;</td><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td><td>&nbsp;</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>&nbsp;</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>&nbsp;</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 obsolete_show_vessels($planet_id)
{
    assert(!empty($planet_id));
    global $_USER;
    // Get global information from the user
    $user = user_get_user($_USER['id']);
    $planet = anomaly_get_anomaly($planet_id);
    // And get the ores from the planet
    $result = sql_query("SELECT * FROM g_ores WHERE planet_id=" . $planet_id);
    $ores = sql_fetchrow($result);
    $stock_ores = ore_csl_to_list($ores['stock_ores']);
    print_subtitle("Create vessel on planet " . $planet['name']);
    // And get all buildings, compare wether or not we may build them...
    $result = sql_query("SELECT * FROM s_vessels ORDER BY id");
    while ($vessel = sql_fetchrow($result)) {
        // Default, we can build this
        $cannot_build = false;
        // Stage 3: Show building if we can build it..
        if ($cannot_build == false) {
            show_vessel_table($vessel, $user, $stock_ores);
        }
    }
}
function alliance_showinfo($alliance_id, $user_id, $extended_info = USER_SHOWINFO_NORMAL)
{
    assert(is_numeric($alliance_id));
    assert(is_numeric($user_id));
    assert(is_numeric($extended_info));
    $result = sql_query("SELECT * FROM g_alliance WHERE id={$alliance_id}");
    $alliance = sql_fetchrow($result);
    $race = user_get_race($alliance['owner_id']);
    $result = sql_query("SELECT COUNT(*) AS count FROM g_users WHERE alliance_id = " . $alliance['id']);
    $tmp = sql_fetchrow($result);
    $alliance_size = $tmp['count'];
    $user = user_get_user($user_id);
    $result = sql_query("SELECT COUNT(*) FROM s_sectors, g_users WHERE s_sectors.user_id = g_users.user_id AND g_users.alliance_id = " . $alliance_id);
    $row = sql_fetchrow($result);
    $sectors_owned = $row['0'];
    $result = sql_query("SELECT COUNT(*) FROM s_anomalies, g_users WHERE s_anomalies.user_id = g_users.user_id AND g_users.alliance_id = " . $alliance_id);
    $row = sql_fetchrow($result);
    $planets_owned = $row['0'];
    echo "<table border=0 align=center width=60%>";
    echo "<tr><th class=white colspan=2>" . $alliance['name'] . "</th></tr>";
    echo "<tr><th colspan=2><b>" . $alliance['tag'] . "</b></th></tr>";
    echo "<tr valign=top>";
    echo "  <td width=120>";
    echo "    <img width=100 height=100 src='images/users/" . $alliance['avatar'] . "'><br>";
    echo "  </td>";
    echo "  <td><table border=0 nowrap width=100%>";
    echo "        <tr class=bl><td colspan=3>" . $alliance['description'] . "</td></tr>";
    echo "        <tr><td colspan=3>&nbsp;</td></tr>";
    echo "        <tr class=bl><td>&nbsp;Owner           &nbsp;</td><td>:</td><td>&nbsp;<a href=stats.php?cmd=" . encrypt_get_vars("show") . "&uid=" . encrypt_get_vars($alliance['owner_id']) . ">" . $race . " race</a>&nbsp;</td></tr>";
    echo "        <tr class=bl><td>&nbsp;Size            &nbsp;</td><td>:</td><td>&nbsp;" . $alliance_size . " user(s)</a>&nbsp;</td></tr>";
    echo "        <tr><td colspan=3>&nbsp;</td></tr>";
    echo "        <tr class=bl><td>&nbsp;Sectors Owned     &nbsp;</td><td>:</td><td>&nbsp;" . $sectors_owned . " sector(s)&nbsp;</td></tr>";
    echo "        <tr class=bl><td>&nbsp;Planets Owned     &nbsp;</td><td>:</td><td>&nbsp;" . $planets_owned . " planet(s)</td></tr>";
    echo "        <tr class=bl><td colspan=3>\n";
    // Only show the users in the alliance when we are part of that alliance...
    if ($user['alliance_id'] == $alliance_id) {
        $result = sql_query("SELECT * FROM g_users WHERE alliance_id=" . $alliance['id']);
        while ($tmp_user = sql_fetchrow($result)) {
            $tmp_race = user_get_race($tmp_user['user_id']);
            echo "<a href=stats.php?cmd=" . encrypt_get_vars("show") . "&uid=" . encrypt_get_vars($tmp_user['user_id']) . ">" . $tmp_race . " race</a>, \n";
        }
        echo "        </td></tr>\n";
        // We can only part an alliance if we're not the owner of it, if we are owner, we can disband the alliance (?)
        if ($user['user_id'] == $alliance['owner_id']) {
            echo "<tr><th colspan=3>";
            echo "[ Disband this alliance ] ";
            echo "</th></tr>";
        } else {
            echo "<tr><th colspan=3>";
            echo "[ <a href=alliance.php?aid=" . encrypt_get_vars(0 - $alliance_id) . "&uid=" . encrypt_get_vars($user['user_id']) . ">Part this alliance</a>  ] ";
            echo "</th></tr>";
        }
    }
    // We're not part of an alliance.. We can join if we want...
    if ($user['alliance_id'] == 0) {
        $result2 = sql_query("SELECT * FROM g_alliance_pending WHERE user_id=" . $user['user_id']);
        $pending = sql_fetchrow($result2);
        // If we already are pending for joining this alliance, we cannot click it anymore..
        if ($pending['alliance_id'] == $alliance_id) {
            echo "<tr><th colspan=3>";
            echo "[ Request pending ] ";
            echo "</th></tr>";
        } else {
            echo "<tr><th colspan=3>";
            echo "[ <a href=alliance.php?aid=" . encrypt_get_vars($alliance_id) . "&uid=" . encrypt_get_vars($user['user_id']) . ">Join this alliance</a>  ] ";
            echo "</th></tr>";
        }
    }
    echo "  </table></td>";
    echo "</tr>";
    echo "</table>";
    echo "<br><br>";
}
Example #13
0
function message_create_alliance($user_id)
{
    $user = user_get_user($user_id);
    $race = user_get_race($user['user_id']);
    $result = sql_query("SELECT * FROM g_alliance WHERE id=" . $user['alliance_id']);
    $alliance = sql_fetchrow($result);
    print_remark("Createmessage");
    form_start();
    echo "  <table align=center border=0 width=80%>\n";
    echo "    <tr><th>Send message</th></tr>\n";
    echo "    <tr><td>From:          </td><td>" . $race . " race</td></tr>\n";
    echo "    <tr><td>To:            </td><td>All members of " . $alliance['name'] . "</td></tr>\n";
    echo "    <tr><td>Subject:       </td><td><input type=text name=ne_subject size=50 maxvalue=50></td></tr>\n";
    echo "    <tr><td>Msg:           </td><td><textarea name=ne_msg rows=5 cols=60></textarea></td></tr>\n";
    echo "    <tr><td>&nbsp;         </td><td><input type=submit name=submit value='Send Message'></td></tr>\n";
    echo "  </table>\n";
    echo "  <br><br>\n";
    echo "\n";
    echo "<input type=hidden name=src_uid value=" . encrypt_get_vars($user['user_id']) . ">\n";
    echo "<input type=hidden name=dst_uid value=" . encrypt_get_vars($user['alliance_id']) . ">\n";
    echo "<input type=hidden name=target value=" . encrypt_get_vars("ALLIANCE") . ">\n";
    echo "<input type=hidden name=cmd value=" . encrypt_get_vars("post") . ">\n";
    form_end();
}
Example #14
0
function print_disoveries($user_id)
{
    assert(is_numeric($user_id));
    global $_GALAXY;
    global $_CONFIG;
    global $_RUN;
    $template = new Smarty();
    $template->debugging = true;
    $user = user_get_user($user_id);
    // Buildings
    $result = sql_query("SELECT COUNT(*) AS count FROM s_buildings");
    $count = sql_fetchrow($result);
    $building_discovered = 0;
    $building_nr = 0;
    $result = sql_query("SELECT * FROM s_buildings");
    while ($building = sql_fetchrow($result)) {
        if ($building['build_level'] > $user['building_level']) {
            $building_href[] = "";
            $building_img[] = $_CONFIG['IMAGE_URL'] . $_GALAXY['image_dir'] . "/general/default.gif";
            $building_text[] = "Not discovered";
        } else {
            $building_href[] = "inventions.php?cmd=" . encrypt_get_vars("showbid") . "&bid=" . encrypt_get_vars($building['id']);
            $building_img[] = $_CONFIG['IMAGE_URL'] . $_GALAXY['image_dir'] . "/buildings/" . $building['image'] . ".jpg";
            $building_text[] = $building['name'];
            $building_discovered++;
        }
        $building_nr++;
    }
    $template->assign("building_discovery_percentage", round($building_discovered / $building_nr * 100, 2));
    $template->assign("building_href", $building_href);
    $template->assign("building_img", $building_img);
    $template->assign("building_text", $building_text);
    $template->assign("building_count", count($building_href));
    // Vessels
    $result = sql_query("SELECT COUNT(*) AS count FROM s_vessels");
    $count = sql_fetchrow($result);
    $vessel_discovered = 0;
    $vessel_nr = 0;
    $result = sql_query("SELECT * FROM s_vessels");
    while ($vessel = sql_fetchrow($result)) {
        if ($vessel['build_level'] > $user['building_level']) {
            $vessel_href[] = "";
            $vessel_img[] = $_CONFIG['IMAGE_URL'] . $_GALAXY['image_dir'] . "/general/default.gif";
            $vessel_text[] = "Not discovered";
        } else {
            $vessel_href[] = "inventions.php?cmd=" . encrypt_get_vars("showvid") . "&vid=" . encrypt_get_vars($vessel['id']);
            $vessel_img[] = $_CONFIG['IMAGE_URL'] . $_GALAXY['image_dir'] . "/vessels/" . $vessel['image'] . ".jpg";
            $vessel_text[] = $vessel['name'];
            $vessel_discovered++;
        }
        $vessel_nr++;
    }
    $template->assign("vessel_discovery_percentage", round($vessel_discovered / $vessel_nr * 100, 2));
    $template->assign("vessel_href", $vessel_href);
    $template->assign("vessel_img", $vessel_img);
    $template->assign("vessel_text", $vessel_text);
    $template->assign("vessel_count", count($vessel_href));
    // Items
    $result = sql_query("SELECT COUNT(*) AS count FROM s_inventions");
    $count = sql_fetchrow($result);
    $item_discovered = 0;
    $item_nr = 0;
    $result = sql_query("SELECT * FROM s_inventions");
    while ($item = sql_fetchrow($result)) {
        if ($item['build_level'] > $user['building_level']) {
            $item_href[] = "";
            $item_img[] = $_CONFIG['IMAGE_URL'] . $_GALAXY['image_dir'] . "/general/default.gif";
            $item_text[] = "Not discovered";
        } else {
            $item_href[] = "inventions.php?cmd=" . encrypt_get_vars("showiid") . "&iid=" . encrypt_get_vars($item['id']);
            $item_img[] = $_CONFIG['IMAGE_URL'] . $_GALAXY['image_dir'] . "/inventions/" . $item['image'] . ".jpg";
            $item_text[] = $item['name'];
            $item_discovered++;
        }
        $item_nr++;
    }
    $template->assign("item_discovery_percentage", round($item_discovered / $item_nr * 100, 2));
    $template->assign("item_href", $item_href);
    $template->assign("item_img", $item_img);
    $template->assign("item_text", $item_text);
    $template->assign("item_count", count($item_href));
    $template->display($_RUN['theme_path'] . "/inventions.tpl");
}
function show_inventions($anomaly_id)
{
    assert(!empty($anomaly_id));
    // Get global information stuff
    $planet = anomaly_get_anomaly($anomaly_id);
    $user = user_get_user($planet['user_id']);
    // And get the ores from the planet
    $result = sql_query("SELECT * FROM g_ores WHERE planet_id=" . $anomaly_id);
    $ores = sql_fetchrow($result);
    $stock_ores = $ores['stock_ores'];
    // Get all buildings that are currently build on the planet
    $surface = planet_get_surface($anomaly_id);
    $current_buildings = csl($surface['csl_building_id']);
    $current_cargo = $surface['csl_cargo_id'];
    print_subtitle("Produceable on planet " . $planet['name']);
    // Get all items, compare wether or not we may build them...
    $result = sql_query("SELECT * FROM s_inventions ORDER BY type, id");
    while ($item = sql_fetchrow($result)) {
        // Default, we can build this
        $cannot_build = false;
        // Stage 1: Item Count Check
        if ($item['max'] > 0) {
            $times_already_build = 0;
            for ($i = 0; $i != count($current_cargo); $i++) {
                if ($current_cargo[$i] == $item['id']) {
                    $times_already_build++;
                }
            }
            // Cannot build cause we already have MAX items of this kind.. :(
            if ($times_already_build == $item['max']) {
                $cannot_build = true;
            }
        }
        // Stage 2: Dependency Check
        // Get all dependencies
        $items_needed = csl($item['csl_depends']);
        // Do we need them? If not, skip dependency-check.
        if (!empty($item['csl_depends'])) {
            $deps_found = count($items_needed);
            // Count to zero...
            while (list($key, $item_dep_id) = each($items_needed)) {
                if ($item_dep_id == "") {
                    $deps_found--;
                    continue;
                }
                // Get all dependencies
                if (in_array($item_dep_id, $current_buildings)) {
                    $deps_found--;
                    // Found in current_items?
                    // Decrease counter
                }
            }
        } else {
            // No need for deps
            $deps_found = 0;
            // Zero is good...
        }
        // Not all dependencies found, we cannot build it.. :(
        if ($deps_found > 0) {
            $cannot_build = true;
        }
        // Stage 3: Show building if we can build it..
        if ($cannot_build == false) {
            invention_show_details($item['id'], $planet['id'], $user['user_id'], $stock_ores);
        }
    }
}
function user_get_race($user_id)
{
    assert(is_numeric($user_id));
    $user = user_get_user($user_id);
    return $user['race'];
}
Example #17
0
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>";
        }
    }
}