function execute_examinefleet() { global $uid; $its_fleet = new fleet($_GET["fid"]); $can_see = false; if ($its_fleet->uid == $uid) { show_svg_message("There should be no button that would allow you doing this. :S"); return false; } $allies = get_allied_ids($uid); if (is_array($allies)) { array_push($allies, $uid); } else { $allies[] = $uid; } $allied_fleet = in_array($its_fleet->uid, $allies); // check ob eigene oder alleierte planeten im system sind $sth = mysql_query("select 1 from planets where sid=" . $its_fleet->sid . " and uid in (" . implode(",", $allies) . ") LIMIT 1"); if (!$sth) { show_svg_message("There was an Database error #mcontrol:exec_exam_fleet:1"); return false; } if (mysql_num_rows($sth) > 0) { $can_see = true; } // check ob eigene oder alleierte flotten im system sind if (!$can_see) { $sth = mysql_query("select 1 from fleet_info where sid=" . $its_fleet->sid . " and uid in (" . implode(",", $allies) . ") LIMIT 1"); if (!$sth) { show_svg_message("There was an Database error #mcontrol:exec_exam_fleet:2"); return false; } if (mysql_num_rows($sth) > 0) { $can_see = true; } } if (can_see) { $doc = domxml_new_doc("1.0"); $rootElem = $doc->create_element("SR_REQUEST"); $rootElem->set_attribute("type", "examine_fleet"); $rootElem->set_attribute("fid", $its_fleet->fid); $rootElem->set_attribute("owner", $its_fleet->uid); $missionElem = $doc->create_element("SR_FLEET_MISSION"); $no_scan = false; // mission if ($allied_fleet) { // alleierte Flotte, wir sehen die mission // mission kann sich unterscheiden wenn das ziel feindlich ist. $no_target = false; $target_relation = false; if ($its_fleet->tsid > 0 && $its_fleet->tpid > 0) { $sth = mysql_query("SELECT s.name as s_name, p.name, p.uid, p.type, p.id FROM systems s LEFT JOIN planets p on s.id = p.sid WHERE s.id = " . $its_fleet->tsid . " and p.id=" . $its_fleet->tpid); } elseif ($its_fleet->tsid > 0) { $sth = mysql_query("SELECT name as s_name from systems where id = " . $its_fleet->tsid); } else { $no_target = true; } if (!$no_target) { if (!$sth || mysql_num_rows($sth) == 0) { show_svg_message("ERR::Can not get Target"); return false; } $target_info = mysql_fetch_assoc($sth); if ($target_info["s_name"]) { $missionElem->set_attribute("tsys_name", htmlspecialchars($target_info["s_name"])); } if ($target_info["name"]) { if ($target_info["name"] == "Unnamed") { $target_info["name"] = get_planetname($target_info["id"]); } $missionElem->set_attribute("tpla_name", htmlspecialchars($target_info["name"])); $missionElem->set_attribute("tpla_type", $target_info["type"]); if ($target_info["uid"] > 0) { $target_relation = get_uids_relation($its_fleet->uid, $target_info["uid"]); } } $eta = get_true_ETA_by_fid($its_fleet->fid); $rootElem->set_attribute("eta", $eta); } switch ($its_fleet->mission) { case M_MOVE: if ($target_relation == "enemy") { $missionElem->set_attribute("mission", "fleet_mission_attack.svgz"); $missionElem->set_attribute("missionText", "Attacking"); } elseif ($target_relation == "allie" || $target_relation == "same" || $its_fleet->tsid == 0) { $missionElem->set_attribute("mission", "fleet_mission_defend.svgz"); $missionElem->set_attribute("missionText", "Defending"); } else { $missionElem->set_attribute("mission", "fleet_mission_move.svgz"); $missionElem->set_attribute("missionText", "Moving"); } break; case M_INVADE: $missionElem->set_attribute("mission", "fleet_mission_invade.svgz"); $missionElem->set_attribute("missionText", "Invading"); break; case M_BOMB: $missionElem->set_attribute("mission", "fleet_mission_bomb.svgz"); $missionElem->set_attribute("missionText", "Bombarding"); break; case M_COLONIZE: $missionElem->set_attribute("mission", "fleet_mission_colonize.svgz"); $missionElem->set_attribute("missionText", "Colonizing"); break; } $missionElem->set_attribute("tactic", $its_fleet->tactic); } else { $missionElem->set_attribute("mission", "fleet_mission_unknown.svgz"); $missionElem->set_attribute("missionText", "unknown mission"); $missionElem->set_attribute("tactic", "-1"); // gucken ob wir no-scan schiffe haben (special 'N' in shipvalues) $sth = mysql_query("SELECT s.prod_id FROM fleet f, shipvalues s WHERE s.special = 'N' AND s.prod_id = f.prod_id AND f.fid = " . $its_fleet->fid); if (!$sth) { show_svg_message("ERROR::Getting NOSCAN ships"); return false; } if (mysql_num_rows($sth) > 0) { $no_scan = true; } // gucken ob der planet vielleicht so nen gebäude hat?? if (!$no_scan && $its_fleet->pid > 0) { // alleierte der flotte $fleet_allies = get_allied_ids($its_fleet->uid); if (is_array($fleet_allies)) { array_push($fleet_allies, $its_fleet->uid); } else { $fleet_allies[] = $its_fleet->uid; } $sth = mysql_query("SELECT s.prod_id FROM planets p, constructions c join shipvalues s using(prod_id) where s.special='N' and c.pid = p.id and p.id = " . $its_fleet->pid . " and p.uid in (" . implode(",", $fleet_allies) . ")"); if (!$sth) { show_svg_message("ERROR::Getting NOSCAN buildings"); return false; } if (mysql_num_rows($sth) > 0) { $no_scan = true; } } } $rootElem->append_child($missionElem); // ships if (!$no_scan) { foreach ($its_fleet->ships as $prod_id => $values) { $shipElem = $doc->create_element("SR_SHIP"); $shipElem->set_attribute("prod_id", $prod_id); $shipElem->set_attribute("count", $values[0]); if ($allied_fleet) { $shipElem->set_attribute("reload", $values[1]); } else { $shipElem->set_attribute("reload", -1); } $rootElem->append_child($shipElem); } } // admiral $sth = mysql_query("SELECT a.pic, a.name, a.id, a.fid from admirals a join fleet_info f using(fid) having a.fid=" . $its_fleet->fid . ""); if (!$sth) { show_svg_message("There was an Database error #mcontrol:exec_exam_fleet:3"); return false; } if (mysql_num_rows($sth) > 0) { list($a_pic, $a_name, $a_id) = mysql_fetch_row($sth); $admiralElem = $doc->create_element("SR_ADMIRAL"); $admiralElem->set_attribute("name", $a_name); $admiralElem->set_attribute("pic", $a_pic); $admiralElem->set_attribute("level", get_admiral_level($a_id)); $rootElem->append_child($admiralElem); $rootElem->set_attribute("pic", "ADMIRAL"); } else { if (!$no_scan) { $rootElem->set_attribute("pic", get_strongest_ship_by_fid($its_fleet->fid)); } else { $rootElem->set_attribute("pic", 0); } } $doc->append_child($rootElem); echo $doc->dump_mem(); } else { show_svg_message("Either this is a bug or you're a h4xx0r. :S"); } }
function combat_report($pid, $sid) { global $combat; if (COMBAT_VERBOSE) { start_timer(1); echo "Erstelle Kampfbericht..."; } $combat_smarty = new Smarty(); global $__base_inc_dir; $combat_smarty->template_dir = $__base_inc_dir . "battle/templates/"; $combat_smarty->compile_dir = $__base_inc_dir . "battle/templates_c"; $combat_smarty->config_dir = $__base_inc_dir . "battle/configs/"; $combat_smarty->cache_dir = $__base_inc_dir . "battle/cache/"; $puid = get_uid_by_pid($pid); if ($pid) { if ($puid) { $puname = get_name_by_uid($puid); } else { $puname = "no owner"; } if ($pid == -1) { $combat_smarty->assign("location", "SimOrbit"); } else { $combat_smarty->assign("location", get_planetname($pid) . " ({$puname})"); } } else { $combat_smarty->assign("location", get_systemname($sid)); } $invader_id = combat_get_conqueror($pid); if (!$invader_id) { $combat_smarty->assign("invasion", ""); } else { $combat["shots_fired"]++; if ($invader_id < 0 && $invader_id > -100) { $combat_smarty->assign("invasion", "Planet1 has been invaded by Side2"); } elseif ($invader_id == -100) { $combat_smarty->assign("invasion", "Planetary combat, production was delayed."); } else { $combat_smarty->assign("invasion", get_planetname($pid) . " has been invaded by " . get_name_by_uid($invader_id)); } } // Admiraele berichten $query = $GLOBALS["db"]->query("SELECT SUM(c1.challenge) AS xp_earned, c2.admiral_id AS admiral_id, c2.uid \nAS uid FROM combat c1 INNER JOIN combat c2 ON (c1.killed_by=c2.id) WHERE c2.admiral_id <> 0 \nGROUP BY c2.admiral_id") or die("Admiral-XP: " . $GLOBALS["db"]->error); while ($result = $query->fetch_assoc()) { if (!is_array($results[$result["uid"]]["admirals"])) { $aidx = 0; } else { $aidx = sizeof($results[$result["uid"]]["admirals"]); } $results[$result["uid"]]["admirals"][$aidx]["name"] = dlookup("name", "admirals", "id=" . $result["admiral_id"]); if (is_null(dlookup("killed_by", "combat", "admiral_carried=" . $result["admiral_id"]))) { $results[$result["uid"]]["admirals"][$aidx]["xp"] = dlookup("value", "admirals", "id=" . $result["admiral_id"]); $results[$result["uid"]]["admirals"][$aidx]["newxp"] = dlookup("value", "admirals", "id=" . $result["admiral_id"]) + $result["xp_earned"]; $results[$result["uid"]]["admirals"][$aidx]["lvlup"] = calculate_admiral_level(dlookup("value", "admirals", "id=" . $result["admiral_id"]) + $result["xp_earned"]) != calculate_admiral_level(dlookup("value", "admirals", "id=" . $result["admiral_id"])); } } $users_query = $GLOBALS["db"]->query("SELECT DISTINCT uid, aid FROM combat") or die($GLOBALS["db"]->error); if (!$users_query) { return false; } while ($users_result = $users_query->fetch_assoc()) { // Feinde $results_query = $GLOBALS["db"]->query("SELECT alliance2 FROM diplomacy dp WHERE status=0 AND \nalliance1=" . $users_result["aid"]) or die($GLOBALS["db"]->error); if (!$results_query) { return false; } while (list($results[$users_result["uid"]]["enemies"][]) = $results_query->fetch_row()) { } // Schiffe gesamt $namefield = "CONCAT(p.name, ' ', IF(c.position='L','[unloaded]',\nIF(c.position='T','[on transport]',IF(c.position='U','[landed]',IF(IFNULL(c.killed_special,'')='E',\n'[disabled]',IF(IFNULL(c.killed_special,'')='R', '[captured]', ''))))))"; $results_query = $GLOBALS["db"]->query("SELECT {$namefield} AS name, \nSUM(c.count_max) AS count FROM combat c INNER JOIN production p \nUSING (prod_id) WHERE uid=" . $users_result["uid"] . " GROUP BY p.name, c.position, c.killed_special") or die($GLOBALS["db"]->error); if (!$results_query) { return false; } while ($unit = $results_query->fetch_assoc()) { $results[$users_result["uid"]]["ships"][$unit["name"]] = $unit["count"]; } // Schiffe zerstört $results_query = $GLOBALS["db"]->query("SELECT {$namefield} AS name, SUM(c.count_max-c.count) AS count,\nIFNULL(c.killed_special,'') AS killed_special FROM combat c INNER JOIN production p \nUSING (prod_id) WHERE uid=" . $users_result["uid"] . " GROUP BY p.name, c.position, c.killed_special") or die($GLOBALS["db"]->error); if (!$results_query) { return false; } while ($unit = $results_query->fetch_assoc()) { if ($unit["killed_special"] != "E" && $unit["killed_special"] != "R") { $results[$users_result["uid"]]["destroyed_ships"][$unit["name"]] = $unit["count"]; } } // Schiffe lebendig $results_query = $GLOBALS["db"]->query("SELECT {$namefield} AS name, SUM(c.count) AS count,\nIFNULL(c.killed_special,'') AS killed_special FROM combat c INNER JOIN production p \nUSING (prod_id) WHERE c.killed_by IS NULL AND uid=" . $users_result["uid"] . " GROUP BY p.name, c.position, \nc.killed_special") or die($GLOBALS["db"]->error); if (!$results_query) { return false; } while ($unit = $results_query->fetch_assoc()) { if ($unit["killed_special"] != "E" && $unit["killed_special"] != "R") { $results[$users_result["uid"]]["remaining_ships"][$unit["name"]] = $unit["count"]; } } } // Planetare Schilde berichten $query = $GLOBALS["db"]->query("SELECT 'Planetary shields' AS name, SUM(c.shield) AS shieldsum, \nSUM(c.shield_max) AS maxsum FROM combat c INNER JOIN production p USING (prod_id) WHERE c.special \nLIKE 'H%'") or die($GLOBALS["db"]->error); while ($result = $query->fetch_assoc()) { if ($result["maxsum"] > 0) { $results[$puid]["ships"][$result["name"]] = $result["maxsum"]; $results[$puid]["destroyed_ships"][$result["name"]] = $result["maxsum"] - $result["shieldsum"]; $results[$puid]["remaining_ships"][$result["name"]] = $result["shieldsum"]; } } $combat_smarty->assign("results", $results); $users_query = $GLOBALS["db"]->query("SELECT DISTINCT uid FROM combat") or die($GLOBALS["db"]->error); if (!$users_query) { return false; } while ($users_result = $users_query->fetch_assoc()) { if ($users_result["uid"] < 0) { $users[$users_result["uid"]] = "BattleSim Side " . $users_result["uid"] * -1; } else { $users[$users_result["uid"]] = get_name_by_uid($users_result["uid"]); } } $combat_smarty->assign("users", $users); ob_start(); $combat_smarty->display("battlereport.tpl"); $report = ob_get_contents(); ob_end_clean(); $combat_smarty->clear_all_assign(); // Report abspeichern if (BATTLE_DESTROY && $combat["shots_fired"] > 0) { $week = dlookup("week", "timeinfo"); $sth = $GLOBALS["db"]->query("INSERT INTO battlereports SET pid={$pid}, sid={$sid}, \nreport='" . addslashes($report) . "', week={$week}") or die($GLOBALS["db"]->error); $report_id = $GLOBALS["db"]->insert_id; $query = $GLOBALS["db"]->query("SELECT DISTINCT uid FROM combat") or die($GLOBALS["db"]->error); while (list($id) = $query->fetch_row()) { $sth = $GLOBALS["db"]->query("INSERT INTO battlereports_user (uid, rid) VALUES ({$id}, {$report_id})") or die($GLOBALS["db"]->error); } $query = $GLOBALS["db"]->query("SELECT DISTINCT aid FROM combat") or die($GLOBALS["db"]->error); while (list($id) = $query->fetch_row()) { $sth = $GLOBALS["db"]->query("INSERT INTO battlereports_alliance (aid, rid) VALUES ({$id}, {$report_id})") or die($GLOBALS["db"]->error); } } if (COMBAT_VERBOSE) { echo "OK! (" . round(read_timer(1), 4) . "s)" . COMBAT_NEWLINE . COMBAT_NEWLINE; } if (!BATTLE_DESTROY) { echo "{$report}" . COMBAT_NEWLINE . COMBAT_NEWLINE; } }
function get_planetDetail($pid) { global $uid; global $map_info; $sth = mysql_query("select * from planets where id='" . $pid . "'"); if (!$sth || !mysql_num_rows($sth)) { return false; } $p_info = mysql_fetch_array($sth); // erzeuge den user tag, der alles nötige über den Besitzer des Planet enthält if ($p_info["uid"]) { $sth = mysql_query("select u.name, u.imperium, a.name as aname, a.color, a.symbol from users u LEFT JOIN alliance a ON u.alliance = a.id where u.id=" . $p_info["uid"]); if (!$sth || !mysql_num_rows($sth)) { return false; } $u_info = mysql_fetch_array($sth); $p_relation = get_uids_relation($uid, $p_info["uid"]); $user_tag = create_user_tag($p_info["uid"], htmlspecialchars($u_info["name"]), htmlspecialchars($u_info["imperium"]), htmlspecialchars($u_info["aname"]), $u_info["color"], $u_info["symbol"], $p_relation); } else { $p_relation = false; } // erzeuge den resource tag, der den derzeitigen resourcen output wiedergibt $resource_tag = create_resource_tag($p_info["metal"], $p_info["energy"], $p_info["mopgas"], $p_info["erkunum"], $p_info["gortium"], $p_info["susebloom"], $p_info["popgain"]); // erzeuge den planeten tag, das alle nötigen infos des planeten enthält if ($p_info["name"] == "Unnamed") { $p_info["name"] = get_planetname($pid); } if ($p_relation == "same" || $p_relation == "allie") { $planet_tag = create_planet_tag($pid, htmlspecialchars($p_info["name"]), $p_info["type"], PIC_ROOT . $p_info["pic"], $p_info["start"], get_poplevel_by_pop($p_info["population"])); $building_tag = create_buildings_tag($pid); $production_tag = create_production_tag($pid); } else { $planet_tag = create_planet_tag($pid, htmlspecialchars($p_info["name"]), $p_info["type"], PIC_ROOT . $p_info["pic"], $p_info["start"]); if (can_scan_planet_surface($pid)) { $building_tag = create_buildings_tag($pid); } } echo "<SR_REQUEST type=\"planet_info\">"; echo $user_tag; echo $resource_tag; echo $planet_tag; echo $building_tag; echo $production_tag; echo "</SR_REQUEST>"; }
function movements() { // mop: reload updaten $sth = mysql_query("update fleet set reload=reload-1 where reload>0"); if (!$sth) { echo "Database failure reload!"; } // mop: alle bewegungen erfassen $fleets = get_global_movements(); for ($i = 0; $i < sizeof($fleets); $i++) { // mop: bewegung an rand des systems (flotte will springen sitzt aber noch auf nem planeten) if ($fleets[$i]["tsid"] != $fleets[$i]["sid"] && $fleets[$i]["pid"] != 0) { // mop: einfach an den rand des systems setzen => pid=0 und der rest bleibt set_flocation($fleets[$i]["fid"], 0, $fleets[$i]["sid"], $fleets[$i]["tpid"], $fleets[$i]["tsid"]); } elseif ($fleets[$i]["tsid"] != $fleets[$i]["sid"]) { move_system_system($fleets[$i]); } elseif ($fleets[$i]["tsid"] == $fleets[$i]["sid"]) { // mop: zu nem planeten if ($fleets[$i]["pid"] != $fleets[$i]["tpid"] && $fleets[$i]["tpid"] != 0) { ticker($fleets[$i]["uid"], "*lfleet.php*Fleet " . $fleets[$i]["name"] . ": arrived at planet " . get_planetname($fleets[$i]["tpid"]), "w"); } set_flocation($fleets[$i]["fid"], $fleets[$i]["tpid"], $fleets[$i]["tsid"], 0, 0); } else { echo "Kaputter Flug!!!!!!!!!\n"; var_dump($fleets[$i]); echo "===================\n"; } } }
function get_name() { $location = get_systemname($this->sid); if ($this->pid) { $location .= " (Orbit of " . get_planetname($this->pid) . ")"; } return $location; }
function start_mission() { global $id; global $uid; global $PHP_SELF; global $imperium; global $pid; $sth = mysql_query("select sum(population) from planets where uid={$uid}"); if (!$sth) { show_error("Database error!"); return 0; } $pop = mysql_fetch_row($sth); $spies = floor($pop[0] / 1000); $sth = mysql_query("select sum(count) from covertops where uid={$uid}"); if (!$sth) { show_error("Database failure!"); return 0; } $count = mysql_fetch_row($sth); if ($count[0] == NULL) { $count[0] = 0; } if ($count[0] == 0 and $spies == 0) { show_message("You don't have enough population to do any covertops!"); return 0; } $sth = mysql_query("select * from covertopsmissions as c , research as r where c.techdepend=r.t_id and r.uid={$uid} and c.id={$id}"); if (!$sth) { show_error("Database error!"); return 0; } if (mysql_num_rows($sth) == 0) { show_message("bbbblllllllllllll"); return 0; } $covertops = mysql_fetch_array($sth); if ($spies - $count[0] < $covertops["count"]) { show_message("You don't have enough free spies!"); return 0; } $sth = mysql_query("select c.id from covertopsmissions as c,ressources as r where c.metal<=r.metal and c.energy<=r.energy and c.mopgas<=r.mopgas and c.erkunum<=r.erkunum and c.gortium<=r.gortium and c.susebloom<=r.susebloom and r.uid={$uid} and c.id={$id}"); if (!$sth) { show_error("Database failure!"); return 0; } if (mysql_num_rows($sth) == 0) { show_error("You don't have enough ressources to start this mission!"); show_status(); return 0; } if ($imperium != "") { //$sth=mysql_query("select id from users where imperium='".addslashes($imperium)."' and id!=$uid"); $sth = mysql_query("select id from users where imperium='" . $imperium . "' and id!={$uid}"); if (!$sth) { show_error("Database error!"); return 0; } if (mysql_num_rows($sth) == 0) { show_message("Hund! 1"); return 0; } if ($covertops["targettype"] == "P" && $pid == "") { $sth = mysql_query("select id from users where imperium='{$imperium}'"); if (!$sth) { show_error("Database failure13!"); return 0; } $uid_target = mysql_fetch_array($sth); $sth = mysql_query("select id,name from planets where uid=" . $uid_target["id"] . " order by name"); if (!$sth) { show_error("Database failure!12"); return 0; } while ($planets = mysql_fetch_array($sth)) { if ($planets["name"] == "Unnamed") { $planets["name"] = get_planetname($planets["id"]); } $select[$planets["name"]] = $planets["id"]; } echo "<form action=\"" . $PHP_SELF . "\" method=post>"; table_start("center", "500"); table_head_text(array("Mission: " . $covertops["descr"]), "2"); table_text(array(" "), "", "", "2", "center", "head"); table_text_open("text", "center"); table_text_design("<img src='arts/idnummer.jpg' width='75' height='50' alt='" . $covertops["descr"] . "'>", "75"); table_text_design($covertops["descr"], "425"); table_text_close(); table_text_open("text", "center"); table_text_design("Target empire", "75"); table_text_design($imperium, "425"); table_text_close(); table_text_open("text", "center"); table_text_design("Time", "75"); table_text_design($covertops["time"], "425"); table_text_close(); table_text_open("text", "center"); table_text_design("Special Info", "75"); table_text_design("dummy", "425"); table_text_close(); table_form_select("Select the targetplanet", "pid", $select, "2", "text", "text"); table_form_submit("Start", "start_mission", "2", "text"); table_end(); form_hidden("imperium", $imperium); form_hidden("id", $id); echo "</form>"; table_end(); } elseif ($covertops["targettype"] == "P") { $sth = mysql_query("select id from planets where id={$pid} and uid!={$uid} and uid!=0"); if (!$sth) { show_error("Database failure!1"); return 0; } if (mysql_num_rows($sth) == 0) { show_error("Hund! 2"); return 0; } proc_start_mission($covertops["id"], $uid, $pid); show_status(); } else { $sth = mysql_query("select id from users where id!={$uid} and imperium='{$imperium}'"); if (!$sth) { show_error("Database failure1!"); return 0; } if (mysql_num_rows($sth) == 0) { show_message("Du Klobrillenvergewaltiger!"); return 0; } $target_uid = mysql_fetch_array($sth); proc_start_mission($covertops["id"], $uid, $target_uid["id"]); show_status(); } } else { $sth = mysql_query("select imperium from users where id!={$uid} order by imperium"); if (!$sth) { show_error("Database failure!"); return 0; } while ($imperiums = mysql_fetch_array($sth)) { $select[$imperiums["imperium"]] = $imperiums["imperium"]; } echo "<form action=\"" . $PHP_SELF . "\" method=post>"; table_start("center", "500"); table_head_text(array("Mission: " . $covertops["descr"]), "2"); table_text(array(" "), "", "", "2", "head"); table_text_open("text", "center"); table_text_design("<img src='arts/o" . $covertops["id"] . ".jpg' width='75' height='50' alt='" . $covertops["descr"] . "'>", "75"); table_text_design($covertops["descr"], "425"); table_text_close(); table_text_open("text", "center"); table_text_design("Time", "75"); table_text_design($covertops["time"], "425", "head"); table_text_close(); table_text_open("text", "center"); table_text_design("Special Info", "75"); table_text_design("dummy", "425", "head"); table_text_close(); table_form_select("Select the target empire", "imperium", $select, "", "text", "text"); table_form_submit("Start", "start_mission", "2", "text"); table_end(); form_hidden("id", $id); echo "</form>"; } }
function show_planet() { global $pid; global $uid; global $PHP_SELF; global $act2; global $act; global $skin; // go_back($PHP_SELF); if ($act2) { $new_act = $act2; } else { $new_act = $act; } $sth = mysql_query("select * from planets where id='{$pid}'"); if (!$sth) { show_error("Database failure!"); return 0; } $planet = mysql_fetch_array($sth); if ($planet["uid"] != $uid) { show_error("I'm not stupid man!"); return 0; } if ($planet["name"] == "Unnamed") { $name = get_planetname($planet["id"]); } else { $name = $planet["name"]; } center_headline($name); $sth = mysql_query("select max(id) from planets where id<{$pid} and uid={$uid}"); if (!$sth) { show_error("Database failure!"); return 0; } $planet = mysql_fetch_row($sth); if ($planet[0] == NULL) { $prev_planet = " "; $prev_head = " "; } else { $prev_planet = "<a href='" . $PHP_SELF . "?act={$new_act}&pid=" . $planet[0] . "'><img src='skins/" . $skin . "_left.jpg' width='30' height='30' border='0' alt='previous planet'></a>"; $prev_head = "<h5>previous planet</h5>"; } $sth = mysql_query("select min(id) from planets where id>{$pid} and uid={$uid}"); if (!$sth) { show_error("Database failure!"); return 0; } $planet = mysql_fetch_row($sth); if ($planet[0] == NULL) { $next_planet = " "; $next_head = " "; } else { $next_planet = "<a href='" . $PHP_SELF . "?act={$new_act}&pid=" . $planet[0] . "'><img src='skins/" . $skin . "_right.jpg' width='30' height='30' border='0' alt='next planet'></a>"; $next_head = "<h5>next planet</h5>"; } table_start("center", "500"); table_text(array($prev_planet, "<a href='" . $PHP_SELF . "?act=Production&pid={$pid}'><img src='skins/" . $skin . "_planetinfo.jpg' width='50' height='50' border='0' alt='Information screen'></a>", "<a href='" . $PHP_SELF . "?act=build&pid={$pid}'><img src='skins/" . $skin . "_buildings.jpg' width='50' height='50' border='0' alt='Bureau of Construction'></a>", "<a href='" . $PHP_SELF . "?pid={$pid}&act=inf'><img src='skins/" . $skin . "_infan.jpg' width='50' height='50' border='0' alt='Base Camp'></a>", "<a href='" . $PHP_SELF . "?act=fleet&pid={$pid}'><img src='skins/" . $skin . "_fleet.jpg' width='50' height='50' border='0' alt='Control Tower'></a>", $next_planet), "center", "125"); table_text(array($prev_head, "<h5>Info</h5>", "<h5>Buildings</h5>", "<h5>Ground Force</h5>", "<h5>Fleet</h5>", $next_head), "center"); table_end(); echo "<br><br>\n"; // return 0; }
function _get_systemplanets($sid) { $sth = mysql_query("select x,sid,uid,metal,energy,mopgas,erkunum,gortium,susebloom,start,id,name,type,population from planets where sid=" . $sid . " order by x"); if (!$sth) { return false; } if (!is_array($this->systemplanets)) { $this->systemplanets = array(); } if (!is_array($this->planets)) { $this->planets = array(); } while ($planet = mysql_fetch_assoc($sth)) { if ($planet["name"] == "Unnamed") { $planet["name"] = get_planetname($planet["id"]); } addslashes($planet["name"]); $this->systemplanets[$sid][] = $planet; $this->planets[$planet["id"]] = $planet; } }
function get_fleets_target($fid) { $sth = mysql_query("select tpid, tsid, pid, sid from fleet_info where fid={$fid}"); if (!$sth || !mysql_num_rows($sth)) { return false; } $target_id = mysql_fetch_array($sth); $fleet_target["planet"]["tid"] = $target_id["tpid"]; $fleet_target["system"]["tid"] = $target_id["tsid"]; $fleet_target["planet"]["id"] = $target_id["pid"]; $fleet_target["system"]["id"] = $target_id["sid"]; if ($target_id["tpid"]) { $fleet_target["planet"]["name"] = get_planetname($target_id[0]); } if ($target_id["tsid"]) { $fleet_target["system"]["name"] = get_systemname($target_id[0]); } return $fleet_target; }
function show_available_fleets() { global $uid; global $pid; global $bewohnbar; global $PHP_SELF; table_start("center", "500"); table_text(array("<a href=\"" . $PHP_SELF . "?act=show_fleets&pid=" . $pid . "&bewohnbar=" . $bewohnbar . "\">Show your own fleets</a>", "<a href=\"" . $PHP_SELF . "?act=show_available_fleets&pid=" . $pid . "&bewohnbar=" . $bewohnbar . "\">Show fleets assigned to you</a>")); table_end(); $sth = mysql_query("select a.milminister,a.id,u.alliance from alliance as a, users as u where a.milminister='{$uid}' and u.alliance = a.id"); if (!$sth) { show_message("Database Failure 1"); return 0; } if ($sth == 0) { show_message("Not working! Fool >:o"); return 0; } $sth = mysql_query("select f.*,p.typ,p.special from fleet as f,production as p where f.milminister='{$uid}' and p.prod_id=f.prod_id order by f.fid"); if (!$sth) { show_error("Database failure! 2"); return 0; } if (mysql_num_rows($sth) == 0) { center_headline("No allied fleets under your command"); return 0; } table_start("center", "80%"); table_head_text(array("Allied Fleets under your command"), "9"); table_text(array(" "), "", "", "9", "text"); table_text(array("Fleet number", "Light Ships", "Medium Ships", "Heavy Ships", "Current Mission", "New Mission", "Behaviour", "ETA", " "), "center", "", "", "head"); while ($part_fleet = mysql_fetch_array($sth)) { if ($part_fleet["fid"] != $fid_old) { $fid_old = $part_fleet["fid"]; $counter++; } $fleet[$counter][] = $part_fleet; } for ($i = 1; $i <= sizeof($fleet); $i++) { $light = ""; $medium = ""; $heavy = ""; for ($j = 0; $j < sizeof($fleet[$i]); $j++) { if ($fleet[$i][$j]["typ"] == "L") { $light += $fleet[$i][$j]["count"]; } if ($fleet[$i][$j]["typ"] == "M") { $medium += $fleet[$i][$j]["count"]; } if ($fleet[$i][$j]["typ"] == "H") { $heavy += $fleet[$i][$j]["count"]; } if ($fleet[$i][$j]["special"] == "O") { $fleet[$i][0]["orbital_colony"] = "O"; } } switch ($fleet[$i][0]["mission"]) { case "0": $mission_text["a"] = "Defending"; $mission_text["b"] = "defend"; break; case "1": $mission_text["a"] = "Attacking"; $mission_text["b"] = "attack"; break; case "4": $mission_text["a"] = "Colonizing"; $mission_text["b"] = "colonize"; break; case "5": $mission_text["a"] = "Invading"; $mission_text["b"] = "invade"; } if ($fleet[$i][0]["pid"] != 0 and $fleet[$i][0]["tsid"] == 0 and $fleet[$i][0]["tpid"] == 0) { $planetname = get_planetname($fleet[$i][0]["pid"]); $mission = $mission_text["a"] . " planet " . $planetname; } if ($fleet[$i][0]["pid"] == 0 and $fleet[$i][0]["tsid"] == 0 and $fleet[$i][0]["tpid"] == 0) { $systemname = get_systemname($fleet[$i][0]["sid"]); $mission = $mission_text["a"] . " system " . $systemname; } if ($fleet[$i][0]["tsid"] != 0 and $fleet[$i][0]["tpid"] == 0) { $systemname = get_systemname($fleet[$i][0]["tsid"]); $mission = "On its way to " . $mission_text["b"] . " system " . $systemname; } if ($fleet[$i][0]["tsid"] != 0 and $fleet[$i][0]["tpid"] != 0) { $planetname = get_planetname($fleet[$i][0]["tpid"]); $mission = "On its way to " . $mission_text["b"] . " planet " . $planetname; } $sth = mysql_query("select x,y,id from systems where id=" . $fleet[$i][0]["sid"]); $system = mysql_fetch_array($sth); $sth = mysql_query("select s.x,s.y,s.id from systems as s,planets as p where s.id=p.sid and p.id={$pid}"); $targetsystem = mysql_fetch_array($sth); if ($targetsystem["id"] == $system["id"]) { $eta = "Already here!"; } else { $sth1 = mysql_query("select max(w.range) from warp as w,research as r where w.tid=r.t_id and r.uid=" . $uid); $range = mysql_fetch_row($sth1); if ($range[0] == NULL) { global $no_warp_tech; $range[0] = $no_warp_tech; } $eta = eta_to_planet($system["x"], $system["y"], $targetsystem["x"], $targetsystem["y"], $range[0], $old); if (!$eta) { $eta = "No route to system"; } else { $eta = $eta[0]; } } $sth = mysql_query("select uid from planets where id={$pid} and uid!=0 and uid!={$uid}"); if (mysql_num_rows($sth) != 0) { $invade = "<option value=\"5\"> Invade Planet"; } if ($fleet[$i][0]["pid"] == $pid) { $sth = mysql_query("select f.fid from inf_transporters as i,fleet as f where i.prod_id=f.prod_id and f.fid=" . $fleet[$i][0]["fid"]); if (mysql_num_rows($sth) != 0) { $transport = "<option value=\"9\"> Transfer Infantery"; } } $new_mission = "<select name=\"newmission\">\n"; $new_mission = $new_mission . "<option value=\"0\">Defend this planet<option value=\"1\">Attack this planet" . $transport . $invade . "</select>"; $behaviour = "<select name=\"behaviour\">\n"; if ($fleet[$i][0]["behaviour"] == 0) { $behaviour = $behaviour . "<option selected value=\"0\">Evasive"; $behaviour = $behaviour . "<option value=\"1\">Aggressive"; } else { $behaviour = $behaviour . "<option value=\"0\">Evasive"; $behaviour = $behaviour . "<option selected value=\"1\">Aggressive"; } $behaviour = $behaviour . "</select>"; if ($light == "") { $light = "0"; } if ($medium == "") { $medium = "0"; } if ($heavy == "") { $heavy = "0"; } echo "<form action=\"" . $PHP_SELF . "\" method=post>"; table_text(array(($k += 1) . "<input type=hidden name=\"fid\" value=\"" . $fleet[$i][0]["fid"] . "\"", $light, $medium, $heavy, $mission, $new_mission, $behaviour, $eta, "<input type=hidden name=\"act\" value=\"newmission\"><input type=hidden name=\"pid\" value=\"" . $pid . "\"><input type=submit value=\"Execute\""), "center", "", "", "text"); echo "</form>"; } table_end(); }
function transfer() { global $uid; global $fleet; global $PHP_SELF; global $HTTP_REFFERRER; if (!is_array($fleet)) { show_error("You have to select a fleet and some ships in order to transfer!"); return 0; } $i = 0; while (list($key, $value) = each($fleet)) { if ($value == "Y") { $fleets[$i] = new fleet($key); if (!$fleets[$i]->uid == $uid) { show_error("Hello! I'm your friend...Why are you trying such nasty things?"); return 0; } if (!$pid) { $pid = $fleets[$i]->pid; $sid = $fleets[$i]->sid; } else { if ($fleets[$i]->pid != $pid || $fleets[$i]->sid != $sid) { show_error("You may only select fleets which are at the same planet and system!"); return 0; } } } $i++; } $new_fleet = new fleet(); echo "<form action=\"" . $PHP_SELF . "\" method=post>"; for ($i = 0; $i < sizeof($fleets); $i++) { $temp_var = "fleet_" . $fleets[$i]->fid; global ${$temp_var}; foreach ((array) ${$temp_var} as $key => $value) { // Überprüfen ob die werte ok sind (key=>prod_id, value=>count) if ($fleets[$i]->ships[$key] && $fleets[$i]->ships[$key][0] >= $value && (int) $value > 0) { // Das wird nachher ausgelesen um die flotten auch um den wert zu reduzieren $fleets[$i]->ships[$key][0] -= $value; $aff_fleets[] = $fleets[$i]->fid; $new_fleet->add_ships_arr(array($key => array($value, $fleets[$i]->ships[$key][1]))); } elseif ($value == 0) { continue; } else { show_error("You entered a wrong shipcount for fleet " . $fleets[$i]->name . "!"); return 0; } form_hidden("fleet_" . $fleets[$i]->fid . "[" . $key . "]", $value); } } $fids = get_fids_by_pid($pid, $uid, $sid); for ($i = 0; $i < sizeof($fleets); $i++) { // mop: was für nen toller hack if (in_array($fleets[$i]->fid, $fids)) { // mop: umdrehen, damit wir das unsetten können ohne das array komplett durchsuchen zu müssen $fids_tmp = array_flip($fids); unset($fids_tmp[$fleets[$i]->fid]); // mop: und wieder zurück $fids = array_flip($fids_tmp); } form_hidden("fid[" . $i . "]", $fleets[$i]->fid); } // mop: wenn fertig fidsarray neubauen $fids = array_values($fids); // mop: jetzt die ausgewählten flotten abwählen for ($i = 0; $i < sizeof($fids); $i++) { $trans_fleets[$i] = new fleet($fids[$i]); } if (sizeof($trans_fleets) == 0) { center_headline("You have no fleets you could transfer these ships to:)"); go_back($_SERVER["PHP_SELF"]); } else { for ($i = 0; $i < sizeof($trans_fleets); $i++) { $head_array = ""; $text_arr = ""; $prod_arr = ""; table_start("center", "80%"); table_head_text(array("Fleet " . $trans_fleets[$i]->name), "20"); $head_array[0] = " "; $prod_arr[0] = ""; $text_arr[0] = "<input type=radio name=\"fleet\" value=\"" . $trans_fleets[$i]->fid . "\">"; reset($trans_fleets[$i]); while (list($prod_id, $ship_arr) = each($trans_fleets[$i]->ships)) { $head_array[] = get_name_by_prod_id($prod_id); $text_arr[] = $ship_arr[0]; } $mission = $trans_fleets[$i]->get_mission(); list($type, $location) = $trans_fleets[$i]->get_location(); if ($type == 0) { $mission_text = $mission[0] . " "; } else { $mission_text = "On its way to " . $mission[1] . " "; } list($location_id, $location_type) = $location; if ($location_type == 0) { $mission_text .= "planet " . get_planetname($trans_fleets[$i]->pid); $location_text = "Planet " . get_planetname($trans_fleets[$i]->pid) . "(" . get_systemname($trans_fleets[$i]->sid) . ")"; } else { $mission_text .= "system " . get_system_coords($trans_fleets[$i]->sid); $location_text = "System " . get_systemname($trans_fleets[$i]->sid); } table_text(array(" "), "", "", "20", "head"); table_text_open(); table_text_design("Mission:", "50", "", "", "smallhead"); table_text_design($mission_text, "", "", "19", "text"); table_text_close(); table_text($head_array, "", "", "", "smallhead"); table_text($text_arr, "", "", "", "text"); table_end(); echo "<br><br>\n"; } form_hidden("act", "transferab"); echo "<center>\n"; echo "<input type=submit value=\"Transfer\">"; echo "</center>\n"; echo "</form>"; } }