44 lines
1.6 KiB
C++
44 lines
1.6 KiB
C++
#ifndef CREATURELIB_HISTORYHOLDER_HPP
|
|
#define CREATURELIB_HISTORYHOLDER_HPP
|
|
|
|
#include <utility>
|
|
#include "../../Library/Exceptions/CreatureException.hpp"
|
|
#include "HistoryElements/HistoryElement.hpp"
|
|
#include "HistoryElements/DamageHistory.hpp"
|
|
|
|
template <class T>
|
|
concept HistoryElementType = std::is_base_of<CreatureLib::Battling::HistoryElement, T>::value;
|
|
|
|
namespace CreatureLib::Battling {
|
|
class HistoryHolder {
|
|
HistoryElement* nullable _top = nullptr;
|
|
std::function<u32()> _getTurnNumber;
|
|
|
|
public:
|
|
HistoryHolder(std::function<u32()> getTurnNumber) : _getTurnNumber(std::move(getTurnNumber)) {}
|
|
HistoryHolder(const HistoryHolder&) = delete;
|
|
HistoryHolder& operator=(const HistoryHolder&) = delete;
|
|
|
|
virtual ~HistoryHolder() { delete _top; }
|
|
|
|
template <HistoryElementType T, class... parameters> void Register(parameters... args) {
|
|
auto* prev = _top;
|
|
_top = new T(args...);
|
|
_top->SetPrevious(prev);
|
|
}
|
|
|
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement> GetTopElement() const noexcept { return _top; }
|
|
|
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
|
GetLastUsedAttack(u32 maxDepth = 0) const noexcept;
|
|
|
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
|
GetLastUsedAttackOnTarget(Creature* non_null target, u32 maxDepth = 0) const noexcept;
|
|
|
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
|
GetLastDamageOnTarget(const ArbUt::BorrowedPtr<const Creature>& creature, u32 maxDepth = 0) const noexcept;
|
|
};
|
|
}
|
|
|
|
#endif // CREATURELIB_HISTORYHOLDER_HPP
|