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;
}
 /** 
  * ctor
  * 
  * @return 
  */
 function battle()
 {
     try {
         $reporter = new battlereporter();
     } catch (Exception $e) {
         throw $e;
     }
     $battles = $this->get_battles();
     if (!is_array($battles)) {
         echo "AAAAAAAAARRRRRRGH KAMPF KAPUTT!";
         return false;
     }
     foreach ($battles as $battle) {
         list($sid, $pid) = $battle;
         try {
             $battlefield = new battlefield($sid, $pid);
             $battlefield->execute_battle();
             if (BATTLE_DESTROY) {
                 $battlefield->capture_units();
                 $battlefield->flee_units();
                 $battlefield->destroy_units();
                 // mop: lieber mehrmals ausführen....nicht, dass wir da nen segfault zwischendurch bekommen und dann die schiffe da bleiben
                 delete_empty_fleets();
                 $sth1 = mysql_query("delete from inf_transports where count<=0");
                 $sth1 = mysql_query("delete from infantery where count<=0");
                 if ($pid) {
                     $owner = get_uid_by_pid($pid);
                     // Mop: derjenigen mit den meisten einheiten erobert den planeten
                     // => idealsituation : der mit der prolligsten armee
                     $sth1 = mysql_query("select i.uid,sum(i.count) as total_count from infantery i left join infantery i2 on i.pid=i2.pid and i2.uid=" . $owner . " where i.pid=" . $pid . " and i.uid!=" . $owner . " and i2.uid is null group by i.uid order by total_count desc limit 1");
                     if (!$sth1) {
                         echo "invade kaputt =>" . $pid . "\n";
                     }
                     if (mysql_num_rows($sth1) != 0) {
                         list($new_owner) = mysql_fetch_row($sth1);
                         $sth1 = mysql_query("update planets set uid=" . $new_owner . " where id=" . $pid);
                         if (!$sth1) {
                             echo "invade kaputt 2 => " . $pid . " " . $new_owner . "\n";
                         }
                         $battlefield->set_invasion($new_owner);
                     }
                 }
             }
             $reporter->set_field($battlefield);
             $reporter->generate_reports();
         } catch (Exception $e) {
             echo $e->getMessage() . "\n";
         }
     }
 }
