summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-10 14:57:39 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-10 14:57:39 +0300
commit3efda43abd11979adfd048fc62fe4f09e702f772 (patch)
tree80f8d0f65bf7648ae78e12badc11f13b4481b87a /src
parenta0c7a0e2d34a13f2c3e86f662e352977ebe2ae73 (diff)
downloadplus-3efda43abd11979adfd048fc62fe4f09e702f772.tar.gz
plus-3efda43abd11979adfd048fc62fe4f09e702f772.tar.bz2
plus-3efda43abd11979adfd048fc62fe4f09e702f772.tar.xz
plus-3efda43abd11979adfd048fc62fe4f09e702f772.zip
improve npchandler class.
Diffstat (limited to 'src')
-rw-r--r--src/net/ea/npchandler.cpp8
-rw-r--r--src/net/ea/npchandler.h8
-rw-r--r--src/net/eathena/npchandler.cpp42
-rw-r--r--src/net/eathena/npchandler.h33
-rw-r--r--src/net/npchandler.h34
-rw-r--r--src/net/tmwa/npchandler.cpp42
-rw-r--r--src/net/tmwa/npchandler.h34
7 files changed, 112 insertions, 89 deletions
diff --git a/src/net/ea/npchandler.cpp b/src/net/ea/npchandler.cpp
index 1640d3650..9f8e5b87f 100644
--- a/src/net/ea/npchandler.cpp
+++ b/src/net/ea/npchandler.cpp
@@ -34,19 +34,19 @@ NpcHandler::NpcHandler() :
{
}
-void NpcHandler::sendLetter(int npcId A_UNUSED,
+void NpcHandler::sendLetter(const int npcId A_UNUSED,
const std::string &recipient A_UNUSED,
- const std::string &text A_UNUSED)
+ const std::string &text A_UNUSED) const
{
// TODO
}
-void NpcHandler::startShopping(int beingId A_UNUSED)
+void NpcHandler::startShopping(const int beingId A_UNUSED) const
{
// TODO
}
-void NpcHandler::endShopping(int beingId A_UNUSED)
+void NpcHandler::endShopping(const int beingId A_UNUSED) const
{
// TODO
}
diff --git a/src/net/ea/npchandler.h b/src/net/ea/npchandler.h
index ea5bad135..526ced9f0 100644
--- a/src/net/ea/npchandler.h
+++ b/src/net/ea/npchandler.h
@@ -42,13 +42,13 @@ class NpcHandler : public Net::NpcHandler
A_DELETE_COPY(NpcHandler)
void sendLetter(int npcId, const std::string &recipient,
- const std::string &text);
+ const std::string &text) const override;
- void startShopping(int beingId);
+ void startShopping(int beingId) const override;
- void endShopping(int beingId);
+ void endShopping(int beingId) const override;
- void clearDialogs();
+ void clearDialogs() override;
virtual int getNpc(Net::MessageIn &msg,
bool haveLength) A_WARN_UNUSED = 0;
diff --git a/src/net/eathena/npchandler.cpp b/src/net/eathena/npchandler.cpp
index 530ba0416..e2d5a003a 100644
--- a/src/net/eathena/npchandler.cpp
+++ b/src/net/eathena/npchandler.cpp
@@ -112,20 +112,20 @@ void NpcHandler::handleMessage(Net::MessageIn &msg)
mDialog = nullptr;
}
-void NpcHandler::talk(int npcId)
+void NpcHandler::talk(const int npcId) const
{
MessageOut outMsg(CMSG_NPC_TALK);
outMsg.writeInt32(npcId);
outMsg.writeInt8(0); // Unused
}
-void NpcHandler::nextDialog(int npcId)
+void NpcHandler::nextDialog(const int npcId) const
{
MessageOut outMsg(CMSG_NPC_NEXT_REQUEST);
outMsg.writeInt32(npcId);
}
-void NpcHandler::closeDialog(int npcId)
+void NpcHandler::closeDialog(const int npcId)
{
MessageOut outMsg(CMSG_NPC_CLOSE);
outMsg.writeInt32(npcId);
@@ -133,29 +133,30 @@ void NpcHandler::closeDialog(int npcId)
const NpcDialogs::iterator it = mNpcDialogs.find(npcId);
if (it != mNpcDialogs.end())
{
- if ((*it).second.dialog)
- (*it).second.dialog->close();
- if ((*it).second.dialog == mDialog)
+ NpcDialog *const dialog = (*it).second.dialog;
+ if (dialog)
+ dialog->close();
+ if (dialog == mDialog)
mDialog = nullptr;
mNpcDialogs.erase(it);
}
}
-void NpcHandler::listInput(int npcId, unsigned char value)
+void NpcHandler::listInput(const int npcId, const unsigned char value) const
{
MessageOut outMsg(CMSG_NPC_LIST_CHOICE);
outMsg.writeInt32(npcId);
outMsg.writeInt8(value);
}
-void NpcHandler::integerInput(int npcId, int value)
+void NpcHandler::integerInput(const int npcId, const int value) const
{
MessageOut outMsg(CMSG_NPC_INT_RESPONSE);
outMsg.writeInt32(npcId);
outMsg.writeInt32(value);
}
-void NpcHandler::stringInput(int npcId, const std::string &value)
+void NpcHandler::stringInput(const int npcId, const std::string &value) const
{
MessageOut outMsg(CMSG_NPC_STR_RESPONSE);
outMsg.writeInt16(static_cast<int16_t>(value.length() + 9));
@@ -164,22 +165,23 @@ void NpcHandler::stringInput(int npcId, const std::string &value)
outMsg.writeInt8(0); // Prevent problems with string reading
}
-void NpcHandler::buy(int beingId)
+void NpcHandler::buy(const int beingId) const
{
MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST);
outMsg.writeInt32(beingId);
outMsg.writeInt8(0); // Buy
}
-void NpcHandler::sell(int beingId)
+void NpcHandler::sell(const int beingId) const
{
MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST);
outMsg.writeInt32(beingId);
outMsg.writeInt8(1); // Sell
}
-void NpcHandler::buyItem(int beingId A_UNUSED, int itemId,
- unsigned char color A_UNUSED, int amount)
+void NpcHandler::buyItem(const int beingId A_UNUSED, const int itemId,
+ const unsigned char color A_UNUSED,
+ const int amount) const
{
MessageOut outMsg(CMSG_NPC_BUY_REQUEST);
outMsg.writeInt16(8); // One item (length of packet)
@@ -187,7 +189,8 @@ void NpcHandler::buyItem(int beingId A_UNUSED, int itemId,
outMsg.writeInt16(static_cast<int16_t>(itemId));
}
-void NpcHandler::sellItem(int beingId A_UNUSED, int itemId, int amount)
+void NpcHandler::sellItem(const int beingId A_UNUSED,
+ const int itemId, const int amount) const
{
MessageOut outMsg(CMSG_NPC_SELL_REQUEST);
outMsg.writeInt16(8); // One item (length of packet)
@@ -195,7 +198,7 @@ void NpcHandler::sellItem(int beingId A_UNUSED, int itemId, int amount)
outMsg.writeInt16(static_cast<int16_t>(amount));
}
-int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength)
+int NpcHandler::getNpc(Net::MessageIn &msg, const bool haveLength)
{
if (haveLength)
msg.readInt16(); // length
@@ -231,9 +234,10 @@ int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength)
}
else
{
- if (mDialog && mDialog != diag->second.dialog)
+ NpcDialog *const dialog = diag->second.dialog;
+ if (mDialog && mDialog != dialog)
mDialog->restoreCamera();
- mDialog = diag->second.dialog;
+ mDialog = dialog;
if (mDialog)
mDialog->saveCamera();
}
@@ -241,14 +245,14 @@ int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength)
}
void NpcHandler::processNpcCutin(Net::MessageIn &msg A_UNUSED,
- int npcId A_UNUSED)
+ int npcId A_UNUSED) const
{
msg.readString(64); // image name
msg.readInt8(); // type
}
void NpcHandler::processNpcViewPoint(Net::MessageIn &msg A_UNUSED,
- int npcId A_UNUSED)
+ int npcId A_UNUSED) const
{
msg.readInt32(); // type
msg.readInt32(); // x
diff --git a/src/net/eathena/npchandler.h b/src/net/eathena/npchandler.h
index fc6a3fb6e..196da8398 100644
--- a/src/net/eathena/npchandler.h
+++ b/src/net/eathena/npchandler.h
@@ -44,33 +44,38 @@ class NpcHandler final : public MessageHandler, public Ea::NpcHandler
A_DELETE_COPY(NpcHandler)
- void handleMessage(Net::MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg) override;
- void talk(int npcId);
+ void talk(const int npcId) const override;
- void nextDialog(int npcId);
+ void nextDialog(const int npcId) const override;
- void closeDialog(int npcId);
+ void closeDialog(const int npcId) override;
- void listInput(int npcId, unsigned char value);
+ void listInput(const int npcId,
+ const unsigned char value) const override;
- void integerInput(int npcId, int value);
+ void integerInput(const int npcId, const int value) const override;
- void stringInput(int npcId, const std::string &value);
+ void stringInput(const int npcId,
+ const std::string &value) const override;
- void buy(int beingId);
+ void buy(const int beingId) const override;
- void sell(int beingId);
+ void sell(const int beingId) const override;
- void buyItem(int beingId, int itemId, unsigned char color, int amount);
+ void buyItem(const int beingId, const int itemId,
+ const unsigned char color,
+ const int amount) const override;
- void sellItem(int beingId, int itemId, int amount);
+ void sellItem(const int beingId, const int itemId,
+ const int amount) const override;
- int getNpc(Net::MessageIn &msg, bool haveLength);
+ int getNpc(Net::MessageIn &msg, const bool haveLength) override;
- void processNpcCutin(Net::MessageIn &msg, int npcId);
+ void processNpcCutin(Net::MessageIn &msg, const int npcId) const;
- void processNpcViewPoint(Net::MessageIn &msg, int npcId);
+ void processNpcViewPoint(Net::MessageIn &msg, const int npcId) const;
};
} // namespace EAthena
diff --git a/src/net/npchandler.h b/src/net/npchandler.h
index c0fa49a9a..685e04c57 100644
--- a/src/net/npchandler.h
+++ b/src/net/npchandler.h
@@ -34,33 +34,37 @@ class NpcHandler
virtual ~NpcHandler()
{ }
- virtual void talk(int npcId) = 0;
+ virtual void talk(const int npcId) const = 0;
- virtual void nextDialog(int npcId) = 0;
+ virtual void nextDialog(const int npcId) const = 0;
- virtual void closeDialog(int npcId) = 0;
+ virtual void closeDialog(const int npcId) = 0;
- virtual void listInput(int npcId, unsigned char value) = 0;
+ virtual void listInput(const int npcId,
+ const unsigned char value) const = 0;
- virtual void integerInput(int npcId, int value) = 0;
+ virtual void integerInput(const int npcId, const int value) const = 0;
- virtual void stringInput(int npcId, const std::string &value) = 0;
+ virtual void stringInput(const int npcId,
+ const std::string &value) const = 0;
- virtual void sendLetter(int npcId, const std::string &recipient,
- const std::string &text) = 0;
+ virtual void sendLetter(const int npcId, const std::string &recipient,
+ const std::string &text) const = 0;
- virtual void startShopping(int beingId) = 0;
+ virtual void startShopping(const int beingId) const = 0;
- virtual void buy(int beingId) = 0;
+ virtual void buy(const int beingId) const = 0;
- virtual void sell(int beingId) = 0;
+ virtual void sell(const int beingId) const = 0;
- virtual void buyItem(int beingId, int itemId, unsigned char color,
- int amount) = 0;
+ virtual void buyItem(const int beingId, const int itemId,
+ const unsigned char color,
+ const int amount) const = 0;
- virtual void sellItem(int beingId, int itemId, int amount) = 0;
+ virtual void sellItem(const int beingId, const int itemId,
+ const int amount) const = 0;
- virtual void endShopping(int beingId) = 0;
+ virtual void endShopping(const int beingId) const = 0;
virtual void clearDialogs() = 0;
};
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp
index 9166c5b84..0c55d8d7e 100644
--- a/src/net/tmwa/npchandler.cpp
+++ b/src/net/tmwa/npchandler.cpp
@@ -111,20 +111,20 @@ void NpcHandler::handleMessage(Net::MessageIn &msg)
BLOCK_END("NpcHandler::handleMessage")
}
-void NpcHandler::talk(int npcId)
+void NpcHandler::talk(const int npcId) const
{
MessageOut outMsg(CMSG_NPC_TALK);
outMsg.writeInt32(npcId);
outMsg.writeInt8(0); // Unused
}
-void NpcHandler::nextDialog(int npcId)
+void NpcHandler::nextDialog(const int npcId) const
{
MessageOut outMsg(CMSG_NPC_NEXT_REQUEST);
outMsg.writeInt32(npcId);
}
-void NpcHandler::closeDialog(int npcId)
+void NpcHandler::closeDialog(const int npcId)
{
MessageOut outMsg(CMSG_NPC_CLOSE);
outMsg.writeInt32(npcId);
@@ -132,29 +132,30 @@ void NpcHandler::closeDialog(int npcId)
const NpcDialogs::iterator it = mNpcDialogs.find(npcId);
if (it != mNpcDialogs.end())
{
- if ((*it).second.dialog)
- (*it).second.dialog->close();
- if ((*it).second.dialog == mDialog)
+ NpcDialog *const dialog = (*it).second.dialog;
+ if (dialog)
+ dialog->close();
+ if (dialog == mDialog)
mDialog = nullptr;
mNpcDialogs.erase(it);
}
}
-void NpcHandler::listInput(int npcId, unsigned char value)
+void NpcHandler::listInput(const int npcId, const unsigned char value) const
{
MessageOut outMsg(CMSG_NPC_LIST_CHOICE);
outMsg.writeInt32(npcId);
outMsg.writeInt8(value);
}
-void NpcHandler::integerInput(int npcId, int value)
+void NpcHandler::integerInput(const int npcId, const int value) const
{
MessageOut outMsg(CMSG_NPC_INT_RESPONSE);
outMsg.writeInt32(npcId);
outMsg.writeInt32(value);
}
-void NpcHandler::stringInput(int npcId, const std::string &value)
+void NpcHandler::stringInput(const int npcId, const std::string &value) const
{
MessageOut outMsg(CMSG_NPC_STR_RESPONSE);
outMsg.writeInt16(static_cast<int16_t>(value.length() + 9));
@@ -163,22 +164,22 @@ void NpcHandler::stringInput(int npcId, const std::string &value)
outMsg.writeInt8(0); // Prevent problems with string reading
}
-void NpcHandler::buy(int beingId)
+void NpcHandler::buy(const int beingId) const
{
MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST);
outMsg.writeInt32(beingId);
outMsg.writeInt8(0); // Buy
}
-void NpcHandler::sell(int beingId)
+void NpcHandler::sell(const int beingId) const
{
MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST);
outMsg.writeInt32(beingId);
outMsg.writeInt8(1); // Sell
}
-void NpcHandler::buyItem(int beingId A_UNUSED, int itemId,
- unsigned char color, int amount)
+void NpcHandler::buyItem(const int beingId A_UNUSED, const int itemId,
+ const unsigned char color, const int amount) const
{
MessageOut outMsg(CMSG_NPC_BUY_REQUEST);
if (serverVersion > 0)
@@ -197,7 +198,8 @@ void NpcHandler::buyItem(int beingId A_UNUSED, int itemId,
}
}
-void NpcHandler::sellItem(int beingId A_UNUSED, int itemId, int amount)
+void NpcHandler::sellItem(const int beingId A_UNUSED,
+ const int itemId, const int amount) const
{
MessageOut outMsg(CMSG_NPC_SELL_REQUEST);
outMsg.writeInt16(8); // One item (length of packet)
@@ -205,7 +207,7 @@ void NpcHandler::sellItem(int beingId A_UNUSED, int itemId, int amount)
outMsg.writeInt16(static_cast<int16_t>(amount));
}
-int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength)
+int NpcHandler::getNpc(Net::MessageIn &msg, const bool haveLength)
{
if (haveLength)
msg.readInt16(); // length
@@ -241,16 +243,17 @@ int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength)
}
else
{
- if (mDialog && mDialog != diag->second.dialog)
+ NpcDialog *const dialog = diag->second.dialog;
+ if (mDialog && mDialog != dialog)
mDialog->restoreCamera();
- mDialog = diag->second.dialog;
+ mDialog = dialog;
if (mDialog)
mDialog->saveCamera();
}
return npcId;
}
-void NpcHandler::processNpcCommand(Net::MessageIn &msg, int npcId)
+void NpcHandler::processNpcCommand(Net::MessageIn &msg, const int npcId)
{
const int cmd = msg.readInt16();
switch (cmd)
@@ -324,7 +327,8 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg, int npcId)
}
}
-void NpcHandler::processLangReuqest(Net::MessageIn &msg A_UNUSED, int npcId)
+void NpcHandler::processLangReuqest(Net::MessageIn &msg A_UNUSED,
+ const int npcId)
{
mRequestLang = false;
stringInput(npcId, getLangSimple());
diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h
index 1659cfb5c..139f37872 100644
--- a/src/net/tmwa/npchandler.h
+++ b/src/net/tmwa/npchandler.h
@@ -44,33 +44,39 @@ class NpcHandler final : public MessageHandler, public Ea::NpcHandler
A_DELETE_COPY(NpcHandler)
- void handleMessage(Net::MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg) override;
- void talk(int npcId);
+ void talk(const int npcId) const override;
- void nextDialog(int npcId);
+ void nextDialog(const int npcId) const override;
- void closeDialog(int npcId);
+ void closeDialog(const int npcId) override;
- void listInput(int npcId, unsigned char value);
+ void listInput(const int npcId,
+ const unsigned char value) const override;
- void integerInput(int npcId, int value);
+ void integerInput(const int npcId, const int value) const override;
- void stringInput(int npcId, const std::string &value);
+ void stringInput(const int npcId,
+ const std::string &value) const override;
- void buy(int beingId);
+ void buy(const int beingId) const override;
- void sell(int beingId);
+ void sell(const int beingId) const override;
- void buyItem(int beingId, int itemId, unsigned char color, int amount);
+ void buyItem(const int beingId, const int itemId,
+ const unsigned char color,
+ const int amount) const override;
- void sellItem(int beingId, int itemId, int amount);
+ void sellItem(const int beingId, const int itemId,
+ const int amount) const override;
- int getNpc(Net::MessageIn &msg, bool haveLength) A_WARN_UNUSED;
+ int getNpc(Net::MessageIn &msg,
+ const bool haveLength) override A_WARN_UNUSED;
- void processNpcCommand(Net::MessageIn &msg, int npcId);
+ void processNpcCommand(Net::MessageIn &msg, const int npcId);
- void processLangReuqest(Net::MessageIn &msg, int npcId);
+ void processLangReuqest(Net::MessageIn &msg, const int npcId);
private:
bool mRequestLang;