summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-04-09 17:36:33 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-18 08:21:32 +0000
commite875242f380662573880e7400fe3e736a2d3375a (patch)
tree1c026e19d98764b57c7619502d8c88535aa58d8e
parenteb206d0a5a9b8d73b103c094e376c5e13cd4c218 (diff)
downloadmana-e875242f380662573880e7400fe3e736a2d3375a.tar.gz
mana-e875242f380662573880e7400fe3e736a2d3375a.tar.bz2
mana-e875242f380662573880e7400fe3e736a2d3375a.tar.xz
mana-e875242f380662573880e7400fe3e736a2d3375a.zip
General code cleanups
-rw-r--r--src/chatlogger.cpp8
-rw-r--r--src/event.cpp6
-rw-r--r--src/gui/widgets/chattab.cpp5
-rw-r--r--src/net/net.cpp4
-rw-r--r--src/net/tmwa/generalhandler.cpp2
-rw-r--r--src/net/tmwa/network.h2
-rw-r--r--src/resources/attributes.cpp24
-rw-r--r--src/resources/itemdb.cpp4
-rw-r--r--src/resources/itemdb.h2
9 files changed, 19 insertions, 38 deletions
diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp
index 1fef16bf..331e322e 100644
--- a/src/chatlogger.cpp
+++ b/src/chatlogger.cpp
@@ -22,7 +22,6 @@
#include "chatlogger.h"
#include <iostream>
-#include <sstream>
#include <dirent.h>
#include <sys/stat.h>
@@ -110,18 +109,15 @@ void ChatLogger::log(std::string name, std::string str)
std::string ChatLogger::getDateString() const
{
- std::string date;
-
time_t rawtime;
struct tm *timeinfo;
- char buffer [80];
+ char buffer[80];
time (&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 79, "%y-%m-%d", timeinfo);
- date = buffer;
- return date;
+ return buffer;
}
std::string ChatLogger::secureName(std::string &name)
diff --git a/src/event.cpp b/src/event.cpp
index 55782300..11d46a2f 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -27,12 +27,8 @@ Event::ListenMap Event::mBindings;
Event::~Event()
{
- auto it = mData.begin();
- while (it != mData.end())
- {
+ for (auto it = mData.begin(); it != mData.end(); ++it)
delete it->second;
- it++;
- }
}
// Integers
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 663464a8..9bdb20ef 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -66,7 +66,7 @@ ChatTab::ChatTab(const std::string &name)
listen(Event::ConfigChannel);
// Initiate the text format
- updateTextFormat(((Window*)getParent())->getGuiAlpha());
+ updateTextFormat(Window::getGuiAlpha());
}
ChatTab::~ChatTab()
@@ -104,8 +104,7 @@ void ChatTab::event(Event::Channel channel, const Event &event)
event.getType() == Event::ConfigOptionChanged &&
event.getString("option") == "guialpha")
{
- int alpha = ((Window*)getParent())->getGuiAlpha();
- updateTextFormat(alpha);
+ updateTextFormat(Window::getGuiAlpha());
}
}
diff --git a/src/net/net.cpp b/src/net/net.cpp
index 86f7dc13..3a389db2 100644
--- a/src/net/net.cpp
+++ b/src/net/net.cpp
@@ -21,7 +21,6 @@
#include "net/net.h"
-#include "main.h"
#include "log.h"
#include "net/adminhandler.h"
@@ -179,8 +178,7 @@ void connectToServer(ServerInfo &server)
void unload()
{
- GeneralHandler *handler = getGeneralHandler();
- if (handler)
+ if (GeneralHandler *handler = getGeneralHandler())
{
handler->unload();
}
diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp
index 832d6973..d8923caa 100644
--- a/src/net/tmwa/generalhandler.cpp
+++ b/src/net/tmwa/generalhandler.cpp
@@ -103,7 +103,7 @@ GeneralHandler::GeneralHandler():
stats.emplace_back("dex", _("Dexterity %+d"));
stats.emplace_back("luck", _("Luck %+d"));
- setStatsList(stats);
+ setStatsList(std::move(stats));
listen(Event::ClientChannel);
listen(Event::GameChannel);
diff --git a/src/net/tmwa/network.h b/src/net/tmwa/network.h
index 4069f916..fa0237dd 100644
--- a/src/net/tmwa/network.h
+++ b/src/net/tmwa/network.h
@@ -58,7 +58,7 @@ class Network
void disconnect();
- ServerInfo getServer() const
+ const ServerInfo &getServer() const
{ return mServer; }
void registerHandler(MessageHandler *handler);
diff --git a/src/resources/attributes.cpp b/src/resources/attributes.cpp
index 17bb40ac..29ef8dec 100644
--- a/src/resources/attributes.cpp
+++ b/src/resources/attributes.cpp
@@ -54,12 +54,10 @@ namespace Attributes {
};
/** Map for attributes. */
- using AttributeMap = std::map<unsigned int, Attribute>;
- static AttributeMap attributes;
+ static std::map<unsigned int, Attribute> attributes;
/** tags = effects on attributes. */
- using TagMap = std::map<std::string, std::string>;
- static TagMap tags;
+ static std::map<std::string, std::string> tags;
/** List of modifiable attribute names used at character's creation. */
static std::vector<std::string> attributeLabels;
@@ -96,9 +94,7 @@ namespace Attributes {
{
// Fill up the modifiable attribute label list.
attributeLabels.clear();
- AttributeMap::const_iterator it, it_end;
- for (it = attributes.begin(), it_end = attributes.end(); it != it_end;
- it++)
+ for (auto it = attributes.cbegin(), it_end = attributes.cend(); it != it_end; it++)
{
if (it->second.modifiable &&
(it->second.scope == "character" || it->second.scope == "being"))
@@ -146,8 +142,7 @@ namespace Attributes {
int getPlayerInfoIdFromAttrId(int attrId)
{
- AttributeMap::const_iterator it = attributes.find(attrId);
-
+ auto it = attributes.find(attrId);
if (it != attributes.end())
{
return it->second.playerInfoId;
@@ -372,18 +367,15 @@ namespace Attributes {
{
std::list<ItemStat> dbStats;
- TagMap::const_iterator it, it_end;
- for (it = tags.begin(), it_end = tags.end(); it != it_end; ++it)
- dbStats.push_back(ItemStat(it->first, it->second));
+ for (auto it = tags.cbegin(), it_end = tags.cend(); it != it_end; ++it)
+ dbStats.emplace_back(it->first, it->second);
- setStatsList(dbStats);
+ setStatsList(std::move(dbStats));
}
void informStatusWindow()
{
- AttributeMap::const_iterator it, it_end;
- for (it = attributes.begin(), it_end = attributes.end(); it != it_end;
- it++)
+ for (auto it = attributes.cbegin(), it_end = attributes.cend(); it != it_end; it++)
{
if (it->second.playerInfoId == -1 &&
(it->second.scope == "character" || it->second.scope == "being"))
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 28830e67..752664d7 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -35,9 +35,9 @@
#include <cassert>
-void setStatsList(const std::list<ItemStat> &stats)
+void setStatsList(std::list<ItemStat> stats)
{
- extraStats = stats;
+ extraStats = std::move(stats);
}
static ItemType itemTypeFromString(const std::string &name, int id = 0)
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h
index dd728e21..37fec717 100644
--- a/src/resources/itemdb.h
+++ b/src/resources/itemdb.h
@@ -65,7 +65,7 @@ class ItemStat
// Used to set nano-description
static std::list<ItemStat> extraStats;
-void setStatsList(const std::list<ItemStat> &stats);
+void setStatsList(std::list<ItemStat> stats);
/**
* Item information database generic definition.