summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2022-08-19 16:55:29 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2022-08-19 17:34:55 +0200
commit109b602701578b9f2b29282f84bf2757544f8d32 (patch)
treea2fd70556c86385a75bfb7651e865beb0a05fd37
parent6c6090991e17276de09f5f82d2fc8a6c1adf5bf4 (diff)
downloadmanaserv-109b602701578b9f2b29282f84bf2757544f8d32.tar.gz
manaserv-109b602701578b9f2b29282f84bf2757544f8d32.tar.bz2
manaserv-109b602701578b9f2b29282f84bf2757544f8d32.tar.xz
manaserv-109b602701578b9f2b29282f84bf2757544f8d32.zip
Apply C++11 fixits
modernize-use-auto modernize-use-nullptr modernize-use-override modernize-use-using
-rw-r--r--src/account-server/account.cpp8
-rw-r--r--src/account-server/account.h2
-rw-r--r--src/account-server/accounthandler.cpp12
-rw-r--r--src/account-server/character.cpp2
-rw-r--r--src/account-server/character.h4
-rw-r--r--src/account-server/main-account.cpp10
-rw-r--r--src/account-server/serverhandler.cpp26
-rw-r--r--src/account-server/storage.cpp59
-rw-r--r--src/chat-server/chatchannel.cpp8
-rw-r--r--src/chat-server/chatchannel.h2
-rw-r--r--src/chat-server/chatchannelmanager.cpp18
-rw-r--r--src/chat-server/chatchannelmanager.h2
-rw-r--r--src/chat-server/chatclient.h2
-rw-r--r--src/chat-server/chathandler.cpp31
-rw-r--r--src/chat-server/chathandler.h6
-rw-r--r--src/chat-server/guild.cpp15
-rw-r--r--src/chat-server/guildhandler.cpp4
-rw-r--r--src/chat-server/guildmanager.cpp18
-rw-r--r--src/chat-server/guildmanager.h2
-rw-r--r--src/chat-server/party.cpp2
-rw-r--r--src/chat-server/party.h2
-rw-r--r--src/chat-server/partyhandler.cpp2
-rw-r--r--src/chat-server/post.cpp13
-rw-r--r--src/common/configuration.cpp6
-rw-r--r--src/common/defines.h4
-rw-r--r--src/common/inventorydata.h4
-rw-r--r--src/common/permissionmanager.cpp10
-rw-r--r--src/common/resourcemanager.cpp2
-rw-r--r--src/dal/dalexcept.h6
-rw-r--r--src/dal/dataprovider.h4
-rw-r--r--src/dal/dataproviderfactory.cpp10
-rw-r--r--src/dal/recordset.cpp10
-rw-r--r--src/dal/recordset.h4
-rw-r--r--src/dal/sqlitedataprovider.cpp8
-rw-r--r--src/dal/sqlitedataprovider.h30
-rw-r--r--src/game-server/abilitycomponent.cpp12
-rw-r--r--src/game-server/abilitycomponent.h4
-rw-r--r--src/game-server/abilitymanager.cpp12
-rw-r--r--src/game-server/abilitymanager.h4
-rw-r--r--src/game-server/accountconnection.cpp10
-rw-r--r--src/game-server/accountconnection.h4
-rw-r--r--src/game-server/actorcomponent.h2
-rw-r--r--src/game-server/attribute.cpp10
-rw-r--r--src/game-server/attributemanager.cpp8
-rw-r--r--src/game-server/being.cpp18
-rw-r--r--src/game-server/being.h8
-rw-r--r--src/game-server/buysell.cpp6
-rw-r--r--src/game-server/buysell.h2
-rw-r--r--src/game-server/charactercomponent.cpp12
-rw-r--r--src/game-server/charactercomponent.h4
-rw-r--r--src/game-server/commandhandler.cpp2
-rw-r--r--src/game-server/effect.cpp6
-rw-r--r--src/game-server/effect.h4
-rw-r--r--src/game-server/emotemanager.cpp4
-rw-r--r--src/game-server/gamehandler.cpp32
-rw-r--r--src/game-server/gamehandler.h6
-rw-r--r--src/game-server/inventory.cpp32
-rw-r--r--src/game-server/item.cpp10
-rw-r--r--src/game-server/item.h16
-rw-r--r--src/game-server/itemmanager.cpp25
-rw-r--r--src/game-server/itemmanager.h6
-rw-r--r--src/game-server/main-game.cpp30
-rw-r--r--src/game-server/map.cpp2
-rw-r--r--src/game-server/map.h2
-rw-r--r--src/game-server/mapcomposite.cpp35
-rw-r--r--src/game-server/mapcomposite.h2
-rw-r--r--src/game-server/mapmanager.cpp4
-rw-r--r--src/game-server/mapmanager.h2
-rw-r--r--src/game-server/mapreader.cpp14
-rw-r--r--src/game-server/monster.cpp2
-rw-r--r--src/game-server/monster.h6
-rw-r--r--src/game-server/monstermanager.cpp10
-rw-r--r--src/game-server/monstermanager.h2
-rw-r--r--src/game-server/npc.cpp4
-rw-r--r--src/game-server/npc.h4
-rw-r--r--src/game-server/quest.cpp20
-rw-r--r--src/game-server/quest.h8
-rw-r--r--src/game-server/spawnareacomponent.cpp4
-rw-r--r--src/game-server/spawnareacomponent.h2
-rw-r--r--src/game-server/state.cpp35
-rw-r--r--src/game-server/statusmanager.cpp6
-rw-r--r--src/game-server/trade.h2
-rw-r--r--src/game-server/triggerareacomponent.cpp2
-rw-r--r--src/game-server/triggerareacomponent.h8
-rw-r--r--src/net/bandwidth.cpp4
-rw-r--r--src/net/bandwidth.h2
-rw-r--r--src/net/connectionhandler.cpp10
-rw-r--r--src/net/connectionhandler.h2
-rw-r--r--src/net/messagein.cpp2
-rw-r--r--src/scripting/lua.cpp34
-rw-r--r--src/scripting/luascript.cpp4
-rw-r--r--src/scripting/luascript.h34
-rw-r--r--src/scripting/luautil.cpp6
-rw-r--r--src/scripting/luautil.h18
-rw-r--r--src/scripting/script.cpp6
-rw-r--r--src/scripting/script.h8
-rw-r--r--src/scripting/scriptmanager.cpp2
-rw-r--r--src/utils/base64.cpp2
-rw-r--r--src/utils/processorutils.cpp2
-rw-r--r--src/utils/sha256.cpp4
-rw-r--r--src/utils/string.h2
-rw-r--r--src/utils/stringfilter.cpp4
-rw-r--r--src/utils/stringfilter.h4
-rw-r--r--src/utils/timer.cpp4
-rw-r--r--src/utils/tokencollector.cpp6
-rw-r--r--src/utils/tokencollector.h6
-rw-r--r--src/utils/xml.cpp4
107 files changed, 476 insertions, 507 deletions
diff --git a/src/account-server/account.cpp b/src/account-server/account.cpp
index 10869294..6fd86842 100644
--- a/src/account-server/account.cpp
+++ b/src/account-server/account.cpp
@@ -24,7 +24,7 @@
Account::~Account()
{
- for (Characters::iterator i = mCharacters.begin(),
+ for (auto i = mCharacters.begin(),
i_end = mCharacters.end(); i != i_end; ++i)
{
delete (*i).second;
@@ -43,7 +43,7 @@ void Account::setCharacters(const Characters &characters)
void Account::addCharacter(CharacterData *character)
{
- unsigned slot = (unsigned) character->getCharacterSlot();
+ auto slot = (unsigned) character->getCharacterSlot();
assert(isSlotEmpty(slot));
mCharacters[slot] = character;
@@ -51,8 +51,8 @@ void Account::addCharacter(CharacterData *character)
void Account::delCharacter(unsigned slot)
{
- for (Characters::iterator iter = mCharacters.begin(),
- iter_end = mCharacters.end(); iter != iter_end; ++iter)
+ for (auto iter = mCharacters.begin(),
+ iter_end = mCharacters.end(); iter != iter_end; ++iter)
{
if ((*iter).second->getCharacterSlot() == slot)
{
diff --git a/src/account-server/account.h b/src/account-server/account.h
index 05c73c96..175d4bcd 100644
--- a/src/account-server/account.h
+++ b/src/account-server/account.h
@@ -235,6 +235,6 @@ class Account
time_t mLastLogin; /**< Date and time of the last login */
};
-typedef std::vector< Account * > Accounts;
+using Accounts = std::vector<Account *>;
#endif // ACCOUNT_H
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp
index 856f07d0..2275e015 100644
--- a/src/account-server/accounthandler.cpp
+++ b/src/account-server/accounthandler.cpp
@@ -77,11 +77,11 @@ protected:
/**
* Processes account related messages.
*/
- void processMessage(NetComputer *client, MessageIn &message);
+ void processMessage(NetComputer *client, MessageIn &message) override;
- NetComputer *computerConnected(ENetPeer *peer);
+ NetComputer *computerConnected(ENetPeer *peer) override;
- void computerDisconnected(NetComputer *comp);
+ void computerDisconnected(NetComputer *comp) override;
private:
void handleLoginRandTriggerMessage(AccountClient &client, MessageIn &msg);
@@ -128,7 +128,7 @@ private:
std::string mUpdateHost;
std::string mDataUrl;
- typedef std::map<int, time_t> IPsToTime;
+ using IPsToTime = std::map<int, time_t>;
IPsToTime mLastLoginAttemptForIP;
};
@@ -256,7 +256,7 @@ NetComputer *AccountHandler::computerConnected(ENetPeer *peer)
void AccountHandler::computerDisconnected(NetComputer *comp)
{
- AccountClient *client = static_cast<AccountClient *>(comp);
+ auto client = static_cast<AccountClient *>(comp);
if (client->status == CLIENT_QUEUED)
// Delete it from the pendingClient list
@@ -801,7 +801,7 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client,
}
else
{
- CharacterData *newCharacter = new CharacterData(name);
+ auto newCharacter = new CharacterData(name);
// Set the initial attributes provided by the client
for (unsigned i = 0; i < mModifiableAttributes.size(); ++i)
diff --git a/src/account-server/character.cpp b/src/account-server/character.cpp
index 80b28b55..e22a84e9 100644
--- a/src/account-server/character.cpp
+++ b/src/account-server/character.cpp
@@ -106,7 +106,7 @@ void CharacterData::serialize(MessageOut &msg)
const EquipData &equipData = poss.getEquipment();
const InventoryData &inventoryData = poss.getInventory();
- for (InventoryData::const_iterator itemIt = inventoryData.begin(),
+ for (auto itemIt = inventoryData.begin(),
itemIt_end = inventoryData.end(); itemIt != itemIt_end; ++itemIt)
{
int slot = itemIt->first;
diff --git a/src/account-server/character.h b/src/account-server/character.h
index 3af6c7d0..d7e905cc 100644
--- a/src/account-server/character.h
+++ b/src/account-server/character.h
@@ -75,7 +75,7 @@ struct QuestInfo
/**
* Stores attributes by their id.
*/
-typedef std::map<unsigned, AttributeValue> AttributeMap;
+using AttributeMap = std::map<unsigned int, AttributeValue>;
class CharacterData
{
@@ -278,6 +278,6 @@ class CharacterData
/**
* Type definition for a list of Characters.
*/
-typedef std::map<unsigned, CharacterData* > Characters;
+using Characters = std::map<unsigned int, CharacterData *>;
#endif
diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp
index e14b301f..9d3a800a 100644
--- a/src/account-server/main-account.cpp
+++ b/src/account-server/main-account.cpp
@@ -249,11 +249,11 @@ static void parseOptions(int argc, char *argv[], CommandLineOptions &options)
const struct option longOptions[] =
{
- { "help", no_argument, 0, 'h' },
- { "config", required_argument, 0, 'c' },
- { "verbosity", required_argument, 0, 'v' },
- { "port", required_argument, 0, 'p' },
- { 0, 0, 0, 0 }
+ { "help", no_argument, nullptr, 'h' },
+ { "config", required_argument, nullptr, 'c' },
+ { "verbosity", required_argument, nullptr, 'v' },
+ { "port", required_argument, nullptr, 'p' },
+ { nullptr, 0, nullptr, 0 }
};
while (optind < argc)
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index 273642b2..49aa2839 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -51,14 +51,14 @@ struct MapStatistics
unsigned short nbMonsters;
};
-typedef std::map<unsigned short, MapStatistics> ServerStatistics;
+using ServerStatistics = std::map<unsigned short, MapStatistics>;
/**
* Stores address, maps, and statistics, of a connected game server.
*/
struct GameServer: NetComputer
{
- GameServer(ENetPeer *peer): NetComputer(peer), server(0), port(0) {}
+ GameServer(ENetPeer *peer): NetComputer(peer), server(nullptr), port(0) {}
std::string name;
std::string address;
@@ -81,18 +81,18 @@ class ServerHandler: public ConnectionHandler
/**
* Processes server messages.
*/
- void processMessage(NetComputer *computer, MessageIn &message);
+ void processMessage(NetComputer *computer, MessageIn &message) override;
/**
* Called when a game server connects. Initializes a simple NetComputer
* as these connections are stateless.
*/
- NetComputer *computerConnected(ENetPeer *peer);
+ NetComputer *computerConnected(ENetPeer *peer) override;
/**
* Called when a game server disconnects.
*/
- void computerDisconnected(NetComputer *comp);
+ void computerDisconnected(NetComputer *comp) override;
};
static ServerHandler *serverHandler;
@@ -133,7 +133,7 @@ static GameServer *getGameServerFromMap(int mapId)
i = serverHandler->clients.begin(),
i_end = serverHandler->clients.end(); i != i_end; ++i)
{
- GameServer *server = static_cast< GameServer * >(*i);
+ auto server = static_cast< GameServer * >(*i);
ServerStatistics::const_iterator it = server->maps.find(mapId);
if (it == server->maps.end()) continue;
return server;
@@ -175,7 +175,7 @@ void GameServerHandler::registerClient(const std::string &token,
void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
{
- GameServer *server = static_cast<GameServer *>(comp);
+ auto server = static_cast<GameServer *>(comp);
switch (msg.getId())
{
@@ -234,7 +234,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
<< " asks for maps to activate.");
const std::map<int, std::string> &maps = MapManager::getMaps();
- for (std::map<int, std::string>::const_iterator it = maps.begin(),
+ for (auto it = maps.begin(),
it_end = maps.end(); it != it_end; ++it)
{
int id = it->first;
@@ -267,7 +267,7 @@ 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 (std::list<FloorItem>::iterator i = items.begin();
+ for (auto i = items.begin();
i != items.end(); ++i)
{
outMsg.writeInt32(i->getItemId());
@@ -431,7 +431,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
while (msg.getUnreadLength())
{
int mapId = msg.readInt16();
- ServerStatistics::iterator i = server->maps.find(mapId);
+ auto i = server->maps.find(mapId);
if (i == server->maps.end())
{
LOG_ERROR("Server " << server->address << ':'
@@ -536,7 +536,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
// save the letter
LOG_DEBUG("Creating letter");
- Letter *letter = new Letter(0, sender, receiver);
+ auto letter = new Letter(0, sender, receiver);
letter->addText(contents);
for (unsigned i = 0; i < items.size(); ++i)
{
@@ -620,7 +620,7 @@ void GameServerHandler::dumpStatistics(std::ostream &os)
i = serverHandler->clients.begin(),
i_end = serverHandler->clients.end(); i != i_end; ++i)
{
- GameServer *server = static_cast< GameServer * >(*i);
+ auto server = static_cast< GameServer * >(*i);
if (!server->port)
continue;
@@ -633,7 +633,7 @@ void GameServerHandler::dumpStatistics(std::ostream &os)
const MapStatistics &m = j->second;
os << "<map id=\"" << j->first << "\" nb_entities=\"" << m.nbEntities
<< "\" nb_monsters=\"" << m.nbMonsters << "\">\n";
- for (std::vector< int >::const_iterator k = m.players.begin(),
+ for (auto k = m.players.begin(),
k_end = m.players.end(); k != k_end; ++k)
{
os << "<character id=\"" << *k << "\"/>\n";
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp
index 308f96fa..d243b1e7 100644
--- a/src/account-server/storage.cpp
+++ b/src/account-server/storage.cpp
@@ -171,7 +171,7 @@ std::unique_ptr<Account> Storage::getAccountBySQL()
// If the account is not even in the database then
// we have no choice but to return nothing.
if (accountInfo.isEmpty())
- return 0;
+ return nullptr;
string_to< unsigned > toUint;
unsigned id = toUint(accountInfo(0, 0));
@@ -188,7 +188,7 @@ std::unique_ptr<Account> Storage::getAccountBySQL()
int level = toUint(accountInfo(0, 4));
// Check if the user is permanently banned, or temporarily banned.
if (level == AL_BANNED
- || time(0) <= (int) toUint(accountInfo(0, 5)))
+ || time(nullptr) <= (int) toUint(accountInfo(0, 5)))
{
account->setLevel(AL_BANNED);
// It is, so skip character loading.
@@ -245,7 +245,7 @@ std::unique_ptr<Account> Storage::getAccountBySQL()
e);
}
- return 0;
+ return nullptr;
}
void Storage::fixCharactersSlot(int accountId)
@@ -292,8 +292,7 @@ void Storage::fixCharactersSlot(int accountId)
dal::PerformTransaction transaction(mDb);
// Update the slots in database.
- for (std::map<unsigned, unsigned>::iterator i =
- slotsToUpdate.begin(),
+ for (auto i = slotsToUpdate.begin(),
i_end = slotsToUpdate.end(); i != i_end; ++i)
{
// Update the character slot.
@@ -324,7 +323,7 @@ std::unique_ptr<Account> Storage::getAccount(const std::string &userName)
mDb->bindValue(1, userName);
return getAccountBySQL();
}
- return 0;
+ return nullptr;
}
std::unique_ptr<Account> Storage::getAccount(int accountID)
@@ -336,12 +335,12 @@ std::unique_ptr<Account> Storage::getAccount(int accountID)
mDb->bindValue(1, accountID);
return getAccountBySQL();
}
- return 0;
+ return nullptr;
}
CharacterData *Storage::getCharacterBySQL(Account *owner)
{
- CharacterData *character = 0;
+ CharacterData *character = nullptr;
string_to< unsigned > toUint;
string_to< int > toInt;
@@ -353,7 +352,7 @@ CharacterData *Storage::getCharacterBySQL(Account *owner)
// If the character is not even in the database then
// we have no choice but to return nothing.
if (charInfo.isEmpty())
- return 0;
+ return nullptr;
string_to< unsigned short > toUshort;
string_to< double > toDouble;
@@ -538,7 +537,7 @@ CharacterData *Storage::getCharacter(int id, Account *owner)
mDb->bindValue(1, id);
return getCharacterBySQL(owner);
}
- return 0;
+ return nullptr;
}
CharacterData *Storage::getCharacter(const std::string &name)
@@ -548,9 +547,9 @@ CharacterData *Storage::getCharacter(const std::string &name)
if (mDb->prepareSql(sql.str()))
{
mDb->bindValue(1, name);
- return getCharacterBySQL(0);
+ return getCharacterBySQL(nullptr);
}
- return 0;
+ return nullptr;
}
unsigned Storage::getCharacterId(const std::string &name)
@@ -835,7 +834,7 @@ bool Storage::updateCharacter(CharacterData *character)
const Possessions &poss = character->getPossessions();
const InventoryData &inventoryData = poss.getInventory();
- for (InventoryData::const_iterator itemIt = inventoryData.begin(),
+ for (auto itemIt = inventoryData.begin(),
j_end = inventoryData.end(); itemIt != j_end; ++itemIt)
{
sql.str("");
@@ -969,7 +968,7 @@ void Storage::flush(const Account &account)
const Characters &characters = account.getCharacters();
// Insert or update the characters.
- for (Characters::const_iterator it = characters.begin(),
+ for (auto it = characters.begin(),
it_end = characters.end(); it != it_end; ++it)
{
CharacterData *character = (*it).second;
@@ -1040,7 +1039,7 @@ void Storage::flush(const Account &account)
for (unsigned i = 0; i < charInMemInfo.rows(); ++i) // In database
{
charFound = false;
- for (Characters::const_iterator it = characters.begin(),
+ for (auto it = characters.begin(),
it_end = characters.end(); it != it_end; ++it) // In memory
{
if (charInMemInfo(i, 0) == (*it).second->getName())
@@ -1426,14 +1425,14 @@ std::map<int, Guild*> Storage::getGuildList()
// Loop through every row in the table and assign it to a guild
for (unsigned i = 0; i < guildInfo.rows(); ++i)
{
- Guild* guild = new Guild(guildInfo(i,1));
+ auto guild = new Guild(guildInfo(i,1));
guild->setId(toShort(guildInfo(i,0)));
guilds[guild->getId()] = guild;
}
string_to< unsigned > toUint;
// Add the members to the guilds.
- for (std::map<int, Guild*>::iterator it = guilds.begin();
+ for (auto it = guilds.begin();
it != guilds.end(); ++it)
{
std::ostringstream memberSql;
@@ -1452,7 +1451,7 @@ std::map<int, Guild*> Storage::getGuildList()
std::list<std::pair<int, int> >::const_iterator i, i_end;
for (i = members.begin(), i_end = members.end(); i != i_end; ++i)
{
- CharacterData *character = getCharacter((*i).first, 0);
+ CharacterData *character = getCharacter((*i).first, nullptr);
if (character)
{
character->addGuild(it->second->getName());
@@ -1611,7 +1610,7 @@ void Storage::setWorldStateVar(const std::string &name,
std::ostringstream updateStateVar;
updateStateVar << "UPDATE " << WORLD_STATES_TBL_NAME
<< " SET value = '" << value << "', "
- << " moddate = '" << time(0) << "' "
+ << " moddate = '" << time(nullptr) << "' "
<< " WHERE state_name = '" << name << "'"
<< " AND map_id = '" << mapId << "';";
mDb->execSql(updateStateVar.str());
@@ -1627,7 +1626,7 @@ void Storage::setWorldStateVar(const std::string &name,
<< "'" << name << "', "
<< "'" << mapId << "', "
<< "'" << value << "', "
- << "'" << time(0) << "');";
+ << "'" << time(nullptr) << "');";
mDb->execSql(insertStateVar.str());
}
catch (const dal::DbSqlQueryExecFailure &e)
@@ -1678,7 +1677,7 @@ void Storage::banCharacter(int id, int duration)
return;
}
- uint64_t bantime = (uint64_t)time(0) + (uint64_t)duration * 60u;
+ uint64_t bantime = (uint64_t)time(nullptr) + (uint64_t)duration * 60u;
// ban the character
std::ostringstream sql;
sql << "update " << ACCOUNTS_TBL_NAME
@@ -1762,7 +1761,7 @@ void Storage::checkBannedAccounts()
sql << "update " << ACCOUNTS_TBL_NAME
<< " set level = " << AL_PLAYER << ", banned = 0"
<< " where level = " << AL_BANNED
- << " AND banned <= " << time(0) << ";";
+ << " AND banned <= " << time(nullptr) << ";";
mDb->execSql(sql.str());
}
catch (const dal::DbSqlQueryExecFailure &e)
@@ -1802,7 +1801,7 @@ void Storage::storeLetter(Letter *letter)
<< letter->getSender()->getDatabaseID() << ", "
<< letter->getReceiver()->getDatabaseID() << ", "
<< letter->getExpiry() << ", "
- << time(0) << ", "
+ << time(nullptr) << ", "
<< "?)";
if (mDb->prepareSql(sql.str()))
{
@@ -1831,7 +1830,7 @@ void Storage::storeLetter(Letter *letter)
<< letter->getReceiver()->getDatabaseID() << "', "
<< " letter_type = '" << letter->getType() << "', "
<< " expiration_date = '" << letter->getExpiry() << "', "
- << " sending_date = '" << time(0) << "', "
+ << " sending_date = '" << time(nullptr) << "', "
<< " letter_text = ? "
<< " WHERE letter_id = '" << letter->getId() << "'";
@@ -1865,7 +1864,7 @@ void Storage::storeLetter(Letter *letter)
Post *Storage::getStoredPost(int playerId)
{
- Post *p = new Post();
+ auto p = new Post();
string_to< unsigned > toUint;
@@ -1886,10 +1885,10 @@ Post *Storage::getStoredPost(int playerId)
for (unsigned i = 0; i < post.rows(); i++ )
{
// Load sender and receiver
- CharacterData *sender = getCharacter(toUint(post(i, 1)), 0);
- CharacterData *receiver = getCharacter(toUint(post(i, 2)), 0);
+ CharacterData *sender = getCharacter(toUint(post(i, 1)), nullptr);
+ CharacterData *receiver = getCharacter(toUint(post(i, 2)), nullptr);
- Letter *letter = new Letter(toUint( post(0,3) ), sender, receiver);
+ auto letter = new Letter(toUint( post(0,3) ), sender, receiver);
letter->setId( toUint(post(0, 0)) );
letter->setExpiry( toUint(post(0, 4)) );
@@ -2068,7 +2067,7 @@ void Storage::setOnlineStatus(int charId, bool online)
sql.clear();
sql.str("");
sql << "INSERT INTO " << ONLINE_USERS_TBL_NAME
- << " VALUES (" << charId << ", " << time(0) << ")";
+ << " VALUES (" << charId << ", " << time(nullptr) << ")";
mDb->execSql(sql.str());
}
else
@@ -2096,7 +2095,7 @@ void Storage::addTransaction(const Transaction &trans)
<< " VALUES (NULL, " << trans.mCharacterId << ", "
<< trans.mAction << ", "
<< "?, "
- << time(0) << ")";
+ << time(nullptr) << ")";
if (mDb->prepareSql(sql.str()))
{
mDb->bindValue(1, trans.mMessage);
diff --git a/src/chat-server/chatchannel.cpp b/src/chat-server/chatchannel.cpp
index 52c9bf5a..a85be8c8 100644
--- a/src/chat-server/chatchannel.cpp
+++ b/src/chat-server/chatchannel.cpp
@@ -69,8 +69,8 @@ bool ChatChannel::addUser(ChatClient *user)
bool ChatChannel::removeUser(ChatClient *user)
{
- ChannelUsers::iterator i_end = mRegisteredUsers.end(),
- i = std::find(mRegisteredUsers.begin(), i_end, user);
+ auto i_end = mRegisteredUsers.end(),
+ i = std::find(mRegisteredUsers.begin(), i_end, user);
if (i == i_end) return false;
mRegisteredUsers.erase(i);
std::vector< ChatChannel * > &channels = user->channels;
@@ -100,7 +100,7 @@ bool ChatChannel::canJoin() const
void ChatChannel::setUserMode(ChatClient *user, unsigned char mode)
{
- std::map<ChatChannel*, std::string>::iterator itr = user->userModes.find(this);
+ auto itr = user->userModes.find(this);
if (itr != user->userModes.end())
{
itr->second += mode;
@@ -120,5 +120,5 @@ std::string ChatChannel::getUserMode(ChatClient *user) const
if (itr != user->userModes.end())
return itr->second;
- return 0;
+ return nullptr;
}
diff --git a/src/chat-server/chatchannel.h b/src/chat-server/chatchannel.h
index 66ffb5b2..d553cfbe 100644
--- a/src/chat-server/chatchannel.h
+++ b/src/chat-server/chatchannel.h
@@ -40,7 +40,7 @@ class ChatClient;
class ChatChannel
{
public:
- typedef std::vector< ChatClient * > ChannelUsers;
+ using ChannelUsers = std::vector<ChatClient *>;
/**
* Constructor.
diff --git a/src/chat-server/chatchannelmanager.cpp b/src/chat-server/chatchannelmanager.cpp
index a94ede24..62b7b735 100644
--- a/src/chat-server/chatchannelmanager.cpp
+++ b/src/chat-server/chatchannelmanager.cpp
@@ -89,7 +89,7 @@ bool ChatChannelManager::tryNewPublicChannel(const std::string &name)
bool ChatChannelManager::removeChannel(int channelId)
{
- ChatChannels::iterator i = mChatChannels.find(channelId);
+ auto i = mChatChannels.find(channelId);
if (i == mChatChannels.end())
return false;
i->second.removeAllUsers();
@@ -102,7 +102,7 @@ std::list<const ChatChannel*> ChatChannelManager::getPublicChannels() const
{
std::list<const ChatChannel*> channels;
- for (ChatChannels::const_iterator i = mChatChannels.begin(),
+ for (auto i = mChatChannels.begin(),
i_end = mChatChannels.end();
i != i_end; ++i)
{
@@ -117,7 +117,7 @@ std::list<const ChatChannel*> ChatChannelManager::getPublicChannels() const
int ChatChannelManager::getChannelId(const std::string &channelName) const
{
- for (ChatChannels::const_iterator i = mChatChannels.begin(),
+ for (auto i = mChatChannels.begin(),
i_end = mChatChannels.end();
i != i_end; ++i)
{
@@ -129,27 +129,27 @@ int ChatChannelManager::getChannelId(const std::string &channelName) const
ChatChannel *ChatChannelManager::getChannel(int channelId)
{
- ChatChannels::iterator i = mChatChannels.find(channelId);
+ auto i = mChatChannels.find(channelId);
if (i != mChatChannels.end())
return &i->second;
- return 0;
+ return nullptr;
}
ChatChannel *ChatChannelManager::getChannel(const std::string &name)
{
- for (ChatChannels::iterator i = mChatChannels.begin();
+ for (auto i = mChatChannels.begin();
i != mChatChannels.end(); ++i)
{
if (i->second.getName() == name)
return &(i->second);
}
- return 0;
+ return nullptr;
}
void ChatChannelManager::setChannelTopic(int channelId, const std::string &topic)
{
- ChatChannels::iterator i = mChatChannels.find(channelId);
+ auto i = mChatChannels.find(channelId);
if (i == mChatChannels.end())
return;
@@ -181,7 +181,7 @@ bool ChatChannelManager::channelExists(int channelId) const
bool ChatChannelManager::channelExists(const std::string &channelName) const
{
- for (ChatChannels::const_iterator i = mChatChannels.begin();
+ for (auto i = mChatChannels.begin();
i != mChatChannels.end(); ++i)
{
if (i->second.getName() == channelName)
diff --git a/src/chat-server/chatchannelmanager.h b/src/chat-server/chatchannelmanager.h
index 9a18954f..76f9e33f 100644
--- a/src/chat-server/chatchannelmanager.h
+++ b/src/chat-server/chatchannelmanager.h
@@ -115,7 +115,7 @@ class ChatChannelManager
int nextUsable();
private:
- typedef std::map<unsigned short, ChatChannel> ChatChannels;
+ using ChatChannels = std::map<unsigned short, ChatChannel>;
/**
* The map keeping all the chat channels. The channel id must be
diff --git a/src/chat-server/chatclient.h b/src/chat-server/chatclient.h
index 79de000a..665f1fc2 100644
--- a/src/chat-server/chatclient.h
+++ b/src/chat-server/chatclient.h
@@ -41,7 +41,7 @@ class ChatClient : public NetComputer
ChatClient(ENetPeer *peer)
: NetComputer(peer)
, characterId(0)
- , party(0)
+ , party(nullptr)
, accountLevel(0)
{
}
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index e1bb10df..a66fb493 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -45,7 +45,7 @@ void registerChatClient(const std::string &token,
const std::string &name,
int level)
{
- ChatHandler::Pending *p = new ChatHandler::Pending;
+ auto p = new ChatHandler::Pending;
p->character = name;
p->level = level;
chatHandler->mTokenCollector.addPendingConnect(token, p);
@@ -112,7 +112,7 @@ NetComputer *ChatHandler::computerConnected(ENetPeer *peer)
void ChatHandler::computerDisconnected(NetComputer *comp)
{
- ChatClient *computer = static_cast< ChatClient * >(comp);
+ auto computer = static_cast< ChatClient * >(comp);
if (computer->characterName.empty())
{
@@ -377,12 +377,10 @@ void ChatHandler::handleEnterChannelMessage(ChatClient &client, MessageIn &msg)
reply.writeString(channel->getAnnouncement());
const ChatChannel::ChannelUsers &users = channel->getUserList();
- for (ChatChannel::ChannelUsers::const_iterator i = users.begin(),
- i_end = users.end();
- i != i_end; ++i)
+ for (auto chatClient : users)
{
- reply.writeString((*i)->characterName);
- reply.writeString(channel->getUserMode((*i)));
+ reply.writeString(chatClient->characterName);
+ reply.writeString(channel->getUserMode(chatClient));
}
// Send an CPMSG_UPDATE_CHANNEL to warn other clients a user went
// in the channel.
@@ -533,7 +531,7 @@ void ChatHandler::handleListChannelsMessage(ChatClient &client, MessageIn &)
std::list<const ChatChannel*> channels =
chatChannelManager->getPublicChannels();
- for (std::list<const ChatChannel*>::iterator i = channels.begin(),
+ for (auto i = channels.begin(),
i_end = channels.end();
i != i_end; ++i)
{
@@ -564,8 +562,7 @@ void ChatHandler::handleListChannelUsersMessage(ChatClient &client,
const ChatChannel::ChannelUsers &users = channel->getUserList();
- for (ChatChannel::ChannelUsers::const_iterator
- i = users.begin(), i_end = users.end(); i != i_end; ++i)
+ for (auto i = users.begin(), i_end = users.end(); i != i_end; ++i)
{
reply.writeString((*i)->characterName);
reply.writeString(channel->getUserMode((*i)));
@@ -622,7 +619,7 @@ void ChatHandler::sayToPlayer(ChatClient &computer,
MessageOut result(CPMSG_PRIVMSG);
result.writeString(computer.characterName);
result.writeString(text);
- for (NetComputers::iterator i = clients.begin(), i_end = clients.end();
+ for (auto i = clients.begin(), i_end = clients.end();
i != i_end; ++i) {
if (static_cast< ChatClient * >(*i)->characterName == playerName)
{
@@ -647,8 +644,7 @@ void ChatHandler::sendInChannel(ChatChannel *channel, MessageOut &msg)
{
const ChatChannel::ChannelUsers &users = channel->getUserList();
- for (ChatChannel::ChannelUsers::const_iterator
- i = users.begin(), i_end = users.end(); i != i_end; ++i)
+ for (auto i = users.begin(), i_end = users.end(); i != i_end; ++i)
{
(*i)->send(msg);
}
@@ -656,11 +652,6 @@ void ChatHandler::sendInChannel(ChatChannel *channel, MessageOut &msg)
ChatClient *ChatHandler::getClient(const std::string &name) const
{
- std::map<std::string, ChatClient*>::const_iterator itr
- = mPlayerMap.find(name);
-
- if (itr != mPlayerMap.end())
- return itr->second;
- else
- return 0;
+ auto itr = mPlayerMap.find(name);
+ return (itr != mPlayerMap.end()) ? itr->second : nullptr;
}
diff --git a/src/chat-server/chathandler.h b/src/chat-server/chathandler.h
index 62970ff5..1c073cf4 100644
--- a/src/chat-server/chathandler.h
+++ b/src/chat-server/chathandler.h
@@ -132,17 +132,17 @@ class ChatHandler : public ConnectionHandler
/**
* Process chat related messages.
*/
- void processMessage(NetComputer *computer, MessageIn &message);
+ void processMessage(NetComputer *computer, MessageIn &message) override;
/**
* Returns a ChatClient instance.
*/
- NetComputer *computerConnected(ENetPeer *);
+ NetComputer *computerConnected(ENetPeer *) override;
/**
* Cleans up after the disconnected client.
*/
- void computerDisconnected(NetComputer *);
+ void computerDisconnected(NetComputer *) override;
/**
* Send messages for each guild the character belongs to.
diff --git a/src/chat-server/guild.cpp b/src/chat-server/guild.cpp
index e86130dc..b87860ae 100644
--- a/src/chat-server/guild.cpp
+++ b/src/chat-server/guild.cpp
@@ -39,7 +39,7 @@ Guild::~Guild()
void Guild::addMember(int playerId, int permissions)
{
// create new guild member
- GuildMember *member = new GuildMember;
+ auto member = new GuildMember;
member->mId = playerId;
member->mPermissions = permissions;
@@ -54,7 +54,7 @@ void Guild::removeMember(int playerId)
if (getOwner() == playerId)
{
// if the leader is leaving, assign next member as leader
- for (std::list<GuildMember*>::iterator it = mMembers.begin(),
+ for (auto it = mMembers.begin(),
it_end = mMembers.end(); it != it_end; ++it)
{
GuildMember *member = *it;
@@ -72,8 +72,8 @@ void Guild::removeMember(int playerId)
int Guild::getOwner() const
{
- std::list<GuildMember*>::const_iterator itr = mMembers.begin();
- std::list<GuildMember*>::const_iterator itr_end = mMembers.end();
+ auto itr = mMembers.begin();
+ auto itr_end = mMembers.end();
while (itr != itr_end)
{
@@ -107,13 +107,12 @@ void Guild::removeInvited(int playerId)
bool Guild::checkInGuild(int playerId) const
{
- return getMember(playerId) != 0;
+ return getMember(playerId) != nullptr;
}
GuildMember *Guild::getMember(int playerId) const
{
- std::list<GuildMember*>::const_iterator itr = mMembers.begin(),
- itr_end = mMembers.end();
+ auto itr = mMembers.begin(), itr_end = mMembers.end();
while (itr != itr_end)
{
if ((*itr)->mId == playerId)
@@ -121,7 +120,7 @@ GuildMember *Guild::getMember(int playerId) const
++itr;
}
- return 0;
+ return nullptr;
}
bool Guild::canInvite(int playerId) const
diff --git a/src/chat-server/guildhandler.cpp b/src/chat-server/guildhandler.cpp
index da666769..21235f8a 100644
--- a/src/chat-server/guildhandler.cpp
+++ b/src/chat-server/guildhandler.cpp
@@ -59,7 +59,7 @@ void ChatHandler::sendGuildRejoin(ChatClient &client)
client.guilds = guilds;
- for (std::vector<Guild *>::iterator it = guilds.begin(),
+ for (auto it = guilds.begin(),
it_end = guilds.end(); it != it_end; ++it)
{
Guild *guild = *it;
@@ -290,7 +290,7 @@ void ChatHandler::handleGuildGetMembers(ChatClient &client, MessageIn &msg)
reply.writeInt16(guildId);
std::list<GuildMember*> memberList = guild->getMembers();
std::list<GuildMember*>::const_iterator itr_end = memberList.end();
- for (std::list<GuildMember*>::iterator itr = memberList.begin();
+ for (auto itr = memberList.begin();
itr != itr_end; ++itr)
{
CharacterData *c = storage->getCharacter((*itr)->mId, nullptr);
diff --git a/src/chat-server/guildmanager.cpp b/src/chat-server/guildmanager.cpp
index b7f945de..4b350b2c 100644
--- a/src/chat-server/guildmanager.cpp
+++ b/src/chat-server/guildmanager.cpp
@@ -36,7 +36,7 @@ GuildManager::GuildManager():
GuildManager::~GuildManager()
{
- for (std::map<int, Guild*>::iterator it = mGuilds.begin();
+ for (auto it = mGuilds.begin();
it != mGuilds.end(); ++it)
{
delete it->second;
@@ -45,7 +45,7 @@ GuildManager::~GuildManager()
Guild* GuildManager::createGuild(const std::string &name, int playerId)
{
- Guild *guild = new Guild(name);
+ auto guild = new Guild(name);
// Add guild to db
storage->addGuild(guild);
@@ -97,7 +97,7 @@ void GuildManager::removeGuildMember(Guild *guild, int playerId,
if (client)
{
- for (std::vector<Guild *>::iterator it = client->guilds.begin(),
+ for (auto it = client->guilds.begin(),
it_end = client->guilds.end(); it != it_end; ++it)
{
if (*it == guild)
@@ -111,13 +111,13 @@ void GuildManager::removeGuildMember(Guild *guild, int playerId,
Guild *GuildManager::findById(short id) const
{
- std::map<int, Guild*>::const_iterator it = mGuilds.find(id);
+ auto it = mGuilds.find(id);
return it == mGuilds.end() ? 0 : it->second;
}
Guild *GuildManager::findByName(const std::string &name) const
{
- for (std::map<int, Guild*>::const_iterator it = mGuilds.begin(),
+ for (auto it = mGuilds.begin(),
it_end = mGuilds.end();
it != it_end; ++it)
{
@@ -125,18 +125,18 @@ Guild *GuildManager::findByName(const std::string &name) const
if (guild->getName() == name)
return guild;
}
- return 0;
+ return nullptr;
}
bool GuildManager::doesExist(const std::string &name) const
{
- return findByName(name) != 0;
+ return findByName(name) != nullptr;
}
std::vector<Guild *> GuildManager::getGuildsForPlayer(int playerId) const
{
std::vector<Guild *> guilds;
- for (std::map<int, Guild*>::const_iterator it = mGuilds.begin();
+ for (auto it = mGuilds.begin();
it != mGuilds.end(); ++it)
{
if (it->second->checkInGuild(playerId))
@@ -149,7 +149,7 @@ std::vector<Guild *> GuildManager::getGuildsForPlayer(int playerId) const
void GuildManager::disconnectPlayer(ChatClient *player)
{
- for (std::vector<Guild *>::iterator it = player->guilds.begin(),
+ for (auto it = player->guilds.begin(),
it_end = player->guilds.end(); it != it_end; ++it)
{
chatHandler->sendGuildListUpdate(*it,
diff --git a/src/chat-server/guildmanager.h b/src/chat-server/guildmanager.h
index 93e5cf2f..becab35e 100644
--- a/src/chat-server/guildmanager.h
+++ b/src/chat-server/guildmanager.h
@@ -58,7 +58,7 @@ class GuildManager
*/
void removeGuildMember(Guild *guild, int playerId,
const std::string &characterName,
- ChatClient *client = 0);
+ ChatClient *client = nullptr);
/**
* Returns the guild with the given id. O(n)
diff --git a/src/chat-server/party.cpp b/src/chat-server/party.cpp
index e665ad1b..1920cd59 100644
--- a/src/chat-server/party.cpp
+++ b/src/chat-server/party.cpp
@@ -51,7 +51,7 @@ void Party::addUser(const std::string &name, const std::string &inviter)
void Party::removeUser(const std::string &name)
{
- PartyUsers::iterator itr = std::find(mUsers.begin(), mUsers.end(), name);
+ auto itr = std::find(mUsers.begin(), mUsers.end(), name);
if (itr != mUsers.end())
{
mUsers.erase(itr);
diff --git a/src/chat-server/party.h b/src/chat-server/party.h
index 18bec58d..273223f1 100644
--- a/src/chat-server/party.h
+++ b/src/chat-server/party.h
@@ -30,7 +30,7 @@
class Party
{
public:
- typedef std::vector<std::string> PartyUsers;
+ using PartyUsers = std::vector<std::string>;
Party();
diff --git a/src/chat-server/partyhandler.cpp b/src/chat-server/partyhandler.cpp
index b78bc22a..b7e1c8d9 100644
--- a/src/chat-server/partyhandler.cpp
+++ b/src/chat-server/partyhandler.cpp
@@ -194,7 +194,7 @@ void ChatHandler::removeUserFromParty(ChatClient &client)
if (client.party->userCount() < 1)
{
delete client.party;
- client.party = 0;
+ client.party = nullptr;
}
}
}
diff --git a/src/chat-server/post.cpp b/src/chat-server/post.cpp
index e6248891..aca1de65 100644
--- a/src/chat-server/post.cpp
+++ b/src/chat-server/post.cpp
@@ -87,8 +87,8 @@ std::vector<InventoryItem> Letter::getAttachments() const
Post::~Post()
{
- std::vector<Letter*>::iterator itr_end = mLetters.end();
- for (std::vector<Letter*>::iterator itr = mLetters.begin();
+ auto itr_end = mLetters.end();
+ for (auto itr = mLetters.begin();
itr != itr_end;
++itr)
{
@@ -127,7 +127,7 @@ unsigned Post::getNumberOfLetters() const
void PostManager::addLetter(Letter *letter)
{
- std::map<CharacterData*, Post*>::iterator itr =
+ auto itr =
mPostBox.find(letter->getReceiver());
if (itr != mPostBox.end())
{
@@ -135,7 +135,7 @@ void PostManager::addLetter(Letter *letter)
}
else
{
- Post *post = new Post();
+ auto post = new Post();
post->addLetter(letter);
mPostBox.insert(
std::pair<CharacterData*, Post*>(letter->getReceiver(), post)
@@ -145,14 +145,13 @@ void PostManager::addLetter(Letter *letter)
Post *PostManager::getPost(CharacterData *player) const
{
- std::map<CharacterData*, Post*>::const_iterator itr = mPostBox.find(player);
+ auto itr = mPostBox.find(player);
return (itr == mPostBox.end()) ? nullptr : itr->second;
}
void PostManager::clearPost(CharacterData *player)
{
- std::map<CharacterData*, Post*>::iterator itr =
- mPostBox.find(player);
+ auto itr = mPostBox.find(player);
if (itr != mPostBox.end())
{
delete itr->second;
diff --git a/src/common/configuration.cpp b/src/common/configuration.cpp
index 906d2629..98d406af 100644
--- a/src/common/configuration.cpp
+++ b/src/common/configuration.cpp
@@ -106,7 +106,7 @@ void Configuration::deinitialize()
std::string Configuration::getValue(const std::string &key,
const std::string &deflt)
{
- std::map<std::string, std::string>::iterator iter = options.find(key);
+ auto iter = options.find(key);
if (iter == options.end())
return deflt;
return iter->second;
@@ -114,7 +114,7 @@ std::string Configuration::getValue(const std::string &key,
int Configuration::getValue(const std::string &key, int deflt)
{
- std::map<std::string, std::string>::iterator iter = options.find(key);
+ auto iter = options.find(key);
if (iter == options.end())
return deflt;
return atoi(iter->second.c_str());
@@ -122,7 +122,7 @@ int Configuration::getValue(const std::string &key, int deflt)
bool Configuration::getBoolValue(const std::string &key, bool deflt)
{
- std::map<std::string, std::string>::iterator iter = options.find(key);
+ auto iter = options.find(key);
if (iter == options.end())
return deflt;
return utils::stringToBool(iter->second.c_str(), deflt);
diff --git a/src/common/defines.h b/src/common/defines.h
index 483a4eb1..c6a9d027 100644
--- a/src/common/defines.h
+++ b/src/common/defines.h
@@ -132,7 +132,7 @@ static inline Element elementFromString(const std::string &name)
table["ice"] = ELEMENT_ICE;
}
- std::map<const std::string, Element>::iterator val = table.find(name);
+ auto val = table.find(name);
return val == table.end() ? ELEMENT_ILLEGAL : (*val).second;
}
@@ -160,7 +160,7 @@ static inline DamageType damageTypeFromString(const std::string &name)
table["other"] = DAMAGE_OTHER;
}
- std::map<const std::string, DamageType>::iterator val = table.find(name);
+ auto val = table.find(name);
return val == table.end() ? DAMAGE_OTHER : (*val).second;
}
diff --git a/src/common/inventorydata.h b/src/common/inventorydata.h
index 5d1d9388..2e9a8e45 100644
--- a/src/common/inventorydata.h
+++ b/src/common/inventorydata.h
@@ -50,10 +50,10 @@ struct InventoryItem
};
// inventory slot id -> { item }
-typedef std::map< unsigned, InventoryItem > InventoryData;
+using InventoryData = std::map<unsigned int, InventoryItem>;
// the slots which are equipped
-typedef std::set<int> EquipData;
+using EquipData = std::set<int>;
/**
* Structure storing the equipment and inventory of a Player.
diff --git a/src/common/permissionmanager.cpp b/src/common/permissionmanager.cpp
index 42f69ae3..5281f44d 100644
--- a/src/common/permissionmanager.cpp
+++ b/src/common/permissionmanager.cpp
@@ -34,7 +34,7 @@ static std::string permissionFile;
void addPermission(std::string permission, char mask)
{
- std::map<std::string, unsigned char>::iterator i = permissions.find(permission);
+ auto i = permissions.find(permission);
if (i == permissions.end())
{
permissions.insert(std::make_pair(permission, mask));
@@ -87,7 +87,7 @@ void PermissionManager::reload()
{
if (xmlStrEqual(perNode->name, BAD_CAST "allow"))
{
- const char* permission = (const char*)perNode->xmlChildrenNode->content;
+ const auto permission = (const char*)perNode->xmlChildrenNode->content;
if (permission && strlen(permission) > 0)
{
addPermission(permission, classmask);
@@ -96,7 +96,7 @@ void PermissionManager::reload()
//const char* permission = (const char*)perNode->xmlChildrenNode->content;
// To be implemented
} else if (xmlStrEqual(perNode->name, BAD_CAST "alias")){
- const char* alias = (const char*)perNode->xmlChildrenNode->content;
+ const auto alias = (const char*)perNode->xmlChildrenNode->content;
if (alias && strlen(alias) > 0)
aliases[alias] = classmask;
}
@@ -113,7 +113,7 @@ PermissionManager::Result PermissionManager::checkPermission(const Entity* chara
PermissionManager::Result PermissionManager::checkPermission(unsigned char level, std::string permission)
{
- std::map<std::string, unsigned char>::iterator iP = permissions.find(permission);
+ auto iP = permissions.find(permission);
if (iP == permissions.end())
{
@@ -130,7 +130,7 @@ PermissionManager::Result PermissionManager::checkPermission(unsigned char level
unsigned char PermissionManager::getMaskFromAlias(const std::string &alias)
{
- std::map<std::string, unsigned char>::iterator i = aliases.find(alias);
+ auto i = aliases.find(alias);
if (i == aliases.end())
{
diff --git a/src/common/resourcemanager.cpp b/src/common/resourcemanager.cpp
index bd6961d9..1dbbcaa9 100644
--- a/src/common/resourcemanager.cpp
+++ b/src/common/resourcemanager.cpp
@@ -104,7 +104,7 @@ char *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
fileSize = PHYSFS_fileLength(file);
// Allocate memory and load the file
- char *buffer = (char *) malloc(fileSize + 1);
+ auto buffer = (char *) malloc(fileSize + 1);
if (PHYSFS_readBytes(file, buffer, fileSize) != fileSize)
{
free(buffer);
diff --git a/src/dal/dalexcept.h b/src/dal/dalexcept.h
index 377c8ee1..96585882 100644
--- a/src/dal/dalexcept.h
+++ b/src/dal/dalexcept.h
@@ -44,7 +44,7 @@ class DbException: public std::exception
{}
~DbException()
- throw()
+ throw() override
{}
/**
@@ -52,8 +52,8 @@ class DbException: public std::exception
*
* @return the error message.
*/
- virtual const char *what() const
- throw()
+ const char *what() const
+ throw() override
{
return mMsg.c_str();
}
diff --git a/src/dal/dataprovider.h b/src/dal/dataprovider.h
index b066ea50..d5dee68c 100644
--- a/src/dal/dataprovider.h
+++ b/src/dal/dataprovider.h
@@ -35,11 +35,11 @@ class DataProvider;
/**
* Enumeration type for the database backends.
*/
-typedef enum {
+enum DbBackends {
DB_BKEND_MYSQL,
DB_BKEND_SQLITE,
DB_BKEND_POSTGRESQL
-} DbBackends;
+};
/**
* Begins a transaction on a given data provider. When the transaction is
diff --git a/src/dal/dataproviderfactory.cpp b/src/dal/dataproviderfactory.cpp
index d8c44f04..4902a2ce 100644
--- a/src/dal/dataproviderfactory.cpp
+++ b/src/dal/dataproviderfactory.cpp
@@ -53,15 +53,13 @@ DataProviderFactory::~DataProviderFactory()
DataProvider *DataProviderFactory::createDataProvider()
{
#if defined (MYSQL_SUPPORT)
- MySqlDataProvider* provider = new MySqlDataProvider;
- return provider;
+ auto provider = new MySqlDataProvider;
#elif defined (POSTGRESQL_SUPPORT)
- PqDataProvider *provider = new PqDataProvider;
- return provider;
+ auto provider = new PqDataProvider;
#else // SQLITE_SUPPORT
- SqLiteDataProvider* provider = new SqLiteDataProvider;
- return provider;
+ auto provider = new SqLiteDataProvider;
#endif
+ return provider;
}
} // namespace dal
diff --git a/src/dal/recordset.cpp b/src/dal/recordset.cpp
index 0529325f..49c245cd 100644
--- a/src/dal/recordset.cpp
+++ b/src/dal/recordset.cpp
@@ -136,9 +136,7 @@ const std::string &RecordSet::operator()(const unsigned row,
throw std::out_of_range(os.str());
}
- Row::const_iterator it = std::find(mHeaders.begin(),
- mHeaders.end(),
- name);
+ auto it = std::find(mHeaders.begin(), mHeaders.end(), name);
if (it == mHeaders.end()) {
std::ostringstream os;
os << "field " << name << " does not exist." << std::ends;
@@ -163,7 +161,7 @@ std::ostream &operator<<(std::ostream &out, const RecordSet &rhs)
// print the field names first.
if (rhs.mHeaders.size() > 0) {
out << "|";
- for (Row::const_iterator it = rhs.mHeaders.begin();
+ for (auto it = rhs.mHeaders.begin();
it != rhs.mHeaders.end();
++it)
{
@@ -173,12 +171,12 @@ std::ostream &operator<<(std::ostream &out, const RecordSet &rhs)
}
// and then print every line.
- for (RecordSet::Rows::const_iterator it = rhs.mRows.begin();
+ for (auto it = rhs.mRows.begin();
it != rhs.mRows.end();
++it)
{
out << "|";
- for (Row::const_iterator it2 = (*it).begin();
+ for (auto it2 = (*it).begin();
it2 != (*it).end();
++it2)
{
diff --git a/src/dal/recordset.h b/src/dal/recordset.h
index 91b434de..f46dc27a 100644
--- a/src/dal/recordset.h
+++ b/src/dal/recordset.h
@@ -30,7 +30,7 @@ namespace dal
/**
* Data type for a row in a RecordSet.
*/
-typedef std::vector<std::string> Row;
+using Row = std::vector<std::string>;
/**
@@ -165,7 +165,7 @@ class RecordSet
private:
Row mHeaders; /**< a list of field names */
- typedef std::vector<Row> Rows;
+ using Rows = std::vector<Row>;
Rows mRows; /**< a list of records */
};
diff --git a/src/dal/sqlitedataprovider.cpp b/src/dal/sqlitedataprovider.cpp
index 4b959f98..4aa7eca0 100644
--- a/src/dal/sqlitedataprovider.cpp
+++ b/src/dal/sqlitedataprovider.cpp
@@ -31,7 +31,7 @@
// sqlite3_int64 is the preferred new datatype for 64-bit int values.
// see: http://www.sqlite.org/capi3ref.html#sqlite3_int64
#ifndef sqlite3_int64
-typedef sqlite_int64 sqlite3_int64;
+using sqlite3_int64 = sqlite_int64;
#endif
namespace dal
@@ -42,8 +42,8 @@ const std::string SqLiteDataProvider::CFGPARAM_SQLITE_DB_DEF = "mana.db";
SqLiteDataProvider::SqLiteDataProvider()
throw()
- : mDb(0)
- , mStmt(0)
+ : mDb(nullptr)
+ , mStmt(nullptr)
{
}
@@ -199,7 +199,7 @@ void SqLiteDataProvider::disconnect()
if (sqlite3_close(mDb) != SQLITE_OK)
throw DbDisconnectionFailure(sqlite3_errmsg(mDb));
- mDb = 0;
+ mDb = nullptr;
mIsConnected = false;
}
diff --git a/src/dal/sqlitedataprovider.h b/src/dal/sqlitedataprovider.h
index c5966299..81e3a1d2 100644
--- a/src/dal/sqlitedataprovider.h
+++ b/src/dal/sqlitedataprovider.h
@@ -39,7 +39,7 @@ class SqLiteDataProvider: public DataProvider
throw();
~SqLiteDataProvider()
- throw();
+ throw() override;
/**
* Get the name of the database backend.
@@ -47,14 +47,14 @@ class SqLiteDataProvider: public DataProvider
* @return the database backend name.
*/
DbBackends getDbBackend() const
- throw();
+ throw() override;
/**
* Create a connection to the database.
*
* @exception DbConnectionFailure if unsuccessful connection.
*/
- void connect();
+ void connect() override;
/**
* Execute a SQL query.
@@ -68,35 +68,35 @@ class SqLiteDataProvider: public DataProvider
* @exception std::runtime_error if trying to query a closed database.
*/
const RecordSet &execSql(const std::string& sql,
- const bool refresh = false);
+ const bool refresh = false) override;
/**
* Close the connection to the database.
*
* @exception DbDisconnectionFailure if unsuccessful disconnection.
*/
- void disconnect();
+ void disconnect() override;
/**
* Starts a transaction.
*
* @exception std::runtime_error if a transaction is still open
*/
- void beginTransaction();
+ void beginTransaction() override;
/**
* Commits a transaction.
*
* @exception std::runtime_error if no connection is currently open.
*/
- void commitTransaction();
+ void commitTransaction() override;
/**
* Rollback a transaction.
*
* @exception std::runtime_error if no connection is currently open.
*/
- void rollbackTransaction();
+ void rollbackTransaction() override;
/**
* Returns wheter the connection has a open transaction or is in auto-
@@ -104,7 +104,7 @@ class SqLiteDataProvider: public DataProvider
*
* @return true, if a transaction is open.
*/
- bool inTransaction() const;
+ bool inTransaction() const override;
/**
* Returns the number of changed rows by the last executed SQL
@@ -112,7 +112,7 @@ class SqLiteDataProvider: public DataProvider
*
* @return Number of rows that have changed.
*/
- unsigned getModifiedRows() const;
+ unsigned getModifiedRows() const override;
/**
* Returns the last inserted value of an autoincrement column after an
@@ -120,33 +120,33 @@ class SqLiteDataProvider: public DataProvider
*
* @return last autoincrement value.
*/
- unsigned getLastId() const;
+ unsigned getLastId() const override;
/**
* Prepare SQL statement
*/
- bool prepareSql(const std::string &sql);
+ bool prepareSql(const std::string &sql) override;
/**
* Process SQL statement
* SQL statement needs to be prepared and parameters binded before
* calling this function
*/
- const RecordSet& processSql();
+ const RecordSet& processSql() override;
/**
* Bind Value (String)
* @param place - which parameter to bind to
* @param value - the string to bind
*/
- void bindValue(int place, const std::string &value);
+ void bindValue(int place, const std::string &value) override;
/**
* Bind Value (Integer)
* @param place - which parameter to bind to
* @param value - the integer to bind
*/
- void bindValue(int place, int value);
+ void bindValue(int place, int value) override;
private:
/** defines the name of the database config parameter */
diff --git a/src/game-server/abilitycomponent.cpp b/src/game-server/abilitycomponent.cpp
index c03eb03d..eb224980 100644
--- a/src/game-server/abilitycomponent.cpp
+++ b/src/game-server/abilitycomponent.cpp
@@ -59,7 +59,7 @@ void AbilityComponent::update(Entity &entity)
*/
bool AbilityComponent::takeAbility(int id)
{
- AbilityMap::iterator i = mAbilities.find(id);
+ auto i = mAbilities.find(id);
if (i != mAbilities.end())
{
mAbilities.erase(i);
@@ -106,7 +106,7 @@ bool AbilityComponent::abilityUseCheck(AbilityMap::iterator it)
*/
bool AbilityComponent::useAbilityOnBeing(Entity &user, int id, Entity *b)
{
- AbilityMap::iterator it = mAbilities.find(id);
+ auto it = mAbilities.find(id);
if (!abilityUseCheck(it))
return false;
@@ -139,7 +139,7 @@ bool AbilityComponent::useAbilityOnBeing(Entity &user, int id, Entity *b)
*/
bool AbilityComponent::useAbilityOnPoint(Entity &user, int id, int x, int y)
{
- AbilityMap::iterator it = mAbilities.find(id);
+ auto it = mAbilities.find(id);
if (!abilityUseCheck(it))
return false;
@@ -167,7 +167,7 @@ bool AbilityComponent::useAbilityOnPoint(Entity &user, int id, int x, int y)
bool AbilityComponent::useAbilityOnDirection(Entity &user, int id,
ManaServ::BeingDirection direction)
{
- AbilityMap::iterator it = mAbilities.find(id);
+ auto it = mAbilities.find(id);
if (!abilityUseCheck(it))
return false;
@@ -223,7 +223,7 @@ bool AbilityComponent::giveAbility(const AbilityManager::AbilityInfo *info)
*/
void AbilityComponent::setAbilityCooldown(int id, int ticks)
{
- AbilityMap::iterator it = mAbilities.find(id);
+ auto it = mAbilities.find(id);
if (it != mAbilities.end())
{
it->second.recharged = false;
@@ -234,7 +234,7 @@ void AbilityComponent::setAbilityCooldown(int id, int ticks)
int AbilityComponent::abilityCooldown(int id)
{
- AbilityMap::iterator it = mAbilities.find(id);
+ auto it = mAbilities.find(id);
if (it != mAbilities.end() && !it->second.recharged)
return it->second.rechargeTimeout.remaining();
diff --git a/src/game-server/abilitycomponent.h b/src/game-server/abilitycomponent.h
index d68e25ae..faf8dd04 100644
--- a/src/game-server/abilitycomponent.h
+++ b/src/game-server/abilitycomponent.h
@@ -44,7 +44,7 @@ struct AbilityValue
/**
* Stores abilities by their id.
*/
-typedef std::map<unsigned, AbilityValue> AbilityMap;
+using AbilityMap = std::map<unsigned int, AbilityValue>;
class AbilityComponent: public Component
@@ -54,7 +54,7 @@ public:
AbilityComponent();
- void update(Entity &entity);
+ void update(Entity &entity) override;
bool useAbilityOnBeing(Entity &user, int id, Entity *b);
bool useAbilityOnPoint(Entity &user, int id, int x, int y);
diff --git a/src/game-server/abilitymanager.cpp b/src/game-server/abilitymanager.cpp
index c1401284..7b5f320c 100644
--- a/src/game-server/abilitymanager.cpp
+++ b/src/game-server/abilitymanager.cpp
@@ -59,7 +59,7 @@ void AbilityManager::readAbilityNode(xmlNodePtr abilityNode,
return;
}
- AbilitiesInfo::iterator it = mAbilitiesInfo.find(id);
+ auto it = mAbilitiesInfo.find(id);
if (it != mAbilitiesInfo.end())
{
LOG_WARN("AbilityManager: The same id: " << id
@@ -70,7 +70,7 @@ void AbilityManager::readAbilityNode(xmlNodePtr abilityNode,
return;
}
- AbilityInfo *newInfo = new AbilityManager::AbilityInfo;
+ auto newInfo = new AbilityManager::AbilityInfo;
newInfo->name = name;
newInfo->id = id;
@@ -94,7 +94,7 @@ void AbilityManager::reload()
void AbilityManager::clear()
{
- for (AbilitiesInfo::iterator it = mAbilitiesInfo.begin(),
+ for (auto it = mAbilitiesInfo.begin(),
it_end = mAbilitiesInfo.end(); it != it_end; ++it)
{
delete it->second;
@@ -113,13 +113,13 @@ unsigned AbilityManager::getId(const std::string &abilityName) const
const std::string AbilityManager::getAbilityName(int id) const
{
- AbilitiesInfo::const_iterator it = mAbilitiesInfo.find(id);
+ auto it = mAbilitiesInfo.find(id);
return it != mAbilitiesInfo.end() ? it->second->name : "";
}
AbilityManager::AbilityInfo *AbilityManager::getAbilityInfo(int id) const
{
- AbilitiesInfo::const_iterator it = mAbilitiesInfo.find(id);
+ auto it = mAbilitiesInfo.find(id);
return it != mAbilitiesInfo.end() ? it->second : 0;
}
@@ -129,5 +129,5 @@ AbilityManager::AbilityInfo *AbilityManager::getAbilityInfo(
if (mNamedAbilitiesInfo.contains(abilityName))
return mNamedAbilitiesInfo.value(abilityName);
else
- return 0;
+ return nullptr;
}
diff --git a/src/game-server/abilitymanager.h b/src/game-server/abilitymanager.h
index 66249a40..27836b09 100644
--- a/src/game-server/abilitymanager.h
+++ b/src/game-server/abilitymanager.h
@@ -90,9 +90,9 @@ private:
*/
void clear();
- typedef std::map<unsigned, AbilityInfo*> AbilitiesInfo;
+ using AbilitiesInfo = std::map<unsigned int, AbilityInfo *>;
AbilitiesInfo mAbilitiesInfo;
- typedef utils::NameMap<AbilityInfo*> NamedAbilitiesInfo;
+ using NamedAbilitiesInfo = utils::NameMap<AbilityInfo *>;
NamedAbilitiesInfo mNamedAbilitiesInfo;
};
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp
index 546ae5ae..d1ac613e 100644
--- a/src/game-server/accountconnection.cpp
+++ b/src/game-server/accountconnection.cpp
@@ -43,7 +43,7 @@ const unsigned SYNC_BUFFER_SIZE = 1024;
const int SYNC_BUFFER_LIMIT = 20;
AccountConnection::AccountConnection():
- mSyncBuffer(0),
+ mSyncBuffer(nullptr),
mSyncMessages(0)
{
}
@@ -155,7 +155,7 @@ void AccountConnection::processMessage(MessageIn &msg)
case AGMSG_PLAYER_ENTER:
{
std::string token = msg.readString(MAGIC_TOKEN_LENGTH);
- Entity *character = new Entity(OBJECT_CHARACTER);
+ auto character = new Entity(OBJECT_CHARACTER);
character->addComponent(new ActorComponent(*character));
character->addComponent(new BeingComponent(*character));
character->addComponent(new CharacterComponent(*character, msg));
@@ -344,17 +344,17 @@ void AccountConnection::sendStatistics()
{
MessageOut msg(GAMSG_STATISTICS);
const MapManager::Maps &maps = MapManager::getMaps();
- for (MapManager::Maps::const_iterator i = maps.begin(),
+ for (auto i = maps.begin(),
i_end = maps.end(); i != i_end; ++i)
{
MapComposite *m = i->second;
if (!m->isActive()) continue;
msg.writeInt16(i->first);
int nbEntities = 0, nbMonsters = 0;
- typedef std::vector< Entity * > Entities;
+ using Entities = std::vector<Entity *>;
const Entities &things = m->getEverything();
std::vector< int > players;
- for (Entities::const_iterator j = things.begin(),
+ for (auto j = things.begin(),
j_end = things.end(); j != j_end; ++j)
{
Entity *t = *j;
diff --git a/src/game-server/accountconnection.h b/src/game-server/accountconnection.h
index f6ef8678..311a179c 100644
--- a/src/game-server/accountconnection.h
+++ b/src/game-server/accountconnection.h
@@ -34,7 +34,7 @@ class AccountConnection : public Connection
{
public:
AccountConnection();
- ~AccountConnection();
+ ~AccountConnection() override;
/**
* Initializes a connection to the account server described in the
@@ -173,7 +173,7 @@ class AccountConnection : public Connection
/**
* Processes server messages.
*/
- virtual void processMessage(MessageIn &);
+ void processMessage(MessageIn &) override;
private:
MessageOut* mSyncBuffer; /**< Message buffer to store sync data. */
diff --git a/src/game-server/actorcomponent.h b/src/game-server/actorcomponent.h
index 8f256923..5c472826 100644
--- a/src/game-server/actorcomponent.h
+++ b/src/game-server/actorcomponent.h
@@ -54,7 +54,7 @@ class ActorComponent : public Component
ActorComponent(Entity &entity);
- void update(Entity &entity)
+ void update(Entity &entity) override
{}
void removed(Entity *entity);
diff --git a/src/game-server/attribute.cpp b/src/game-server/attribute.cpp
index b15c2ec7..8390bc76 100644
--- a/src/game-server/attribute.cpp
+++ b/src/game-server/attribute.cpp
@@ -142,7 +142,7 @@ bool AttributeModifiersEffect::remove(double value, unsigned id,
mStates.sort(durationCompare); /* Search only through those with a duration of 0. */
bool ret = false;
- for (std::list< AttributeModifierState * >::iterator it = mStates.begin();
+ for (auto it = mStates.begin();
it != mStates.end() && (fullCheck || !(*it)->mDuration);)
{
/* Check for a match */
@@ -297,7 +297,7 @@ bool Attribute::remove(double value, unsigned layer,
bool AttributeModifiersEffect::tick()
{
bool ret = false;
- std::list<AttributeModifierState *>::iterator it = mStates.begin();
+ auto it = mStates.begin();
while (it != mStates.end())
{
if ((*it)->tick())
@@ -348,7 +348,7 @@ bool Attribute::tick()
{
bool ret = false;
double prev = mBase;
- for (std::vector<AttributeModifiersEffect *>::iterator it = mMods.begin(),
+ for (auto it = mMods.begin(),
it_end = mMods.end(); it != it_end; ++it)
{
if ((*it)->tick())
@@ -366,7 +366,7 @@ bool Attribute::tick()
void Attribute::clearMods()
{
- for (std::vector<AttributeModifiersEffect *>::iterator it = mMods.begin(),
+ for (auto it = mMods.begin(),
it_end = mMods.end(); it != it_end; ++it)
(*it)->clearMods(mBase);
}
@@ -377,7 +377,7 @@ void Attribute::setBase(double base)
LOG_DEBUG("Setting base attribute from " << mBase << " to " << base << ".");
double prev = mBase = base;
- std::vector<AttributeModifiersEffect *>::iterator it = mMods.begin();
+ auto it = mMods.begin();
while (it != mMods.end())
{
if ((*it)->recalculateModifiedValue(prev))
diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp
index 08b933a2..f54c3a62 100644
--- a/src/game-server/attributemanager.cpp
+++ b/src/game-server/attributemanager.cpp
@@ -53,7 +53,7 @@ AttributeInfo *AttributeManager::getAttributeInfo(
{
auto ret = mAttributeMap.find(id);
if (ret == mAttributeMap.end())
- return 0;
+ return nullptr;
return ret->second;
}
@@ -62,7 +62,7 @@ AttributeInfo *AttributeManager::getAttributeInfo(
{
if (mAttributeNameMap.contains(name))
return mAttributeNameMap.value(name);
- return 0;
+ return nullptr;
}
const std::set<AttributeInfo *>
@@ -86,7 +86,7 @@ const std::string *AttributeManager::getTag(const ModifierLocation &location) co
if (it.second == location)
return &it.first;
}
- return 0;
+ return nullptr;
}
/**
@@ -112,7 +112,7 @@ void AttributeManager::readAttributeNode(xmlNodePtr attributeNode)
return;
}
- AttributeInfo *attribute = new AttributeInfo(id, name);
+ auto attribute = new AttributeInfo(id, name);
attribute->persistent = XML::getBoolProperty(attributeNode, "persistent",
false);
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index 1d8ff094..c22b2e1f 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -369,19 +369,19 @@ void BeingComponent::createAttribute(AttributeInfo *attributeInfo)
const Attribute *BeingComponent::getAttribute(AttributeInfo *attribute) const
{
- AttributeMap::const_iterator ret = mAttributes.find(attribute);
+ auto ret = mAttributes.find(attribute);
if (ret == mAttributes.end())
{
LOG_DEBUG("BeingComponent::getAttribute: Attribute "
<< attribute->id << " not found! Returning 0.");
- return 0;
+ return nullptr;
}
return &ret->second;
}
double BeingComponent::getAttributeBase(AttributeInfo *attribute) const
{
- AttributeMap::const_iterator ret = mAttributes.find(attribute);
+ auto ret = mAttributes.find(attribute);
if (ret == mAttributes.end())
{
LOG_DEBUG("BeingComponent::getAttributeBase: Attribute "
@@ -394,7 +394,7 @@ double BeingComponent::getAttributeBase(AttributeInfo *attribute) const
double BeingComponent::getModifiedAttribute(AttributeInfo *attribute) const
{
- AttributeMap::const_iterator ret = mAttributes.find(attribute);
+ auto ret = mAttributes.find(attribute);
if (ret == mAttributes.end())
{
LOG_DEBUG("BeingComponent::getModifiedAttribute: Attribute "
@@ -504,14 +504,14 @@ bool BeingComponent::hasStatusEffect(int id) const
unsigned BeingComponent::getStatusEffectTime(int id) const
{
- StatusEffects::const_iterator it = mStatus.find(id);
+ auto it = mStatus.find(id);
if (it != mStatus.end()) return it->second.time;
else return 0;
}
void BeingComponent::setStatusEffectTime(int id, int time)
{
- StatusEffects::iterator it = mStatus.find(id);
+ auto it = mStatus.find(id);
if (it != mStatus.end()) it->second.time = time;
}
@@ -543,7 +543,7 @@ void BeingComponent::update(Entity &entity)
}
// Update lifetime of effects.
- for (AttributeMap::iterator it = mAttributes.begin();
+ for (auto it = mAttributes.begin();
it != mAttributes.end();
++it)
{
@@ -552,7 +552,7 @@ void BeingComponent::update(Entity &entity)
}
// Update and run status effects
- StatusEffects::iterator it = mStatus.begin();
+ auto it = mStatus.begin();
while (it != mStatus.end())
{
it->second.time--;
@@ -561,7 +561,7 @@ void BeingComponent::update(Entity &entity)
if (it->second.time <= 0 || mAction == DEAD)
{
- StatusEffects::iterator removeIt = it;
+ auto removeIt = it;
++it; // bring this iterator to the safety of the next element
mStatus.erase(removeIt);
}
diff --git a/src/game-server/being.h b/src/game-server/being.h
index a29ae747..eb03c134 100644
--- a/src/game-server/being.h
+++ b/src/game-server/being.h
@@ -38,7 +38,7 @@ class BeingComponent;
class MapComposite;
class StatusEffect;
-typedef std::map<AttributeInfo *, Attribute> AttributeMap;
+using AttributeMap = std::map<AttributeInfo *, Attribute>;
struct Status
{
@@ -46,12 +46,12 @@ struct Status
unsigned time; // Number of ticks
};
-typedef std::map< int, Status > StatusEffects;
+using StatusEffects = std::map<int, Status>;
/**
* Type definition for a list of hits
*/
-typedef std::vector<unsigned> Hits;
+using Hits = std::vector<unsigned int>;
/**
* Generic being (living actor). Keeps direction, destination and a few other
@@ -70,7 +70,7 @@ class BeingComponent : public Component
/**
* Update being state.
*/
- virtual void update(Entity &entity);
+ void update(Entity &entity) override;
/** Restores all hit points of the being */
void heal(Entity &entity);
diff --git a/src/game-server/buysell.cpp b/src/game-server/buysell.cpp
index 27b0437b..9376a307 100644
--- a/src/game-server/buysell.cpp
+++ b/src/game-server/buysell.cpp
@@ -80,7 +80,7 @@ int BuySell::registerPlayerItems()
auto *component = mChar->getComponent<CharacterComponent>();
const InventoryData &inventoryData =
component->getPossessions().getInventory();
- for (InventoryData::const_iterator it = inventoryData.begin(),
+ for (auto it = inventoryData.begin(),
it_end = inventoryData.end(); it != it_end; ++it)
{
unsigned amount = it->second.amount;
@@ -108,7 +108,7 @@ int BuySell::registerPlayerItems()
// We check if the item Id has been already
// added. If so, we cumulate the amounts.
bool itemAlreadyAdded = false;
- for (TradedItems::iterator i = mItems.begin(),
+ for (auto i = mItems.begin(),
i_end = mItems.end(); i != i_end; ++i)
{
if (i->itemId == id)
@@ -157,7 +157,7 @@ void BuySell::perform(unsigned id, int amount)
{
MessageOut msg(GPMSG_NPC_BUYSELL_RESPONSE);
- for (TradedItems::iterator i = mItems.begin(),
+ for (auto i = mItems.begin(),
i_end = mItems.end(); i != i_end; ++i)
{
if (i->itemId != id)
diff --git a/src/game-server/buysell.h b/src/game-server/buysell.h
index 259108f2..d59881ed 100644
--- a/src/game-server/buysell.h
+++ b/src/game-server/buysell.h
@@ -76,7 +76,7 @@ class BuySell
int cost;
};
- typedef std::vector< TradedItem > TradedItems;
+ using TradedItems = std::vector<TradedItem>;
/** The attribute ID of the currency to use. Hardcoded for now (FIXME) */
AttributeInfo *mCurrency;
diff --git a/src/game-server/charactercomponent.cpp b/src/game-server/charactercomponent.cpp
index 1fe7cd46..0248bbe9 100644
--- a/src/game-server/charactercomponent.cpp
+++ b/src/game-server/charactercomponent.cpp
@@ -75,7 +75,7 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg):
mParty(0),
mTransaction(TRANS_NONE),
mTalkNpcId(0),
- mNpcThread(0),
+ mNpcThread(nullptr),
mBaseEntity(&entity)
{
auto *beingComponent = entity.getComponent<BeingComponent>();
@@ -180,7 +180,7 @@ void CharacterComponent::deserialize(Entity &entity, MessageIn &msg)
int questlogSize = msg.readInt16();
for (int i = 0; i < questlogSize; ++i) {
unsigned id = msg.readInt16();
- QuestState state = (QuestState) msg.readInt8();
+ auto state = (QuestState) msg.readInt8();
std::string title = msg.readString();
std::string description = msg.readString();
@@ -280,7 +280,7 @@ void CharacterComponent::serialize(Entity &entity, MessageOut &msg)
const Possessions &poss = getPossessions();
const InventoryData &inventoryData = poss.getInventory();
- for (InventoryData::const_iterator itemIt = inventoryData.begin(),
+ for (auto itemIt = inventoryData.begin(),
itemIt_end = inventoryData.end(); itemIt != itemIt_end; ++itemIt)
{
msg.writeInt16(itemIt->first); // slot id
@@ -531,7 +531,7 @@ void CharacterComponent::attributeChanged(Entity *entity,
void CharacterComponent::incrementKillCount(int monsterType)
{
- std::map<int, int>::iterator i = mKillCount.find(monsterType);
+ auto i = mKillCount.find(monsterType);
if (i == mKillCount.end())
{
// Character has never murdered this species before
@@ -546,7 +546,7 @@ void CharacterComponent::incrementKillCount(int monsterType)
int CharacterComponent::getKillCount(int monsterType) const
{
- std::map<int, int>::const_iterator i = mKillCount.find(monsterType);
+ auto i = mKillCount.find(monsterType);
if (i != mKillCount.end())
return i->second;
return 0;
@@ -614,7 +614,7 @@ void CharacterComponent::resumeNpcThread()
gameHandler->sendTo(mClient, msg);
mTalkNpcId = 0;
- mNpcThread = 0;
+ mNpcThread = nullptr;
}
}
diff --git a/src/game-server/charactercomponent.h b/src/game-server/charactercomponent.h
index 49cd1bec..2160e1cb 100644
--- a/src/game-server/charactercomponent.h
+++ b/src/game-server/charactercomponent.h
@@ -81,9 +81,9 @@ class CharacterComponent : public Component
*/
CharacterComponent(Entity &entity, MessageIn &msg);
- ~CharacterComponent();
+ ~CharacterComponent() override;
- virtual void update(Entity &entity);
+ void update(Entity &entity) override;
/**
* Executes the global die script
diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp
index 0bf3adeb..4c51df4f 100644
--- a/src/game-server/commandhandler.cpp
+++ b/src/game-server/commandhandler.cpp
@@ -745,7 +745,7 @@ static void handleSpawn(Entity *player, std::string &args)
// create the monsters and put them on the map
for (int i = 0; i < value; ++i)
{
- Entity *monster = new Entity(OBJECT_MONSTER);
+ auto monster = new Entity(OBJECT_MONSTER);
auto *actorComponent = new ActorComponent(*monster);
monster->addComponent(actorComponent);
actorComponent->setPosition(*monster, pos);
diff --git a/src/game-server/effect.cpp b/src/game-server/effect.cpp
index af8094fd..a1af5288 100644
--- a/src/game-server/effect.cpp
+++ b/src/game-server/effect.cpp
@@ -34,7 +34,7 @@ namespace Effects
{
void show(int id, MapComposite *map, const Point &pos)
{
- Entity *effect = new Entity(OBJECT_EFFECT);
+ auto effect = new Entity(OBJECT_EFFECT);
auto *actorComponent = new ActorComponent(*effect);
effect->addComponent(actorComponent);
effect->addComponent(new EffectComponent(id));
@@ -46,10 +46,10 @@ namespace Effects
void show(int id, Entity *b)
{
- EffectComponent *effectComponent = new EffectComponent(id);
+ auto effectComponent = new EffectComponent(id);
effectComponent->setBeing(b);
- Entity *effect = new Entity(OBJECT_EFFECT);
+ auto effect = new Entity(OBJECT_EFFECT);
auto *actorComponent = new ActorComponent(*effect);
effect->addComponent(actorComponent);
effect->addComponent(effectComponent);
diff --git a/src/game-server/effect.h b/src/game-server/effect.h
index a2567a3b..2517f50f 100644
--- a/src/game-server/effect.h
+++ b/src/game-server/effect.h
@@ -36,7 +36,7 @@ class EffectComponent : public Component
EffectComponent(int id)
: mEffectId(id)
- , mBeing(0)
+ , mBeing(nullptr)
{}
int getEffectId() const
@@ -48,7 +48,7 @@ class EffectComponent : public Component
/**
* Removes effect after it has been shown.
*/
- void update(Entity &entity);
+ void update(Entity &entity) override;
void setBeing(Entity *b)
{ mBeing = b; }
diff --git a/src/game-server/emotemanager.cpp b/src/game-server/emotemanager.cpp
index c4128545..4c7e3680 100644
--- a/src/game-server/emotemanager.cpp
+++ b/src/game-server/emotemanager.cpp
@@ -61,8 +61,8 @@ void EmoteManager::checkStatus()
bool EmoteManager::isIdAvailable(int id) const
{
- std::vector<int>::const_iterator it = mEmoteIds.begin();
- std::vector<int>::const_iterator it_end = mEmoteIds.end();
+ auto it = mEmoteIds.begin();
+ auto it_end = mEmoteIds.end();
for (; it != it_end; ++it)
{
if ((*it) == id)
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index 2d122ed7..f48ac7f5 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -102,7 +102,7 @@ void GameHandler::completeServerChange(int id, const std::string &token,
for (NetComputers::const_iterator i = clients.begin(),
i_end = clients.end(); i != i_end; ++i)
{
- GameClient *c = static_cast< GameClient * >(*i);
+ auto c = static_cast< GameClient * >(*i);
if (c->status == CLIENT_CHANGE_SERVER &&
c->character->getComponent<CharacterComponent>()
->getDatabaseID() == id)
@@ -127,7 +127,7 @@ void GameHandler::updateCharacter(int charid, int partyid)
for (NetComputers::const_iterator i = clients.begin(),
i_end = clients.end(); i != i_end; ++i)
{
- GameClient *c = static_cast< GameClient * >(*i);
+ auto c = static_cast< GameClient * >(*i);
auto *characterComponent =
c->character->getComponent<CharacterComponent>();
@@ -150,7 +150,7 @@ static Entity *findActorNear(Entity *p, int id)
return e;
}
- return 0;
+ return nullptr;
}
static Entity *findBeingNear(Entity *p, int id)
@@ -159,7 +159,7 @@ static Entity *findBeingNear(Entity *p, int id)
if (e->hasComponent<BeingComponent>())
return e;
- return 0;
+ return nullptr;
}
static Entity *findCharacterNear(Entity *p, int id)
@@ -168,7 +168,7 @@ static Entity *findCharacterNear(Entity *p, int id)
if (e->getType() == OBJECT_CHARACTER)
return e;
- return 0;
+ return nullptr;
}
void GameHandler::processMessage(NetComputer *computer, MessageIn &message)
@@ -324,7 +324,7 @@ void GameHandler::addPendingCharacter(const std::string &token, Entity *ch)
for (NetComputer *i : clients)
{
- GameClient *c = static_cast< GameClient * >(i);
+ auto c = static_cast< GameClient * >(i);
Entity *old_ch = c->character;
if (old_ch && id == old_ch->getComponent<CharacterComponent>()->getDatabaseID())
{
@@ -407,10 +407,10 @@ void GameHandler::deletePendingConnect(Entity *character)
Entity *GameHandler::getCharacterByNameSlow(const std::string &name) const
{
- for (NetComputers::const_iterator i = clients.begin(),
+ for (auto i = clients.begin(),
i_end = clients.end(); i != i_end; ++i)
{
- GameClient *c = static_cast< GameClient * >(*i);
+ auto c = static_cast< GameClient * >(*i);
Entity *ch = c->character;
if (ch && ch->getComponent<BeingComponent>()->getName() == name &&
c->status == CLIENT_CONNECTED)
@@ -418,7 +418,7 @@ Entity *GameHandler::getCharacterByNameSlow(const std::string &name) const
return ch;
}
}
- return 0;
+ return nullptr;
}
void GameHandler::handleSay(GameClient &client, MessageIn &message)
@@ -492,7 +492,7 @@ void GameHandler::handlePickup(GameClient &client, MessageIn &message)
if (o->getType() == OBJECT_ITEM && opos.x == x && opos.y == y)
{
- ItemComponent *item = o->getComponent<ItemComponent>();
+ auto item = o->getComponent<ItemComponent>();
ItemClass *ic = item->getItemClass();
int amount = item->getAmount();
@@ -638,7 +638,7 @@ void GameHandler::handleUseAbilityOnBeing(GameClient &client, MessageIn &message
const int abilityID = message.readInt8();
const int targetID = message.readInt16(); // 0 when no target is selected
- Entity *being = 0;
+ Entity *being = nullptr;
if (targetID != 0)
being = findBeingNear(client.character, targetID);
@@ -675,7 +675,7 @@ void GameHandler::handleUseAbilityOnDirection(GameClient &client, MessageIn &mes
return;
const int abilityID = message.readInt8();
- const BeingDirection direction = (BeingDirection)message.readInt8();
+ const auto direction = (BeingDirection)message.readInt8();
const int publicId =
client.character->getComponent<ActorComponent>()->getPublicID();
@@ -691,8 +691,8 @@ void GameHandler::handleActionChange(GameClient &client, MessageIn &message)
{
auto *beingComponent = client.character->getComponent<BeingComponent>();
- const BeingAction action = (BeingAction) message.readInt8();
- const BeingAction current = (BeingAction) beingComponent->getAction();
+ const auto action = (BeingAction) message.readInt8();
+ const auto current = (BeingAction) beingComponent->getAction();
bool logActionChange = true;
switch (action)
@@ -733,7 +733,7 @@ void GameHandler::handleActionChange(GameClient &client, MessageIn &message)
void GameHandler::handleDirectionChange(GameClient &client, MessageIn &message)
{
- const BeingDirection direction = (BeingDirection) message.readInt8();
+ const auto direction = (BeingDirection) message.readInt8();
client.character->getComponent<BeingComponent>()
->setDirection(*client.character, direction);
}
@@ -761,7 +761,7 @@ void GameHandler::handleDisconnect(GameClient &client, MessageIn &message)
characterComponent->disconnected(*client.character);
delete client.character;
- client.character = 0;
+ client.character = nullptr;
client.status = CLIENT_LOGIN;
client.send(result);
diff --git a/src/game-server/gamehandler.h b/src/game-server/gamehandler.h
index 4134704e..75855cf4 100644
--- a/src/game-server/gamehandler.h
+++ b/src/game-server/gamehandler.h
@@ -114,13 +114,13 @@ class GameHandler: public ConnectionHandler
Entity *getCharacterByNameSlow(const std::string &) const;
protected:
- NetComputer *computerConnected(ENetPeer *);
- void computerDisconnected(NetComputer *);
+ NetComputer *computerConnected(ENetPeer *) override;
+ void computerDisconnected(NetComputer *) override;
/**
* Processes messages related to core game events.
*/
- void processMessage(NetComputer *computer, MessageIn &message);
+ void processMessage(NetComputer *computer, MessageIn &message) override;
private:
void handleSay(GameClient &client, MessageIn &message);
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp
index ee42c9a4..4b15f4cf 100644
--- a/src/game-server/inventory.cpp
+++ b/src/game-server/inventory.cpp
@@ -66,10 +66,10 @@ void Inventory::initialize()
/*
* Set the equipment slots
*/
- for (EquipData::iterator it = mPoss->equipment.begin(),
+ for (auto it = mPoss->equipment.begin(),
it_end = mPoss->equipment.end(); it != it_end; ++it)
{
- InventoryData::iterator 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;
@@ -84,7 +84,7 @@ void Inventory::initialize()
/*
* Construct a set of itemIds to keep track of duplicate itemIds.
*/
- for (InventoryData::iterator it = mPoss->inventory.begin(),
+ for (auto it = mPoss->inventory.begin(),
it_end = mPoss->inventory.end(); it != it_end;)
{
ItemClass *item = itemManager->getItem(it->second.itemId);
@@ -116,7 +116,7 @@ void Inventory::initialize()
unsigned Inventory::getItem(unsigned slot) const
{
- InventoryData::iterator item = mPoss->inventory.find(slot);
+ auto item = mPoss->inventory.find(slot);
return item != mPoss->inventory.end() ? item->second.itemId : 0;
}
@@ -207,7 +207,7 @@ unsigned Inventory::insert(unsigned itemId, unsigned amount)
unsigned Inventory::count(unsigned itemId) const
{
unsigned nb = 0;
- for (InventoryData::iterator it = mPoss->inventory.begin(),
+ for (auto it = mPoss->inventory.begin(),
it_end = mPoss->inventory.end(); it != it_end; ++it)
{
if (it->second.itemId == itemId)
@@ -219,7 +219,7 @@ unsigned Inventory::count(unsigned itemId) const
int Inventory::getFirstSlot(unsigned itemId)
{
- for (InventoryData::iterator it = mPoss->inventory.begin(),
+ for (auto it = mPoss->inventory.begin(),
it_end = mPoss->inventory.end(); it != it_end; ++it)
if (it->second.itemId == itemId)
return (int)it->first;
@@ -238,7 +238,7 @@ unsigned Inventory::remove(unsigned itemId, unsigned amount)
MessageOut invMsg(GPMSG_INVENTORY);
bool triggerLeaveInventory = true;
- for (InventoryData::iterator it = mPoss->inventory.begin();
+ for (auto it = mPoss->inventory.begin();
it != mPoss->inventory.end();)
{
LOG_DEBUG("Remove: Treating slot id: " << it->first);
@@ -291,7 +291,7 @@ unsigned Inventory::remove(unsigned itemId, unsigned amount)
unsigned Inventory::removeFromSlot(unsigned slot, unsigned amount)
{
- InventoryData::iterator it = mPoss->inventory.find(slot);
+ auto it = mPoss->inventory.find(slot);
// When the given slot doesn't exist, we can't remove anything
if (it == mPoss->inventory.end())
@@ -354,8 +354,8 @@ void Inventory::updateEquipmentTrigger(unsigned oldId, unsigned newId)
{
if (!oldId && !newId)
return;
- updateEquipmentTrigger(oldId ? itemManager->getItem(oldId) : 0,
- newId ? itemManager->getItem(newId) : 0);
+ updateEquipmentTrigger(oldId ? itemManager->getItem(oldId) : nullptr,
+ newId ? itemManager->getItem(newId) : nullptr);
}
void Inventory::updateEquipmentTrigger(ItemClass *oldI, ItemClass *newI)
@@ -382,10 +382,10 @@ bool Inventory::checkEquipmentCapacity(unsigned equipmentSlot,
return false;
// Test whether the slot capacity requested is reached.
- for (EquipData::const_iterator it = mPoss->equipment.begin(),
+ for (auto it = mPoss->equipment.begin(),
it_end = mPoss->equipment.end(); it != it_end; ++it)
{
- InventoryData::iterator itemIt = mPoss->inventory.find(*it);
+ auto itemIt = mPoss->inventory.find(*it);
if (itemIt->second.equipmentSlot == equipmentSlot)
{
const int itemId = itemIt->second.itemId;
@@ -460,11 +460,11 @@ bool Inventory::equip(int inventorySlot)
&& hasInventoryEnoughSpace(equipReq.equipSlotId))
{
// Then, we unequip each iteminstance of the equip slot
- for (EquipData::iterator it = mPoss->equipment.begin(),
+ for (auto it = mPoss->equipment.begin(),
it_end = mPoss->equipment.end(); it != it_end; ++it)
{
const unsigned slot = *it;
- InventoryData::iterator itemIt = mPoss->inventory.find(slot);
+ auto itemIt = mPoss->inventory.find(slot);
assert(itemIt != mPoss->inventory.end());
if (itemIt->second.equipmentSlot == equipReq.equipSlotId) {
slotsToUnequipFirst.insert(itemIt->first);
@@ -481,7 +481,7 @@ bool Inventory::equip(int inventorySlot)
}
// Potential Pre-unequipment process
- for (std::set<unsigned>::const_iterator itemsToUnequip =
+ for (auto itemsToUnequip =
slotsToUnequipFirst.begin(),
itemsToUnequip_end = slotsToUnequipFirst.end();
itemsToUnequip != itemsToUnequip_end; ++itemsToUnequip)
@@ -535,7 +535,7 @@ bool Inventory::unequipAll(unsigned itemId)
bool Inventory::unequip(unsigned itemSlot)
{
- InventoryData::iterator it = mPoss->inventory.find(itemSlot);
+ auto it = mPoss->inventory.find(itemSlot);
if (it == mPoss->inventory.end())
{
LOG_DEBUG("Tried to unequip invalid item at slot " << itemSlot);
diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp
index 5e5ca3d9..dc97ed66 100644
--- a/src/game-server/item.cpp
+++ b/src/game-server/item.cpp
@@ -151,12 +151,12 @@ void ItemComponent::update(Entity &entity)
namespace Item {
Entity *create(MapComposite *map,
- Point pos,
- ItemClass *itemClass,
- int amount)
+ Point pos,
+ ItemClass *itemClass,
+ int amount)
{
- Entity *itemActor = new Entity(OBJECT_ITEM);
- ActorComponent *actorComponent = new ActorComponent(*itemActor);
+ auto itemActor = new Entity(OBJECT_ITEM);
+ auto actorComponent = new ActorComponent(*itemActor);
itemActor->addComponent(actorComponent);
itemActor->addComponent(new ItemComponent(itemClass, amount));
itemActor->setMap(map);
diff --git a/src/game-server/item.h b/src/game-server/item.h
index c8ee225e..d8f686ba 100644
--- a/src/game-server/item.h
+++ b/src/game-server/item.h
@@ -92,8 +92,8 @@ class ItemEffectAttrMod : public ItemEffectInfo
, mModId(modId)
{}
- bool apply(Entity *itemUser);
- void dispell(Entity *itemUser);
+ bool apply(Entity *itemUser) override;
+ void dispell(Entity *itemUser) override;
private:
AttributeInfo *mAttribute;
@@ -106,9 +106,9 @@ class ItemEffectAttrMod : public ItemEffectInfo
class ItemEffectConsumes : public ItemEffectInfo
{
public:
- bool apply(Entity *)
+ bool apply(Entity *) override
{ return true; }
- void dispell(Entity *)
+ void dispell(Entity *) override
{}
};
@@ -123,10 +123,10 @@ class ItemEffectScript : public ItemEffectInfo
mDispellEventName(dispellEventName)
{}
- ~ItemEffectScript();
+ ~ItemEffectScript() override;
- bool apply(Entity *itemUser);
- void dispell(Entity *itemUser);
+ bool apply(Entity *itemUser) override;
+ void dispell(Entity *itemUser) override;
private:
ItemClass *mItemClass;
@@ -264,7 +264,7 @@ class ItemComponent : public Component
int getAmount() const
{ return mAmount; }
- void update(Entity &entity);
+ void update(Entity &entity) override;
private:
ItemClass *mType;
diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp
index 1ca61a65..8a8f2092 100644
--- a/src/game-server/itemmanager.cpp
+++ b/src/game-server/itemmanager.cpp
@@ -45,13 +45,13 @@ void ItemManager::initialize()
void ItemManager::deinitialize()
{
- for (ItemClasses::iterator i = mItemClasses.begin(),
+ for (auto i = mItemClasses.begin(),
i_end = mItemClasses.end(); i != i_end; ++i)
{
delete i->second;
}
- for (std::map< unsigned, EquipSlotInfo* >::iterator it =
+ for (auto it =
mEquipSlotsInfo.begin(), it_end = mEquipSlotsInfo.end(); it != it_end;
++it)
{
@@ -64,7 +64,7 @@ void ItemManager::deinitialize()
ItemClass *ItemManager::getItem(int itemId) const
{
- ItemClasses::const_iterator i = mItemClasses.find(itemId);
+ auto i = mItemClasses.find(itemId);
return i != mItemClasses.end() ? i->second : 0;
}
@@ -86,13 +86,13 @@ unsigned ItemManager::getEquipSlotIdFromName(const std::string &name) const
unsigned ItemManager::getEquipSlotCapacity(unsigned id) const
{
- EquipSlotsInfo::const_iterator i = mEquipSlotsInfo.find(id);
+ auto i = mEquipSlotsInfo.find(id);
return i != mEquipSlotsInfo.end() ? i->second->slotCapacity : 0;
}
bool ItemManager::isEquipSlotVisible(unsigned id) const
{
- EquipSlotsInfo::const_iterator i = mEquipSlotsInfo.find(id);
+ auto i = mEquipSlotsInfo.find(id);
return i != mEquipSlotsInfo.end() ? i->second->visibleSlot : false;
}
@@ -137,8 +137,7 @@ void ItemManager::readEquipSlotNode(xmlNodePtr node)
if (visible)
++mVisibleEquipSlotCount;
- EquipSlotsInfo::iterator i = mEquipSlotsInfo.find(slotId);
-
+ auto i = mEquipSlotsInfo.find(slotId);
if (i != mEquipSlotsInfo.end())
{
LOG_WARN("Item Manager: Ignoring duplicate definition "
@@ -148,8 +147,7 @@ void ItemManager::readEquipSlotNode(xmlNodePtr node)
LOG_DEBUG("Adding equip slot, id: " << slotId << ", name: " << name
<< ", capacity: " << capacity << ", visible? " << visible);
- EquipSlotInfo *equipSlotInfo =
- new EquipSlotInfo(slotId, name, capacity, visible);
+ auto equipSlotInfo = new EquipSlotInfo(slotId, name, capacity, visible);
mEquipSlotsInfo.insert(std::make_pair(slotId, equipSlotInfo));
mNamedEquipSlotsInfo.insert(name, equipSlotInfo);
}
@@ -173,8 +171,7 @@ void ItemManager::readItemNode(xmlNodePtr itemNode, const std::string &filename)
if (type == "hairsprite" || type == "racesprite")
return;
- ItemClasses::iterator i = mItemClasses.find(id);
-
+ auto i = mItemClasses.find(id);
if (i != mItemClasses.end())
{
LOG_WARN("Item Manager: Ignoring duplicate definition of item '" << id
@@ -190,7 +187,7 @@ void ItemManager::readItemNode(xmlNodePtr itemNode, const std::string &filename)
maxPerSlot = 1;
}
- ItemClass *item = new ItemClass(id, maxPerSlot);
+ auto item = new ItemClass(id, maxPerSlot);
mItemClasses.insert(std::make_pair(id, item));
const std::string name = XML::getProperty(itemNode, "name", std::string());
@@ -301,9 +298,7 @@ void ItemManager::readEffectNode(xmlNodePtr effectNode, ItemClass *item)
triggerTable["null"].dispell = ITT_NULL;
}
- std::map<const std::string, ItemTrigger>::iterator
- it = triggerTable.find(triggerName);
-
+ auto it = triggerTable.find(triggerName);
if (it == triggerTable.end()) {
LOG_WARN("Item Manager: Unable to find effect trigger type \""
<< triggerName << "\", skipping!");
diff --git a/src/game-server/itemmanager.h b/src/game-server/itemmanager.h
index ac3c0b84..cce0e2b8 100644
--- a/src/game-server/itemmanager.h
+++ b/src/game-server/itemmanager.h
@@ -111,14 +111,14 @@ class ItemManager
void readEquipNode(xmlNodePtr equipNode, ItemClass *item);
void readEffectNode(xmlNodePtr effectNode, ItemClass *item);
- typedef std::map< int, ItemClass * > ItemClasses;
+ using ItemClasses = std::map<int, ItemClass *>;
ItemClasses mItemClasses; /**< Item reference */
utils::NameMap<ItemClass*> mItemClassesByName;
// Map an equip slot id with the equip slot info.
- typedef std::map< unsigned, EquipSlotInfo* > EquipSlotsInfo;
+ using EquipSlotsInfo = std::map<unsigned int, EquipSlotInfo *>;
// Reference to the vector position of equipSlots
- typedef std::vector< unsigned > VisibleEquipSlots;
+ using VisibleEquipSlots = std::vector<unsigned int>;
EquipSlotsInfo mEquipSlotsInfo;
// Map a string (name of slot) with (str-id, max-per-equip-slot)
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index 7b78bc21..970474cd 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -175,18 +175,18 @@ static void deinitializeServer()
enet_deinitialize();
// Destroy message handlers
- delete gameHandler; gameHandler = 0;
- delete accountHandler; accountHandler = 0;
- delete postMan; postMan = 0;
- delete gBandwidth; gBandwidth = 0;
+ delete gameHandler; gameHandler = nullptr;
+ delete accountHandler; accountHandler = nullptr;
+ delete postMan; postMan = nullptr;
+ delete gBandwidth; gBandwidth = nullptr;
// Destroy Managers
- delete stringFilter; stringFilter = 0;
- delete monsterManager; monsterManager = 0;
- delete abilityManager; abilityManager = 0;
- delete itemManager; itemManager = 0;
- delete emoteManager; emoteManager = 0;
- delete settingsManager; settingsManager = 0;
+ delete stringFilter; stringFilter = nullptr;
+ delete monsterManager; monsterManager = nullptr;
+ delete abilityManager; abilityManager = nullptr;
+ delete itemManager; itemManager = nullptr;
+ delete emoteManager; emoteManager = nullptr;
+ delete settingsManager; settingsManager = nullptr;
MapManager::deinitialize();
StatusManager::deinitialize();
ScriptManager::deinitialize();
@@ -243,11 +243,11 @@ static void parseOptions(int argc, char *argv[], CommandLineOptions &options)
const struct option longOptions[] =
{
- { "help", no_argument, 0, 'h' },
- { "config", required_argument, 0, 'c' },
- { "verbosity", required_argument, 0, 'v' },
- { "port", required_argument, 0, 'p' },
- { 0, 0, 0, 0 }
+ { "help", no_argument, nullptr, 'h' },
+ { "config", required_argument, nullptr, 'c' },
+ { "verbosity", required_argument, nullptr, 'v' },
+ { "port", required_argument, nullptr, 'p' },
+ { nullptr, 0, nullptr, 0 }
};
while (optind < argc)
diff --git a/src/game-server/map.cpp b/src/game-server/map.cpp
index b4e66e02..0f7fea60 100644
--- a/src/game-server/map.cpp
+++ b/src/game-server/map.cpp
@@ -109,7 +109,7 @@ Map::Map(int width, int height, int tileWidth, int tileHeight):
Map::~Map()
{
- for (std::vector<MapObject*>::iterator it = mMapObjects.begin();
+ for (auto it = mMapObjects.begin();
it != mMapObjects.end(); ++it)
{
delete *it;
diff --git a/src/game-server/map.h b/src/game-server/map.h
index 33663d37..715843d3 100644
--- a/src/game-server/map.h
+++ b/src/game-server/map.h
@@ -30,7 +30,7 @@
#include "utils/point.h"
#include "utils/string.h"
-typedef std::list<Point> Path;
+using Path = std::list<Point>;
enum BlockType
{
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp
index 41073b3c..0b0773b6 100644
--- a/src/game-server/mapcomposite.cpp
+++ b/src/game-server/mapcomposite.cpp
@@ -417,8 +417,7 @@ Entity *MapContent::findEntityById(int publicId) const
static void addZone(MapRegion &r, unsigned z)
{
- MapRegion::iterator i_end = r.end(),
- i = std::lower_bound(r.begin(), i_end, z);
+ auto i_end = r.end(), i = std::lower_bound(r.begin(), i_end, z);
if (i == i_end || *i != z)
{
r.insert(i, z);
@@ -596,8 +595,8 @@ Script::Ref MapComposite::mUpdateCallback;
MapComposite::MapComposite(int id, const std::string &name):
mActive(false),
- mMap(0),
- mContent(0),
+ mMap(nullptr),
+ mContent(nullptr),
mName(name),
mID(id),
mPvPRules(PVP_NONE)
@@ -681,7 +680,7 @@ ZoneIterator MapComposite::getAroundBeingIterator(Entity *obj, int radius) const
obj->getComponent<BeingComponent>()->getOldPosition(),
radius);
MapRegion r2 = r1;
- for (MapRegion::iterator i = r1.begin(), i_end = r1.end(); i != i_end; ++i)
+ for (auto i = r1.begin(), i_end = r1.end(); i != i_end; ++i)
{
/* Fills region with destinations taken around the old position.
This is necessary to detect two moving objects changing zones at the
@@ -722,7 +721,7 @@ bool MapComposite::insert(Entity *ptr)
void MapComposite::remove(Entity *ptr)
{
- for (std::vector<Entity*>::iterator i = mContent->entities.begin(),
+ for (auto i = mContent->entities.begin(),
i_end = mContent->entities.end(); i != i_end; ++i)
{
if (*i == ptr)
@@ -753,7 +752,7 @@ void MapComposite::update()
{
// Update object status
const std::vector< Entity * > &entities = getEverything();
- for (std::vector< Entity * >::const_iterator it = entities.begin(),
+ for (auto it = entities.begin(),
it_end = entities.end(); it != it_end; ++it)
{
(*it)->update();
@@ -779,7 +778,7 @@ void MapComposite::update()
}
// Cannot use a WholeMap iterator as objects will change zones under its feet.
- for (std::vector< Entity * >::iterator i = mContent->entities.begin(),
+ for (auto i = mContent->entities.begin(),
i_end = mContent->entities.end(); i != i_end; ++i)
{
if (!(*i)->canMove())
@@ -809,7 +808,7 @@ const std::vector< Entity * > &MapComposite::getEverything() const
std::string MapComposite::getVariable(const std::string &key) const
{
- std::map<std::string, std::string>::const_iterator i = mScriptVariables.find(key);
+ auto i = mScriptVariables.find(key);
if (i != mScriptVariables.end())
return i->second;
else
@@ -819,7 +818,7 @@ std::string MapComposite::getVariable(const std::string &key) const
void MapComposite::setVariable(const std::string &key, const std::string &value)
{
// check if the value actually changed
- std::map<std::string, std::string>::iterator i = mScriptVariables.find(key);
+ auto i = mScriptVariables.find(key);
if (i == mScriptVariables.end() || i->second != value)
{
// changed value or unknown variable
@@ -846,8 +845,7 @@ static void callVariableCallback(Script::Ref &function, const std::string &key,
void MapComposite::callMapVariableCallback(const std::string &key,
const std::string &value)
{
- std::map<const std::string, Script::Ref>::iterator it =
- mMapVariableCallbacks.find(key);
+ auto it = mMapVariableCallbacks.find(key);
if (it == mMapVariableCallbacks.end())
return;
callVariableCallback(it->second, key, value, this);
@@ -856,8 +854,7 @@ void MapComposite::callMapVariableCallback(const std::string &key,
void MapComposite::callWorldVariableCallback(const std::string &key,
const std::string &value)
{
- std::map<const std::string, Script::Ref>::iterator it =
- mWorldVariableCallbacks.find(key);
+ auto it = mWorldVariableCallbacks.find(key);
if (it == mWorldVariableCallbacks.end())
return;
callVariableCallback(it->second, key, value, this);
@@ -882,7 +879,7 @@ const MapObject *MapComposite::findMapObject(const std::string &name,
return obj;
}
}
- return 0; // nothing found
+ return nullptr; // nothing found
}
/**
@@ -1011,7 +1008,7 @@ void MapComposite::initializeContent()
}
// add this trigger to the map
- Entity *entity = new Entity(OBJECT_OTHER, this);
+ auto entity = new Entity(OBJECT_OTHER, this);
entity->addComponent(
new TriggerAreaComponent(
sourceBounds,
@@ -1023,7 +1020,7 @@ void MapComposite::initializeContent()
}
else if (utils::compareStrI(type, "SPAWN") == 0)
{
- MonsterClass *monster = 0;
+ MonsterClass *monster = nullptr;
int maxBeings = utils::stringToInt(object->getProperty("MAX_BEINGS"));
int spawnRate = utils::stringToInt(object->getProperty("SPAWN_RATE"));
std::string monsterName = object->getProperty("MONSTER_ID");
@@ -1050,8 +1047,8 @@ void MapComposite::initializeContent()
if (monster && maxBeings && spawnRate)
{
- Entity *entity = new Entity(OBJECT_OTHER, this);
- SpawnAreaComponent *spawnArea =
+ auto entity = new Entity(OBJECT_OTHER, this);
+ auto spawnArea =
new SpawnAreaComponent(monster, object->getBounds(),
maxBeings, spawnRate);
diff --git a/src/game-server/mapcomposite.h b/src/game-server/mapcomposite.h
index b428074e..cd46f740 100644
--- a/src/game-server/mapcomposite.h
+++ b/src/game-server/mapcomposite.h
@@ -47,7 +47,7 @@ enum PvPRules
/**
* Ordered sets of zones of a map.
*/
-typedef std::vector< unsigned > MapRegion;
+using MapRegion = std::vector<unsigned int>;
/**
* Iterates through the zones of a region of the map.
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp
index f3e9fcf2..17ddd2f8 100644
--- a/src/game-server/mapmanager.cpp
+++ b/src/game-server/mapmanager.cpp
@@ -49,7 +49,7 @@ void MapManager::initialize()
*/
void MapManager::deinitialize()
{
- for (Maps::iterator i = maps.begin(), i_end = maps.end(); i != i_end; ++i)
+ for (auto i = maps.begin(), i_end = maps.end(); i != i_end; ++i)
{
delete i->second;
}
@@ -139,7 +139,7 @@ MapComposite *MapManager::getMap(const std::string &mapName)
bool MapManager::activateMap(int mapId)
{
- Maps::iterator i = maps.find(mapId);
+ auto i = maps.find(mapId);
assert(i != maps.end());
MapComposite *composite = i->second;
diff --git a/src/game-server/mapmanager.h b/src/game-server/mapmanager.h
index b1b47591..0c1b77ef 100644
--- a/src/game-server/mapmanager.h
+++ b/src/game-server/mapmanager.h
@@ -31,7 +31,7 @@ class MapComposite;
namespace MapManager
{
- typedef std::map< int, MapComposite * > Maps;
+ using Maps = std::map<int, MapComposite *>;
void initialize();
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index acac6856..91f481d6 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -42,7 +42,7 @@ Map *MapReader::readMap(const std::string &filename)
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "map"))
{
LOG_ERROR("Error: Not a map file (" << filename << ")!");
- return 0;
+ return nullptr;
}
return readMap(rootNode);
@@ -114,7 +114,7 @@ Map *MapReader::readMap(xmlNodePtr node)
int objH = XML::getProperty(objectNode, "height", 0);
Rectangle rect = { objX, objY, objW, objH };
- MapObject *newObject = new MapObject(rect, objName, objType);
+ auto newObject = new MapObject(rect, objName, objType);
for_each_xml_child_node(propertiesNode, objectNode)
{
@@ -181,8 +181,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
}
int len = strlen((const char *) dataChild->content) + 1;
- char *charData = new char[len + 1];
- const char *charStart = (const char *) dataChild->content;
+ auto charData = new char[len + 1];
+ const auto *charStart = (const char *) dataChild->content;
char *charIndex = charData;
while (*charStart)
@@ -252,7 +252,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
if (!dataChild)
return;
- const char *data = (const char*) xmlNodeGetContent(dataChild);
+ const auto data = (const char*) xmlNodeGetContent(dataChild);
std::string csv(data);
size_t pos = 0;
@@ -311,7 +311,7 @@ std::string MapReader::getObjectProperty(xmlNodePtr node,
{
return XML::getProperty(node, "value", def);
}
- else if (const char *prop = (const char *)node->xmlChildrenNode->content)
+ else if (const auto prop = (const char *)node->xmlChildrenNode->content)
{
return std::string(prop);
}
@@ -325,7 +325,7 @@ int MapReader::getObjectProperty(xmlNodePtr node, int def)
{
val = XML::getProperty(node, "value", def);
}
- else if (const char *prop = (const char *)node->xmlChildrenNode->content)
+ else if (const auto prop = (const char *)node->xmlChildrenNode->content)
{
val = atoi(prop);
}
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 56a08cd9..0688abf7 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -78,7 +78,7 @@ MonsterComponent::MonsterComponent(Entity &entity, MonsterClass *specy):
beingComponent->setGender(specy->getGender());
beingComponent->setName(specy->getName());
- AbilityComponent *abilityComponent = new AbilityComponent();
+ auto abilityComponent = new AbilityComponent();
entity.addComponent(abilityComponent);
for (auto *abilitiyInfo : specy->getAbilities())
{
diff --git a/src/game-server/monster.h b/src/game-server/monster.h
index 618e1e9d..a6b17369 100644
--- a/src/game-server/monster.h
+++ b/src/game-server/monster.h
@@ -51,9 +51,9 @@ struct MonsterDrop
int probability;
};
-typedef std::vector< MonsterDrop > MonsterDrops;
+using MonsterDrops = std::vector<MonsterDrop>;
-typedef std::map<Element, double> Vulnerabilities;
+using Vulnerabilities = std::map<Element, double>;
/**
* Class describing the characteristics of a generic monster.
@@ -173,7 +173,7 @@ class MonsterComponent : public Component
/**
* Performs one step of controller logic.
*/
- void update(Entity &entity);
+ void update(Entity &entity) override;
/**
* Signal handler
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index a5acd126..4f0ba519 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -44,7 +44,7 @@ void MonsterManager::initialize()
void MonsterManager::deinitialize()
{
- for (MonsterClasses::iterator i = mMonsterClasses.begin(),
+ for (auto i = mMonsterClasses.begin(),
i_end = mMonsterClasses.end(); i != i_end; ++i)
{
delete i->second;
@@ -60,7 +60,7 @@ MonsterClass *MonsterManager::getMonsterByName(const std::string &name) const
MonsterClass *MonsterManager::getMonster(int id) const
{
- MonsterClasses::const_iterator i = mMonsterClasses.find(id);
+ auto i = mMonsterClasses.find(id);
return i != mMonsterClasses.end() ? i->second : 0;
}
@@ -84,7 +84,7 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
return;
}
- MonsterClasses::iterator i = mMonsterClasses.find(monsterId);
+ auto i = mMonsterClasses.find(monsterId);
if (i != mMonsterClasses.end())
{
LOG_WARN("Monster Manager: Ignoring duplicate definition of "
@@ -92,7 +92,7 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
return;
}
- MonsterClass *monster = new MonsterClass(monsterId);
+ auto monster = new MonsterClass(monsterId);
mMonsterClasses[monsterId] = monster;
if (!name.empty())
@@ -194,7 +194,7 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
{
const std::string idText = XML::getProperty(subnode, "id",
std::string());
- AbilityManager::AbilityInfo *info = 0;
+ AbilityManager::AbilityInfo *info = nullptr;
if (utils::isNumeric(idText))
{
const int abilityId = utils::stringToInt(idText);
diff --git a/src/game-server/monstermanager.h b/src/game-server/monstermanager.h
index c00d24fd..d299a85a 100644
--- a/src/game-server/monstermanager.h
+++ b/src/game-server/monstermanager.h
@@ -29,7 +29,7 @@
class MonsterClass;
-typedef std::map< int, MonsterClass * > MonsterClasses;
+using MonsterClasses = std::map<int, MonsterClass *>;
class MonsterManager
{
diff --git a/src/game-server/npc.cpp b/src/game-server/npc.cpp
index 2b6ab1fd..bcc62d33 100644
--- a/src/game-server/npc.cpp
+++ b/src/game-server/npc.cpp
@@ -76,7 +76,7 @@ static Script *prepareResume(Entity *ch, Script::ThreadState expectedState)
Script::Thread *thread =
ch->getComponent<CharacterComponent>()->getNpcThread();
if (!thread || thread->mState != expectedState)
- return 0;
+ return nullptr;
Script *script = ScriptManager::currentState();
script->prepareResume(thread);
@@ -85,7 +85,7 @@ static Script *prepareResume(Entity *ch, Script::ThreadState expectedState)
void Npc::start(Entity *npc, Entity *ch)
{
- NpcComponent *npcComponent = npc->getComponent<NpcComponent>();
+ auto npcComponent = npc->getComponent<NpcComponent>();
Script *script = ScriptManager::currentState();
Script::Ref talkCallback = npcComponent->getTalkCallback();
diff --git a/src/game-server/npc.h b/src/game-server/npc.h
index 98fbd64d..d66b9bfc 100644
--- a/src/game-server/npc.h
+++ b/src/game-server/npc.h
@@ -37,7 +37,7 @@ class NpcComponent : public Component
NpcComponent(int npcId);
- ~NpcComponent();
+ ~NpcComponent() override;
/**
* Sets the function that should be called when this NPC is talked to.
@@ -55,7 +55,7 @@ class NpcComponent : public Component
/**
* Calls the update callback, if any.
*/
- void update(Entity &entity);
+ void update(Entity &entity) override;
/**
* Sets whether the NPC is enabled.
diff --git a/src/game-server/quest.cpp b/src/game-server/quest.cpp
index 4ed8a6fc..3a049eaa 100644
--- a/src/game-server/quest.cpp
+++ b/src/game-server/quest.cpp
@@ -31,8 +31,8 @@
#include <sigc++/connection.h>
-typedef std::list< QuestCallback * > QuestCallbacks;
-typedef std::map< std::string, QuestCallbacks > PendingVariables;
+using QuestCallbacks = std::list<QuestCallback *>;
+using PendingVariables = std::map<std::string, QuestCallbacks>;
struct PendingQuest
{
@@ -42,14 +42,13 @@ struct PendingQuest
PendingVariables variables;
};
-typedef std::map< int, PendingQuest > PendingQuests;
+using PendingQuests = std::map<int, PendingQuest>;
static PendingQuests pendingQuests;
bool getQuestVar(Entity *ch, const std::string &name, std::string &value)
{
- std::map< std::string, std::string >::iterator
- i = ch->getComponent<CharacterComponent>()->questCache.find(name);
+ auto i = ch->getComponent<CharacterComponent>()->questCache.find(name);
if (i == ch->getComponent<CharacterComponent>()->questCache.end())
return false;
value = i->second;
@@ -62,8 +61,7 @@ void setQuestVar(Entity *ch, const std::string &name,
auto *characterComponent =
ch->getComponent<CharacterComponent>();
- std::map< std::string, std::string >::iterator
- i = characterComponent->questCache.lower_bound(name);
+ auto i = characterComponent->questCache.lower_bound(name);
if (i == characterComponent->questCache.end() || i->first != name)
{
characterComponent->questCache.insert(i, std::make_pair(name, value));
@@ -98,7 +96,7 @@ 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 (PendingVariables::iterator i = variables.begin(),
+ for (auto i = variables.begin(),
i_end = variables.end(); i != i_end; ++i)
{
i->second.clear();
@@ -129,7 +127,7 @@ void recoverQuestVar(Entity *ch, const std::string &name,
assert(characterComponent->questCache.find(name) ==
characterComponent->questCache.end());
int id = ch->getComponent<CharacterComponent>()->getDatabaseID();
- PendingQuests::iterator i = pendingQuests.lower_bound(id);
+ auto i = pendingQuests.lower_bound(id);
if (i == pendingQuests.end() || i->first != id)
{
PendingQuest pendingQuest;
@@ -155,7 +153,7 @@ void recoveredQuestVar(int id,
const std::string &name,
const std::string &value)
{
- PendingQuests::iterator i = pendingQuests.find(id);
+ auto i = pendingQuests.find(id);
if (i == pendingQuests.end())
return;
@@ -164,7 +162,7 @@ void recoveredQuestVar(int id,
pendingQuest.disconnectedConnection.disconnect();
PendingVariables &variables = pendingQuest.variables;
- PendingVariables::iterator j = variables.find(name);
+ auto j = variables.find(name);
if (j == variables.end())
{
LOG_ERROR("Account server recovered an unexpected quest variable.");
diff --git a/src/game-server/quest.h b/src/game-server/quest.h
index bfc1f874..4344f1c9 100644
--- a/src/game-server/quest.h
+++ b/src/game-server/quest.h
@@ -42,9 +42,7 @@ class QuestCallback
class QuestThreadCallback : public QuestCallback
{
public:
- typedef void (*Handler)(Entity *,
- const std::string &value,
- Script *mScript);
+ using Handler = void (*)(Entity *, const std::string &, Script *);
QuestThreadCallback(Handler handler,
Script *script) :
@@ -52,7 +50,7 @@ class QuestThreadCallback : public QuestCallback
mScript(script)
{ }
- void triggerCallback(Entity *ch, const std::string &value) const
+ void triggerCallback(Entity *ch, const std::string &value) const override
{ mHandler(ch, value, mScript); }
private:
@@ -67,7 +65,7 @@ class QuestRefCallback : public QuestCallback
mQuestName(questName)
{ script->assignCallback(mRef); }
- void triggerCallback(Entity *ch, const std::string &value) const;
+ void triggerCallback(Entity *ch, const std::string &value) const override;
private:
Script::Ref mRef;
diff --git a/src/game-server/spawnareacomponent.cpp b/src/game-server/spawnareacomponent.cpp
index da715f4f..15e24b3a 100644
--- a/src/game-server/spawnareacomponent.cpp
+++ b/src/game-server/spawnareacomponent.cpp
@@ -64,7 +64,7 @@ void SpawnAreaComponent::update(Entity &entity)
const int width = mZone.w;
const int height = mZone.h;
- Entity *being = new Entity(OBJECT_MONSTER);
+ auto being = new Entity(OBJECT_MONSTER);
auto *actorComponent = new ActorComponent(*being);
being->addComponent(actorComponent);
auto *beingComponent = new BeingComponent(*being);
@@ -76,7 +76,7 @@ void SpawnAreaComponent::update(Entity &entity)
{
LOG_WARN("Refusing to spawn dead monster " << mSpecy->getId());
delete being;
- being = 0;
+ being = nullptr;
}
if (being)
diff --git a/src/game-server/spawnareacomponent.h b/src/game-server/spawnareacomponent.h
index 04658448..87c8c4f5 100644
--- a/src/game-server/spawnareacomponent.h
+++ b/src/game-server/spawnareacomponent.h
@@ -41,7 +41,7 @@ class SpawnAreaComponent : public Component
const Rectangle &zone,
int maxBeings, int spawnRate);
- void update(Entity &entity);
+ void update(Entity &entity) override;
/**
* Keeps track of the number of spawned being.
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index b4261e55..c6775e03 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -58,7 +58,7 @@ struct DelayedEvent
MapComposite *map;
};
-typedef std::map< Entity *, DelayedEvent > DelayedEvents;
+using DelayedEvents = std::map<Entity *, DelayedEvent>;
/**
* The current world time in ticks since server start.
@@ -94,10 +94,10 @@ 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 (EquipData::const_iterator it = equipData.begin(),
+ for (auto it = equipData.begin(),
it_end = equipData.end(); it != it_end; ++it)
{
- InventoryData::const_iterator itemIt = inventoryData.find(*it);
+ auto itemIt = inventoryData.find(*it);
if (!itemManager->isEquipSlotVisible(itemIt->second.equipmentSlot))
continue;
@@ -245,7 +245,7 @@ static void informPlayer(MapComposite *map, Entity *p)
{
auto *beingComponent = o->getComponent<BeingComponent>();
const Hits &hits = beingComponent->getHitsTaken();
- for (Hits::const_iterator j = hits.begin(),
+ for (auto j = hits.begin(),
j_end = hits.end(); j != j_end; ++j)
{
damageMsg.writeInt16(oid);
@@ -292,7 +292,7 @@ static void informPlayer(MapComposite *map, Entity *p)
case OBJECT_MONSTER:
{
- MonsterComponent *monsterComponent =
+ auto monsterComponent =
o->getComponent<MonsterComponent>();
enterMsg.writeInt16(monsterComponent->getSpecy()->getId());
enterMsg.writeString(
@@ -301,7 +301,7 @@ static void informPlayer(MapComposite *map, Entity *p)
case OBJECT_NPC:
{
- NpcComponent *npcComponent =
+ auto npcComponent =
o->getComponent<NpcComponent>();
enterMsg.writeInt16(npcComponent->getNpcId());
enterMsg.writeString(
@@ -411,7 +411,7 @@ static void informPlayer(MapComposite *map, Entity *p)
{
case OBJECT_ITEM:
{
- ItemComponent *item = o->getComponent<ItemComponent>();
+ auto item = o->getComponent<ItemComponent>();
ItemClass *itemClass = item->getItemClass();
if (oflags & UPDATEFLAG_NEW_ON_MAP)
@@ -434,7 +434,7 @@ static void informPlayer(MapComposite *map, Entity *p)
break;
case OBJECT_EFFECT:
{
- EffectComponent *e = o->getComponent<EffectComponent>();
+ auto e = o->getComponent<EffectComponent>();
// Don't show old effects
if (!(oflags & UPDATEFLAG_NEW_ON_MAP))
break;
@@ -482,7 +482,7 @@ void GameState::update(int tick)
// Update game state (update AI, etc.)
const MapManager::Maps &maps = MapManager::getMaps();
- for (MapManager::Maps::const_iterator m = maps.begin(),
+ for (auto m = maps.begin(),
m_end = maps.end(); m != m_end; ++m)
{
MapComposite *map = m->second;
@@ -512,7 +512,7 @@ void GameState::update(int tick)
# endif
// Take care of events that were delayed because of their side effects.
- for (DelayedEvents::iterator it = delayedEvents.begin(),
+ for (auto it = delayedEvents.begin(),
it_end = delayedEvents.end(); it != it_end; ++it)
{
const DelayedEvent &e = it->second;
@@ -558,7 +558,7 @@ bool GameState::insert(Entity *ptr)
}
// Check that coordinates are actually valid.
- Entity *obj = static_cast< Entity * >(ptr);
+ auto obj = static_cast< Entity * >(ptr);
Map *mp = map->getMap();
Point pos = obj->getComponent<ActorComponent>()->getPosition();
if ((int)pos.x / mp->getTileWidth() >= mp->getWidth() ||
@@ -604,7 +604,7 @@ bool GameState::insert(Entity *ptr)
case OBJECT_MONSTER:
{
- MonsterComponent *monsterComponent =
+ auto monsterComponent =
obj->getComponent<MonsterComponent>();
LOG_DEBUG("Monster inserted: "
<< monsterComponent->getSpecy()->getId());
@@ -681,7 +681,7 @@ void GameState::remove(Entity *ptr)
case OBJECT_MONSTER:
{
- MonsterComponent *monsterComponent =
+ auto monsterComponent =
ptr->getComponent<MonsterComponent>();
LOG_DEBUG("Monster removed: "
<< monsterComponent->getSpecy()->getId());
@@ -799,7 +799,7 @@ void GameState::enqueueInsert(Entity *ptr)
{
DelayedEvent event;
event.type = EVENT_INSERT;
- event.map = 0;
+ event.map = nullptr;
enqueueEvent(ptr, event);
}
@@ -807,7 +807,7 @@ void GameState::enqueueRemove(Entity *ptr)
{
DelayedEvent event;
event.type = EVENT_REMOVE;
- event.map = 0;
+ event.map = nullptr;
enqueueEvent(ptr, event);
}
@@ -884,8 +884,7 @@ void GameState::sayToAll(const std::string &text)
std::string GameState::getVariable(const std::string &key)
{
- std::map<std::string, std::string>::iterator iValue =
- mScriptVariables.find(key);
+ auto iValue = mScriptVariables.find(key);
if (iValue != mScriptVariables.end())
return iValue->second;
else
@@ -914,7 +913,7 @@ void GameState::callVariableCallbacks(const std::string &key,
const std::string &value)
{
const MapManager::Maps &maps = MapManager::getMaps();
- for (MapManager::Maps::const_iterator m = maps.begin(),
+ for (auto m = maps.begin(),
m_end = maps.end(); m != m_end; ++m)
{
m->second->callWorldVariableCallback(key, value);
diff --git a/src/game-server/statusmanager.cpp b/src/game-server/statusmanager.cpp
index 2056b581..830291a9 100644
--- a/src/game-server/statusmanager.cpp
+++ b/src/game-server/statusmanager.cpp
@@ -29,7 +29,7 @@
#include <set>
#include <sstream>
-typedef std::map< int, StatusEffect * > StatusEffectsMap;
+using StatusEffectsMap = std::map<int, StatusEffect *>;
static StatusEffectsMap statusEffects;
static utils::NameMap<StatusEffect*> statusEffectsByName;
@@ -45,7 +45,7 @@ void StatusManager::reload()
void StatusManager::deinitialize()
{
- for (StatusEffectsMap::iterator i = statusEffects.begin(),
+ for (auto i = statusEffects.begin(),
i_end = statusEffects.end(); i != i_end; ++i)
{
delete i->second;
@@ -80,7 +80,7 @@ void StatusManager::readStatusNode(xmlNodePtr node, const std::string &filename)
return;
}
- StatusEffect *statusEffect = new StatusEffect(id);
+ auto statusEffect = new StatusEffect(id);
const std::string name = XML::getProperty(node, "name",
std::string());
diff --git a/src/game-server/trade.h b/src/game-server/trade.h
index 70ae1095..b3c7c9ad 100644
--- a/src/game-server/trade.h
+++ b/src/game-server/trade.h
@@ -84,7 +84,7 @@ class Trade
int amount;
};
- typedef std::vector< TradedItem > TradedItems;
+ using TradedItems = std::vector<TradedItem>;
/*
* See trade.cpp for doc on TradeStates
diff --git a/src/game-server/triggerareacomponent.cpp b/src/game-server/triggerareacomponent.cpp
index 9054bf80..4785e700 100644
--- a/src/game-server/triggerareacomponent.cpp
+++ b/src/game-server/triggerareacomponent.cpp
@@ -47,7 +47,7 @@ void AutowarpAction::process(Entity *obj)
return;
// get the direction
- ActorComponent *actor = obj->getComponent<ActorComponent>();
+ auto actor = obj->getComponent<ActorComponent>();
// calculate proportions
float horizontal = float(mTargetArea.w) / float(mSourceArea.w);
diff --git a/src/game-server/triggerareacomponent.h b/src/game-server/triggerareacomponent.h
index 5857e55a..d50224bf 100644
--- a/src/game-server/triggerareacomponent.h
+++ b/src/game-server/triggerareacomponent.h
@@ -43,7 +43,7 @@ class WarpAction : public TriggerAction
WarpAction(MapComposite *m, const Point &point)
: mMap(m), mTargetPoint(point) {}
- virtual void process(Entity *obj);
+ void process(Entity *obj) override;
private:
MapComposite *mMap;
@@ -70,7 +70,7 @@ class AutowarpAction: public TriggerAction
mDirection(direction)
{}
- virtual void process(Entity *obj);
+ void process(Entity *obj) override;
private:
/** Target map */
@@ -88,7 +88,7 @@ class ScriptAction : public TriggerAction
public:
ScriptAction(Script *script, Script::Ref callback, int arg);
- virtual void process(Entity *obj);
+ void process(Entity *obj) override;
private:
Script *mScript; // Script object to be called
@@ -112,7 +112,7 @@ class TriggerAreaComponent : public Component
mOnce(once)
{}
- void update(Entity &entity);
+ void update(Entity &entity) override;
private:
Rectangle mZone;
diff --git a/src/net/bandwidth.cpp b/src/net/bandwidth.cpp
index 4d04b3b9..d394b222 100644
--- a/src/net/bandwidth.cpp
+++ b/src/net/bandwidth.cpp
@@ -44,7 +44,7 @@ void BandwidthMonitor::increaseClientOutput(NetComputer *nc, int size)
{
mAmountClientOutput += size;
// look for an existing client stored
- ClientBandwidth::iterator itr = mClientBandwidth.find(nc);
+ auto itr = mClientBandwidth.find(nc);
// if there isnt one, create one
if (itr == mClientBandwidth.end())
@@ -63,7 +63,7 @@ void BandwidthMonitor::increaseClientInput(NetComputer *nc, int size)
mAmountClientInput += size;
// look for an existing client stored
- ClientBandwidth::iterator itr = mClientBandwidth.find(nc);
+ auto itr = mClientBandwidth.find(nc);
// if there isnt one, create it
if (itr == mClientBandwidth.end())
diff --git a/src/net/bandwidth.h b/src/net/bandwidth.h
index 4ffeff73..b4162131 100644
--- a/src/net/bandwidth.h
+++ b/src/net/bandwidth.h
@@ -44,7 +44,7 @@ private:
int mAmountClientOutput;
int mAmountClientInput;
// map of client to output and input
- typedef std::map<NetComputer*, std::pair<int, int> > ClientBandwidth;
+ using ClientBandwidth = std::map<NetComputer *, std::pair<int, int>>;
ClientBandwidth mClientBandwidth;
};
diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp
index edf46dba..1cdae2f3 100644
--- a/src/net/connectionhandler.cpp
+++ b/src/net/connectionhandler.cpp
@@ -61,7 +61,7 @@ bool ConnectionHandler::startListen(enet_uint16 port,
0 /* assume any amount of outgoing bandwidth */);
#endif
- return host != 0;
+ return host != nullptr;
}
void ConnectionHandler::stopListen()
@@ -111,8 +111,7 @@ void ConnectionHandler::process(enet_uint32 timeout)
case ENET_EVENT_TYPE_RECEIVE:
{
- NetComputer *comp =
- static_cast<NetComputer*>(event.peer->data);
+ auto comp = static_cast<NetComputer*>(event.peer->data);
// If the scripting subsystem didn't hook the message
// it will be handled by the default message handler.
@@ -137,8 +136,7 @@ void ConnectionHandler::process(enet_uint32 timeout)
case ENET_EVENT_TYPE_DISCONNECT:
{
- NetComputer *comp =
- static_cast<NetComputer*>(event.peer->data);
+ auto comp = static_cast<NetComputer*>(event.peer->data);
LOG_INFO("" << *comp << " disconnected.");
@@ -155,7 +153,7 @@ void ConnectionHandler::process(enet_uint32 timeout)
void ConnectionHandler::sendToEveryone(const MessageOut &msg)
{
- for (NetComputers::iterator i = clients.begin(), i_end = clients.end();
+ for (auto i = clients.begin(), i_end = clients.end();
i != i_end; ++i)
{
(*i)->send(msg);
diff --git a/src/net/connectionhandler.h b/src/net/connectionhandler.h
index 7dde004f..e49d49a9 100644
--- a/src/net/connectionhandler.h
+++ b/src/net/connectionhandler.h
@@ -110,7 +110,7 @@ class ConnectionHandler
*/
virtual void processMessage(NetComputer *, MessageIn &) = 0;
- typedef std::list<NetComputer*> NetComputers;
+ using NetComputers = std::list<NetComputer *>;
/**
* A list of pointers to the client structures created by
* computerConnected.
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index ce1be488..9d206de5 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -175,7 +175,7 @@ std::string MessageIn::readString(int length)
// Read the string
const char *stringBeg = mData + mPos;
- const char *stringEnd = (const char *)memchr(stringBeg, '\0', length);
+ const auto stringEnd = (const char *)memchr(stringBeg, '\0', length);
std::string readString(stringBeg,
stringEnd ? stringEnd - stringBeg : length);
mPos += length;
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 0a198da3..a724e9d2 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -275,9 +275,9 @@ static int npc_create(lua_State *s)
MapComposite *m = checkCurrentMap(s);
- NpcComponent *npcComponent = new NpcComponent(id);
+ auto npcComponent = new NpcComponent(id);
- Entity *npc = new Entity(OBJECT_NPC);
+ auto npc = new Entity(OBJECT_NPC);
auto *actorComponent = new ActorComponent(*npc);
npc->addComponent(actorComponent);
auto *beingComponent = new BeingComponent(*npc);
@@ -355,7 +355,7 @@ static int monster_create(lua_State *s)
const int y = luaL_checkint(s, 3);
MapComposite *m = checkCurrentMap(s);
- Entity *monster = new Entity(OBJECT_MONSTER);
+ auto monster = new Entity(OBJECT_MONSTER);
auto *actorComponent = new ActorComponent(*monster);
monster->addComponent(actorComponent);
monster->addComponent(new BeingComponent(*monster));
@@ -415,11 +415,11 @@ static int trigger_create(lua_State *s)
script->assignCallback(function);
lua_pop(s, 1);
- Entity *triggerEntity = new Entity(OBJECT_OTHER, m);
+ auto triggerEntity = new Entity(OBJECT_OTHER, m);
- ScriptAction *action = new ScriptAction(script, function, id);
+ auto action = new ScriptAction(script, function, id);
Rectangle r = { x, y, width, height };
- TriggerAreaComponent *area = new TriggerAreaComponent(r, action, once);
+ auto area = new TriggerAreaComponent(r, action, once);
triggerEntity->addComponent(area);
@@ -791,7 +791,7 @@ static int trade(lua_State *s)
luaL_argcheck(s, lua_isboolean(s, 1), 1, "boolean expected");
bool sellMode = lua_toboolean(s, 1);
- BuySell *t = new BuySell(character, sellMode);
+ auto t = new BuySell(character, sellMode);
if (!lua_istable(s, 2))
{
if (sellMode)
@@ -1018,7 +1018,7 @@ static int entity_get_inventory(lua_State *s)
int firstTableStackPosition = lua_gettop(s);
int tableIndex = 1;
- for (InventoryData::const_iterator it = invData.begin(),
+ for (auto it = invData.begin(),
it_end = invData.end(); it != it_end; ++it)
{
if (!it->second.itemId || !it->second.amount)
@@ -1092,10 +1092,10 @@ static int entity_get_equipment(lua_State *s)
int firstTableStackPosition = lua_gettop(s);
int tableIndex = 1;
- for (EquipData::const_iterator it = equipData.begin(),
+ for (auto it = equipData.begin(),
it_end = equipData.end(); it != it_end; ++it)
{
- InventoryData::const_iterator itemIt = inventoryData.find(*it);
+ auto itemIt = inventoryData.find(*it);
const InventoryItem &item = itemIt->second;
// Create the sub-table (value of the main one)
@@ -1495,7 +1495,7 @@ static int entity_get_action(lua_State *s)
static int entity_set_action(lua_State *s)
{
Entity *being = checkBeing(s, 1);
- BeingAction act = static_cast<BeingAction>(luaL_checkint(s, 2));
+ auto act = static_cast<BeingAction>(luaL_checkint(s, 2));
being->getComponent<BeingComponent>()->setAction(*being, act);
return 0;
}
@@ -1533,7 +1533,7 @@ static int entity_get_direction(lua_State *s)
static int entity_set_direction(lua_State *s)
{
Entity *being = checkBeing(s, 1);
- BeingDirection dir = static_cast<BeingDirection>(luaL_checkint(s, 2));
+ auto dir = static_cast<BeingDirection>(luaL_checkint(s, 2));
being->getComponent<BeingComponent>()->setDirection(*being, dir);
return 0;
}
@@ -2195,7 +2195,7 @@ static int entity_register(lua_State *s)
entity->signal_removed.connect(sigc::mem_fun(script, &Script::processRemoveEvent));
- if (BeingComponent *bc = entity->findComponent<BeingComponent>())
+ if (auto bc = entity->findComponent<BeingComponent>())
bc->signal_died.connect(sigc::mem_fun(script, &Script::processDeathEvent));
return 0;
@@ -2354,7 +2354,7 @@ static int set_questlog(lua_State *s)
{
const Entity *character = checkCharacter(s, 1);
const int questId = luaL_checkinteger(s, 2);
- const QuestState questState = (QuestState)luaL_checkinteger(s, 3);
+ const auto questState = (QuestState)luaL_checkinteger(s, 3);
const char *questTitle = luaL_checkstring(s, 4);
const char *questDescription = luaL_checkstring(s, 5);
const bool questNotification = checkOptionalBool(s, 6, true);
@@ -2381,7 +2381,7 @@ static int set_questlog_state(lua_State *s)
{
const Entity *character = checkCharacter(s, 1);
const int questId = luaL_checkinteger(s, 2);
- const QuestState questState = (QuestState)luaL_checkinteger(s, 3);
+ const auto questState = (QuestState)luaL_checkinteger(s, 3);
const bool questNotification = checkOptionalBool(s, 4, true);
auto *characterComponent = character->getComponent<CharacterComponent>();
@@ -2441,7 +2441,7 @@ static int set_questlog_description(lua_State *s)
static int entity_get_monster_id(lua_State *s)
{
Entity *monster = checkMonster(s, 1);
- MonsterComponent *monsterComponent = monster->getComponent<MonsterComponent>();
+ auto monsterComponent = monster->getComponent<MonsterComponent>();
lua_pushinteger(s, monsterComponent->getSpecy()->getId());
return 1;
}
@@ -3155,7 +3155,7 @@ static int map_get_objects(lua_State *s)
else
{
std::vector<MapObject*> filteredObjects;
- for (std::vector<MapObject*>::const_iterator it = objects.begin();
+ for (auto it = objects.begin();
it != objects.end(); ++it)
{
if (utils::compareStrI((*it)->getType(), filter) == 0)
diff --git a/src/scripting/luascript.cpp b/src/scripting/luascript.cpp
index 06fbd2ab..3698498e 100644
--- a/src/scripting/luascript.cpp
+++ b/src/scripting/luascript.cpp
@@ -55,7 +55,7 @@ Script::Thread *LuaScript::newThread()
assert(nbArgs == -1);
assert(!mCurrentThread);
- LuaThread *thread = new LuaThread(this);
+ auto thread = new LuaThread(this);
mCurrentThread = thread;
mCurrentState = thread->mState;
@@ -325,6 +325,6 @@ LuaScript::LuaThread::LuaThread(LuaScript *script) :
LuaScript::LuaThread::~LuaThread()
{
- LuaScript *luaScript = static_cast<LuaScript*>(mScript);
+ auto luaScript = static_cast<LuaScript*>(mScript);
luaL_unref(luaScript->mRootState, LUA_REGISTRYINDEX, mRef);
}
diff --git a/src/scripting/luascript.h b/src/scripting/luascript.h
index 2d47d8ea..2e2fed0c 100644
--- a/src/scripting/luascript.h
+++ b/src/scripting/luascript.h
@@ -42,30 +42,30 @@ class LuaScript : public Script
*/
LuaScript();
- ~LuaScript();
+ ~LuaScript() override;
void load(const char *prog, const char *name,
- const Context &context = Context());
+ const Context &context = Context()) override;
- Thread *newThread();
+ Thread *newThread() override;
- void prepare(Ref function);
+ void prepare(Ref function) override;
- void prepareResume(Thread *thread);
+ void prepareResume(Thread *thread) override;
- void push(int);
- void push(const std::string &);
- void push(Entity *);
- void push(const std::list<InventoryItem> &itemList);
- void push(AttributeInfo *);
+ void push(int) override;
+ void push(const std::string &) override;
+ void push(Entity *) override;
+ void push(const std::list<InventoryItem> &itemList) override;
+ void push(AttributeInfo *) override;
- int execute(const Context &context = Context());
+ int execute(const Context &context = Context()) override;
- bool resume();
+ bool resume() override;
- void assignCallback(Ref &function);
+ void assignCallback(Ref &function) override;
- void unref(Ref &ref);
+ void unref(Ref &ref) override;
static void getQuestCallback(Entity *,
const std::string &value,
@@ -76,9 +76,9 @@ class LuaScript : public Script
const std::string &letter,
Script *);
- void processDeathEvent(Entity *entity);
+ void processDeathEvent(Entity *entity) override;
- void processRemoveEvent(Entity *entity);
+ void processRemoveEvent(Entity *entity) override;
static void setDeathNotificationCallback(Script *script)
@@ -94,7 +94,7 @@ class LuaScript : public Script
{
public:
LuaThread(LuaScript *script);
- ~LuaThread();
+ ~LuaThread() override;
lua_State *mState;
int mRef;
diff --git a/src/scripting/luautil.cpp b/src/scripting/luautil.cpp
index 1408eb63..b9a668bf 100644
--- a/src/scripting/luautil.cpp
+++ b/src/scripting/luautil.cpp
@@ -169,7 +169,7 @@ Script *getScript(lua_State *s)
{
lua_pushlightuserdata(s, (void *)&LuaScript::registryKey);
lua_gettable(s, LUA_REGISTRYINDEX);
- Script *script = static_cast<Script *>(lua_touserdata(s, -1));
+ auto script = static_cast<Script *>(lua_touserdata(s, -1));
lua_pop(s, 1);
return script;
}
@@ -185,7 +185,7 @@ Script *getScript(lua_State *s)
ItemClass *getItemClass(lua_State *s, int p)
{
- ItemClass *itemClass = 0;
+ ItemClass *itemClass = nullptr;
switch (lua_type(s, p))
{
@@ -205,7 +205,7 @@ ItemClass *getItemClass(lua_State *s, int p)
MonsterClass *getMonsterClass(lua_State *s, int p)
{
- MonsterClass *monsterClass = 0;
+ MonsterClass *monsterClass = nullptr;
switch (lua_type(s, p))
{
diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h
index 46a07713..567a3fe1 100644
--- a/src/scripting/luautil.h
+++ b/src/scripting/luautil.h
@@ -187,13 +187,13 @@ private:
static UserDataCache mUserDataCache;
};
-typedef LuaUserData<Entity> LuaEntity;
-typedef LuaUserData<ItemClass> LuaItemClass;
-typedef LuaUserData<MapObject> LuaMapObject;
-typedef LuaUserData<MonsterClass> LuaMonsterClass;
-typedef LuaUserData<StatusEffect> LuaStatusEffect;
-typedef LuaUserData<AbilityManager::AbilityInfo> LuaAbilityInfo;
-typedef LuaUserData<AttributeInfo> LuaAttributeInfo;
+using LuaEntity = LuaUserData<Entity>;
+using LuaItemClass = LuaUserData<ItemClass>;
+using LuaMapObject = LuaUserData<MapObject>;
+using LuaMonsterClass = LuaUserData<MonsterClass>;
+using LuaStatusEffect = LuaUserData<StatusEffect>;
+using LuaAbilityInfo = LuaUserData<AbilityManager::AbilityInfo>;
+using LuaAttributeInfo = LuaUserData<AttributeInfo>;
Script * getScript(lua_State *s);
@@ -213,8 +213,8 @@ AbilityManager::AbilityInfo * checkAbility(lua_State *s, int p);
AttributeInfo * checkAttribute(lua_State *s, int p);
unsigned char checkWalkMask(lua_State *s, int p);
-MapComposite * checkCurrentMap(lua_State *s, Script *script = 0);
-Script::Thread* checkCurrentThread(lua_State *s, Script *script = 0);
+MapComposite * checkCurrentMap(lua_State *s, Script *script = nullptr);
+Script::Thread* checkCurrentThread(lua_State *s, Script *script = nullptr);
/* Polymorphic wrapper for pushing variables.
diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp
index 715a7991..638ccb17 100644
--- a/src/scripting/script.cpp
+++ b/src/scripting/script.cpp
@@ -31,7 +31,7 @@
#include <string.h>
-typedef std::map< std::string, Script::Factory > Engines;
+using Engines = std::map<std::string, Script::Factory>;
static Engines *engines = nullptr;
@@ -39,8 +39,8 @@ Script::Ref Script::mCreateNpcDelayedCallback;
Script::Ref Script::mUpdateCallback;
Script::Script():
- mCurrentThread(0),
- mContext(0)
+ mCurrentThread(nullptr),
+ mContext(nullptr)
{}
Script::~Script()
diff --git a/src/scripting/script.h b/src/scripting/script.h
index d4b51345..2eb979b1 100644
--- a/src/scripting/script.h
+++ b/src/scripting/script.h
@@ -49,16 +49,16 @@ class Script : public sigc::trackable
Entity *character;
Context()
- : map(0)
- , npc(0)
- , character(0)
+ : map(nullptr)
+ , npc(nullptr)
+ , character(nullptr)
{}
};
/**
* Defines a function that creates a Script instance.
*/
- typedef Script *(*Factory)();
+ using Factory = Script *(*)();
/**
* Registers a new scripting engine.
diff --git a/src/scripting/scriptmanager.cpp b/src/scripting/scriptmanager.cpp
index ee231611..06b9b761 100644
--- a/src/scripting/scriptmanager.cpp
+++ b/src/scripting/scriptmanager.cpp
@@ -36,7 +36,7 @@ void ScriptManager::initialize()
void ScriptManager::deinitialize()
{
delete _currentState;
- _currentState = 0;
+ _currentState = nullptr;
}
bool ScriptManager::loadMainScript(const std::string &file)
diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp
index 342c39b0..b89ee9e7 100644
--- a/src/utils/base64.cpp
+++ b/src/utils/base64.cpp
@@ -34,7 +34,7 @@ static char base64_pad = '=';
unsigned char *php_base64_encode(const unsigned char *str, int length, int *ret_length) {
const unsigned char *current = str;
int i = 0;
- unsigned char *result = (unsigned char *)malloc(((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char));
+ auto result = (unsigned char *)malloc(((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char));
while (length > 2) { /* keep going until we have less than 24 bits */
result[i++] = base64_table[current[0] >> 2];
diff --git a/src/utils/processorutils.cpp b/src/utils/processorutils.cpp
index 06ef0178..4b18bf00 100644
--- a/src/utils/processorutils.cpp
+++ b/src/utils/processorutils.cpp
@@ -30,6 +30,6 @@ void utils::processor::init()
bool utils::processor::littleEndianCheck()
{
short int word = 0x0001; // Store 0x0001 in a 16-bit int.
- char *byte = (char *) &word; // 'byte' points to the first byte in word.
+ auto byte = (char *) &word; // 'byte' points to the first byte in word.
return(byte[0]); // byte[0] will be 1 on little-endian processors.
}
diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp
index 102171e9..f9ea3fa1 100644
--- a/src/utils/sha256.cpp
+++ b/src/utils/sha256.cpp
@@ -77,8 +77,8 @@
#ifdef HAVE_STDINT_H
#include <stdint.h>
#else
-typedef unsigned char uint8_t;
-typedef unsigned int uint32_t;
+using uint8_t = unsigned char;
+using uint32_t = unsigned int;
#endif
#define SHA256_BLOCK_SIZE (512 / 8)
diff --git a/src/utils/string.h b/src/utils/string.h
index 882b1b09..6dcd6fe4 100644
--- a/src/utils/string.h
+++ b/src/utils/string.h
@@ -121,7 +121,7 @@ namespace utils
}
private:
- typedef std::map<std::string, T> Map;
+ using Map = std::map<std::string, T>;
Map mMap;
const T mDefault;
diff --git a/src/utils/stringfilter.cpp b/src/utils/stringfilter.cpp
index e3696097..8c417ed0 100644
--- a/src/utils/stringfilter.cpp
+++ b/src/utils/stringfilter.cpp
@@ -60,7 +60,7 @@ void StringFilter::writeSlangFilterList()
{
// Write the list to config
std::string slangsList;
- for (SlangIterator i = mSlangs.begin(); i != mSlangs.end(); )
+ for (auto i = mSlangs.begin(); i != mSlangs.end(); )
{
slangsList += *i;
++i;
@@ -82,7 +82,7 @@ bool StringFilter::filterContent(const std::string &text) const
std::transform(text.begin(), text.end(), upperCaseText.begin(),
(int(*)(int))std::toupper);
- for (Slangs::const_iterator i = mSlangs.begin(); i != mSlangs.end(); ++i)
+ for (auto i = mSlangs.begin(); i != mSlangs.end(); ++i)
{
// We look for slangs into the sentence.
std::string upperCaseSlang = *i;
diff --git a/src/utils/stringfilter.h b/src/utils/stringfilter.h
index 1ccb5c72..2d5ba5ba 100644
--- a/src/utils/stringfilter.h
+++ b/src/utils/stringfilter.h
@@ -71,8 +71,8 @@ class StringFilter
bool findDoubleQuotes(const std::string &text) const;
private:
- typedef std::list<std::string> Slangs;
- typedef Slangs::iterator SlangIterator;
+ using Slangs = std::list<std::string>;
+ using SlangIterator = Slangs::iterator;
Slangs mSlangs; /**< the formatted Slangs list */
bool mInitialized; /**< Set if the list is loaded */
};
diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp
index c01a4134..3d1e0e6d 100644
--- a/src/utils/timer.cpp
+++ b/src/utils/timer.cpp
@@ -35,7 +35,7 @@ static uint64_t getTimeInMillisec()
uint64_t timeInMillisec;
timeval time;
- gettimeofday(&time, 0);
+ gettimeofday(&time, nullptr);
timeInMillisec = (uint64_t)time.tv_sec * 1000 + time.tv_usec / 1000;
return timeInMillisec;
}
@@ -59,7 +59,7 @@ void Timer::sleep()
struct timespec req;
req.tv_sec = 0;
req.tv_nsec = (interval - (now - lastpulse)) * (1000 * 1000);
- nanosleep(&req, 0);
+ nanosleep(&req, nullptr);
#else
Sleep(interval - (now - lastpulse));
#endif
diff --git a/src/utils/tokencollector.cpp b/src/utils/tokencollector.cpp
index 691eca20..ecbae632 100644
--- a/src/utils/tokencollector.cpp
+++ b/src/utils/tokencollector.cpp
@@ -29,7 +29,7 @@
void TokenCollectorBase::insertClient(const std::string &token, intptr_t data)
{
- for (std::list<Item>::reverse_iterator it = mPendingConnects.rbegin(),
+ for (auto it = mPendingConnects.rbegin(),
it_end = mPendingConnects.rend(); it != it_end; ++it)
{
if (it->token == token)
@@ -53,7 +53,7 @@ void TokenCollectorBase::insertClient(const std::string &token, intptr_t data)
void TokenCollectorBase::insertConnect(const std::string &token, intptr_t data)
{
- for (std::list<Item>::reverse_iterator it = mPendingClients.rbegin(),
+ for (auto it = mPendingClients.rbegin(),
it_end = mPendingClients.rend(); it != it_end; ++it)
{
if (it->token == token)
@@ -77,7 +77,7 @@ void TokenCollectorBase::insertConnect(const std::string &token, intptr_t data)
void TokenCollectorBase::removeClient(intptr_t data)
{
- for (std::list<Item>::iterator it = mPendingClients.begin(),
+ for (auto it = mPendingClients.begin(),
it_end = mPendingClients.end(); it != it_end; ++it)
{
if (it->data == data)
diff --git a/src/utils/tokencollector.h b/src/utils/tokencollector.h
index 0923eac6..64977d26 100644
--- a/src/utils/tokencollector.h
+++ b/src/utils/tokencollector.h
@@ -124,13 +124,13 @@ class TokenCollector: private TokenCollectorBase
private:
- void removedClient(intptr_t data)
+ void removedClient(intptr_t data) override
{ mHandler->deletePendingClient((Client)data); }
- void removedConnect(intptr_t data)
+ void removedConnect(intptr_t data) override
{ mHandler->deletePendingConnect((ServerData)data); }
- void foundMatch(intptr_t client, intptr_t data)
+ void foundMatch(intptr_t client, intptr_t data) override
{ mHandler->tokenMatched((Client)client, (ServerData)data); }
Handler *mHandler;
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 3c286db1..f1b27cbe 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -31,7 +31,7 @@
namespace XML
{
Document::Document(const std::string &fileName, bool useResman):
- mDoc(0)
+ mDoc(nullptr)
{
std::string resolvedFileName = fileName;
if (useResman)
@@ -63,7 +63,7 @@ namespace XML
xmlNodePtr Document::rootNode()
{
- return mDoc ? xmlDocGetRootElement(mDoc) : 0;
+ return mDoc ? xmlDocGetRootElement(mDoc) : nullptr;
}
bool hasProperty(xmlNodePtr node, const char *name)