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 is_in_scanrange($uid, $sid) { global $uid; // erstmal check ob eine eigene bzw. allieerte flotte im system ist $is_in_range = false; if (is_a_fleet_in_system($uid, $sid)) { $is_in_range = true; } else { // flotten von alliierten im system? $allied = get_allied_ids($uid); for ($i = 0; $i < sizeof($allied); $i++) { if (is_a_fleet_in_system($allied[$i], $sid)) { $is_in_range = true; break; } } // ist es denn wenigstens in irgendeinem scanradius des users oder eines allierten? if (!$is_in_range) { $sth = mysql_query("select max(radius) from scanradius"); if (!$sth || mysql_num_rows($sth) == 0) { return 0; } $max_scanrange = mysql_fetch_row($sth); $systems = get_systems_in_scanrange($sid, $max_scanrange[0]); for ($i = 0; $i < sizeof($systems); $i++) { $own_star = is_own_star($systems[$i]); // auch ob er alliiert ist if ($own_star) { // nen gebäude mit ner aussreichenden scanrange? $sth = mysql_query("select p.uid,p.id,s.x,s.y from planets as p, systems as s where p.sid='{$systems[$i]}' and s.id='{$systems[$i]}'"); if (!$sth) { return 0; } while ($planets = mysql_fetch_array($sth)) { if ($planets["uid"] == $uid || is_allied($uid, $planets["uid"])) { $planets_scan_range = get_max_scan_range_by_pid($planets["id"]); if ($planets_scan_range) { $system_coords = get_system_coords($sid); $system_x = substr($system_coords, 0, strpos($system_coords, ":")); $system_y = substr($system_coords, strpos($system_coords, ":") + 1); $entfernung = calculate_distance($planets["x"], $planets["y"], $system_x, $system_y); if ($entfernung <= $planets_scan_range) { $is_in_range = true; } } } } } // end if // oder vielleicht ne flotte? if (!$is_in_range) { // $sth = mysql_query("select s.radius,fi.uid,sy.x,sy.y from scanradius as s,systems as sy, fleet as f, fleetinfo as fi where f.prod_id = s.prod_id and f.fid = fi.fid and fi.sid='$systems[$i]' and and sy.id='$systems[$i]'"); $sth = mysql_query("select fid, uid, sid from fleet_info where sid=" . $systems[$i] . ""); if (!$sth) { return 0; } if (mysql_num_rows($sth) != 0) { while ($flotten = mysql_fetch_array($sth)) { if ($flotten["uid"] == $uid || is_allied($uid, $flotten["uid"])) { $sth2 = mysql_query("select max(s.radius) from scanradius as s, fleet as f where f.fid=" . $flotten["fid"] . " and f.prod_id=s.prod_id"); $fleet_scan_range = mysql_fetch_row($sth2); if ($fleet_scan_range) { $system_coords = get_system_coords($sid); $system_x = substr($system_coords, 0, strpos($system_coords, ":")); $system_y = substr($system_coords, strpos($system_coords, ":") + 1); $fleet_coords = get_system_coords($flotten["{$sid}"]); $fleet_x = substr($fleet_coords, 0, strpos($fleet_coords, ":")); $fleet_y = substr($fleet_coords, strpos($fleet_coords, ":") + 1); $entfernung = calculate_distance($fleet_x, $fleet_y, $system_x, $system_y); if ($entfernung <= $fleet_scan_range) { $is_in_range = true; } } } } } //if (!$sth) //return 0; } } // end for } } return $is_in_range; }
function accept_pending() { global $uid; global $faid; if (has_alliance_lock($uid)) { show_message("You can't use any alliance options due to an alliance lock!"); return false; } $aid = get_alliance($uid); if (!is_leader($uid, $aid)) { show_message("Be aware of the dark side!"); return 0; } $pending_status = get_pending_diplomacy_change($faid, $aid); if (!$pending_status) { show_message("fu! ;)"); return 0; } if (!drop_pending_diplomatic_request($faid, $aid)) { show_error("Database failure!"); return 0; } if (!change_diplomatic_status($aid, $faid, $pending_status)) { show_error("Database failure2!"); return 0; } $f_leader = get_leader($faid); $f_allies = get_allied_ids($f_leader); ticker($f_leader, "*lcommunication.php?act=show_diplomacy*Alliance " . get_alliance_name($aid) . " has accepted your request to change status to " . get_diplomatic_status_text($pending_status), "w"); for ($i = 0; $i < sizeof($f_allies); $i++) { ticker($f_allies[$i], "Alliance " . get_alliance_name($aid) . " has accepted your leaders request to change status to " . get_diplomatic_status_text($pending_status), "w"); } $allies = get_allied_ids(get_leader($aid)); for ($i = 0; $i < sizeof($allies); $i++) { ticker($allies[$i], "Your leader accepted a request from Alliance " . get_alliance_name($faid) . " to change status to " . get_diplomatic_status_text($pending_status), "w"); } show_message("Status changed!"); }
function has_noscan_ships_and_constructions($fid) { // noscan schiffe? $sth = mysql_query("SELECT s.prod_id FROM shipvalues s JOIN fleet f USING(prod_id) WHERE s.special = 'N' and f.fid = " . $fid); if (!$sth) { show_svg_message("ERROR::GETTING NOSCAN SHIPS"); return false; } if (mysql_num_rows($sth) > 0) { return true; } //noscan gebäude? $fleet = new fleet($fid); if ($fleet->pid > 0) { $allies = get_allied_ids($fleet->uid); if (is_array($allies)) { array_push($allies, $fleet->uid); } else { $allies[] = $fleet->uid; } $sth = mysql_query("SELECT s.prod_id FROM planets p, shipvalues s JOIN constructions c USING(prod_id) where s.special='N' and c.pid=p.id and p.id = " . $fleet->pid . " and p.uid in (" . implode(",", $allies) . ")"); if (!$sth) { show_svg_message("ERROR::GETTING NOSCAN CONSTRUCTIONS"); return false; } if (mysql_num_rows($sth) > 0) { return true; } } return false; }