mirror of
https://github.com/edubart/otclient.git
synced 2025-05-02 02:29:22 +02:00
Remove if spaces
This commit is contained in:
parent
70115e391d
commit
36e5a5a92f
@ -60,7 +60,7 @@ void BinaryTree::seek(uint pos)
|
|||||||
|
|
||||||
uint8 BinaryTree::getU8()
|
uint8 BinaryTree::getU8()
|
||||||
{
|
{
|
||||||
if (m_pos+1 > m_buffer.size())
|
if(m_pos+1 > m_buffer.size())
|
||||||
stdext::throw_exception("BinaryTree: getU8 failed");
|
stdext::throw_exception("BinaryTree: getU8 failed");
|
||||||
uint8 v = m_buffer[m_pos];
|
uint8 v = m_buffer[m_pos];
|
||||||
m_pos += 1;
|
m_pos += 1;
|
||||||
@ -69,7 +69,7 @@ uint8 BinaryTree::getU8()
|
|||||||
|
|
||||||
uint16 BinaryTree::getU16()
|
uint16 BinaryTree::getU16()
|
||||||
{
|
{
|
||||||
if (m_pos+2 > m_buffer.size())
|
if(m_pos+2 > m_buffer.size())
|
||||||
stdext::throw_exception("BinaryTree: getU16 failed");
|
stdext::throw_exception("BinaryTree: getU16 failed");
|
||||||
uint16 v = stdext::readLE16(&m_buffer[m_pos]);
|
uint16 v = stdext::readLE16(&m_buffer[m_pos]);
|
||||||
m_pos += 2;
|
m_pos += 2;
|
||||||
@ -78,7 +78,7 @@ uint16 BinaryTree::getU16()
|
|||||||
|
|
||||||
uint32 BinaryTree::getU32()
|
uint32 BinaryTree::getU32()
|
||||||
{
|
{
|
||||||
if (m_pos+4 > m_buffer.size())
|
if(m_pos+4 > m_buffer.size())
|
||||||
stdext::throw_exception("BinaryTree: getU32 failed");
|
stdext::throw_exception("BinaryTree: getU32 failed");
|
||||||
uint32 v = stdext::readLE32(&m_buffer[m_pos]);
|
uint32 v = stdext::readLE32(&m_buffer[m_pos]);
|
||||||
m_pos += 4;
|
m_pos += 4;
|
||||||
@ -87,7 +87,7 @@ uint32 BinaryTree::getU32()
|
|||||||
|
|
||||||
uint64 BinaryTree::getU64()
|
uint64 BinaryTree::getU64()
|
||||||
{
|
{
|
||||||
if (m_pos+8 > m_buffer.size())
|
if(m_pos+8 > m_buffer.size())
|
||||||
stdext::throw_exception("BinaryTree: getU64 failed");
|
stdext::throw_exception("BinaryTree: getU64 failed");
|
||||||
uint64 v = stdext::readLE64(&m_buffer[m_pos]);
|
uint64 v = stdext::readLE64(&m_buffer[m_pos]);
|
||||||
m_pos += 8;
|
m_pos += 8;
|
||||||
@ -97,10 +97,10 @@ uint64 BinaryTree::getU64()
|
|||||||
std::string BinaryTree::getString()
|
std::string BinaryTree::getString()
|
||||||
{
|
{
|
||||||
uint16 len = getU16();
|
uint16 len = getU16();
|
||||||
if (len == 0 || len > 8192)
|
if(len == 0 || len > 8192)
|
||||||
stdext::throw_exception("BinaryTree: getString failed: invalid or too large string length");
|
stdext::throw_exception("BinaryTree: getString failed: invalid or too large string length");
|
||||||
|
|
||||||
if (m_pos+len > m_buffer.size())
|
if(m_pos+len > m_buffer.size())
|
||||||
stdext::throw_exception("BinaryTree: getString failed: string length exceeded buffer size.");
|
stdext::throw_exception("BinaryTree: getString failed: string length exceeded buffer size.");
|
||||||
|
|
||||||
std::string ret((char *)&m_buffer[m_pos], len);
|
std::string ret((char *)&m_buffer[m_pos], len);
|
||||||
|
@ -191,7 +191,7 @@ public:
|
|||||||
else
|
else
|
||||||
r2 = r.x2;
|
r2 = r.x2;
|
||||||
|
|
||||||
if (l1 > r2 || l2 > r1)
|
if(l1 > r2 || l2 > r1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int t1 = y1;
|
int t1 = y1;
|
||||||
@ -203,7 +203,7 @@ public:
|
|||||||
|
|
||||||
int t2 = r.y1;
|
int t2 = r.y1;
|
||||||
int b2 = r.y1;
|
int b2 = r.y1;
|
||||||
if (r.y2 - r.y1 + 1 < 0)
|
if(r.y2 - r.y1 + 1 < 0)
|
||||||
t2 = r.y2;
|
t2 = r.y2;
|
||||||
else
|
else
|
||||||
b2 = r.y2;
|
b2 = r.y2;
|
||||||
|
@ -27,20 +27,20 @@ Houses g_houses;
|
|||||||
House::House(uint32 hId, const std::string &name, const Position &pos)
|
House::House(uint32 hId, const std::string &name, const Position &pos)
|
||||||
: m_id(hId), m_name(name)
|
: m_id(hId), m_name(name)
|
||||||
{
|
{
|
||||||
if (pos.isValid())
|
if(pos.isValid())
|
||||||
m_doors.insert(std::make_pair(0, pos)); // first door
|
m_doors.insert(std::make_pair(0, pos)); // first door
|
||||||
}
|
}
|
||||||
|
|
||||||
void House::addDoor(uint16 doorId, const Position& pos)
|
void House::addDoor(uint16 doorId, const Position& pos)
|
||||||
{
|
{
|
||||||
if (m_doors.find(doorId) == m_doors.end())
|
if(m_doors.find(doorId) == m_doors.end())
|
||||||
m_doors.insert(std::make_pair(doorId, pos));
|
m_doors.insert(std::make_pair(doorId, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
void House::setTile(const TilePtr& tile)
|
void House::setTile(const TilePtr& tile)
|
||||||
{
|
{
|
||||||
tile->setFlags(TILESTATE_HOUSE);
|
tile->setFlags(TILESTATE_HOUSE);
|
||||||
if (std::find(m_tiles.begin(), m_tiles.end(), tile) == m_tiles.end())
|
if(std::find(m_tiles.begin(), m_tiles.end(), tile) == m_tiles.end())
|
||||||
m_tiles.push_back(tile);
|
m_tiles.push_back(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,18 +49,18 @@ void House::setTile(const TilePtr& tile)
|
|||||||
void House::load(const TiXmlElement *elem)
|
void House::load(const TiXmlElement *elem)
|
||||||
{
|
{
|
||||||
std::string name = elem->Attribute("name");
|
std::string name = elem->Attribute("name");
|
||||||
if (name.empty())
|
if(name.empty())
|
||||||
name = stdext::format("UnNamed house #%u", getId());
|
name = stdext::format("UnNamed house #%u", getId());
|
||||||
|
|
||||||
uint32 rent = fugly_get("rent", uint32);
|
uint32 rent = fugly_get("rent", uint32);
|
||||||
m_rent = rent;
|
m_rent = rent;
|
||||||
|
|
||||||
uint32 townId = fugly_get("townid", uint32);
|
uint32 townId = fugly_get("townid", uint32);
|
||||||
if (!g_map.getTown(townId))
|
if(!g_map.getTown(townId))
|
||||||
stdext::throw_exception(stdext::format("invalid town id for house %d", townId));
|
stdext::throw_exception(stdext::format("invalid town id for house %d", townId));
|
||||||
|
|
||||||
uint32 size = fugly_get("size", uint32);
|
uint32 size = fugly_get("size", uint32);
|
||||||
if (size == 0)
|
if(size == 0)
|
||||||
size = 1;
|
size = 1;
|
||||||
|
|
||||||
m_size = size;
|
m_size = size;
|
||||||
@ -71,21 +71,21 @@ void House::load(const TiXmlElement *elem)
|
|||||||
|
|
||||||
void Houses::addHouse(const HousePtr& house)
|
void Houses::addHouse(const HousePtr& house)
|
||||||
{
|
{
|
||||||
if (findHouse(house->getId()) == m_houses.end())
|
if(findHouse(house->getId()) == m_houses.end())
|
||||||
m_houses.push_back(house);
|
m_houses.push_back(house);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Houses::removeHouse(uint32 houseId)
|
void Houses::removeHouse(uint32 houseId)
|
||||||
{
|
{
|
||||||
auto it = findHouse(houseId);
|
auto it = findHouse(houseId);
|
||||||
if (it != m_houses.end())
|
if(it != m_houses.end())
|
||||||
m_houses.erase(it);
|
m_houses.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
HousePtr Houses::getHouse(uint32 houseId)
|
HousePtr Houses::getHouse(uint32 houseId)
|
||||||
{
|
{
|
||||||
auto it = findHouse(houseId);
|
auto it = findHouse(houseId);
|
||||||
if (it != m_houses.end())
|
if(it != m_houses.end())
|
||||||
return *it;
|
return *it;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -94,20 +94,20 @@ HousePtr Houses::getHouse(uint32 houseId)
|
|||||||
void Houses::load(const std::string& fileName)
|
void Houses::load(const std::string& fileName)
|
||||||
{
|
{
|
||||||
TiXmlDocument doc(fileName.c_str());
|
TiXmlDocument doc(fileName.c_str());
|
||||||
if (!doc.LoadFile())
|
if(!doc.LoadFile())
|
||||||
stdext::throw_exception(stdext::format("failed to load '%s' (House XML)", fileName));
|
stdext::throw_exception(stdext::format("failed to load '%s' (House XML)", fileName));
|
||||||
|
|
||||||
TiXmlElement *root = doc.FirstChildElement();
|
TiXmlElement *root = doc.FirstChildElement();
|
||||||
if (!root || root->ValueTStr() != "houses")
|
if(!root || root->ValueTStr() != "houses")
|
||||||
stdext::throw_exception("invalid root tag name");
|
stdext::throw_exception("invalid root tag name");
|
||||||
|
|
||||||
for (TiXmlElement *elem = root->FirstChildElement(); elem; elem = elem->NextSiblingElement()) {
|
for (TiXmlElement *elem = root->FirstChildElement(); elem; elem = elem->NextSiblingElement()) {
|
||||||
if (elem->ValueTStr() != "house")
|
if(elem->ValueTStr() != "house")
|
||||||
stdext::throw_exception("invalid house tag.");
|
stdext::throw_exception("invalid house tag.");
|
||||||
|
|
||||||
uint32 houseId = fugly_get("houseid", uint32);
|
uint32 houseId = fugly_get("houseid", uint32);
|
||||||
HousePtr house = getHouse(houseId);
|
HousePtr house = getHouse(houseId);
|
||||||
if (!house)
|
if(!house)
|
||||||
house = HousePtr(new House(houseId)), addHouse(house);
|
house = HousePtr(new House(houseId)), addHouse(house);
|
||||||
|
|
||||||
house->load(elem);
|
house->load(elem);
|
||||||
|
@ -211,7 +211,7 @@ void Item::unserializeItem(const BinaryTreePtr &in)
|
|||||||
{
|
{
|
||||||
while (in->canRead()) {
|
while (in->canRead()) {
|
||||||
uint8 attrType = in->getU8();
|
uint8 attrType = in->getU8();
|
||||||
if (attrType == 0)
|
if(attrType == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// fugly switch yes?
|
// fugly switch yes?
|
||||||
@ -286,7 +286,7 @@ void Item::unserializeItem(const BinaryTreePtr &in)
|
|||||||
|
|
||||||
bool Item::isMoveable()
|
bool Item::isMoveable()
|
||||||
{
|
{
|
||||||
if (m_datType)
|
if(m_datType)
|
||||||
return !m_datType->isNotMoveable();
|
return !m_datType->isNotMoveable();
|
||||||
|
|
||||||
g_logger.warning(stdext::format(
|
g_logger.warning(stdext::format(
|
||||||
|
@ -63,22 +63,22 @@ void Map::notificateTileUpdateToMapViews(const Position& pos)
|
|||||||
void Map::loadOtbm(const std::string& fileName)
|
void Map::loadOtbm(const std::string& fileName)
|
||||||
{
|
{
|
||||||
FileStreamPtr fin = g_resources.openFile(fileName);
|
FileStreamPtr fin = g_resources.openFile(fileName);
|
||||||
if (!fin)
|
if(!fin)
|
||||||
stdext::throw_exception(stdext::format("Unable to load map '%s'", fileName));
|
stdext::throw_exception(stdext::format("Unable to load map '%s'", fileName));
|
||||||
|
|
||||||
fin->cache();
|
fin->cache();
|
||||||
if (!g_things.isOtbLoaded())
|
if(!g_things.isOtbLoaded())
|
||||||
stdext::throw_exception("OTB isn't loaded yet to load a map.");
|
stdext::throw_exception("OTB isn't loaded yet to load a map.");
|
||||||
|
|
||||||
if (fin->getU32())
|
if(fin->getU32())
|
||||||
stdext::throw_exception("Unknown file version detected");
|
stdext::throw_exception("Unknown file version detected");
|
||||||
|
|
||||||
BinaryTreePtr root = fin->getBinaryTree();
|
BinaryTreePtr root = fin->getBinaryTree();
|
||||||
if (root->getU8())
|
if(root->getU8())
|
||||||
stdext::throw_exception("could not read root property!");
|
stdext::throw_exception("could not read root property!");
|
||||||
|
|
||||||
uint32 headerVersion = root->getU32();
|
uint32 headerVersion = root->getU32();
|
||||||
if (!headerVersion || headerVersion > 3)
|
if(!headerVersion || headerVersion > 3)
|
||||||
stdext::throw_exception(stdext::format("Unknown OTBM version detected: %u.", headerVersion));
|
stdext::throw_exception(stdext::format("Unknown OTBM version detected: %u.", headerVersion));
|
||||||
|
|
||||||
m_width = root->getU16();
|
m_width = root->getU16();
|
||||||
@ -86,25 +86,25 @@ void Map::loadOtbm(const std::string& fileName)
|
|||||||
dump << "Map size: " << m_width << "x" << m_height;
|
dump << "Map size: " << m_width << "x" << m_height;
|
||||||
|
|
||||||
uint32 headerMajorItems = root->getU8();
|
uint32 headerMajorItems = root->getU8();
|
||||||
if (headerMajorItems < 3) {
|
if(headerMajorItems < 3) {
|
||||||
stdext::throw_exception(stdext::format("This map needs to be upgraded. read %d what it's supposed to be: %u",
|
stdext::throw_exception(stdext::format("This map needs to be upgraded. read %d what it's supposed to be: %u",
|
||||||
headerMajorItems, g_things.getOtbMajorVersion()));
|
headerMajorItems, g_things.getOtbMajorVersion()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headerMajorItems > g_things.getOtbMajorVersion()) {
|
if(headerMajorItems > g_things.getOtbMajorVersion()) {
|
||||||
stdext::throw_exception(stdext::format("This map was saved with different OTB version. read %d what it's supposed to be: %d",
|
stdext::throw_exception(stdext::format("This map was saved with different OTB version. read %d what it's supposed to be: %d",
|
||||||
headerMajorItems, g_things.getOtbMajorVersion()));
|
headerMajorItems, g_things.getOtbMajorVersion()));
|
||||||
}
|
}
|
||||||
|
|
||||||
root->skip(3);
|
root->skip(3);
|
||||||
uint32 headerMinorItems = root->getU32();
|
uint32 headerMinorItems = root->getU32();
|
||||||
if (headerMinorItems > g_things.getOtbMinorVersion()) {
|
if(headerMinorItems > g_things.getOtbMinorVersion()) {
|
||||||
g_logger.warning(stdext::format("This map needs an updated OTB. read %d what it's supposed to be: %d",
|
g_logger.warning(stdext::format("This map needs an updated OTB. read %d what it's supposed to be: %d",
|
||||||
headerMinorItems, g_things.getOtbMinorVersion()));
|
headerMinorItems, g_things.getOtbMinorVersion()));
|
||||||
}
|
}
|
||||||
|
|
||||||
BinaryTreePtr node = root->getChildren()[0];
|
BinaryTreePtr node = root->getChildren()[0];
|
||||||
if (node->getU8() != OTBM_MAP_DATA)
|
if(node->getU8() != OTBM_MAP_DATA)
|
||||||
stdext::throw_exception("Could not read root data node");
|
stdext::throw_exception("Could not read root data node");
|
||||||
|
|
||||||
while (node->canRead()) {
|
while (node->canRead()) {
|
||||||
@ -127,13 +127,13 @@ void Map::loadOtbm(const std::string& fileName)
|
|||||||
|
|
||||||
for (const BinaryTreePtr &nodeMapData : node->getChildren()) {
|
for (const BinaryTreePtr &nodeMapData : node->getChildren()) {
|
||||||
uint8 mapDataType = nodeMapData->getU8();
|
uint8 mapDataType = nodeMapData->getU8();
|
||||||
if (mapDataType == OTBM_TILE_AREA) {
|
if(mapDataType == OTBM_TILE_AREA) {
|
||||||
uint16 baseX = nodeMapData->getU16(), baseY = nodeMapData->getU16();
|
uint16 baseX = nodeMapData->getU16(), baseY = nodeMapData->getU16();
|
||||||
uint8 pz = nodeMapData->getU8();
|
uint8 pz = nodeMapData->getU8();
|
||||||
|
|
||||||
for (const BinaryTreePtr &nodeTile : nodeMapData->getChildren()) {
|
for (const BinaryTreePtr &nodeTile : nodeMapData->getChildren()) {
|
||||||
uint8 type = nodeTile->getU8();
|
uint8 type = nodeTile->getU8();
|
||||||
if (type != OTBM_TILE && type != OTBM_HOUSETILE)
|
if(type != OTBM_TILE && type != OTBM_HOUSETILE)
|
||||||
stdext::throw_exception(stdext::format("invalid node tile type %d", (int)type));
|
stdext::throw_exception(stdext::format("invalid node tile type %d", (int)type));
|
||||||
|
|
||||||
TilePtr tile = nullptr;
|
TilePtr tile = nullptr;
|
||||||
@ -144,10 +144,10 @@ void Map::loadOtbm(const std::string& fileName)
|
|||||||
uint16 px = baseX + nodeTile->getU8(), py = baseY + nodeTile->getU8();
|
uint16 px = baseX + nodeTile->getU8(), py = baseY + nodeTile->getU8();
|
||||||
Position pos(px, py, pz);
|
Position pos(px, py, pz);
|
||||||
|
|
||||||
if (type == OTBM_HOUSETILE) {
|
if(type == OTBM_HOUSETILE) {
|
||||||
uint32 hId = nodeTile->getU32();
|
uint32 hId = nodeTile->getU32();
|
||||||
tile = createTile(pos);
|
tile = createTile(pos);
|
||||||
if (!(house = m_houses.getHouse(hId))) {
|
if(!(house = m_houses.getHouse(hId))) {
|
||||||
house = HousePtr(new House(hId));
|
house = HousePtr(new House(hId));
|
||||||
m_houses.addHouse(house);
|
m_houses.addHouse(house);
|
||||||
}
|
}
|
||||||
@ -159,26 +159,26 @@ void Map::loadOtbm(const std::string& fileName)
|
|||||||
switch (tileAttr) {
|
switch (tileAttr) {
|
||||||
case OTBM_ATTR_TILE_FLAGS: {
|
case OTBM_ATTR_TILE_FLAGS: {
|
||||||
uint32 _flags = nodeTile->getU32();
|
uint32 _flags = nodeTile->getU32();
|
||||||
if ((_flags & TILESTATE_PROTECTIONZONE) == TILESTATE_PROTECTIONZONE)
|
if((_flags & TILESTATE_PROTECTIONZONE) == TILESTATE_PROTECTIONZONE)
|
||||||
flags |= TILESTATE_PROTECTIONZONE;
|
flags |= TILESTATE_PROTECTIONZONE;
|
||||||
else if ((_flags & TILESTATE_OPTIONALZONE) == TILESTATE_OPTIONALZONE)
|
else if((_flags & TILESTATE_OPTIONALZONE) == TILESTATE_OPTIONALZONE)
|
||||||
flags |= TILESTATE_OPTIONALZONE;
|
flags |= TILESTATE_OPTIONALZONE;
|
||||||
else if ((_flags & TILESTATE_HARDCOREZONE) == TILESTATE_HARDCOREZONE)
|
else if((_flags & TILESTATE_HARDCOREZONE) == TILESTATE_HARDCOREZONE)
|
||||||
flags |= TILESTATE_HARDCOREZONE;
|
flags |= TILESTATE_HARDCOREZONE;
|
||||||
|
|
||||||
if ((_flags & TILESTATE_NOLOGOUT) == TILESTATE_NOLOGOUT)
|
if((_flags & TILESTATE_NOLOGOUT) == TILESTATE_NOLOGOUT)
|
||||||
flags |= TILESTATE_NOLOGOUT;
|
flags |= TILESTATE_NOLOGOUT;
|
||||||
|
|
||||||
if ((_flags & TILESTATE_REFRESH) == TILESTATE_REFRESH)
|
if((_flags & TILESTATE_REFRESH) == TILESTATE_REFRESH)
|
||||||
flags |= TILESTATE_REFRESH;
|
flags |= TILESTATE_REFRESH;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OTBM_ATTR_ITEM: {
|
case OTBM_ATTR_ITEM: {
|
||||||
ItemPtr item = Item::createFromOtb(nodeTile->getU16());
|
ItemPtr item = Item::createFromOtb(nodeTile->getU16());
|
||||||
if (tile)
|
if(tile)
|
||||||
addThing(item, pos, 255);
|
addThing(item, pos, 255);
|
||||||
else if (item->isGround())
|
else if(item->isGround())
|
||||||
ground = item;
|
ground = item;
|
||||||
else
|
else
|
||||||
tile = createTileEx(pos, ground, item);
|
tile = createTileEx(pos, ground, item);
|
||||||
@ -191,16 +191,16 @@ void Map::loadOtbm(const std::string& fileName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const BinaryTreePtr &nodeItem : nodeTile->getChildren()) {
|
for (const BinaryTreePtr &nodeItem : nodeTile->getChildren()) {
|
||||||
if (nodeItem->getU8() != OTBM_ITEM)
|
if(nodeItem->getU8() != OTBM_ITEM)
|
||||||
stdext::throw_exception("invalid item node");
|
stdext::throw_exception("invalid item node");
|
||||||
|
|
||||||
ItemPtr item = Item::createFromOtb(nodeItem->getU16());
|
ItemPtr item = Item::createFromOtb(nodeItem->getU16());
|
||||||
item->unserializeItem(nodeItem);
|
item->unserializeItem(nodeItem);
|
||||||
if (item->isContainer()) {
|
if(item->isContainer()) {
|
||||||
// This is a temporary way for reading container items.
|
// This is a temporary way for reading container items.
|
||||||
MapContainerPtr mapContainer(new MapContainer);
|
MapContainerPtr mapContainer(new MapContainer);
|
||||||
for (const BinaryTreePtr &insideItem : nodeItem->getChildren()) {
|
for (const BinaryTreePtr &insideItem : nodeItem->getChildren()) {
|
||||||
if (insideItem->getU8() != OTBM_ITEM)
|
if(insideItem->getU8() != OTBM_ITEM)
|
||||||
stdext::throw_exception("invalid container item node");
|
stdext::throw_exception("invalid container item node");
|
||||||
|
|
||||||
ItemPtr newItem = Item::createFromOtb(insideItem->getU16());
|
ItemPtr newItem = Item::createFromOtb(insideItem->getU16());
|
||||||
@ -210,36 +210,36 @@ void Map::loadOtbm(const std::string& fileName)
|
|||||||
m_containers.push_back(mapContainer);
|
m_containers.push_back(mapContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (house) {
|
if(house) {
|
||||||
if (item->isMoveable()) {
|
if(item->isMoveable()) {
|
||||||
g_logger.warning(stdext::format("Movable item found in house: %d at pos %d %d %d - escaping...", item->getId(),
|
g_logger.warning(stdext::format("Movable item found in house: %d at pos %d %d %d - escaping...", item->getId(),
|
||||||
px, py, pz));
|
px, py, pz));
|
||||||
item = nullptr;
|
item = nullptr;
|
||||||
} else if (item->isDoor())
|
} else if(item->isDoor())
|
||||||
house->addDoor(item->getDoorId(), pos);
|
house->addDoor(item->getDoorId(), pos);
|
||||||
} else if (tile)
|
} else if(tile)
|
||||||
addThing(item, pos, 255);
|
addThing(item, pos, 255);
|
||||||
else if (item->isGround())
|
else if(item->isGround())
|
||||||
ground = item;
|
ground = item;
|
||||||
else
|
else
|
||||||
tile = createTileEx(pos, ground, item);
|
tile = createTileEx(pos, ground, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tile)
|
if(!tile)
|
||||||
tile = createTileEx(pos, ground);
|
tile = createTileEx(pos, ground);
|
||||||
|
|
||||||
tile->setFlags((tileflags_t)flags);
|
tile->setFlags((tileflags_t)flags);
|
||||||
}
|
}
|
||||||
} else if (mapDataType == OTBM_TOWNS) {
|
} else if(mapDataType == OTBM_TOWNS) {
|
||||||
TownPtr town = nullptr;
|
TownPtr town = nullptr;
|
||||||
for (const BinaryTreePtr &nodeTown : nodeMapData->getChildren()) {
|
for (const BinaryTreePtr &nodeTown : nodeMapData->getChildren()) {
|
||||||
if (nodeTown->getU8() != OTBM_TOWN)
|
if(nodeTown->getU8() != OTBM_TOWN)
|
||||||
stdext::throw_exception("invalid town node.");
|
stdext::throw_exception("invalid town node.");
|
||||||
|
|
||||||
uint32 townId = nodeTown->getU32();
|
uint32 townId = nodeTown->getU32();
|
||||||
std::string townName = nodeTown->getString();
|
std::string townName = nodeTown->getString();
|
||||||
Position townCoords(nodeTown->getU16(), nodeTown->getU16(), nodeTown->getU8());
|
Position townCoords(nodeTown->getU16(), nodeTown->getU16(), nodeTown->getU8());
|
||||||
if (!(town = m_towns.getTown(townId))) {
|
if(!(town = m_towns.getTown(townId))) {
|
||||||
town = TownPtr(new Town(townId, townName, townCoords));
|
town = TownPtr(new Town(townId, townName, townCoords));
|
||||||
m_towns.addTown(town);
|
m_towns.addTown(town);
|
||||||
} else {
|
} else {
|
||||||
@ -249,14 +249,14 @@ void Map::loadOtbm(const std::string& fileName)
|
|||||||
town->setId(townId);
|
town->setId(townId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (mapDataType == OTBM_WAYPOINTS && headerVersion > 1) {
|
} else if(mapDataType == OTBM_WAYPOINTS && headerVersion > 1) {
|
||||||
for (const BinaryTreePtr &nodeWaypoint : nodeMapData->getChildren()) {
|
for (const BinaryTreePtr &nodeWaypoint : nodeMapData->getChildren()) {
|
||||||
if (nodeWaypoint->getU8() != OTBM_WAYPOINT)
|
if(nodeWaypoint->getU8() != OTBM_WAYPOINT)
|
||||||
stdext::throw_exception("invalid waypoint node.");
|
stdext::throw_exception("invalid waypoint node.");
|
||||||
|
|
||||||
std::string name = nodeWaypoint->getString();
|
std::string name = nodeWaypoint->getString();
|
||||||
Position waypointPos(nodeWaypoint->getU16(), nodeWaypoint->getU16(), nodeWaypoint->getU8());
|
Position waypointPos(nodeWaypoint->getU16(), nodeWaypoint->getU16(), nodeWaypoint->getU8());
|
||||||
if (waypointPos.isValid() && !name.empty() && m_waypoints.find(waypointPos) == m_waypoints.end())
|
if(waypointPos.isValid() && !name.empty() && m_waypoints.find(waypointPos) == m_waypoints.end())
|
||||||
m_waypoints.insert(std::make_pair(waypointPos, name));
|
m_waypoints.insert(std::make_pair(waypointPos, name));
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@ -278,27 +278,27 @@ void Map::saveOtbm(const std::string &fileName)
|
|||||||
stdext::throw_exception(stdext::format("failed to open file '%s'", fileName));
|
stdext::throw_exception(stdext::format("failed to open file '%s'", fileName));
|
||||||
|
|
||||||
std::string dir;
|
std::string dir;
|
||||||
if (fileName.find_last_of('/') <= 0)
|
if(fileName.find_last_of('/') <= 0)
|
||||||
dir = g_resources.getWorkDir();
|
dir = g_resources.getWorkDir();
|
||||||
else
|
else
|
||||||
dir = fileName.substr(0, fileName.find_last_of('/'));
|
dir = fileName.substr(0, fileName.find_last_of('/'));
|
||||||
|
|
||||||
if (m_houseFile.empty())
|
if(m_houseFile.empty())
|
||||||
m_houseFile = "houses.xml";
|
m_houseFile = "houses.xml";
|
||||||
if (m_spawnFile.empty())
|
if(m_spawnFile.empty())
|
||||||
m_spawnFile = "spawns.xml";
|
m_spawnFile = "spawns.xml";
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (!m_houses->save(dir + "/" + m_houseFile))
|
if(!m_houses->save(dir + "/" + m_houseFile))
|
||||||
;
|
;
|
||||||
if (!m_spawns->save(dir + "/" + m_spawnFile))
|
if(!m_spawns->save(dir + "/" + m_spawnFile))
|
||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32 ver;
|
uint32 ver;
|
||||||
if (g_things.getOtbMajorVersion() < 2)
|
if(g_things.getOtbMajorVersion() < 2)
|
||||||
ver =0;
|
ver =0;
|
||||||
else if (g_things.getOtbMajorVersion() < 10)
|
else if(g_things.getOtbMajorVersion() < 10)
|
||||||
ver = 1;
|
ver = 1;
|
||||||
else
|
else
|
||||||
ver = 2;
|
ver = 2;
|
||||||
@ -328,7 +328,7 @@ void Map::saveOtbm(const std::string &fileName)
|
|||||||
fin->addString(m_spawnFile);
|
fin->addString(m_spawnFile);
|
||||||
|
|
||||||
// house file.
|
// house file.
|
||||||
if (ver > 1) {
|
if(ver > 1) {
|
||||||
fin->addU8(OTBM_ATTR_HOUSE_FILE);
|
fin->addU8(OTBM_ATTR_HOUSE_FILE);
|
||||||
fin->addString(m_houseFile);
|
fin->addString(m_houseFile);
|
||||||
}
|
}
|
||||||
@ -341,10 +341,10 @@ void Map::saveOtbm(const std::string &fileName)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Position tilePos = pair.first;
|
Position tilePos = pair.first;
|
||||||
if (tilePos.x < pos.x || tilePos.x >= pos.x + 256 ||
|
if(tilePos.x < pos.x || tilePos.x >= pos.x + 256 ||
|
||||||
tilePos.y < pos.y || tilePos.y >= pos.y + 256 ||
|
tilePos.y < pos.y || tilePos.y >= pos.y + 256 ||
|
||||||
tilePos.z != pos.z) {
|
tilePos.z != pos.z) {
|
||||||
if (!first)
|
if(!first)
|
||||||
fin->endNode();
|
fin->endNode();
|
||||||
|
|
||||||
pos.x = tilePos.x & 0xFF00;
|
pos.x = tilePos.x & 0xFF00;
|
||||||
@ -362,10 +362,10 @@ void Map::saveOtbm(const std::string &fileName)
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// TODO: hOUSES again.
|
// TODO: hOUSES again.
|
||||||
if (is house tile)
|
if(is house tile)
|
||||||
add u32 house id...;
|
add u32 house id...;
|
||||||
#endif
|
#endif
|
||||||
if (tile->flags()) {
|
if(tile->flags()) {
|
||||||
fin->addU8(OTBM_ATTR_TILE_FLAGS);
|
fin->addU8(OTBM_ATTR_TILE_FLAGS);
|
||||||
fin->addU32(tile->flags());
|
fin->addU32(tile->flags());
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public:
|
|||||||
void add(const ItemPtr& item) { m_items.push_back(item); }
|
void add(const ItemPtr& item) { m_items.push_back(item); }
|
||||||
ItemPtr operator[](uint idx) { return getItem(idx); }
|
ItemPtr operator[](uint idx) { return getItem(idx); }
|
||||||
ItemPtr getItem(int index) {
|
ItemPtr getItem(int index) {
|
||||||
if (index < 0 || index > (int)m_items.size())
|
if(index < 0 || index > (int)m_items.size())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return m_items[index];
|
return m_items[index];
|
||||||
|
@ -80,7 +80,7 @@ Color Outfit::getColor(int color)
|
|||||||
if(loc3 == 0)
|
if(loc3 == 0)
|
||||||
return Color(0, 0, 0);
|
return Color(0, 0, 0);
|
||||||
|
|
||||||
if (loc2 == 0) {
|
if(loc2 == 0) {
|
||||||
int loc7 = int(loc3 * 255);
|
int loc7 = int(loc3 * 255);
|
||||||
return Color(loc7, loc7, loc7);
|
return Color(loc7, loc7, loc7);
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ Color Outfit::getColor(int color)
|
|||||||
blue = loc3 * (1 - loc2);
|
blue = loc3 * (1 - loc2);
|
||||||
green = blue + (loc3 - blue) * 6 * loc1;
|
green = blue + (loc3 - blue) * 6 * loc1;
|
||||||
}
|
}
|
||||||
else if (loc1 < 2.0/6.0) {
|
else if(loc1 < 2.0/6.0) {
|
||||||
green = loc3;
|
green = loc3;
|
||||||
blue = loc3 * (1 - loc2);
|
blue = loc3 * (1 - loc2);
|
||||||
red = green - (loc3 - blue) * (6 * loc1 - 1);
|
red = green - (loc3 - blue) * (6 * loc1 - 1);
|
||||||
@ -102,12 +102,12 @@ Color Outfit::getColor(int color)
|
|||||||
red = loc3 * (1 - loc2);
|
red = loc3 * (1 - loc2);
|
||||||
blue = red + (loc3 - red) * (6 * loc1 - 2);
|
blue = red + (loc3 - red) * (6 * loc1 - 2);
|
||||||
}
|
}
|
||||||
else if (loc1 < 4.0/6.0) {
|
else if(loc1 < 4.0/6.0) {
|
||||||
blue = loc3;
|
blue = loc3;
|
||||||
red = loc3 * (1 - loc2);
|
red = loc3 * (1 - loc2);
|
||||||
green = blue - (loc3 - red) * (6 * loc1 - 3);
|
green = blue - (loc3 - red) * (6 * loc1 - 3);
|
||||||
}
|
}
|
||||||
else if (loc1 < 5.0/6.0) {
|
else if(loc1 < 5.0/6.0) {
|
||||||
blue = loc3;
|
blue = loc3;
|
||||||
green = loc3 * (1 - loc2);
|
green = loc3 * (1 - loc2);
|
||||||
red = green + (loc3 - green) * (6 * loc1 - 4);
|
red = green + (loc3 - green) * (6 * loc1 - 4);
|
||||||
|
@ -122,30 +122,30 @@ void ThingTypeManager::loadOtb(const std::string& file)
|
|||||||
void ThingTypeManager::loadXml(const std::string& file)
|
void ThingTypeManager::loadXml(const std::string& file)
|
||||||
{
|
{
|
||||||
TiXmlDocument doc(file.c_str());
|
TiXmlDocument doc(file.c_str());
|
||||||
if (!doc.LoadFile())
|
if(!doc.LoadFile())
|
||||||
stdext::throw_exception(stdext::format("failed to load xml '%s'", file));
|
stdext::throw_exception(stdext::format("failed to load xml '%s'", file));
|
||||||
|
|
||||||
TiXmlElement* root = doc.FirstChildElement();
|
TiXmlElement* root = doc.FirstChildElement();
|
||||||
if (!root || root->ValueTStr() != "items")
|
if(!root || root->ValueTStr() != "items")
|
||||||
stdext::throw_exception("invalid root tag name");
|
stdext::throw_exception("invalid root tag name");
|
||||||
|
|
||||||
ThingTypeOtbPtr otbType = nullptr;
|
ThingTypeOtbPtr otbType = nullptr;
|
||||||
for (TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) {
|
for (TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) {
|
||||||
if (element->ValueTStr() != "item")
|
if(element->ValueTStr() != "item")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string name = element->Attribute("id");
|
std::string name = element->Attribute("id");
|
||||||
if (name.empty())
|
if(name.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uint16 id = stdext::unsafe_cast<uint16>(element->Attribute("id"));
|
uint16 id = stdext::unsafe_cast<uint16>(element->Attribute("id"));
|
||||||
if (!(otbType = getOtbType(id))) {
|
if(!(otbType = getOtbType(id))) {
|
||||||
// try reading fromId toId
|
// try reading fromId toId
|
||||||
uint16 from = stdext::unsafe_cast<uint16>(element->Attribute("fromId"));
|
uint16 from = stdext::unsafe_cast<uint16>(element->Attribute("fromId"));
|
||||||
uint16 to = stdext::unsafe_cast<uint16>(element->Attribute("toid"));
|
uint16 to = stdext::unsafe_cast<uint16>(element->Attribute("toid"));
|
||||||
|
|
||||||
for (uint16 __id = from; __id < to; ++__id) {
|
for (uint16 __id = from; __id < to; ++__id) {
|
||||||
if (!(otbType = getOtbType(__id)))
|
if(!(otbType = getOtbType(__id)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
otbType->setHasRange();
|
otbType->setHasRange();
|
||||||
@ -155,14 +155,14 @@ void ThingTypeManager::loadXml(const std::string& file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perform last check
|
// perform last check
|
||||||
if (!otbType) {
|
if(!otbType) {
|
||||||
stdext::throw_exception(stdext::format("failed to find item with server id %d - tried reading fromid to id",
|
stdext::throw_exception(stdext::format("failed to find item with server id %d - tried reading fromid to id",
|
||||||
id));
|
id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TiXmlElement *attr = element->FirstChildElement(); attr; attr = attr->NextSiblingElement()) {
|
for (TiXmlElement *attr = element->FirstChildElement(); attr; attr = attr->NextSiblingElement()) {
|
||||||
if (attr->ValueTStr() != "attribute")
|
if(attr->ValueTStr() != "attribute")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
otbType->unserializeXML(attr);
|
otbType->unserializeXML(attr);
|
||||||
|
@ -68,8 +68,8 @@ void ThingTypeOtb::unserializeXML(const TiXmlElement* elem)
|
|||||||
std::string key = elem->Attribute("key");
|
std::string key = elem->Attribute("key");
|
||||||
std::string value = elem->Attribute("value");
|
std::string value = elem->Attribute("value");
|
||||||
|
|
||||||
if (key == "name")
|
if(key == "name")
|
||||||
setName(value);
|
setName(value);
|
||||||
else if (key == "description")
|
else if(key == "description")
|
||||||
setDesc(value);
|
setDesc(value);
|
||||||
}
|
}
|
||||||
|
@ -27,28 +27,28 @@ Towns g_towns;
|
|||||||
Town::Town(uint32 tid, const std::string& name, const Position& pos)
|
Town::Town(uint32 tid, const std::string& name, const Position& pos)
|
||||||
: m_id(tid), m_name(name)
|
: m_id(tid), m_name(name)
|
||||||
{
|
{
|
||||||
if (pos.isValid())
|
if(pos.isValid())
|
||||||
m_pos = pos;
|
m_pos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Towns::addTown(const TownPtr &town)
|
void Towns::addTown(const TownPtr &town)
|
||||||
{
|
{
|
||||||
if (findTown(town->getId()) == m_towns.end())
|
if(findTown(town->getId()) == m_towns.end())
|
||||||
m_towns.push_back(town);
|
m_towns.push_back(town);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Towns::removeTown(uint32 townId)
|
void Towns::removeTown(uint32 townId)
|
||||||
{
|
{
|
||||||
auto it = findTown(townId);
|
auto it = findTown(townId);
|
||||||
if (it != m_towns.end())
|
if(it != m_towns.end())
|
||||||
m_towns.erase(it);
|
m_towns.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
TownPtr Towns::getTown(uint32 townId)
|
TownPtr Towns::getTown(uint32 townId)
|
||||||
{
|
{
|
||||||
auto it = findTown(townId);
|
auto it = findTown(townId);
|
||||||
if (it != m_towns.end())
|
if(it != m_towns.end())
|
||||||
return *it;
|
return *it;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user