summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-06-13 19:56:05 +0300
committerAndrei Karas <akaras@inbox.ru>2017-06-13 19:56:05 +0300
commit38873bb99dea8a8089f1056bc1b28a59ed1f83d3 (patch)
tree702b19cf37f846f8a777777b958122d2cb562359 /src
parentc4d8fa788e0f89d73ba5ae2b66b79ad0351c5fbf (diff)
downloadmv-38873bb99dea8a8089f1056bc1b28a59ed1f83d3.tar.gz
mv-38873bb99dea8a8089f1056bc1b28a59ed1f83d3.tar.bz2
mv-38873bb99dea8a8089f1056bc1b28a59ed1f83d3.tar.xz
mv-38873bb99dea8a8089f1056bc1b28a59ed1f83d3.zip
Move virtual methods from Being constructor to postInit.
Diffstat (limited to 'src')
-rw-r--r--src/actormanager.cpp5
-rw-r--r--src/being/being.cpp20
-rw-r--r--src/being/being.h12
-rw-r--r--src/being/localplayer.cpp5
-rw-r--r--src/being/localplayer.h2
-rw-r--r--src/gui/windowmanager_unittest.cc4
-rw-r--r--src/gui/windows/charcreatedialog.cpp2
-rw-r--r--src/gui/windows/npcdialog.cpp2
-rw-r--r--src/utils/chatutils_unittest.cc14
9 files changed, 45 insertions, 21 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index 44e8e7cb7..bef691a71 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -277,7 +277,10 @@ Being *ActorManager::createBeing(const BeingId id,
const ActorTypeT type,
const BeingTypeId subtype)
{
- Being *const being = new Being(id, type, subtype, mMap);
+ Being *const being = Being::createBeing(id,
+ type,
+ subtype,
+ mMap);
mActors.insert(being);
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 97492d431..e954a5e97 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -156,9 +156,7 @@ static const unsigned int SPEECH_MAX_TIME = 800;
FOR_EACH (std::vector<AnimatedSprite*>::const_iterator, it, name)
Being::Being(const BeingId id,
- const ActorTypeT type,
- const BeingTypeId subtype,
- Map *const map) :
+ const ActorTypeT type) :
ActorSprite(id),
mNextSound(),
mInfo(BeingInfo::unknown),
@@ -277,7 +275,11 @@ Being::Being(const BeingId id,
for_each_badges()
mBadges[f] = nullptr;
+}
+void Being::postInit(const BeingTypeId subtype,
+ Map *const map)
+{
setMap(map);
setSubtype(subtype, 0);
@@ -5359,3 +5361,15 @@ void Being::setLanguageId(const int lang) restrict2 noexcept2
mLanguageId = lang;
}
}
+
+Being *Being::createBeing(const BeingId id,
+ const ActorTypeT type,
+ const BeingTypeId subType,
+ Map *const map)
+{
+ Being *const being = new Being(id,
+ type);
+ being->postInit(subType,
+ map);
+ return being;
+}
diff --git a/src/being/being.h b/src/being/being.h
index 52ea8b9ec..3d21311b7 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -102,9 +102,7 @@ class Being notfinal : public ActorSprite,
* @param map the map the being is on
*/
Being(const BeingId id,
- const ActorTypeT type,
- const BeingTypeId subtype,
- Map *const map);
+ const ActorTypeT type);
A_DELETE_COPY(Being)
@@ -1084,6 +1082,11 @@ class Being notfinal : public ActorSprite,
void fixDirectionOffsets(int &offsetX,
int &offsetY) const;
+ static Being *createBeing(const BeingId id,
+ const ActorTypeT type,
+ const BeingTypeId subtype,
+ Map *const map);
+
protected:
void drawPlayerSpriteAt(Graphics *restrict const graphics,
const int x,
@@ -1206,6 +1209,9 @@ class Being notfinal : public ActorSprite,
bool mIsGM;
protected:
+ void postInit(const BeingTypeId subType,
+ Map *const map);
+
/**
* Calculates the offset in the given directions.
* If walking in direction 'neg' the value is negated.
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index e2b126065..ea64bb0a3 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -110,8 +110,8 @@ extern OkDialog *weightNotice;
extern time_t weightNoticeTime;
LocalPlayer::LocalPlayer(const BeingId id,
- const BeingTypeId subtype) :
- Being(id, ActorType::Player, subtype, nullptr),
+ const BeingTypeId subType) :
+ Being(id, ActorType::Player),
ActorSpriteListener(),
AttributeListener(),
PlayerDeathListener(),
@@ -184,6 +184,7 @@ LocalPlayer::LocalPlayer(const BeingId id,
{
logger->log1("LocalPlayer::LocalPlayer");
+ postInit(subType, nullptr);
mAttackRange = 0;
mLevel = 1;
mAdvanced = true;
diff --git a/src/being/localplayer.h b/src/being/localplayer.h
index e123fa6a6..99cab9b55 100644
--- a/src/being/localplayer.h
+++ b/src/being/localplayer.h
@@ -58,7 +58,7 @@ class LocalPlayer final : public Being,
* Constructor.
*/
explicit LocalPlayer(const BeingId id,
- const BeingTypeId subtype = BeingTypeId_zero);
+ const BeingTypeId subType = BeingTypeId_zero);
A_DELETE_COPY(LocalPlayer)
diff --git a/src/gui/windowmanager_unittest.cc b/src/gui/windowmanager_unittest.cc
index 0928cb121..8f280036a 100644
--- a/src/gui/windowmanager_unittest.cc
+++ b/src/gui/windowmanager_unittest.cc
@@ -250,7 +250,7 @@ TEST_CASE("Windows tests", "windowmanager")
Map *map = new Map("test map",
10, 10,
32, 32);
- Being *being = new Being(BeingId_zero,
+ Being *being = Being::createBeing(BeingId_zero,
ActorType::Avatar,
id,
map);
@@ -404,7 +404,7 @@ TEST_CASE("Windows tests", "windowmanager")
{
Equipment *equipment = new Equipment;
Map *map = new Map("test", 100, 100, 32, 32);
- Being *being = new Being(BeingId_zero,
+ Being *being = Being::createBeing(BeingId_zero,
ActorType::Player,
BeingTypeId_zero,
map);
diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp
index 535ee956f..4d4e7b35b 100644
--- a/src/gui/windows/charcreatedialog.cpp
+++ b/src/gui/windows/charcreatedialog.cpp
@@ -112,7 +112,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
mCreateButton(new Button(this, _("Create"), "create", this)),
// TRANSLATORS: char create dialog button
mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
- mPlayer(new Being(BeingId_zero,
+ mPlayer(Being::createBeing(BeingId_zero,
ActorType::Player,
BeingTypeId_zero,
nullptr)),
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
index 453f35126..7b1cedfd2 100644
--- a/src/gui/windows/npcdialog.cpp
+++ b/src/gui/windows/npcdialog.cpp
@@ -1128,7 +1128,7 @@ void NpcDialog::showAvatar(const BeingTypeId avatarId)
if (needShow)
{
delete mAvatarBeing;
- mAvatarBeing = new Being(BeingId_zero,
+ mAvatarBeing = Being::createBeing(BeingId_zero,
ActorType::Avatar,
avatarId,
nullptr);
diff --git a/src/utils/chatutils_unittest.cc b/src/utils/chatutils_unittest.cc
index f6e608556..cbe87da9d 100644
--- a/src/utils/chatutils_unittest.cc
+++ b/src/utils/chatutils_unittest.cc
@@ -132,7 +132,7 @@ TEST_CASE("chatutils replaceVars", "")
SECTION("player")
{
- Being *player1 = new Being(static_cast<BeingId>(2),
+ Being *player1 = Being::createBeing(static_cast<BeingId>(2),
ActorType::Player,
BeingTypeId_zero,
nullptr);
@@ -147,7 +147,7 @@ TEST_CASE("chatutils replaceVars", "")
SECTION("monster")
{
- Being *const monster = new Being(static_cast<BeingId>(3),
+ Being *const monster = Being::createBeing(static_cast<BeingId>(3),
ActorType::Monster,
BeingTypeId_zero,
nullptr);
@@ -167,7 +167,7 @@ TEST_CASE("chatutils replaceVars", "")
replaceVars(str);
REQUIRE(str == "test ");
- Being *const player1 = new Being(static_cast<BeingId>(2),
+ Being *const player1 = Being::createBeing(static_cast<BeingId>(2),
ActorType::Player,
BeingTypeId_zero,
nullptr);
@@ -178,7 +178,7 @@ TEST_CASE("chatutils replaceVars", "")
replaceVars(str);
REQUIRE(str == "test player1");
- Being *const player2 = new Being(static_cast<BeingId>(4),
+ Being *const player2 = Being::createBeing(static_cast<BeingId>(4),
ActorType::Player,
BeingTypeId_zero,
nullptr);
@@ -203,7 +203,7 @@ TEST_CASE("chatutils replaceVars", "")
replaceVars(str);
REQUIRE(str == "test ");
- Being *const player1 = new Being(static_cast<BeingId>(2),
+ Being *const player1 = Being::createBeing(static_cast<BeingId>(2),
ActorType::Player,
BeingTypeId_zero,
nullptr);
@@ -215,7 +215,7 @@ TEST_CASE("chatutils replaceVars", "")
replaceVars(str);
REQUIRE(str == "test player1");
- Being *const player2 = new Being(static_cast<BeingId>(4),
+ Being *const player2 = Being::createBeing(static_cast<BeingId>(4),
ActorType::Player,
BeingTypeId_zero,
nullptr);
@@ -229,7 +229,7 @@ TEST_CASE("chatutils replaceVars", "")
Party *const party2 = Party::getParty(2);
- Being *const player3 = new Being(static_cast<BeingId>(5),
+ Being *const player3 = Being::createBeing(static_cast<BeingId>(5),
ActorType::Player,
BeingTypeId_zero,
nullptr);