当前位置: 首页>>代码示例>>C++>>正文


C++ Tile::__getThing方法代码示例

本文整理汇总了C++中Tile::__getThing方法的典型用法代码示例。如果您正苦于以下问题:C++ Tile::__getThing方法的具体用法?C++ Tile::__getThing怎么用?C++ Tile::__getThing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tile的用法示例。


在下文中一共展示了Tile::__getThing方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loadItem

bool IOMapSerialize::loadItem(PropStream& propStream, Cylinder* parent, bool depotTransfer/* = false*/)
{
	Tile* tile = NULL;
	if(!parent->getItem())
		tile = parent->getTile();

	uint16_t id = 0;
	propStream.GET_USHORT(id);
	Item* item = NULL;

	const ItemType& iType = Item::items[id];
	if(iType.moveable || iType.forceSerialize || (!depotTransfer && !tile))
	{
		if(!(item = Item::CreateItem(id)))
			return true;

		if(!item->unserializeAttr(propStream))
		{
			std::cout << "[Warning - IOMapSerialize::loadItem] Unserialization error [0] for item type " << id << std::endl;
			delete item;
			return false;
		}

		if(Container* container = item->getContainer())
		{
			if(!loadContainer(propStream, container))
			{
				delete item;
				return false;
			}
		}

		if(parent)
		{
			parent->__internalAddThing(item);
			item->__startDecaying();
		}
		else
			delete item;

		return true;
	}

	if(tile)
	{
		//Stationary items
		Item* findItem = NULL;
		for(uint32_t i = 0; i < tile->getThingCount(); ++i)
		{
			if(!(findItem = tile->__getThing(i)->getItem()))
				continue;

			if(findItem->getID() == id)
			{
				item = findItem;
				break;
			}

			if(iType.isDoor() && findItem->getDoor())
			{
				item = findItem;
				break;
			}

			if(iType.isBed() && findItem->getBed())
			{
				item = findItem;
				break;
			}
		}
	}

	if(item)
	{
		if(item->unserializeAttr(propStream))
		{
			Container* container = item->getContainer();
			if(container && !loadContainer(propStream, container))
				return false;

			item = g_game.transformItem(item, id);
		}
		else
			std::cout << "[Warning - IOMapSerialize::loadItem] Unserialization error [1] for item type " << id << std::endl;

		return true;
	}

	//The map changed since the last save, just read the attributes
	if(!(item = Item::CreateItem(id)))
		return true;

	item->unserializeAttr(propStream);
	if(Container* container = item->getContainer())
	{
		if(!loadContainer(propStream, container))
		{
			delete item;
			return false;
		}
//.........这里部分代码省略.........
开发者ID:PrzemolKing,项目名称:wedoserver,代码行数:101,代码来源:iomapserialize.cpp

示例2: loadItems

bool IOMapSerialize::loadItems(Database* db, DBResult* result, Cylinder* parent, bool depotTransfer/* = false*/)
{
	ItemMap itemMap;
	Tile* tile = NULL;
	if(!parent->getItem())
		tile = parent->getTile();


	Item* item = NULL;
	int32_t sid, pid, id, count;
	do
	{
		sid = result->getDataInt("sid");
		pid = result->getDataInt("pid");
		id = result->getDataInt("itemtype");
		count = result->getDataInt("count");

		item = NULL;
		uint64_t attrSize = 0;
		const char* attr = result->getDataStream("attributes", attrSize);

		PropStream propStream;
		propStream.init(attr, attrSize);

		const ItemType& iType = Item::items[id];
		if(iType.moveable || iType.forceSerialize || pid)
		{
			if(!(item = Item::CreateItem(id, count)))
				continue;

			if(item->unserializeAttr(propStream))
			{
				if(!pid)
				{
					parent->__internalAddThing(item);
					item->__startDecaying();
				}
			}
			else
				std::cout << "[Warning - IOMapSerialize::loadItems] Unserialization error [0] for item type " << id << std::endl;
		}
		else if(tile)
		{
			//find this type in the tile
			Item* findItem = NULL;
			for(uint32_t i = 0; i < tile->getThingCount(); ++i)
			{
				if(!(findItem = tile->__getThing(i)->getItem()))
					continue;

				if(findItem->getID() == id)
				{
					item = findItem;
					break;
				}

				if(iType.isDoor() && findItem->getDoor())
				{
					item = findItem;
					break;
				}

				if(iType.isBed() && findItem->getBed())
				{
					item = findItem;
					break;
				}
			}
		}

		if(item)
		{
			if(item->unserializeAttr(propStream))
			{
				if((item = g_game.transformItem(item, id)))
					itemMap[sid] = std::make_pair(item, pid);
			}
			else
				std::cout << "[Warning - IOMapSerialize::loadItems] Unserialization error [1] for item type " << id << std::endl;
		}
		else if((item = Item::CreateItem(id)))
		{
			item->unserializeAttr(propStream);
			if(!depotTransfer)
				std::cout << "[Warning - IOMapSerialize::loadItems] NULL item at "
				<< tile->getPosition() << " (type = " << id << ", sid = "
				<< sid << ", pid = " << pid << ")" << std::endl;
			else
				itemMap[sid] = std::make_pair(parent->getItem(), pid);

			delete item;
			item = NULL;
		}
	}
	while(result->next());

	ItemMap::iterator it;
	for(ItemMap::reverse_iterator rit = itemMap.rbegin(); rit != itemMap.rend(); ++rit)
	{
		if(!(item = rit->second.first))
//.........这里部分代码省略.........
开发者ID:PrzemolKing,项目名称:wedoserver,代码行数:101,代码来源:iomapserialize.cpp


注:本文中的Tile::__getThing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。