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;
}
/** 
 * zeigt die reports der allianz an 
 * 
 * @return 
 */
function show_alliance()
{
    global $uid;
    // mop: instanzname
    $instanz = "reports_own";
    // mop: act
    $act = "show_alliance";
    // mop: betroffene tabellen
    $tables = "battlereports b,battlereports_alliance ba,systems s left join planets p on (p.id=b.pid)";
    // mop: alle felder, die angezeigt werden sollen
    $fields = array("Week" => "b.week", "System" => "s.name", "Planet" => "p.name");
    $where_addon = print_searchform($instanz, $act);
    if (!$where_addon) {
        $where_addon .= "where 1=1";
    }
    $where_addon .= " and b.id=ba.rid and s.id=b.sid and ba.aid=" . get_alliance($uid);
    $browser = new srbrowser($tables, "b.week", $fields, $act, $instanz, "b.id", $GLOBALS["db"]);
    $browser->tabellenkopftext = "Alliance Battlereports";
    browse_reports($browser, $where_addon);
}
Example #3
0
function combat_commit($pid)
{
    global $combat;
    if (COMBAT_VERBOSE) {
        echo "Kampf wird durchgeführt..." . COMBAT_NEWLINE;
    }
    // Los geht's! Alle Einheiten werden durchlaufen...
    $puid = get_uid_by_pid($pid);
    $paid = get_alliance($puid);
    $ini_loop_qry = $GLOBALS["db"]->query("SELECT id FROM combat WHERE aid<>0 AND initiative >= 0 \nAND killed_by IS NULL AND position <> 'T' AND position <> 'L' ORDER BY initiative DESC, \nRand()") or die($GLOBALS["db"]->error);
    $time_target = 0;
    $time_shoot = 0;
    if (!$ini_loop_qry) {
        return false;
    }
    while ($ini_unit = $ini_loop_qry->fetch_assoc()) {
        $unit =& $combat[$ini_unit["id"]];
        $startcount = $unit["count"];
        for ($group = 1; $group <= $startcount; $group++) {
            if (COMBAT_MAXIMUM_VERBOSITY) {
                $verbose_info_qry = $GLOBALS["db"]->query("SELECT * FROM production WHERE prod_id=" . $unit["prod_id"]) or die($GLOBALS["db"]->error);
                $verbose_info = $verbose_info_qry->fetch_assoc();
                echo "&nbsp;&nbsp;" . $unit["uid"] . "/" . $unit["aid"] . "/" . $unit["initiative"] . "/" . $unit["ecm"] . " " . $verbose_info["name"] . " " . $unit["id"] . " Squad {$group}/{$startcount}: ";
            }
            if ($unit["position"] == "L") {
                if (COMBAT_MAXIMUM_VERBOSITY) {
                    echo "group has landed already!";
                }
                break;
            }
            // Lebe ich überhaupt noch?
            if (is_null($unit["killed_by"])) {
                // Bin ich ein beladener Transporter? Mag ich abladen?
                if ($unit["transport_capacity"] > 0 && $unit["mission"] == M_INVADE && dcount("id", "combat", "on_transport=" . $unit["id"]) > 0) {
                    // Und ist der Planet überhaupt feindlich?? Sind die Schilde schon aus?
                    // Oder darf ich durch Schilde durchfliegen?
                    if (is_enemy($paid, $unit["aid"])) {
                        if (dcount("id", "combat", "count > 0 AND special LIKE 'H%'") == 0 || $unit["special"] == "P") {
                            // Okaydo, los geht's mit Abwehrfeuer
                            if (COMBAT_MAXIMUM_VERBOSITY) {
                                echo "INVADE ";
                            }
                            $query = $GLOBALS["db"]->query("SELECT id FROM combat WHERE special='D' AND count>0 \n  AND counterfire<num_attacks*2") or die($GLOBALS["db"]->error);
                            while (list($d_id) = $query->fetch_row()) {
                                if (COMBAT_MAXIMUM_VERBOSITY) {
                                    echo "counterfire ";
                                }
                                for ($i = $combat[$d_id]["counterfire"]; $i < $combat[$d_id]["num_attacks"] * 2; $i++) {
                                    if (combat_shoot_unit($d_id, $unit["id"], true) == "KILLED") {
                                        break;
                                    }
                                }
                                if ($unit["count"] <= 0) {
                                    break;
                                }
                            }
                            if ($unit["count"] > 0) {
                                $combat["shots_fired"]++;
                                $sth = $GLOBALS["db"]->query("UPDATE combat SET position='U', on_transport=NULL WHERE \n        on_transport=" . $unit["id"] . " AND killed_by IS NULL") or die($GLOBALS["db"]->error);
                                // Transporter gelandet?
                                if ($GLOBALS["db"]->affected_rows > 0) {
                                    $sth = $GLOBALS["db"]->query("UPDATE combat SET position='L' WHERE id=" . $unit["id"]);
                                    $unit["position"] = "L";
                                    if (COMBAT_MAXIMUM_VERBOSITY) {
                                        echo "UNLOAD ";
                                    }
                                }
                            }
                        }
                    }
                }
                // Kann ich denn schießen?
                if ($unit["weaponpower"] > 0 && $unit["num_attacks"] > 0 && $unit["count"] > 0) {
                    // Jau, also schnell ein paar Werte geladen...
                    unset($target_pos_ar);
                    $target_pos = $unit["position"];
                    $target_pos_ar[] = $unit["position"];
                    if ($unit["special"] == "B" && ($unit["mission"] == M_BOMB || $unit["mission"] == M_INVADE)) {
                        $target_pos = "P,O";
                        $target_pos_ar[] = "P";
                    }
                    if ($unit["special"] == "D") {
                        if (COMBAT_MAXIMUM_VERBOSITY) {
                            echo "orbital defense ";
                        }
                        $target_pos = "O";
                        unset($target_pos_ar);
                        $target_pos_ar[] = "O";
                    }
                    // Dann schauen wir doch mal nach einem Primärziel
                    $guns_fired = 0;
                    $living = 1;
                    do {
                        $found_target = false;
                        // Sensoren ausreichend?
                        $sensor_check = mt_rand(0, $unit["sensor"]);
                        $digger_luck = mt_rand(1, 100 + $sensor_check);
                        // Letztes Ziel noch mal?
                        if ($last_target[$unit["aid"]] && $last_target[$unit["aid"]]["ecm"] <= $sensor_check && $last_target[$unit["aid"]]["size_num"] == $unit["target1_num"]) {
                            if (is_null($last_target[$unit["aid"]]["killed_by"]) && $digger_luck > $last_target[$unit["aid"]]["digin_depth"] + $last_target[$unit["aid"]]["digin_bonus"] && in_array($last_target[$unit["aid"]]["position"], $target_pos_ar)) {
                                if (COMBAT_MAXIMUM_VERBOSITY) {
                                    echo "(last trg) ";
                                }
                                $found_target = true;
                                $target =& $combat[$last_target[$unit["aid"]]["id"]];
                            } else {
                                unset($last_target[$unit["aid"]]);
                            }
                        } else {
                            unset($last_target[$unit["aid"]]);
                        }
                        start_timer(1);
                        if (!$found_target) {
                            $target_id = combat_acquire_target($unit, $target_pos, $sensor_check, $digger_luck);
                            if ($target_id) {
                                $target =& $combat[$target_id];
                                $found_target = true;
                                if ($target["aid"] == $unit["aid"]) {
                                    echo "ALERT({$target_id})!!";
                                    combat_validate_index("alert_trigger");
                                }
                            }
                        }
                        $time_target += read_timer(1);
                        if ($found_target) {
                            $last_target[$unit["aid"]] =& $combat[$target["id"]];
                            if (COMBAT_MAXIMUM_VERBOSITY) {
                                $verbose_info_qry = $GLOBALS["db"]->query("SELECT * FROM production WHERE prod_id=" . $target["prod_id"]) or die($GLOBALS["db"]->error);
                                $verbose_info = $verbose_info_qry->fetch_assoc();
                                echo "TARGET(" . $target["uid"] . "/" . $target["aid"] . " " . $verbose_info["name"] . " [" . $target["count"] . "] " . $target["id"] . ") ";
                            }
                            do {
                                $guns_fired++;
                                start_timer(1);
                                $shoot_val = combat_shoot_unit($unit["id"], $target["id"], false);
                                if ($shoot_val == "KILLED") {
                                    $target["counterfire"] = 0;
                                }
                                $time_shoot += read_timer(1);
                                if ($shoot_val != "KILLED" && $target["hull"] > 0 && $target["counterfire"] < $target["num_attacks"] && ($target["position"] == $unit["position"] || $target["position"] != $unit["position"] && $target["special"] == "D")) {
                                    if (COMBAT_MAXIMUM_VERBOSITY) {
                                        echo "counterfire ";
                                    }
                                    $target["counterfire"]++;
                                    start_timer(1);
                                    $shoot_val = combat_shoot_unit($target["id"], $unit["id"], true);
                                    if ($shoot_val == "KILLED") {
                                        $guns_fired = $unit["num_attacks"];
                                    }
                                    $time_shoot += read_timer(1);
                                }
                            } while ($guns_fired < $unit["num_attacks"] && $unit["hull"] > 0 && $target["hull"] > 0);
                            if ($target["hull"] > 0) {
                                $sth = $GLOBALS["db"]->query("UPDATE combat SET counterfire=" . $target["counterfire"] . " WHERE id=" . $target["id"]);
                            } else {
                                unset($last_target[$unit["aid"]]);
                            }
                        } else {
                            if (COMBAT_MAXIMUM_VERBOSITY) {
                                echo "no more targets, ";
                            }
                        }
                    } while ($found_target && $guns_fired < $unit["num_attacks"] && $unit["hull"] > 0);
                    if (COMBAT_MAXIMUM_VERBOSITY) {
                        echo "finished. Totally " . $guns_fired . " guns fired." . COMBAT_NEWLINE;
                    }
                } else {
                    if (COMBAT_MAXIMUM_VERBOSITY) {
                        echo "unarmed!" . COMBAT_NEWLINE;
                    }
                }
            } else {
                if (COMBAT_MAXIMUM_VERBOSITY) {
                    echo "dead already!" . COMBAT_NEWLINE;
                }
            }
        }
    }
    if (COMBAT_VERBOSE) {
        echo "...Kampf beendet! Schießen: " . round($time_shoot, 4) . "s; Zielen: " . round($time_target, 4) . "s" . COMBAT_NEWLINE . COMBAT_NEWLINE;
    }
}
Example #4
0
function show_ships_rankings()
{
    global $PHP_SELF;
    global $uid;
    $user_alliance = get_alliance($uid);
    $counter = 1;
    table_text_open("text");
    table_text_design("User rankings by ships", "", "", "5", "head");
    table_text_close();
    table_text_open("text");
    table_text_design("<br>", "", "", "5", "text");
    table_text_close();
    table_text_open("head");
    table_text_design("Place", "", "", "", "head");
    table_text_design("Player", "", "", "", "head");
    table_text_design("Empire", "", "", "", "head");
    table_text_design("Alliance", "", "", "", "head");
    table_text_design("Ships", "", "", "", "head");
    table_text_close();
    $sth = mysql_query("select sum(f.count) as ship_count, u.name as uname, u.imperium, a.name as aname, a.color, a.id as aid,u.id as uid from fleet f left join fleet_info fi using(fid), users u left join alliance a on a.id = u.alliance where u.id = fi.uid group by u.id order by ship_count DESC LIMIT 100");
    if (!$sth || !mysql_num_rows($sth)) {
        show_error("Can't display user rankings by ships");
        return 0;
    }
    while ($score = mysql_fetch_assoc($sth)) {
        if ($score["aid"] == $user_alliance || $score["uid"] == $uid) {
            $planet_count = $score["ship_count"];
        } else {
            $planet_count = "&nbsp;";
        }
        $class = $uid == $score["uid"] ? "head" : "text";
        $alliance = "<a href=\"database.php?act=info_alliance&aid=" . $score["aid"] . "\"><font color=\"" . $score["color"] . "\">" . $score["aname"] . "</font></a>";
        table_text(array($counter++, $score["uname"], $score["imperium"], $alliance, $planet_count), "", "", "", $class);
    }
    table_text(array("<a href=\"#top\">Top</a>"), "center", "", "5", "head");
}
 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);
     }
 }
