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> Power Generated </td><td> " . $totals['power_out'] . " </td></tr>\n"; echo " <tr><td> Power Needed </td><td> " . $totals['power_in'] . " </td></tr>\n"; echo " <tr><td> <font color={$power_color}><b>Power Left </b></font> </td><td> <font color={$power_color}><b>" . ($totals['power_out'] - $totals['power_in']) . "</b></font> </td></tr>\n"; echo " </table>\n"; echo " </td><td>\n"; echo " <table width=100% border=0 cellpadding=0 cellspacing=0>\n"; echo " <tr><td> <font color={$crew_color}>Inhabitants</font> </td><td> <font color={$crew_color}>" . $planet['population'] . "</font> </td></tr>\n"; echo " <tr><td> <font color={$crew_color}>Capacity</font> </td><td> <font color={$crew_color}>" . $planet['population_capacity'] . "</font> </td></tr>\n"; echo " <tr><td> </td><td> </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> " . $quantity . " </td>\n"; echo " <td> " . $active . " " . $building['name'] . " </td>\n"; echo " <td> " . $building['power_in'] . " </td>\n"; echo " <td> " . $building['power_out'] . " </td>\n"; echo " <td> " . $building['rule'] . " </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> " . $quantity . " </font></td>\n"; echo " <td><font color=red> " . $active . " " . $building['name'] . " </font></td>\n"; echo " <td colspan=3><font color=red> Building not active </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> " . $quantity . " </td>\n"; echo " <td> <img " . $activeimg . "> " . $invention['name'] . " </td>\n"; echo " <td> " . $invention['rule'] . " </td>\n"; echo " </tr>\n"; } echo "</table>\n"; echo "<br><br>\n"; }
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']); } } }