From 173c6c9926be5134b8f696b3f2921f69d1e41335 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 12 Feb 2022 17:19:07 +0100 Subject: [PATCH] Adds pointer to battle library in on initialize function --- src/Battling/Models/Creature.cpp | 4 ++-- src/Battling/ScriptHandling/BattleScript.hpp | 4 +++- src/Battling/TurnChoices/AttackTurnChoice.hpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index ef3d493..828057b 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -24,7 +24,7 @@ namespace CreatureLib::Battling { _activeTalent = std::unique_ptr( _library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()->GetEffect())); if (_activeTalent != nullptr) { - _activeTalent->OnInitialize(GetActiveTalent()->GetParameters()); + _activeTalent->OnInitialize(_library.GetRaw(), GetActiveTalent()->GetParameters()); } for (auto t : _variant->GetTypes()) { _types.push_back(t); @@ -80,7 +80,7 @@ namespace CreatureLib::Battling { _activeTalent = std::unique_ptr( _library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()->GetEffect())); if (_activeTalent != nullptr) { - _activeTalent->OnInitialize(GetActiveTalent()->GetParameters()); + _activeTalent->OnInitialize(_library.GetRaw(), GetActiveTalent()->GetParameters()); } // We modify the health of the creature by the change in its max health. diff --git a/src/Battling/ScriptHandling/BattleScript.hpp b/src/Battling/ScriptHandling/BattleScript.hpp index 8e64d6b..56f95ac 100644 --- a/src/Battling/ScriptHandling/BattleScript.hpp +++ b/src/Battling/ScriptHandling/BattleScript.hpp @@ -15,6 +15,7 @@ namespace CreatureLib::Battling { class FleeTurnChoice; class ExecutingAttack; class Creature; + class BattleLibrary; class BattleScript { ArbUt::OptionalBorrowedPtr _owner; @@ -43,7 +44,8 @@ namespace CreatureLib::Battling { #define _par_ [[maybe_unused]] - virtual void OnInitialize(_par_ const ArbUt::List& parameters){}; + virtual void OnInitialize(_par_ const BattleLibrary*, + _par_ const ArbUt::List& parameters){}; virtual void OnBeforeTurn(_par_ const BaseTurnChoice* choice){}; virtual void ChangePriority(_par_ AttackTurnChoice* choice, _par_ int8_t* priority){}; diff --git a/src/Battling/TurnChoices/AttackTurnChoice.hpp b/src/Battling/TurnChoices/AttackTurnChoice.hpp index 6f9db1a..1f23ef6 100644 --- a/src/Battling/TurnChoices/AttackTurnChoice.hpp +++ b/src/Battling/TurnChoices/AttackTurnChoice.hpp @@ -28,7 +28,7 @@ namespace CreatureLib::Battling { _attackScript = std::unique_ptr( library->LoadScript(this, ScriptCategory::Attack, effect->GetEffectName())); if (_attackScript != nullptr) { - _attackScript->OnInitialize(effect->GetParameters()); + _attackScript->OnInitialize(battle.GetValue()->GetLibrary().GetRaw(), effect->GetParameters()); } } }