Example #1
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 #3
0
function vessel_show_trade_details($vessel_id)
{
    assert(is_numeric($vessel_id));
    $vessel = vessel_get_vessel($vessel_id);
    // Default action is not to show anything from a planet,
    // since we can be in flight
    for ($i = 0; $i != ore_get_ore_count(); $i++) {
        $planet_stock_ores[$i] = '?';
    }
    $status = vessel_get_current_status($vessel_id);
    if (vessel_is_in_orbit($vessel_id)) {
        $result = sql_query("SELECT * FROM g_ores WHERE planet_id=" . $vessel['planet_id']);
        $tmp = sql_fetchrow($result);
        $planet_stock_ores = ore_csl_to_list($tmp['stock_ores']);
    }
    $result = sql_query("SELECT * FROM i_vessels WHERE vessel_id=" . $vessel['id']);
    $tmp = sql_fetchrow($result);
    $vessel_stock_ores = ore_csl_to_list($tmp['ores']);
    echo "<table border=0 width=75% align=center>\n";
    echo "  <tr class=wb><th colspan=2>Trade vessel: " . $vessel['name'] . "</th></tr>\n";
    echo "  <tr><td>\n";
    echo "    <table border=0 width=100% cellpading=0 cellspacing=0>\n";
    echo "    <tr class=bl><th colspan=2>Ores on planet:</th></tr>\n";
    for ($i = 0; $i != ore_get_ore_count(); $i++) {
        echo "    <tr class=bl><td>" . ore_get_ore_name($i) . "</td> <td>" . $planet_stock_ores[$i] . "</td></tr>\n";
    }
    echo "    </table>\n";
    echo "  </td><td>\n";
    echo "    <table border=0 width=100% cellpading=0 cellspacing=0>\n";
    echo "      <tr class=bl><th colspan=2>Ores on trader:</th></tr>\n";
    for ($i = 0; $i != ore_get_ore_count(); $i++) {
        echo "      <tr class=bl><td>" . ore_get_ore_name($i) . "</td> <td>" . $vessel_stock_ores[$i] . "</td></tr>\n";
    }
    echo "    </table>\n";
    echo "  </td></tr>\n";
    // Don't load/unload when we are in a trade route
    if (vessel_in_traderoute($vessel_id)) {
        echo "  <tr class=wb><th colspan=2>Cannot load/unload because vessel is part of a trade route.</th></tr>";
    }
    // TODO: Don't load/unload when it's not our planet :)
    if (vessel_is_in_orbit($vessel_id)) {
        $planet = anomaly_get_anomaly($vessel['planet_id']);
        echo "  <tr class=bl align=center><td colspan=2>";
        form_start();
        echo "    <input type=hidden name=vid value=" . encrypt_get_vars($vessel['id']) . ">\n";
        echo "    <input type=hidden name=pid value=" . encrypt_get_vars($vessel['planet_id']) . ">\n";
        echo "    <select name=sl>\n";
        echo "      <option value=dump>Unload from vessel</option>\n";
        echo "      <option value=store>Load into vessel</option>\n";
        echo "    </select>&nbsp;\n";
        echo "    <select name=pc>\n";
        echo "      <option value=5>5%</option>\n";
        echo "      <option value=10>10%</option>\n";
        echo "      <option value=25>25%</option>\n";
        echo "      <option value=50>50%</option>\n";
        echo "      <option value=75>75%</option>\n";
        echo "      <option value=100>100%</option>\n";
        echo "    </select>&nbsp;\n";
        echo "    <select name=sp>\n";
        for ($i = 0; $i != ore_get_ore_count(); $i++) {
            echo "      <option value={$i}>" . ore_get_ore_name($i) . "</option>\n";
        }
        echo "      <option value=" . ORE_ALL . ">All ores</option>\n";
        echo "    </select>&nbsp;\n";
        echo "    <input type=submit name=submit value=go>\n";
        form_end();
        echo "  </td></tr>\n";
    }
    echo "</table>";
    echo "<br><br>\n\n\n";
}
function obsolete_svt_upkeep_ores($cannot_build, $s_vessel, $user, $stock_ores)
{
    assert(is_numeric($cannot_build));
    assert(is_array($s_vessel));
    assert(is_array($user));
    assert(is_array($stock_ores));
    $vessel_upkeep_ores = ore_csl_to_list($s_vessel['upkeep_ores']);
    $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;" . $s_vessel['upkeep_costs'] . "&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;" . $vessel_upkeep_ores[$i] . "&nbsp;</td>\n";
        echo "  </tr>\n";
    }
    echo "</table>\n";
    return $cannot_build;
}
function planet_show_planet($planet_id)
{
    assert(!empty($planet_id));
    global $_GALAXY;
    global $_CONFIG;
    global $_RUN;
    if (!anomaly_is_planet($planet_id)) {
        return;
    }
    $planet = anomaly_get_anomaly($planet_id);
    $result = sql_query("SELECT * FROM g_ores WHERE planet_id=" . $planet_id);
    $ore = sql_fetchrow($result);
    $stock_ore = ore_csl_to_list($ore['stock_ores']);
    $race = user_get_race($planet['user_id']);
    $sector = sector_get_sector($planet['sector_id']);
    $result = sql_query("SELECT * FROM s_state WHERE id=" . $planet['state_id']);
    $state = sql_fetchrow($result);
    if ($race == "") {
        $race = "-";
    }
    $extra_attack = 0;
    $extra_defense = 0;
    $attack = $planet['cur_attack'];
    $defense = $planet['cur_attack'];
    // Count all ships and their attack/defense currently in orbit around the planet
    $result = sql_query("SELECT COUNT(*) FROM g_vessels AS g, s_vessels AS s WHERE g.planet_id=" . $planet_id . " AND s.id = g.vessel_id AND s.type='" . VESSEL_TYPE_BATTLE . "' AND status='ORBIT' AND created=1");
    $tmp = sql_fetchrow($result);
    $battle_vessels = $tmp[0];
    $result = sql_query("SELECT COUNT(*) FROM g_vessels AS g, s_vessels AS s WHERE g.planet_id=" . $planet_id . " AND s.id = g.vessel_id AND s.type='" . VESSEL_TYPE_TRADE . "' AND status='ORBIT' AND created=1");
    $tmp = sql_fetchrow($result);
    $trade_vessels = $tmp[0];
    $result = sql_query("SELECT COUNT(*) FROM g_vessels AS g, s_vessels AS s WHERE g.planet_id=" . $planet_id . " AND s.id = g.vessel_id AND s.type='" . VESSEL_TYPE_EXPLORE . "' AND status='ORBIT' AND created=1");
    $tmp = sql_fetchrow($result);
    $explore_vessels = $tmp[0];
    $result = sql_query("SELECT SUM(cur_attack) AS CA, SUM(cur_defense) AS CD FROM g_vessels AS g WHERE g.planet_id=" . $planet_id . " AND status='ORBIT' AND created=1");
    $tmp = sql_fetchrow($result);
    if (isset($tmp['CA'])) {
        $extra_attack = $extra_attack + $tmp['CA'];
    }
    if (isset($tmp['CD'])) {
        $extra_defense = $extra_defense + $tmp['CD'];
    }
    $template = new Smarty();
    $template->debugging = true;
    $template->assign("sector_name", $sector['name']);
    $template->assign("planet_name", $planet['name']);
    $template->assign("image", $_CONFIG['IMAGE_URL'] . $_GALAXY['image_dir'] . "/planets/" . $planet['image'] . ".jpg");
    if ($planet['unknown'] == 1) {
        $template->assign("cmd", encrypt_get_vars("claim"));
        $template->assign("formid", generate_form_id());
        $template->assign("aid", encrypt_get_vars($planet_id));
        $template->assign("rename_form_visible", "true");
    } else {
        $template->assign("rename_form_visible", "false");
    }
    $template->assign("class", $planet['class']);
    $template->assign("race", $race);
    $template->assign("state", $state['name']);
    $template->assign("happieness", planet_get_happy_string($planet['happieness']));
    $template->assign("healtieness", planet_get_healty_string($planet['sickness']));
    $template->assign("population", $planet['population']);
    $template->assign("radius", $planet['radius']);
    $template->assign("distance", $planet['distance']);
    $template->assign("water", $planet['water']);
    $template->assign("temperature", $planet['temperature']);
    for ($i = 0; $i != ore_get_ore_count(); $i++) {
        $tmp = array();
        $tmp['name'] = ore_get_ore_name($i);
        $tmp['stock'] = $stock_ore[$i];
        $tmpvar[] = $tmp;
    }
    $template->assign("ores", $tmpvar);
    $template->assign("attack", $attack);
    $template->assign("extra_attack", $extra_attack);
    $template->assign("defense", $defense);
    $template->assign("extra_defense", $extra_defense);
    $template->assign("strength", $planet['cur_strength']);
    $template->assign("orbit_battle", $trade_vessels);
    $template->assign("orbit_trade", $battle_vessels);
    $template->assign("orbit_explore", $explore_vessels);
    $template->assign("description", convert_px_to_html_tags($planet['description']));
    $template->display($_RUN['theme_path'] . "/planet-details.tpl");
    $commands = array();
    // If we have at least 1 ship in orbit, we can view them here...
    if ($explore_vessels + $trade_vessels + $battle_vessels > 0) {
        $commands['View Vessels'] = "vessel.php?cmd=" . encrypt_get_vars("showaid") . "&aid=" . encrypt_get_vars($planet_id);
    }
    // If it's a solid-class planet (lower than M), we can view the surface.
    if (planet_is_habitable($planet_id) or planet_is_minable($planet_id)) {
        $commands['View Surface'] = "surface.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($planet_id);
    }
    // If it's our planet we might construct and manufacture,..
    if (anomaly_am_i_owner($planet['id'])) {
        $commands['Change Description'] = "anomaly.php?cmd=" . encrypt_get_vars("description") . "&aid=" . encrypt_get_vars($planet_id);
        // Only minable or habitable or lower can construct
        if (planet_is_habitable($planet_id) or planet_is_minable($planet_id)) {
            $commands['Construct'] = "construct.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($planet_id);
            $commands['Manufacture'] = "manufacture.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($planet_id);
        }
        if (planet_has_vesselbuilding_capability($planet_id)) {
            $commands['Create Vessel'] = "vesselcreate.php?cmd=" . encrypt_get_vars("showaid") . "&aid=" . encrypt_get_vars($planet_id);
        }
    }
    create_submenu($commands);
}
Example #6
0
function mining_show_sector($sector_id, $user_id)
{
    assert(!empty($sector_id));
    assert(!empty($user_id));
    // 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)) {
        #      if (!in_array ($planet['id'], $planets)) continue;
        $result2 = sql_query("SELECT * FROM g_ores WHERE planet_id=" . $planet['id']);
        $ores = sql_fetchrow($result2);
        $cur_ores = ore_csl_to_list($ores['cur_ores']);
        $max_ores = ore_csl_to_list($ores['max_ores']);
        for ($i = 0; $i != ore_get_ore_count(); $i++) {
            $fo = "ore" . $i . "c";
            if ($max_ores[$i] == 0) {
                $tmp = 0;
            } else {
                $tmp = $cur_ores[$i] / $max_ores[$i] * 100;
            }
            ${$fo} = "white";
            if ($tmp > 50) {
                ${$fo} = "yellow";
            }
            if ($tmp > 75) {
                ${$fo} = "orange";
            }
            if ($tmp > 99) {
                ${$fo} = "red";
            }
        }
        # 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>Name</th>";
            for ($i = 0; $i != ore_get_ore_count(); $i++) {
                echo "<th>" . ore_get_ore_name($i) . "</th>";
            }
            echo "</tr>\n";
        }
        if (!planet_is_minable($planet['id'])) {
            echo "  <tr class=bl>";
            echo "<td>&nbsp;Planet " . $planet['name'] . "&nbsp;</td>";
            echo "<th colspan=" . ore_get_ore_count() . ">No mining possible</th>";
            echo "</tr>\n";
        } else {
            echo "  <tr class=bl>";
            echo "<td>&nbsp;<a href=\"anomaly.php?cmd=" . encrypt_get_vars("show") . "&aid=" . encrypt_get_vars($planet['id']) . "\">Planet " . $planet['name'] . "</a>&nbsp;</td>";
            for ($i = 0; $i != ore_get_ore_count(); $i++) {
                $fo = "ore" . $i . "c";
                echo "<td><font color=" . ${$fo} . ">" . $cur_ores[$i] . "</font></td>";
            }
            echo "</tr>\n";
        }
    }
    // while
    if ($first_row == false) {
        echo "</table>\n";
        // Close last sector
        echo "<br><br>\n";
    }
}