Beispiel #1
0
function get_global_SVGTransform($uid, $type = 0, $sid = 0, $innerHeight = 0, $innerWidth = 0)
{
    $homeWorld = get_homeworld($uid);
    $homeSystem = get_sid_by_pid($homeWorld);
    $homeCoords = get_system_coords($homeSystem, 2);
    $homeX = $homeCoords[x];
    $homeY = $homeCoords[y];
    if ($type == 1) {
        $systemCoords = get_system_coords($sid, 2);
        $systemX = $systemCoords[x];
        $systemY = $systemCoords[y];
        if ($innerWidth < 800) {
            $systemCoords = $systemX - $homeX + $innerWidth / 3 . " " . ($systemY - $homeY + $innerHeight / 2);
        } else {
            $systemCoords = $systemX - $homeX + $innerWidth / 2 . " " . ($systemY - $homeY + $innerHeight / 2);
        }
        return $systemCoords;
    } else {
        if ($innerWidth < 800) {
            $systemCoords = -$homeX + $innerWidth / 3 . " " . (-$homeY + $innerHeight / 2);
        } else {
            $systemCoords = -$homeX + $innerWidth / 2 . " " . (-$homeY + $innerHeight / 2);
        }
        return $systemCoords;
    }
}
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;
}
Beispiel #3
0
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] = "&nbsp;";
            $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("&nbsp;"), "", "", "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>";
    }
}