function check()
{
    global $uid;
    global $fleet;
    global $capacity;
    $fid = $_GET["fid"];
    $pid = $_GET["pid"];
    // 1. check ob die flotte eigene bzw. einem zugeordnete flotte ist
    if (!($fleet->uid == $uid || $fleet->milminister == 1 && $uid == get_milminister(get_alliance($uid)))) {
        show_svg_message("Darn, thats not your fleet!");
        return false;
    }
    // 2.check ob die flotte transporter hat
    if (!$capacity) {
        show_svg_message("Doh! This fleet can't hold any groundforces");
        return false;
    }
    // 3. check ob flotte im orbit des planeten ist
    if ($fleet->pid != $pid) {
        show_svg_message("There's no beaming! :P");
        return false;
    }
    // 4. check ob user infantry auf dem planeten hat
    $sth = mysql_query("SELECT 1 FROM infantery i,production p WHERE i.pid=" . $fleet->pid . " and i.prod_id=p.prod_id and p.name!='Militia' and i.uid=" . $uid);
    if (!$sth || mysql_num_rows($sth) == 0) {
        // 4.5 check ob der Planet zu der flotte gehört
        if (!is_allied($fleet->uid, get_uid_by_pid($pid))) {
            show_svg_message("Kidnapping forces ain't looking like a good idea to me!");
            return false;
        }
    }
    return true;
}
 function get_minimap_values($colors = true, $scanrange = true, $fleets = true)
 {
     global $uid;
     $user_alliance = get_alliance($uid);
     if (!$colors) {
         $scanrange = false;
     }
     $sth = mysql_query("select id, uid from planets where sid=" . $this->id . " and uid != 0");
     if (!$sth) {
         return 0;
     }
     while ($its_planets = mysql_fetch_array($sth)) {
         $its_uid = $its_planets["uid"];
         $its_id = $its_planets["id"];
         // minimap_colors
         if ($colors) {
             if ($its_uid == $uid) {
                 $this->minimap_colors[] = "lime";
                 $this->scan = true;
                 // scanrange
                 if ($scanrange) {
                     $its_scanradius = get_max_scan_range_by_pid($its_id);
                 }
             } elseif (is_allied($its_uid, $uid)) {
                 $this->minimap_colors[] = "yellow";
                 $this->scan = true;
                 // scanrange
                 if ($scanrange) {
                     $its_scanradius = get_max_scan_range_by_pid($its_id);
                 }
             } else {
                 $planet_alliance = get_alliance($its_uid);
                 if ($user_alliance && $planet_alliance && is_friendly($user_alliance, $planet_alliance)) {
                     $this->minimap_colors[] = "orange";
                 } elseif ($user_alliance && $planet_alliance && is_enemy($user_alliance, $planet_alliance)) {
                     $this->minimap_colors[] = "red";
                 } else {
                     $this->minimap_colors[] = "blue";
                 }
             }
         }
         // max scanrange ermitteln
         if ($its_scanradius && $this->scanradius < $its_scanradius) {
             $this->scanradius = $its_scanradius;
         }
     }
     // minimap_fleets
     if ($fleets) {
         $sth = mysql_query("select distinct(uid) as unique_uid from fleet_info where sid=" . $this->id);
         if (!$sth || !mysql_num_rows($sth)) {
             return 0;
         }
         while ($its_fleets = mysql_fetch_array($sth)) {
             $its_uid = $its_fleets["unique_uid"];
             if ($its_uid == $uid) {
                 $this->minimap_fleets[] = "lime";
                 $this->scan = true;
                 // scanrange der Flotten
                 if ($scanrange) {
                     $fleet_scanradius = get_max_fleet_scanrange_by_sid($this->id);
                 }
             } elseif (is_allied($its_uid, $uid)) {
                 $this->minimap_fleets[] = "yellow";
                 $this->scan = true;
                 // scanrange der Flotten
                 if ($scanrange) {
                     $fleet_scanradius = get_max_fleet_scanrange_by_sid($this->id);
                 }
             } else {
                 $fleet_alliance = get_alliance($its_uid);
                 if ($user_alliance && $fleet_alliance && is_friendly($user_alliance, $fleet_alliance)) {
                     $this->minimap_fleets[] = "orange";
                 } elseif ($user_alliance && $fleet_alliance && is_enemy($user_alliance, $fleet_alliance)) {
                     $this->minimap_fleets[] = "red";
                 } else {
                     $this->minimap_fleets[] = "blue";
                 }
             }
             if ($fleet_scanradius && $this->scanradius < $fleet_scanradius) {
                 $this->scanradius = $fleet_scanradius;
             }
         }
         // Scanrange
         if ($scanrange) {
             // Systeme in Scanrange
             $visible_systems = get_systems_in_scanrange($this->id, $this->scanradius);
             if (is_array($visible_systems)) {
                 for ($j = 0; $j < sizeof($visible_systems); $j++) {
                     $this->systems_in_scanrange[] = new MINIMAP_SYSTEM($visible_systems[$j]);
                 }
             }
             for ($j = 0; $j < sizeof($this->systems_in_scanrange); $j++) {
                 $this->systems_in_scanrange[$j]->get_minimap_values(true, false, true);
                 $this->systems_in_scanrange[$j]->make_visible();
             }
         }
     }
     // ende WHILE
     if (isset($this->minimap_colors[0])) {
         $this->minimap_colors = array_unique($this->minimap_colors);
     }
     if (isset($this->minimap_fleets[0])) {
         $this->minimap_fleets = array_unique($this->minimap_fleets);
     }
 }
