diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-09-21 13:44:03 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-09-21 13:44:03 +0300 |
commit | 46d1266f00dfde5d04d7980daea4bab02e77cb69 (patch) | |
tree | adfaa8bdc5b96bf951de15119b1a0854e2eedc9f /src/being | |
parent | ba88670fe4b5f4606f80651f6433cc755ab6b6c1 (diff) | |
download | manaplus-46d1266f00dfde5d04d7980daea4bab02e77cb69.tar.gz manaplus-46d1266f00dfde5d04d7980daea4bab02e77cb69.tar.bz2 manaplus-46d1266f00dfde5d04d7980daea4bab02e77cb69.tar.xz manaplus-46d1266f00dfde5d04d7980daea4bab02e77cb69.zip |
Use MercenaryInfo object for storing mercenary attributes.
Diffstat (limited to 'src/being')
-rw-r--r-- | src/being/being.cpp | 6 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 1 | ||||
-rw-r--r-- | src/being/localplayer.h | 7 | ||||
-rw-r--r-- | src/being/mercenaryinfo.h | 39 | ||||
-rw-r--r-- | src/being/playerinfo.cpp | 15 | ||||
-rw-r--r-- | src/being/playerinfo.h | 6 |
6 files changed, 65 insertions, 9 deletions
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 |