Exemplo n.º 3
0
function combat_get_conqueror($pid)
{
    $retval = false;
    if ($pid > 0) {
        $puid = get_uid_by_pid($pid);
        $paid = get_aid_by_uid($puid);
        if (!$paid) {
            return false;
        }
    } elseif ($pid == 0 || !$pid) {
        return false;
    } else {
        $puid = -1;
        $paid = -1;
    }
    if ($paid > 0) {
        $enemies = get_enemy_aids($puid);
    } else {
        $enemies[] = -2;
    }
    if (sizeof($enemies) > 0) {
        $query = $GLOBALS["db"]->query("SELECT uid, SUM((susebloom+mopgas+erkunum+energy+metal+gortium)*count) \n  AS inf_power FROM combat INNER JOIN production USING (prod_id) WHERE position='P' AND aid \n  IN (" . implode(",", $enemies) . ") AND killed_by IS NULL GROUP BY uid \n  HAVING inf_power>0 ORDER BY inf_power DESC LIMIT 1") or die($GLOBALS["db"]->error);
        if ($query->num_rows > 0) {
            list($bestenemy, $bla) = $query->fetch_row();
        }
    }
    $query = $GLOBALS["db"]->query("SELECT SUM(count) AS CountSum FROM combat WHERE position='P' AND\naid={$paid} AND size<>'H'") or die($GLOBALS["db"]->error);
    list($result) = $query->fetch_row();
    if ($result == 0) {
        // Uh-Oh, keine Verteidiger mehr! Angreifer denn?
        if ($bestenemy) {
            $retval = $bestenemy;
        }
    } else {
        // Es sind noch Verteidiger da, waren denn auch Angreifer da?
        if ($bestenemy) {
            $retval = -100;
        }
    }
    return $retval;
}
Exemplo n.º 4
0
function production()
{
    // Orbital Start
    $sth = mysql_query("select * from o_production where time=1 and pos=1");
    if (!$sth) {
        echo "Database failure!\n";
        return 0;
    }
    while ($orbital = mysql_fetch_array($sth)) {
        $sth1 = mysql_query("insert into constructions (pid,prod_id,type) values ('" . $orbital["planet_id"] . "','" . $orbital["prod_id"] . "',1)");
        if (!$sth1) {
            echo "Database failure!";
        }
        $sth1 = mysql_query("select uid from planets where id=" . $orbital["planet_id"]);
        if (!$sth1) {
            echo "Datasbe failure!";
        }
        list($uid) = mysql_fetch_row($sth1);
        $sth1 = mysql_query("select name from production where prod_id=" . $orbital["prod_id"]);
        if (!$sth1) {
            echo "Database failure!";
        }
        $blub = mysql_fetch_array($sth1);
        $planetname = get_planetname($orbital["planet_id"]);
        ticker($uid, "*lproduction.php?act=build&pid=" . $orbital["planet_id"] . "*" . $planetname . ": " . $blub["name"] . " in orbit constructed.", "w");
        $sth1 = mysql_query("delete from o_production where planet_id='" . $orbital["planet_id"] . "' and prod_id='" . $orbital["prod_id"] . "'");
        if (!$sth1) {
            echo "Database failure!";
            return 0;
        }
        $sth1 = mysql_query("select typ from production where prod_id=" . $orbital["prod_id"] . " and typ='R'");
        if (mysql_num_rows($sth1) > 0) {
            $sth1 = mysql_query("select uid from planets where id=" . $orbital["planet_id"]);
            list($uid) = mysql_fetch_array($sth1);
            $sth1 = mysql_query("delete from tradestations where uid={$uid}");
            $sth1 = mysql_query("insert into tradestations (metal,energy,mopgas,erkunum,gortium,susebloom,uid,pid) values ('0','0','0','0','0','0','{$uid}','" . $orbital["planet_id"] . "')");
        }
        $sth1 = mysql_query("select prod_id from production where prod_id='" . $orbital["prod_id"] . "' and special='S'");
        if (!$sth1) {
            echo "Database failure!";
        }
        if (mysql_num_rows($sth1) > 0) {
            $sth1 = mysql_query("select sid from planets where id=" . $orbital["planet_id"]);
            if (!$sth1) {
                echo "Database failure!";
            }
            $sid = mysql_fetch_row($sth1);
            $sth1 = mysql_query("select * from jumpgatevalues where prod_id=" . $orbital["prod_id"]);
            if (!$sth1) {
                echo "Databaser failure!";
            }
            if (mysql_num_rows($sth1) > 0) {
                $password = crypt(md5(uniqid(mt_rand())));
                $sth1 = mysql_query("insert into jumpgates (prod_id,password,sid,pid) values ('" . $orbital["prod_id"] . "','" . $password . "','" . $sid[0] . "','" . $orbital["planet_id"] . "')");
                if (!$sth1) {
                    echo "Dtasabser failuert!";
                }
                $sth1 = mysql_query("select uid from planets where id=" . $orbital["planet_id"]);
                if (!$sth1) {
                    echo "Dtasber faileu8r!";
                }
                $uid = mysql_fetch_row($sth1);
                mail_to_uid($uid[0], "Password for your jumpgate in system " . $sid[0], $password);
            }
        }
    }
    $sth = mysql_query("update o_production set time=time-'1' where time>1 and pos=1");
    if (!$sth) {
        echo "Database failure!";
        return 0;
    }
    $sth = mysql_query("select distinct p1.planet_id from o_production as p1 left join o_production as p2 on p2.pos=1 and p2.planet_id=p1.planet_id where p1.pos!=1 and p2.pos is NULL");
    if (!$sth) {
        echo "Database failure!";
    }
    while ($pids = mysql_fetch_row($sth)) {
        $next_prod_id = next_in_queue(0, $pids[0]);
        if ($next_prod_id) {
            $uid = get_uid_by_pid($pids[0]);
            if (has_ressources($uid, $next_prod_id)) {
                $sth1 = mysql_query("update o_production set pos=1 where planet_id=" . $pids[0] . " and prod_id={$next_prod_id}");
                $sth1 = mysql_query("select metal,energy,mopgas,erkunum,gortium,susebloom from production where prod_id={$next_prod_id}");
                list($metal, $energy, $mopgas, $erkunum, $gortium, $susebloom) = mysql_fetch_row($sth1);
                $sth1 = mysql_query("update ressources set metal=metal-{$metal},energy=energy-{$energy},mopgas=mopgas-{$mopgas},erkunum=erkunum-{$erkunum},gortium=gortium-{$gortium},susebloom=susebloom-{$susebloom} where uid={$uid}");
            }
        }
    }
    // Orbital Ende
    // Planet production
    $sth = mysql_query("select * from p_production where time=1 and pos=1");
    if (!$sth) {
        echo "Database failure!\n";
        return 0;
    }
    while ($buildings = mysql_fetch_array($sth)) {
        $sth1 = mysql_query("select uid,name from planets where id=" . $buildings["planet_id"]);
        if (!$sth1) {
            echo "Database failure!";
        }
        $uid = mysql_fetch_array($sth1);
        if ($uid["name"] == "Unnamed") {
            $uid["name"] = get_planetname($buildings["planet_id"]);
        }
        $sth1 = mysql_query("select name from production where prod_id=" . $buildings["prod_id"]);
        // Schilde einbauen
        list($value, $shield) = dselect("CONV(SUBSTRING(special FROM 2),10,10), shield", "shipvalues", "special LIKE 'H%' AND prod_id=" . $buildings["prod_id"]);
        if ($value) {
            $janne = mysql_query("REPLACE INTO planetary_shields (pid, prod_id, value, max_value, regeneration, \n        regeneration_bonus) VALUES (" . $buildings["planet_id"] . ", " . $buildings["prod_id"] . ", {$shield}, {$shield},\n          {$value}, 0)");
        }
        if (!$sth1) {
            echo "Database failure!";
        }
        $blub = mysql_fetch_array($sth1);
        ticker($uid["uid"], "*lproduction.php?act=build&pid=" . $buildings["planet_id"] . "*" . $uid["name"] . ": " . $blub["name"] . " constructed.", "w");
        $sth1 = mysql_query("insert into constructions (pid,prod_id,type) values ('" . $buildings["planet_id"] . "','" . $buildings["prod_id"] . "',0)");
        if (!$sth1) {
            echo "Database failure! (CREATING BUILDING ON PLANET)";
        }
        $sth1 = mysql_query("delete from p_production where planet_id='" . $buildings["planet_id"] . "' and prod_id='" . $buildings["prod_id"] . "'");
        if (!$sth1) {
            echo "Database failure! (DELETING PLANETAR PRODUCTION)";
        }
    }
    $sth = mysql_query("update p_production set time=time-'1' where time>1 and pos=1");
    if (!$sth) {
        echo "Database failure!";
        return 0;
    }
    $sth = mysql_query("select distinct p1.planet_id from p_production as p1 left join p_production as p2 on p2.pos=1 and p2.planet_id=p1.planet_id where p1.pos!=1 and p2.pos is NULL");
    if (!$sth) {
        echo "Database failure!";
    }
    while ($pids = mysql_fetch_row($sth)) {
        $next_prod_id = next_in_queue(1, $pids[0]);
        if ($next_prod_id) {
            $uid = get_uid_by_pid($pids[0]);
            if (has_ressources($uid, $next_prod_id)) {
                $sth1 = mysql_query("update p_production set pos=1 where planet_id=" . $pids[0] . " and prod_id={$next_prod_id}");
                $sth1 = mysql_query("select metal,energy,mopgas,erkunum,gortium,susebloom from production where prod_id={$next_prod_id}");
                list($metal, $energy, $mopgas, $erkunum, $gortium, $susebloom) = mysql_fetch_row($sth1);
                $sth1 = mysql_query("update ressources set metal=metal-{$metal},energy=energy-{$energy},mopgas=mopgas-{$mopgas},erkunum=erkunum-{$erkunum},gortium=gortium-{$gortium},susebloom=susebloom-{$susebloom} where uid={$uid}");
            }
        }
    }
    // Planetar Ende
    // Fleet Production Start
    $uids = array();
    $sth = mysql_query("select s.planet_id,s.prod_id,s.count,s.time,s.priority,\nr.uid,r.metal as rmetal,r.energy as renergy,r.mopgas as rmopgas,r.erkunum as rerkunum,r.gortium as rgortium,r.susebloom as rsusebloom,\npl.id,p.metal,p.energy,p.mopgas,p.erkunum,p.gortium,p.susebloom,\nsum(ps.tonnage) as slots,\nsv.tonnage,\np.com_time\nfrom s_production s,planets pl,production p,ressources r,production_slots ps,constructions c,shipvalues sv where s.planet_id=pl.id\nand s.prod_id=p.prod_id\nand p.prod_id=sv.prod_id\nand ps.prod_id=c.prod_id\nand c.pid=pl.id\nand r.uid=pl.uid\ngroup by s.planet_id,s.prod_id,s.time\norder by pl.uid,s.priority DESC,s.time DESC");
    if (!$sth) {
        echo "ERR::GET S_PRODUCTION";
    } else {
        while ($data = mysql_fetch_assoc($sth)) {
            if (!$uids[$data["uid"]]) {
                $uids[$data["uid"]] = array("production_slots" => $data["slots"], "ressources" => array("metal" => $data["rmetal"], "energy" => $data["renergy"], "mopgas" => $data["rmopgas"], "erkunum" => $data["rerkunum"], "gortium" => $data["rgortium"], "susebloom" => $data["rsusebloom"]));
            }
            // mop: maximale anzahl der produzierbaren schiffe ermitteln (durch slots limitiert)
            $prod_count = floor($uids[$data["uid"]]["production_slots"] / $data["tonnage"]);
            $real_count = min($data["count"], $prod_count);
            if ($real_count > 0) {
                // mop: jetzt koenen uns nur noch die ressourcen aufhalten
                foreach (array("metal", "energy", "mopgas", "erkunum", "gortium", "susebloom") as $res) {
                    if ($data[$res]) {
                        $real_count = min($real_count, floor($uids[$data["uid"]]["ressources"][$res] / ceil($data[$res] / $data["com_time"])));
                    }
                }
                if ($real_count > 0) {
                    // mop: alle schiffe produzierbar?
                    if ($real_count == $data["count"]) {
                        // mop: alles easy
                        $sth1 = mysql_query("update s_production s,ressources r set s.time=s.time+1,\n                r.metal=r.metal-" . ceil($real_count * $data["metal"] / $data["com_time"]) . ",\n                r.energy=r.energy-" . ceil($real_count * $data["energy"] / $data["com_time"]) . ",\n                r.mopgas=r.mopgas-" . ceil($real_count * $data["mopgas"] / $data["com_time"]) . ",\n                r.erkunum=r.erkunum-" . ceil($real_count * $data["erkunum"] / $data["com_time"]) . ",\n                r.gortium=r.gortium-" . ceil($real_count * $data["gortium"] / $data["com_time"]) . ",\n                r.susebloom=r.susebloom-" . ceil($real_count * $data["susebloom"] / $data["com_time"]) . "\n                where s.prod_id=" . $data["prod_id"] . " and s.time=" . $data["time"] . " and s.planet_id=" . $data["planet_id"] . " and r.uid=" . $data["uid"]);
                        if (!$sth1) {
                            echo "ERR::UPDATE S_PROD 1";
                        }
                    } else {
                        // mop: stress...aufsplitten
                        $sth1 = mysql_query("insert into s_production set prod_id=" . $data["prod_id"] . ",planet_id=" . $data["planet_id"] . ",count=" . $real_count . ",time=" . ($data["time"] + 1) . ",priority=" . $data["priority"] . " on duplicate key update count=count+" . $real_count . ",priority=" . $data["priority"]);
                        if (!$sth1) {
                            echo "ERR::INSERT SPLIT S_PROD";
                        }
                        // mop: update des rests und der ressourcen
                        $sth1 = mysql_query("update s_production s,ressources r set s.count=s.count-" . $real_count . ",\n                r.metal=r.metal-" . ceil($real_count * $data["metal"] / $data["com_time"]) . ",\n                r.energy=r.energy-" . ceil($real_count * $data["energy"] / $data["com_time"]) . ",\n                r.mopgas=r.mopgas-" . ceil($real_count * $data["mopgas"] / $data["com_time"]) . ",\n                r.erkunum=r.erkunum-" . ceil($real_count * $data["erkunum"] / $data["com_time"]) . ",\n                r.gortium=r.gortium-" . ceil($real_count * $data["gortium"] / $data["com_time"]) . ",\n                r.susebloom=r.susebloom-" . ceil($real_count * $data["susebloom"] / $data["com_time"]) . "\n                where s.prod_id=" . $data["prod_id"] . " and s.time=" . $data["time"] . " and s.planet_id=" . $data["planet_id"] . " and r.uid=" . $data["uid"]);
                        if (!$sth1) {
                            echo "ERR::UPDATE REST S_PROD";
                        }
                    }
                    $uids[$data["uid"]]["production_slots"] -= $real_count * $data["tonnage"];
                    foreach (array("metal", "energy", "mopgas", "erkunum", "gortium", "susebloom") as $res) {
                        $uids[$data["uid"]]["ressources"][$res] -= ceil($real_count * $data[$res] / $data["com_time"]);
                    }
                }
            }
        }
    }
    // mop: rundungsfehler fuer die dinger, die jetzt fertig werden ausgleichen
    $fragments = array();
    foreach (array("metal", "energy", "mopgas", "erkunum", "gortium", "susebloom") as $res) {
        $fragments[] = "r." . $res . "=r." . $res . "+ceil(p." . $res . "*s.count/p.com_time)*p.com_time-p." . $res . "*s.count";
    }
    $sth = mysql_query("update s_production s,production p,planets pl,ressources r set " . implode($fragments, ",") . " where r.uid=pl.uid and pl.id=s.planet_id and s.prod_id=p.prod_id and p.com_time-s.time=0");
    if (!$sth) {
        echo "ERR::CORRECT CEILINGS\n";
    }
    $sth = mysql_query("select * from s_production sp,production p where p.com_time-sp.time=0 and sp.prod_id=p.prod_id");
    if (!$sth) {
        echo "Database failure!\n";
        return 0;
    }
    while ($ships = mysql_fetch_assoc($sth)) {
        $sth1 = mysql_query("select uid,name from planets where id=" . $ships["planet_id"]);
        if (!$sth1) {
            echo "Datasbe failure!";
        }
        $uid = mysql_fetch_assoc($sth1);
        ticker($uid["uid"], "*lproduction.php?pid=" . $ships["planet_id"] . "*" . $uid["name"] . ": " . $ships["count"] . " " . $ships["name"] . "(s) produced.", "w");
        $sth1 = mysql_query("select sid from planets where id=" . $ships["planet_id"]);
        if (!$sth1) {
            echo "Dtabase failuer!";
        }
        $system = mysql_fetch_array($sth1);
        $fids = get_fids_by_pid($ships["planet_id"], $uid["uid"]);
        // Keine Flotte auf dem Planet?
        if (!$fids) {
            $new_fleet = new fleet();
            $new_fleet->add_ships_arr(array($ships["prod_id"] => array($ships["count"], 0)));
            $new_fleet->uid = $uid["uid"];
            $new_fleet->pid = $ships["planet_id"];
            $new_fleet->sid = $system["sid"];
            $new_fleet->create_fleet();
        } else {
            $prod_id_in_fid = false;
            for ($i = 0; $i <= sizeof($fids) - 1; $i++) {
                $fleet = new fleet($fids[$i]);
                if ($fleet->ships[$ships["prod_id"]]) {
                    $prod_id_in_fid =& $fleet;
                    // Das is ne referenz :) Irgendwann musste ich die einfach mal benutzen:)
                    break;
                }
            }
            if ($prod_id_in_fid) {
                $prod_id_in_fid->ships[$ships["prod_id"]][0] += $ships["count"];
                $prod_id_in_fid->update_prod_id($ships["prod_id"]);
            } else {
                $fleet->add_ships_arr(array($ships["prod_id"] => array($ships["count"], 0)));
                if (!$fleet->update_prod_id($ships["prod_id"])) {
                    echo "Error assigning new prod id to fleet " . $fleet->fid . "\n";
                }
            }
        }
        $sth1 = mysql_query("delete from s_production where planet_id='" . $ships["planet_id"] . "' and prod_id='" . $ships["prod_id"] . "' and count='" . $ships["count"] . "' and time=" . $ships["time"]);
        if (!$sth1) {
            echo "Dtaabase failuer!";
        }
    }
    // Fleet Ende
    // Infantery Production Start
    $sth = mysql_query("select * from i_production where time=1");
    if (!$sth) {
        echo "Database failure!\n";
        return 0;
    }
    while ($soldiers = mysql_fetch_array($sth)) {
        $sth1 = mysql_query("select uid,name from planets where id=" . $soldiers["planet_id"]);
        if (!$sth1) {
            echo "Datasbe failure!";
        }
        $uid = mysql_fetch_array($sth1);
        $sth1 = mysql_query("select name from production where prod_id=" . $soldiers["prod_id"]);
        if (!$sth1) {
            echo "Database failure!";
        }
        $blub = mysql_fetch_array($sth1);
        ticker($uid["uid"], "*lproduction.php?pid=" . $soldiers["planet_id"] . "*" . $uid["name"] . ": " . $soldiers["count"] . " " . $blub["name"] . "(s) produced.", "w");
        $sth1 = mysql_query("select prod_id from infantery where prod_id=" . $soldiers["prod_id"] . " and pid=" . $soldiers["planet_id"]);
        if (!$sth1) {
            echo "Dazsu failu!";
        }
        if (mysql_num_rows($sth1) == 0) {
            $sth1 = mysql_query("insert into infantery (prod_id,pid,count,uid) values ('" . $soldiers["prod_id"] . "','" . $soldiers["planet_id"] . "','" . $soldiers["count"] . "','" . $uid[0] . "')");
            if (!$sth1) {
                echo "Database failuerfleet!";
            }
        } else {
            $sth1 = mysql_query("update infantery set count=count+" . $soldiers["count"] . " where pid='" . $soldiers["planet_id"] . "' and prod_id='" . $soldiers["prod_id"] . "' and uid='" . $uid["uid"] . "' limit 1");
            if (!$sth1) {
                echo "Database failure!";
            }
        }
        $sth1 = mysql_query("delete from i_production where planet_id='" . $soldiers["planet_id"] . "' and prod_id='" . $soldiers["prod_id"] . "' and count='" . $soldiers["count"] . "' and time=1");
        if (!$sth1) {
            echo "Dtaabase failuer!";
        }
    }
    $sth = mysql_query("select * from infbattle" . $soldier["planet_id"]);
    if ($sth) {
        $sth = mysql_query("insert into infbattle" . $soldier["planet_id"] . " (prod_id,count,initiative,side) values ('" . $soldier["prod_id"] . "','" . $soldier["count"] . "','0','0')");
    }
    $sth = mysql_query("update i_production set time=time-'1' where time>1");
    if (!$sth) {
        echo "Database failure!";
        //      return 0;
    }
    // Infantery Ende
}
Exemplo n.º 5
0
function get_planetProduction($pid)
{
    global $uid;
    $puid = get_uid_by_pid($pid);
    $p_relation = get_uids_relation($uid, $puid);
    if ($p_relation == "same" || $p_relation == "allie") {
        $production_tag = create_production_tag($pid);
    }
    echo "<SR_REQUEST type=\"planet_info_prod\" pid=\"" . $pid . "\">";
    echo $production_tag;
    echo "</SR_REQUEST>";
}
Exemplo n.º 6
0
function get_max_scanrange_by_sid($sid, $user_id = 0)
{
    global $uid;
    if (!$user_id) {
        $user_id = $uid;
    }
    $sth = mysql_query("select id from planets where sid='{$sid}' and uid != 0");
    if (!$sth || !mysql_num_rows($sth)) {
        return 0;
    }
    while ($its_planets = mysql_fetch_array($sth)) {
        $its_user = get_uid_by_pid($its_planets["id"]);
        if ($its_user == $user_id || is_allied($its_user, $user_id)) {
            $scanrange[] = get_max_scan_range_by_pid($its_planets["id"]);
        }
    }
    if (is_array($scanrange)) {
        rsort($scanrange);
        $max_scanrange = $scanrange[0];
    } else {
        $max_scanrange = 0;
    }
    return $max_scanrange;
}
Exemplo n.º 7
0
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();
             }
         }
     }
 }
