summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-02 17:26:44 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-02 17:27:39 +0100
commit72ceaaa426166bfa425f519c2418a66872839e12 (patch)
tree1ce7253fc629d4df445b89b2f533899341f03fc5 /src
parent78d6d9352f66f41963207b04a999d94c17d67cf2 (diff)
downloadMana-72ceaaa426166bfa425f519c2418a66872839e12.tar.gz
Mana-72ceaaa426166bfa425f519c2418a66872839e12.tar.bz2
Mana-72ceaaa426166bfa425f519c2418a66872839e12.tar.xz
Mana-72ceaaa426166bfa425f519c2418a66872839e12.zip
Changed server type to "enum class"
Diffstat (limited to 'src')
-rw-r--r--src/actorsprite.cpp3
-rw-r--r--src/being.cpp2
-rw-r--r--src/client.cpp10
-rw-r--r--src/commandhandler.cpp2
-rw-r--r--src/gui/charcreatedialog.cpp4
-rw-r--r--src/gui/charselectdialog.cpp2
-rw-r--r--src/gui/customserverdialog.cpp10
-rw-r--r--src/gui/ministatuswindow.cpp2
-rw-r--r--src/gui/popupmenu.cpp2
-rw-r--r--src/gui/selldialog.cpp2
-rw-r--r--src/gui/serverdialog.cpp12
-rw-r--r--src/gui/skilldialog.cpp2
-rw-r--r--src/gui/statuswindow.cpp2
-rw-r--r--src/gui/viewport.cpp6
-rw-r--r--src/localplayer.cpp2
-rw-r--r--src/map.cpp2
-rw-r--r--src/net/net.cpp16
-rw-r--r--src/net/net.h2
-rw-r--r--src/net/serverinfo.h51
-rw-r--r--src/party.cpp2
-rw-r--r--src/resources/monsterdb.cpp2
-rw-r--r--src/resources/settingsmanager.cpp2
-rw-r--r--src/statuseffect.cpp39
-rw-r--r--src/statuseffect.h5
24 files changed, 86 insertions, 98 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp
index db9f274f..088bc9f4 100644
--- a/src/actorsprite.cpp
+++ b/src/actorsprite.cpp
@@ -30,8 +30,7 @@
#include "sound.h"
#include "statuseffect.h"
-#include "net/net.h"
-
+#include "resources/animation.h"
#include "resources/image.h"
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
diff --git a/src/being.cpp b/src/being.cpp
index 98ba78e1..ad43ec52 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -949,7 +949,7 @@ void Being::showName()
}
// Display the IP when under tmw-Athena (GM only).
- if (Net::getNetworkType() == ServerInfo::TMWATHENA && local_player
+ if (Net::getNetworkType() == ServerType::TMWATHENA && local_player
&& local_player->getShowIp() && player->getIp())
{
mDisplayName += strprintf(" %s", ipToString(player->getIp()));
diff --git a/src/client.cpp b/src/client.cpp
index f90ca05a..98c8be30 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -384,12 +384,12 @@ Client::Client(const Options &options):
loginData.remember = config.getBoolValue("remember");
loginData.registerLogin = false;
- if (mCurrentServer.type == ServerInfo::UNKNOWN && mCurrentServer.port != 0)
+ if (mCurrentServer.type == ServerType::UNKNOWN && mCurrentServer.port != 0)
{
mCurrentServer.type = ServerInfo::defaultServerTypeForPort(mCurrentServer.port);
}
- if (mCurrentServer.type == ServerInfo::UNKNOWN)
+ if (mCurrentServer.type == ServerType::UNKNOWN)
{
mCurrentServer.type = ServerInfo::parseType(
branding.getValue("defaultServerType", "tmwathena"));
@@ -754,10 +754,10 @@ int Client::exec()
switch (Net::getNetworkType())
{
- case ServerInfo::TMWATHENA:
+ case ServerType::TMWATHENA:
itemDb = new TmwAthena::TaItemDB;
break;
- case ServerInfo::MANASERV:
+ case ServerType::MANASERV:
itemDb = new ManaServ::ManaServItemDB;
break;
default:
@@ -815,7 +815,7 @@ int Client::exec()
Net::getGameHandler()->connect();
mCurrentDialog = new ConnectionDialog(
_("Connecting to the game server"),
- Net::getNetworkType() == ServerInfo::TMWATHENA ?
+ Net::getNetworkType() == ServerType::TMWATHENA ?
STATE_CHOOSE_SERVER : STATE_SWITCH_CHARACTER);
break;
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 01975d80..addb7367 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -115,7 +115,7 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
{
handlePresent(args, tab);
}
- else if (type == "showip" && Net::getNetworkType() == ServerInfo::TMWATHENA)
+ else if (type == "showip" && Net::getNetworkType() == ServerType::TMWATHENA)
{
handleShowIp(args, tab);
}
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp
index fd27c89c..0d8a928e 100644
--- a/src/gui/charcreatedialog.cpp
+++ b/src/gui/charcreatedialog.cpp
@@ -167,7 +167,7 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
{
if (event.getId() == "create")
{
- if (Net::getNetworkType() == ServerInfo::MANASERV
+ if (Net::getNetworkType() == ServerType::MANASERV
|| getName().length() >= 4)
{
// Attempt to create the character
@@ -175,7 +175,7 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
int characterSlot = mSlot;
// On Manaserv, the slots start at 1, so we offset them.
- if (Net::getNetworkType() == ServerInfo::MANASERV)
+ if (Net::getNetworkType() == ServerType::MANASERV)
++characterSlot;
// Should avoid the most common crash case
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index 4bd712f6..a0a14c65 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -277,7 +277,7 @@ void CharSelectDialog::setCharacters(const Net::Characters &characters)
// Slots Number start at 1 for Manaserv, so we offset them by one.
int characterSlot = character->slot;
- if (Net::getNetworkType() == ServerInfo::MANASERV
+ if (Net::getNetworkType() == ServerType::MANASERV
&& characterSlot > 0)
--characterSlot;
diff --git a/src/gui/customserverdialog.cpp b/src/gui/customserverdialog.cpp
index 455951ec..c4fadca9 100644
--- a/src/gui/customserverdialog.cpp
+++ b/src/gui/customserverdialog.cpp
@@ -128,7 +128,7 @@ CustomServerDialog::CustomServerDialog(ServerDialog *parent, int index):
mServerAddressField->setText(serverInfo.hostname);
mPortField->setText(toString(serverInfo.port));
#ifdef MANASERV_SUPPORT
- mTypeField->setSelected(serverInfo.type == ServerInfo::TMWATHENA ?
+ mTypeField->setSelected(serverInfo.type == ServerType::TMWATHENA ?
0 : 1);
#endif
}
@@ -180,16 +180,16 @@ void CustomServerDialog::action(const gcn::ActionEvent &event)
switch (mTypeField->getSelected())
{
case 0:
- serverInfo.type = ServerInfo::TMWATHENA;
+ serverInfo.type = ServerType::TMWATHENA;
break;
case 1:
- serverInfo.type = ServerInfo::MANASERV;
+ serverInfo.type = ServerType::MANASERV;
break;
default:
- serverInfo.type = ServerInfo::UNKNOWN;
+ serverInfo.type = ServerType::UNKNOWN;
}
#else
- serverInfo.type = ServerInfo::TMWATHENA;
+ serverInfo.type = ServerType::TMWATHENA;
#endif
if (mPortField->getText().empty())
serverInfo.port = ServerInfo::defaultPortForServerType(serverInfo.type);
diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp
index 29718ed6..9988df48 100644
--- a/src/gui/ministatuswindow.cpp
+++ b/src/gui/ministatuswindow.cpp
@@ -143,7 +143,7 @@ void MiniStatusWindow::event(Event::Channel channel,
}
if (event.getType() == Event::UpdateStat)
{
- if (Net::getNetworkType() == ServerInfo::TMWATHENA &&
+ if (Net::getNetworkType() == ServerType::TMWATHENA &&
event.getInt("id") == TmwAthena::MATK)
{
StatusWindow::updateMPBar(mMpBar);
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 048ecc78..dec3faf9 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -127,7 +127,7 @@ void PopupMenu::showPopup(int x, int y, Being *being)
strprintf(_("Invite %s to join your guild"),
name.c_str()).c_str()));
if (local_player->isInParty() ||
- Net::getNetworkType() == ServerInfo::MANASERV)
+ Net::getNetworkType() == ServerType::MANASERV)
{
mBrowserBox->addRow(strprintf("@@party|%s@@",
strprintf(_("Invite %s to join your party"),
diff --git a/src/gui/selldialog.cpp b/src/gui/selldialog.cpp
index 38730862..ef694f96 100644
--- a/src/gui/selldialog.cpp
+++ b/src/gui/selldialog.cpp
@@ -205,7 +205,7 @@ void SellDialog::action(const gcn::ActionEvent &event)
sellCount = item->sellCurrentDuplicate(mAmountItems);
// For Manaserv, the Item id is to be given as index.
- if ((Net::getNetworkType() == ServerInfo::MANASERV))
+ if ((Net::getNetworkType() == ServerType::MANASERV))
itemIndex = item->getId();
Net::getNpcHandler()->sellItem(mNpcId, itemIndex, sellCount);
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 0bff4c9e..bad2c2b5 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -55,13 +55,13 @@
static const int MAX_SERVERLIST = 6;
-static std::string serverTypeToString(ServerInfo::Type type)
+static std::string serverTypeToString(ServerType type)
{
switch (type)
{
- case ServerInfo::TMWATHENA:
+ case ServerType::TMWATHENA:
return "TmwAthena";
- case ServerInfo::MANASERV:
+ case ServerType::MANASERV:
return "ManaServ";
default:
return std::string();
@@ -267,7 +267,7 @@ void ServerDialog::action(const gcn::ActionEvent &event)
// Check login
if (index < 0
#ifndef MANASERV_SUPPORT
- || mServersListModel->getServer(index).type == ServerInfo::MANASERV
+ || mServersListModel->getServer(index).type == ServerType::MANASERV
#endif
)
{
@@ -458,9 +458,9 @@ void ServerDialog::loadServers()
server.type = ServerInfo::parseType(type);
// Ignore unknown server types
- if (server.type == ServerInfo::UNKNOWN
+ if (server.type == ServerType::UNKNOWN
#ifndef MANASERV_SUPPORT
- || server.type == ServerInfo::MANASERV
+ || server.type == ServerType::MANASERV
#endif
)
{
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 96a57e54..c43183a2 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -327,7 +327,7 @@ void SkillDialog::loadSkills()
{
logger->log("Error loading skills file: %s", SKILLS_FILE);
- if (Net::getNetworkType() == ServerInfo::TMWATHENA)
+ if (Net::getNetworkType() == ServerType::TMWATHENA)
{
auto *model = new SkillModel();
auto *skill = new SkillInfo;
diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp
index ef6ca62e..ffcfa350 100644
--- a/src/gui/statuswindow.cpp
+++ b/src/gui/statuswindow.cpp
@@ -290,7 +290,7 @@ void StatusWindow::event(Event::Channel channel,
it->second->update();
}
- if (Net::getNetworkType() == ServerInfo::TMWATHENA &&
+ if (Net::getNetworkType() == ServerType::TMWATHENA &&
id == TmwAthena::MATK)
{
updateMPBar(mMpBar, true);
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 8c174c8d..a31a65f6 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -323,11 +323,11 @@ void Viewport::_drawDebugPath(Graphics *graphics)
unsigned char walkMask;
switch (Net::getNetworkType())
{
- case ServerInfo::TMWATHENA:
+ case ServerType::TMWATHENA:
walkMask = Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER;
break;
- case ServerInfo::MANASERV:
- default:
+ case ServerType::MANASERV:
+ default:
walkMask = Map::BLOCKMASK_WALL;
break;
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 288dfd33..92224c03 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -936,7 +936,7 @@ void LocalPlayer::setAttackRange(int range)
{
mAttackRange = range;
}
- else if (Net::getNetworkType() == ServerInfo::TMWATHENA)
+ else if (Net::getNetworkType() == ServerType::TMWATHENA)
{
// TODO: Fix this to be more generic
Item *weapon = PlayerInfo::getEquipment(TmwAthena::EQUIP_FIGHT1_SLOT);
diff --git a/src/map.cpp b/src/map.cpp
index 76f6b56b..1ddc8b65 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -886,7 +886,7 @@ Path Map::findPath(int startX, int startY, int destX, int destY,
// It costs extra to walk through a being (needs to be enough
// to make it more attractive to walk around).
// N.B.: Specific to TmwAthena for now.
- if (Net::getNetworkType() == ServerInfo::TMWATHENA &&
+ if (Net::getNetworkType() == ServerType::TMWATHENA &&
occupied(x, y))
{
Gcost += 3 * basicCost;
diff --git a/src/net/net.cpp b/src/net/net.cpp
index c060d2e8..86f7dc13 100644
--- a/src/net/net.cpp
+++ b/src/net/net.cpp
@@ -125,18 +125,18 @@ Net::TradeHandler *Net::getTradeHandler()
namespace Net
{
-ServerInfo::Type networkType = ServerInfo::UNKNOWN;
+ServerType networkType = ServerType::UNKNOWN;
void connectToServer(ServerInfo &server)
{
- if (server.type == ServerInfo::UNKNOWN)
+ if (server.type == ServerType::UNKNOWN)
{
// TODO: Query the server about itself and choose the netcode based on
// that
if (server.port == 6901)
- server.type = ServerInfo::TMWATHENA;
+ server.type = ServerType::TMWATHENA;
else if (server.port == 9601)
- server.type = ServerInfo::MANASERV;
+ server.type = ServerType::MANASERV;
else
logger->error(_("Unknown Server Type! Exiting."));
}
@@ -147,7 +147,7 @@ void connectToServer(ServerInfo &server)
}
else
{
- if (networkType != ServerInfo::UNKNOWN && getGeneralHandler() != nullptr)
+ if (networkType != ServerType::UNKNOWN && getGeneralHandler() != nullptr)
{
getGeneralHandler()->unload();
}
@@ -155,11 +155,11 @@ void connectToServer(ServerInfo &server)
switch (server.type)
{
#ifdef MANASERV_SUPPORT
- case ServerInfo::MANASERV:
+ case ServerType::MANASERV:
new ManaServ::GeneralHandler;
break;
#endif
- case ServerInfo::TMWATHENA:
+ case ServerType::TMWATHENA:
new TmwAthena::GeneralHandler;
break;
default:
@@ -186,7 +186,7 @@ void unload()
}
}
-ServerInfo::Type getNetworkType()
+ServerType getNetworkType()
{
return networkType;
}
diff --git a/src/net/net.h b/src/net/net.h
index 46a63ce9..135f2cb7 100644
--- a/src/net/net.h
+++ b/src/net/net.h
@@ -62,7 +62,7 @@ PlayerHandler *getPlayerHandler();
SpecialHandler *getSpecialHandler();
TradeHandler *getTradeHandler();
-ServerInfo::Type getNetworkType();
+ServerType getNetworkType();
/**
* Handles server detection and connection
diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h
index 481ef7cd..fd66c676 100644
--- a/src/net/serverinfo.h
+++ b/src/net/serverinfo.h
@@ -28,18 +28,19 @@
#include <deque>
#include <string>
+enum class ServerType
+{
+ UNKNOWN,
+ MANASERV,
+ TMWATHENA
+};
+
class ServerInfo
{
public:
- enum Type {
- UNKNOWN,
- MANASERV,
- TMWATHENA
- };
-
using VersionString = std::pair<int, std::string>;
- Type type = UNKNOWN;
+ ServerType type = ServerType::UNKNOWN;
std::string name;
std::string hostname;
uint16_t port = 0;
@@ -52,7 +53,7 @@ public:
bool isValid() const
{
- return !hostname.empty() && port != 0 && type != UNKNOWN;
+ return !hostname.empty() && port != 0 && type != ServerType::UNKNOWN;
}
void clear()
@@ -72,39 +73,39 @@ public:
port != other.port);
}
- static Type parseType(const std::string &type)
+ static ServerType parseType(const std::string &type)
{
if (compareStrI(type, "tmwathena") == 0)
- return TMWATHENA;
+ return ServerType::TMWATHENA;
// Used for backward compatibility
if (compareStrI(type, "eathena") == 0)
- return TMWATHENA;
+ return ServerType::TMWATHENA;
if (compareStrI(type, "manaserv") == 0)
- return MANASERV;
- return UNKNOWN;
+ return ServerType::MANASERV;
+ return ServerType::UNKNOWN;
}
- static uint16_t defaultPortForServerType(Type type)
+ static uint16_t defaultPortForServerType(ServerType type)
{
switch (type)
{
- default:
- case ServerInfo::UNKNOWN:
- return 0;
- case ServerInfo::TMWATHENA:
- return 6901;
- case ServerInfo::MANASERV:
- return 9601;
+ default:
+ case ServerType::UNKNOWN:
+ return 0;
+ case ServerType::TMWATHENA:
+ return 6901;
+ case ServerType::MANASERV:
+ return 9601;
}
}
- static Type defaultServerTypeForPort(uint16_t port)
+ static ServerType defaultServerTypeForPort(uint16_t port)
{
if (port == 6901)
- return TMWATHENA;
+ return ServerType::TMWATHENA;
if (port == 9601)
- return MANASERV;
- return UNKNOWN;
+ return ServerType::MANASERV;
+ return ServerType::UNKNOWN;
}
};
diff --git a/src/party.cpp b/src/party.cpp
index bfa867bf..92b6c22f 100644
--- a/src/party.cpp
+++ b/src/party.cpp
@@ -45,7 +45,7 @@ Party::~Party()
PartyMember *Party::addMember(int id, const std::string &name)
{
PartyMember *m;
- if (Net::getNetworkType() == ServerInfo::TMWATHENA && (m = getMember(id)))
+ if (Net::getNetworkType() == ServerType::TMWATHENA && (m = getMember(id)))
{
return m;
}
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index fc860958..49ee2174 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -54,7 +54,7 @@ void MonsterDB::init()
unload();
// This can be overridden by an 'offset' attribute on a 'monsters' root tag.
- mMonsterIdOffset = Net::getNetworkType() == ServerInfo::TMWATHENA ? OLD_TMWATHENA_OFFSET : 0;
+ mMonsterIdOffset = Net::getNetworkType() == ServerType::TMWATHENA ? OLD_TMWATHENA_OFFSET : 0;
}
void MonsterDB::setMonsterIdOffset(int offset)
diff --git a/src/resources/settingsmanager.cpp b/src/resources/settingsmanager.cpp
index f4a40577..28c08617 100644
--- a/src/resources/settingsmanager.cpp
+++ b/src/resources/settingsmanager.cpp
@@ -82,7 +82,7 @@ namespace SettingsManager
StatusEffect::checkStatus();
Units::checkStatus();
- if (Net::getNetworkType() == ServerInfo::MANASERV)
+ if (Net::getNetworkType() == ServerType::MANASERV)
{
Attributes::informItemDB();
}
diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp
index 42b48783..004e2f66 100644
--- a/src/statuseffect.cpp
+++ b/src/statuseffect.cpp
@@ -22,7 +22,6 @@
#include "statuseffect.h"
#include "event.h"
-#include "log.h"
#include "sound.h"
#include "configuration.h"
@@ -33,12 +32,8 @@
bool StatusEffect::mLoaded = false;
-StatusEffect::StatusEffect() :
- mPersistentParticleEffect(false)
-{}
-
-StatusEffect::~StatusEffect()
-{}
+StatusEffect::StatusEffect() = default;
+StatusEffect::~StatusEffect() = default;
void StatusEffect::playSFX()
{
@@ -56,33 +51,29 @@ Particle *StatusEffect::getParticle()
{
if (mParticleEffect.empty())
return nullptr;
- else
- return particleEngine->addEffect(mParticleEffect, 0, 0);
+ return particleEngine->addEffect(mParticleEffect, 0, 0);
}
AnimatedSprite *StatusEffect::getIcon()
{
if (mIcon.empty())
return nullptr;
- else
+
+ AnimatedSprite *sprite = AnimatedSprite::load(
+ paths.getStringValue("sprites") + mIcon);
+ if (false && sprite)
{
- AnimatedSprite *sprite = AnimatedSprite::load(
- paths.getStringValue("sprites") + mIcon);
- if (false && sprite)
- {
- sprite->play(SpriteAction::DEFAULT);
- sprite->reset();
- }
- return sprite;
+ sprite->play(SpriteAction::DEFAULT);
+ sprite->reset();
}
+ return sprite;
}
-std::string StatusEffect::getAction()
+std::string StatusEffect::getAction() const
{
if (mAction.empty())
return SpriteAction::INVALID;
- else
- return mAction;
+ return mAction;
}
@@ -162,10 +153,8 @@ void StatusEffect::checkStatus()
void unloadMap(std::map<int, StatusEffect *> map)
{
- std::map<int, StatusEffect *>::iterator it;
-
- for (it = map.begin(); it != map.end(); it++)
- delete (*it).second;
+ for (auto &[_, effect] : map)
+ delete effect;
map.clear();
}
diff --git a/src/statuseffect.h b/src/statuseffect.h
index 5b1a7e23..20e106a2 100644
--- a/src/statuseffect.h
+++ b/src/statuseffect.h
@@ -25,7 +25,6 @@
#include "particle.h"
#include "animatedsprite.h"
-#include "resources/animation.h"
#include "utils/xml.h"
class StatusEffect
@@ -59,7 +58,7 @@ public:
/**
* Retrieves an action to perform, or SpriteAction::INVALID
*/
- std::string getAction();
+ std::string getAction() const;
/**
* Determines whether the particle effect should be restarted when the
@@ -110,7 +109,7 @@ private:
std::string mParticleEffect;
std::string mIcon;
std::string mAction;
- bool mPersistentParticleEffect;
+ bool mPersistentParticleEffect = false;
};
#endif // !defined(STATUS_EFFECT_H)