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;
}
Example #2
0
function fleet_is_examinable($fid, $sid = 0)
{
    global $uid;
    $examinable = false;
    if ($sid == 0) {
        $sid = get_sid_by_fid($fid);
    }
    $allies = get_allied_ids($uid);
    if (is_array($allies)) {
        array_push($allies, $uid);
    } else {
        $allies[] = $uid;
    }
    for ($m = 0; $m < sizeof($allies); $m++) {
        if (is_a_fleet_in_system($allies[$m], $sid)) {
            $examinable = true;
            break;
        }
        if (has_a_planet_in_system($allies[$m], $sid) == "true") {
            $examinable = true;
            break;
        }
    }
    return $examinable;
}