function is_minister($uid)
{
    $alliance = get_alliance($uid);
    if ($alliance) {
        $sth = mysql_query("select leader, milminister, devminister, forminister from alliance where id=" . $alliance);
        if (!$sth || !mysql_num_rows($sth)) {
            return false;
        }
        $ministers = mysql_fetch_array($sth);
        switch ($uid) {
            case $ministers["leader"]:
                return "leader";
                break;
            case $ministers["milminister"]:
                return "milminister";
                break;
            case $ministers["devminister"]:
                return "devminister";
                break;
            case $ministers["forminister"]:
                return "forminister";
                break;
            default:
                return false;
                break;
        }
    } else {
        return false;
    }
}
function getPlanetData()
{
    global $uid;
    global $pid;
    // übergeben in der URL
    global $map_info;
    // BUTTON Definitionen
    $buttonShape = "button_circle_30x30_shadow";
    $my_alliance = get_alliance($uid);
    $fog_of_war = $map_info->get_fog_of_war();
    // *** HEADER ****
    // Zuerst allgemeine Informationen über den Planeten
    //$sth = mysql_query("SELECT p.name, p.type as picture, p.sid, u.name as user_name, u.id as p_uid, p.metal, p.energy, p.mopgas, p.erkunum, p.gortium, p.susebloom, u.alliance FROM planets p LEFT OUTER JOIN users u ON p.uid = u.id WHERE p.id = $pid");
    $sth = mysql_query("SELECT p.name, p.type as picture, p.sid, b.name as user_name, b.id as p_uid, p.metal, p.energy, p.mopgas, p.erkunum, p.gortium, p.susebloom, b.a_name, b.symbol, b.color FROM planets p left join (SELECT u.id, u.name, a.name as a_name, a.color, a.symbol from users u left join alliance a on u.alliance = a.id) b on b.id = p.uid where p.id = '" . $pid . "'");
    if (!$sth || !mysql_num_rows($sth)) {
        return false;
    }
    $planet_info = mysql_fetch_assoc($sth);
    // gucken ob der planet nicht einen falschen namen hat
    if ($planet_info["name"] == "" || $planet_info["name"] == "Unnamed") {
        $planet_info["name"] = get_planetname($pid);
    } else {
        $planet_info["name"] = $planet_info["name"];
    }
    // Besitzer des planeten
    if (!$planet_info["user_name"]) {
        $planet_info["user_name"] = 0;
    } else {
        $planet_info["user_name"] = "of " . $planet_info["user_name"];
    }
    // Kontur und Alliancen Symbol
    if (!$planet_info["a_name"]) {
        $planet_info["a_name"] = 0;
        $planet_info["symbol"] = 0;
        $planet_info["color"] = 0;
        if ($planet_info["p_uid"]) {
            if ($uid == $planet_info["p_uid"]) {
                $kontur = "colorOwn";
            } else {
                $kontur = "colorNeutral";
            }
        }
    } else {
        $kontur = get_uids_relation($uid, $planet_info["p_uid"], 1);
    }
    // Buttons
    $planet_fleets = false;
    // Flotten button
    $planet_troops = false;
    // Infatry button
    $planet_planet = false;
    // planet button
    // Wenn es ein eigener oder alleierter Planet ist, ebenfalls die Buttons: fleets, buildings, infantry darstellen
    // den fleet button auch darstellen , wenn eine eigene (alleierte Flotte) in dem System ist
    if ($uids_relation == "same" || $uids_relation == "allied") {
        // Ok, der Planet gehört mir oder nem Alleierten, also kann ich die Flotten und Truppen sehen
        $planet_fleets = true;
        $planet_troops = true;
        $planet_planet = true;
    } else {
        $scanned_sids = $map_info->get_scanned_systems();
        if (in_array($planet_info["sid"], $scanned_sids)) {
            $planet_fleets = true;
            $planet_planet = true;
        }
    }
    // Check ob flotten vorort
    // Wenn keine Flotten da sind muss ich auch keinen Button anzeigen
    if ($planet_fleets) {
        $sth = mysql_query("SELECT 1 FROM fleet_info WHERE pid = {$pid} LIMIT 1");
        if (!$sth) {
            return false;
        }
        if (!mysql_num_rows($sth)) {
            $planet_fleets = false;
        }
    }
    // Check ob Infantry vor Ort
    // Wenn keine Truppen da sind muss ich auch keinen Button anzeigen
    if ($planet_troops) {
        $sth = mysql_query("SELECT 1 FROM infantery WHERE pid = {$pid} LIMIT 1");
        if (!$sth) {
            return false;
        }
        if (!mysql_num_rows($sth)) {
            $planet_troops = false;
        }
    }
    // Ok, Buttons kreieren und in $new_button[] speichern
    if ($planet_planet) {
        $new_button[] = create_button($buttonShape, "button_face_info", "showPlanetInfo(evt, " . $pid . ",'" . addslashes($planet_info["name"]) . "')", 0, "show planet details");
    }
    if ($planet_fleets) {
        $new_button[] = create_button($buttonShape, "button_face_ship", "showItemBoxItems('fleet')", 0, "show fleets");
    }
    if ($planet_troops) {
        $new_button[] = create_button($buttonShape, "button_face_infantry", "showItemBoxItems('infantry')", 0, "show groundforces");
    }
    $new_header = create_header(PIC_ROOT . $planet_info["picture"] . ".png", $planet_info["name"], $planet_info["user_name"], $kontur, $planet_info["symbol"], $planet_info["a_name"], $planet_info["color"], $planet_info["metal"], $planet_info["energy"], $planet_info["mopgas"], $planet_info["erkunum"], $planet_info["gortium"], $planet_info["susebloom"]);
    // Button in das Header Tag einfügen
    for ($i = 0; $i < sizeof($new_button); $i++) {
        $new_header .= $new_button[$i];
    }
    $new_header .= "</SR_HEAD>";
    echo "newItemBox\n";
    // nötig um zu ermitteln wie der inhalt behnadelt werden soll!
    echo $new_header;
}
function accept_pending()
{
    global $uid;
    global $faid;
    if (has_alliance_lock($uid)) {
        show_message("You can't use any alliance options due to an alliance lock!");
        return false;
    }
    $aid = get_alliance($uid);
    if (!is_leader($uid, $aid)) {
        show_message("Be aware of the dark side!");
        return 0;
    }
    $pending_status = get_pending_diplomacy_change($faid, $aid);
    if (!$pending_status) {
        show_message("fu! ;)");
        return 0;
    }
    if (!drop_pending_diplomatic_request($faid, $aid)) {
        show_error("Database failure!");
        return 0;
    }
    if (!change_diplomatic_status($aid, $faid, $pending_status)) {
        show_error("Database failure2!");
        return 0;
    }
    $f_leader = get_leader($faid);
    $f_allies = get_allied_ids($f_leader);
    ticker($f_leader, "*lcommunication.php?act=show_diplomacy*Alliance " . get_alliance_name($aid) . " has accepted your request to change status to " . get_diplomatic_status_text($pending_status), "w");
    for ($i = 0; $i < sizeof($f_allies); $i++) {
        ticker($f_allies[$i], "Alliance " . get_alliance_name($aid) . " has accepted your leaders request to change status to " . get_diplomatic_status_text($pending_status), "w");
    }
    $allies = get_allied_ids(get_leader($aid));
    for ($i = 0; $i < sizeof($allies); $i++) {
        ticker($allies[$i], "Your leader accepted a request from Alliance " . get_alliance_name($faid) . " to change status to " . get_diplomatic_status_text($pending_status), "w");
    }
    show_message("Status changed!");
}
 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();
             }
         }
     }
 }
 /**
  * generiert zu einem battlefield alle nötigen reports
  */
 function generate_reports()
 {
     $this->gather_results();
     $participants = $this->battlefield->get_participants();
     $uids = array();
     for ($i = 0; $i < sizeof($participants); $i++) {
         if (!in_array($participants[$i]->get_uid(), $uids)) {
             $uids[] = $participants[$i]->get_uid();
         }
     }
     if ($invader = $this->battlefield->get_invasion()) {
         $invasion = $this->battlefield->get_name() . " has been invaded by " . $this->users[$invader];
     } else {
         $invasion = false;
     }
     $this->smarty->assign("location", $this->battlefield->get_name());
     $this->smarty->assign("invasion", $invasion);
     $this->smarty->assign("results", $this->results);
     $this->smarty->assign("users", $this->users);
     ob_start();
     $this->smarty->display("battlereport.tpl");
     $report = ob_get_contents();
     ob_end_clean();
     // mop: alles zurücksetzen für den nächsten kampf
     $this->smarty->clear_all_assign();
     // mop: allianzen aller user rausfinden
     $alliances = array();
     for ($i = 0; $i < sizeof($uids); $i++) {
         $alliance = get_alliance($uids[$i]);
         if (!in_array($alliance, $alliances)) {
             $alliances[] = $alliance;
         }
     }
     $this->save_report($alliances, $uids, $this->battlefield, $report);
 }
Example #11
0
function get_enemy_aids($uid)
{
    $its_alliance = get_alliance($uid);
    if ($its_alliance) {
        $sth = mysql_query("SELECT alliance2 FROM diplomacy WHERE alliance1=\n{$its_alliance} and status=0") or die(mysql_error());
        if (!$sth || mysql_num_rows($sth) == 0) {
            return false;
        }
        while ($enemy_ids = mysql_fetch_array($sth)) {
            $enemy_array[] = $enemy_ids["alliance2"];
        }
        return $enemy_array;
    } else {
        return false;
    }
}