From 568232c7a586b64ad6cdf508492a77d4c3e4e70b Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 5 Jan 2020 13:43:47 +0100 Subject: [PATCH] Split off initialization of Creature into new function that's not called in the constructor. This has to do with specific implementations of stat calculator requiring an inherited type of the Creature class, and by calling it in the constructor casting to this inherited type will fail. --- src/Battling/Models/CreateCreature.cpp | 6 ++++-- src/Battling/Models/Creature.cpp | 2 -- src/Battling/Models/Creature.hpp | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Battling/Models/CreateCreature.cpp b/src/Battling/Models/CreateCreature.cpp index ca66203..c8388b5 100644 --- a/src/Battling/Models/CreateCreature.cpp +++ b/src/Battling/Models/CreateCreature.cpp @@ -59,6 +59,8 @@ Creature* CreateCreature::Create() { auto kv = _attacks[i]; attacks[i] = new LearnedAttack(std::get<0>(kv), std::get<1>(kv)); } - return new Creature(_library, species, variant, _level, experience, identifier, gender, _coloring, heldItem, - _nickname, talent, attacks); + auto c = new Creature(_library, species, variant, _level, experience, identifier, gender, _coloring, heldItem, + _nickname, talent, attacks); + c->Initialize(); + return c; } diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index cfa6ccd..55a78e6 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -13,8 +13,6 @@ Battling::Creature::Creature(const BattleLibrary* library, const Library::Creatu : _library(library), __Species(species), __Variant(variant), __Level(level), __Experience(experience), __UniqueIdentifier(uid), __Gender(gender), __Coloring(coloring), __HeldItem(heldItem), _nickname(std::move(nickname)), _talentIndex(talent), _hasOverridenTalent(false), _attacks(std::move(attacks)) { - RecalculateFlatStats(); - __CurrentHealth = GetBoostedStat(Core::Statistic::Health); _activeTalent = _library->LoadScript(ScriptResolver::ScriptCategory::Talent, GetActiveTalent()); } diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 034d2f8..a7e1f20 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -68,6 +68,11 @@ namespace CreatureLib::Battling { } }; + virtual void Initialize() { + RecalculateFlatStats(); + __CurrentHealth = GetBoostedStat(Core::Statistic::Health); + } + void SetBattleData(Battle* battle, BattleSide* side); Battle* GetBattle() const; BattleSide* GetBattleSide() const;