Exemplo n.º 1
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";
}
function building_show_details($building_id, $planet_id, $user_id, $stock_ores)
{
    assert(is_numeric($building_id));
    assert(is_numeric($planet_id));
    assert(is_numeric($user_id));
    assert(is_string($stock_ores));
    global $_GALAXY;
    global $_CONFIG;
    $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;
    }
    $building = building_get_building($building_id);
    if ($build_option) {
        $cannot_build = false;
        $planet = anomaly_get_anomaly($planet_id);
        $totals = calc_planet_totals($planet_id);
        $planet_ores = ore_csl_to_list($stock_ores);
        $building_ores = ore_csl_to_list($building['initial_ores']);
    } else {
        $cannot_build = true;
        $totals['power_out'] = 0;
        $totals['power_in'] = 0;
        $planet_ores = ore_csl_to_list("");
        $building_ores = ore_csl_to_list("");
    }
    $href = "construct.php?cmd=" . encrypt_get_vars("build") . "&bid=" . encrypt_get_vars($building_id) . "&aid=" . encrypt_get_vars($planet_id);
    $template = new Template($_CONFIG['TEMPLATE_PATH'] . "/building-details.tpl", E_YAPTER_ALL);
    $template->set("name", $building['name']);
    $template->set("image", $_CONFIG['IMAGE_URL'] . $_GALAXY['image_dir'] . "/buildings/" . $building['image'] . ".jpg");
    $template->set("construction_href", $href);
    $template->set("description", $building['description']);
    $template->set("rule", $building['rule']);
    $template->set("class", "");
    $template->set("power_needed", $building['power_in']);
    $template->set("power_output", $building['power_out']);
    $template->set("attack", $building['attack']);
    $template->set("defense", $building['defense']);
    $template->set("strength", $building['strength']);
    if ($build_option) {
        $template->hide("block_build");
        $template->hide("block_build2");
    } else {
        $template->hide("block_nobuild");
        $template->hide("block_nobuild2");
    }
    $template->parse();
    $template->spit();
    /*
        echo "<table border=1 cellpadding=0 cellspacing=0 align=center width=50%>";
    
    // Building name
        echo "  <tr><th colspan=2>".$building['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']."/buildings/".$building['image'].".jpg\" width=150 height=150></td></tr>";
        echo "                    </table>";
        echo "                 </td>";
        echo "               </tr>";
        echo "             </table>";
        echo "    </td>";
        echo "    <td align=left valign=top>";
        if ($build_option) {
          if (($totals['power_out']-$totals['power_in']) < $building['power_in']) {
              $class="f";
              $cannot_build = true;
          } else {
              $class="t";
          }
        } else {
          $class="t";
        }
        echo "             <table border=0 cellpadding=0 cellspacing=0 width=100%>";
        echo "                <tr>";
        echo "                  <td class=".$class.">&nbsp;<strong>Power Needed</strong>&nbsp;</td>";
        echo "                  <td class=".$class.">&nbsp;<strong>:</strong>&nbsp;</td>";
        echo "                  <td class=".$class.">&nbsp;".$building['power_in']." uts&nbsp;</td>";
        echo "                </tr>";
        $class = 't';
        echo "                <tr>";
        echo "                  <td class=".$class.">&nbsp;<strong>Power Output</strong>&nbsp;</td>";
        echo "                  <td class=".$class.">&nbsp;<strong>:</strong>&nbsp;</td>";
        echo "                  <td class=".$class.">&nbsp;".$building['power_out']." uts&nbsp;</td>";
        echo "                </tr>";
        echo "<tr><td colspan=3><hr></td></tr>";
        $class = 't';
        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;".$building['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;".$building['defense']." pts&nbsp;</td>";
        echo "                </tr>";
        echo "                <tr>";
        echo "                  <td class=".$class.">&nbsp;<strong>Strength</strong>&nbsp;</td>";
        echo "                  <td class=".$class.">&nbsp;<strong>:</strong>&nbsp;</td>";
        echo "                  <td class=".$class.">&nbsp;".$building['strength']." pts&nbsp;</td>";
        echo "                </tr>";
        echo "              </table>";
        echo "    </td>";
        echo "  </tr>";
    
        if ($build_option) {
          // Costs + ores  (initial / upkeep)
          echo "  <tr><td colspan=2>&nbsp;</td></tr>\n";
          echo "  <tr><td>";
          $cannot_build = sbt_initial_ores ($cannot_build, $building_id, $user_id, $planet_ores);
          echo "  </td><td>";
          $cannot_build = sbt_upkeep_ores ($cannot_build, $building_id, $user_id, $planet_ores);
          echo "  </td></tr>";
          echo "  <tr><td colspan=2>&nbsp;</td></tr>\n";
        } else {
          echo "  <tr><td colspan=2>&nbsp;</td></tr>\n";
          echo "  <tr><td>";
          sbt_initial_ores (0, $building_id, $user_id, $planet_ores);
          echo "  </td><td>";
          sbt_upkeep_ores (0, $building_id, $user_id, $planet_ores);
          echo "  </td></tr>";
          echo "  <tr><td colspan=2>&nbsp;</td></tr>\n";
        }
    
    // Print rule and description
        if ($building['rule'] != "") {
          echo "<tr><td colspan=2><table border=0 cellspacing=5><tr><td>Effect: ".$building['rule']."</td></tr></table></td></tr>";
        }
    
        if ($building['description'] != "") {
          echo "<tr><td colspan=2><table border=0 cellspacing=5><tr><td>".$building['description']."</td></tr></table></td></tr>";
        }
    
    // Print building possibility
        if ($build_option) {
          if ($cannot_build == false) {
            echo "<tr><th colspan=2><a href=construct.php?cmd=".encrypt_get_vars ("build").
                                                        "&bid=".encrypt_get_vars ($building['id']).
                                                        "&aid=".encrypt_get_vars ($planet['id']).
                                                        ">BUILD IT</a></th></tr>";
          } else {
            echo "<tr><th colspan=2>CANNOT BUILD</th></tr>";
          }
       }
        echo "</table>\n";
        echo "<br><br>\n";
    */
}