本文整理汇总了C++中PropStream::GET_USHORT方法的典型用法代码示例。如果您正苦于以下问题:C++ PropStream::GET_USHORT方法的具体用法?C++ PropStream::GET_USHORT怎么用?C++ PropStream::GET_USHORT使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropStream
的用法示例。
在下文中一共展示了PropStream::GET_USHORT方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readAttr
Attr_ReadValue Teleport::readAttr(AttrTypes_t attr, PropStream& propStream)
{
if (ATTR_TELE_DEST == attr) {
if (!propStream.GET_USHORT(destPos.x) || !propStream.GET_USHORT(destPos.y) || !propStream.GET_UCHAR(destPos.z)) {
return ATTR_READ_ERROR;
}
return ATTR_READ_CONTINUE;
} else {
return Item::readAttr(attr, propStream);
}
}
示例2: loadMap
bool IOMapSerialize::loadMap(Map* map)
{
int64_t start = OTSYS_TIME();
Database* db = Database::getInstance();
std::ostringstream query;
DBResult* result = db->storeQuery("SELECT `id` FROM `houses`");
if (!result) {
return true;
}
do {
query.str("");
query << "SELECT `data` FROM `tile_store` WHERE `house_id` = " << result->getDataInt("id");
DBResult* tileResult = db->storeQuery(query.str());
if (!tileResult) {
continue;
}
do {
unsigned long attrSize = 0;
const char* attr = tileResult->getDataStream("data", attrSize);
PropStream propStream;
propStream.init(attr, attrSize);
uint16_t x = 0, y = 0;
uint8_t z = 0;
propStream.GET_USHORT(x);
propStream.GET_USHORT(y);
propStream.GET_UCHAR(z);
if (x == 0 || y == 0) {
continue;
}
Tile* tile = map->getTile(x, y, z);
if (!tile) {
continue;
}
uint32_t item_count = 0;
propStream.GET_ULONG(item_count);
while (item_count--) {
loadItem(propStream, tile);
}
} while (tileResult->next());
db->freeResult(tileResult);
} while (result->next());
db->freeResult(result);
std::cout << "> Loaded house items in: " << (OTSYS_TIME() - start) / (1000.) << " s" << std::endl;
return true;
}
示例3: loadMap
void IOMapSerialize::loadMap(Map* map)
{
int64_t start = OTSYS_TIME();
Database* db = Database::getInstance();
DBResult* result = db->storeQuery("SELECT `data` FROM `tile_store`");
if (!result) {
return;
}
do {
unsigned long attrSize;
const char* attr = result->getDataStream("data", attrSize);
PropStream propStream;
propStream.init(attr, attrSize);
uint16_t x, y;
uint8_t z;
if (!propStream.GET_USHORT(x) || !propStream.GET_USHORT(y) || !propStream.GET_UCHAR(z)) {
continue;
}
Tile* tile = map->getTile(x, y, z);
if (!tile) {
continue;
}
uint32_t item_count;
if (!propStream.GET_ULONG(item_count)) {
continue;
}
while (item_count--) {
loadItem(propStream, tile);
}
} while (result->next());
db->freeResult(result);
std::cout << "> Loaded house items in: " << (OTSYS_TIME() - start) / (1000.) << " s" << std::endl;
}
示例4: readAttr
Attr_ReadValue Depot::readAttr(AttrTypes_t attr, PropStream& propStream)
{
if(attr != ATTR_DEPOT_ID)
return Item::readAttr(attr, propStream);
uint16_t depotId;
if(!propStream.GET_USHORT(depotId))
return ATTR_READ_ERROR;
setAttribute("depotid", depotId);
return ATTR_READ_CONTINUE;
}
示例5: readAttr
Attr_ReadValue Depot::readAttr(AttrTypes_t attr, PropStream& propStream)
{
if(ATTR_DEPOT_ID == attr){
uint16_t _depotId;
if(!propStream.GET_USHORT(_depotId)){
return ATTR_READ_ERROR;
}
setDepotId(_depotId);
return ATTR_READ_CONTINUE;
}
else
return Item::readAttr(attr, propStream);
}
示例6: readAttr
bool Depot::readAttr(AttrTypes_t attr, PropStream& propStream)
{
if(ATTR_DEPOT_ID == attr){
uint16_t _depotId;
if(!propStream.GET_USHORT(_depotId)){
return false;
}
setDepotId(_depotId);
return true;
}
else
return Item::readAttr(attr, propStream);
}
示例7: unserializeAttributeMap
bool ItemAttributes::unserializeAttributeMap(PropStream& stream)
{
uint16_t n;
if(stream.GET_USHORT(n)){
createAttributes();
std::string key;
ItemAttribute attrib;
while(n--){
if(!stream.GET_STRING(key))
return false;
if(!attrib.unserialize(stream))
return false;
(*attributes)[key] = attrib;
}
}
return true;
}
示例8: loadFromOtb
int32_t Items::loadFromOtb(const std::string& file)
{
FileLoader f;
if (!f.openFile(file.c_str(), "OTBI")) {
return f.getError();
}
uint32_t type;
NODE node = f.getChildNode(NO_NODE, type);
PropStream props;
if (f.getProps(node, props)) {
//4 byte flags
//attributes
//0x01 = version data
uint32_t flags;
if (!props.GET_ULONG(flags)) {
return ERROR_INVALID_FORMAT;
}
uint8_t attr;
if (!props.GET_VALUE(attr)) {
return ERROR_INVALID_FORMAT;
}
if (attr == ROOT_ATTR_VERSION) {
uint16_t datalen;
if (!props.GET_VALUE(datalen)) {
return ERROR_INVALID_FORMAT;
}
if (datalen != sizeof(VERSIONINFO)) {
return ERROR_INVALID_FORMAT;
}
VERSIONINFO* vi;
if (!props.GET_STRUCT(vi)) {
return ERROR_INVALID_FORMAT;
}
Items::dwMajorVersion = vi->dwMajorVersion; //items otb format file version
Items::dwMinorVersion = vi->dwMinorVersion; //client version
Items::dwBuildNumber = vi->dwBuildNumber; //revision
}
}
if (Items::dwMajorVersion == 0xFFFFFFFF) {
std::cout << "[Warning - Items::loadFromOtb] items.otb using generic client version." << std::endl;
} else if (Items::dwMajorVersion != 3) {
std::cout << "Old version detected, a newer version of items.otb is required." << std::endl;
return ERROR_INVALID_FORMAT;
} else if (Items::dwMinorVersion < CLIENT_VERSION_1035) {
std::cout << "A newer version of items.otb is required." << std::endl;
return ERROR_INVALID_FORMAT;
}
node = f.getChildNode(node, type);
while (node != NO_NODE) {
PropStream stream;
if (!f.getProps(node, stream)) {
return f.getError();
}
uint32_t flags;
if (!stream.GET_VALUE(flags)) {
return ERROR_INVALID_FORMAT;
}
uint16_t serverId = 0;
uint16_t clientId = 0;
uint16_t speed = 0;
uint16_t lightLevel = 0;
uint16_t lightColor = 0;
uint16_t wareId = 0;
uint8_t alwaysOnTopOrder = 0;
uint8_t attrib;
while (stream.GET_VALUE(attrib)) {
uint16_t datalen;
if (!stream.GET_VALUE(datalen)) {
return ERROR_INVALID_FORMAT;
}
switch (attrib) {
case ITEM_ATTR_SERVERID: {
if (datalen != sizeof(uint16_t)) {
return ERROR_INVALID_FORMAT;
}
if (!stream.GET_USHORT(serverId)) {
return ERROR_INVALID_FORMAT;
}
if (serverId > 30000 && serverId < 30100) {
serverId -= 30000;
}
break;
}
case ITEM_ATTR_CLIENTID: {
//.........这里部分代码省略.........
示例9: 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;
}
//.........这里部分代码省略.........
示例10: loadMapBinary
bool IOMapSerialize::loadMapBinary(Map* map)
{
Database* db = Database::getInstance();
DBResult* result;
DBQuery query;
query << "SELECT `house_id`, `data` FROM `house_data` WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
if(!(result = db->storeQuery(query.str())))
return false;
House* house = NULL;
do
{
int32_t houseId = result->getDataInt("house_id");
house = Houses::getInstance()->getHouse(houseId);
uint64_t attrSize = 0;
const char* attr = result->getDataStream("data", attrSize);
PropStream propStream;
propStream.init(attr, attrSize);
while(propStream.size())
{
uint16_t x = 0, y = 0;
uint8_t z = 0;
propStream.GET_USHORT(x);
propStream.GET_USHORT(y);
propStream.GET_UCHAR(z);
uint32_t itemCount = 0;
propStream.GET_ULONG(itemCount);
Position pos(x, y, (int16_t)z);
if(house && house->hasPendingTransfer())
{
if(Player* player = g_game.getPlayerByGuidEx(house->getOwner()))
{
Depot* depot = player->getDepot(player->getTown(), true);
while(itemCount--)
loadItem(propStream, depot, true);
if(player->isVirtual())
{
IOLoginData::getInstance()->savePlayer(player);
delete player;
}
}
}
else if(Tile* tile = map->getTile(pos))
{
while(itemCount--)
loadItem(propStream, tile, false);
}
else
{
std::cout << "[Error - IOMapSerialize::loadMapBinary] Unserialization of invalid tile"
<< " at position " << pos << std::endl;
break;
}
}
}
while(result->next());
result->free();
return true;
}
示例11: loadItem
bool IOMapSerialize::loadItem(PropStream& propStream, Cylinder* parent)
{
uint16_t id;
if (!propStream.GET_USHORT(id)) {
return false;
}
Tile* tile = nullptr;
if (parent->getParent() == nullptr) {
tile = parent->getTile();
}
const ItemType& iType = Item::items[id];
if (iType.moveable || !tile) {
//create a new item
Item* item = Item::CreateItem(id);
if (item) {
if (item->unserializeAttr(propStream)) {
Container* container = item->getContainer();
if (container && !loadContainer(propStream, container)) {
delete item;
return false;
}
parent->__internalAddThing(item);
item->__startDecaying();
} else {
std::cout << "WARNING: Unserialization error in IOMapSerialize::loadItem()" << id << std::endl;
delete item;
return false;
}
}
} else {
// Stationary items like doors/beds/blackboards/bookcases
Item* item = nullptr;
if (const TileItemVector* items = tile->getItemList()) {
for (Item* findItem : *items) {
if (findItem->getID() == id) {
item = findItem;
break;
} else if (iType.isDoor() && findItem->getDoor()) {
item = findItem;
break;
} else 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: Unserialization error in IOMapSerialize::loadItem()" << id << std::endl;
}
} else {
//The map changed since the last save, just read the attributes
Item* dummy = Item::CreateItem(id);
if (dummy) {
dummy->unserializeAttr(propStream);
Container* container = dummy->getContainer();
if (container && !loadContainer(propStream, container)) {
delete dummy;
return false;
}
delete dummy;
}
}
}
return true;
}
示例12: readAttr
Attr_ReadValue Item::readAttr(AttrTypes_t attr, PropStream& propStream)
{
switch (attr) {
case ATTR_COUNT: {
uint8_t _count = 0;
if (!propStream.GET_UCHAR(_count)) {
return ATTR_READ_ERROR;
}
setSubType(_count);
break;
}
case ATTR_ACTION_ID: {
uint16_t _actionid = 0;
if (!propStream.GET_USHORT(_actionid)) {
return ATTR_READ_ERROR;
}
setActionId(_actionid);
break;
}
case ATTR_UNIQUE_ID: {
uint16_t _uniqueid;
if (!propStream.GET_USHORT(_uniqueid)) {
return ATTR_READ_ERROR;
}
setUniqueId(_uniqueid);
break;
}
case ATTR_TEXT: {
std::string _text;
if (!propStream.GET_STRING(_text)) {
return ATTR_READ_ERROR;
}
setText(_text);
break;
}
case ATTR_WRITTENDATE: {
uint32_t _writtenDate;
if (!propStream.GET_ULONG(_writtenDate)) {
return ATTR_READ_ERROR;
}
setDate(_writtenDate);
break;
}
case ATTR_WRITTENBY: {
std::string _writer;
if (!propStream.GET_STRING(_writer)) {
return ATTR_READ_ERROR;
}
setWriter(_writer);
break;
}
case ATTR_DESC: {
std::string _text;
if (!propStream.GET_STRING(_text)) {
return ATTR_READ_ERROR;
}
setSpecialDescription(_text);
break;
}
case ATTR_RUNE_CHARGES: {
uint8_t _charges = 1;
if (!propStream.GET_UCHAR(_charges)) {
return ATTR_READ_ERROR;
}
setSubType(_charges);
break;
}
case ATTR_CHARGES: {
uint16_t _charges = 1;
if (!propStream.GET_USHORT(_charges)) {
return ATTR_READ_ERROR;
}
setSubType(_charges);
break;
//.........这里部分代码省略.........
示例13: loadFromOtb
//.........这里部分代码省略.........
iType->alwaysOnTop = ((flags & FLAG_ALWAYSONTOP) == FLAG_ALWAYSONTOP);
iType->canDecay = !((flags & FLAG_CANNOTDECAY) == FLAG_CANNOTDECAY);
iType->isVertical = ((flags & FLAG_VERTICAL) == FLAG_VERTICAL);
iType->isHorizontal = ((flags & FLAG_HORIZONTAL) == FLAG_HORIZONTAL);
iType->isHangable = ((flags & FLAG_HANGABLE) == FLAG_HANGABLE);
iType->allowDistRead = ((flags & FLAG_ALLOWDISTREAD) == FLAG_ALLOWDISTREAD);
if(type == ITEM_GROUP_WRITEABLE) {
iType->RWInfo |= CAN_BE_WRITTEN;
}
if((flags & FLAG_READABLE) == FLAG_READABLE)
iType->RWInfo |= CAN_BE_READ;
iType->rotable = ((flags & FLAG_ROTABLE) == FLAG_ROTABLE);
attribute_t attrib;
datasize_t datalen = 0;
while(props.GET_VALUE(attrib)){
//size of data
if(!props.GET_VALUE(datalen)){
delete iType;
return ERROR_INVALID_FORMAT;
}
switch(attrib){
case ITEM_ATTR_SERVERID:
{
if(datalen != sizeof(unsigned short))
return ERROR_INVALID_FORMAT;
unsigned short serverid;
if(!props.GET_USHORT(serverid))
return ERROR_INVALID_FORMAT;
if(serverid > 20000 && serverid < 20100)
serverid = serverid - 20000;
iType->id = serverid;
break;
}
case ITEM_ATTR_CLIENTID:
{
if(datalen != sizeof(unsigned short))
return ERROR_INVALID_FORMAT;
if(!props.GET_USHORT(iType->clientId))
return ERROR_INVALID_FORMAT;
break;
}
case ITEM_ATTR_NAME:
{
char name[128];
if(datalen >= sizeof(name))
return ERROR_INVALID_FORMAT;
if(!props.GET_NSTRING(datalen, iType->name))
return ERROR_INVALID_FORMAT;
break;
}
case ITEM_ATTR_DESCR:
{
char descr[128];
示例14: readAttr
bool Item::readAttr(AttrTypes_t attr, PropStream& propStream)
{
switch(attr){
case ATTR_COUNT:
{
unsigned char _count = 0;
if(!propStream.GET_UCHAR(_count)){
return false;
}
setItemCountOrSubtype(_count);
break;
}
case ATTR_ACTION_ID:
{
unsigned short _actionid = 0;
if(!propStream.GET_USHORT(_actionid)){
return false;
}
setActionId(_actionid);
break;
}
case ATTR_UNIQUE_ID:
{
unsigned short _uniqueid;
if(!propStream.GET_USHORT(_uniqueid)){
return false;
}
setUniqueId(_uniqueid);
break;
}
case ATTR_TEXT:
{
std::string _text;
if(!propStream.GET_STRING(_text)){
return false;
}
setText(_text);
break;
}
case ATTR_DESC:
{
std::string _text;
if(!propStream.GET_STRING(_text)){
return false;
}
setSpecialDescription(_text);
break;
}
case ATTR_RUNE_CHARGES:
{
unsigned char _charges = 1;
if(!propStream.GET_UCHAR(_charges)){
return false;
}
setItemCountOrSubtype(_charges);
break;
}
//these should be handled through derived classes
//If these are called then something has changed in the items.otb since the map was saved
//just read the values
//Depot class
case ATTR_DEPOT_ID:
{
unsigned short _depotId;
if(!propStream.GET_USHORT(_depotId)){
return false;
}
return true;
}
//Door class
case ATTR_HOUSEDOORID:
{
unsigned char _doorId;
if(!propStream.GET_UCHAR(_doorId)){
return false;
}
return true;
}
//Teleport class
case ATTR_TELE_DEST:
{
TeleportDest* tele_dest;
if(!propStream.GET_STRUCT(tele_dest)){
//.........这里部分代码省略.........