Example #1
0
 /**
  * Returns the formatted speed.
  *
  * @return string
  */
 public function getFormattedSpeed()
 {
     return fNumber(Game::getSpeed($this->getId(), $this->get("speed")));
 }
Example #2
0
 /**
  * Select the mission's target and speed.
  *
  * @param integer $galaxy
  * @param integer $system
  * @param integer $position
  * @param string $targetType
  * @param string $code
  * @param array $ships
  *
  * @return Bengine_Game_Controller_Mission
  */
 protected function selectCoordinates($galaxy, $system, $position, $targetType, $code, $ships)
 {
     $this->noAction = true;
     Core::getTPL()->addHTMLHeaderFile("lib/jquery.countdown.js", "js");
     $galaxy = $galaxy > 0 ? (int) $galaxy : Game::getPlanet()->getData("galaxy");
     $system = $system > 0 ? (int) $system : Game::getPlanet()->getData("system");
     $position = $position > 0 ? (int) $position : Game::getPlanet()->getData("position");
     $targetType = $targetType == "tf" ? "tf" : ($targetType == "moon" ? "moon" : "planet");
     $data = array("ships" => array());
     Core::getQuery()->delete("temp_fleet", "planetid = ?", null, null, array(Core::getUser()->get("curplanet")));
     $select = array("u2s.unitid", "u2s.quantity", "d.capicity", "d.speed", "d.consume", "b.name");
     $joins = "LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = u2s.unitid)";
     $joins .= "LEFT JOIN " . PREFIX . "ship_datasheet d ON (d.unitid = u2s.unitid)";
     $result = Core::getQuery()->select("unit2shipyard u2s", $select, $joins, Core::getDB()->quoteInto("b.mode = '3' AND u2s.planetid = ?", Core::getUser()->get("curplanet")));
     $capacity = 0;
     $consumption = 0;
     $speed = 0;
     $quantity = 0;
     foreach ($result->fetchAll() as $row) {
         $id = $row["unitid"];
         $quantity = isset($ships[$id]) ? (int) $ships[$id] : 0;
         if ($quantity > $row["quantity"]) {
             $quantity = $row["quantity"];
         }
         if ($quantity > 0) {
             $id = (int) $id;
             $capacity += $row["capicity"] * $quantity;
             $data["ships"][$id]["quantity"] = $quantity;
             $data["ships"][$id]["name"] = $row["name"];
             $data["ships"][$id]["id"] = $id;
             $shipSpeed = Game::getSpeed($id, $row["speed"]);
             if ($speed == 0 || $shipSpeed < $speed) {
                 $speed = $shipSpeed;
             }
             $consumption += $row["consume"] * $quantity;
         }
     }
     $result->closeCursor();
     if (count($data["ships"]) > 0 && $speed > 0) {
         $distance = Game::getDistance($galaxy, $system, $position);
         $time = Game::getFlyTime($distance, $speed);
         Hook::event("MissionSetData", array(&$data, &$quantity, &$consumption, &$speed, &$capacity));
         Core::getTPL()->assign(array("galaxy" => $galaxy, "system" => $system, "position" => $position, "targetType" => $targetType, "code" => $code, "oGalaxy" => Game::getPlanet()->getData("galaxy"), "oSystem" => Game::getPlanet()->getData("system"), "oPos" => Game::getPlanet()->getData("position"), "maxspeedVar" => $speed, "distance" => $distance, "capacity_raw" => $capacity, "basicConsumption" => $consumption, "time" => getTimeTerm($time), "maxspeed" => fNumber($speed), "capacity" => fNumber($capacity - Game::getFlyConsumption($consumption, $distance)), "fuel" => fNumber(Game::getFlyConsumption($consumption, $distance))));
         $data["consumption"] = $consumption;
         $data["maxspeed"] = $speed;
         $data["capacity"] = $capacity;
         $data = serialize($data);
         Core::getQuery()->insert("temp_fleet", array("planetid" => Core::getUser()->get("curplanet"), "data" => $data));
         // Short speed selection
         $selectbox = "";
         for ($n = 10; $n > 0; $n--) {
             $selectbox .= createOption($n * 10, $n * 10, 0);
         }
         Core::getTPL()->assign("speedFromSelectBox", $selectbox);
         // Invatations for alliance attack
         $invitations = array();
         $joins = "LEFT JOIN " . PREFIX . "events e ON (e.eventid = fi.eventid)";
         $joins .= "LEFT JOIN " . PREFIX . "attack_formation af ON (e.eventid = af.eventid)";
         $joins .= "LEFT JOIN " . PREFIX . "galaxy g ON (g.planetid = e.destination)";
         $joins .= "LEFT JOIN " . PREFIX . "galaxy m ON (m.moonid = e.destination)";
         $select = array("af.eventid", "af.name", "af.time", "g.galaxy", "g.system", "g.position", "m.galaxy AS moongala", "m.system AS moonsys", "m.position AS moonpos");
         $_result = Core::getQuery()->select("formation_invitation fi", $select, $joins, Core::getDB()->quoteInto("fi.userid = ? AND af.time > '" . TIME . "'", Core::getUser()->get("userid")));
         foreach ($_result->fetchAll() as $_row) {
             $_row["type"] = 0;
             if (!empty($_row["moongala"]) && !empty($_row["moonsys"]) && !empty($_row["moonpos"])) {
                 $_row["galaxy"] = $_row["moongala"];
                 $_row["system"] = $_row["moonsys"];
                 $_row["position"] = $_row["moonpos"];
                 $_row["type"] = 2;
             }
             $_row["time_r"] = $_row["time"] - TIME;
             $_row["formatted_time"] = getTimeTerm($_row["time_r"]);
             $invitations[] = $_row;
         }
         $_result->closeCursor();
         Core::getTPL()->addLoop("invitations", $invitations);
         // Planet shortlinks
         $sl = array();
         $order = "p.sort_index ASC, p.planetid ASC";
         $where = Core::getDB()->quoteInto("p.userid = ? AND p.planetid != ?", array(Core::getUser()->get("userid"), Core::getUser()->get("curplanet")));
         $_result = Core::getQuery()->select("planet p", array("p.ismoon", "p.planetname", "g.galaxy", "g.system", "g.position", "gm.galaxy moongala", "gm.system as moonsys", "gm.position as moonpos"), "LEFT JOIN " . PREFIX . "galaxy g ON (g.planetid = p.planetid) LEFT JOIN " . PREFIX . "galaxy gm ON (gm.moonid = p.planetid)", $where, $order);
         foreach ($_result->fetchAll() as $_row) {
             $sl[] = array("planetname" => $_row["planetname"], "galaxy" => $_row["ismoon"] ? $_row["moongala"] : $_row["galaxy"], "system" => $_row["ismoon"] ? $_row["moonsys"] : $_row["system"], "position" => $_row["ismoon"] ? $_row["moonpos"] : $_row["position"], "type" => $_row["ismoon"] ? 2 : 0);
         }
         $_result->closeCursor();
         Hook::event("MissionPlanetQuickLinks", array(&$sl));
         Core::getTPL()->addLoop("shortlinks", $sl);
         $this->setTemplate("mission/step2");
     } else {
         Logger::addMessage("NO_SHIPS_SELECTED");
     }
     return $this;
 }
