2019-11-09 11:15:45 +00:00
|
|
|
#ifndef CREATURELIB_SCRIPTAGGREGATOR_HPP
|
|
|
|
#define CREATURELIB_SCRIPTAGGREGATOR_HPP
|
|
|
|
|
2020-03-22 18:21:40 +00:00
|
|
|
#include <Arbutils/Collections/List.hpp>
|
2020-03-22 09:11:53 +00:00
|
|
|
#include "../../Library/Exceptions/NotReachableException.hpp"
|
2019-11-09 11:15:45 +00:00
|
|
|
#include "Script.hpp"
|
|
|
|
#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 {
|
2020-04-23 21:23:58 +00:00
|
|
|
const ScriptWrapper* _scripts;
|
|
|
|
size_t _size;
|
2019-12-07 21:15:50 +00:00
|
|
|
size_t _index = 0;
|
2020-04-23 17:57:45 +00:00
|
|
|
size_t _setIndex = 0;
|
2019-11-28 11:55:22 +00:00
|
|
|
|
2019-11-09 11:15:45 +00:00
|
|
|
public:
|
2020-04-23 17:57:45 +00:00
|
|
|
ScriptAggregator(){};
|
2020-05-26 16:31:06 +00:00
|
|
|
explicit ScriptAggregator(const ArbUt::List<ScriptWrapper>& scripts)
|
2020-04-23 21:23:58 +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() {
|
2020-04-23 17:57:45 +00:00
|
|
|
_index = 0;
|
|
|
|
_setIndex = 0;
|
|
|
|
}
|
2020-04-23 21:23:58 +00:00
|
|
|
inline bool HasNext() { return _index < _size; }
|
2019-11-09 11:15:45 +00:00
|
|
|
|
2020-04-23 21:23:58 +00:00
|
|
|
Script* GetNextNotNull() {
|
|
|
|
while (HasNext()) {
|
|
|
|
auto s = GetNext();
|
|
|
|
if (s != nullptr) {
|
|
|
|
return s;
|
2019-11-09 11:15:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-23 21:23:58 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Script* GetNext() {
|
|
|
|
auto& current = _scripts[_index];
|
|
|
|
if (!current.IsSet()) {
|
|
|
|
_index++;
|
|
|
|
auto s = current.GetScript();
|
|
|
|
if (s == nullptr)
|
|
|
|
return nullptr;
|
2020-06-02 11:43:44 +00:00
|
|
|
return (*s).get();
|
2019-11-28 11:55:22 +00:00
|
|
|
} else {
|
2020-04-23 21:23:58 +00:00
|
|
|
auto& set = *current.GetScriptSet()->GetIterator();
|
|
|
|
auto count = set.Count();
|
|
|
|
if (_setIndex >= count) {
|
|
|
|
_index++;
|
|
|
|
_setIndex = 0;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto v = set[_setIndex++];
|
|
|
|
if (_setIndex >= count) {
|
|
|
|
_index++;
|
|
|
|
_setIndex = 0;
|
|
|
|
}
|
|
|
|
return v;
|
2019-11-09 11:15:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
#endif // CREATURELIB_SCRIPTAGGREGATOR_HPP
|