Split off initialization of Creature into new function that's not called in the constructor.
All checks were successful
continuous-integration/drone/push Build is passing

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.
This commit is contained in:
2020-01-05 13:43:47 +01:00
parent dd8d4d738d
commit 568232c7a5
3 changed files with 9 additions and 4 deletions

View File

@@ -59,6 +59,8 @@ Creature* CreateCreature::Create() {
auto kv = _attacks[i]; auto kv = _attacks[i];
attacks[i] = new LearnedAttack(std::get<0>(kv), std::get<1>(kv)); attacks[i] = new LearnedAttack(std::get<0>(kv), std::get<1>(kv));
} }
return new Creature(_library, species, variant, _level, experience, identifier, gender, _coloring, heldItem, auto c = new Creature(_library, species, variant, _level, experience, identifier, gender, _coloring, heldItem,
_nickname, talent, attacks); _nickname, talent, attacks);
c->Initialize();
return c;
} }

View File

@@ -13,8 +13,6 @@ Battling::Creature::Creature(const BattleLibrary* library, const Library::Creatu
: _library(library), __Species(species), __Variant(variant), __Level(level), __Experience(experience), : _library(library), __Species(species), __Variant(variant), __Level(level), __Experience(experience),
__UniqueIdentifier(uid), __Gender(gender), __Coloring(coloring), __HeldItem(heldItem), __UniqueIdentifier(uid), __Gender(gender), __Coloring(coloring), __HeldItem(heldItem),
_nickname(std::move(nickname)), _talentIndex(talent), _hasOverridenTalent(false), _attacks(std::move(attacks)) { _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()); _activeTalent = _library->LoadScript(ScriptResolver::ScriptCategory::Talent, GetActiveTalent());
} }

View File

@@ -68,6 +68,11 @@ namespace CreatureLib::Battling {
} }
}; };
virtual void Initialize() {
RecalculateFlatStats();
__CurrentHealth = GetBoostedStat(Core::Statistic::Health);
}
void SetBattleData(Battle* battle, BattleSide* side); void SetBattleData(Battle* battle, BattleSide* side);
Battle* GetBattle() const; Battle* GetBattle() const;
BattleSide* GetBattleSide() const; BattleSide* GetBattleSide() const;