Beispiel #1
0
 public function getProductionTime($formatted = false)
 {
     if (!$this->exists("production_time")) {
         $this->set("production_time", getBuildTime($this->get("basic_metal"), $this->get("basic_silicon"), $this->get("mode")));
     }
     $time = $this->get("production_time");
     return $formatted ? getTimeTerm($time) : $time;
 }
Beispiel #2
0
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Returns production time.
  *
  * @param bool $formatted
  * @return int|string
  */
 public function getProductionTime($formatted = false)
 {
     if (!$this->exists("production_time")) {
         $required = $this->calculateRequiredResources();
         $time = getBuildTime($required["required_metal"], $required["required_silicon"], $this->get("mode"));
         $this->set("production_time", $time);
     }
     $time = $this->get("production_time");
     return $formatted ? getTimeTerm($time) : $time;
 }
Beispiel #5
0
 /**
  * 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;
 }