Adds GetLastUsedAttackOnTarget helper to BattleHistory
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a89d79f8bc
commit
a570e90f67
|
@ -1,5 +1,7 @@
|
||||||
#ifndef CREATURELIB_HISTORYELEMENTKIND_HPP
|
#ifndef CREATURELIB_HISTORYELEMENTKIND_HPP
|
||||||
#define CREATURELIB_HISTORYELEMENTKIND_HPP
|
#define CREATURELIB_HISTORYELEMENTKIND_HPP
|
||||||
|
#include <Arbutils/Enum.hpp>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
ENUM(HistoryElementKind, uint8_t, AttackUse, Damage)
|
ENUM(HistoryElementKind, uint8_t, AttackUse, Damage)
|
||||||
#endif // CREATURELIB_HISTORYELEMENTKIND_HPP
|
#endif // CREATURELIB_HISTORYELEMENTKIND_HPP
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#ifndef CREATURELIB_DAMAGEHISTORY_HPP
|
#ifndef CREATURELIB_DAMAGEHISTORY_HPP
|
||||||
#define CREATURELIB_DAMAGEHISTORY_HPP
|
#define CREATURELIB_DAMAGEHISTORY_HPP
|
||||||
|
#include "../../Models/Creature.hpp"
|
||||||
#include "../../Models/DamageSource.hpp"
|
#include "../../Models/DamageSource.hpp"
|
||||||
#include "HistoryElement.hpp"
|
#include "HistoryElement.hpp"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef CREATURELIB_HISTORYELEMENT_HPP
|
#ifndef CREATURELIB_HISTORYELEMENT_HPP
|
||||||
#define CREATURELIB_HISTORYELEMENT_HPP
|
#define CREATURELIB_HISTORYELEMENT_HPP
|
||||||
|
|
||||||
|
#include <Arbutils/Memory/Memory.hpp>
|
||||||
|
#include "../../../Defines.hpp"
|
||||||
#include "../HistoryElementKind.hpp"
|
#include "../HistoryElementKind.hpp"
|
||||||
|
|
||||||
namespace CreatureLib::Battling {
|
namespace CreatureLib::Battling {
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
#include "HistoryHolder.hpp"
|
||||||
|
#include "HistoryElementKind.hpp"
|
||||||
|
#include "HistoryElements/AttackUseHistory.hpp"
|
||||||
|
|
||||||
|
namespace CreatureLib::Battling {
|
||||||
|
ArbUt::OptionalBorrowedPtr<const HistoryElement> HistoryHolder::GetLastUsedAttack(u32 maxDepth) const noexcept {
|
||||||
|
ArbUt::OptionalBorrowedPtr<const HistoryElement> c = _top;
|
||||||
|
auto turn = _getTurnNumber();
|
||||||
|
while (c.HasValue()) {
|
||||||
|
if (maxDepth != 0 && turn - c.GetValue()->GetTurnNumber() > maxDepth - 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (c.GetValue()->GetKind() == HistoryElementKind::AttackUse) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
c = c.GetValue()->GetPrevious();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
||||||
|
HistoryHolder::GetLastUsedAttackOnTarget(Creature* target, u32 maxDepth) const noexcept {
|
||||||
|
ArbUt::OptionalBorrowedPtr<const HistoryElement> c = _top;
|
||||||
|
auto turn = _getTurnNumber();
|
||||||
|
while (c.HasValue()) {
|
||||||
|
if (maxDepth != 0 && turn - c.GetValue()->GetTurnNumber() > maxDepth - 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (c.GetValue()->GetKind() == HistoryElementKind::AttackUse) {
|
||||||
|
if (c.ForceAs<const AttackUseHistory>().GetValue()->GetAttack()->GetTargets().Contains(target)) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c = c.GetValue()->GetPrevious();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
||||||
|
HistoryHolder::GetLastDamageOnTarget(const ArbUt::BorrowedPtr<const Creature>& creature,
|
||||||
|
u32 maxDepth) const noexcept {
|
||||||
|
ArbUt::OptionalBorrowedPtr<const HistoryElement> c = _top;
|
||||||
|
auto turn = _getTurnNumber();
|
||||||
|
while (c.HasValue()) {
|
||||||
|
if (maxDepth != 0 && turn - c.GetValue()->GetTurnNumber() > maxDepth - 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (c.GetValue()->GetKind() == HistoryElementKind::Damage &&
|
||||||
|
c.ForceAs<const DamageHistory>().GetValue()->GetTarget() == creature) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
c = c.GetValue()->GetPrevious();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "../../Library/Exceptions/CreatureException.hpp"
|
#include "../../Library/Exceptions/CreatureException.hpp"
|
||||||
#include "HistoryElements/DamageHistory.hpp"
|
|
||||||
#include "HistoryElements/HistoryElement.hpp"
|
#include "HistoryElements/HistoryElement.hpp"
|
||||||
|
#include "HistoryElements/DamageHistory.hpp"
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
concept HistoryElementType = std::is_base_of<CreatureLib::Battling::HistoryElement, T>::value;
|
concept HistoryElementType = std::is_base_of<CreatureLib::Battling::HistoryElement, T>::value;
|
||||||
|
@ -30,37 +30,13 @@ namespace CreatureLib::Battling {
|
||||||
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement> GetTopElement() const noexcept { return _top; }
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement> GetTopElement() const noexcept { return _top; }
|
||||||
|
|
||||||
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
||||||
GetLastUsedAttack(u32 maxDepth = 0) const noexcept {
|
GetLastUsedAttack(u32 maxDepth = 0) const noexcept;
|
||||||
ArbUt::OptionalBorrowedPtr<const HistoryElement> c = _top;
|
|
||||||
auto turn = _getTurnNumber();
|
|
||||||
while (c.HasValue()) {
|
|
||||||
if (maxDepth != 0 && turn - c.GetValue()->GetTurnNumber() > maxDepth - 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (c.GetValue()->GetKind() == HistoryElementKind::AttackUse) {
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
c = c.GetValue()->GetPrevious();
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
||||||
GetLastDamageOnTarget(const ArbUt::BorrowedPtr<const Creature>& creature, u32 maxDepth = 0) const noexcept {
|
GetLastUsedAttackOnTarget(Creature* target, u32 maxDepth = 0) const noexcept;
|
||||||
ArbUt::OptionalBorrowedPtr<const HistoryElement> c = _top;
|
|
||||||
auto turn = _getTurnNumber();
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
||||||
while (c.HasValue()) {
|
GetLastDamageOnTarget(const ArbUt::BorrowedPtr<const Creature>& creature, u32 maxDepth = 0) const noexcept;
|
||||||
if (maxDepth != 0 && turn - c.GetValue()->GetTurnNumber() > maxDepth - 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (c.GetValue()->GetKind() == HistoryElementKind::Damage &&
|
|
||||||
c.ForceAs<const DamageHistory>().GetValue()->GetTarget() == creature) {
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
c = c.GetValue()->GetPrevious();
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue