From 38873bb99dea8a8089f1056bc1b28a59ed1f83d3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 13 Jun 2017 19:56:05 +0300 Subject: Move virtual methods from Being constructor to postInit. --- src/being/being.cpp | 20 +++++++++++++++++--- src/being/being.h | 12 +++++++++--- src/being/localplayer.cpp | 5 +++-- src/being/localplayer.h | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) (limited to 'src/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::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) -- cgit v1.2.3-70-g09d2