From a5ec922b9143f97ad963eaf39e2377477b0ee7cb Mon Sep 17 00:00:00 2001 From: Beats Date: Sun, 24 Mar 2024 15:55:48 -0300 Subject: [PATCH] up --- src/io/iobestiary.cpp | 11 ++--- src/map/house/house.cpp | 52 ++++++++++---------- src/server/network/protocol/protocolgame.cpp | 22 ++++----- 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/io/iobestiary.cpp b/src/io/iobestiary.cpp index f7305d8503c..c544021367e 100644 --- a/src/io/iobestiary.cpp +++ b/src/io/iobestiary.cpp @@ -97,7 +97,7 @@ bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, std::share std::shared_ptr IOBestiary::getBestiaryCharm(charmRune_t activeCharm, bool force /*= false*/) const { const auto charmInternal = g_game().getCharmList(); - for (const auto tmpCharm : charmInternal) { + for (const auto &tmpCharm : charmInternal) { if (tmpCharm->id == activeCharm) { return tmpCharm; } @@ -169,7 +169,7 @@ void IOBestiary::setCharmRuneCreature(std::shared_ptr player, const std: std::list IOBestiary::getCharmUsedRuneBitAll(std::shared_ptr player) { int32_t input = player->getUsedRunesBit(); - ; + int8_t i = 0; std::list rtn; while (input != 0) { @@ -191,7 +191,7 @@ uint16_t IOBestiary::getBestiaryRaceUnlocked(std::shared_ptr player, Bes uint16_t count = 0; std::map besty_l = g_game().getBestiaryList(); - for (auto it : besty_l) { + for (const auto &it : besty_l) { const auto mtype = g_monsters().getMonsterType(it.second); if (mtype && mtype->info.bestiaryRace == race && player->getBestiaryKillCount(mtype->info.raceid) > 0) { count++; @@ -271,7 +271,7 @@ int32_t IOBestiary::bitToggle(int32_t input, const std::shared_ptr charm, return CHARM_NONE; } - int32_t returnToggle = 0; + int32_t returnToggle; int32_t binary = charm->binary; if (on) { returnToggle = input | binary; @@ -307,7 +307,7 @@ void IOBestiary::sendBuyCharmRune(std::shared_ptr player, charmRune_t ru player->setUnlockedRunesBit(value); } else if (action == 1) { std::list usedRunes = getCharmUsedRuneBitAll(player); - uint16_t limitRunes = 0; + uint16_t limitRunes; if (player->isPremium()) { if (player->hasCharmExpansion()) { @@ -343,7 +343,6 @@ void IOBestiary::sendBuyCharmRune(std::shared_ptr player, charmRune_t ru player->sendFYIBox("You don't have enough gold."); } player->BestiarysendCharms(); - return; } std::map IOBestiary::getMonsterElements(const std::shared_ptr mtype) const { diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 7967e21c3cc..842622b2af5 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -45,7 +45,7 @@ void House::setNewOwnerGuid(int32_t newOwnerGuid, bool serverStartup) { void House::clearHouseInfo(bool preventOwnerDeletion) { // Remove players from beds - for (auto bed : bedsList) { + for (const auto &bed : bedsList) { if (bed->getSleeper() != 0) { bed->wakeUp(nullptr); } @@ -60,7 +60,7 @@ void House::clearHouseInfo(bool preventOwnerDeletion) { setAccessList(SUBOWNER_LIST, ""); setAccessList(GUEST_LIST, ""); - for (auto door : doorList) { + for (const auto &door : doorList) { door->setAccessList(""); } } @@ -73,7 +73,7 @@ bool House::tryTransferOwnership(std::shared_ptr player, bool serverStar transferSuccess = transferToDepot(); } - for (auto tile : houseTiles) { + for (const auto &tile : houseTiles) { if (const CreatureVector* creatures = tile->getCreatures()) { for (int32_t i = creatures->size(); --i >= 0;) { const auto creature = (*creatures)[i]; @@ -103,7 +103,7 @@ void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, std::shared isLoaded = true; if (owner != 0) { - tryTransferOwnership(player, false); + tryTransferOwnership(std::move(player), false); } else { std::string strRentPeriod = asLowerCaseString(g_configManager().getString(HOUSE_RENT_PERIOD, __FUNCTION__)); time_t currentTime = time(nullptr); @@ -237,7 +237,7 @@ void House::setAccessList(uint32_t listId, const std::string &textlist) { } // kick uninvited players - for (std::shared_ptr tile : houseTiles) { + for (const std::shared_ptr &tile : houseTiles) { if (CreatureVector* creatures = tile->getCreatures()) { for (int32_t i = creatures->size(); --i >= 0;) { std::shared_ptr player = (*creatures)[i]->getPlayer(); @@ -272,7 +272,7 @@ bool House::transferToDepot(std::shared_ptr player) const { if (townId == 0 || !player) { return false; } - for (std::shared_ptr tile : houseTiles) { + for (const std::shared_ptr &tile : houseTiles) { if (!transferToDepot(player, tile)) { return false; } @@ -304,7 +304,7 @@ bool House::transferToDepot(std::shared_ptr player, std::shared_ptr> playersToSave = { player }; - for (std::shared_ptr item : moveItemList) { + for (const std::shared_ptr &item : moveItemList) { g_logger().debug("[{}] moving item '{}' to depot", __FUNCTION__, item->getName()); auto targetPlayer = player; if (item->hasOwner() && !item->isOwner(targetPlayer)) { @@ -317,7 +317,7 @@ bool House::transferToDepot(std::shared_ptr player, std::shared_ptrgetParent(), targetPlayer->getInbox(), INDEX_WHEREEVER, item, item->getItemCount(), nullptr, FLAG_NOLIMIT); } - for (auto playerToSave : playersToSave) { + for (const auto &playerToSave : playersToSave) { g_saveManager().savePlayer(playerToSave); } return true; @@ -379,7 +379,7 @@ void House::handleWrapableItem(ItemList &moveItemList, std::shared_ptr ite void House::handleContainer(ItemList &moveItemList, std::shared_ptr item) const { if (const auto container = item->getContainer()) { - for (std::shared_ptr containerItem : container->getItemList()) { + for (const std::shared_ptr &containerItem : container->getItemList()) { moveItemList.push_back(containerItem); } } @@ -554,32 +554,32 @@ void AccessList::parseList(const std::string &list) { } auto lines = explodeString(validList, "\n", 100); - for (auto &line : lines) { - trimString(line); - trim_left(line, '\t'); - trim_right(line, '\t'); - trimString(line); + for (auto &m_line : lines) { + trimString(m_line); + trim_left(m_line, '\t'); + trim_right(m_line, '\t'); + trimString(m_line); - if (line.empty() || line.front() == '#' || line.length() > 100) { + if (m_line.empty() || m_line.front() == '#' || m_line.length() > 100) { continue; } - toLowerCaseString(line); + toLowerCaseString(m_line); - std::string::size_type at_pos = line.find("@"); + std::string::size_type at_pos = m_line.find('@'); if (at_pos != std::string::npos) { if (at_pos == 0) { - addGuild(line.substr(1)); + addGuild(m_line.substr(1)); } else { - addGuildRank(line.substr(0, at_pos - 1), line.substr(at_pos + 1)); + addGuildRank(m_line.substr(0, at_pos - 1), m_line.substr(at_pos + 1)); } - } else if (line == "*") { + } else if (m_line == "*") { allowEveryone = true; - } else if (line.find_first_of("!*?") != std::string::npos) { + } else if (m_line.find_first_of("!*?") != std::string::npos) { // Remove regular expressions since they don't make much sense in houses continue; - } else if (line.length() <= NETWORKMESSAGE_PLAYERNAME_MAXLENGTH) { - addPlayer(line); + } else if (m_line.length() <= NETWORKMESSAGE_PLAYERNAME_MAXLENGTH) { + addPlayer(m_line); } } } @@ -603,7 +603,7 @@ namespace { return nullptr; } - const auto guild = g_game().getGuild(guildId); + auto guild = g_game().getGuild(guildId); if (guild) { return guild; } @@ -615,7 +615,7 @@ namespace { void AccessList::addGuild(const std::string &name) { const auto guild = getGuildByName(name); if (guild) { - for (const auto rank : guild->getRanks()) { + for (const auto &rank : guild->getRanks()) { guildRankList.insert(rank->id); } } @@ -669,7 +669,7 @@ void Door::setHouse(std::shared_ptr newHouse) { return; } - this->house = newHouse; + this->house = std::move(newHouse); if (!accessList) { accessList = std::make_unique(); diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index e9a35d9302f..ca2547c6f32 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -2233,7 +2233,7 @@ void ProtocolGame::parseBestiarysendRaces() { for (uint8_t i = BESTY_RACE_FIRST; i <= BESTY_RACE_LAST; i++) { std::string BestClass = ""; uint16_t count = 0; - for (auto rit : mtype_list) { + for (const auto &rit : mtype_list) { const auto mtype = g_monsters().getMonsterType(rit.second); if (!mtype) { return; @@ -2309,7 +2309,7 @@ void ProtocolGame::parseBestiarysendMonsterData(NetworkMessage &msg) { std::vector lootList = mtype->info.lootItems; newmsg.addByte(lootList.size()); - for (LootBlock loot : lootList) { + for (const LootBlock &loot : lootList) { int8_t difficult = g_iobestiary().calculateDifficult(loot.chance); bool shouldAddItem = false; @@ -2621,7 +2621,7 @@ void ProtocolGame::createLeaderTeamFinder(NetworkMessage &msg) { auto party = player->getParty(); if (teamAssemble->partyBool && party) { - for (std::shared_ptr member : party->getMembers()) { + for (const std::shared_ptr &member : party->getMembers()) { if (member && member->getGUID() != player->getGUID()) { teamAssemble->membersMap.insert({ member->getGUID(), 3 }); } @@ -2893,7 +2893,7 @@ void ProtocolGame::parseBestiarysendCreatures(NetworkMessage &msg) { std::string raceName = msg.getString(); race = g_iobestiary().findRaceByName(raceName); - if (race.size() == 0) { + if (race.empty()) { g_logger().warn("[ProtocolGame::parseBestiarysendCreature] - " "Race was not found: {}, search: {}", raceName, search); @@ -2907,7 +2907,7 @@ void ProtocolGame::parseBestiarysendCreatures(NetworkMessage &msg) { newmsg.add(race.size()); std::map creaturesKilled = g_iobestiary().getBestiaryKillCountByMonsterIDs(player, race); - for (auto it_ : race) { + for (const auto &it_ : race) { uint16_t raceid_ = it_.first; newmsg.add(raceid_); @@ -3982,7 +3982,7 @@ void ProtocolGame::sendBasicData() { // Send total size of spells msg.add(validSpells.size()); // Send each spell valid ids - for (auto spell : validSpells) { + for (const auto &spell : validSpells) { if (!spell) { continue; } @@ -4321,7 +4321,7 @@ void ProtocolGame::sendContainer(uint8_t cid, std::shared_ptr contain msg.addByte(0x00); } else if (container->getID() == ITEM_STORE_INBOX && !itemsStoreInboxToSend.empty()) { msg.addByte(std::min(maxItemsToSend, containerSize)); - for (const auto item : itemsStoreInboxToSend) { + for (const auto &item : itemsStoreInboxToSend) { AddItem(msg, item); } } else { @@ -4449,7 +4449,7 @@ void ProtocolGame::sendShop(std::shared_ptr npc) { msg.add(itemsToSend); uint16_t i = 0; - for (ShopBlock shopBlock : shoplist) { + for (const ShopBlock &shopBlock : shoplist) { if (++i > itemsToSend) { break; } @@ -4557,7 +4557,7 @@ void ProtocolGame::sendSaleItemList(const std::vector &shopVector, co auto msgPosition = msg.getBufferPosition(); msg.skipBytes(1); - for (ShopBlock shopBlock : shopVector) { + for (const ShopBlock &shopBlock : shopVector) { if (shopBlock.itemSellPrice == 0) { continue; } @@ -5687,7 +5687,7 @@ void ProtocolGame::sendTradeItemRequest(const std::string &traderName, std::shar std::shared_ptr container = listContainer.front(); listContainer.pop_front(); - for (std::shared_ptr containerItem : container->getItemList()) { + for (const std::shared_ptr &containerItem : container->getItemList()) { std::shared_ptr tmpContainer = containerItem->getContainer(); if (tmpContainer) { listContainer.push_back(tmpContainer); @@ -5697,7 +5697,7 @@ void ProtocolGame::sendTradeItemRequest(const std::string &traderName, std::shar } msg.addByte(itemList.size()); - for (std::shared_ptr listItem : itemList) { + for (const std::shared_ptr &listItem : itemList) { AddItem(msg, listItem); } } else {