Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
beats-dh committed Mar 24, 2024
1 parent 170a019 commit a5ec922
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 43 deletions.
11 changes: 5 additions & 6 deletions src/io/iobestiary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool IOBestiary::parseCharmCombat(const std::shared_ptr<Charm> charm, std::share

std::shared_ptr<Charm> 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;
}
Expand Down Expand Up @@ -169,7 +169,7 @@ void IOBestiary::setCharmRuneCreature(std::shared_ptr<Player> player, const std:

std::list<charmRune_t> IOBestiary::getCharmUsedRuneBitAll(std::shared_ptr<Player> player) {
int32_t input = player->getUsedRunesBit();
;

int8_t i = 0;
std::list<charmRune_t> rtn;
while (input != 0) {
Expand All @@ -191,7 +191,7 @@ uint16_t IOBestiary::getBestiaryRaceUnlocked(std::shared_ptr<Player> player, Bes
uint16_t count = 0;
std::map<uint16_t, std::string> 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++;
Expand Down Expand Up @@ -271,7 +271,7 @@ int32_t IOBestiary::bitToggle(int32_t input, const std::shared_ptr<Charm> charm,
return CHARM_NONE;
}

int32_t returnToggle = 0;
int32_t returnToggle;
int32_t binary = charm->binary;
if (on) {
returnToggle = input | binary;
Expand Down Expand Up @@ -307,7 +307,7 @@ void IOBestiary::sendBuyCharmRune(std::shared_ptr<Player> player, charmRune_t ru
player->setUnlockedRunesBit(value);
} else if (action == 1) {
std::list<charmRune_t> usedRunes = getCharmUsedRuneBitAll(player);
uint16_t limitRunes = 0;
uint16_t limitRunes;

if (player->isPremium()) {
if (player->hasCharmExpansion()) {
Expand Down Expand Up @@ -343,7 +343,6 @@ void IOBestiary::sendBuyCharmRune(std::shared_ptr<Player> player, charmRune_t ru
player->sendFYIBox("You don't have enough gold.");
}
player->BestiarysendCharms();
return;
}

std::map<uint8_t, int16_t> IOBestiary::getMonsterElements(const std::shared_ptr<MonsterType> mtype) const {
Expand Down
52 changes: 26 additions & 26 deletions src/map/house/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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("");
}
}
Expand All @@ -73,7 +73,7 @@ bool House::tryTransferOwnership(std::shared_ptr<Player> 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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -237,7 +237,7 @@ void House::setAccessList(uint32_t listId, const std::string &textlist) {
}

// kick uninvited players
for (std::shared_ptr<HouseTile> tile : houseTiles) {
for (const std::shared_ptr<HouseTile> &tile : houseTiles) {
if (CreatureVector* creatures = tile->getCreatures()) {
for (int32_t i = creatures->size(); --i >= 0;) {
std::shared_ptr<Player> player = (*creatures)[i]->getPlayer();
Expand Down Expand Up @@ -272,7 +272,7 @@ bool House::transferToDepot(std::shared_ptr<Player> player) const {
if (townId == 0 || !player) {
return false;
}
for (std::shared_ptr<HouseTile> tile : houseTiles) {
for (const std::shared_ptr<HouseTile> &tile : houseTiles) {
if (!transferToDepot(player, tile)) {
return false;
}
Expand Down Expand Up @@ -304,7 +304,7 @@ bool House::transferToDepot(std::shared_ptr<Player> player, std::shared_ptr<Hous

std::unordered_set<std::shared_ptr<Player>> playersToSave = { player };

for (std::shared_ptr<Item> item : moveItemList) {
for (const std::shared_ptr<Item> &item : moveItemList) {
g_logger().debug("[{}] moving item '{}' to depot", __FUNCTION__, item->getName());
auto targetPlayer = player;
if (item->hasOwner() && !item->isOwner(targetPlayer)) {
Expand All @@ -317,7 +317,7 @@ bool House::transferToDepot(std::shared_ptr<Player> player, std::shared_ptr<Hous
}
g_game().internalMoveItem(item->getParent(), 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;
Expand Down Expand Up @@ -379,7 +379,7 @@ void House::handleWrapableItem(ItemList &moveItemList, std::shared_ptr<Item> ite

void House::handleContainer(ItemList &moveItemList, std::shared_ptr<Item> item) const {
if (const auto container = item->getContainer()) {
for (std::shared_ptr<Item> containerItem : container->getItemList()) {
for (const std::shared_ptr<Item> &containerItem : container->getItemList()) {
moveItemList.push_back(containerItem);
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -603,7 +603,7 @@ namespace {
return nullptr;
}

const auto guild = g_game().getGuild(guildId);
auto guild = g_game().getGuild(guildId);
if (guild) {
return guild;
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -669,7 +669,7 @@ void Door::setHouse(std::shared_ptr<House> newHouse) {
return;
}

this->house = newHouse;
this->house = std::move(newHouse);

if (!accessList) {
accessList = std::make_unique<AccessList>();
Expand Down
22 changes: 11 additions & 11 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2309,7 +2309,7 @@ void ProtocolGame::parseBestiarysendMonsterData(NetworkMessage &msg) {

std::vector<LootBlock> 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;

Expand Down Expand Up @@ -2621,7 +2621,7 @@ void ProtocolGame::createLeaderTeamFinder(NetworkMessage &msg) {

auto party = player->getParty();
if (teamAssemble->partyBool && party) {
for (std::shared_ptr<Player> member : party->getMembers()) {
for (const std::shared_ptr<Player> &member : party->getMembers()) {
if (member && member->getGUID() != player->getGUID()) {
teamAssemble->membersMap.insert({ member->getGUID(), 3 });
}
Expand Down Expand Up @@ -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);
Expand All @@ -2907,7 +2907,7 @@ void ProtocolGame::parseBestiarysendCreatures(NetworkMessage &msg) {
newmsg.add<uint16_t>(race.size());
std::map<uint16_t, uint32_t> creaturesKilled = g_iobestiary().getBestiaryKillCountByMonsterIDs(player, race);

for (auto it_ : race) {
for (const auto &it_ : race) {
uint16_t raceid_ = it_.first;
newmsg.add<uint16_t>(raceid_);

Expand Down Expand Up @@ -3982,7 +3982,7 @@ void ProtocolGame::sendBasicData() {
// Send total size of spells
msg.add<uint16_t>(validSpells.size());
// Send each spell valid ids
for (auto spell : validSpells) {
for (const auto &spell : validSpells) {
if (!spell) {
continue;
}
Expand Down Expand Up @@ -4321,7 +4321,7 @@ void ProtocolGame::sendContainer(uint8_t cid, std::shared_ptr<Container> contain
msg.addByte(0x00);
} else if (container->getID() == ITEM_STORE_INBOX && !itemsStoreInboxToSend.empty()) {
msg.addByte(std::min<uint32_t>(maxItemsToSend, containerSize));
for (const auto item : itemsStoreInboxToSend) {
for (const auto &item : itemsStoreInboxToSend) {
AddItem(msg, item);
}
} else {
Expand Down Expand Up @@ -4449,7 +4449,7 @@ void ProtocolGame::sendShop(std::shared_ptr<Npc> npc) {
msg.add<uint16_t>(itemsToSend);

uint16_t i = 0;
for (ShopBlock shopBlock : shoplist) {
for (const ShopBlock &shopBlock : shoplist) {
if (++i > itemsToSend) {
break;
}
Expand Down Expand Up @@ -4557,7 +4557,7 @@ void ProtocolGame::sendSaleItemList(const std::vector<ShopBlock> &shopVector, co
auto msgPosition = msg.getBufferPosition();
msg.skipBytes(1);

for (ShopBlock shopBlock : shopVector) {
for (const ShopBlock &shopBlock : shopVector) {
if (shopBlock.itemSellPrice == 0) {
continue;
}
Expand Down Expand Up @@ -5687,7 +5687,7 @@ void ProtocolGame::sendTradeItemRequest(const std::string &traderName, std::shar
std::shared_ptr<Container> container = listContainer.front();
listContainer.pop_front();

for (std::shared_ptr<Item> containerItem : container->getItemList()) {
for (const std::shared_ptr<Item> &containerItem : container->getItemList()) {
std::shared_ptr<Container> tmpContainer = containerItem->getContainer();
if (tmpContainer) {
listContainer.push_back(tmpContainer);
Expand All @@ -5697,7 +5697,7 @@ void ProtocolGame::sendTradeItemRequest(const std::string &traderName, std::shar
}

msg.addByte(itemList.size());
for (std::shared_ptr<Item> listItem : itemList) {
for (const std::shared_ptr<Item> &listItem : itemList) {
AddItem(msg, listItem);
}
} else {
Expand Down

0 comments on commit a5ec922

Please sign in to comment.