Esempio n. 3
0
function get_fleet_items($id, $sql_foreign_key)
{
    global $uid;
    global $map_info;
    $sth = mysql_query("SELECT * FROM fleet_info WHERE " . $sql_foreign_key . "=" . $id . " order by uid");
    if (!$sth || !mysql_num_rows($sth)) {
        return false;
    }
    $i = 0;
    $ships = array();
    while ($fleets = mysql_fetch_assoc($sth)) {
        $ships[$i] = array();
        $its_fleet = new fleet($fleets["fid"]);
        $its_fid = $fleets["fid"];
        // get fleets userdata
        // ALLIANZ
        $sth2 = mysql_query("select u.name, u.imperium, a.name as alliance_name, a.color, a.symbol, a.milminister from users u left outer join alliance a on a.id=u.alliance where u.id=" . $fleets["uid"]);
        if (!$sth2 || !mysql_num_rows($sth2)) {
            return 0;
        }
        $fleets_user_info = mysql_fetch_array($sth2);
        if ($fleets_user_info["alliance_name"]) {
            $return_array[$i]["allianceName"] = htmlspecialchars($fleets_user_info["alliance_name"]);
            $return_array[$i]["allianceColor"] = $fleets_user_info["color"];
            if ($fleets_user_info["symbol"]) {
                $return_array[$i]["allianceSymbol"] = $fleets_user_info["symbol"];
            } else {
                $return_array[$i]["allianceSymbol"] = 0;
            }
        } else {
            $return_array[$i]["allianceName"] = 0;
            $return_array[$i]["allianceColor"] = 0;
            $return_array[$i]["allianceSymbol"] = 0;
        }
        // all items same data
        $return_array[$i]["picture"] = get_fleet_pic($its_fid);
        $return_array[$i]["topic"] = htmlspecialchars($fleets["name"]);
        $return_array[$i]["description"] = htmlspecialchars($fleets["name"]);
        $return_array[$i]["oid"] = $fleets["fid"];
        $return_array[$i]["sid"] = $fleets["sid"];
        $return_array[$i]["pid"] = $fleets["pid"];
        $return_array[$i]["tsid"] = $fleets["tsid"];
        $return_array[$i]["tpid"] = $fleets["tpid"];
        $return_array[$i]["relationClass"] = get_uids_relation($uid, $fleets["uid"], 1);
        $return_array[$i]["footer"] = false;
        $is_commanded_by_mod = $its_fleet->milminister == 1 && $fleets_user_info["milminister"] == $uid;
        if ($uid == $its_fleet->uid || $is_commanded_by_mod) {
            $its_mission = get_mission_by_mission_id($fleets["mission"]);
            $its_target = get_fleets_target($its_fid);
            // full fleet item, own or borrowed units
            $return_array[$i]["itemType"] = "FULL_FLEET_ITEM";
            $return_array[$i]["type"] = "fleet";
            // sounds
            // okay, suboptimal weil gleiche funkiion schon bei get_fleet_pic aufgerufen wird :S, bin jetzt aba faul
            $strongest_ship = get_strongest_ship_by_fid($its_fid);
            // ggf noch sounds von admirälen einfügen
            $sound_array = get_sound_by_prod_id($strongest_ship);
            $return_array[$i]["soundReport"] = $sound_array["report"];
            $return_array[$i]["soundConfirm"] = $sound_array["confirm"];
            // Target
            if ($its_target["planet"]["tid"] || $its_target["system"]["tid"]) {
                // ETA berechnen
                $return_array[$i]["eta"] = get_true_ETA_by_fid($its_fid);
                if ($its_target["planet"]["tid"]) {
                    $return_array[$i]["target"] = get_planetname($its_target["planet"]["tid"]);
                } else {
                    $return_array[$i]["target"] = get_systemname($its_target["system"]["tid"]);
                }
            }
            // Mission
            $return_array[$i]["missionSymbol"] = $its_mission[2];
            $return_array[$i]["missionName"] = $its_mission[0];
            $return_array[$i]["mission"] = $fleets["mission"];
            // Tactics
            $return_array[$i]["tactic"] = $fleets["tactic"];
            $return_array[$i]["tacticSymbol"] = 0;
            $return_array[$i]["tacticName"] = get_tactic_by_tacticflag($fleets["tactic"]);
            // Reloading?
            $return_array[$i]["reloadSymbol"] = get_reload($its_fid);
            // Infantry aboard?
            $return_array[$i]["infantrySymbol"] = get_infantrycount_by_fid($its_fid);
            // Minister of Defence
            $return_array[$i]["modSymbol"] = $fleets["milminister"];
            // FLEET CONTROL
            //manage fleet
            if (!$is_commanded_by_mod) {
                $return_array[$i]["fleet_control"] .= "<SR_FLEET_CONTROL type=\"SR_SIMPLE_ACTION\" face=\"control_button_manage_fleet.svgz\" controlName=\"manage fleet\" description=\"manage fleet\"/>";
            }
            $planet_uid = get_uid_by_pid($its_fleet->pid);
            // transfer infantry
            if ($its_fleet->get_total_transporter_capacity() > 0 && ($planet_uid == $its_fleet->uid || is_allied($planet_uid, $its_fleet->uid)) || has_infantry_on_planet($its_fleet->pid, $its_fleet->uid)) {
                $return_array[$i]["fleet_control"] .= "<SR_FLEET_CONTROL type=\"SR_SIMPLE_ACTION\" face=\"control_button_inf_transfer.svgz\" controlName=\"transfer infantry\" description=\"transfer infantry\"/>";
            }
        } else {
            // bäh, mir fällt kein anständiges query ein
            $light = 0;
            $medium = 0;
            $heavy = 0;
            $sth3 = mysql_query("select sum(count), typ as shipcount from fleet join production using(prod_id) where fid='" . $its_fid . "' group by typ");
            if (!$sth3 || !mysql_num_rows($sth3)) {
                return 0;
            }
            while (list($shipcount, $typ) = mysql_fetch_row($sth3)) {
                switch ($typ) {
                    case "L":
                        $light = $shipcount;
                        break;
                    case "M":
                        $medium = $shipcount;
                        break;
                    case "H":
                        $heavy = $shipcount;
                        break;
                }
            }
            $return_array[$i]["footer"] = $heavy . " " . $medium . " " . $light;
            $return_array[$i]["type"] = "fleet";
            $return_array[$i]["text1"] = htmlspecialchars($fleets_user_info["name"]);
            $return_array[$i]["text2"] = htmlspecialchars($fleets_user_info["imperium"]);
            if ($return_array[$i]["relationClass"] == "colorAllied") {
                $return_array[$i]["itemType"] = "ADVANCED_FLEET_ITEM";
                $return_array[$i]["fleet_control"] .= "<SR_FLEET_CONTROL type=\"SR_SIMPLE_ACTION\" face=\"control_button_examine_fleet.svgz\" controlName=\"examine fleet\" description=\"view fleet details\"/>";
            } else {
                $return_array[$i]["itemType"] = "FLEET_ITEM";
                // fleet control buttons, keine Attribute sondern childs, nur nach den Attributen im $return_array auflisten!
                // special actions
                $special_actions = get_special_fleet_actions($its_fid, "fleet");
                if (is_array($special_actions)) {
                    for ($j = 0; $j < sizeof($special_actions); $j++) {
                        $return_array[$i]["fleet_control"] .= "<SR_FLEET_CONTROL type=\"SR_SPECIAL_ACTION\" face=\"" . $special_actions[$j]["picture"] . "\" controlName=\"" . $special_actions[$j]["name"] . "\" description=\"" . $special_actions[$j]["description"] . "\" controlId=\"" . $special_actions[$j]["action_id"] . "\"";
                        $return_array[$i]["fleet_control"] .= " metal=\"" . $special_actions[$j]["metal"] . "\" energy=\"" . $special_actions[$j]["energy"] . "\" mopgas=\"" . $special_actions[$j]["mopgas"] . "\" erkunum=\"" . $special_actions[$j]["erkunum"] . "\" gortium=\"" . $special_actions[$j]["gortium"] . "\" susebloom=\"" . $special_actions[$j]["susebloom"] . "\"/>";
                    }
                }
                // fleet control EXAMINE FLEET falls die flotte sich in unmittelbarer Nähe zu dem user und seinen alliierten befindet
                if (fleet_is_examinable($its_fid, $its_fleet->sid) == "true") {
                    $return_array[$i]["fleet_control"] .= "<SR_FLEET_CONTROL type=\"SR_SIMPLE_ACTION\" face=\"control_button_examine_fleet.svgz\" controlName=\"examine fleet\" description=\"view fleet details\"/>";
                    if (has_noscan_ships_and_constructions($its_fid)) {
                        $return_array[$i]["picture"] = "animationRauschen";
                        $return_array[$i]["footer"] = "0 0 0";
                    }
                } else {
                    // wenn in scanrange, aber nicht wirklih sichbar, picture zu p_unknown.jpg ändern
                    $return_array[$i]["picture"] = PIC_ROOT . "p_unknown.png";
                    if (has_noscan_ships_and_constructions($its_fid)) {
                        $return_array[$i]["footer"] = "0 0 0";
                    }
                }
            }
        }
        if ($uid == $its_fleet->uid || $map_info->is_allied($its_fleet->uid) || fleet_is_examinable($its_fid)) {
            // mop: alle schiffsnamen
            $prod_ids = array_keys($its_fleet->ships);
            $sth2 = mysql_query("select prod_id,name,typ from production where prod_id in (" . implode(",", $prod_ids) . ")");
            while (list($prod_id, $name, $typ) = mysql_fetch_row($sth2)) {
                $ship_data = $its_fleet->ships[$prod_id];
                $ship_data[] = $name;
                $ship_data[] = $typ;
                $ships[$i][$prod_id] = $ship_data;
                // mop: enthält dann array aus count und reload
            }
        }
        $i++;
    }
    return array($return_array, $ships);
}
Esempio n. 4
0
function get_max_fleet_scanrange_by_sid($sid, $user_id = 0)
{
    global $uid;
    if (!$user_id) {
        $user_id = $uid;
    }
    $sth = mysql_query("select fid from fleet_info where sid=" . $sid);
    if (!$sth || !mysql_num_rows($sth)) {
        return 0;
    }
    while ($its_fleets = mysql_fetch_array($sth)) {
        $its_user = get_uid_by_fid($its_fleets["fid"]);
        if ($its_user == $user_id || is_allied($its_user, $user_id)) {
            $scanrange[] = get_max_scanrange_by_fid($its_fleets["fid"]);
        }
    }
    if (is_array($scanrange)) {
        rsort($scanrange);
        $max_scanrange = $scanrange[0];
    } else {
        $max_scanrange = 0;
    }
    return $max_scanrange;
}
function draw_jumpgate($sid)
{
    global $map_info;
    $jumpgate_pid = get_pid_of_jumpgate($sid);
    if ($jumpgate_pid) {
        echo "<g onclick=\"clickOnJumpGate(evt)\" id=\"j" . $sid . "\">\n";
        echo "<g transform=\"translate(10 -30)\">\n";
        echo "<g>\n";
        echo "<use xlink:href=\"#sJumpgate\" id=\"j" . $sid . "UseElement\" x=\"0\" y=\"0\"/>\n";
        if ($uid == get_uid_by_pid($jumpgate_pid) || is_allied($uid, get_uid_by_pid($jumpgate_pid))) {
            echo "<noPass />";
            $jumpgate_prod_id = get_jumpgate_by_pid($jumpgate_pid);
            $current_tonnage = get_jumpgate_used_tonnage($jumpgate_pid);
            if ($current_tonnage != 0) {
                $max_tonnage = get_jumpgate_max_tonnage($jumpgate_prod_id);
                $tonnage_percent = 0.3 * ($current_tonnage * 100) / $max_tonnage;
                // 0.3 weil die anzeige exakt 30 pixel groß ist
                echo "<clipPath id=\"cJumpgate" . $sid . "\">";
                echo "<rect x=\"34\" y=\"" . $tonnage_percent . "\" width=\"4\" height=\"" . (30 - $tonnage_percent) . "\"/>";
                echo "</clipPath>";
                echo "<rect x=\"35\" y=\"0\" width=\"2\" height=\"" . $tonnage_percent . "\" style=\"stroke:blue;stroke-width:0.2pt;fill:black;\"/>";
                echo "<rect clip-path=\"url(#cJumpgate" . $sid . ")\" clip-rule=\"nonzero\" x=\"35\" y=\"0\" fill=\"url(#gLRedGreen)\" width=\"2\" height=\"30\" style=\"stroke:blue;stroke-width:0.2pt;\"/>";
            } else {
                echo "<rect x=\"35\" y=\"0\" fill=\"url(#gLRedGreen)\" width=\"2\" height=\"30\" style=\"stroke:blue;stroke-width:0.2pt;\"/>";
            }
        }
        if ($map_info->has_map_anims()) {
            echo "<animateTransform attributeType=\"XML\" attributeName=\"transform\" type=\"rotate\" values=\"360;0\" dur=\"" . ($j + 2) * 100 . "\" repeatCount=\"indefinite\"/>";
        }
        echo "</g>";
        echo "</g>";
        if ($map_info->has_map_anims()) {
            echo "<animateTransform attributeType=\"XML\" attributeName=\"transform\" type=\"rotate\" values=\"0;360\" dur=\"" . ($j + 2) * 100 . "\" repeatCount=\"indefinite\"/>";
        }
        echo "</g>\n";
    }
}
 function shipbattle($simulation = false, $aarray = null, $darray = null)
 {
     // einfach nur ne simulation?
     if ($simulation) {
         $this->prepare_simulation($aarray, $darray);
     } else {
         // Ersma alle flotten raussuchen, die mit anderen flotten, die einem nich gehören auf einem fleck hocken
         $sth = mysql_query("select f1.fid,f1.pid,f1.sid,f1.uid,f1.mission from fleet_info f1,fleet_info f2 where f1.uid!=f2.uid and f1.pid=f2.pid and f1.sid=f2.sid group by f1.fid order by f1.pid,f1.sid");
         if (!$sth) {
             echo "Database failure!";
         }
         while ($poss_battle = mysql_fetch_array($sth)) {
             // neue pid und sid?
             if ($poss_battle["pid"] != $last_pid && $poss_battle["sid"] != $last_sid) {
                 if (!isset($i)) {
                     $i = 0;
                 } else {
                     $i++;
                 }
                 // neuen container erzeugen
                 $poss_battle_locations[$i] = new possible_battle_container();
                 $poss_battle_locations[$i]->sid = $poss_battle["sid"];
                 $poss_battle_locations[$i]->pid = $poss_battle["pid"];
                 $last_pid = $poss_battle["pid"];
                 $last_sid = $poss_battle["sid"];
             }
             $poss_battle_locations[$i]->fleets[$poss_battle["uid"]][] = array("fid" => $poss_battle["fid"], "mission" => $poss_battle["mission"]);
         }
         // so jetzt die uids pro location vergleichen und schauen ob nen kampf zustande kommt und die battlelocations indizes sichern
         for ($i = 0; $i < sizeof($poss_battle_locations); $i++) {
             $battle_location[$i] = new possible_battle_container();
             $battle_location[$i]->pid = $poss_battle_locations[$i]->pid;
             $battle_location[$i]->sid = $poss_battle_locations[$i]->sid;
             $nachzuegler = array();
             $uids = array_keys($poss_battle_locations[$i]->fleets);
             $uids = array_flip($uids);
             $owner = get_uid_by_pid($poss_battle_locations[$i]->pid);
             $owner_alliance = get_alliance($owner);
             while (list($uid, $dummy) = each($poss_battle_locations[$i]->fleets)) {
                 $uids_temp = $uids;
                 unset($uids_temp[$uid]);
                 reset($uids_temp);
                 while (list($second_uid, $dummy) = each($uids_temp)) {
                     $alliance = get_alliance($uid);
                     $sec_alliance = get_alliance($second_uid);
                     if (is_enemy($alliance, $sec_alliance)) {
                         $battle_location[$i]->fleets[$uid] = $poss_battle_locations[$i]->fleets[$uid];
                         $battle_location[$i]->fleets[$second_uid] = $poss_battle_locations[$i]->fleets[$second_uid];
                         unset($poss_battle_locations[$i]->fleets[$second_uid]);
                         echo "BLA\n";
                     } elseif (is_allied($alliance, $sec_alliance) || is_friendly($alliance, $sec_alliance)) {
                         $nachzuegler[] = $poss_battle_locations[$i]->fleet[$second_uid];
                         unset($poss_battle_locations[$i]->fleets[$second_uid]);
                     } elseif (is_enemy($alliance, $owner_alliance)) {
                         for ($j = 0; $j < sizeof($poss_battle_locations[$i]->fleets[$uid]); $j++) {
                             if ($poss_battle_locations[$i]->fleets[$uid][$j]["mission"] == 3 || $poss_battle_locations[$i]->fleets[$uid][$j]["mission"] == 5) {
                                 // invading oder bombarding? ziemlicher gayer hack :S
                                 $battle_location[$i]->fleets[$uid] = $poss_battle_locations[$i]->fleets[$uid];
                             }
                         }
                     } else {
                         // neutrale müssen nochmal gesondert betrachtet werden deswegen kein unset
                     }
                 }
             }
             // mop: wenn es ne freund/feind situation irgendwie gibt, dann müssen die nachzuegler mit rein
             if (is_array($battle_location[$i]->fleets)) {
                 for ($j = 0; $j < sizeof($nachzuegler); $j++) {
                     $battle_location[$i]->fleets = array_merge($battle_location[$i]->fleets, $nachzuegler[$j]);
                 }
                 echo "BLA2\n";
             }
         }
         echo "BLA3\n";
         var_dump($battle_location);
         // jetzt haben wir die battlelocations...nun wirds interessant...wir müssen die ganze hundescheisse jetzt nach defenders und
         // attackers umdröseln
         for ($i = 0; $i < sizeof($battle_location); $i++) {
             echo "=> {$i}\n";
             $this->a_uids = array();
             $this->d_uids = array();
             $this->attackers = array();
             $this->defenders = array();
             $this->report = new battlereport();
             $this->report->pid = $battle_location[$i]->pid;
             $this->report->sid = $battle_location[$i]->sid;
             if (is_array($battle_location[$i]->fleets)) {
                 echo "JO\n";
                 // dann muss es da auch irgendwas zum kampftrollen geben
                 if ($battle_location[$i]->pid == 0) {
                     echo "JO=>2\n";
                     if ($intercepting = $battle_location[$i]->find_intercepting_uid()) {
                         $this->d_uids[] = $intercepting;
                         for ($j = 0; $j < sizeof($battle_location[$i]->fleets[$intercepting]); $j++) {
                             $battlefleet = new battlefleet($battle_location[$i]->fleets[$intercepting][$j]["fid"], 0);
                             $this->report->add_fleet($battlefleet);
                             $this->defenders[] = $battlefleet;
                         }
                         $d_alliance = get_alliance($intercepting);
                         // verteidigende allianz sichern
                         reset($battle_location[$i]->fleets);
                         while (list($uid, $fleet) = each($battle_location[$i]->fleets)) {
                             if ($uid != $this->d_uids[0]) {
                                 if (is_enemy($d_alliance, get_alliance($uid))) {
                                     if (!in_array($uid, $this->a_uids)) {
                                         $this->a_uids[] = $uid;
                                         for ($j = 0; $j < sizeof($fleet); $j++) {
                                             $battlefleet = new battlefleet($fleet[$j]["fid"], 1);
                                             $this->report->add_fleet($battlefleet);
                                             $this->attackers[] = $battlefleet;
                                         }
                                     }
                                 } elseif (is_friendly($d_alliance, get_alliance($uid)) || is_allied($d_alliance, get_alliance($uid))) {
                                     if (!in_array($uid, $this->d_uids)) {
                                         $this->d_uids[] = $uid;
                                         for ($j = 0; $j < sizeof($fleet); $j++) {
                                             $battlefleet = new battlefleet($fleet[$j]["fid"], 0);
                                             $this->report->add_fleet($battlefleet);
                                             $this->defenders[] = $battlefleet;
                                         }
                                     }
                                 } else {
                                     echo "Neutral Player detected :S\n";
                                 }
                             }
                         }
                     } else {
                         // :S
                     }
                 } else {
                     echo "JO2\n";
                     $owner = get_uid_by_pid($battle_location[$i]->pid);
                     $planet_active = false;
                     if (in_array($owner, array_keys($battle_location[$i]->fleets))) {
                         $this->d_uids[] = $owner;
                     } else {
                         $owner = array_rand($battle_location[$i]->fleets);
                         $this->d_uids[] = $owner;
                         echo "Owner ist => " . $owner . "\n";
                     }
                     for ($j = 0; $j < sizeof($battle_location[$i]->fleets[$owner]); $j++) {
                         $battlefleet = new battlefleet($battle_location[$i]->fleets[$owner][$j]["fid"], 0);
                         $this->report->add_fleet($battlefleet);
                         $this->defenders[] = $battlefleet;
                     }
                     $d_alliance = get_alliance($owner);
                     // verteidigende allianz sichern
                     reset($battle_location[$i]->fleets);
                     while (list($uid, $fleet) = each($battle_location[$i]->fleets)) {
                         if ($uid != $this->d_uids[0]) {
                             if (is_enemy($d_alliance, get_alliance($uid))) {
                                 if (!in_array($uid, $this->a_uids)) {
                                     $this->a_uids[] = $uid;
                                     for ($j = 0; $j < sizeof($fleet); $j++) {
                                         $battlefleet = new battlefleet($fleet[$j]["fid"], 1);
                                         if ($battlefleet->mission == 3) {
                                             $planet_active = true;
                                             $planet_attack_type = 0;
                                         } elseif ($battlefleet->mission == 5) {
                                             $planet_active = true;
                                             $planet_attack_type = 1;
                                         }
                                         $this->report->add_fleet($battlefleet);
                                         $this->attackers[] = $battlefleet;
                                     }
                                 }
                             } elseif (is_friendly($d_alliance, get_alliance($uid)) || is_allied($d_alliance, get_alliance($uid))) {
                                 if (!in_array($uid, $this->d_uids)) {
                                     $this->d_uids[] = $uid;
                                     for ($j = 0; $j < sizeof($fleet); $j++) {
                                         $battlefleet = new battlefleet($fleet[$j]["fid"], 0);
                                         $this->report->add_fleet($battlefleet);
                                         $this->defenders[] = $battlefleet;
                                     }
                                 }
                             } else {
                                 echo "Neutral Player detected :S\n";
                             }
                         }
                     }
                 }
                 if ($planet_active) {
                     // d_uids wurde schon vorher hinzugfügt
                     $battleplanet = new battleplanet($battle_location[0]->pid, $planet_attack_type);
                     $this->report->add_planet($battleplanet);
                     $this->defenders[] = $battleplanet;
                 }
             }
             if (sizeof($this->a_uids) > 0 && sizeof($this->d_uids) > 0) {
                 $this->attackers_count = sizeof($this->attackers);
                 $this->defenders_count = sizeof($this->defenders);
                 $this->prepare_battle();
                 $this->do_battle();
                 $this->destroy_ships();
                 $this->report->do_report();
             }
         }
     }
 }
