2019-11-09 11:15:45 +00:00
|
|
|
#ifndef CREATURELIB_SCRIPTAGGREGATOR_HPP
|
|
|
|
#define CREATURELIB_SCRIPTAGGREGATOR_HPP
|
|
|
|
|
2021-03-07 09:26:41 +00:00
|
|
|
#include "BattleScript.hpp"
|
2019-11-09 11:15:45 +00:00
|
|
|
#include "ScriptSet.hpp"
|
2019-11-10 16:08:42 +00:00
|
|
|
#include "ScriptWrapper.hpp"
|
2019-11-09 11:15:45 +00:00
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
namespace CreatureLib::Battling {
|
|
|
|
class ScriptAggregator {
|
2022-03-23 12:56:45 +00:00
|
|
|
const ScriptWrapper* nullable _scripts;
|
2021-04-17 12:44:33 +00:00
|
|
|
i32 _size;
|
2021-04-18 10:50:48 +00:00
|
|
|
i32 _index = -1;
|
|
|
|
i32 _setIndex = -1;
|
2019-11-28 11:55:22 +00:00
|
|
|
|
2021-04-18 10:50:48 +00:00
|
|
|
inline bool IncrementToNextNotNull() {
|
|
|
|
if (_index != -1 && _scripts[_index].IsSet()) {
|
2020-06-05 16:06:45 +00:00
|
|
|
_setIndex++;
|
2021-04-17 14:23:29 +00:00
|
|
|
if (_setIndex >= (i32)_scripts[_index].GetScriptSet()->Count()) {
|
2021-04-17 12:44:33 +00:00
|
|
|
_setIndex = -1;
|
2020-06-05 16:06:45 +00:00
|
|
|
} else {
|
2021-04-18 10:50:48 +00:00
|
|
|
return true;
|
2020-06-05 16:06:45 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-18 10:50:48 +00:00
|
|
|
for (_index++; _index < _size; ++_index) {
|
2020-06-05 16:06:45 +00:00
|
|
|
if (_scripts[_index].HasValue()) {
|
2021-04-17 14:31:03 +00:00
|
|
|
if (_scripts[_index].IsSet()) {
|
2021-04-18 10:50:48 +00:00
|
|
|
_setIndex = 0;
|
2021-04-17 14:31:03 +00:00
|
|
|
}
|
2021-04-18 10:50:48 +00:00
|
|
|
return true;
|
2020-06-05 16:06:45 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-18 10:50:48 +00:00
|
|
|
return false;
|
2020-06-05 16:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-09 11:15:45 +00:00
|
|
|
public:
|
2021-04-17 14:23:29 +00:00
|
|
|
ScriptAggregator(){};
|
2021-04-17 13:08:26 +00:00
|
|
|
|
2021-04-17 14:23:29 +00:00
|
|
|
explicit ScriptAggregator(const ArbUt::List<ScriptWrapper>& scripts)
|
2021-04-18 10:50:48 +00:00
|
|
|
: _scripts(scripts.RawData()), _size(scripts.Count()){};
|
2019-11-09 11:15:45 +00:00
|
|
|
|
2020-04-23 21:23:58 +00:00
|
|
|
inline void Reset() {
|
2021-04-18 10:50:48 +00:00
|
|
|
_index = -1;
|
|
|
|
_setIndex = -1;
|
2020-04-23 17:57:45 +00:00
|
|
|
}
|
2021-04-17 13:08:26 +00:00
|
|
|
|
2021-04-18 10:50:48 +00:00
|
|
|
bool GetNext(ArbUt::BorrowedPtr<BattleScript>& out) {
|
|
|
|
if (!IncrementToNextNotNull()) {
|
|
|
|
return false;
|
2019-11-09 11:15:45 +00:00
|
|
|
}
|
2021-04-17 14:23:29 +00:00
|
|
|
auto& current = _scripts[_index];
|
2020-04-23 21:23:58 +00:00
|
|
|
if (!current.IsSet()) {
|
|
|
|
auto s = current.GetScript();
|
2022-05-14 15:36:38 +00:00
|
|
|
out = s->GetValue();
|
2021-04-18 10:50:48 +00:00
|
|
|
return true;
|
2019-11-28 11:55:22 +00:00
|
|
|
} else {
|
2021-04-17 14:23:29 +00:00
|
|
|
auto& set = current.GetScriptSet()->GetIterator();
|
2020-06-05 16:06:45 +00:00
|
|
|
auto v = set[_setIndex];
|
2021-04-18 10:50:48 +00:00
|
|
|
out = v;
|
|
|
|
return true;
|
2019-11-09 11:15:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
#endif // CREATURELIB_SCRIPTAGGREGATOR_HPP
|