summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-21 13:44:03 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-21 13:44:03 +0300
commit46d1266f00dfde5d04d7980daea4bab02e77cb69 (patch)
treeadfaa8bdc5b96bf951de15119b1a0854e2eedc9f
parentba88670fe4b5f4606f80651f6433cc755ab6b6c1 (diff)
downloadmanaverse-46d1266f00dfde5d04d7980daea4bab02e77cb69.tar.gz
manaverse-46d1266f00dfde5d04d7980daea4bab02e77cb69.tar.bz2
manaverse-46d1266f00dfde5d04d7980daea4bab02e77cb69.tar.xz
manaverse-46d1266f00dfde5d04d7980daea4bab02e77cb69.zip
Use MercenaryInfo object for storing mercenary attributes.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/actormanager.cpp2
-rw-r--r--src/being/being.cpp6
-rw-r--r--src/being/localplayer.cpp1
-rw-r--r--src/being/localplayer.h7
-rw-r--r--src/being/mercenaryinfo.h39
-rw-r--r--src/being/playerinfo.cpp15
-rw-r--r--src/being/playerinfo.h6
-rw-r--r--src/net/eathena/mercenaryhandler.cpp9
10 files changed, 77 insertions, 10 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 64df67770..a38612688 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -889,6 +889,7 @@ SET(SRCS
localconsts.h
being/localplayer.cpp
being/localplayer.h
+ being/mercenaryinfo.h
being/pickup.h
logger.cpp
logger.h
diff --git a/src/Makefile.am b/src/Makefile.am
index ab50ef03a..fdb58fb72 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1009,6 +1009,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
localconsts.h \
being/localplayer.cpp \
being/localplayer.h \
+ being/mercenaryinfo.h \
being/pickup.h \
logger.cpp \
logger.h \
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index 7f4114c1c..5bb9c64aa 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -813,6 +813,7 @@ void ActorManager::logic()
if (beingEquipmentWindow)
beingEquipmentWindow->resetBeing(being);
}
+/*
else if (localPlayer && type == ActorType::Mercenary)
{
if (actor->getId() == localPlayer->getMercenary())
@@ -825,6 +826,7 @@ void ActorManager::logic()
}
}
}
+*/
if (localPlayer)
{
if (localPlayer->getTarget() == actor)
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 40d20fe98..047d351fc 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -259,7 +259,11 @@ Being::~Being()
delete2(mChat);
if (mOwner)
- mOwner->unassignPet(this);
+ {
+ if (mType == ActorType::LocalPet)
+ mOwner->unassignPet(this);
+ mOwner = nullptr;
+ }
FOR_EACH (std::vector<Being*>::iterator, it, mPets)
{
Being *pet = *it;
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 062a06678..30e323d7e 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -153,7 +153,6 @@ LocalPlayer::LocalPlayer(const int id, const uint16_t subtype) :
mTestParticleName(),
mTestParticleTime(0),
mTestParticleHash(0L),
- mMercenaryId(0),
mWalkingDir(0),
mUpdateName(true),
mBlockAdvert(false),
diff --git a/src/being/localplayer.h b/src/being/localplayer.h
index d90e94dc1..ed2b42b53 100644
--- a/src/being/localplayer.h
+++ b/src/being/localplayer.h
@@ -403,12 +403,6 @@ class LocalPlayer final : public Being,
AwayListener *getAwayListener() const A_WARN_UNUSED
{ return mAwayListener; }
- void setMercenary(const int id)
- { mMercenaryId = id; }
-
- int getMercenary() const
- { return mMercenaryId; }
-
protected:
void updateCoords() override final;
@@ -490,7 +484,6 @@ class LocalPlayer final : public Being,
std::string mTestParticleName;
int mTestParticleTime;
unsigned long mTestParticleHash;
- int mMercenaryId;
unsigned char mWalkingDir; // The direction the player is walking in.
/** Whether or not the name settings have changed */
bool mUpdateName;
diff --git a/src/being/mercenaryinfo.h b/src/being/mercenaryinfo.h
new file mode 100644
index 000000000..6bb9fd84d
--- /dev/null
+++ b/src/being/mercenaryinfo.h
@@ -0,0 +1,39 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef BEING_MERCENARYINFO_H
+#define BEING_MERCENARYINFO_H
+
+#include "localconsts.h"
+
+struct MercenaryInfo final
+{
+ MercenaryInfo() :
+ id(0),
+ name()
+ { }
+
+ A_DELETE_COPY(MercenaryInfo)
+
+ int id;
+ std::string name;
+};
+
+#endif // BEING_MERCENARYINFO_H
diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp
index 6ab9015e6..993c4d8a6 100644
--- a/src/being/playerinfo.cpp
+++ b/src/being/playerinfo.cpp
@@ -26,6 +26,7 @@
#include "inventory.h"
#include "being/attributes.h"
+#include "being/mercenaryinfo.h"
#include "itemsoundmanager.h"
@@ -53,6 +54,7 @@ int mCharId = 0;
Inventory *mInventory = nullptr;
Equipment *mEquipment = nullptr;
+MercenaryInfo *mMercenary = nullptr;
bool mTrading = false;
int mLevelProgress = 0;
@@ -388,6 +390,7 @@ void init()
void deinit()
{
clearInventory();
+ delete2(mMercenary);
}
void loadData()
@@ -462,4 +465,16 @@ bool isItemProtected(const int id)
return mProtectedItems.find(id) != mProtectedItems.end();
}
+void setMercenary(MercenaryInfo *const info)
+{
+ if (mMercenary)
+ delete mMercenary;
+ mMercenary = info;
+}
+
+MercenaryInfo *getMercenary()
+{
+ return mMercenary;
+}
+
} // namespace PlayerInfo
diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h
index abdc8bc69..c01fdd237 100644
--- a/src/being/playerinfo.h
+++ b/src/being/playerinfo.h
@@ -62,6 +62,8 @@ class FloorItem;
class Inventory;
class Item;
+struct MercenaryInfo;
+
/**
* A database like namespace which holds global info about the localplayer
*
@@ -234,6 +236,10 @@ namespace PlayerInfo
bool isItemProtected(const int id);
+ MercenaryInfo *getMercenary();
+
+ void setMercenary(MercenaryInfo *const info);
+
} // namespace PlayerInfo
#endif // BEING_PLAYERINFO_H
diff --git a/src/net/eathena/mercenaryhandler.cpp b/src/net/eathena/mercenaryhandler.cpp
index 424bc337c..a614cf429 100644
--- a/src/net/eathena/mercenaryhandler.cpp
+++ b/src/net/eathena/mercenaryhandler.cpp
@@ -25,6 +25,7 @@
#include "being/being.h"
#include "being/localplayer.h"
+#include "being/mercenaryinfo.h"
#include "being/playerinfo.h"
#include "gui/windows/skilldialog.h"
@@ -111,8 +112,14 @@ void MercenaryHandler::processMercenaryInfo(Net::MessageIn &msg)
dstBeing->setName(name);
dstBeing->setLevel(level);
dstBeing->setAttackRange(range);
+ dstBeing->setOwner(localPlayer);
if (localPlayer)
- localPlayer->setMercenary(dstBeing->getId());
+ {
+ MercenaryInfo *const mercenary = new MercenaryInfo;
+ mercenary->id = dstBeing->getId();
+ mercenary->name = name;
+ PlayerInfo::setMercenary(mercenary);
+ }
}
}