/** * Stores the required resources for the current building. * * @param integer $nextLevel * @param Bengine_Game_Model_Construction $construction * * @return Bengine_Game_Controller_Construction_Abstract */ protected function setRequieredResources($nextLevel, Bengine_Game_Model_Construction $construction) { $basicMetal = $construction->get("basic_metal"); $basicSilicon = $construction->get("basic_silicon"); $basicHydrogen = $construction->get("basic_hydrogen"); $basicEnergy = $construction->get("basic_energy"); if ($nextLevel > 1) { if ($basicMetal > 0) { $this->requiredMetal = parseFormula($construction->get("charge_metal"), $basicMetal, $nextLevel); } else { $this->requiredMetal = 0; } if ($basicSilicon > 0) { $this->requiredSilicon = parseFormula($construction->get("charge_silicon"), $basicSilicon, $nextLevel); } else { $this->requiredSilicon = 0; } if ($basicHydrogen > 0) { $this->requiredHydrogen = parseFormula($construction->get("charge_hydrogen"), $basicHydrogen, $nextLevel); } else { $this->requiredHydrogen = 0; } if ($basicEnergy > 0) { $this->requiredEnergy = parseFormula($construction->get("charge_energy"), $basicEnergy, $nextLevel); } else { $this->requiredEnergy = 0; } } else { $this->requiredMetal = (int) $basicMetal; $this->requiredSilicon = (int) $basicSilicon; $this->requiredHydrogen = (int) $basicHydrogen; $this->requiredEnergy = (int) $basicEnergy; } 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 the required resources. * * @return array */ public function calculateRequiredResources() { if (!$this->get("resources_calculated")) { $nextLevel = $this->get("level"); if (!$nextLevel) { $nextLevel = 1; } else { $nextLevel++; } $requiredMetal = (int) $this->get("basic_metal"); $requiredSilicon = (int) $this->get("basic_silicon"); $requiredHydrogen = (int) $this->get("basic_hydrogen"); $requiredEnergy = (int) $this->get("basic_energy"); if ($nextLevel > 1) { if ($requiredMetal) { $requiredMetal = parseFormula($this->get("charge_metal"), $requiredMetal, $nextLevel); } if ($requiredSilicon) { $requiredSilicon = parseFormula($this->get("charge_silicon"), $requiredSilicon, $nextLevel); } if ($requiredHydrogen) { $requiredHydrogen = parseFormula($this->get("charge_hydrogen"), $requiredHydrogen, $nextLevel); } if ($requiredEnergy) { $requiredEnergy = parseFormula($this->get("charge_energy"), $requiredEnergy, $nextLevel); } } $ret = array("required_metal" => (int) $requiredMetal, "required_silicon" => (int) $requiredSilicon, "required_hydrogen" => (int) $requiredHydrogen, "required_energy" => (int) $requiredEnergy, "resources_calculated" => true); $this->set($ret); } else { $ret = array("required_metal" => $this->get("required_metal"), "required_silicon" => $this->get("required_silicon"), "required_hydrogen" => $this->get("required_hydrogen"), "required_energy" => $this->get("required_energy")); } return $ret; }