Reworks ScriptSources so we can get individual scripts on a source. Fixed OnEndTurn making no sense.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
316ac12a01
commit
5fd8abb3a8
|
@ -25,13 +25,28 @@ void TurnHandler::RunTurn(const ArbUt::BorrowedPtr<ChoiceQueue>& queue, const Ar
|
|||
<< " with message");
|
||||
}
|
||||
if (!battle->HasEnded()) {
|
||||
ArbUt::List<ScriptWrapper> scripts;
|
||||
for (const auto& side : battle->GetSides()) {
|
||||
for (const auto& creature : side->GetCreatures()) {
|
||||
if (!creature.HasValue()) {
|
||||
continue;
|
||||
}
|
||||
HOOK(OnEndTurn, creature.GetValue(), creature.GetValue());
|
||||
scripts.Clear();
|
||||
creature.GetValue()->GetOwnScripts(scripts);
|
||||
for (auto& s : scripts) {
|
||||
EXECUTE_SCRIPT_FUNC(s, OnEndTurn);
|
||||
}
|
||||
}
|
||||
scripts.Clear();
|
||||
side->GetOwnScripts(scripts);
|
||||
for (auto& s : scripts) {
|
||||
EXECUTE_SCRIPT_FUNC(s, OnEndTurn);
|
||||
}
|
||||
}
|
||||
scripts.Clear();
|
||||
battle->GetOwnScripts(scripts);
|
||||
for (auto& s : scripts) {
|
||||
EXECUTE_SCRIPT_FUNC(s, OnEndTurn);
|
||||
}
|
||||
}
|
||||
queue->HasCompletedQueue = true;
|
||||
|
|
|
@ -113,9 +113,9 @@ bool Battle::CreatureInField(ArbUt::BorrowedPtr<Creature> creature) const {
|
|||
void Battle::ForceRecall(uint8_t side, uint8_t index) { _sides[side]->SetCreature(nullptr, index); }
|
||||
|
||||
size_t Battle::ScriptCount() const { return 1; }
|
||||
void Battle::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) {
|
||||
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
||||
}
|
||||
void Battle::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) { GetOwnScripts(scripts); }
|
||||
|
||||
void Battle::GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) { scripts.Append(ScriptWrapper::FromSet(&_volatile)); }
|
||||
|
||||
void Battle::SwitchCreature(uint8_t sideIndex, uint8_t index, Creature* c) {
|
||||
auto side = this->_sides[sideIndex];
|
||||
|
|
|
@ -79,6 +79,7 @@ namespace CreatureLib::Battling {
|
|||
|
||||
size_t ScriptCount() const override;
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||
|
||||
void ValidateBattleState();
|
||||
inline bool HasEnded() const noexcept { return _hasEnded; }
|
||||
|
|
|
@ -82,9 +82,12 @@ bool BattleSide::CreatureOnSide(const ArbUt::BorrowedPtr<Creature>& creature) co
|
|||
const ArbUt::OptionalBorrowedPtr<Creature>& BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; }
|
||||
|
||||
void BattleSide::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) {
|
||||
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
||||
GetOwnScripts(scripts);
|
||||
_battle->GetActiveScripts(scripts);
|
||||
}
|
||||
void BattleSide::GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) {
|
||||
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
||||
}
|
||||
size_t BattleSide::ScriptCount() const { return _battle->ScriptCount() + 1; }
|
||||
|
||||
uint8_t BattleSide::GetRandomCreatureIndex() {
|
||||
|
|
|
@ -50,6 +50,7 @@ namespace CreatureLib::Battling {
|
|||
|
||||
size_t ScriptCount() const override;
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||
|
||||
const ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>>& GetCreatures() { return _creatures; }
|
||||
|
||||
|
|
|
@ -234,13 +234,17 @@ namespace CreatureLib::Battling {
|
|||
}
|
||||
|
||||
void Creature::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) {
|
||||
scripts.Append(ScriptWrapper::FromScript(&_activeTalent));
|
||||
scripts.Append(ScriptWrapper::FromScript(&_status));
|
||||
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
||||
GetOwnScripts(scripts);
|
||||
if (_battleData.Side.HasValue()) {
|
||||
_battleData.Side.GetValue()->GetActiveScripts(scripts);
|
||||
}
|
||||
}
|
||||
void Creature::GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) {
|
||||
scripts.Append(ScriptWrapper::FromScript(&_activeTalent));
|
||||
scripts.Append(ScriptWrapper::FromScript(&_status));
|
||||
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
||||
}
|
||||
|
||||
void Creature::ClearVolatileScripts() { _volatile.Clear(); }
|
||||
void Creature::AddExperience(uint32_t amount) {
|
||||
auto maxLevel = _library->GetSettings()->GetMaximalLevel();
|
||||
|
|
|
@ -148,6 +148,7 @@ namespace CreatureLib::Battling {
|
|||
|
||||
size_t ScriptCount() const override;
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||
void ClearVolatileScripts();
|
||||
BattleScript* AddVolatileScript(const ArbUt::StringView& name);
|
||||
BattleScript* AddVolatileScript(BattleScript* script);
|
||||
|
|
|
@ -105,11 +105,13 @@ namespace CreatureLib::Battling {
|
|||
|
||||
inline ArbUt::BorrowedPtr<BattleScript> GetScript() const noexcept { return _script; }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(ScriptWrapper::FromScript(&_script));
|
||||
GetOwnScripts(scripts);
|
||||
_user->GetActiveScripts(scripts);
|
||||
}
|
||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(ScriptWrapper::FromScript(&_script));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace CreatureLib::Battling {
|
|||
virtual void PreventOpponentRunAway([[maybe_unused]] const FleeTurnChoice* choice,
|
||||
[[maybe_unused]] bool* result){};
|
||||
|
||||
virtual void OnEndTurn([[maybe_unused]] Creature* creature){};
|
||||
virtual void OnEndTurn(){};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -16,3 +16,22 @@
|
|||
THROW("Exception setting up script hook '" #hookName "': " << e.what()) \
|
||||
} \
|
||||
}
|
||||
|
||||
#define EXECUTE_SCRIPT_FUNC(scriptWrapper, hookName, ...) \
|
||||
{ \
|
||||
try { \
|
||||
if (scriptWrapper.HasValue()) { \
|
||||
if (scriptWrapper.IsSet()) { \
|
||||
for (const auto& sv : scriptWrapper.GetScriptSet()->GetIterator()) { \
|
||||
sv->hookName(__VA_ARGS__); \
|
||||
} \
|
||||
} else { \
|
||||
scriptWrapper.GetScript()->get()->hookName(__VA_ARGS__); \
|
||||
} \
|
||||
} \
|
||||
} catch (const ArbUt::Exception& e) { \
|
||||
throw e; \
|
||||
} catch (const std::exception& e) { \
|
||||
THROW("Exception setting up script hook '" #hookName "': " << e.what()) \
|
||||
} \
|
||||
}
|
|
@ -12,7 +12,6 @@ namespace CreatureLib::Battling {
|
|||
ScriptAggregator _scriptsIterator;
|
||||
|
||||
protected:
|
||||
virtual void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) = 0;
|
||||
void ResetActiveScripts() {
|
||||
_areScriptsInitialized = false;
|
||||
_scripts.Clear();
|
||||
|
@ -30,6 +29,9 @@ namespace CreatureLib::Battling {
|
|||
_scriptsIterator.Reset();
|
||||
return _scriptsIterator;
|
||||
}
|
||||
|
||||
virtual void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) = 0;
|
||||
virtual void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -66,11 +66,13 @@ namespace CreatureLib::Battling {
|
|||
const std::unique_ptr<BattleScript>& GetAttackScript() const noexcept { return _attackScript; }
|
||||
size_t ScriptCount() const override { return 1 + GetUser()->ScriptCount(); }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
|
||||
GetOwnScripts(scripts);
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace CreatureLib::Battling {
|
|||
|
||||
protected:
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override { GetUser()->GetActiveScripts(scripts); }
|
||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>&) override {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace CreatureLib::Battling {
|
|||
|
||||
protected:
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override { GetUser()->GetActiveScripts(scripts); }
|
||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>&) override {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace CreatureLib::Battling {
|
|||
|
||||
protected:
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override { GetUser()->GetActiveScripts(scripts); }
|
||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>&) override {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ public:
|
|||
|
||||
protected:
|
||||
size_t ScriptCount() const override { return 1; }
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override { GetOwnScripts(scripts); }
|
||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(ScriptWrapper::FromScript(&ScriptPtr));
|
||||
}
|
||||
};
|
||||
|
@ -35,9 +36,8 @@ public:
|
|||
|
||||
protected:
|
||||
size_t ScriptCount() const override { return 1; }
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(ScriptWrapper::FromSet(&Set));
|
||||
}
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override { GetOwnScripts(scripts); }
|
||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override { scripts.Append(ScriptWrapper::FromSet(&Set)); }
|
||||
};
|
||||
|
||||
TEST_CASE("Script source with unset script ptr.") {
|
||||
|
|
Loading…
Reference in New Issue