コード例 #1
0
function move_fleet($mission)
{
    global $uid;
    $fid = $_GET["fid"];
    $targetId = $_GET["targetId"];
    $targetType = $_GET["targetType"];
    // planet || system
    $fleet = new fleet($fid);
    // validation
    if ($uid != $fleet->uid) {
        if ($fleet->milminister == 1) {
            $sth = mysql_query("select a.milminister from users u left join alliance a on u.alliance = a.id where u.id = " . $uid);
            if (!$sth) {
                show_svg_message("ERR::GET MoD");
                return false;
            }
            list($its_mod) = mysql_fetch_row($sth);
            if ($its_mod != $uid) {
                show_svg_message("You can not command that fleet");
                return false;
            }
        } else {
            show_svg_message("You can not command that fleet");
            return false;
        }
    }
    if ($targetType == "system") {
        $destination_system = $targetId;
        $destination_planet = 0;
        $destination_name = get_systemname($targetId);
    } else {
        $sth = mysql_query("select sid, name, uid from planets where id = '{$targetId}'");
        if (!$sth || !mysql_num_rows($sth)) {
            return 0;
        }
        $dest_data = mysql_fetch_row($sth);
        $destination_system = $dest_data[0];
        $destination_name = $dest_data[1];
        $destination_planet = $targetId;
        $destination_planet_uid = $dest_data[2];
    }
    $max_warp = get_max_warp($uid);
    $route = move_to($fleet->sid, $destination_system, $max_warp);
    if (is_array($route)) {
        $fleet_mode = "defensive";
        // gucken ob der zielplanet ein feindlicher ist
        if ($destination_planet != 0 && $destination_planet_uid != 0) {
            if (get_uids_relation($uid, $destination_planet_uid) == "enemy") {
                $fleet_mode = "aggressive";
            }
        }
        set_mission($fid, $mission, $destination_system, $destination_planet);
        $its_mission = get_mission_by_mission_id($mission, $fleet_mode);
        set_route($route, $fid);
        $true_eta = get_true_ETA_by_fid($fid);
        $request .= "<SR_REQUEST oid=\"" . $fid . "\" type=\"FLEET_ROUTE\">";
        $request .= "<SR_ROUTE_INFO eta=\"" . $true_eta . "\" targetName=\"" . $destination_name . "\" sid=\"" . $fleet->sid . "\" mission=\"" . $mission . "\" missionName=\"" . $its_mission[0] . "\" missionSymbol=\"" . $its_mission[2] . "\" />";
        // general info
        if ($fleet->sid == $destination_system) {
            if ($destination_planet == 0 || $fleet->pid == 0) {
                if ($destination_planet == 0) {
                    $target_planet = $fleet->pid;
                    $target_system = $destination_system;
                } else {
                    $target_planet = $destination_planet;
                    $target_system = $fleet->sid;
                }
                $request .= "<SR_ROUTE_SYSTEM_TO_PLANET jumpNumber=\"0\" pid=\"" . $target_planet . "\" sid=\"" . $target_system . "\"/>";
            } else {
                $request .= "<SR_ROUTE_PLANET_TO_PLANET jumpNumber=\"0\" pid1=\"" . $fleet->pid . "\" pid2=\"" . $destination_planet . "\" sid=\"" . $fleet->sid . "\"/>";
            }
        } else {
            // wenn die flotte nicht schon überm stern hängt, muss sie erst dahin fliegen um das system zu verlassen
            $a = 0;
            if ($fleet->pid != 0) {
                $request .= "<SR_ROUTE_SYSTEM_TO_PLANET jumpNumber=\"" . $a++ . "\" pid=\"" . $fleet->pid . "\" sid=\"" . $fleet->sid . "\"/>";
            }
            for ($i = 0; $i < sizeof($route); $i++) {
                $request .= "<SR_ROUTE_SYSTEM jumpNumber=\"" . ($i + $a) . "\" sid=\"" . $route[$i] . "\"/>";
            }
            // wenn die flotte nicht zum einem anderen stern fliegt, sondern zu einem planeten, kommt noch ein inter-planetärer flug hinzu
            if ($destination_planet != 0) {
                $request .= "<SR_ROUTE_SYSTEM_TO_PLANET jumpNumber=\"" . ++$i . "\" pid=\"" . $destination_planet . "\" sid=\"" . $destination_system . "\"/>";
            }
        }
        $request .= "</SR_REQUEST>";
        echo $request;
        return true;
    } else {
        show_svg_message("Sir! Our fleet '" . get_fleet_name($_GET["fid"]) . "' can't carry out your command. The targets destination has an insuperable gap that exceeds our warp technolgy of " . $max_warp . " parsec.");
        return false;
    }
}
コード例 #2
0
function quick_colonize($uid, $pid)
{
    if (!habitable($pid)) {
        return false;
    }
    $sth = mysql_query("select p.sid,s.x,s.y from planets as p, systems as s where pid={$pid} and p.sid=s.id");
    if (!$sth || mysql_num_rows($sth) == 0) {
        return false;
    }
    list($sid, $tx, $ty) = mysql_fetch_row($sth);
    $sth = mysql_query("select max(w.range) from warp as w,research as r where w.tid=r.t_id and r.uid=" . $uid);
    if (!$sth || mysql_num_rows($sth) == 0) {
        return false;
    }
    list($range) = mysql_fetch_row($sth);
    $sth = mysql_query("select distinct f.fid,fi.sid from fleet as f, production as p left join fleet_info as fi on f.fid=fi.fid and fi.uid={$uid} where p.prod_id=f.prod_id and fi.fid is not NULL and (p.special='O' or p.special='C')");
    if (!$sth || mysql_num_rows($sth) == 0) {
        return false;
    }
    $found_fid = false;
    $shortest_way = false;
    while ($fid = mysql_fetch_array($sth)) {
        $sth1 = mysql_query("select x,y from systems where id=" . $fid["sid"]);
        if (!$sth1 || mysql_num_rows($sth1) == 0) {
            return false;
        }
        while ($start = mysql_fetch_array($sth1)) {
            $length = eta_to_planet($start["x"], $start["y"], $tx, $ty, $range, array());
            if ($length) {
                if (!$shortest_way) {
                    $shortest_way = $length;
                    $found_fid = $fid["fid"];
                } else {
                    if ($length < $shortest_way) {
                        $shortest_way = $length;
                        $found_fid = $fid["fid"];
                    }
                }
            }
        }
    }
    if ($found_fid) {
        set_mission($found_fid, 4, $sid, $pid);
        return $found_fid;
    } else {
        return false;
    }
}