/** * @version 0.1.3 * @since 0.1.0 * @param int $id House ID. * @return OTS_House House information wrapper. * @throws E_OTS_NotLoaded If houses list is not loaded. * @deprecated 0.1.3 Use POT::getHousesList()->getHouse(). */ public function getHouse($id) { if (isset($this->houses)) { return $this->houses->getHouse($id); } throw new E_OTS_NotLoaded(); }
/** * Parses loaded file. * * @version 0.1.0 * @since 0.0.6 * @throws E_OTS_FileLoaderError When error occurs during file operation. * @throws E_OTS_OutOfBuffer When there is read attemp after end of stream. */ private function parse() { // root node header $version = $this->root->getLong(); $this->width = $this->root->getShort(); $this->height = $this->root->getShort(); $majorVersionItems = $this->root->getLong(); $minorVersionItems = $this->root->getLong(); // checks version of root node if ($version > 2 || $version <= 0) { throw new E_OTS_OTBMError(E_OTS_OTBMError::LOADMAPERROR_OUTDATEDHEADER); } // reads root's first child $node = $this->root->getChild(); // it should be OTBM_NODE_MAP_DATA if ($node->getType() != self::OTBM_NODE_MAP_DATA) { throw new E_OTS_OTBMError(E_OTS_OTBMError::LOADMAPERROR_UNKNOWNNODETYPE); } // reads map attributes while ($node->isValid()) { switch ($node->getChar()) { // description text case self::OTBM_ATTR_DESCRIPTION: $this->description .= $node->getString() . "\n"; break; // external houses file // external houses file case self::OTBM_ATTR_EXT_HOUSE_FILE: $this->housesList = new OTS_HousesList($this->directory . '/' . $node->getString()); break; // external spawns file // external spawns file case self::OTBM_ATTR_EXT_SPAWN_FILE: // just we need to skip known attributes $node->getString(); break; // unsupported attribute // unsupported attribute default: throw new E_OTS_OTBMError(E_OTS_OTBMError::LOADMAPERROR_UNKNOWNNODETYPE); } } $node = $node->getChild(); // reads map nodes while ($node) { switch ($node->getType()) { // map definition part case self::OTBM_NODE_TILE_AREA: // reads base X, Y and Z coords $baseX = $node->getShort(); $baseY = $node->getShort(); $z = $node->getChar(); $tileNode = $node->getChild(); while ($tileNode) { //Sleavely: save tiles to $this->tiles array if ($tileNode->getType() == self::OTBM_NODE_TILE) { $tile = array(); // reads tile coords $offsetX = $tileNode->getChar(); $offsetY = $tileNode->getChar(); $coords = new OTS_MapCoords($baseX + $offsetX, $baseY + $offsetY, $z); if ($tileNode->isValid()) { switch ($tileNode->getChar()) { case self::OTBM_ATTR_ITEM: $itemID = $tileNode->getShort(); $tile['itemid'] = $itemID; break; } } $item = $tileNode->getChild(); //if there are children while ($item) { if ($item->getType() == self::OTBM_NODE_ITEM) { if (!isset($tile['items'])) { $tile['items'] = array(); } $tile['items'][] = $this->parseItem($item); } $item = $item->getNext(); } $this->addTile($tile, $coords->x, $coords->y, $coords->z); } // reads houses tiles // we dont need other tiles at the moment in POT, feel free to add it's suport on yourself if ($tileNode->getType() == self::OTBM_NODE_HOUSETILE) { // reads tile coords $offsetX = $tile->getChar(); $offsetY = $tile->getChar(); $coords = new OTS_MapCoords($baseX + $offsetX, $baseY + $offsetY, $z); // reads house by it's ID $house = $this->housesList->getHouse($tileNode->getLong()); $house->addTile($coords); } $tileNode = $tileNode->getNext(); } break; // list of towns on map // list of towns on map case self::OTBM_NODE_TOWNS: $town = $node->getChild(); // reads all towns while ($town) { // checks if it's town node if ($town->getType() != self::OTBM_NODE_TOWN) { throw new E_OTS_OTBMError(E_OTS_OTBMError::LOADMAPERROR_UNKNOWNNODETYPE); } // reads basic town info $id = $town->getLong(); $this->towns[$id] = $town->getString(); // temple coords $x = $town->getShort(); $y = $town->getShort(); $z = $town->getChar(); $this->temples[$id] = new OTS_MapCoords($x, $y, $z); $town = $town->getNext(); } break; // waypoints list // waypoints list case self::OTBM_NODE_WAYPOINTS: $waypoint = $node->getChild(); $list = array(); // reads all waypoints while ($waypoint) { // checks if it's waypoint if ($town->getType() != self::OTBM_NODE_WAYPOINT) { throw new E_OTS_OTBMError(E_OTS_OTBMError::LOADMAPERROR_UNKNOWNNODETYPE); } // reads waypoint name $name = $town->getString(); // point coords $x = $town->getShort(); $y = $town->getShort(); $z = $town->getChar(); $list[] = new OTS_Waypoint($name, $x, $y, $z); $waypoint = $waypoint->getNext(); } // adds track to waypoints list $this->waypoints[] = $list; break; // unknown type // unknown type default: throw new E_OTS_OTBMError(E_OTS_OTBMError::LOADMAPERROR_UNKNOWNNODETYPE); } $node = $node->getNext(); } }