Esempio n. 1
0
function eta_to_planet($x, $y, $tx, $ty, $range, $old, $count = "0")
{
    if (!is_array($old)) {
        $old = array();
    } else {
        $old[][$x] = $y;
    }
    // is das System schon in Reichweite???
    $count++;
    $temp_x1 = $tx - $x;
    $temp_x2 = $ty - $y;
    $temp_betrag = sqrt($temp_x1 * $temp_x1 + $temp_x2 * $temp_x2);
    $sth = mysql_query("select id from systems where " . $range . ">=" . $temp_betrag . " and x=" . $tx . " and y=" . $ty);
    if (mysql_num_rows($sth) != 0) {
        reset($old);
        for ($i = 0; $i < sizeof($old); $i++) {
            reset($old[$i]);
            list($x, $y) = each($old[$i]);
            $sth1 = mysql_query("select id from systems where x={$x} and y={$y}");
            if (!$sth1) {
                show_error("Database failure!");
                return 0;
            }
            list($systemid) = mysql_fetch_row($sth1);
            $route[] = $systemid;
        }
        $target = mysql_fetch_row($sth);
        $route[] = $target[0];
        return array($count++, $route);
    }
    // Ersma Zielvektor berechnen
    $x1 = $tx - $x;
    $x2 = $ty - $y;
    // Betrag berechnen
    $betrag = sqrt($x1 * $x1 + $x2 * $x2);
    //echo("Betrag: ".$betrag."\n");
    // Vektor auf Länge $range abschneiden und zum Ortsvektor machen
    $x1 = $x1 * ($range / $betrag) + $x;
    $x2 = $x2 * ($range / $betrag) + $y;
    /* Naechste System suchen
         Erster Abschnitt : Abstand der Systeme vom temp. Vektor
         Zweiter Abschnitt: Nur die Systeme , für die der Abstand vom jetzigen System auch der max. Sprungweite entspricht
       */
    if (is_array($old)) {
        for ($i = 0; $i < sizeof($old); $i++) {
            reset($old[$i]);
            list($key, $value) = each($old[$i]);
            $excl = $excl . " and x!=" . $key . " and y!=" . $value;
        }
    }
    $sth = mysql_query("select sqrt((x-" . $x1 . ")*(x-" . $x1 . ")+(y-" . $x2 . ")*(y-" . $x2 . ")),x,y,id from systems where " . $range . ">=sqrt((x-" . $x . ")*(x-" . $x . ")+(y-{$y})*(y-{$y})) and x!=" . $x . " and y!=" . $y . $excl . " order by 1 limit 1");
    if (mysql_num_rows($sth) == 0) {
        return false;
    }
    $system = mysql_fetch_array($sth);
    //echo("ID ist: ".$system["id"]."\n");
    $way = eta_to_planet($system["x"], $system["y"], $tx, $ty, $range, $old, $count);
    if ($way) {
        //echo($system["id"]."\n");
        return $way;
    }
    return false;
}
Esempio n. 2
0
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("&nbsp;"), "", "", "9", "text");
    table_text(array("Fleet number", "Light Ships", "Medium Ships", "Heavy Ships", "Current Mission", "New Mission", "Behaviour", "ETA", "&nbsp;"), "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();
}