summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2022-08-19 17:34:12 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2022-08-19 17:34:55 +0200
commit2effe9775db423d61d8a2bdd15c40e6015bac6f5 (patch)
treec39246dbbd85c66987dd8c2c071648f2da7eaede /src
parent109b602701578b9f2b29282f84bf2757544f8d32 (diff)
downloadmanaserv-2effe9775db423d61d8a2bdd15c40e6015bac6f5.tar.gz
manaserv-2effe9775db423d61d8a2bdd15c40e6015bac6f5.tar.bz2
manaserv-2effe9775db423d61d8a2bdd15c40e6015bac6f5.tar.xz
manaserv-2effe9775db423d61d8a2bdd15c40e6015bac6f5.zip
Apply C++11 fixits
modernize-loop-convert modernize-deprecated-headers
Diffstat (limited to 'src')
-rw-r--r--src/account-server/account.cpp5
-rw-r--r--src/account-server/account.h2
-rw-r--r--src/account-server/character.cpp11
-rw-r--r--src/account-server/main-account.cpp2
-rw-r--r--src/account-server/serverhandler.cpp54
-rw-r--r--src/account-server/storage.cpp51
-rw-r--r--src/chat-server/chatchannel.cpp23
-rw-r--r--src/chat-server/chatchannelmanager.cpp28
-rw-r--r--src/chat-server/chathandler.cpp33
-rw-r--r--src/chat-server/guild.cpp4
-rw-r--r--src/chat-server/guildhandler.cpp5
-rw-r--r--src/chat-server/guildmanager.cpp18
-rw-r--r--src/common/permissionmanager.cpp1
-rw-r--r--src/dal/recordset.cpp21
-rw-r--r--src/dal/sqlitedataprovider.cpp2
-rw-r--r--src/game-server/abilitymanager.cpp5
-rw-r--r--src/game-server/accountconnection.cpp16
-rw-r--r--src/game-server/attribute.cpp33
-rw-r--r--src/game-server/attributemanager.cpp4
-rw-r--r--src/game-server/being.cpp8
-rw-r--r--src/game-server/being.h6
-rw-r--r--src/game-server/buysell.cpp23
-rw-r--r--src/game-server/charactercomponent.cpp13
-rw-r--r--src/game-server/entity.cpp14
-rw-r--r--src/game-server/gamehandler.cpp15
-rw-r--r--src/game-server/inventory.cpp45
-rw-r--r--src/game-server/itemmanager.cpp11
-rw-r--r--src/game-server/main-game.cpp4
-rw-r--r--src/game-server/map.cpp13
-rw-r--r--src/game-server/map.h4
-rw-r--r--src/game-server/mapcomposite.cpp37
-rw-r--r--src/game-server/mapmanager.cpp4
-rw-r--r--src/game-server/mapreader.cpp7
-rw-r--r--src/game-server/monstermanager.cpp5
-rw-r--r--src/game-server/quest.cpp12
-rw-r--r--src/game-server/state.cpp37
-rw-r--r--src/game-server/statusmanager.cpp5
-rw-r--r--src/game-server/trade.cpp9
-rw-r--r--src/net/connectionhandler.cpp7
-rw-r--r--src/net/messagein.cpp2
-rw-r--r--src/net/messageout.cpp2
-rw-r--r--src/scripting/lua.cpp31
-rw-r--r--src/scripting/luautil.cpp2
-rw-r--r--src/scripting/script.cpp3
-rw-r--r--src/utils/mathutils.cpp6
-rw-r--r--src/utils/sha256.cpp6
-rw-r--r--src/utils/string.cpp4
-rw-r--r--src/utils/stringfilter.cpp7
-rw-r--r--src/utils/timer.cpp2
-rw-r--r--src/utils/timer.h2
-rw-r--r--src/utils/tokencollector.h4
51 files changed, 272 insertions, 396 deletions
diff --git a/src/account-server/account.cpp b/src/account-server/account.cpp
index 6fd86842..11773c47 100644
--- a/src/account-server/account.cpp
+++ b/src/account-server/account.cpp
@@ -24,10 +24,9 @@
Account::~Account()
{
- for (auto i = mCharacters.begin(),
- i_end = mCharacters.end(); i != i_end; ++i)
+ for (auto &character : mCharacters)
{
- delete (*i).second;
+ delete character.second;
}
}
diff --git a/src/account-server/account.h b/src/account-server/account.h
index 175d4bcd..2eb582c2 100644
--- a/src/account-server/account.h
+++ b/src/account-server/account.h
@@ -23,7 +23,7 @@
#include <string>
#include <vector>
-#include <time.h>
+#include <ctime>
#include "account-server/character.h"
diff --git a/src/account-server/character.cpp b/src/account-server/character.cpp
index e22a84e9..c61be1f6 100644
--- a/src/account-server/character.cpp
+++ b/src/account-server/character.cpp
@@ -106,14 +106,13 @@ void CharacterData::serialize(MessageOut &msg)
const EquipData &equipData = poss.getEquipment();
const InventoryData &inventoryData = poss.getInventory();
- for (auto itemIt = inventoryData.begin(),
- itemIt_end = inventoryData.end(); itemIt != itemIt_end; ++itemIt)
+ for (const auto &itemIt : inventoryData)
{
- int slot = itemIt->first;
+ int slot = itemIt.first;
msg.writeInt16(slot);
- msg.writeInt16(itemIt->second.itemId);
- msg.writeInt16(itemIt->second.amount);
- if (equipData.find(itemIt->first) != equipData.end())
+ msg.writeInt16(itemIt.second.itemId);
+ msg.writeInt16(itemIt.second.amount);
+ if (equipData.find(itemIt.first) != equipData.end())
msg.writeInt8(1); // equipped
else
msg.writeInt8(0); // not equipped
diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp
index 9d3a800a..73382f23 100644
--- a/src/account-server/main-account.cpp
+++ b/src/account-server/main-account.cpp
@@ -49,7 +49,7 @@
#include <cstdlib>
#include <getopt.h>
-#include <signal.h>
+#include <csignal>
#include <iostream>
#include <fstream>
#include <physfs.h>
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index 49aa2839..cc53eace 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -129,11 +129,9 @@ void ServerHandler::computerDisconnected(NetComputer *comp)
static GameServer *getGameServerFromMap(int mapId)
{
- for (ServerHandler::NetComputers::const_iterator
- i = serverHandler->clients.begin(),
- i_end = serverHandler->clients.end(); i != i_end; ++i)
+ for (auto client : serverHandler->clients)
{
- auto server = static_cast< GameServer * >(*i);
+ auto server = static_cast< GameServer * >(client);
ServerStatistics::const_iterator it = server->maps.find(mapId);
if (it == server->maps.end()) continue;
return server;
@@ -234,11 +232,10 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
<< " asks for maps to activate.");
const std::map<int, std::string> &maps = MapManager::getMaps();
- for (auto it = maps.begin(),
- it_end = maps.end(); it != it_end; ++it)
+ for (const auto &it : maps)
{
- int id = it->first;
- const std::string &reservedServer = it->second;
+ int id = it.first;
+ const std::string &reservedServer = it.second;
if (reservedServer == server->name)
{
MessageOut outMsg(AGMSG_ACTIVE_MAP);
@@ -267,13 +264,12 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
outMsg.writeInt16(items.size()); //number of floor items
// Send each map item: item_id, amount, pos_x, pos_y
- for (auto i = items.begin();
- i != items.end(); ++i)
+ for (auto &item : items)
{
- outMsg.writeInt32(i->getItemId());
- outMsg.writeInt16(i->getItemAmount());
- outMsg.writeInt16(i->getPosX());
- outMsg.writeInt16(i->getPosY());
+ outMsg.writeInt32(item.getItemId());
+ outMsg.writeInt16(item.getItemAmount());
+ outMsg.writeInt16(item.getPosX());
+ outMsg.writeInt16(item.getPosY());
}
comp->send(outMsg);
@@ -487,10 +483,10 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
result.writeString(letter->getSender()->getName());
result.writeString(letter->getContents());
std::vector<InventoryItem> items = letter->getAttachments();
- for (unsigned j = 0; j < items.size(); ++j)
+ for (auto &item : items)
{
- result.writeInt16(items[j].itemId);
- result.writeInt16(items[j].amount);
+ result.writeInt16(item.itemId);
+ result.writeInt16(item.amount);
}
}
@@ -538,11 +534,11 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
LOG_DEBUG("Creating letter");
auto letter = new Letter(0, sender, receiver);
letter->addText(contents);
- for (unsigned i = 0; i < items.size(); ++i)
+ for (auto &i : items)
{
InventoryItem item;
- item.itemId = items[i].first;
- item.amount = items[i].second;
+ item.itemId = i.first;
+ item.amount = i.second;
letter->addAttachment(item);
}
postalManager->addLetter(letter);
@@ -616,27 +612,23 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
void GameServerHandler::dumpStatistics(std::ostream &os)
{
- for (ServerHandler::NetComputers::const_iterator
- i = serverHandler->clients.begin(),
- i_end = serverHandler->clients.end(); i != i_end; ++i)
+ for (auto client : serverHandler->clients)
{
- auto server = static_cast< GameServer * >(*i);
+ auto server = static_cast< GameServer * >(client);
if (!server->port)
continue;
os << "<gameserver address=\"" << server->address << "\" port=\""
<< server->port << "\">\n";
- for (ServerStatistics::const_iterator j = server->maps.begin(),
- j_end = server->maps.end(); j != j_end; ++j)
+ for (const auto &j : server->maps)
{
- const MapStatistics &m = j->second;
- os << "<map id=\"" << j->first << "\" nb_entities=\"" << m.nbEntities
+ const MapStatistics &m = j.second;
+ os << "<map id=\"" << j.first << "\" nb_entities=\"" << m.nbEntities
<< "\" nb_monsters=\"" << m.nbMonsters << "\">\n";
- for (auto k = m.players.begin(),
- k_end = m.players.end(); k != k_end; ++k)
+ for (int player : m.players)
{
- os << "<character id=\"" << *k << "\"/>\n";
+ os << "<character id=\"" << player << "\"/>\n";
}
os << "</map>\n";
}
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp
index d243b1e7..919238b0 100644
--- a/src/account-server/storage.cpp
+++ b/src/account-server/storage.cpp
@@ -19,7 +19,7 @@
*/
#include <cassert>
-#include <time.h>
+#include <ctime>
#include "account-server/storage.h"
@@ -39,7 +39,7 @@
#include "utils/throwerror.h"
#include "utils/xml.h"
-#include <stdint.h>
+#include <cstdint>
static const char *DEFAULT_ITEM_FILE = "items.xml";
@@ -292,15 +292,14 @@ void Storage::fixCharactersSlot(int accountId)
dal::PerformTransaction transaction(mDb);
// Update the slots in database.
- for (auto i = slotsToUpdate.begin(),
- i_end = slotsToUpdate.end(); i != i_end; ++i)
+ for (auto &i : slotsToUpdate)
{
// Update the character slot.
sql.clear();
sql.str("");
sql << "UPDATE " << CHARACTERS_TBL_NAME
- << " SET slot = " << i->second
- << " where id = " << i->first;
+ << " SET slot = " << i.second
+ << " where id = " << i.first;
mDb->execSql(sql.str());
}
@@ -834,16 +833,15 @@ bool Storage::updateCharacter(CharacterData *character)
const Possessions &poss = character->getPossessions();
const InventoryData &inventoryData = poss.getInventory();
- for (auto itemIt = inventoryData.begin(),
- j_end = inventoryData.end(); itemIt != j_end; ++itemIt)
+ for (const auto &itemIt : inventoryData)
{
sql.str("");
- unsigned short slot = itemIt->first;
- unsigned itemId = itemIt->second.itemId;
- unsigned amount = itemIt->second.amount;
+ unsigned short slot = itemIt.first;
+ unsigned itemId = itemIt.second.itemId;
+ unsigned amount = itemIt.second.amount;
assert(itemId);
sql << base << slot << ", " << itemId << ", " << amount << ", "
- << itemIt->second.equipmentSlot << ");";
+ << itemIt.second.equipmentSlot << ");";
mDb->execSql(sql.str());
}
@@ -968,10 +966,9 @@ void Storage::flush(const Account &account)
const Characters &characters = account.getCharacters();
// Insert or update the characters.
- for (auto it = characters.begin(),
- it_end = characters.end(); it != it_end; ++it)
+ for (auto it : characters)
{
- CharacterData *character = (*it).second;
+ CharacterData *character = it.second;
if (character->getDatabaseID() >= 0)
{
updateCharacter(character);
@@ -1039,10 +1036,9 @@ void Storage::flush(const Account &account)
for (unsigned i = 0; i < charInMemInfo.rows(); ++i) // In database
{
charFound = false;
- for (auto it = characters.begin(),
- it_end = characters.end(); it != it_end; ++it) // In memory
+ for (auto character : characters) // In memory
{
- if (charInMemInfo(i, 0) == (*it).second->getName())
+ if (charInMemInfo(i, 0) == character.second->getName())
{
charFound = true;
break;
@@ -1411,12 +1407,11 @@ std::map<int, Guild*> Storage::getGuildList()
std::stringstream sql;
string_to<short> toShort;
-
// Get the guilds stored in the db.
try
{
sql << "select id, name from " << GUILDS_TBL_NAME << ";";
- const dal::RecordSet& guildInfo = mDb->execSql(sql.str());
+ const dal::RecordSet &guildInfo = mDb->execSql(sql.str());
// Check that at least 1 guild was returned
if (guildInfo.isEmpty())
@@ -1432,30 +1427,28 @@ std::map<int, Guild*> Storage::getGuildList()
string_to< unsigned > toUint;
// Add the members to the guilds.
- for (auto it = guilds.begin();
- it != guilds.end(); ++it)
+ for (auto &guild : guilds)
{
std::ostringstream memberSql;
memberSql << "select member_id, rights from "
<< GUILD_MEMBERS_TBL_NAME
- << " where guild_id = '" << it->second->getId() << "';";
+ << " where guild_id = '" << guild.second->getId() << "';";
const dal::RecordSet& memberInfo = mDb->execSql(memberSql.str());
std::list<std::pair<int, int> > members;
for (unsigned j = 0; j < memberInfo.rows(); ++j)
{
members.push_back(std::pair<int, int>(toUint(memberInfo(j, 0)),
- toUint(memberInfo(j, 1))));
+ toUint(memberInfo(j, 1))));
}
- std::list<std::pair<int, int> >::const_iterator i, i_end;
- for (i = members.begin(), i_end = members.end(); i != i_end; ++i)
+ for (auto i : members)
{
- CharacterData *character = getCharacter((*i).first, nullptr);
+ CharacterData *character = getCharacter(i.first, nullptr);
if (character)
{
- character->addGuild(it->second->getName());
- it->second->addMember(character->getDatabaseID(), (*i).second);
+ character->addGuild(guild.second->getName());
+ guild.second->addMember(character->getDatabaseID(), i.second);
}
}
}
diff --git a/src/chat-server/chatchannel.cpp b/src/chat-server/chatchannel.cpp
index a85be8c8..2673bd18 100644
--- a/src/chat-server/chatchannel.cpp
+++ b/src/chat-server/chatchannel.cpp
@@ -71,23 +71,23 @@ bool ChatChannel::removeUser(ChatClient *user)
{
auto i_end = mRegisteredUsers.end(),
i = std::find(mRegisteredUsers.begin(), i_end, user);
- if (i == i_end) return false;
+ if (i == i_end)
+ return false;
mRegisteredUsers.erase(i);
- std::vector< ChatChannel * > &channels = user->channels;
+ std::vector<ChatChannel *> &channels = user->channels;
channels.erase(std::find(channels.begin(), channels.end(), this));
- std::map<ChatChannel*,std::string> &modes = user->userModes;
+ std::map<ChatChannel*, std::string> &modes = user->userModes;
modes.erase(modes.begin(), modes.end());
return true;
}
void ChatChannel::removeAllUsers()
{
- for (ChannelUsers::const_iterator i = mRegisteredUsers.begin(),
- i_end = mRegisteredUsers.end(); i != i_end; ++i)
+ for (auto registeredUser : mRegisteredUsers)
{
- std::vector< ChatChannel * > &channels = (*i)->channels;
+ std::vector<ChatChannel *> &channels = registeredUser->channels;
channels.erase(std::find(channels.begin(), channels.end(), this));
- std::map<ChatChannel*,std::string> &modes = (*i)->userModes;
+ std::map<ChatChannel*,std::string> &modes = registeredUser->userModes;
modes.erase(modes.begin(), modes.end());
}
mRegisteredUsers.clear();
@@ -114,11 +114,6 @@ void ChatChannel::setUserMode(ChatClient *user, unsigned char mode)
std::string ChatChannel::getUserMode(ChatClient *user) const
{
- std::map<ChatChannel*, std::string>::const_iterator itr =
- user->userModes.find(const_cast<ChatChannel*>(this));
-
- if (itr != user->userModes.end())
- return itr->second;
-
- return nullptr;
+ auto itr = user->userModes.find(const_cast<ChatChannel*>(this));
+ return (itr != user->userModes.end()) ? itr->second : std::string();
}
diff --git a/src/chat-server/chatchannelmanager.cpp b/src/chat-server/chatchannelmanager.cpp
index 62b7b735..61d40de2 100644
--- a/src/chat-server/chatchannelmanager.cpp
+++ b/src/chat-server/chatchannelmanager.cpp
@@ -102,13 +102,11 @@ std::list<const ChatChannel*> ChatChannelManager::getPublicChannels() const
{
std::list<const ChatChannel*> channels;
- for (auto i = mChatChannels.begin(),
- i_end = mChatChannels.end();
- i != i_end; ++i)
+ for (const auto &chatChannel : mChatChannels)
{
- if (i->second.canJoin())
+ if (chatChannel.second.canJoin())
{
- channels.push_back(&i->second);
+ channels.push_back(&chatChannel.second);
}
}
@@ -117,12 +115,10 @@ std::list<const ChatChannel*> ChatChannelManager::getPublicChannels() const
int ChatChannelManager::getChannelId(const std::string &channelName) const
{
- for (auto i = mChatChannels.begin(),
- i_end = mChatChannels.end();
- i != i_end; ++i)
+ for (const auto &chatChannel : mChatChannels)
{
- if (i->second.getName() == channelName)
- return i->first;
+ if (chatChannel.second.getName() == channelName)
+ return chatChannel.first;
}
return 0;
}
@@ -137,11 +133,10 @@ ChatChannel *ChatChannelManager::getChannel(int channelId)
ChatChannel *ChatChannelManager::getChannel(const std::string &name)
{
- for (auto i = mChatChannels.begin();
- i != mChatChannels.end(); ++i)
+ for (auto &chatChannel : mChatChannels)
{
- if (i->second.getName() == name)
- return &(i->second);
+ if (chatChannel.second.getName() == name)
+ return &(chatChannel.second);
}
return nullptr;
@@ -181,10 +176,9 @@ bool ChatChannelManager::channelExists(int channelId) const
bool ChatChannelManager::channelExists(const std::string &channelName) const
{
- for (auto i = mChatChannels.begin();
- i != mChatChannels.end(); ++i)
+ for (const auto &chatChannel : mChatChannels)
{
- if (i->second.getName() == channelName)
+ if (chatChannel.second.getName() == channelName)
return true;
}
return false;
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index a66fb493..a80d8404 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -528,15 +528,11 @@ void ChatHandler::handleListChannelsMessage(ChatClient &client, MessageIn &)
{
MessageOut reply(CPMSG_LIST_CHANNELS_RESPONSE);
- std::list<const ChatChannel*> channels =
- chatChannelManager->getPublicChannels();
-
- for (auto i = channels.begin(),
- i_end = channels.end();
- i != i_end; ++i)
+ const auto channels = chatChannelManager->getPublicChannels();
+ for (auto &channel : channels)
{
- reply.writeString((*i)->getName());
- reply.writeInt16((*i)->getUserList().size());
+ reply.writeString(channel->getName());
+ reply.writeInt16(channel->getUserList().size());
}
client.send(reply);
@@ -560,12 +556,10 @@ void ChatHandler::handleListChannelUsersMessage(ChatClient &client,
{
reply.writeString(channel->getName());
- const ChatChannel::ChannelUsers &users = channel->getUserList();
-
- for (auto i = users.begin(), i_end = users.end(); i != i_end; ++i)
+ for (auto user : channel->getUserList())
{
- reply.writeString((*i)->characterName);
- reply.writeString(channel->getUserMode((*i)));
+ reply.writeString(user->characterName);
+ reply.writeString(channel->getUserMode(user));
}
client.send(reply);
@@ -619,11 +613,10 @@ void ChatHandler::sayToPlayer(ChatClient &computer,
MessageOut result(CPMSG_PRIVMSG);
result.writeString(computer.characterName);
result.writeString(text);
- for (auto i = clients.begin(), i_end = clients.end();
- i != i_end; ++i) {
- if (static_cast< ChatClient * >(*i)->characterName == playerName)
+ for (auto &client : clients) {
+ if (static_cast< ChatClient * >(client)->characterName == playerName)
{
- (*i)->send(result);
+ client->send(result);
break;
}
}
@@ -642,11 +635,9 @@ void ChatHandler::warnUsersAboutPlayerEventInChat(ChatChannel *channel,
void ChatHandler::sendInChannel(ChatChannel *channel, MessageOut &msg)
{
- const ChatChannel::ChannelUsers &users = channel->getUserList();
-
- for (auto i = users.begin(), i_end = users.end(); i != i_end; ++i)
+ for (auto user : channel->getUserList())
{
- (*i)->send(msg);
+ user->send(msg);
}
}
diff --git a/src/chat-server/guild.cpp b/src/chat-server/guild.cpp
index b87860ae..05592ebc 100644
--- a/src/chat-server/guild.cpp
+++ b/src/chat-server/guild.cpp
@@ -54,10 +54,8 @@ void Guild::removeMember(int playerId)
if (getOwner() == playerId)
{
// if the leader is leaving, assign next member as leader
- for (auto it = mMembers.begin(),
- it_end = mMembers.end(); it != it_end; ++it)
+ for (auto member : mMembers)
{
- GuildMember *member = *it;
if (member->mId != playerId)
{
setOwner(member->mId);
diff --git a/src/chat-server/guildhandler.cpp b/src/chat-server/guildhandler.cpp
index 21235f8a..b6870699 100644
--- a/src/chat-server/guildhandler.cpp
+++ b/src/chat-server/guildhandler.cpp
@@ -59,11 +59,8 @@ void ChatHandler::sendGuildRejoin(ChatClient &client)
client.guilds = guilds;
- for (auto it = guilds.begin(),
- it_end = guilds.end(); it != it_end; ++it)
+ for (auto guild : guilds)
{
- Guild *guild = *it;
-
const int permissions = guild->getUserPermissions(client.characterId);
const std::string guildName = guild->getName();
diff --git a/src/chat-server/guildmanager.cpp b/src/chat-server/guildmanager.cpp
index 4b350b2c..c2131ba4 100644
--- a/src/chat-server/guildmanager.cpp
+++ b/src/chat-server/guildmanager.cpp
@@ -36,10 +36,9 @@ GuildManager::GuildManager():
GuildManager::~GuildManager()
{
- for (auto it = mGuilds.begin();
- it != mGuilds.end(); ++it)
+ for (auto &guildIt : mGuilds)
{
- delete it->second;
+ delete guildIt.second;
}
}
@@ -117,11 +116,9 @@ Guild *GuildManager::findById(short id) const
Guild *GuildManager::findByName(const std::string &name) const
{
- for (auto it = mGuilds.begin(),
- it_end = mGuilds.end();
- it != it_end; ++it)
+ for (auto guildIt : mGuilds)
{
- Guild *guild = it->second;
+ Guild *guild = guildIt.second;
if (guild->getName() == name)
return guild;
}
@@ -136,12 +133,11 @@ bool GuildManager::doesExist(const std::string &name) const
std::vector<Guild *> GuildManager::getGuildsForPlayer(int playerId) const
{
std::vector<Guild *> guilds;
- for (auto it = mGuilds.begin();
- it != mGuilds.end(); ++it)
+ for (auto guildIt : mGuilds)
{
- if (it->second->checkInGuild(playerId))
+ if (guildIt.second->checkInGuild(playerId))
{
- guilds.push_back(it->second);
+ guilds.push_back(guildIt.second);
}
}
return guilds;
diff --git a/src/common/permissionmanager.cpp b/src/common/permissionmanager.cpp
index 5281f44d..661c1ae3 100644
--- a/src/common/permissionmanager.cpp
+++ b/src/common/permissionmanager.cpp
@@ -24,7 +24,6 @@
#include "utils/logger.h"
#include "utils/xml.h"
-#include <string.h>
#include <cstring>
static std::map<std::string, unsigned char> permissions;
diff --git a/src/dal/recordset.cpp b/src/dal/recordset.cpp
index 49c245cd..69104933 100644
--- a/src/dal/recordset.cpp
+++ b/src/dal/recordset.cpp
@@ -161,27 +161,16 @@ std::ostream &operator<<(std::ostream &out, const RecordSet &rhs)
// print the field names first.
if (rhs.mHeaders.size() > 0) {
out << "|";
- for (auto it = rhs.mHeaders.begin();
- it != rhs.mHeaders.end();
- ++it)
- {
- out << (*it) << "|";
- }
+ for (const auto &header : rhs.mHeaders)
+ out << header << "|";
out << std::endl << std::endl;
}
// and then print every line.
- for (auto it = rhs.mRows.begin();
- it != rhs.mRows.end();
- ++it)
- {
+ for (const auto &row : rhs.mRows) {
out << "|";
- for (auto it2 = (*it).begin();
- it2 != (*it).end();
- ++it2)
- {
- out << (*it2) << "|";
- }
+ for (const auto &element : row)
+ out << element << "|";
out << std::endl;
}
diff --git a/src/dal/sqlitedataprovider.cpp b/src/dal/sqlitedataprovider.cpp
index 4aa7eca0..787088d1 100644
--- a/src/dal/sqlitedataprovider.cpp
+++ b/src/dal/sqlitedataprovider.cpp
@@ -26,7 +26,7 @@
#include "utils/logger.h"
#include <stdexcept>
-#include <limits.h>
+#include <climits>
// sqlite3_int64 is the preferred new datatype for 64-bit int values.
// see: http://www.sqlite.org/capi3ref.html#sqlite3_int64
diff --git a/src/game-server/abilitymanager.cpp b/src/game-server/abilitymanager.cpp
index 7b5f320c..92da714f 100644
--- a/src/game-server/abilitymanager.cpp
+++ b/src/game-server/abilitymanager.cpp
@@ -94,10 +94,9 @@ void AbilityManager::reload()
void AbilityManager::clear()
{
- for (auto it = mAbilitiesInfo.begin(),
- it_end = mAbilitiesInfo.end(); it != it_end; ++it)
+ for (auto &it : mAbilitiesInfo)
{
- delete it->second;
+ delete it.second;
}
mAbilitiesInfo.clear();
mNamedAbilitiesInfo.clear();
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp
index d1ac613e..6072894e 100644
--- a/src/game-server/accountconnection.cpp
+++ b/src/game-server/accountconnection.cpp
@@ -344,20 +344,17 @@ void AccountConnection::sendStatistics()
{
MessageOut msg(GAMSG_STATISTICS);
const MapManager::Maps &maps = MapManager::getMaps();
- for (auto i = maps.begin(),
- i_end = maps.end(); i != i_end; ++i)
+ for (auto map : maps)
{
- MapComposite *m = i->second;
+ MapComposite *m = map.second;
if (!m->isActive()) continue;
- msg.writeInt16(i->first);
+ msg.writeInt16(map.first);
int nbEntities = 0, nbMonsters = 0;
using Entities = std::vector<Entity *>;
const Entities &things = m->getEverything();
std::vector< int > players;
- for (auto j = things.begin(),
- j_end = things.end(); j != j_end; ++j)
+ for (auto t : things)
{
- Entity *t = *j;
switch (t->getType())
{
case OBJECT_CHARACTER:
@@ -377,10 +374,9 @@ void AccountConnection::sendStatistics()
msg.writeInt16(nbEntities);
msg.writeInt16(nbMonsters);
msg.writeInt16(players.size());
- for (std::vector< int >::const_iterator j = players.begin(),
- j_end = players.end(); j != j_end; ++j)
+ for (int player : players)
{
- msg.writeInt32(*j);
+ msg.writeInt32(player);
}
}
send(msg);
diff --git a/src/game-server/attribute.cpp b/src/game-server/attribute.cpp
index 8390bc76..1f2dbb61 100644
--- a/src/game-server/attribute.cpp
+++ b/src/game-server/attribute.cpp
@@ -188,12 +188,8 @@ void AttributeModifiersEffect::updateMod(double value)
else
{
mMod = 1;
- for (std::list< AttributeModifierState * >::const_iterator
- it = mStates.begin(),
- it_end = mStates.end();
- it != it_end;
- ++it)
- mMod *= (*it)->mValue;
+ for (auto state : mStates)
+ mMod *= state->mValue;
}
}
else LOG_ERROR("Attribute modifiers effect: unhandled type '"
@@ -204,13 +200,9 @@ void AttributeModifiersEffect::updateMod(double value)
if (mMod == value)
{
mMod = 0;
- for (std::list< AttributeModifierState * >::const_iterator
- it = mStates.begin(),
- it_end = mStates.end();
- it != it_end;
- ++it)
- if ((*it)->mValue > mMod)
- mMod = (*it)->mValue;
+ for (auto state : mStates)
+ if (state->mValue > mMod)
+ mMod = state->mValue;
}
}
else
@@ -322,13 +314,13 @@ Attribute::Attribute(const AttributeInfo *info):
const std::vector<AttributeModifier> &modifiers = info->modifiers;
LOG_DEBUG("Construction of new attribute with '" << modifiers.size()
<< "' layers.");
- for (unsigned i = 0; i < modifiers.size(); ++i)
+ for (auto modifier : modifiers)
{
LOG_DEBUG("Adding layer with stackable type "
- << modifiers[i].stackableType
- << " and effect type " << modifiers[i].effectType << ".");
- mMods.push_back(new AttributeModifiersEffect(modifiers[i].stackableType,
- modifiers[i].effectType));
+ << modifier.stackableType
+ << " and effect type " << modifier.effectType << ".");
+ mMods.push_back(new AttributeModifiersEffect(modifier.stackableType,
+ modifier.effectType));
LOG_DEBUG("Layer added.");
}
mBase = checkBounds(mBase);
@@ -366,9 +358,8 @@ bool Attribute::tick()
void Attribute::clearMods()
{
- for (auto it = mMods.begin(),
- it_end = mMods.end(); it != it_end; ++it)
- (*it)->clearMods(mBase);
+ for (auto &mod : mMods)
+ mod->clearMods(mBase);
}
void Attribute::setBase(double base)
diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp
index f54c3a62..758ee30e 100644
--- a/src/game-server/attributemanager.cpp
+++ b/src/game-server/attributemanager.cpp
@@ -44,8 +44,8 @@ void AttributeManager::deinitialize()
delete it.second;
mAttributeMap.clear();
- for (unsigned i = 0; i < MaxScope; ++i)
- mAttributeScopes[i].clear();
+ for (auto &attributeScope : mAttributeScopes)
+ attributeScope.clear();
}
AttributeInfo *AttributeManager::getAttributeInfo(
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index c22b2e1f..238d63e6 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -543,12 +543,10 @@ void BeingComponent::update(Entity &entity)
}
// Update lifetime of effects.
- for (auto it = mAttributes.begin();
- it != mAttributes.end();
- ++it)
+ for (auto &attribute : mAttributes)
{
- if (it->second.tick())
- updateDerivedAttributes(entity, it->first);
+ if (attribute.second.tick())
+ updateDerivedAttributes(entity, attribute.first);
}
// Update and run status effects
diff --git a/src/game-server/being.h b/src/game-server/being.h
index eb03c134..38fd3247 100644
--- a/src/game-server/being.h
+++ b/src/game-server/being.h
@@ -21,11 +21,11 @@
#ifndef BEING_H
#define BEING_H
-#include <string>
-#include <vector>
+#include <climits>
#include <list>
#include <map>
-#include "limits.h"
+#include <string>
+#include <vector>
#include "game-server/actorcomponent.h"
#include "game-server/attribute.h"
diff --git a/src/game-server/buysell.cpp b/src/game-server/buysell.cpp
index 9376a307..86975393 100644
--- a/src/game-server/buysell.cpp
+++ b/src/game-server/buysell.cpp
@@ -80,14 +80,13 @@ int BuySell::registerPlayerItems()
auto *component = mChar->getComponent<CharacterComponent>();
const InventoryData &inventoryData =
component->getPossessions().getInventory();
- for (auto it = inventoryData.begin(),
- it_end = inventoryData.end(); it != it_end; ++it)
+ for (const auto &it : inventoryData)
{
- unsigned amount = it->second.amount;
+ unsigned amount = it.second.amount;
if (!amount)
continue;
- unsigned id = it->second.itemId;
+ unsigned id = it.second.itemId;
int cost = -1;
if (itemManager->getItem(id))
{
@@ -108,13 +107,12 @@ int BuySell::registerPlayerItems()
// We check if the item Id has been already
// added. If so, we cumulate the amounts.
bool itemAlreadyAdded = false;
- for (auto i = mItems.begin(),
- i_end = mItems.end(); i != i_end; ++i)
+ for (auto &item : mItems)
{
- if (i->itemId == id)
+ if (item.itemId == id)
{
itemAlreadyAdded = true;
- i->amount += amount;
+ item.amount += amount;
break;
}
}
@@ -142,12 +140,11 @@ bool BuySell::start(Entity *actor)
MessageOut msg(mSell ? GPMSG_NPC_SELL : GPMSG_NPC_BUY);
msg.writeInt16(actor->getComponent<ActorComponent>()->getPublicID());
- for (TradedItems::const_iterator i = mItems.begin(),
- i_end = mItems.end(); i != i_end; ++i)
+ for (auto item : mItems)
{
- msg.writeInt16(i->itemId);
- msg.writeInt16(i->amount);
- msg.writeInt16(i->cost);
+ msg.writeInt16(item.itemId);
+ msg.writeInt16(item.amount);
+ msg.writeInt16(item.cost);
}
mChar->getComponent<CharacterComponent>()->getClient()->send(msg);
return true;
diff --git a/src/game-server/charactercomponent.cpp b/src/game-server/charactercomponent.cpp
index 0248bbe9..68ecc792 100644
--- a/src/game-server/charactercomponent.cpp
+++ b/src/game-server/charactercomponent.cpp
@@ -41,8 +41,8 @@
#include <algorithm>
#include <cassert>
+#include <climits>
#include <cmath>
-#include <limits.h>
Script::Ref CharacterComponent::mDeathCallback;
Script::Ref CharacterComponent::mDeathAcceptedCallback;
@@ -280,13 +280,12 @@ void CharacterComponent::serialize(Entity &entity, MessageOut &msg)
const Possessions &poss = getPossessions();
const InventoryData &inventoryData = poss.getInventory();
- for (auto itemIt = inventoryData.begin(),
- itemIt_end = inventoryData.end(); itemIt != itemIt_end; ++itemIt)
+ for (const auto &itemIt : inventoryData)
{
- msg.writeInt16(itemIt->first); // slot id
- msg.writeInt16(itemIt->second.itemId);
- msg.writeInt16(itemIt->second.amount);
- msg.writeInt8(itemIt->second.equipmentSlot);
+ msg.writeInt16(itemIt.first); // slot id
+ msg.writeInt16(itemIt.second.itemId);
+ msg.writeInt16(itemIt.second.amount);
+ msg.writeInt8(itemIt.second.equipmentSlot);
}
}
diff --git a/src/game-server/entity.cpp b/src/game-server/entity.cpp
index 15afc29d..791d98c1 100644
--- a/src/game-server/entity.cpp
+++ b/src/game-server/entity.cpp
@@ -28,14 +28,14 @@ Entity::Entity(EntityType type, MapComposite *map) :
mMap(map),
mType(type)
{
- for (int i = 0; i < ComponentTypeCount; ++i)
- mComponents[i] = nullptr;
+ for (auto &component : mComponents)
+ component = nullptr;
}
Entity::~Entity()
{
- for (int i = 0; i < ComponentTypeCount; ++i)
- delete mComponents[i];
+ for (auto &component : mComponents)
+ delete component;
mIdManager.free(mId);
}
@@ -45,7 +45,7 @@ Entity::~Entity()
*/
void Entity::update()
{
- for (int i = 0; i < ComponentTypeCount; ++i)
- if (mComponents[i])
- mComponents[i]->update(*this);
+ for (auto &component : mComponents)
+ if (component)
+ component->update(*this);
}
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index f48ac7f5..01653f2a 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -99,10 +99,9 @@ void GameHandler::prepareServerChange(Entity *ch)
void GameHandler::completeServerChange(int id, const std::string &token,
const std::string &address, int port)
{
- for (NetComputers::const_iterator i = clients.begin(),
- i_end = clients.end(); i != i_end; ++i)
+ for (auto client : clients)
{
- auto c = static_cast< GameClient * >(*i);
+ auto c = static_cast< GameClient * >(client);
if (c->status == CLIENT_CHANGE_SERVER &&
c->character->getComponent<CharacterComponent>()
->getDatabaseID() == id)
@@ -124,10 +123,9 @@ void GameHandler::completeServerChange(int id, const std::string &token,
void GameHandler::updateCharacter(int charid, int partyid)
{
- for (NetComputers::const_iterator i = clients.begin(),
- i_end = clients.end(); i != i_end; ++i)
+ for (auto client : clients)
{
- auto c = static_cast< GameClient * >(*i);
+ auto c = static_cast< GameClient * >(client);
auto *characterComponent =
c->character->getComponent<CharacterComponent>();
@@ -407,10 +405,9 @@ void GameHandler::deletePendingConnect(Entity *character)
Entity *GameHandler::getCharacterByNameSlow(const std::string &name) const
{
- for (auto i = clients.begin(),
- i_end = clients.end(); i != i_end; ++i)
+ for (auto client : clients)
{
- auto c = static_cast< GameClient * >(*i);
+ auto c = static_cast< GameClient * >(client);
Entity *ch = c->character;
if (ch && ch->getComponent<BeingComponent>()->getName() == name &&
c->status == CLIENT_CONNECTED)
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp
index 4b15f4cf..9468001e 100644
--- a/src/game-server/inventory.cpp
+++ b/src/game-server/inventory.cpp
@@ -66,10 +66,9 @@ void Inventory::initialize()
/*
* Set the equipment slots
*/
- for (auto it = mPoss->equipment.begin(),
- it_end = mPoss->equipment.end(); it != it_end; ++it)
+ for (int it : mPoss->equipment)
{
- auto itemIt = mPoss->inventory.find(*it);
+ auto itemIt = mPoss->inventory.find(it);
const ItemEquipRequirement &equipReq = itemManager->getItem(
itemIt->second.itemId)->getItemEquipRequirement();
itemIt->second.equipmentSlot = equipReq.equipSlotId;
@@ -207,11 +206,10 @@ unsigned Inventory::insert(unsigned itemId, unsigned amount)
unsigned Inventory::count(unsigned itemId) const
{
unsigned nb = 0;
- for (auto it = mPoss->inventory.begin(),
- it_end = mPoss->inventory.end(); it != it_end; ++it)
+ for (auto &it : mPoss->inventory)
{
- if (it->second.itemId == itemId)
- nb += it->second.amount;
+ if (it.second.itemId == itemId)
+ nb += it.second.amount;
}
return nb;
@@ -219,10 +217,9 @@ unsigned Inventory::count(unsigned itemId) const
int Inventory::getFirstSlot(unsigned itemId)
{
- for (auto it = mPoss->inventory.begin(),
- it_end = mPoss->inventory.end(); it != it_end; ++it)
- if (it->second.itemId == itemId)
- return (int)it->first;
+ for (auto &it : mPoss->inventory)
+ if (it.second.itemId == itemId)
+ return (int)it.first;
return -1;
}
@@ -304,12 +301,10 @@ unsigned Inventory::removeFromSlot(unsigned slot, unsigned amount)
MessageOut invMsg(GPMSG_INVENTORY);
// Check if an item of the same id exists elsewhere in the inventory
bool exists = false;
- for (InventoryData::const_iterator it2 = mPoss->inventory.begin(),
- it2_end = mPoss->inventory.end();
- it2 != it2_end; ++it2)
+ for (const auto &it2 : mPoss->inventory)
{
- if (it2->second.itemId == it->second.itemId
- && it->first != it2->first)
+ if (it2.second.itemId == it->second.itemId
+ && it->first != it2.first)
{
exists = true;
break;
@@ -382,10 +377,9 @@ bool Inventory::checkEquipmentCapacity(unsigned equipmentSlot,
return false;
// Test whether the slot capacity requested is reached.
- for (auto it = mPoss->equipment.begin(),
- it_end = mPoss->equipment.end(); it != it_end; ++it)
+ for (int it : mPoss->equipment)
{
- auto itemIt = mPoss->inventory.find(*it);
+ auto itemIt = mPoss->inventory.find(it);
if (itemIt->second.equipmentSlot == equipmentSlot)
{
const int itemId = itemIt->second.itemId;
@@ -460,10 +454,8 @@ bool Inventory::equip(int inventorySlot)
&& hasInventoryEnoughSpace(equipReq.equipSlotId))
{
// Then, we unequip each iteminstance of the equip slot
- for (auto it = mPoss->equipment.begin(),
- it_end = mPoss->equipment.end(); it != it_end; ++it)
+ for (unsigned int slot : mPoss->equipment)
{
- const unsigned slot = *it;
auto itemIt = mPoss->inventory.find(slot);
assert(itemIt != mPoss->inventory.end());
if (itemIt->second.equipmentSlot == equipReq.equipSlotId) {
@@ -481,18 +473,15 @@ bool Inventory::equip(int inventorySlot)
}
// Potential Pre-unequipment process
- for (auto itemsToUnequip =
- slotsToUnequipFirst.begin(),
- itemsToUnequip_end = slotsToUnequipFirst.end();
- itemsToUnequip != itemsToUnequip_end; ++itemsToUnequip)
+ for (unsigned int itemsToUnequip : slotsToUnequipFirst)
{
- if (!unequip(*itemsToUnequip))
+ if (!unequip(itemsToUnequip))
{
// Something went wrong even when we tested the unequipment process.
LOG_WARN("Unable to unequip even when unequip was tested. "
"Character : "
<< mCharacter->getComponent<BeingComponent>()->getName()
- << ", unequip slot: " << *itemsToUnequip);
+ << ", unequip slot: " << itemsToUnequip);
return false;
}
}
diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp
index 8a8f2092..9884458e 100644
--- a/src/game-server/itemmanager.cpp
+++ b/src/game-server/itemmanager.cpp
@@ -45,17 +45,14 @@ void ItemManager::initialize()
void ItemManager::deinitialize()
{
- for (auto i = mItemClasses.begin(),
- i_end = mItemClasses.end(); i != i_end; ++i)
+ for (auto &itemClass : mItemClasses)
{
- delete i->second;
+ delete itemClass.second;
}
- for (auto it =
- mEquipSlotsInfo.begin(), it_end = mEquipSlotsInfo.end(); it != it_end;
- ++it)
+ for (auto &it : mEquipSlotsInfo)
{
- delete it->second;
+ delete it.second;
}
mItemClasses.clear();
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index 970474cd..ed8e6677 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -45,12 +45,12 @@
#include "utils/timer.h"
#include "utils/mathutils.h"
+#include <csignal>
#include <cstdlib>
+#include <enet/enet.h>
#include <getopt.h>
#include <iostream>
-#include <signal.h>
#include <physfs.h>
-#include <enet/enet.h>
#include <unistd.h>
#ifdef __MINGW32__
diff --git a/src/game-server/map.cpp b/src/game-server/map.cpp
index 0f7fea60..ad68b13e 100644
--- a/src/game-server/map.cpp
+++ b/src/game-server/map.cpp
@@ -19,10 +19,10 @@
*/
#include <algorithm>
-#include <queue>
#include <cassert>
+#include <climits>
#include <cstring>
-#include <limits.h>
+#include <queue>
#include "game-server/map.h"
@@ -109,10 +109,9 @@ Map::Map(int width, int height, int tileWidth, int tileHeight):
Map::~Map()
{
- for (auto it = mMapObjects.begin();
- it != mMapObjects.end(); ++it)
+ for (auto mapObject : mMapObjects)
{
- delete *it;
+ delete mapObject;
}
}
@@ -394,8 +393,8 @@ void FindPath::prepare(const Map *map)
// Reset closed and open list IDs and clear the whichList values
mOnClosedList = 1;
mOnOpenList = 2;
- for (unsigned i = 0, end = mPathInfos.size(); i < end; ++i)
- mPathInfos[i].whichList = 0;
+ for (auto &pathInfo : mPathInfos)
+ pathInfo.whichList = 0;
}
// Make sure we have enough room to cover this map with path information
diff --git a/src/game-server/map.h b/src/game-server/map.h
index 715843d3..db63de00 100644
--- a/src/game-server/map.h
+++ b/src/game-server/map.h
@@ -52,8 +52,8 @@ class MetaTile
MetaTile()
: blockmask(0)
{
- for (unsigned i = 0; i < NB_BLOCKTYPES; ++i)
- occupation[i] = 0;
+ for (unsigned int &i : occupation)
+ i = 0;
}
unsigned occupation[NB_BLOCKTYPES];
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp
index 0b0773b6..d9df83cd 100644
--- a/src/game-server/mapcomposite.cpp
+++ b/src/game-server/mapcomposite.cpp
@@ -64,10 +64,10 @@ struct ObjectBucket
ObjectBucket::ObjectBucket()
: free(256), next_object(0)
{
- for (unsigned i = 0; i < 256 / int_bitsize; ++i)
+ for (unsigned int &i : bitmap)
{
// An occupied ID is represented by zero in the bitmap.
- bitmap[i] = ~0u;
+ i = ~0u;
}
}
@@ -305,7 +305,7 @@ struct MapContent
/**
* Entities (items, characters, monsters, etc) located on the map.
*/
- std::vector< Entity * > entities;
+ std::vector<Entity *> entities;
/**
* Buckets of MovingObjects located on the map, referenced by ID.
@@ -341,9 +341,9 @@ MapContent::MapContent(Map *map)
MapContent::~MapContent()
{
- for (int i = 0; i < 256; ++i)
+ for (auto &bucket : buckets)
{
- delete buckets[i];
+ delete bucket;
}
delete[] zones;
}
@@ -680,13 +680,13 @@ ZoneIterator MapComposite::getAroundBeingIterator(Entity *obj, int radius) const
obj->getComponent<BeingComponent>()->getOldPosition(),
radius);
MapRegion r2 = r1;
- for (auto i = r1.begin(), i_end = r1.end(); i != i_end; ++i)
+ for (unsigned int &i : r1)
{
/* Fills region with destinations taken around the old position.
This is necessary to detect two moving objects changing zones at the
same time and at the border, and going in opposite directions (or
more simply to detect teleportations, if any). */
- MapRegion &r4 = mContent->zones[*i].destinations;
+ MapRegion &r4 = mContent->zones[i].destinations;
if (!r4.empty())
{
MapRegion r3;
@@ -752,11 +752,8 @@ void MapComposite::update()
{
// Update object status
const std::vector< Entity * > &entities = getEverything();
- for (auto it = entities.begin(),
- it_end = entities.end(); it != it_end; ++it)
- {
- (*it)->update();
- }
+ for (auto entity : entities)
+ entity->update();
if (mUpdateCallback.isValid())
{
@@ -778,24 +775,23 @@ void MapComposite::update()
}
// Cannot use a WholeMap iterator as objects will change zones under its feet.
- for (auto i = mContent->entities.begin(),
- i_end = mContent->entities.end(); i != i_end; ++i)
+ for (auto &entity : mContent->entities)
{
- if (!(*i)->canMove())
+ if (!entity->canMove())
continue;
const Point &pos1 =
- (*i)->getComponent<BeingComponent>()->getOldPosition();
+ entity->getComponent<BeingComponent>()->getOldPosition();
const Point &pos2 =
- (*i)->getComponent<ActorComponent>()->getPosition();
+ entity->getComponent<ActorComponent>()->getPosition();
MapZone &src = mContent->getZone(pos1),
&dst = mContent->getZone(pos2);
if (&src != &dst)
{
addZone(src.destinations, &dst - mContent->zones);
- src.remove(*i);
- dst.insert(*i);
+ src.remove(entity);
+ dst.insert(entity);
}
}
}
@@ -892,9 +888,8 @@ void MapComposite::initializeContent()
const std::vector<MapObject *> &objects = mMap->getObjects();
- for (size_t i = 0; i < objects.size(); ++i)
+ for (auto object : objects)
{
- const MapObject *object = objects.at(i);
const std::string &type = object->getType();
if (utils::compareStrI(type, "WARP") == 0)
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp
index 17ddd2f8..2857fd8b 100644
--- a/src/game-server/mapmanager.cpp
+++ b/src/game-server/mapmanager.cpp
@@ -49,9 +49,9 @@ void MapManager::initialize()
*/
void MapManager::deinitialize()
{
- for (auto i = maps.begin(), i_end = maps.end(); i != i_end; ++i)
+ for (auto &map : maps)
{
- delete i->second;
+ delete map.second;
}
maps.clear();
}
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index 91f481d6..cbb1eb90 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -346,13 +346,12 @@ void MapReader::setTileWithGid(Map *map, int x, int y, unsigned gid)
// Find the tileset with the highest firstGid below/eq to gid
unsigned set = gid;
- for (std::vector<unsigned>::const_iterator i = ::tilesetFirstGids.begin(),
- i_end = ::tilesetFirstGids.end(); i != i_end; ++i)
+ for (unsigned int tilesetFirstGid : ::tilesetFirstGids)
{
- if (gid < *i)
+ if (gid < tilesetFirstGid)
break;
- set = *i;
+ set = tilesetFirstGid;
}
if (gid != set)
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index 4f0ba519..d8cc836a 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -44,10 +44,9 @@ void MonsterManager::initialize()
void MonsterManager::deinitialize()
{
- for (auto i = mMonsterClasses.begin(),
- i_end = mMonsterClasses.end(); i != i_end; ++i)
+ for (auto &monsterClass : mMonsterClasses)
{
- delete i->second;
+ delete monsterClass.second;
}
mMonsterClasses.clear();
mMonsterClassesByName.clear();
diff --git a/src/game-server/quest.cpp b/src/game-server/quest.cpp
index 3a049eaa..444c8140 100644
--- a/src/game-server/quest.cpp
+++ b/src/game-server/quest.cpp
@@ -96,10 +96,9 @@ static void partialRemove(Entity *t)
int id = t->getComponent<CharacterComponent>()->getDatabaseID();
PendingVariables &variables = pendingQuests[id].variables;
// Remove all the callbacks, but do not remove the variable names.
- for (auto i = variables.begin(),
- i_end = variables.end(); i != i_end; ++i)
+ for (auto &variable : variables)
{
- i->second.clear();
+ variable.second.clear();
}
// The listener is kept in case a fullRemove is needed later.
}
@@ -174,11 +173,10 @@ void recoveredQuestVar(int id,
characterComponent->questCache[name] = value;
// Call the registered callbacks.
- for (QuestCallbacks::const_iterator k = j->second.begin(),
- k_end = j->second.end(); k != k_end; ++k)
+ for (auto k : j->second)
{
- (*k)->triggerCallback(ch, value);
- delete (*k);
+ k->triggerCallback(ch, value);
+ delete k;
}
variables.erase(j);
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index c6775e03..6fa84901 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -94,10 +94,9 @@ static void serializeLooks(Entity *ch, MessageOut &msg)
// Note that we can send several updates on the same slot type as different
// items may have been equipped.
- for (auto it = equipData.begin(),
- it_end = equipData.end(); it != it_end; ++it)
+ for (int it : equipData)
{
- auto itemIt = inventoryData.find(*it);
+ auto itemIt = inventoryData.find(it);
if (!itemManager->isEquipSlotVisible(itemIt->second.equipmentSlot))
continue;
@@ -112,12 +111,10 @@ static void serializeLooks(Entity *ch, MessageOut &msg)
// Number of look changes to send
msg.writeInt8(lookChanges.size());
- for (std::map<unsigned, unsigned>::const_iterator it =
- lookChanges.begin(), it_end = lookChanges.end();
- it != it_end; ++it)
+ for (auto lookChange : lookChanges)
{
- msg.writeInt8(it->first);
- msg.writeInt16(it->second);
+ msg.writeInt8(lookChange.first);
+ msg.writeInt16(lookChange.second);
}
}
}
@@ -245,11 +242,10 @@ static void informPlayer(MapComposite *map, Entity *p)
{
auto *beingComponent = o->getComponent<BeingComponent>();
const Hits &hits = beingComponent->getHitsTaken();
- for (auto j = hits.begin(),
- j_end = hits.end(); j != j_end; ++j)
+ for (unsigned int hit : hits)
{
damageMsg.writeInt16(oid);
- damageMsg.writeInt16(*j);
+ damageMsg.writeInt16(hit);
}
}
@@ -482,10 +478,9 @@ void GameState::update(int tick)
// Update game state (update AI, etc.)
const MapManager::Maps &maps = MapManager::getMaps();
- for (auto m = maps.begin(),
- m_end = maps.end(); m != m_end; ++m)
+ for (auto m : maps)
{
- MapComposite *map = m->second;
+ MapComposite *map = m.second;
if (!map->isActive())
continue;
@@ -512,11 +507,10 @@ void GameState::update(int tick)
# endif
// Take care of events that were delayed because of their side effects.
- for (auto it = delayedEvents.begin(),
- it_end = delayedEvents.end(); it != it_end; ++it)
+ for (auto &delayedEvent : delayedEvents)
{
- const DelayedEvent &e = it->second;
- Entity *o = it->first;
+ const DelayedEvent &e = delayedEvent.second;
+ Entity *o = delayedEvent.first;
switch (e.type)
{
case EVENT_REMOVE:
@@ -913,9 +907,6 @@ void GameState::callVariableCallbacks(const std::string &key,
const std::string &value)
{
const MapManager::Maps &maps = MapManager::getMaps();
- for (auto m = maps.begin(),
- m_end = maps.end(); m != m_end; ++m)
- {
- m->second->callWorldVariableCallback(key, value);
- }
+ for (auto map : maps)
+ map.second->callWorldVariableCallback(key, value);
}
diff --git a/src/game-server/statusmanager.cpp b/src/game-server/statusmanager.cpp
index 830291a9..2131257b 100644
--- a/src/game-server/statusmanager.cpp
+++ b/src/game-server/statusmanager.cpp
@@ -45,10 +45,9 @@ void StatusManager::reload()
void StatusManager::deinitialize()
{
- for (auto i = statusEffects.begin(),
- i_end = statusEffects.end(); i != i_end; ++i)
+ for (auto &statusEffect : statusEffects)
{
- delete i->second;
+ delete statusEffect.second;
}
statusEffects.clear();
statusEffectsByName.clear();
diff --git a/src/game-server/trade.cpp b/src/game-server/trade.cpp
index 57bc04e6..a7cf7153 100644
--- a/src/game-server/trade.cpp
+++ b/src/game-server/trade.cpp
@@ -92,12 +92,11 @@ bool Trade::request(Entity *c, int id)
bool Trade::perform(TradedItems items, Inventory &inv1, Inventory &inv2)
{
- for (TradedItems::const_iterator i = items.begin(),
- i_end = items.end(); i != i_end; ++i)
+ for (auto item : items)
{
- if (i->id != inv1.getItem(i->slot) ||
- inv1.removeFromSlot(i->slot, i->amount) != 0 ||
- inv2.insert(i->id, i->amount) != 0)
+ if (item.id != inv1.getItem(item.slot) ||
+ inv1.removeFromSlot(item.slot, item.amount) != 0 ||
+ inv2.insert(item.id, item.amount) != 0)
{
return false;
}
diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp
index 1cdae2f3..4edb1fd2 100644
--- a/src/net/connectionhandler.cpp
+++ b/src/net/connectionhandler.cpp
@@ -153,11 +153,8 @@ void ConnectionHandler::process(enet_uint32 timeout)
void ConnectionHandler::sendToEveryone(const MessageOut &msg)
{
- for (auto i = clients.begin(), i_end = clients.end();
- i != i_end; ++i)
- {
- (*i)->send(msg);
- }
+ for (auto &client : clients)
+ client->send(msg);
}
unsigned ConnectionHandler::getClientCount() const
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index 9d206de5..8d89ad46 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -27,7 +27,7 @@
#ifndef USE_NATIVE_DOUBLE
#include <sstream>
#endif
-#include <stdint.h>
+#include <cstdint>
#include "net/messagein.h"
#include "utils/logger.h"
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index af305a6e..85ee7962 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -28,7 +28,7 @@
#include <limits>
#include <sstream>
#endif
-#include <stdint.h>
+#include <cstdint>
#include <string>
#include <enet/enet.h>
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index a724e9d2..8b92ecd4 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -52,8 +52,8 @@
#include "utils/logger.h"
#include "utils/speedconv.h"
-#include <string.h>
-#include <math.h>
+#include <cstring>
+#include <cmath>
/*
* This file includes all script bindings available to LUA scripts.
@@ -1018,10 +1018,9 @@ static int entity_get_inventory(lua_State *s)
int firstTableStackPosition = lua_gettop(s);
int tableIndex = 1;
- for (auto it = invData.begin(),
- it_end = invData.end(); it != it_end; ++it)
+ for (const auto &it : invData)
{
- if (!it->second.itemId || !it->second.amount)
+ if (!it.second.itemId || !it.second.amount)
continue;
// Create the sub-table (value of the main one)
@@ -1029,23 +1028,23 @@ static int entity_get_inventory(lua_State *s)
int subTableStackPosition = lua_gettop(s);
// Stores the item info in it.
lua_pushliteral(s, "slot");
- lua_pushinteger(s, it->first); // The slot id
+ lua_pushinteger(s, it.first); // The slot id
lua_settable(s, subTableStackPosition);
lua_pushliteral(s, "id");
- lua_pushinteger(s, it->second.itemId);
+ lua_pushinteger(s, it.second.itemId);
lua_settable(s, subTableStackPosition);
lua_pushliteral(s, "name");
- push(s, itemManager->getItem(it->second.itemId)->getName());
+ push(s, itemManager->getItem(it.second.itemId)->getName());
lua_settable(s, subTableStackPosition);
lua_pushliteral(s, "amount");
- lua_pushinteger(s, it->second.amount);
+ lua_pushinteger(s, it.second.amount);
lua_settable(s, subTableStackPosition);
lua_pushliteral(s, "equipped");
- lua_pushboolean(s, it->second.equipmentSlot != 0);
+ lua_pushboolean(s, it.second.equipmentSlot != 0);
lua_settable(s, subTableStackPosition);
// Add the sub-table as value of the main one.
@@ -1092,10 +1091,9 @@ static int entity_get_equipment(lua_State *s)
int firstTableStackPosition = lua_gettop(s);
int tableIndex = 1;
- for (auto it = equipData.begin(),
- it_end = equipData.end(); it != it_end; ++it)
+ for (int it : equipData)
{
- auto itemIt = inventoryData.find(*it);
+ auto itemIt = inventoryData.find(it);
const InventoryItem &item = itemIt->second;
// Create the sub-table (value of the main one)
@@ -3155,12 +3153,11 @@ static int map_get_objects(lua_State *s)
else
{
std::vector<MapObject*> filteredObjects;
- for (auto it = objects.begin();
- it != objects.end(); ++it)
+ for (auto object : objects)
{
- if (utils::compareStrI((*it)->getType(), filter) == 0)
+ if (utils::compareStrI(object->getType(), filter) == 0)
{
- filteredObjects.push_back(*it);
+ filteredObjects.push_back(object);
}
}
pushSTLContainer<MapObject*>(s, filteredObjects);
diff --git a/src/scripting/luautil.cpp b/src/scripting/luautil.cpp
index b9a668bf..c737aad9 100644
--- a/src/scripting/luautil.cpp
+++ b/src/scripting/luautil.cpp
@@ -21,7 +21,7 @@
#include "luautil.h"
-#include <string.h>
+#include <cstring>
#include "game-server/charactercomponent.h"
#include "game-server/itemmanager.h"
diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp
index 638ccb17..e71a6c92 100644
--- a/src/scripting/script.cpp
+++ b/src/scripting/script.cpp
@@ -27,10 +27,9 @@
#include <cassert>
#include <cstdlib>
+#include <cstring>
#include <map>
-#include <string.h>
-
using Engines = std::map<std::string, Script::Factory>;
static Engines *engines = nullptr;
diff --git a/src/utils/mathutils.cpp b/src/utils/mathutils.cpp
index a11538e5..cc87ec0b 100644
--- a/src/utils/mathutils.cpp
+++ b/src/utils/mathutils.cpp
@@ -20,10 +20,10 @@
#include "mathutils.h"
+#include <cfloat>
#include <cmath>
-#include <stdint.h>
-#include <string.h>
-#include <float.h>
+#include <cstdint>
+#include <cstring>
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp
index f9ea3fa1..25117e4d 100644
--- a/src/utils/sha256.cpp
+++ b/src/utils/sha256.cpp
@@ -264,10 +264,10 @@ std::string SHA256Hash(const char *src, int len)
// Convert it to hex
const char* hxc = "0123456789abcdef";
std::string hash;
- for (int i = 0; i < SHA256_DIGEST_SIZE; i++)
+ for (unsigned char i : bytehash)
{
- hash += hxc[bytehash[i] / 16];
- hash += hxc[bytehash[i] % 16];
+ hash += hxc[i / 16];
+ hash += hxc[i % 16];
}
return hash;
}
diff --git a/src/utils/string.cpp b/src/utils/string.cpp
index fdc5eb59..028bd7c2 100644
--- a/src/utils/string.cpp
+++ b/src/utils/string.cpp
@@ -40,9 +40,9 @@ std::string toLower(std::string s)
bool isNumeric(const std::string &s)
{
- for (unsigned i = 0; i < s.size(); ++i)
+ for (char i : s)
{
- if (!isdigit(s[i]))
+ if (!isdigit(i))
{
return false;
}
diff --git a/src/utils/stringfilter.cpp b/src/utils/stringfilter.cpp
index 8c417ed0..381a0c43 100644
--- a/src/utils/stringfilter.cpp
+++ b/src/utils/stringfilter.cpp
@@ -80,14 +80,13 @@ bool StringFilter::filterContent(const std::string &text) const
std::string upperCaseText = text;
std::transform(text.begin(), text.end(), upperCaseText.begin(),
- (int(*)(int))std::toupper);
+ (int(*)(int))std::toupper);
- for (auto i = mSlangs.begin(); i != mSlangs.end(); ++i)
+ for (auto upperCaseSlang : mSlangs)
{
// We look for slangs into the sentence.
- std::string upperCaseSlang = *i;
std::transform(upperCaseSlang.begin(), upperCaseSlang.end(),
- upperCaseSlang.begin(), (int(*)(int))std::toupper);
+ upperCaseSlang.begin(), (int(*)(int))std::toupper);
if (upperCaseText.compare(upperCaseSlang)) {
isContentClean = false;
diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp
index 3d1e0e6d..7da2d45c 100644
--- a/src/utils/timer.cpp
+++ b/src/utils/timer.cpp
@@ -20,7 +20,7 @@
#include "timer.h"
-#include <time.h>
+#include <ctime>
#include <sys/time.h>
#ifdef _WIN32
diff --git a/src/utils/timer.h b/src/utils/timer.h
index 2fb9e7b1..a505338d 100644
--- a/src/utils/timer.h
+++ b/src/utils/timer.h
@@ -25,7 +25,7 @@
#ifdef _MSC_VER
typedef __uint64 uint64_t // when using MSVC use its internal type
#else
- #include <stdint.h> // on other compilers use the C99 official header
+ #include <cstdint> // on other compilers use the C++11 official header
#endif
namespace utils
diff --git a/src/utils/tokencollector.h b/src/utils/tokencollector.h
index 64977d26..8c4c72ca 100644
--- a/src/utils/tokencollector.h
+++ b/src/utils/tokencollector.h
@@ -21,10 +21,10 @@
#ifndef TOKENCOLLECTOR_H
#define TOKENCOLLECTOR_H
-#include <stdint.h>
+#include <cstdint>
#include <string>
#include <list>
-#include <time.h>
+#include <ctime>
/**
* Base class containing the generic implementation of TokenCollector.