Esempio n. 7
0
function get_uids_relation($uid1, $uid2, $type = 0)
{
    if ($uid1 == $uid2) {
        $type == 0 ? $relation = "same" : ($relation = "colorOwn");
    } elseif (is_allied($uid1, $uid2)) {
        $type == 0 ? $relation = "allie" : ($relation = "colorAllied");
    } else {
        $alliance1 = get_alliance($uid1);
        $alliance2 = get_alliance($uid2);
        if ($alliance1 && $alliance2) {
            if (is_friendly($alliance1, $alliance2)) {
                $type == 0 ? $relation = "friend" : ($relation = "colorFriend");
            } elseif (is_enemy($alliance1, $alliance2)) {
                $type == 0 ? $relation = "enemy" : ($relation = "colorEnemy");
            } else {
                $type == 0 ? $relation = "neutral" : ($relation = "colorNeutral");
            }
        } else {
            $type == 0 ? $relation = "neutral" : ($relation = "colorNeutral");
        }
    }
    return $relation;
}
Esempio n. 8
0
function is_own_fleet($fid, $type = 0)
{
    global $uid;
    $fleet_uid = get_uid_by_fid($fid);
    if ($type == 0) {
        if ($uid == $fleet_uid) {
            return true;
        } else {
            return false;
        }
    } else {
        if ($uid == $fleet_uid || is_allied($uid, $fleet_uid)) {
            return true;
        } else {
            return false;
        }
    }
}