From 36e5a5a92fb3b86c2cfb59b2b43442ec692989de Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sat, 14 Jul 2012 14:29:42 -0300 Subject: [PATCH] Remove if spaces --- src/framework/core/binarytree.cpp | 12 ++-- src/framework/util/rect.h | 4 +- src/otclient/houses.cpp | 26 ++++----- src/otclient/item.cpp | 4 +- src/otclient/map.cpp | 94 +++++++++++++++---------------- src/otclient/map.h | 2 +- src/otclient/outfit.cpp | 8 +-- src/otclient/thingtypemanager.cpp | 16 +++--- src/otclient/thingtypeotb.cpp | 4 +- src/otclient/towns.cpp | 8 +-- 10 files changed, 89 insertions(+), 89 deletions(-) diff --git a/src/framework/core/binarytree.cpp b/src/framework/core/binarytree.cpp index 7a4ff7b5..6fc1ba4c 100644 --- a/src/framework/core/binarytree.cpp +++ b/src/framework/core/binarytree.cpp @@ -60,7 +60,7 @@ void BinaryTree::seek(uint pos) uint8 BinaryTree::getU8() { - if (m_pos+1 > m_buffer.size()) + if(m_pos+1 > m_buffer.size()) stdext::throw_exception("BinaryTree: getU8 failed"); uint8 v = m_buffer[m_pos]; m_pos += 1; @@ -69,7 +69,7 @@ uint8 BinaryTree::getU8() uint16 BinaryTree::getU16() { - if (m_pos+2 > m_buffer.size()) + if(m_pos+2 > m_buffer.size()) stdext::throw_exception("BinaryTree: getU16 failed"); uint16 v = stdext::readLE16(&m_buffer[m_pos]); m_pos += 2; @@ -78,7 +78,7 @@ uint16 BinaryTree::getU16() uint32 BinaryTree::getU32() { - if (m_pos+4 > m_buffer.size()) + if(m_pos+4 > m_buffer.size()) stdext::throw_exception("BinaryTree: getU32 failed"); uint32 v = stdext::readLE32(&m_buffer[m_pos]); m_pos += 4; @@ -87,7 +87,7 @@ uint32 BinaryTree::getU32() uint64 BinaryTree::getU64() { - if (m_pos+8 > m_buffer.size()) + if(m_pos+8 > m_buffer.size()) stdext::throw_exception("BinaryTree: getU64 failed"); uint64 v = stdext::readLE64(&m_buffer[m_pos]); m_pos += 8; @@ -97,10 +97,10 @@ uint64 BinaryTree::getU64() std::string BinaryTree::getString() { 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"); - 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."); std::string ret((char *)&m_buffer[m_pos], len); diff --git a/src/framework/util/rect.h b/src/framework/util/rect.h index 22bcba9a..52954d51 100644 --- a/src/framework/util/rect.h +++ b/src/framework/util/rect.h @@ -191,7 +191,7 @@ public: else r2 = r.x2; - if (l1 > r2 || l2 > r1) + if(l1 > r2 || l2 > r1) return false; int t1 = y1; @@ -203,7 +203,7 @@ public: int t2 = r.y1; int b2 = r.y1; - if (r.y2 - r.y1 + 1 < 0) + if(r.y2 - r.y1 + 1 < 0) t2 = r.y2; else b2 = r.y2; diff --git a/src/otclient/houses.cpp b/src/otclient/houses.cpp index ea0af0c9..f7e93e33 100644 --- a/src/otclient/houses.cpp +++ b/src/otclient/houses.cpp @@ -27,20 +27,20 @@ Houses g_houses; House::House(uint32 hId, const std::string &name, const Position &pos) : m_id(hId), m_name(name) { - if (pos.isValid()) + if(pos.isValid()) m_doors.insert(std::make_pair(0, pos)); // first door } 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)); } void House::setTile(const TilePtr& tile) { 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); } @@ -49,18 +49,18 @@ void House::setTile(const TilePtr& tile) void House::load(const TiXmlElement *elem) { std::string name = elem->Attribute("name"); - if (name.empty()) + if(name.empty()) name = stdext::format("UnNamed house #%u", getId()); uint32 rent = fugly_get("rent", uint32); m_rent = rent; 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)); uint32 size = fugly_get("size", uint32); - if (size == 0) + if(size == 0) size = 1; m_size = size; @@ -71,21 +71,21 @@ void House::load(const TiXmlElement *elem) 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); } void Houses::removeHouse(uint32 houseId) { auto it = findHouse(houseId); - if (it != m_houses.end()) + if(it != m_houses.end()) m_houses.erase(it); } HousePtr Houses::getHouse(uint32 houseId) { auto it = findHouse(houseId); - if (it != m_houses.end()) + if(it != m_houses.end()) return *it; return nullptr; @@ -94,20 +94,20 @@ HousePtr Houses::getHouse(uint32 houseId) void Houses::load(const std::string& fileName) { TiXmlDocument doc(fileName.c_str()); - if (!doc.LoadFile()) + if(!doc.LoadFile()) stdext::throw_exception(stdext::format("failed to load '%s' (House XML)", fileName)); TiXmlElement *root = doc.FirstChildElement(); - if (!root || root->ValueTStr() != "houses") + if(!root || root->ValueTStr() != "houses") stdext::throw_exception("invalid root tag name"); for (TiXmlElement *elem = root->FirstChildElement(); elem; elem = elem->NextSiblingElement()) { - if (elem->ValueTStr() != "house") + if(elem->ValueTStr() != "house") stdext::throw_exception("invalid house tag."); uint32 houseId = fugly_get("houseid", uint32); HousePtr house = getHouse(houseId); - if (!house) + if(!house) house = HousePtr(new House(houseId)), addHouse(house); house->load(elem); diff --git a/src/otclient/item.cpp b/src/otclient/item.cpp index f32b6749..08cd4a26 100644 --- a/src/otclient/item.cpp +++ b/src/otclient/item.cpp @@ -211,7 +211,7 @@ void Item::unserializeItem(const BinaryTreePtr &in) { while (in->canRead()) { uint8 attrType = in->getU8(); - if (attrType == 0) + if(attrType == 0) break; // fugly switch yes? @@ -286,7 +286,7 @@ void Item::unserializeItem(const BinaryTreePtr &in) bool Item::isMoveable() { - if (m_datType) + if(m_datType) return !m_datType->isNotMoveable(); g_logger.warning(stdext::format( diff --git a/src/otclient/map.cpp b/src/otclient/map.cpp index fda9e534..2a9d7b32 100644 --- a/src/otclient/map.cpp +++ b/src/otclient/map.cpp @@ -63,22 +63,22 @@ void Map::notificateTileUpdateToMapViews(const Position& pos) void Map::loadOtbm(const std::string& fileName) { FileStreamPtr fin = g_resources.openFile(fileName); - if (!fin) + if(!fin) stdext::throw_exception(stdext::format("Unable to load map '%s'", fileName)); fin->cache(); - if (!g_things.isOtbLoaded()) + if(!g_things.isOtbLoaded()) 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"); BinaryTreePtr root = fin->getBinaryTree(); - if (root->getU8()) + if(root->getU8()) stdext::throw_exception("could not read root property!"); uint32 headerVersion = root->getU32(); - if (!headerVersion || headerVersion > 3) + if(!headerVersion || headerVersion > 3) stdext::throw_exception(stdext::format("Unknown OTBM version detected: %u.", headerVersion)); m_width = root->getU16(); @@ -86,25 +86,25 @@ void Map::loadOtbm(const std::string& fileName) dump << "Map size: " << m_width << "x" << m_height; 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", 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", headerMajorItems, g_things.getOtbMajorVersion())); } root->skip(3); 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", headerMinorItems, g_things.getOtbMinorVersion())); } 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"); while (node->canRead()) { @@ -127,13 +127,13 @@ void Map::loadOtbm(const std::string& fileName) for (const BinaryTreePtr &nodeMapData : node->getChildren()) { uint8 mapDataType = nodeMapData->getU8(); - if (mapDataType == OTBM_TILE_AREA) { + if(mapDataType == OTBM_TILE_AREA) { uint16 baseX = nodeMapData->getU16(), baseY = nodeMapData->getU16(); uint8 pz = nodeMapData->getU8(); for (const BinaryTreePtr &nodeTile : nodeMapData->getChildren()) { 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)); TilePtr tile = nullptr; @@ -144,10 +144,10 @@ void Map::loadOtbm(const std::string& fileName) uint16 px = baseX + nodeTile->getU8(), py = baseY + nodeTile->getU8(); Position pos(px, py, pz); - if (type == OTBM_HOUSETILE) { + if(type == OTBM_HOUSETILE) { uint32 hId = nodeTile->getU32(); tile = createTile(pos); - if (!(house = m_houses.getHouse(hId))) { + if(!(house = m_houses.getHouse(hId))) { house = HousePtr(new House(hId)); m_houses.addHouse(house); } @@ -159,26 +159,26 @@ void Map::loadOtbm(const std::string& fileName) switch (tileAttr) { case OTBM_ATTR_TILE_FLAGS: { uint32 _flags = nodeTile->getU32(); - if ((_flags & TILESTATE_PROTECTIONZONE) == TILESTATE_PROTECTIONZONE) + if((_flags & TILESTATE_PROTECTIONZONE) == TILESTATE_PROTECTIONZONE) flags |= TILESTATE_PROTECTIONZONE; - else if ((_flags & TILESTATE_OPTIONALZONE) == TILESTATE_OPTIONALZONE) + else if((_flags & TILESTATE_OPTIONALZONE) == TILESTATE_OPTIONALZONE) flags |= TILESTATE_OPTIONALZONE; - else if ((_flags & TILESTATE_HARDCOREZONE) == TILESTATE_HARDCOREZONE) + else if((_flags & TILESTATE_HARDCOREZONE) == TILESTATE_HARDCOREZONE) flags |= TILESTATE_HARDCOREZONE; - if ((_flags & TILESTATE_NOLOGOUT) == TILESTATE_NOLOGOUT) + if((_flags & TILESTATE_NOLOGOUT) == TILESTATE_NOLOGOUT) flags |= TILESTATE_NOLOGOUT; - if ((_flags & TILESTATE_REFRESH) == TILESTATE_REFRESH) + if((_flags & TILESTATE_REFRESH) == TILESTATE_REFRESH) flags |= TILESTATE_REFRESH; break; } case OTBM_ATTR_ITEM: { ItemPtr item = Item::createFromOtb(nodeTile->getU16()); - if (tile) + if(tile) addThing(item, pos, 255); - else if (item->isGround()) + else if(item->isGround()) ground = item; else tile = createTileEx(pos, ground, item); @@ -191,16 +191,16 @@ void Map::loadOtbm(const std::string& fileName) } for (const BinaryTreePtr &nodeItem : nodeTile->getChildren()) { - if (nodeItem->getU8() != OTBM_ITEM) + if(nodeItem->getU8() != OTBM_ITEM) stdext::throw_exception("invalid item node"); ItemPtr item = Item::createFromOtb(nodeItem->getU16()); item->unserializeItem(nodeItem); - if (item->isContainer()) { + if(item->isContainer()) { // This is a temporary way for reading container items. MapContainerPtr mapContainer(new MapContainer); for (const BinaryTreePtr &insideItem : nodeItem->getChildren()) { - if (insideItem->getU8() != OTBM_ITEM) + if(insideItem->getU8() != OTBM_ITEM) stdext::throw_exception("invalid container item node"); ItemPtr newItem = Item::createFromOtb(insideItem->getU16()); @@ -210,36 +210,36 @@ void Map::loadOtbm(const std::string& fileName) m_containers.push_back(mapContainer); } - if (house) { - if (item->isMoveable()) { + if(house) { + if(item->isMoveable()) { g_logger.warning(stdext::format("Movable item found in house: %d at pos %d %d %d - escaping...", item->getId(), px, py, pz)); item = nullptr; - } else if (item->isDoor()) + } else if(item->isDoor()) house->addDoor(item->getDoorId(), pos); - } else if (tile) + } else if(tile) addThing(item, pos, 255); - else if (item->isGround()) + else if(item->isGround()) ground = item; else tile = createTileEx(pos, ground, item); } - if (!tile) + if(!tile) tile = createTileEx(pos, ground); tile->setFlags((tileflags_t)flags); } - } else if (mapDataType == OTBM_TOWNS) { + } else if(mapDataType == OTBM_TOWNS) { TownPtr town = nullptr; for (const BinaryTreePtr &nodeTown : nodeMapData->getChildren()) { - if (nodeTown->getU8() != OTBM_TOWN) + if(nodeTown->getU8() != OTBM_TOWN) stdext::throw_exception("invalid town node."); uint32 townId = nodeTown->getU32(); std::string townName = nodeTown->getString(); 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)); m_towns.addTown(town); } else { @@ -249,14 +249,14 @@ void Map::loadOtbm(const std::string& fileName) town->setId(townId); } } - } else if (mapDataType == OTBM_WAYPOINTS && headerVersion > 1) { + } else if(mapDataType == OTBM_WAYPOINTS && headerVersion > 1) { for (const BinaryTreePtr &nodeWaypoint : nodeMapData->getChildren()) { - if (nodeWaypoint->getU8() != OTBM_WAYPOINT) + if(nodeWaypoint->getU8() != OTBM_WAYPOINT) stdext::throw_exception("invalid waypoint node."); std::string name = nodeWaypoint->getString(); 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)); } } else @@ -278,27 +278,27 @@ void Map::saveOtbm(const std::string &fileName) stdext::throw_exception(stdext::format("failed to open file '%s'", fileName)); std::string dir; - if (fileName.find_last_of('/') <= 0) + if(fileName.find_last_of('/') <= 0) dir = g_resources.getWorkDir(); else dir = fileName.substr(0, fileName.find_last_of('/')); - if (m_houseFile.empty()) + if(m_houseFile.empty()) m_houseFile = "houses.xml"; - if (m_spawnFile.empty()) + if(m_spawnFile.empty()) m_spawnFile = "spawns.xml"; #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 uint32 ver; - if (g_things.getOtbMajorVersion() < 2) + if(g_things.getOtbMajorVersion() < 2) ver =0; - else if (g_things.getOtbMajorVersion() < 10) + else if(g_things.getOtbMajorVersion() < 10) ver = 1; else ver = 2; @@ -328,7 +328,7 @@ void Map::saveOtbm(const std::string &fileName) fin->addString(m_spawnFile); // house file. - if (ver > 1) { + if(ver > 1) { fin->addU8(OTBM_ATTR_HOUSE_FILE); fin->addString(m_houseFile); } @@ -341,10 +341,10 @@ void Map::saveOtbm(const std::string &fileName) continue; 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.z != pos.z) { - if (!first) + if(!first) fin->endNode(); pos.x = tilePos.x & 0xFF00; @@ -362,10 +362,10 @@ void Map::saveOtbm(const std::string &fileName) #if 0 // TODO: hOUSES again. - if (is house tile) + if(is house tile) add u32 house id...; #endif - if (tile->flags()) { + if(tile->flags()) { fin->addU8(OTBM_ATTR_TILE_FLAGS); fin->addU32(tile->flags()); } diff --git a/src/otclient/map.h b/src/otclient/map.h index cf2a7f89..b83ab285 100644 --- a/src/otclient/map.h +++ b/src/otclient/map.h @@ -91,7 +91,7 @@ public: void add(const ItemPtr& item) { m_items.push_back(item); } ItemPtr operator[](uint idx) { return getItem(idx); } ItemPtr getItem(int index) { - if (index < 0 || index > (int)m_items.size()) + if(index < 0 || index > (int)m_items.size()) return nullptr; return m_items[index]; diff --git a/src/otclient/outfit.cpp b/src/otclient/outfit.cpp index 807de33e..549b4892 100644 --- a/src/otclient/outfit.cpp +++ b/src/otclient/outfit.cpp @@ -80,7 +80,7 @@ Color Outfit::getColor(int color) if(loc3 == 0) return Color(0, 0, 0); - if (loc2 == 0) { + if(loc2 == 0) { int loc7 = int(loc3 * 255); return Color(loc7, loc7, loc7); } @@ -92,7 +92,7 @@ Color Outfit::getColor(int color) blue = loc3 * (1 - loc2); green = blue + (loc3 - blue) * 6 * loc1; } - else if (loc1 < 2.0/6.0) { + else if(loc1 < 2.0/6.0) { green = loc3; blue = loc3 * (1 - loc2); red = green - (loc3 - blue) * (6 * loc1 - 1); @@ -102,12 +102,12 @@ Color Outfit::getColor(int color) red = loc3 * (1 - loc2); blue = red + (loc3 - red) * (6 * loc1 - 2); } - else if (loc1 < 4.0/6.0) { + else if(loc1 < 4.0/6.0) { blue = loc3; red = loc3 * (1 - loc2); green = blue - (loc3 - red) * (6 * loc1 - 3); } - else if (loc1 < 5.0/6.0) { + else if(loc1 < 5.0/6.0) { blue = loc3; green = loc3 * (1 - loc2); red = green + (loc3 - green) * (6 * loc1 - 4); diff --git a/src/otclient/thingtypemanager.cpp b/src/otclient/thingtypemanager.cpp index 5e7d4723..690bf279 100644 --- a/src/otclient/thingtypemanager.cpp +++ b/src/otclient/thingtypemanager.cpp @@ -122,30 +122,30 @@ void ThingTypeManager::loadOtb(const std::string& file) void ThingTypeManager::loadXml(const std::string& file) { TiXmlDocument doc(file.c_str()); - if (!doc.LoadFile()) + if(!doc.LoadFile()) stdext::throw_exception(stdext::format("failed to load xml '%s'", file)); TiXmlElement* root = doc.FirstChildElement(); - if (!root || root->ValueTStr() != "items") + if(!root || root->ValueTStr() != "items") stdext::throw_exception("invalid root tag name"); ThingTypeOtbPtr otbType = nullptr; for (TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) { - if (element->ValueTStr() != "item") + if(element->ValueTStr() != "item") continue; std::string name = element->Attribute("id"); - if (name.empty()) + if(name.empty()) continue; uint16 id = stdext::unsafe_cast(element->Attribute("id")); - if (!(otbType = getOtbType(id))) { + if(!(otbType = getOtbType(id))) { // try reading fromId toId uint16 from = stdext::unsafe_cast(element->Attribute("fromId")); uint16 to = stdext::unsafe_cast(element->Attribute("toid")); for (uint16 __id = from; __id < to; ++__id) { - if (!(otbType = getOtbType(__id))) + if(!(otbType = getOtbType(__id))) continue; otbType->setHasRange(); @@ -155,14 +155,14 @@ void ThingTypeManager::loadXml(const std::string& file) } // 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", id)); } } for (TiXmlElement *attr = element->FirstChildElement(); attr; attr = attr->NextSiblingElement()) { - if (attr->ValueTStr() != "attribute") + if(attr->ValueTStr() != "attribute") continue; otbType->unserializeXML(attr); diff --git a/src/otclient/thingtypeotb.cpp b/src/otclient/thingtypeotb.cpp index 9d5f59a5..80a6d915 100644 --- a/src/otclient/thingtypeotb.cpp +++ b/src/otclient/thingtypeotb.cpp @@ -68,8 +68,8 @@ void ThingTypeOtb::unserializeXML(const TiXmlElement* elem) std::string key = elem->Attribute("key"); std::string value = elem->Attribute("value"); - if (key == "name") + if(key == "name") setName(value); - else if (key == "description") + else if(key == "description") setDesc(value); } diff --git a/src/otclient/towns.cpp b/src/otclient/towns.cpp index 426b4ec8..1f84dabb 100644 --- a/src/otclient/towns.cpp +++ b/src/otclient/towns.cpp @@ -27,28 +27,28 @@ Towns g_towns; Town::Town(uint32 tid, const std::string& name, const Position& pos) : m_id(tid), m_name(name) { - if (pos.isValid()) + if(pos.isValid()) m_pos = pos; } 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); } void Towns::removeTown(uint32 townId) { auto it = findTown(townId); - if (it != m_towns.end()) + if(it != m_towns.end()) m_towns.erase(it); } TownPtr Towns::getTown(uint32 townId) { auto it = findTown(townId); - if (it != m_towns.end()) + if(it != m_towns.end()) return *it; return nullptr; }