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;
}
Пример #2
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";
}
Пример #3
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>";
}
Пример #4
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']);
        }
    }
}
Пример #5
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";
    }
}
Пример #6
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);
        }
    }
}