/** * @return bool */ protected function _match() { if ($this->getUser()->get("hp") == Core::getUser()->get("curplanet")) { return Game::getPlanet()->getData("planetname") != Core::getLang()->get("HOME_PLANET"); } $planet = Game::getModel("game/planet")->load($this->getUser()->get("hp")); return $planet->get("planetname") != Core::getLang()->get("HOME_PLANET"); }
/** * (non-PHPdoc) * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_add($event, $data) */ protected function _add(Bengine_Game_Model_Event $event, array $data) { $planet = Game::getPlanet(); $planet->setData("metal", $planet->getData("metal") - $data["metal"] * $data["quantity"]); $planet->setData("silicon", $planet->getData("silicon") - $data["silicon"] * $data["quantity"]); $planet->setData("hydrogen", $planet->getData("hydrogen") - $data["hydrogen"] * $data["quantity"]); $spec = array("metal" => new Recipe_Database_Expr("metal - ?"), "silicon" => new Recipe_Database_Expr("silicon - ?"), "hydrogen" => new Recipe_Database_Expr("hydrogen - ?")); $bind = array($data["metal"] * $data["quantity"], $data["silicon"] * $data["quantity"], $data["hydrogen"] * $data["quantity"], $event->get("planetid")); $bind = array_map("intval", $bind); Core::getQuery()->update("planet", $spec, "planetid = ?", $bind); return $this; }
public function hasResources() { if ($this->get("basic_metal") > Game::getPlanet()->getData("metal")) { return false; } if ($this->get("basic_silicon") > Game::getPlanet()->getData("silicon")) { return false; } if ($this->get("basic_hydrogen") > Game::getPlanet()->getData("hydrogen")) { return false; } $energy = Game::getPlanet()->getEnergy() < 0 ? 0 : Game::getPlanet()->getEnergy(); if ($this->get("basic_energy") > $energy) { return false; } return true; }
/** * Checks the resources. * * @return boolean True if resources suffice, fals if not */ protected function checkResources() { if ($this->requiredMetal > Game::getPlanet()->getData("metal")) { return false; } if ($this->requiredSilicon > Game::getPlanet()->getData("silicon")) { return false; } if ($this->requiredHydrogen > Game::getPlanet()->getData("hydrogen")) { return false; } $energy = Game::getPlanet()->getEnergy() < 0 ? 0 : Game::getPlanet()->getEnergy(); if ($this->requiredEnergy > $energy) { return false; } return true; }
/** * Checks if the current planet has enough resources to build this. * * @return bool */ public function hasResources() { $required = $this->calculateRequiredResources(); if ($required["required_metal"] > Game::getPlanet()->getData("metal")) { return false; } if ($required["required_silicon"] > Game::getPlanet()->getData("silicon")) { return false; } if ($required["required_hydrogen"] > Game::getPlanet()->getData("hydrogen")) { return false; } $energy = Game::getPlanet()->getEnergy() < 0 ? 0 : Game::getPlanet()->getEnergy(); if ($required["required_energy"] > $energy) { return false; } return true; }
/** * Checks for validation. * * @throws Recipe_Exception_Generic * @return Bengine_Game_Controller_MonitorPlanet */ protected function validate() { if (!$this->planetData->getPlanetid() || $this->planetData->getIsmoon() || Core::getUser()->get("curplanet") == $this->planetData->getPlanetid()) { throw new Recipe_Exception_Generic("The selected planet is unavailable."); } // Check range if (Game::getPlanet()->getBuilding("STAR_SURVEILLANCE") <= 0) { throw new Recipe_Exception_Generic("Range exceeded."); } $range = pow(Game::getPlanet()->getBuilding("STAR_SURVEILLANCE"), 2) - 1; $diff = abs(Game::getPlanet()->getData("system") - $this->planetData->getSystem()); if ($this->planetData->getGalaxy() != Game::getPlanet()->getData("galaxy") || $range < $diff) { throw new Recipe_Exception_Generic("Range exceeded."); } // Check consumption Core::getLanguage()->load(array("Galaxy", "Main", "info")); if (Game::getPlanet()->getData("hydrogen") < Core::getOptions()->get("STAR_SURVEILLANCE_CONSUMPTION")) { Logger::dieMessage("DEFICIENT_CONSUMPTION"); } return $this; }
/** * Checks the resource against the given quantity and reduce it if needed. * * @param integer $qty Quantity * @param Bengine_Game_Model_Unit $construction Ship data row * * @return integer */ protected function checkResourceForQuantity($qty, Bengine_Game_Model_Unit $construction) { $basicMetal = $construction->get("basic_metal"); $basicSilicon = $construction->get("basic_silicon"); $basicHydrogen = $construction->get("basic_hydrogen"); $basicEnergy = $construction->get("basic_energy"); $metal = _pos(Game::getPlanet()->getData("metal")); $silicon = _pos(Game::getPlanet()->getData("silicon")); $hydrogen = _pos(Game::getPlanet()->getData("hydrogen")); $energy = _pos(Game::getPlanet()->getEnergy()); $requiredMetal = $basicMetal * $qty; $requiredSilicon = $basicSilicon * $qty; $requiredHydrogen = $basicHydrogen * $qty; $requiredEnergy = $basicEnergy * $qty; if ($requiredMetal > $metal || $requiredSilicon > $silicon || $requiredHydrogen > $hydrogen || $requiredEnergy > $energy) { // Try to reduce quantity $q = array(); $q[] = $basicMetal > 0 ? floor($metal / $basicMetal) : $qty; $q[] = $basicSilicon > 0 ? floor($silicon / $basicSilicon) : $qty; $q[] = $basicHydrogen > 0 ? floor($hydrogen / $basicHydrogen) : $qty; $q[] = $basicEnergy > 0 ? floor($energy / $basicEnergy) : $qty; $qty = min($q); } return $qty; }
/** * Index action. * * @return Bengine_Game_Controller_Techtree */ protected function indexAction() { $reqs = Game::getAllRequirements(); $cons = array(); $research = array(); $ships = array(); $def = array(); $moon = array(); $result = Core::getQuery()->select("construction", array("buildingid", "mode", "name"), "ORDER BY display_order ASC, buildingid ASC"); foreach ($result->fetchAll() as $row) { Hook::event("LoadTechtree", array(&$row)); $bid = $row["buildingid"]; $requirements = ""; if (!isset($reqs[$bid])) { $reqs[$bid] = array(); } foreach ($reqs[$bid] as $r) { $buffer = Core::getLanguage()->getItem($r["name"]) . " (" . Core::getLanguage()->getItem("LEVEL") . " " . $r["level"] . ")</span><br />"; $rLevel = 0; if ($r["mode"] == 1 || $r["mode"] == 5) { $rLevel = Game::getPlanet()->getBuilding($r["needs"]); } else { if ($r["mode"] == 2) { $rLevel = Game::getResearch($r["needs"]); } } if ($rLevel >= $r["level"]) { $requirements .= "<span class=\"true\">" . $buffer; } else { $requirements .= "<span class=\"false\">" . $buffer; } } $name = Core::getLanguage()->getItem($row["name"]); switch ($row["mode"]) { case 1: $cons[$bid]["name"] = Link::get("game/" . SID . "/Constructions/Info/" . $row["buildingid"], $name); $cons[$bid]["requirements"] = $requirements; break; case 2: $research[$bid]["name"] = Link::get("game/" . SID . "/Constructions/Info/" . $row["buildingid"], $name); $research[$bid]["requirements"] = $requirements; break; case 3: $ships[$bid]["name"] = Link::get("game/" . SID . "/Unit/Info/" . $row["buildingid"], $name); $ships[$bid]["requirements"] = $requirements; break; case 4: $def[$bid]["name"] = Link::get("game/" . SID . "/Unit/Info/" . $row["buildingid"], $name); $def[$bid]["requirements"] = $requirements; break; case 5: $moon[$bid]["name"] = Link::get("game/" . SID . "/Constructions/Info/" . $row["buildingid"], $name); $moon[$bid]["requirements"] = $requirements; break; } } $result->closeCursor(); Hook::event("ShowLoadedTechtree", array(&$cons, &$research, &$ships, &$def, &$moon, &$moon)); Core::getTPL()->addLoop("construction", $cons); Core::getTPL()->addLoop("research", $research); Core::getTPL()->addLoop("shipyard", $ships); Core::getTPL()->addLoop("defense", $def); Core::getTPL()->addLoop("moon", $moon); return $this; }
/** * Shows form for planet options. * * @param string $planetname * @param boolean $abandon * @param string $password * * @return Bengine_Game_Controller_Index */ protected function changePlanetOptions($planetname, $abandon, $password) { $planetname = trim($planetname); Hook::event("SAVE_PLANET_OPTIONS", array(&$planetname, &$abandon)); if ($abandon == 1) { $ok = true; if (Game::getEH()->getPlanetFleetEvents()) { Logger::addMessage("CANNOT_DELETE_PLANET"); $ok = false; } if (Core::getUser()->get("hp") == Core::getUser()->get("curplanet")) { Logger::addMessage("CANNOT_DELETE_HOMEPLANET"); $ok = false; } $result = Core::getQuery()->select("password", "password", "", Core::getDB()->quoteInto("userid = ?", Core::getUser()->get("userid"))); $row = $result->fetchRow(); $result->closeCursor(); $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5"; $password = Str::encode($password, $encryption); if (!Str::compare($row["password"], $password)) { Logger::addMessage("WRONG_PASSWORD"); $ok = false; } if ($ok) { deletePlanet(Game::getPlanet()->getPlanetId(), Core::getUser()->get("userid"), Game::getPlanet()->getData("ismoon")); Core::getQuery()->update("user", array("curplanet" => Core::getUser()->get("hp")), "userid = ?", array(Core::getUser()->get("userid"))); Core::getUser()->rebuild(); $this->redirect("game/" . SID . "/Index"); } } else { if (checkCharacters($planetname)) { Core::getQuery()->update("planet", array("planetname" => $planetname), "planetid = ?", array(Core::getUser()->get("curplanet"))); $this->redirect("game/" . SID . "/Index"); } else { Logger::addMessage("INVALID_PLANET_NAME"); } } return $this; }
/** * Shows all building information. * * @param integer $id * @throws Recipe_Exception_Generic * @return Bengine_Game_Controller_Constructions */ protected function infoAction($id) { $select = array("name", "demolish", "basic_metal", "basic_silicon", "basic_hydrogen", "basic_energy", "prod_metal", "prod_silicon", "prod_hydrogen", "prod_energy", "special", "cons_metal", "cons_silicon", "cons_hydrogen", "cons_energy", "charge_metal", "charge_silicon", "charge_hydrogen", "charge_energy"); $result = Core::getQuery()->select("construction", $select, "", Core::getDB()->quoteInto("buildingid = ? AND (mode = '1' OR mode = '2' OR mode = '5')", $id)); if ($row = $result->fetchRow()) { $result->closeCursor(); Core::getLanguage()->load("info,Resource"); Hook::event("BuildingInfoBefore", array(&$row)); // Assign general building data Core::getTPL()->assign("buildingName", Core::getLanguage()->getItem($row["name"])); Core::getTPL()->assign("buildingDesc", Core::getLanguage()->getItem($row["name"] . "_FULL_DESC")); Core::getTPL()->assign("buildingImage", Image::getImage("buildings/" . $row["name"] . ".gif", Core::getLanguage()->getItem($row["name"]), null, null, "leftImage")); Core::getTPL()->assign("edit", Link::get("game/" . SID . "/Construction_Edit/Index/" . $id, "[" . Core::getLanguage()->getItem("EDIT") . "]")); // Production and consumption of the building $prodFormula = false; if (!empty($row["prod_metal"])) { $prodFormula = $row["prod_metal"]; $baseCost = $row["basic_metal"]; } else { if (!empty($row["prod_silicon"])) { $prodFormula = $row["prod_silicon"]; $baseCost = $row["basic_metal"]; } else { if (!empty($row["prod_hydrogen"])) { $prodFormula = $row["prod_hydrogen"]; $baseCost = $row["basic_hydrogen"]; } else { if (!empty($row["prod_energy"])) { $prodFormula = $row["prod_energy"]; $baseCost = $row["basic_energy"]; } else { if (!empty($row["special"])) { $prodFormula = $row["special"]; $baseCost = 0; } } } } } $consFormula = false; if (!empty($row["cons_metal"])) { $consFormula = $row["cons_metal"]; } else { if (!empty($row["cons_silicon"])) { $consFormula = $row["cons_silicon"]; } else { if (!empty($row["cons_hydrogen"])) { $consFormula = $row["cons_hydrogen"]; } else { if (!empty($row["cons_energy"])) { $consFormula = $row["cons_energy"]; } } } } // Production and consumption chart $chartType = false; if ($prodFormula != false || $consFormula != false) { $chart = array(); $chartType = "cons_chart"; if ($prodFormula && $consFormula) { $chartType = "prod_and_cons_chart"; } else { if ($prodFormula) { $chartType = "prod_chart"; } } if (Game::getPlanet()->getBuilding($id) - 7 < 0) { $start = 7; } else { $start = Game::getPlanet()->getBuilding($id); } $productionFactor = (double) Core::getConfig()->get("PRODUCTION_FACTOR"); if (!empty($row["prod_energy"])) { $productionFactor = 1; } $currentProduction = 0; if ($prodFormula) { $currentProduction = parseFormula($prodFormula, $baseCost, Game::getPlanet()->getBuilding($id)) * $productionFactor; } $currentConsumption = 0; if ($consFormula) { $currentConsumption = parseFormula($consFormula, 0, Game::getPlanet()->getBuilding($id)); } for ($i = $start - 7; $i <= Game::getPlanet()->getBuilding($id) + 7; $i++) { $chart[$i]["level"] = $i; $chart[$i]["s_prod"] = $prodFormula ? parseFormula($prodFormula, $baseCost, $i) * $productionFactor : 0; $chart[$i]["s_diffProd"] = $prodFormula ? $chart[$i]["s_prod"] - $currentProduction : 0; $chart[$i]["s_cons"] = $consFormula ? parseFormula($consFormula, 0, $i) : 0; $chart[$i]["s_diffCons"] = $consFormula ? $currentConsumption - $chart[$i]["s_cons"] : 0; $chart[$i]["prod"] = fNumber($chart[$i]["s_prod"]); $chart[$i]["diffProd"] = fNumber($chart[$i]["s_diffProd"]); $chart[$i]["cons"] = fNumber($chart[$i]["s_cons"]); $chart[$i]["diffCons"] = fNumber($chart[$i]["s_diffCons"]); } Hook::event("BuildingInfoProduction", array(&$chart)); Core::getTPL()->addLoop("chart", $chart); } if ($chartType) { Core::getTPL()->assign("chartType", "game/constructions/" . $chartType); } // Show demolish function $factor = floatval($row["demolish"]); if (Game::getPlanet()->getBuilding($id) > 0 && $factor > 0.0) { Core::getTPL()->assign("buildingLevel", Game::getPlanet()->getBuilding($id)); Core::getTPL()->assign("demolish", true); $metal = ""; $_metal = 0; $silicon = ""; $_silicon = 0; $hydrogen = ""; $_hydrogen = 0; if ($row["basic_metal"] > 0) { $_metal = 1 / $factor * parseFormula($row["charge_metal"], $row["basic_metal"], Game::getPlanet()->getBuilding($id)); $metal = Core::getLanguage()->getItem("METAL") . ": " . fNumber($_metal); } Core::getTPL()->assign("metal", $metal); if ($row["basic_silicon"] > 0) { $_silicon = 1 / $factor * parseFormula($row["charge_silicon"], $row["basic_silicon"], Game::getPlanet()->getBuilding($id)); $silicon = Core::getLanguage()->getItem("SILICON") . ": " . fNumber($_silicon); } Core::getTPL()->assign("silicon", $silicon); if ($row["basic_hydrogen"] > 0) { $_hydrogen = 1 / $factor * parseFormula($row["charge_hydrogen"], $row["basic_hydrogen"], Game::getPlanet()->getBuilding($id)); $hydrogen = Core::getLanguage()->getItem("HYDROGEN") . ": " . fNumber($_hydrogen); } Core::getTPL()->assign("hydrogen", $hydrogen); $time = getBuildTime($_metal, $_silicon, self::BUILDING_CONSTRUCTION_TYPE); Core::getTPL()->assign("dimolishTime", getTimeTerm($time)); $showLink = Game::getPlanet()->getData("metal") >= $_metal && Game::getPlanet()->getData("silicon") >= $_silicon && Game::getPlanet()->getData("hydrogen") >= $_hydrogen; if ($id == 12 && Game::getEH()->getResearchEvent()) { $showLink = false; } $shipyardSize = Game::getEH()->getShipyardEvents()->getCalculatedSize(); if (($id == 8 || $id == 7) && $shipyardSize > 0) { $showLink = false; } Core::getTPL()->assign("showLink", $showLink && !$this->event && !Core::getUser()->get("umode")); Core::getTPL()->assign("demolishNow", Link::get("game/" . SID . "/Constructions/Demolish/{$id}", Core::getLanguage()->getItem("DEMOLISH_NOW"))); } else { Core::getTPL()->assign("demolish", false); } Hook::event("BuildingInfoAfter", array(&$row)); } else { $result->closeCursor(); throw new Recipe_Exception_Generic("Unkown building. You'd better don't manipulate the URL. We see everything ;)"); } return $this; }
/** * Checks if the current solar system is in missile range. * * @return boolean */ protected function inMissileRange() { if ($this->galaxy != Game::getPlanet()->getData("galaxy")) { return false; } if (abs(Game::getPlanet()->getData("system") - $this->system) <= $this->missileRange) { return true; } return false; }
/** * Saves resource production factor. * * @return Bengine_Game_Controller_Resource */ protected function updateAction() { if (!Core::getUser()->get("umode")) { $post = Core::getRequest()->getPOST(); Hook::event("SaveResources"); foreach ($this->data as $key => $value) { if ($value["level"] > 0) { $factor = abs(isset($post[$key]) ? $post[$key] : 100); $factor = $factor > 100 ? 100 : $factor; Core::getQuery()->update("building2planet", array("prod_factor" => $factor), "buildingid = ? AND planetid = ?", array($key, Core::getUser()->get("curplanet"))); } } if (Game::getPlanet()->getBuilding(Bengine_Game_Planet::SOLAR_SAT_ID) > 0) { $satelliteProd = abs($post[39]); $satelliteProd = $satelliteProd > 100 ? 100 : $satelliteProd; Core::getQuery()->update("planet", array("solar_satellite_prod" => $satelliteProd), "planetid = ?", array(Core::getUser()->get("curplanet"))); } } $this->redirect("game/" . SID . "/Resource"); return $this; }
/** * This starts the missions and shows a quick overview of the flight. * * @param integer $mode * @param integer $metal * @param integer $silicon * @param integer $hydrogen * @param integer $holdingTime * @throws Recipe_Exception_Generic * @return Bengine_Game_Controller_Mission */ protected function sendFleet($mode, $metal, $silicon, $hydrogen, $holdingTime) { $this->noAction = true; $fleetEvents = Game::getEH()->getOwnFleetEvents(); if ($fleetEvents && Game::getResearch(14) + 1 <= count(Game::getEH()->getOwnFleetEvents())) { throw new Recipe_Exception_Generic("Too many fleets on missions."); } $result = Core::getQuery()->select("temp_fleet", "data", "", Core::getDB()->quoteInto("planetid = ?", Core::getUser()->get("curplanet"))); if ($row = $result->fetchRow()) { $result->closeCursor(); $temp = unserialize($row["data"]); if (!in_array($mode, $temp["amissions"])) { Logger::dieMessage("UNKNOWN_MISSION"); } $data["ships"] = $temp["ships"]; $data["galaxy"] = $temp["galaxy"]; $data["system"] = $temp["system"]; $data["position"] = $temp["position"]; $data["sgalaxy"] = Game::getPlanet()->getData("galaxy"); $data["ssystem"] = Game::getPlanet()->getData("system"); $data["sposition"] = Game::getPlanet()->getData("position"); $data["maxspeed"] = $temp["maxspeed"]; $distance = Game::getDistance($data["galaxy"], $data["system"], $data["position"]); $data["consumption"] = Game::getFlyConsumption($temp["consumption"], $distance, $temp["speed"]); if (Game::getPlanet()->getData("hydrogen") - $data["consumption"] < 0) { Logger::dieMessage("NOT_ENOUGH_FUEL"); } if ($temp["capacity"] < $data["consumption"]) { Logger::dieMessage("NOT_ENOUGH_CAPACITY"); } $data["metal"] = (int) abs($metal); $data["silicon"] = (int) abs($silicon); $data["hydrogen"] = (int) abs($hydrogen); if ($data["metal"] > Game::getPlanet()->getData("metal")) { $data["metal"] = _pos(Game::getPlanet()->getData("metal")); } if ($data["silicon"] > Game::getPlanet()->getData("silicon")) { $data["silicon"] = _pos(Game::getPlanet()->getData("silicon")); } if ($data["hydrogen"] > Game::getPlanet()->getData("hydrogen") - $data["consumption"]) { $data["hydrogen"] = _pos(Game::getPlanet()->getData("hydrogen") - $data["consumption"]); } if ($mode == 13) { $data["duration"] = _pos($holdingTime); if ($data["duration"] > 24) { $data["duration"] = 24; } $data["duration"] *= 3600; } $capa = $temp["capacity"] - $data["consumption"] - $data["metal"] - $data["silicon"] - $data["hydrogen"]; // Reduce used capacity automatically if ($capa < 0) { if ($capa + $data["hydrogen"] > 0) { $data["hydrogen"] -= abs($capa); } else { $capa += $data["hydrogen"]; $data["hydrogen"] = 0; if ($capa + $data["silicon"] > 0 && $capa < 0) { $data["silicon"] -= abs($capa); } else { if ($capa < 0) { $capa += $data["silicon"]; $data["silicon"] = 0; if ($capa + $data["metal"] && $capa < 0) { $data["metal"] -= abs($capa); } else { if ($capa < 0) { $data["metal"] = 0; } } } } } } $data["capacity"] = $temp["capacity"] - $data["consumption"] - $data["metal"] - $data["silicon"] - $data["hydrogen"]; if ($data["capacity"] < 0) { Logger::dieMessage("NOT_ENOUGH_CAPACITY"); } // If mission is recycling, get just the capacity of the recyclers. if ($mode == 9 && $data["capacity"] > 0) { $_result = Core::getQuery()->select("ship_datasheet", "capicity", "", "unitid = '37'"); // It is __capacity__ and not capicity $_row = $_result->fetchRow(); $_result->closeCursor(); $recCapa = $_row["capicity"] * $temp["ships"][37]["quantity"]; if ($data["capacity"] >= $recCapa) { $data["capacity"] = $recCapa; } } $time = Game::getFlyTime($distance, $data["maxspeed"], $temp["speed"]); $data["time"] = $time; if ($mode == 18) { $data["alliance_attack"] = $temp["alliance_attack"]; $mainFleet = Game::getEH()->getMainFormationFleet($data["alliance_attack"]["eventid"]); $allFleets = Game::getEH()->getFormationFleets($data["alliance_attack"]["eventid"]); $numFleets = 1; $formationUser[$mainFleet->get("user")] = true; /* @var Bengine_Game_Model_Fleet $oneFleet */ foreach ($allFleets as $oneFleet) { $numFleets++; $formationUser[$oneFleet->get("user")] = true; } unset($formationUser[Core::getUser()->get("userid")]); if ($numFleets >= Core::getOptions()->get("MAX_FORMATION_FLEETS")) { Logger::dieMessage("MAX_FORMATION_FLEETS_EXCEEDED"); } if (count($formationUser) >= Core::getOptions()->get("MAX_FORMATION_USER")) { Logger::dieMessage("MAX_FORMATION_USER_EXCEEDED"); } if ($data["time"] + TIME > ($mainFleet["time"] - TIME) * (1 + Core::getOptions()->get("MAX_FORMATION_DELAY")) + TIME) { Logger::dieMessage("MAX_FORMATION_DELAY_EXCEEDED"); } } Hook::event("SendFleet", array(&$data, &$time, &$temp, $distance)); Core::getQuery()->delete("temp_fleet", "planetid = ?", null, null, array(Core::getUser()->get("curplanet"))); $handler = Game::getEH()->addEvent($mode, $time + TIME, Core::getUser()->get("curplanet"), Core::getUser()->get("userid"), isset($temp["destination"]) ? $temp["destination"] : null, $data); Core::getTPL()->assign("mission", Game::getMissionName($mode)); Core::getTPL()->assign("mode", $mode); Core::getTPL()->assign("distance", fNumber($distance)); Core::getTPL()->assign("speed", fNumber($temp["maxspeed"])); Core::getTPL()->assign("consume", fNumber($data["consumption"])); Core::getTPL()->assign("start", Game::getPlanet()->getCoords(false)); Core::getTPL()->assign("target", $data["galaxy"] . ":" . $data["system"] . ":" . $data["position"]); Core::getTPL()->assign("arrival", Date::timeToString(1, $handler->getFinishTime())); if ($returnTime = $handler->getReturnTime()) { Core::getTPL()->assign("return", Date::timeToString(1, $returnTime)); } $fleet = array(); foreach ($data["ships"] as $key => $value) { $fleet[$key]["name"] = Core::getLanguage()->getItem($value["name"]); $fleet[$key]["quantity"] = fNumber($value["quantity"]); } Core::getTPL()->addLoop("fleet", $fleet); $this->setTemplate("mission/step4"); } return $this; }
/** * 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; }
/** * Check for sufficient resources and start research upgrade. * * @param integer $id Building id to upgrade * @throws Recipe_Exception_Generic * @return Bengine_Game_Controller_Research */ protected function upgradeAction($id) { // Check events if ($this->event != false || Core::getUser()->get("umode")) { $this->redirect("game/" . SID . "/Research"); } // Check for requirements if (!Game::canBuild($id) || !Game::getPlanet()->getBuilding("RESEARCH_LAB")) { throw new Recipe_Exception_Generic("You do not fulfil the requirements to research this."); } // Check if research labor is not in progress if (!Game::getEH()->canReasearch()) { throw new Recipe_Exception_Generic("Research labor in progress."); } /* @var Bengine_Game_Model_Construction $construction */ $construction = Game::getModel("game/construction"); $construction->load($id); if (!$construction->getId()) { throw new Recipe_Exception_Generic("Unkown research :("); } if ($construction->get("mode") != self::RESEARCH_CONSTRUCTION_TYPE) { throw new Recipe_Exception_Generic("Research not allowed."); } if (Game::getPlanet()->getData("ismoon") && !$construction->get("allow_on_moon")) { throw new Recipe_Exception_Generic("Research not allowed."); } Hook::event("UpgradeResearchFirst", array($construction)); // Get required resources $level = Game::getResearch($id); if ($level > 0) { $level = $level + 1; } else { $level = 1; } $this->setRequieredResources($level, $construction); // Check resources if ($this->checkResources()) { $data["metal"] = $this->requiredMetal; $data["silicon"] = $this->requiredSilicon; $data["hydrogen"] = $this->requiredHydrogen; $data["energy"] = $this->requiredEnergy; $time = getBuildTime($data["metal"], $data["silicon"], self::RESEARCH_CONSTRUCTION_TYPE); $data["level"] = $level; $data["buildingid"] = $id; $data["buildingname"] = $construction->get("name"); Hook::event("UpgradeResearchLast", array($construction, &$data, &$time)); Game::getEH()->addEvent(3, $time + TIME, Core::getUser()->get("curplanet"), Core::getUser()->get("userid"), null, $data); $this->redirect("game/" . SID . "/Research"); } else { Logger::dieMessage("INSUFFICIENT_RESOURCES"); } return $this; }
/** * Prepares a fleet for launch (remove ships from planet, extract consumption, ...) * * @param array $data * @throws Recipe_Exception_Generic * @return Bengine_Game_EventHandler_Handler_Abstract */ protected function prepareFleet(array $data) { foreach ($data["ships"] as $unit_id => $ships) { $result = Core::getQuery()->select("unit2shipyard", array("quantity"), "", Core::getDB()->quoteInto("unitid = ? AND planetid = ?", array($unit_id, Game::getPlanet()->getPlanetId()))); $availQty = $result->fetchColumn(); $result->closeCursor(); if ($availQty < $ships["quantity"]) { throw new Recipe_Exception_Generic("Sorry, you have been attacked. Process stopped."); } Core::getDB()->query("UPDATE " . PREFIX . "unit2shipyard SET quantity = quantity - ? WHERE unitid = ? AND planetid = ?", array($ships["quantity"], $unit_id, Game::getPlanet()->getPlanetId())); } $this->removeResourceFromPlanet($data); Core::getQuery()->delete("unit2shipyard", "quantity = '0'"); return $this; }
/** * Returns building time due to the used resources. * * @param integer $metal Used metal * @param integer $silicon Used silicon * @param integer $mode Building mode (1: building, 2: unit, 3: research) * @throws Recipe_Exception_Generic * @return integer Time in seconds */ function getBuildTime($metal, $silicon, $mode) { switch ($mode) { case 1: // Buildings // Buildings case 5: $roboFactory = Game::getPlanet()->getBuilding("ROBOTIC_FACTORY"); $time = ($metal + $silicon) / 2500 * (1 / ($roboFactory + 1)) * pow(0.5, Game::getPlanet()->getBuilding("NANO_FACTORY")); break; case 2: // Research $time = Game::getResearchTime($metal + $silicon); break; case 3: // Shipyard // Shipyard case 4: $time = ($metal + $silicon) / 5000 * (2 / (Game::getPlanet()->getBuilding("SHIPYARD") + 1)) * pow(0.5, Game::getPlanet()->getBuilding("NANO_FACTORY")); break; default: throw new Recipe_Exception_Generic("Unknown mode for build time calculation."); break; } if (is_numeric(Core::getOptions()->get("GAMESPEED")) && Core::getOptions()->get("GAMESPEED") > 0) { $time *= 3600 * floatval(Core::getOptions()->get("GAMESPEED")); } Hook::event("ConstructTime", array(&$time, $metal, $silicon, $mode)); return (int) max(ceil($time), 1); }