/** * Creates a new Territory * * @return iTerritory */ public static function create($name, $type = TERR_LAND, $isSupply = false) { $t = new TerritoryTemplate(); $t->setName($name); $t->setType($type); $t->setIsSupply($isSupply); return $t; }
/** * Responsible for the initial loading of a territory into the game (not * the match) **/ public function loadTerritories(array $objs) { //print_r($objs); $ts = array(); foreach ($objs as $obj) { $t = TerritoryTemplate::create($obj->name, $obj->type, $obj->has_supply ? true : false); //global $config; $config->system->db->useDebug(true); $empire = EmpireQuery::create()->filterByGame($this)->filterByAbbr($obj->empire_start)->findOne(); if ($empire instanceof Empire) { $t->setInitialOccupation($empire, new Unit($obj->starting_forces)); } //$config->system->db->useDebug(false); $this->addGameTerritory($t); $t->save(); $ts[$obj->id] = $t; // Use the 'given' ID, rather than the new DB ID } unset($obj); // Safety // Second pass, set up neighbours foreach ($objs as $obj) { $t = $ts[$obj->id]; foreach ($obj->neighbours as $nid) { $n = $ts[$nid]; // again, using the spreadsheet IDs (nid) here // This doubles the size of the map, but makes it easier to query. // Re-evaluate this later. Maybe I could modify getNeighbours() to // query territory_a or territory_b. $t->addNeighbour($n); $n->addNeighbour($t); // Now that neighbours are in, lets work on converting some of these // 'land's to 'coast's if ($t->getType() === 'land' && $n->getType() === 'water') { $t->setType('coast'); } $n->save(); } unset($n); unset($nid); // safety $t->save(); } unset($obj); unset($t); // safety $this->save(); }