Exemplo n.º 9
0
function change_fprio($pid, $prod_id, $time, $change)
{
    global $uid;
    if (get_uid_by_pid($pid) != $uid) {
        show_error("TADA!!!!");
        return false;
    }
    switch ($change) {
        case 1:
        case -1:
            $sth = mysql_query("update s_production set priority=if(priority+" . $change . ">2 or priority+" . $change . "<0,priority,priority+" . $change . ") where planet_id=" . $pid . " and prod_id=" . $prod_id . " and time=" . $time);
            if (!$sth) {
                show_error("ERR::SET PRIO");
            }
    }
}
Exemplo n.º 10
0
function draw_special_symbols($x, $y, $specials, $sid)
{
    global $uid;
    global $map_info;
    $abstand_x = -40;
    $abstand_y = -25;
    for ($i = 0; $i < sizeof($specials); $i++) {
        if (isset($specials[$i])) {
            $its_uid = get_uid_by_pid($specials[$i][pid]);
            if ($uid == $its_uid || $map_info->is_allied($its_uid)) {
                $allied_special[] = $specials[$i][special];
            } else {
                if ($map_info->is_friendly($its_uid)) {
                    $friendly_special[] = $specials[$i][special];
                } elseif ($map_info->is_enemy($its_uid)) {
                    $enemy_special[] = $specials[$i][special];
                } else {
                    $neutral_special[] = $specials[$i][special];
                }
            }
        }
    }
    if (is_array($allied_special)) {
        $allied_special = array_unique($allied_special);
        for ($i = 0; $i < sizeof($allied_special); $i++) {
            $its_specials = each($allied_special);
            $special_symbols .= "<use xlink:href=\"#sStarSpecialSymbol_" . $its_specials[1] . "\" x=\"" . ($x + $abstand_x - $i * 25) . "\" y=\"" . ($y + $abstand_y) . "\"  class=\"colorOwnDiscreet\"/>";
        }
        $abstand_y += -25;
    }
    if (is_array($friendly_special)) {
        $friendly_special = array_unique($friendly_special);
        for ($i = 0; $i < sizeof($friendly_special); $i++) {
            $its_specials = each($friendly_special);
            $special_symbols .= "<use xlink:href=\"#sStarSpecialSymbol_" . $its_specials[1] . "\" x=\"" . ($x + $abstand_x - $i * 25) . "\" y=\"" . ($y + $abstand_y) . "\"  class=\"colorFriendDiscreet\"/>";
        }
        $abstand_y += -25;
    }
    if (is_array($enemy_special)) {
        $enemy_special = array_unique($enemy_special);
        for ($i = 0; $i < sizeof($enemy_special); $i++) {
            $its_specials = each($enemy_special);
            $special_symbols .= "<use xlink:href=\"#sStarSpecialSymbol_" . $its_specials[1] . "\" x=\"" . ($x + $abstand_x - $i * 25) . "\" y=\"" . ($y + $abstand_y) . "\"  class=\"colorEnemyDiscreet\"/>";
        }
        $abstand_y += -25;
    }
    if (is_array($neutral_special)) {
        $neutral_special = array_unique($neutral_special);
        for ($i = 0; $i < sizeof($neutral_special); $i++) {
            $its_specials = each($neutral_special);
            $special_symbols .= "<use xlink:href=\"#sStarSpecialSymbol_" . $its_specials[1] . "\" x=\"" . ($x + $abstand_x - $i * 25) . "\" y=\"" . ($y + $abstand_y) . "\" class=\"colorNeutralDiscreet\"/>";
        }
        $abstand_y += -25;
    }
    return $special_symbols;
}
Exemplo n.º 11
0
function get_true_ETA_by_fid($fid)
{
    global $uid;
    $fleets_target = get_fleets_target($fid);
    // kein ziel
    if ($fleets_target["system"]["tid"] == 0 && $fleets_target["planet"]["tid"] == 0) {
        return 0;
    }
    // ziel = standort
    if ($fleets_target["system"]["tid"] == $fleets_target["system"]["id"] && $fleets_target["planet"]["tid"] == $fleets_target["planet"]["id"]) {
        return 0;
    }
    // innerhalb eines systems
    if ($fleets_target["system"]["tid"] == $fleets_target["system"]["id"] && $fleets_target["planet"]["tid"] != $fleets_planets["planet"]["id"]) {
        return 1;
    } else {
        // Alleierte raussuchen
        $allies = get_allied_ids($uid);
        if (is_array($allies)) {
            array_push($allies, $uid);
        } else {
            $allies[0] = $uid;
        }
        // route besorgen
        $sth = mysql_query("select route from routes where fid={$fid}");
        if (!$sth || !mysql_num_rows($sth)) {
            return false;
        }
        list($route) = mysql_fetch_row($sth);
        $route = unserialize($route);
        // Anzahl sprünge ermitteln
        $jumps = sizeof($route);
        $refueling_stations_count = 0;
        // refueling stations ermitteln
        $refueling_stations = get_prodid_by_special("F");
        // nach refuelingstations auf dem weg suchen
        for ($i = 0; $i < $jumps - 1; $i++) {
            $current_system_planets = get_planets_by_sid($route[$i]);
            // Filtern nach alleierten und eigenen Planeten
            for ($j = 0; $j < sizeof($current_system_planets); $j++) {
                if (in_array(get_uid_by_pid($current_system_planets[$j]), $allies)) {
                    // construction list des planeten heraussuchen
                    $planet_constructions = get_construction_list($current_system_planets[$j]);
                    // gucken ob refuelingstation auf planet gebaut
                    for ($k = 0; $k < sizeof($refueling_stations); $k++) {
                        if (in_array($refueling_stations[$k], $planet_constructions)) {
                            // refueling statoin gefunden
                            $k = sizeof($refueling_stations);
                            $j = sizeof($current_system_planets);
                            $refueling_stations_count++;
                        }
                    }
                }
            }
        }
        // derzeitigen refuel status der flotte ermitteln
        $current_refuel_time = get_reload($fid);
        if ($current_refuel_time == 0) {
            $current_refuel_time = 1;
        }
        $jumps--;
        $max_refuel_time = get_max_reload($fid);
        if ($jumps < 0) {
            $jumps = 0;
        }
        $eta = $current_refuel_time + $jumps * $max_refuel_time - $refueling_stations_count;
        // jetzt noch den weg vom planeten zum system und entgegengesetzt einberechnen
        if ($fleets_target["planet"]["id"] && $current_refuel_time < 2) {
            $eta++;
        }
        if ($fleets_target["planet"]["tid"] != 0) {
            $eta++;
        }
        // lol, nen hack :S
        if ($eta < 1) {
            $eta = 1;
        }
        // weil alles was 0 ist der eigene standort ist und schon am anfang abgefangen wird
    }
    return $eta;
}