/** * 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; }
/** * Starts an event for building units. * * @throws Recipe_Exception_Generic * @return Bengine_Game_Controller_Shipyard */ protected function orderAction() { if (Core::getUser()->get("umode") || Game::isDbLocked()) { $this->redirect("game/" . SID . "/" . Core::getRequest()->getGET("controller")); } if (!$this->canBuildUnits) { throw new Recipe_Exception_Generic("Shipyard or nano factory in progress."); } $post = Core::getRequest()->getPOST(); /* @var Bengine_Game_Model_Collection_Construction $collection */ $collection = Application::getCollection("game/construction", "game/unit"); $collection->addTypeFilter($this->mode, Game::getPlanet()->getData("ismoon"))->addShipyardJoin(Core::getUser()->get("curplanet")); foreach ($collection as $construction) { /* @var Bengine_Game_Model_Unit $construction */ $id = $construction->getId(); if (isset($post[$id]) && $post[$id] > 0) { // Check for requirements if (!Game::canBuild($id)) { throw new Recipe_Exception_Generic("You cannot build this."); } $quantity = _pos($post[$id]); if ($quantity > Core::getConfig()->get("SHIPYARD_MAX_UNITS_PER_ORDER")) { $quantity = (int) Core::getConfig()->get("SHIPYARD_MAX_UNITS_PER_ORDER"); } Hook::event("UnitOrderStart", array($construction, &$quantity)); if ($id == 49 || $id == 50) { $where = Core::getDB()->quoteInto("unitid = ? AND planetid = ?", array($id, Core::getUser()->get("curplanet"))); $_result = Core::getQuery()->select("unit2shipyard", "quantity", "", $where); if ($_result->rowCount() > 0) { throw new Recipe_Exception_Generic("You cannot build this."); } $_result->closeCursor(); if (Game::getEH()->hasSmallShieldDome() && $id == 49) { throw new Recipe_Exception_Generic("You cannot build this."); } if (Game::getEH()->hasLargeShieldDome() && $id == 50) { throw new Recipe_Exception_Generic("You cannot build this."); } $quantity = 1; // Make sure that shields cannot be build twice } if ($id == 51 || $id == 52) { $maxsize = Game::getRocketStationSize(); // Check max. size if (!$this->canBuildRockets) { continue; } // Decrease quantity, if necessary if ($id == 52) { $quantity *= 2; } if ($quantity > $maxsize - $this->existingRockets) { $quantity = $maxsize - $this->existingRockets; } if ($id == 52) { $quantity = floor($quantity / 2); } } // Check resources $quantity = $this->checkResourceForQuantity($quantity, $construction); // make event if ($quantity > 0) { $latest = TIME; $existingEvents = Game::getEH()->getShipyardEvents(); foreach ($existingEvents as $existingEvent) { if ($existingEvent->getData("finished") > $latest) { $latest = $existingEvent->getData("finished"); } } $time = getBuildTime($construction->get("basic_metal"), $construction->get("basic_silicon"), $this->mode); $data["one"] = $time; $data["quantity"] = $quantity; $data["finished"] = $time * $quantity + $latest; $data["mission"] = $construction->get("name"); $data["buildingid"] = $id; $data["metal"] = $construction->get("basic_metal"); $data["silicon"] = $construction->get("basic_silicon"); $data["hydrogen"] = $construction->get("basic_hydrogen"); $data["points"] = ($construction->get("basic_metal") + $construction->get("basic_silicon") + $construction->get("basic_hydrogen")) / 1000; $mode = $this->mode == self::FLEET_CONSTRUCTION_TYPE ? 4 : 5; Hook::event("UnitOrderLast", array($construction, $quantity, $mode, &$time, &$latest, &$data)); Game::getEH()->addEvent($mode, $time + $latest, Core::getUser()->get("curplanet"), Core::getUser()->get("userid"), null, $data); } } } $this->redirect("game/" . SID . "/" . Core::getRequest()->getGET("controller")); return $this; }
/** * Check for sufficient resources and start to upgrade building. * * @param integer $id Building id to upgrade * @throws Recipe_Exception_Generic * @return Bengine_Game_Controller_Constructions */ protected function upgradeAction($id) { // Check events if ($this->event != false || Core::getUser()->get("umode")) { $this->redirect("game/" . SID . "/Constructions"); } if ($id == 12 && Game::getEH()->getResearchEvent()) { throw new Recipe_Exception_Generic("Do not mess with the url."); } $shipyardSize = Game::getEH()->getShipyardEvents()->getCalculatedSize(); if (($id == 8 || $id == 7) && $shipyardSize > 0) { throw new Recipe_Exception_Generic("Do not mess with the url."); } // Check fields if (!Game::getPlanet()->planetFree()) { Logger::dieMessage("PLANET_FULLY_DEVELOPED"); } // Check for requirements if (!Game::canBuild($id)) { throw new Recipe_Exception_Generic("You do not fulfil the requirements to build this."); } // Load building data Core::getLanguage()->load(array("info", "buildings")); $isMoon = Game::getPlanet()->getData("ismoon"); /* @var Bengine_Game_Model_Construction $construction */ $construction = Game::getModel("game/construction"); $construction->load($id); if (!$construction->getId()) { throw new Recipe_Exception_Generic("Unkown building :("); } $mode = $construction->get("mode"); if ($isMoon && $mode != self::MOON_CONSTRUCTION_TYPE) { if ($mode == self::BUILDING_CONSTRUCTION_TYPE && !$construction->get("allow_on_moon")) { throw new Recipe_Exception_Generic("Building not allowed."); } } if (!$isMoon && $mode != self::BUILDING_CONSTRUCTION_TYPE) { throw new Recipe_Exception_Generic("Building not allowed."); } Hook::event("UpgradeBuildingFirst", array($construction)); // Get required resources $level = Game::getPlanet()->getBuilding($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::BUILDING_CONSTRUCTION_TYPE); $data["level"] = $level; $data["buildingid"] = $id; $data["buildingname"] = $construction->get("name"); Hook::event("UpgradeBuildingLast", array($construction, &$data, &$time)); Game::getEH()->addEvent(1, $time + TIME, Core::getUser()->get("curplanet"), Core::getUser()->get("userid"), null, $data); $this->redirect("game/" . SID . "/Constructions"); } else { Logger::dieMessage("INSUFFICIENT_RESOURCES"); } return $this; }