예제 #1
0
function anomaly_is_discovered_by_user($anomaly_id, $user_id)
{
    assert(is_numeric($anomaly_id));
    assert(is_numeric($user_id));
    $tmp = user_get_all_anomalies_from_user($user_id);
    $undiscovered_anomalies = csl($tmp['csl_undiscovered_id']);
    $discovered_anomalies = csl($tmp['csl_discovered_id']);
    if (in_array($anomaly_id, $discovered_anomalies)) {
        return true;
    }
    return false;
}
예제 #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;
    }
}
function calc_planet_totals($planet_id)
{
    assert(is_numeric($planet_id));
    $totals['power_in'] = 0;
    $totals['power_out'] = 0;
    // Get all buildings that are currently build on the planet
    $surface = planet_get_surface($planet_id);
    $buildings = csl($surface['csl_building_id']);
    reset($buildings);
    while (list($key, $building_id) = each($buildings)) {
        if (!building_is_active($building_id)) {
            continue;
        }
        $building = building_get_building($building_id);
        $totals['power_in'] = $totals['power_in'] + $building['power_in'];
        $totals['power_out'] = $totals['power_out'] + $building['power_out'];
    }
    return $totals;
}
예제 #4
0
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");
}
예제 #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";
}
예제 #6
0
function invention_show_details($invention_id, $planet_id, $user_id, $stock_ores)
{
    assert(is_numeric($invention_id));
    assert(is_numeric($planet_id));
    assert(is_numeric($user_id));
    assert(is_string($stock_ores));
    global $_GALAXY;
    $build_option = 1;
    // Check our mode, we can just look at details, or let the user build
    if ($planet_id == 0 and $user_id == 0 and $stock_ores == "") {
        $build_option = 0;
    }
    $invention = item_get_item($invention_id);
    if ($build_option) {
        $cannot_build = false;
        $user = user_get_user($user_id);
        $planet = anomaly_get_anomaly($planet_id);
        $planet_ores = csl($stock_ores);
        $invention_ores = ore_csl_to_list($invention['initial_ores']);
    } else {
        $planet_ores = ore_csl_to_list("");
        $invention_ores = ore_csl_to_list("");
    }
    echo "<table border=1 cellpadding=0 cellspacing=0 align=center width=50%>";
    // invention name
    echo "  <tr class=wb><th colspan=2>" . $invention['name'] . "</th></tr>";
    // Plaatje plus ADS etc
    echo "  <tr>";
    echo "    <td align=center valign=top bgcolor=black>";
    echo "              <table border=0 cellpadding=0 cellspacing=0>";
    echo "                <tr>";
    echo "                   <td >";
    echo "                    <table align=left border=0 cellpadding=0 cellspacing=0 width=100%>";
    echo "                      <tr><td width=100><img src=\"" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/inventions/" . $invention['image'] . ".jpg\" width=150 height=150></td></tr>";
    echo "                    </table>";
    echo "                 </td>";
    echo "               </tr>";
    echo "             </table>";
    echo "    </td>";
    echo "    <td align=left valign=top bgcolor=black>";
    $class = 't';
    echo "             <table border=0 cellpadding=0 cellspacing=0 width=100%>";
    echo "                <tr>";
    echo "                  <td class=" . $class . ">&nbsp;<strong>Function</strong>&nbsp;</td>";
    echo "                  <td class=" . $class . ">&nbsp;<strong>:</strong>&nbsp;</td>";
    echo "                  <td class=" . $class . ">&nbsp;" . item_get_type($invention['id']) . "&nbsp;</td>";
    echo "                </tr>";
    echo "                <tr><td colspan=3><hr></td></tr>\n";
    echo "                <tr>";
    echo "                  <td class=" . $class . ">&nbsp;<strong>Maximum Stock</strong>&nbsp;</td>";
    echo "                  <td class=" . $class . ">&nbsp;<strong>:</strong>&nbsp;</td>";
    echo "                  <td class=" . $class . ">&nbsp;" . $invention['max'] . " pcs&nbsp;</td>";
    echo "                </tr>";
    echo "                <tr><td colspan=3><hr></td></tr>\n";
    echo "                <tr>";
    echo "                  <td class=" . $class . ">&nbsp;<strong>Attack</strong>&nbsp;</td>";
    echo "                  <td class=" . $class . ">&nbsp;<strong>:</strong>&nbsp;</td>";
    echo "                  <td class=" . $class . ">&nbsp;" . $invention['attack'] . " pts&nbsp;</td>";
    echo "                </tr>";
    echo "                <tr>";
    echo "                  <td class=" . $class . ">&nbsp;<strong>Defense</strong>&nbsp;</td>";
    echo "                  <td class=" . $class . ">&nbsp;<strong>:</strong>&nbsp;</td>";
    echo "                  <td class=" . $class . ">&nbsp;" . $invention['defense'] . " pts&nbsp;</td>";
    echo "                </tr>";
    echo "              </table>";
    echo "    </td>";
    echo "  </tr>";
    if ($build_option) {
        // Costs + ores  (initial / upkeep)
        echo "  <tr bgcolor=black><td colspan=2>&nbsp;</td></tr>\n";
        echo "  <tr bgcolor=black><td>";
        $cannot_build = smt_initial_ores($cannot_build, $invention_id, $user_id, $planet_ores);
        echo "  </td><td>";
        $cannot_build = smt_upkeep_ores($cannot_build, $invention_id, $user_id, $planet_ores);
        echo "  </td></tr>";
        echo "  <tr bgcolor=black><td colspan=2>&nbsp;</td></tr>\n";
    } else {
        echo "  <tr bgcolor=black><td colspan=2>&nbsp;</td></tr>\n";
        echo "  <tr bgcolor=black><td>";
        smt_initial_ores(0, $invention_id, $user_id, $planet_ores);
        echo "  </td><td>";
        smt_upkeep_ores(0, $invention_id, $user_id, $planet_ores);
        echo "  </td></tr>";
        echo "  <tr bgcolor=black><td colspan=2>&nbsp;</td></tr>\n";
    }
    // Print rule and description
    if ($invention['rule'] != "") {
        echo "<tr bgcolor=black><td colspan=2><table border=0 cellspacing=5><tr><td>Effect: " . $invention['rule'] . "</td></tr></table></td></tr>";
    }
    if ($invention['description'] != "") {
        echo "<tr bgcolor=black><td colspan=2 ><table border=0 cellspacing=5><tr><td>" . $invention['description'] . "</td></tr></table></td></tr>";
    }
    // Print building possibility
    if ($build_option) {
        if ($cannot_build == false) {
            echo "<tr bgcolor=black><th colspan=2><a href=manufacture.php?cmd=" . encrypt_get_vars("manufacture") . "&iid=" . encrypt_get_vars($invention['id']) . "&aid=" . encrypt_get_vars($planet['id']) . ">BUILD IT</a></th></tr>";
        } else {
            echo "<tr bgcolor=black><th colspan=2>CANNOT BUILD</th></tr>";
        }
    }
    echo "</table>\n";
    echo "<br><br>\n";
}
예제 #7
0
function choose_vessel($user_id)
{
    global $_GALAXY;
    echo "<table align=center border=1>";
    echo "<tr><th>Name</th><th>Impulse</th><th>Warp</th><th>Status</th></tr>";
    $result = sql_query("SELECT g.* FROM g_vessels AS g, s_vessels AS s WHERE g.user_id=" . $user_id . " AND g.created=1 AND g.vessel_id = s.id ORDER BY s.type, g.id");
    while ($vessel = sql_fetchrow($result)) {
        // We can only upgrade if we are near a vessel station.
        if ($vessel['status'] != "ORBIT") {
            $nocando = 1;
        } else {
            // Check if we have a spacedock or vessel construction station
            $surface = planet_get_surface($vessel['planet_id']);
            $buildings = csl($surface['csl_building_id']);
            $vesseltype = vessel_get_vesseltype($vessel['id']);
            $nocando = 0;
            if ($vesseltype['type'] == VESSEL_TYPE_BATTLE and !in_array(BUILDING_VESSEL_STATION, $buildings)) {
                $nocando = 1;
            }
            if ($vesseltype['type'] != VESSEL_TYPE_BATTLE and !in_array(BUILDING_SPACEDOCK, $buildings)) {
                $nocando = 1;
            }
        }
        if ($nocando == 0) {
            $status = "Nearby a vessel or docking station";
            $upgrade = 1;
        } else {
            $status = "Not in the vicinity of a vessel station";
            $upgrade = 0;
        }
        echo "<tr>";
        if ($upgrade == 1) {
            echo "<td>&nbsp;<img alt=Active src=" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/general/active.gif>&nbsp;<a href=vesselupgrade.php?vid=" . encrypt_get_vars($vessel['id']) . ">" . $vessel['name'] . "</a>&nbsp;</td>";
        } else {
            echo "<td>&nbsp;<img alt=Inactive src=" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/general/inactive.gif>&nbsp;" . $vessel['name'] . "</a>&nbsp;</td>";
        }
        echo "<td>&nbsp;Impulse: " . $vessel['impulse'] . "% &nbsp;</td>";
        echo "<td>&nbsp;Warp: ";
        printf("%.1f", $vessel['warp'] / 10);
        echo "&nbsp;</td>";
        echo "<td>&nbsp;{$status}&nbsp;</td>";
        echo "</tr>";
    }
    echo "</table>";
}
예제 #8
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']);
        }
    }
}
예제 #9
0
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>&nbsp;</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>&nbsp;" . $q . "&nbsp;</td>";
            echo "  <td>&nbsp;<img " . $activeimg . ">&nbsp;" . $invention['name'] . "&nbsp;</td>";
            if ($vessel['planet_id'] == 0) {
                echo "  <td nowrap>&nbsp;&nbsp;</td>";
            } else {
                echo "  <td nowrap>&nbsp;<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>&nbsp;</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>&nbsp;</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>&nbsp;" . $q . "&nbsp;</td>\n";
            echo "    <td>&nbsp;<img " . $activeimg . ">&nbsp;" . $invention['name'] . "&nbsp;</td>\n";
            echo "    <td nowrap>&nbsp;<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>&nbsp;</td>\n";
            echo "  </tr>\n";
        }
        echo "</table>\n";
        form_end();
        echo "<br><br>\n";
    }
}
예제 #10
0
function trade_show_routes($user_id)
{
    assert(is_numeric($user_id));
    global $_GALAXY;
    $firstrow = 1;
    $result = sql_query("SELECT * FROM a_trades");
    while ($traderoute = sql_fetchrow($result)) {
        $src_planet = anomaly_get_anomaly($traderoute['src_planet_id']);
        $dst_planet = anomaly_get_anomaly($traderoute['dst_planet_id']);
        // We don't own the source or destination planet... skip it..
        if ($src_planet['user_id'] != $user_id and $dst_planet['user_id'] != $user_id) {
            continue;
        }
        $vessel = vessel_get_vessel($traderoute['vessel_id']);
        $ore1 = "";
        $ore2 = "";
        if ($traderoute['src_ore'] == ORE_NONE) {
            $ore1 = "None, ";
        } elseif ($traderoute['src_ore'] == ORE_ALL) {
            $ore1 = "All ores, ";
        } else {
            $ores = csl($traderoute['src_ore']);
            foreach ($ores as $ore) {
                $ore1 .= ore_get_ore_name($ore) . ", ";
            }
        }
        // Chop off last comma
        $ore1 = substr_replace($ore1, "", -2);
        if ($traderoute['dst_ore'] == ORE_NONE) {
            $ore2 = "None, ";
        } elseif ($traderoute['dst_ore'] == ORE_ALL) {
            $ore2 = "All ores, ";
        } else {
            $ores = csl($traderoute['dst_ore']);
            foreach ($ores as $ore) {
                $ore2 .= ore_get_ore_name($ore) . ", ";
            }
        }
        // Chop off last comma
        $ore2 = substr_replace($ore2, "", -2);
        if ($firstrow == 1) {
            $firstrow = 0;
            print_remark("Vessel table");
            echo "<table align=center width=80% border=0>\n";
            echo "  <tr class=wb>";
            echo "<th>Vessel</th>";
            echo "<th>Source</th>";
            echo "<th>Ores</th>";
            echo "<th>Destination</th>";
            echo "<th>Ores</th>";
            echo "</tr>\n";
        }
        echo "  <tr class=bl>\n";
        echo "    <td>&nbsp;<img src=" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/ships/trade.jpg>&nbsp;<a href=vessel.php?cmd=" . encrypt_get_vars("showvid") . "&vid=" . encrypt_get_vars($vessel['id']) . ">" . $vessel['name'] . "</a>&nbsp;</td>\n";
        echo "    <td>&nbsp;<a href=anomaly.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($src_planet['id']) . ">" . $src_planet['name'] . "</a>&nbsp;</td>\n";
        echo "    <td>&nbsp;" . $ore1 . "&nbsp;</td>\n";
        echo "    <td>&nbsp;<a href=anomaly.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($dst_planet['id']) . ">" . $dst_planet['name'] . "</a>&nbsp;</td>\n";
        echo "    <td>&nbsp;" . $ore2 . "&nbsp;</td>\n";
        echo "  </tr>\n";
    }
    if ($firstrow == 0) {
        echo "</table>\n";
        echo "<br><br>\n";
    } else {
        print_line("There are currently no traderoutes available.");
    }
}
예제 #11
0
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);
        }
    }
}
예제 #12
0
function load_current_ffn($uid)
{
    assert(is_numeric($uid));
    global $current_ffn;
    $current_ffn = array();
    $tmp = user_get_knownspecies($uid);
    $current_ffn['uid'] = $uid;
    $current_ffn['csl_neutral_id'] = csl($tmp['csl_neutral_id']);
    $current_ffn['csl_enemy_id'] = csl($tmp['csl_enemy_id']);
    $current_ffn['csl_friend_id'] = csl($tmp['csl_friend_id']);
}
function csl_merge_fields($org, $new)
{
    return array_merge($org, csl($new));
}