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;
}
Example #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";
}
Example #3
0
}
if ($cmd == "build") {
    $ok = "";
    $errors['PARAMS'] = "Incorrect parameters specified..\n";
    $errors['CREDITS'] = "You don't have enough cash to construct the building...\n";
    $errors['ORE'] = "You don't have enough ores to construct the building...\n";
    $errors['POWER'] = "You need more (advanced) powerplants to construct the building...\n";
    $errors['MAX'] = "You cannot build anymore buildings of this type on the planet...\n";
    $errors['DEPS'] = "You cannot build this building before you have build all dependencies...\n";
    $errors['QUEUE'] = "Maximum number of constructions per planet reached. Wait until other buildings are finished...\n";
    $errors['SCIENCE'] = "You cannot build the construction since you haven't invented it yet...\n";
    $data['building_id'] = $bid;
    $data['anomaly_id'] = $aid;
    $data['user_id'] = user_ourself();
    if (comm_send_to_server("BUILD", $data, $ok, $errors) == 1) {
        $building = building_get_building($data['bid']);
        echo "<br><br><br><br>";
        echo "<table align=center border=0>";
        echo "  <tr><th>New construction in progress</th></tr>";
        echo "  <tr><td align=center><img align=center src=\"" . $_CONFIG['URL'] . $_GALAXY['image_dir'] . "/buildings/" . $building['image'] . ".jpg\" width=150 height=150></td></tr>";
        echo "</table>";
    }
}
print_footer();
exit;
// ============================================================================================
//
//
// Description:
//
//
function sbt_upkeep_ores($cannot_build, $building_id, $user_id, $stock_ores)
{
    assert(is_bool((bool) $cannot_build));
    assert(is_numeric($building_id));
    assert(is_numeric($user_id));
    assert(is_array($stock_ores));
    $building = building_get_building($building_id);
    $building_upkeep_ores = ore_csl_to_list($building['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;" . $building['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;" . $building_upkeep_ores[$i] . " tons&nbsp;</td>\n";
        echo "  </tr>\n";
    }
    echo "</table>\n";
    return $cannot_build;
}
Example #5
0
function queue_print($user_id)
{
    assert(is_numeric($user_id));
    global $_RUN;
    $totalcount = 0;
    $template = new Smarty();
    $template->debugging = true;
    // Buildings
    $count = 0;
    $tmpvar = array();
    $result = sql_query("SELECT * FROM h_queue WHERE type='" . QUEUE_BUILD . "' AND user_id=" . $user_id);
    while ($queue = sql_fetchrow($result)) {
        $totalcount++;
        $count++;
        $building = building_get_building($queue['building_id']);
        $planet = anomaly_get_anomaly($queue['planet_id']);
        $tmpvar['what'][] = "Building " . $building['name'] . " on " . $planet['name'];
        $tmpvar['ticks'][] = $queue['ticks'];
    }
    $tmpvar['count'] = $count;
    $template->assign("building", $tmpvar);
    // Items
    $count = 0;
    $tmpvar = array();
    $result = sql_query("SELECT * FROM h_queue WHERE type='" . QUEUE_INVENTION . "' AND user_id=" . $user_id);
    while ($queue = sql_fetchrow($result)) {
        $totalcount++;
        $count++;
        $item = item_get_item($queue['building_id']);
        $planet = anomaly_get_anomaly($queue['planet_id']);
        $tmpvar['what'][] = "Manufacturing " . $item['name'] . " on " . $planet['name'];
        $tmpvar['ticks'][] = $queue['ticks'];
    }
    $tmpvar['count'] = $count;
    $template->assign("item", $tmpvar);
    // Vessels
    $count = 0;
    $tmpvar = array();
    $result = sql_query("SELECT * FROM h_queue WHERE type='" . QUEUE_VESSEL . "' AND user_id=" . $user_id);
    while ($queue = sql_fetchrow($result)) {
        $totalcount++;
        $count++;
        $vessel = vessel_get_vessel($queue['vessel_id']);
        $planet = anomaly_get_anomaly($queue['planet_id']);
        $tmpvar['what'][] = "Building " . $vessel['name'] . " on " . $planet['name'];
        $tmpvar['ticks'][] = $queue['ticks'];
    }
    $tmpvar['count'] = $count;
    $template->assign("vessel", $tmpvar);
    // Upgrade (NOTE: THESE ARE ALSO PART OF THE VESSEL[] ARRAY
    $count = 0;
    $tmpvar = array();
    $result = sql_query("SELECT * FROM h_queue WHERE type='" . QUEUE_UPGRADE . "' AND user_id=" . $user_id);
    while ($queue = sql_fetchrow($result)) {
        $totalcount++;
        $count++;
        $vessel = vessel_get_vessel($queue['vessel_id']);
        $planet = anomaly_get_anomaly($queue['planet_id']);
        $tmpvar['what'][] = "Upgrading " . $vessel['name'] . " on " . $planet['name'];
        $tmpvar['ticks'][] = $queue['ticks'];
    }
    $tmpvar['count'] = $count;
    $template->assign("vessel", $tmpvar);
    // Flights
    $count = 0;
    $tmpvar = array();
    $result = sql_query("SELECT * FROM h_queue WHERE type='" . QUEUE_FLIGHT . "' AND user_id=" . $user_id);
    while ($queue = sql_fetchrow($result)) {
        $totalcount++;
        $count++;
        $result2 = sql_query("SELECT * FROM g_vessels WHERE id=" . $queue['vessel_id']);
        $vessel = sql_fetchrow($result2);
        if ($vessel['dst_planet_id'] == 0) {
            if ($vessel['dst_sector_id'] == 0) {
                $tmpvar['what'][] = "Flying " . $vessel['name'] . " to outer space.";
            } else {
                $sector = sector_get_sector($vessel['dst_sector_id']);
                $tmpvar['what'][] = "Flying " . $vessel['name'] . " to sector " . $sector['name'];
            }
        } else {
            $planet = anomaly_get_anomaly($vessel['dst_planet_id']);
            $tmpvar['what'][] = "Flying " . $vessel['name'] . " to " . $planet['name'];
        }
        $tmpvar['ticks'][] = $queue['ticks'];
    }
    $tmpvar['count'] = $count;
    $template->assign("flight", $tmpvar);
    $template->assign("itemcount", $totalcount);
    $template->display($_RUN['theme_path'] . "/order-queue.tpl");
}