Example #3
0
 /**
  * Sends espionage probes.
  *
  * @param int $target
  * @return Bengine_Game_Controller_Ajax_Fleet
  */
 protected function espionageAction($target)
 {
     if (Game::attackingStoppageEnabled()) {
         $this->display($this->format(Core::getLang()->get("ATTACKING_STOPPAGE_ENABLED")));
     }
     $select = array("p.planetid", "g.galaxy", "g.system", "g.position", "u2s.quantity", "sd.capicity", "sd.speed", "sd.consume", "b.name AS shipname");
     $joins = "LEFT JOIN " . PREFIX . "galaxy g ON (g.planetid = p.planetid)";
     $joins .= "LEFT JOIN " . PREFIX . "unit2shipyard u2s ON (u2s.planetid = p.planetid)";
     $joins .= "LEFT JOIN " . PREFIX . "ship_datasheet sd ON (sd.unitid = u2s.unitid)";
     $joins .= "LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = u2s.unitid)";
     $result = Core::getQuery()->select("planet p", $select, $joins, Core::getDB()->quoteInto("p.planetid = ? AND u2s.unitid = '38'", Core::getUser()->get("curplanet")));
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         $joins = "LEFT JOIN " . PREFIX . "planet p ON (g.planetid = p.planetid)";
         $joins .= "LEFT JOIN " . PREFIX . "user u ON (u.userid = p.userid)";
         $joins .= "LEFT JOIN " . PREFIX . "ban_u b ON (u.userid = b.userid)";
         $where = Core::getDB()->quoteInto("g.planetid = ? OR g.moonid = ?", $target);
         $result = Core::getQuery()->select("galaxy g", array("g.galaxy", "g.system", "g.position", "u.points", "u.last", "u.umode", "b.to"), $joins, $where);
         if ($tar = $result->fetchRow()) {
             $result->closeCursor();
             Hook::event("AjaxSendFleetEspionage", array($this, &$row, &$tar));
             $ignoreNP = false;
             if ($tar["last"] <= TIME - 604800) {
                 $ignoreNP = true;
             } else {
                 if ($tar["to"] >= TIME) {
                     $ignoreNP = true;
                 }
             }
             $data = array();
             // Check for newbie protection
             if ($ignoreNP === false) {
                 $isProtected = isNewbieProtected(Core::getUser()->get("points"), $tar["points"]);
                 if ($isProtected == 1) {
                     $this->display($this->format(Core::getLanguage()->getItem("TARGET_TOO_WEAK")));
                 } else {
                     if ($isProtected == 2) {
                         $this->display($this->format(Core::getLanguage()->getItem("TARGET_TOO_STRONG")));
                     }
                 }
             }
             // Check for vacation mode
             if ($tar["umode"] || Core::getUser()->get("umode")) {
                 $this->display($this->format(Core::getLanguage()->getItem("TARGET_IN_UMODE")));
             }
             // Get quantity
             if ($row["quantity"] >= Core::getUser()->get("esps")) {
                 $data["ships"][38]["quantity"] = Core::getUser()->get("esps") > 0 ? Core::getUser()->get("esps") : 1;
             } else {
                 $data["ships"][38]["quantity"] = $row["quantity"];
             }
             $data["ships"][38]["id"] = 38;
             $data["ships"][38]["name"] = $row["shipname"];
             $data["maxspeed"] = Game::getSpeed(38, $row["speed"]);
             $distance = Game::getDistance($tar["galaxy"], $tar["system"], $tar["position"]);
             $time = Game::getFlyTime($distance, $data["maxspeed"]);
             $data["consumption"] = Game::getFlyConsumption($data["ships"][38]["quantity"] * $row["consume"], $distance);
             if (Game::getPlanet()->getData("hydrogen") < $data["consumption"]) {
                 $this->display($this->format(Core::getLanguage()->getItem("DEFICIENT_CONSUMPTION")));
             }
             if ($row["capicity"] * $data["ships"][38]["quantity"] - $data["consumption"] < 0) {
                 $this->display($this->format(Core::getLanguage()->getItem("DEFICIENT_CAPACITY")));
             }
             Game::getPlanet()->setData("hydrogen", Game::getPlanet()->getData("hydrogen") - $data["consumption"]);
             $data["time"] = $time;
             $data["galaxy"] = $tar["galaxy"];
             $data["system"] = $tar["system"];
             $data["position"] = $tar["position"];
             $data["sgalaxy"] = $row["galaxy"];
             $data["ssystem"] = $row["system"];
             $data["sposition"] = $row["position"];
             $data["metal"] = 0;
             $data["silicon"] = 0;
             $data["hydrogen"] = 0;
             Hook::event("AjaxSendFleetEspionageStartEvent", array($row, $tar, &$data));
             Game::getEH()->addEvent(11, $time + TIME, Core::getUser()->get("curplanet"), Core::getUser()->get("userid"), $target, $data);
             $this->display($this->format(sprintf(Core::getLanguage()->getItem("ESPS_SENT"), $data["ships"][38]["quantity"], $data["galaxy"], $data["system"], $data["position"]), 1));
         } else {
             $result->closeCursor();
             $this->display($this->format("Unkown destination"));
         }
     } else {
         $result->closeCursor();
         $this->display($this->format(Core::getLanguage()->getItem("DEFICIENT_ESPS")));
     }
     return $this;
 }