summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-03-05 16:08:37 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-03-07 22:27:48 +0100
commite9f8e94c67283057feac75128962fd5fd3a4daa0 (patch)
tree6f98a53ffb3f4d26c165ed00aa32c9cc24136078 /src
parentf1fa20dbaa8769d928c00c24f860ea5e62ccf945 (diff)
downloadmana-e9f8e94c67283057feac75128962fd5fd3a4daa0.tar.gz
mana-e9f8e94c67283057feac75128962fd5fd3a4daa0.tar.bz2
mana-e9f8e94c67283057feac75128962fd5fd3a4daa0.tar.xz
mana-e9f8e94c67283057feac75128962fd5fd3a4daa0.zip
General code cleanups
Diffstat (limited to 'src')
-rw-r--r--src/event.cpp12
-rw-r--r--src/gui/popupmenu.cpp11
-rw-r--r--src/inventory.cpp2
-rw-r--r--src/inventory.h1
-rw-r--r--src/item.cpp3
-rw-r--r--src/item.h6
-rw-r--r--src/net/manaserv/itemhandler.cpp2
-rw-r--r--src/net/manaserv/network.cpp4
-rw-r--r--src/net/tmwa/abilityhandler.cpp32
-rw-r--r--src/net/tmwa/inventoryhandler.h2
-rw-r--r--src/net/tmwa/network.cpp11
-rw-r--r--src/resources/attributes.cpp34
12 files changed, 42 insertions, 78 deletions
diff --git a/src/event.cpp b/src/event.cpp
index 11d46a2f..64df4f70 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -27,8 +27,8 @@ Event::ListenMap Event::mBindings;
Event::~Event()
{
- for (auto it = mData.begin(); it != mData.end(); ++it)
- delete it->second;
+ for (auto &[_, data] : mData)
+ delete data;
}
// Integers
@@ -191,10 +191,6 @@ void Event::unbind(EventListener *listener, Channel channel)
void Event::remove(EventListener *listener)
{
- auto it = mBindings.begin();
- while (it != mBindings.end())
- {
- it->second.erase(listener);
- it++;
- }
+ for (auto &[_, listeners] : mBindings)
+ listeners.erase(listener);
}
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index b1165f27..5c240fd6 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -249,18 +249,15 @@ void PopupMenu::handleLink(const std::string &link)
{
local_player->inviteToGuild(being);
}
-
// Pick Up Floor Item action
else if ((link == "pickup") && mFloorItem)
{
local_player->pickUp(mFloorItem);
}
-
// Look To action
else if (link == "look")
{
}
-
else if (link == "activate" || link == "equip" || link == "unequip")
{
assert(mItem);
@@ -288,49 +285,41 @@ void PopupMenu::handleLink(const std::string &link)
else if (mFloorItem)
chatWindow->addItemText(mFloorItem->getInfo().name);
}
-
else if (link == "split")
{
ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit,
inventoryWindow, mItem);
}
-
else if (link == "drop")
{
ItemAmountWindow::showWindow(ItemAmountWindow::ItemDrop,
inventoryWindow, mItem);
}
-
else if (link == "store")
{
ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd,
inventoryWindow, mItem);
}
-
else if (link == "retrieve")
{
ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, mWindow,
mItem);
}
-
else if (link == "party" && being &&
being->getType() == ActorSprite::PLAYER)
{
Net::getPartyHandler()->invite(being);
}
-
else if (link == "name" && being)
{
const std::string &name = being->getName();
chatWindow->addInputText(name);
}
-
else if (link == "admin-kick" && being &&
being->getType() == ActorSprite::PLAYER)
{
Net::getAdminHandler()->kick(being->getName());
}
-
// Unknown actions
else if (link != "cancel")
{
diff --git a/src/inventory.cpp b/src/inventory.cpp
index e689f8bb..6aa30c00 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -159,7 +159,5 @@ void Inventory::removeInventoryListener(InventoryListener* listener)
void Inventory::distributeSlotsChangedEvent()
{
for (auto inventoryListener : mInventoryListeners)
- {
inventoryListener->slotsChanged(this);
- }
}
diff --git a/src/inventory.h b/src/inventory.h
index 504965e1..40a9403a 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -124,7 +124,6 @@ class Inventory
int getLastUsedSlot() const;
void addInventoryListener(InventoryListener* listener);
-
void removeInventoryListener(InventoryListener* listener);
int getType() const
diff --git a/src/item.cpp b/src/item.cpp
index 120c55a7..65fda05b 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -24,7 +24,6 @@
#include "configuration.h"
#include "event.h"
-#include "resources/image.h"
#include "resources/iteminfo.h"
#include "resources/resourcemanager.h"
#include "resources/theme.h"
@@ -36,8 +35,6 @@ Item::Item(int id, int quantity, bool equipped):
setId(id);
}
-Item::~Item() = default;
-
void Item::setId(int id)
{
mId = id;
diff --git a/src/item.h b/src/item.h
index b08c2f5e..4ed552ed 100644
--- a/src/item.h
+++ b/src/item.h
@@ -23,10 +23,8 @@
#include "event.h"
+#include "resources/image.h"
#include "resources/itemdb.h"
-#include "resources/resource.h"
-
-class Image;
const int ITEM_ICON_SIZE = 32;
@@ -38,7 +36,7 @@ class Item
public:
Item(int id = -1, int quantity = 0, bool equipped = false);
- virtual ~Item();
+ virtual ~Item() = default;
/**
* Sets the item id, identifying the item type.
diff --git a/src/net/manaserv/itemhandler.cpp b/src/net/manaserv/itemhandler.cpp
index de5b36fa..870e7a9f 100644
--- a/src/net/manaserv/itemhandler.cpp
+++ b/src/net/manaserv/itemhandler.cpp
@@ -26,8 +26,6 @@
#include "net/manaserv/manaserv_protocol.h"
#include "net/manaserv/messagein.h"
-#include "log.h"
-
namespace ManaServ {
ItemHandler::ItemHandler()
diff --git a/src/net/manaserv/network.cpp b/src/net/manaserv/network.cpp
index b8d3fa93..d69d3397 100644
--- a/src/net/manaserv/network.cpp
+++ b/src/net/manaserv/network.cpp
@@ -88,17 +88,13 @@ Connection *getConnection()
void registerHandler(MessageHandler *handler)
{
for (const uint16_t *i = handler->handledMessages; *i; i++)
- {
mMessageHandlers[*i] = handler;
- }
}
void unregisterHandler(MessageHandler *handler)
{
for (const uint16_t *i = handler->handledMessages; *i; i++)
- {
mMessageHandlers.erase(*i);
- }
}
void clearNetworkHandlers()
diff --git a/src/net/tmwa/abilityhandler.cpp b/src/net/tmwa/abilityhandler.cpp
index e3e5d3bc..ab891b40 100644
--- a/src/net/tmwa/abilityhandler.cpp
+++ b/src/net/tmwa/abilityhandler.cpp
@@ -82,18 +82,15 @@ AbilityHandler::AbilityHandler()
void AbilityHandler::handleMessage(MessageIn &msg)
{
- int skillCount;
- int skillId;
-
switch (msg.getId())
{
- case SMSG_PLAYER_SKILLS:
+ case SMSG_PLAYER_SKILLS: {
msg.readInt16(); // length
- skillCount = (msg.getLength() - 4) / 37;
+ const int skillCount = (msg.getLength() - 4) / 37;
for (int k = 0; k < skillCount; k++)
{
- skillId = msg.readInt16();
+ int skillId = msg.readInt16();
msg.readInt16(); // target type
msg.skip(2); // unused
int level = msg.readInt16();
@@ -107,10 +104,11 @@ void AbilityHandler::handleMessage(MessageIn &msg)
skillDialog->setModifiable(skillId, up);
}
break;
+ }
case SMSG_PLAYER_SKILL_UP:
{
- skillId = msg.readInt16();
+ int skillId = msg.readInt16();
int level = msg.readInt16();
msg.readInt16(); // sp
msg.readInt16(); // range
@@ -124,20 +122,20 @@ void AbilityHandler::handleMessage(MessageIn &msg)
case SMSG_SKILL_FAILED:
// Action failed (ex. sit because you have not reached the
// right level)
- skillId = msg.readInt16();
- short bskill = msg.readInt16();
- msg.readInt16(); // unknown
- char success = msg.readInt8();
- char reason = msg.readInt8();
- if (success != SKILL_FAILED && bskill == BSKILL_EMOTE)
+ int skillId = msg.readInt16();
+ auto btype = msg.readInt16();
+ msg.readInt16(); // zero1
+ msg.readInt8(); // zero2
+ auto type = msg.readInt8();
+ if (btype == BSKILL_EMOTE)
{
- logger->log("Action: %d/%d", bskill, success);
+ logger->log("Action: %d", btype);
}
std::string msg;
- if (success == SKILL_FAILED && skillId == SKILL_BASIC)
+ if (skillId == SKILL_BASIC)
{
- switch (bskill)
+ switch (btype)
{
case BSKILL_TRADE:
msg = _("Trade failed!");
@@ -161,7 +159,7 @@ void AbilityHandler::handleMessage(MessageIn &msg)
msg += " ";
- switch (reason)
+ switch (type)
{
case RFAIL_SKILLDEP:
msg += _("You have not yet reached a high enough lvl!");
diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h
index 49f0e26e..ce8231bd 100644
--- a/src/net/tmwa/inventoryhandler.h
+++ b/src/net/tmwa/inventoryhandler.h
@@ -37,7 +37,7 @@
#include "utils/gettext.h"
-#include <list>
+#include <vector>
namespace TmwAthena {
diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp
index 5a2dd0d0..353495da 100644
--- a/src/net/tmwa/network.cpp
+++ b/src/net/tmwa/network.cpp
@@ -331,20 +331,16 @@ void Network::disconnect()
void Network::registerHandler(MessageHandler *handler)
{
- for (const Uint16 *i = handler->handledMessages; *i; ++i)
- {
+ for (const uint16_t *i = handler->handledMessages; *i; ++i)
mMessageHandlers[*i] = handler;
- }
handler->setNetwork(this);
}
void Network::unregisterHandler(MessageHandler *handler)
{
- for (const Uint16 *i = handler->handledMessages; *i; ++i)
- {
+ for (const uint16_t *i = handler->handledMessages; *i; ++i)
mMessageHandlers.erase(*i);
- }
handler->setNetwork(nullptr);
}
@@ -352,9 +348,8 @@ void Network::unregisterHandler(MessageHandler *handler)
void Network::clearHandlers()
{
for (auto& [_, messageHandler] : mMessageHandlers)
- {
messageHandler->setNetwork(nullptr);
- }
+
mMessageHandlers.clear();
}
diff --git a/src/resources/attributes.cpp b/src/resources/attributes.cpp
index ab270b65..7ec6b516 100644
--- a/src/resources/attributes.cpp
+++ b/src/resources/attributes.cpp
@@ -40,7 +40,7 @@
namespace Attributes {
- using Attribute = struct
+ struct Attribute
{
unsigned int id;
std::string name;
@@ -94,11 +94,11 @@ namespace Attributes {
{
// Fill up the modifiable attribute label list.
attributeLabels.clear();
- for (auto it = attributes.cbegin(), it_end = attributes.cend(); it != it_end; it++)
+ for (const auto &[_, attribute] : attributes)
{
- if (it->second.modifiable &&
- (it->second.scope == "character" || it->second.scope == "being"))
- attributeLabels.push_back(it->second.name + ":");
+ if (attribute.modifiable &&
+ (attribute.scope == "character" || attribute.scope == "being"))
+ attributeLabels.push_back(attribute.name + ":");
}
}
@@ -228,7 +228,7 @@ namespace Attributes {
void init()
{
- if (attributes.size())
+ if (!attributes.empty())
unload();
}
@@ -238,14 +238,14 @@ namespace Attributes {
void readAttributeNode(XML::Node node, const std::string &filename)
{
int id = node.getProperty("id", 0);
-
if (!id)
{
logger->log("Attributes: Invalid or missing stat ID in "
DEFAULT_ATTRIBUTESDB_FILE "!");
return;
}
- else if (attributes.find(id) != attributes.end())
+
+ if (attributes.find(id) != attributes.end())
{
logger->log("Attributes: Redefinition of stat ID %d", id);
}
@@ -364,23 +364,23 @@ namespace Attributes {
{
std::list<ItemStat> dbStats;
- for (auto it = tags.cbegin(), it_end = tags.cend(); it != it_end; ++it)
- dbStats.emplace_back(it->first, it->second);
+ for (const auto &[tag, format] : tags)
+ dbStats.emplace_back(tag, format);
setStatsList(std::move(dbStats));
}
void informStatusWindow()
{
- for (auto it = attributes.cbegin(), it_end = attributes.cend(); it != it_end; it++)
+ for (const auto &[_, attribute] : attributes)
{
- if (it->second.playerInfoId == -1 &&
- (it->second.scope == "character" || it->second.scope == "being"))
+ if (attribute.playerInfoId == -1 &&
+ (attribute.scope == "character" || attribute.scope == "being"))
{
- statusWindow->addAttribute(it->second.id,
- it->second.name,
- it->second.modifiable,
- it->second.description);
+ statusWindow->addAttribute(attribute.id,
+ attribute.name,
+ attribute.modifiable,
+ attribute.description);
}
}
}