Add nullability to large parts of the codebase
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
beb2e44a0b
commit
eccf2c9121
|
@ -15,13 +15,13 @@ namespace CreatureLib::Battling {
|
||||||
/// for it.
|
/// for it.
|
||||||
class EventHook {
|
class EventHook {
|
||||||
public:
|
public:
|
||||||
typedef std::function<void(const CreatureLib::Battling::EventData*)> EventHookFunc;
|
typedef std::function<void(const CreatureLib::Battling::EventData* non_null)> EventHookFunc;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<EventHookFunc> _listeners;
|
std::vector<EventHookFunc> _listeners;
|
||||||
size_t _offset;
|
size_t _offset;
|
||||||
size_t _capacity;
|
size_t _capacity;
|
||||||
u8* _memory = nullptr;
|
u8* nullable _memory = nullptr;
|
||||||
|
|
||||||
static constexpr size_t initialSize = 2048;
|
static constexpr size_t initialSize = 2048;
|
||||||
static constexpr size_t stepSize = 1024;
|
static constexpr size_t stepSize = 1024;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "ChoiceQueue.hpp"
|
#include "ChoiceQueue.hpp"
|
||||||
|
|
||||||
bool CreatureLib::Battling::ChoiceQueue::MoveCreatureChoiceNext(CreatureLib::Battling::Creature* creature) {
|
bool CreatureLib::Battling::ChoiceQueue::MoveCreatureChoiceNext(CreatureLib::Battling::Creature* non_null creature) {
|
||||||
EnsureNotNull(creature)
|
EnsureNotNull(creature)
|
||||||
// Find which index the creature choice is at.
|
// Find which index the creature choice is at.
|
||||||
size_t choiceIndex = SIZE_MAX;
|
size_t choiceIndex = SIZE_MAX;
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<BaseTurnChoice>>& GetInnerQueue() { return _queue; }
|
const std::vector<std::shared_ptr<BaseTurnChoice>>& GetInnerQueue() { return _queue; }
|
||||||
|
|
||||||
bool MoveCreatureChoiceNext(Creature* creature);
|
bool MoveCreatureChoiceNext(Creature* non_null creature);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
|
|
||||||
ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
||||||
HistoryHolder::GetLastUsedAttackOnTarget(Creature* target, u32 maxDepth) const noexcept {
|
HistoryHolder::GetLastUsedAttackOnTarget(Creature* non_null target, u32 maxDepth) const noexcept {
|
||||||
ArbUt::OptionalBorrowedPtr<const HistoryElement> c = _top;
|
ArbUt::OptionalBorrowedPtr<const HistoryElement> c = _top;
|
||||||
auto turn = _getTurnNumber();
|
auto turn = _getTurnNumber();
|
||||||
while (c.HasValue()) {
|
while (c.HasValue()) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ concept HistoryElementType = std::is_base_of<CreatureLib::Battling::HistoryEleme
|
||||||
|
|
||||||
namespace CreatureLib::Battling {
|
namespace CreatureLib::Battling {
|
||||||
class HistoryHolder {
|
class HistoryHolder {
|
||||||
HistoryElement* _top = nullptr;
|
HistoryElement* nullable _top = nullptr;
|
||||||
std::function<u32()> _getTurnNumber;
|
std::function<u32()> _getTurnNumber;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -33,7 +33,7 @@ namespace CreatureLib::Battling {
|
||||||
GetLastUsedAttack(u32 maxDepth = 0) const noexcept;
|
GetLastUsedAttack(u32 maxDepth = 0) const noexcept;
|
||||||
|
|
||||||
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
||||||
GetLastUsedAttackOnTarget(Creature* target, u32 maxDepth = 0) const noexcept;
|
GetLastUsedAttackOnTarget(Creature* non_null target, u32 maxDepth = 0) const noexcept;
|
||||||
|
|
||||||
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
[[nodiscard]] ArbUt::OptionalBorrowedPtr<const HistoryElement>
|
||||||
GetLastDamageOnTarget(const ArbUt::BorrowedPtr<const Creature>& creature, u32 maxDepth = 0) const noexcept;
|
GetLastDamageOnTarget(const ArbUt::BorrowedPtr<const Creature>& creature, u32 maxDepth = 0) const noexcept;
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
using namespace CreatureLib::Battling;
|
using namespace CreatureLib::Battling;
|
||||||
|
|
||||||
BattleLibrary::BattleLibrary(const CreatureLib::Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator,
|
BattleLibrary::BattleLibrary(const CreatureLib::Library::DataLibrary* non_null staticLib,
|
||||||
DamageLibrary* damageLibrary, ExperienceLibrary* experienceLibrary,
|
BattleStatCalculator* non_null statCalculator, DamageLibrary* non_null damageLibrary,
|
||||||
ScriptResolver* scriptResolver, MiscLibrary* miscLibrary)
|
ExperienceLibrary* non_null experienceLibrary, ScriptResolver* non_null scriptResolver,
|
||||||
|
MiscLibrary* non_null miscLibrary)
|
||||||
: _staticLib(staticLib), _statCalculator(statCalculator), _damageLibrary(damageLibrary),
|
: _staticLib(staticLib), _statCalculator(statCalculator), _damageLibrary(damageLibrary),
|
||||||
_experienceLibrary(experienceLibrary), _scriptResolver(scriptResolver), _miscLibrary(miscLibrary) {
|
_experienceLibrary(experienceLibrary), _scriptResolver(scriptResolver), _miscLibrary(miscLibrary) {
|
||||||
EnsureNotNull(_staticLib);
|
EnsureNotNull(_staticLib);
|
||||||
|
@ -43,7 +44,7 @@ const std::unique_ptr<const DamageLibrary>& BattleLibrary::GetDamageLibrary() co
|
||||||
|
|
||||||
const std::unique_ptr<const MiscLibrary>& BattleLibrary::GetMiscLibrary() const noexcept { return _miscLibrary; }
|
const std::unique_ptr<const MiscLibrary>& BattleLibrary::GetMiscLibrary() const noexcept { return _miscLibrary; }
|
||||||
|
|
||||||
BattleScript* BattleLibrary::LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
|
BattleScript* nullable BattleLibrary::LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
|
||||||
const ArbUt::StringView& scriptName) const {
|
const ArbUt::StringView& scriptName) const {
|
||||||
return _scriptResolver->LoadScript(owner, category, scriptName);
|
return _scriptResolver->LoadScript(owner, category, scriptName);
|
||||||
}
|
}
|
|
@ -19,9 +19,9 @@ namespace CreatureLib::Battling {
|
||||||
std::unique_ptr<const MiscLibrary> _miscLibrary = nullptr;
|
std::unique_ptr<const MiscLibrary> _miscLibrary = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BattleLibrary(const Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator,
|
BattleLibrary(const Library::DataLibrary* non_null staticLib, BattleStatCalculator* non_null statCalculator,
|
||||||
DamageLibrary* damageLibrary, ExperienceLibrary* experienceLibrary,
|
DamageLibrary* non_null damageLibrary, ExperienceLibrary* non_null experienceLibrary,
|
||||||
ScriptResolver* scriptResolver, MiscLibrary* miscLibrary);
|
ScriptResolver* non_null scriptResolver, MiscLibrary* non_null miscLibrary);
|
||||||
~BattleLibrary() = default;
|
~BattleLibrary() = default;
|
||||||
inline const std::unique_ptr<const Library::DataLibrary>& GetStaticLib() const noexcept { return _staticLib; }
|
inline const std::unique_ptr<const Library::DataLibrary>& GetStaticLib() const noexcept { return _staticLib; }
|
||||||
|
|
||||||
|
@ -44,7 +44,8 @@ namespace CreatureLib::Battling {
|
||||||
return _scriptResolver;
|
return _scriptResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] BattleScript* LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
|
[[nodiscard]] BattleScript* nullable LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner,
|
||||||
|
ScriptCategory category,
|
||||||
const ArbUt::StringView& scriptName) const;
|
const ArbUt::StringView& scriptName) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
|
|
||||||
using namespace CreatureLib;
|
using namespace CreatureLib;
|
||||||
|
|
||||||
Library::StatisticSet<u32> Battling::BattleStatCalculator::CalculateFlatStats(Battling::Creature* creature) const {
|
Library::StatisticSet<u32>
|
||||||
|
Battling::BattleStatCalculator::CalculateFlatStats(Battling::Creature* non_null creature) const {
|
||||||
return Library::StatisticSet<u32>(CalculateFlatStat(creature, Library::Statistic::Health),
|
return Library::StatisticSet<u32>(CalculateFlatStat(creature, Library::Statistic::Health),
|
||||||
CalculateFlatStat(creature, Library::Statistic::PhysicalAttack),
|
CalculateFlatStat(creature, Library::Statistic::PhysicalAttack),
|
||||||
CalculateFlatStat(creature, Library::Statistic::PhysicalDefense),
|
CalculateFlatStat(creature, Library::Statistic::PhysicalDefense),
|
||||||
|
@ -12,7 +13,8 @@ Library::StatisticSet<u32> Battling::BattleStatCalculator::CalculateFlatStats(Ba
|
||||||
CalculateFlatStat(creature, Library::Statistic::Speed));
|
CalculateFlatStat(creature, Library::Statistic::Speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
Library::StatisticSet<u32> Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* creature) const {
|
Library::StatisticSet<u32>
|
||||||
|
Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* non_null creature) const {
|
||||||
return Library::StatisticSet<u32>(CalculateBoostedStat(creature, Library::Statistic::Health),
|
return Library::StatisticSet<u32>(CalculateBoostedStat(creature, Library::Statistic::Health),
|
||||||
CalculateBoostedStat(creature, Library::Statistic::PhysicalAttack),
|
CalculateBoostedStat(creature, Library::Statistic::PhysicalAttack),
|
||||||
CalculateBoostedStat(creature, Library::Statistic::PhysicalDefense),
|
CalculateBoostedStat(creature, Library::Statistic::PhysicalDefense),
|
||||||
|
@ -21,26 +23,29 @@ Library::StatisticSet<u32> Battling::BattleStatCalculator::CalculateBoostedStats
|
||||||
CalculateBoostedStat(creature, Library::Statistic::Speed));
|
CalculateBoostedStat(creature, Library::Statistic::Speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 CalculateHealthStat(Battling::Creature* creature) {
|
u32 CalculateHealthStat(Battling::Creature* non_null creature) {
|
||||||
EnsureNotNull(creature)
|
EnsureNotNull(creature)
|
||||||
auto level = creature->GetLevel();
|
auto level = creature->GetLevel();
|
||||||
float a = (creature->GetBaseStat(Library::Statistic::Health)) * 2.0 * level;
|
float a = (creature->GetBaseStat(Library::Statistic::Health)) * 2.0 * level;
|
||||||
return static_cast<u32>(floor(a / 100.0) + level + 10);
|
return static_cast<u32>(floor(a / 100.0) + level + 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 CalculateOtherStat(Battling::Creature* creature, Library::Statistic stat) {
|
u32 CalculateOtherStat(Battling::Creature* non_null creature, Library::Statistic stat) {
|
||||||
EnsureNotNull(creature)
|
EnsureNotNull(creature)
|
||||||
auto level = creature->GetLevel();
|
auto level = creature->GetLevel();
|
||||||
float a = (creature->GetBaseStat(stat)) * 2.0 * level;
|
float a = (creature->GetBaseStat(stat)) * 2.0 * level;
|
||||||
return static_cast<u32>(floor(a / 100.0) + 5);
|
return static_cast<u32>(floor(a / 100.0) + 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Battling::BattleStatCalculator::CalculateFlatStat(Battling::Creature* creature, Library::Statistic stat) const {
|
u32 Battling::BattleStatCalculator::CalculateFlatStat(Battling::Creature* non_null creature,
|
||||||
|
Library::Statistic stat) const {
|
||||||
|
EnsureNotNull(creature);
|
||||||
if (stat == Library::Statistic::Health)
|
if (stat == Library::Statistic::Health)
|
||||||
return CalculateHealthStat(creature);
|
return CalculateHealthStat(creature);
|
||||||
return CalculateOtherStat(creature, stat);
|
return CalculateOtherStat(creature, stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Battling::BattleStatCalculator::CalculateBoostedStat(Battling::Creature* creature, Library::Statistic stat) const {
|
u32 Battling::BattleStatCalculator::CalculateBoostedStat(Battling::Creature* non_null creature,
|
||||||
|
Library::Statistic stat) const {
|
||||||
return creature->GetFlatStat(stat) + (creature->GetBoostedStat(stat));
|
return creature->GetFlatStat(stat) + (creature->GetBoostedStat(stat));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,10 @@ namespace CreatureLib::Battling {
|
||||||
public:
|
public:
|
||||||
virtual ~BattleStatCalculator() = default;
|
virtual ~BattleStatCalculator() = default;
|
||||||
|
|
||||||
virtual Library::StatisticSet<u32> CalculateFlatStats(Creature* creature) const;
|
virtual Library::StatisticSet<u32> CalculateFlatStats(Creature* non_null creature) const;
|
||||||
virtual Library::StatisticSet<u32> CalculateBoostedStats(Creature* creature) const;
|
virtual Library::StatisticSet<u32> CalculateBoostedStats(Creature* non_null creature) const;
|
||||||
virtual u32 CalculateFlatStat(Creature* creature, Library::Statistic stat) const;
|
virtual u32 CalculateFlatStat(Creature* non_null creature, Library::Statistic stat) const;
|
||||||
virtual u32 CalculateBoostedStat(Creature* creature, Library::Statistic stat) const;
|
virtual u32 CalculateBoostedStat(Creature* non_null creature, Library::Statistic stat) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "../ScriptHandling/ScriptMacros.hpp"
|
#include "../ScriptHandling/ScriptMacros.hpp"
|
||||||
|
|
||||||
using namespace CreatureLib::Battling;
|
using namespace CreatureLib::Battling;
|
||||||
u32 DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, u8 hitIndex,
|
u32 DamageLibrary::GetDamage(ExecutingAttack* non_null attack, Creature* non_null target, u8 hitIndex,
|
||||||
const ExecutingAttack::HitData& hitData) const {
|
const ExecutingAttack::HitData& hitData) const {
|
||||||
EnsureNotNull(attack)
|
EnsureNotNull(attack)
|
||||||
EnsureNotNull(target)
|
EnsureNotNull(target)
|
||||||
|
@ -17,7 +17,7 @@ u32 DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, u8 hitIn
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, u8 hitIndex,
|
u8 DamageLibrary::GetBasePower(ExecutingAttack* non_null attack, Creature* non_null target, u8 hitIndex,
|
||||||
[[maybe_unused]] const ExecutingAttack::HitData& hitData) const {
|
[[maybe_unused]] const ExecutingAttack::HitData& hitData) const {
|
||||||
EnsureNotNull(attack)
|
EnsureNotNull(attack)
|
||||||
EnsureNotNull(target)
|
EnsureNotNull(target)
|
||||||
|
@ -26,7 +26,7 @@ u8 DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, u8 hit
|
||||||
return bp;
|
return bp;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, u8 hitIndex,
|
float DamageLibrary::GetStatModifier(ExecutingAttack* non_null attack, Creature* non_null target, u8 hitIndex,
|
||||||
const ExecutingAttack::HitData& hitData) const {
|
const ExecutingAttack::HitData& hitData) const {
|
||||||
EnsureNotNull(attack)
|
EnsureNotNull(attack)
|
||||||
EnsureNotNull(target)
|
EnsureNotNull(target)
|
||||||
|
@ -65,7 +65,7 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
|
||||||
return offensiveValue / defensiveValue;
|
return offensiveValue / defensiveValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, u8 hitIndex,
|
float DamageLibrary::GetDamageModifier(ExecutingAttack* non_null attack, Creature* non_null target, u8 hitIndex,
|
||||||
const ExecutingAttack::HitData& hitData) const {
|
const ExecutingAttack::HitData& hitData) const {
|
||||||
EnsureNotNull(attack)
|
EnsureNotNull(attack)
|
||||||
EnsureNotNull(target)
|
EnsureNotNull(target)
|
||||||
|
|
|
@ -8,14 +8,14 @@ namespace CreatureLib::Battling {
|
||||||
class DamageLibrary {
|
class DamageLibrary {
|
||||||
public:
|
public:
|
||||||
virtual ~DamageLibrary() = default;
|
virtual ~DamageLibrary() = default;
|
||||||
virtual u32 GetDamage(ExecutingAttack* attack, Creature* target, u8 hitIndex,
|
virtual u32 GetDamage(ExecutingAttack* non_null attack, Creature* non_null target, u8 hitIndex,
|
||||||
const ExecutingAttack::HitData& hitData) const;
|
const ExecutingAttack::HitData& hitData) const;
|
||||||
|
|
||||||
virtual u8 GetBasePower(ExecutingAttack* attack, Creature* target, u8 hitIndex,
|
virtual u8 GetBasePower(ExecutingAttack* non_null attack, Creature* non_null target, u8 hitIndex,
|
||||||
const ExecutingAttack::HitData& hitData) const;
|
const ExecutingAttack::HitData& hitData) const;
|
||||||
virtual float GetStatModifier(ExecutingAttack* attack, Creature* target, u8 hitIndex,
|
virtual float GetStatModifier(ExecutingAttack* non_null attack, Creature* non_null target, u8 hitIndex,
|
||||||
const ExecutingAttack::HitData& hitData) const;
|
const ExecutingAttack::HitData& hitData) const;
|
||||||
virtual float GetDamageModifier(ExecutingAttack* attack, Creature* target, u8 hitIndex,
|
virtual float GetDamageModifier(ExecutingAttack* non_null attack, Creature* non_null target, u8 hitIndex,
|
||||||
const ExecutingAttack::HitData& hitData) const;
|
const ExecutingAttack::HitData& hitData) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "../Models/Creature.hpp"
|
#include "../Models/Creature.hpp"
|
||||||
|
|
||||||
void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
|
void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
|
||||||
CreatureLib::Battling::Creature* faintedMon,
|
CreatureLib::Battling::Creature* non_null faintedMon,
|
||||||
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const {
|
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const {
|
||||||
for (const auto& opponent : opponents) {
|
for (const auto& opponent : opponents) {
|
||||||
if (opponent->IsFainted())
|
if (opponent->IsFainted())
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace CreatureLib::Battling {
|
||||||
public:
|
public:
|
||||||
virtual ~ExperienceLibrary() = default;
|
virtual ~ExperienceLibrary() = default;
|
||||||
|
|
||||||
virtual void HandleExperienceGain(Creature* faintedMon,
|
virtual void HandleExperienceGain(Creature* non_null faintedMon,
|
||||||
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const;
|
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
#include "../Models/Battle.hpp"
|
#include "../Models/Battle.hpp"
|
||||||
#include "../TurnChoices/AttackTurnChoice.hpp"
|
#include "../TurnChoices/AttackTurnChoice.hpp"
|
||||||
|
|
||||||
bool CreatureLib::Battling::MiscLibrary::IsCritical([[maybe_unused]] CreatureLib::Battling::ExecutingAttack* attack,
|
bool CreatureLib::Battling::MiscLibrary::IsCritical(
|
||||||
CreatureLib::Battling::Creature* target,
|
[[maybe_unused]] CreatureLib::Battling::ExecutingAttack* non_null attack,
|
||||||
[[maybe_unused]] u8 hit) const {
|
CreatureLib::Battling::Creature* non_null target, [[maybe_unused]] u8 hit) const {
|
||||||
EnsureNotNull(target)
|
EnsureNotNull(target)
|
||||||
Ensure(target->GetBattle().HasValue())
|
Ensure(target->GetBattle().HasValue())
|
||||||
auto rand = target->GetBattle().GetValue()->GetRandom();
|
auto rand = target->GetBattle().GetValue()->GetRandom();
|
||||||
return rand->Get(10) <= 0;
|
return rand->Get(10) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CreatureLib::Battling::LearnedAttack* _replacementAttack = nullptr;
|
static CreatureLib::Battling::LearnedAttack* nullable _replacementAttack = nullptr;
|
||||||
static std::unique_ptr<const CreatureLib::Library::AttackData> _replacementAttackData = nullptr;
|
static std::unique_ptr<const CreatureLib::Library::AttackData> _replacementAttackData = nullptr;
|
||||||
|
|
||||||
static ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> GetReplacementAttackData() {
|
static ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> GetReplacementAttackData() {
|
||||||
|
@ -24,7 +24,7 @@ static ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> GetReplacement
|
||||||
return _replacementAttackData;
|
return _replacementAttackData;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CreatureLib::Battling::LearnedAttack* GetReplacementAttack() {
|
static CreatureLib::Battling::LearnedAttack* non_null GetReplacementAttack() {
|
||||||
if (_replacementAttack == nullptr) {
|
if (_replacementAttack == nullptr) {
|
||||||
_replacementAttack = new CreatureLib::Battling::LearnedAttack(
|
_replacementAttack = new CreatureLib::Battling::LearnedAttack(
|
||||||
GetReplacementAttackData(), CreatureLib::Battling::AttackLearnMethod::Unknown);
|
GetReplacementAttackData(), CreatureLib::Battling::AttackLearnMethod::Unknown);
|
||||||
|
@ -32,9 +32,12 @@ static CreatureLib::Battling::LearnedAttack* GetReplacementAttack() {
|
||||||
return _replacementAttack;
|
return _replacementAttack;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CreatureLib::Battling::MiscLibrary::CanFlee([[maybe_unused]] FleeTurnChoice* switchChoice) const { return true; }
|
bool CreatureLib::Battling::MiscLibrary::CanFlee([[maybe_unused]] FleeTurnChoice* non_null switchChoice) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
CreatureLib::Battling::BaseTurnChoice*
|
CreatureLib::Battling::BaseTurnChoice*
|
||||||
CreatureLib::Battling::MiscLibrary::ReplacementAttack(Creature* user, [[maybe_unused]] CreatureIndex target) const {
|
CreatureLib::Battling::MiscLibrary::ReplacementAttack(Creature* non_null user,
|
||||||
|
[[maybe_unused]] CreatureIndex target) const {
|
||||||
EnsureNotNull(user)
|
EnsureNotNull(user)
|
||||||
Ensure(user->GetBattleSide().HasValue())
|
Ensure(user->GetBattleSide().HasValue())
|
||||||
auto sideTarget = 0;
|
auto sideTarget = 0;
|
||||||
|
|
|
@ -9,9 +9,9 @@ namespace CreatureLib::Battling {
|
||||||
class MiscLibrary {
|
class MiscLibrary {
|
||||||
public:
|
public:
|
||||||
virtual ~MiscLibrary() = default;
|
virtual ~MiscLibrary() = default;
|
||||||
virtual bool IsCritical(ExecutingAttack* attack, Creature* target, u8 hit) const;
|
virtual bool IsCritical(ExecutingAttack* non_null attack, Creature* non_null target, u8 hit) const;
|
||||||
virtual bool CanFlee(FleeTurnChoice* switchChoice) const;
|
virtual bool CanFlee(FleeTurnChoice* non_null switchChoice) const;
|
||||||
virtual BaseTurnChoice* ReplacementAttack(Creature* user, CreatureIndex target) const;
|
virtual BaseTurnChoice* non_null ReplacementAttack(Creature* non_null user, CreatureIndex target) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define CREATURELIB_ATTACKLEARNMETHOD_HPP
|
#define CREATURELIB_ATTACKLEARNMETHOD_HPP
|
||||||
|
|
||||||
namespace CreatureLib::Battling {
|
namespace CreatureLib::Battling {
|
||||||
enum class AttackLearnMethod { Unknown, Level };
|
ENUM(AttackLearnMethod, u8, Unknown, Level);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CREATURELIB_ATTACKLEARNMETHOD_HPP
|
#endif // CREATURELIB_ATTACKLEARNMETHOD_HPP
|
||||||
|
|
|
@ -24,7 +24,7 @@ bool Battle::CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Battle::TrySetChoice(BaseTurnChoice* choice) {
|
bool Battle::TrySetChoice(BaseTurnChoice* non_null choice) {
|
||||||
EnsureNotNull(choice)
|
EnsureNotNull(choice)
|
||||||
if (!CanUse(choice)) {
|
if (!CanUse(choice)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -117,7 +117,7 @@ void Battle::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) { GetOwnScrip
|
||||||
|
|
||||||
void Battle::GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) { scripts.Append(ScriptWrapper::FromSet(&_volatile)); }
|
void Battle::GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) { scripts.Append(ScriptWrapper::FromSet(&_volatile)); }
|
||||||
|
|
||||||
void Battle::SwitchCreature(u8 sideIndex, u8 index, Creature* c) {
|
void Battle::SwitchCreature(u8 sideIndex, u8 index, Creature* nullable c) {
|
||||||
auto side = this->_sides[sideIndex];
|
auto side = this->_sides[sideIndex];
|
||||||
side->SetCreature(c, index);
|
side->SetCreature(c, index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace CreatureLib::Battling {
|
||||||
long _lastTurnTime;
|
long _lastTurnTime;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Battle(const BattleLibrary* library, ArbUt::List<BattleParty*> parties, bool canFlee = true,
|
Battle(const BattleLibrary* non_null library, ArbUt::List<BattleParty * non_null> parties, bool canFlee = true,
|
||||||
u8 numberOfSides = 2, u8 creaturesPerSide = 1,
|
u8 numberOfSides = 2, u8 creaturesPerSide = 1,
|
||||||
uint_fast32_t randomSeed = std::chrono::duration_cast<std::chrono::milliseconds>(
|
uint_fast32_t randomSeed = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
std::chrono::system_clock::now().time_since_epoch())
|
std::chrono::system_clock::now().time_since_epoch())
|
||||||
|
@ -55,14 +55,14 @@ namespace CreatureLib::Battling {
|
||||||
inline u8 GetCreaturesPerSide() const noexcept { return _creaturesPerSide; }
|
inline u8 GetCreaturesPerSide() const noexcept { return _creaturesPerSide; }
|
||||||
|
|
||||||
virtual bool CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice);
|
virtual bool CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice);
|
||||||
virtual bool TrySetChoice(BaseTurnChoice* choice);
|
virtual bool TrySetChoice(BaseTurnChoice* non_null choice);
|
||||||
|
|
||||||
bool CanFlee() const noexcept { return _canFlee; }
|
bool CanFlee() const noexcept { return _canFlee; }
|
||||||
|
|
||||||
void CheckChoicesSetAndRun();
|
void CheckChoicesSetAndRun();
|
||||||
|
|
||||||
[[nodiscard]] ArbUt::BorrowedPtr<ChoiceQueue> GetCurrentTurnQueue() const noexcept;
|
[[nodiscard]] ArbUt::BorrowedPtr<ChoiceQueue> GetCurrentTurnQueue() const noexcept;
|
||||||
BattleRandom* GetRandom() noexcept;
|
BattleRandom* non_null GetRandom() noexcept;
|
||||||
|
|
||||||
bool CreatureInField(ArbUt::BorrowedPtr<Creature> creature) const;
|
bool CreatureInField(ArbUt::BorrowedPtr<Creature> creature) const;
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ForceRecall(u8 side, u8 index);
|
void ForceRecall(u8 side, u8 index);
|
||||||
void SwitchCreature(u8 side, u8 index, Creature* c);
|
void SwitchCreature(u8 side, u8 index, Creature* nullable c);
|
||||||
bool CanSlotBeFilled(u8 side, u8 index) const;
|
bool CanSlotBeFilled(u8 side, u8 index) const;
|
||||||
|
|
||||||
size_t ScriptCount() const override;
|
size_t ScriptCount() const override;
|
||||||
|
@ -96,11 +96,11 @@ namespace CreatureLib::Battling {
|
||||||
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(u32 keyHash) const noexcept {
|
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(u32 keyHash) const noexcept {
|
||||||
return _volatile.Get(keyHash);
|
return _volatile.Get(keyHash);
|
||||||
}
|
}
|
||||||
BattleScript* AddVolatileScript(const ArbUt::StringView& key);
|
BattleScript* non_null AddVolatileScript(const ArbUt::StringView& key);
|
||||||
BattleScript* AddVolatileScript(BattleScript* script);
|
BattleScript* non_null AddVolatileScript(BattleScript* non_null script);
|
||||||
void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
|
void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
|
||||||
void RemoveVolatileScript(u32 keyHash) { _volatile.Remove(keyHash); }
|
void RemoveVolatileScript(u32 keyHash) { _volatile.Remove(keyHash); }
|
||||||
void RemoveVolatileScript(BattleScript* script);
|
void RemoveVolatileScript(BattleScript* non_null script);
|
||||||
bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
|
bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
|
||||||
bool HasVolatileScript(u32 keyHash) const { return _volatile.Has(keyHash); }
|
bool HasVolatileScript(u32 keyHash) const { return _volatile.Has(keyHash); }
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ namespace CreatureLib::Battling {
|
||||||
try_creature(this->_historyHolder->Register<T>(this->GetCurrentTurn(), args...);
|
try_creature(this->_historyHolder->Register<T>(this->GetCurrentTurn(), args...);
|
||||||
, "Exception occurred during history element registration.");
|
, "Exception occurred during history element registration.");
|
||||||
}
|
}
|
||||||
const HistoryHolder* GetHistory() const noexcept { return _historyHolder.GetRaw(); }
|
const ArbUt::BorrowedPtr<HistoryHolder> GetHistory() const noexcept { return _historyHolder.GetRaw(); }
|
||||||
|
|
||||||
long GetLastTurnTimeMicroseconds() const noexcept { return _lastTurnTime; }
|
long GetLastTurnTimeMicroseconds() const noexcept { return _lastTurnTime; }
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Battle* Clone() const;
|
virtual Battle* non_null Clone() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace CreatureLib::Battling {
|
||||||
ArbUt::List<CreatureIndex> _responsibleIndices;
|
ArbUt::List<CreatureIndex> _responsibleIndices;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BattleParty(CreatureParty* party, const ArbUt::List<CreatureIndex>& responsibleIndices)
|
BattleParty(CreatureParty* non_null party, const ArbUt::List<CreatureIndex>& responsibleIndices)
|
||||||
: _party(party), _responsibleIndices(responsibleIndices) {}
|
: _party(party), _responsibleIndices(responsibleIndices) {}
|
||||||
|
|
||||||
virtual ~BattleParty() = default;
|
virtual ~BattleParty() = default;
|
||||||
|
@ -43,7 +43,7 @@ namespace CreatureLib::Battling {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual BattleParty* Clone() const { return new BattleParty(_party->Clone(), _responsibleIndices); }
|
virtual BattleParty* non_null Clone() const { return new BattleParty(_party->Clone(), _responsibleIndices); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
#include "Creature.hpp"
|
#include "Creature.hpp"
|
||||||
#include "ExecutingAttack.hpp"
|
#include "ExecutingAttack.hpp"
|
||||||
|
|
||||||
bool CreatureLib::Battling::BattleRandom::EffectChance(float chance, ExecutingAttack* attack, Creature* target) {
|
bool CreatureLib::Battling::BattleRandom::EffectChance(float chance, ExecutingAttack* non_null attack,
|
||||||
|
Creature* non_null target) {
|
||||||
|
EnsureNotNull(attack);
|
||||||
|
EnsureNotNull(target);
|
||||||
HOOK(ModifyEffectChance, attack, attack, target, &chance);
|
HOOK(ModifyEffectChance, attack, attack, target, &chance);
|
||||||
HOOK(ModifyIncomingEffectChance, target, attack, target, &chance);
|
HOOK(ModifyIncomingEffectChance, target, attack, target, &chance);
|
||||||
chance /= 100;
|
chance /= 100;
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace CreatureLib::Battling {
|
||||||
BattleRandom() noexcept : _random() {}
|
BattleRandom() noexcept : _random() {}
|
||||||
explicit BattleRandom(uint_fast32_t seed) noexcept : _random(seed) {}
|
explicit BattleRandom(uint_fast32_t seed) noexcept : _random(seed) {}
|
||||||
|
|
||||||
bool EffectChance(float chance, ExecutingAttack* attack, Creature* target);
|
bool EffectChance(float chance, ExecutingAttack* non_null attack, Creature* non_null target);
|
||||||
i32 Get() noexcept { return _random.Get(); }
|
i32 Get() noexcept { return _random.Get(); }
|
||||||
i32 Get(i32 max) noexcept { return _random.Get(max); }
|
i32 Get(i32 max) noexcept { return _random.Get(max); }
|
||||||
i32 Get(i32 min, i32 max) noexcept { return _random.Get(min, max); }
|
i32 Get(i32 min, i32 max) noexcept { return _random.Get(min, max); }
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
[[nodiscard]] bool AllPossibleSlotsFilled() const;
|
[[nodiscard]] bool AllPossibleSlotsFilled() const;
|
||||||
|
|
||||||
void SetChoice(BaseTurnChoice* choice);
|
void SetChoice(BaseTurnChoice* non_null choice);
|
||||||
void ResetChoices() noexcept;
|
void ResetChoices() noexcept;
|
||||||
|
|
||||||
void ForceClearCreature(u8 index) { _creatures[index] = {}; }
|
void ForceClearCreature(u8 index) { _creatures[index] = {}; }
|
||||||
|
@ -94,7 +94,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
bool SwapPositions(u8 a, u8 b);
|
bool SwapPositions(u8 a, u8 b);
|
||||||
|
|
||||||
BattleSide* CloneWithoutCreatures(ArbUt::BorrowedPtr<Battle> battle) const;
|
BattleSide* non_null CloneWithoutCreatures(ArbUt::BorrowedPtr<Battle> battle) const;
|
||||||
|
|
||||||
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(const ArbUt::StringView& key) const {
|
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(const ArbUt::StringView& key) const {
|
||||||
return _volatile.Get(key);
|
return _volatile.Get(key);
|
||||||
|
@ -102,11 +102,11 @@ namespace CreatureLib::Battling {
|
||||||
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(u32 keyHash) const noexcept {
|
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(u32 keyHash) const noexcept {
|
||||||
return _volatile.Get(keyHash);
|
return _volatile.Get(keyHash);
|
||||||
}
|
}
|
||||||
BattleScript* AddVolatileScript(const ArbUt::StringView& key);
|
BattleScript* non_null AddVolatileScript(const ArbUt::StringView& key);
|
||||||
BattleScript* AddVolatileScript(BattleScript* script);
|
BattleScript* non_null AddVolatileScript(BattleScript* non_null script);
|
||||||
void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
|
void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
|
||||||
void RemoveVolatileScript(u32 keyHash) { _volatile.Remove(keyHash); }
|
void RemoveVolatileScript(u32 keyHash) { _volatile.Remove(keyHash); }
|
||||||
void RemoveVolatileScript(BattleScript* script);
|
void RemoveVolatileScript(BattleScript* non_null script);
|
||||||
bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
|
bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
|
||||||
bool HasVolatileScript(u32 keyHash) const { return _volatile.Has(keyHash); }
|
bool HasVolatileScript(u32 keyHash) const { return _volatile.Has(keyHash); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -174,10 +174,10 @@ namespace CreatureLib::Battling {
|
||||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||||
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||||
void ClearVolatileScripts();
|
void ClearVolatileScripts();
|
||||||
BattleScript* AddVolatileScript(const ArbUt::StringView& name);
|
BattleScript* non_null AddVolatileScript(const ArbUt::StringView& name);
|
||||||
BattleScript* AddVolatileScript(BattleScript* script);
|
BattleScript* non_null AddVolatileScript(BattleScript* non_null script);
|
||||||
void RemoveVolatileScript(const ArbUt::BasicStringView& name);
|
void RemoveVolatileScript(const ArbUt::BasicStringView& name);
|
||||||
void RemoveVolatileScript(BattleScript* script);
|
void RemoveVolatileScript(BattleScript* non_null script);
|
||||||
bool HasVolatileScript(const ArbUt::BasicStringView& name) const;
|
bool HasVolatileScript(const ArbUt::BasicStringView& name) const;
|
||||||
|
|
||||||
const ArbUt::OptionalUniquePtrList<LearnedAttack>& GetAttacks() noexcept { return _attacks; }
|
const ArbUt::OptionalUniquePtrList<LearnedAttack>& GetAttacks() noexcept { return _attacks; }
|
||||||
|
@ -205,8 +205,8 @@ namespace CreatureLib::Battling {
|
||||||
inline void SetAllowedExperienceGain(bool allowed) noexcept { _allowedExperienceGain = allowed; }
|
inline void SetAllowedExperienceGain(bool allowed) noexcept { _allowedExperienceGain = allowed; }
|
||||||
|
|
||||||
u8 GetAvailableAttackSlot() const noexcept;
|
u8 GetAvailableAttackSlot() const noexcept;
|
||||||
void AddAttack(LearnedAttack* attack);
|
void AddAttack(LearnedAttack* non_null attack);
|
||||||
void ReplaceAttack(size_t index, LearnedAttack* attack);
|
void ReplaceAttack(size_t index, LearnedAttack* non_null attack);
|
||||||
void SwapAttacks(size_t a, size_t b) { _attacks.Swap(a, b); }
|
void SwapAttacks(size_t a, size_t b) { _attacks.Swap(a, b); }
|
||||||
|
|
||||||
void SetStatus(const ArbUt::StringView& name);
|
void SetStatus(const ArbUt::StringView& name);
|
||||||
|
@ -231,7 +231,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
virtual Creature* Clone() const;
|
virtual Creature* non_null Clone() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace CreatureLib::Battling {
|
||||||
_party.Append(nullptr);
|
_party.Append(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CreatureParty(ArbUt::List<Creature*> party) noexcept : _party(party.GetStdList()) {}
|
CreatureParty(ArbUt::List<Creature * nullable> party) noexcept : _party(party.GetStdList()) {}
|
||||||
CreatureParty(std::initializer_list<Creature*> party) noexcept : _party(party) {}
|
CreatureParty(std::initializer_list<Creature*> party) noexcept : _party(party) {}
|
||||||
|
|
||||||
virtual ~CreatureParty() = default;
|
virtual ~CreatureParty() = default;
|
||||||
|
@ -22,7 +22,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
void Switch(size_t a, size_t b) noexcept { _party.Swap(a, b); }
|
void Switch(size_t a, size_t b) noexcept { _party.Swap(a, b); }
|
||||||
|
|
||||||
Creature* SwapInto(size_t index, Creature* creature) {
|
Creature* nullable SwapInto(size_t index, Creature* nullable creature) {
|
||||||
if (index >= _party.Count()) {
|
if (index >= _party.Count()) {
|
||||||
THROW("Index was out of bounds for party.")
|
THROW("Index was out of bounds for party.")
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ namespace CreatureLib::Battling {
|
||||||
return _party.Contains(creature);
|
return _party.Contains(creature);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual CreatureParty* Clone() const {
|
virtual CreatureParty* non_null Clone() const {
|
||||||
auto party = new CreatureParty(_party.Count());
|
auto party = new CreatureParty(_party.Count());
|
||||||
auto i = 0;
|
auto i = 0;
|
||||||
for (auto c : _party) {
|
for (auto c : _party) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ namespace CreatureLib::Battling {
|
||||||
THROW("Invalid target requested.");
|
THROW("Invalid target requested.");
|
||||||
}
|
}
|
||||||
|
|
||||||
HitData* GetTargetIteratorBegin(ArbUt::BorrowedPtr<Creature> creature) {
|
HitData* non_null GetTargetIteratorBegin(ArbUt::BorrowedPtr<Creature> creature) {
|
||||||
for (u8 i = 0; i < _targets.Count(); i++) {
|
for (u8 i = 0; i < _targets.Count(); i++) {
|
||||||
if (!_targets[i].HasValue()) {
|
if (!_targets[i].HasValue()) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
virtual ~BattleScript() = default;
|
virtual ~BattleScript() = default;
|
||||||
|
|
||||||
virtual BattleScript* Clone(const ArbUt::OptionalBorrowedPtr<void>& owner) = 0;
|
virtual BattleScript* non_null Clone(const ArbUt::OptionalBorrowedPtr<void>& owner) = 0;
|
||||||
|
|
||||||
virtual void Stack(){};
|
virtual void Stack(){};
|
||||||
virtual void OnRemove(){};
|
virtual void OnRemove(){};
|
||||||
|
@ -45,82 +45,89 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
#define _par_ [[maybe_unused]]
|
#define _par_ [[maybe_unused]]
|
||||||
|
|
||||||
virtual void OnInitialize(_par_ const BattleLibrary*,
|
virtual void OnInitialize(_par_ const BattleLibrary* non_null,
|
||||||
_par_ const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
|
_par_ const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
|
||||||
virtual void OnBeforeTurn(_par_ const BaseTurnChoice* choice){};
|
virtual void OnBeforeTurn(_par_ const BaseTurnChoice* non_null choice){};
|
||||||
|
|
||||||
virtual void ChangeSpeed(_par_ BaseTurnChoice* choice, _par_ u32* speed){};
|
virtual void ChangeSpeed(_par_ BaseTurnChoice* non_null choice, _par_ u32* non_null speed){};
|
||||||
virtual void ChangePriority(_par_ AttackTurnChoice* choice, _par_ i8* priority){};
|
virtual void ChangePriority(_par_ AttackTurnChoice* non_null choice, _par_ i8* non_null priority){};
|
||||||
virtual void ChangeAttack(_par_ AttackTurnChoice* choice, _par_ ArbUt::StringView* outAttack){};
|
virtual void ChangeAttack(_par_ AttackTurnChoice* non_null choice,
|
||||||
virtual void ModifyNumberOfHits(_par_ AttackTurnChoice* choice, _par_ u8* numberOfHits){};
|
_par_ ArbUt::StringView* non_null outAttack){};
|
||||||
virtual void PreventAttack(_par_ ExecutingAttack* attack, _par_ bool* outResult){};
|
virtual void ModifyNumberOfHits(_par_ AttackTurnChoice* non_null choice, _par_ u8* non_null numberOfHits){};
|
||||||
virtual void FailAttack(_par_ ExecutingAttack* attack, _par_ bool* outFailed){};
|
virtual void PreventAttack(_par_ ExecutingAttack* non_null attack, _par_ bool* non_null outResult){};
|
||||||
virtual void StopBeforeAttack(_par_ ExecutingAttack* attack, _par_ bool* outResult){};
|
virtual void FailAttack(_par_ ExecutingAttack* non_null attack, _par_ bool* non_null outFailed){};
|
||||||
virtual void OnBeforeAttack(_par_ ExecutingAttack* attack){};
|
virtual void StopBeforeAttack(_par_ ExecutingAttack* non_null attack, _par_ bool* non_null outResult){};
|
||||||
|
virtual void OnBeforeAttack(_par_ ExecutingAttack* non_null attack){};
|
||||||
|
|
||||||
virtual void FailIncomingAttack(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ bool* outResult){};
|
virtual void FailIncomingAttack(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
virtual void IsInvulnerable(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ bool* outResult){};
|
_par_ bool* non_null outResult){};
|
||||||
virtual void OnAttackMiss(_par_ ExecutingAttack* attack, _par_ Creature* target){};
|
virtual void IsInvulnerable(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
virtual void ChangeAttackType(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber,
|
_par_ bool* non_null outResult){};
|
||||||
_par_ u8* outType){};
|
virtual void OnAttackMiss(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target){};
|
||||||
virtual void ChangeEffectiveness(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber,
|
virtual void ChangeAttackType(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ float* effectiveness){};
|
_par_ u8 hitNumber, _par_ u8* non_null outType){};
|
||||||
virtual void BlockCritical(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber,
|
virtual void ChangeEffectiveness(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ bool* blockCritical){};
|
_par_ u8 hitNumber, _par_ float* non_null effectiveness){};
|
||||||
|
virtual void BlockCritical(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
|
_par_ u8 hitNumber, _par_ bool* non_null blockCritical){};
|
||||||
|
|
||||||
virtual void OverrideBasePower(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
|
virtual void OverrideBasePower(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ u8* basePower){};
|
_par_ u8 hitIndex, _par_ u8* non_null basePower){};
|
||||||
virtual void ChangeDamageStatsUser(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
|
virtual void ChangeDamageStatsUser(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ Creature** statsUser){};
|
_par_ u8 hitIndex, _par_ Creature* non_null* non_null statsUser){};
|
||||||
|
|
||||||
virtual void BypassDefensiveStat(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
|
virtual void BypassDefensiveStat(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ bool* bypass){};
|
_par_ u8 hitIndex, _par_ bool* non_null bypass){};
|
||||||
virtual void BypassOffensiveStat(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
|
virtual void BypassOffensiveStat(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ bool* bypass){};
|
_par_ u8 hitIndex, _par_ bool* non_null bypass){};
|
||||||
virtual void ModifyStatModifier(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
|
virtual void ModifyStatModifier(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ float* modifier){};
|
_par_ u8 hitIndex, _par_ float* non_null modifier){};
|
||||||
virtual void ModifyDamageModifier(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
|
virtual void ModifyDamageModifier(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ float* modifier){};
|
_par_ u8 hitIndex, _par_ float* non_null modifier){};
|
||||||
virtual void OverrideDamage(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
|
virtual void OverrideDamage(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ u32* damage){};
|
_par_ u8 hitIndex, _par_ u32* non_null damage){};
|
||||||
virtual void OverrideIncomingDamage(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
|
virtual void OverrideIncomingDamage(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ u32* damage){};
|
_par_ u8 hitIndex, _par_ u32* non_null damage){};
|
||||||
|
|
||||||
virtual void OnIncomingHit(_par_ const ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber){};
|
virtual void OnIncomingHit(_par_ const ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
virtual void OnFaintingOpponent(_par_ const ExecutingAttack* attack, _par_ Creature* target,
|
_par_ u8 hitNumber){};
|
||||||
|
virtual void OnFaintingOpponent(_par_ const ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ u8 hitNumber){};
|
_par_ u8 hitNumber){};
|
||||||
|
|
||||||
virtual void PreventStatBoostChange(_par_ Creature* target, _par_ Library::Statistic stat, _par_ i8 diffAmount,
|
virtual void PreventStatBoostChange(_par_ Creature* non_null target, _par_ Library::Statistic stat,
|
||||||
_par_ bool selfInflicted, _par_ bool* prevent){};
|
_par_ i8 diffAmount, _par_ bool selfInflicted,
|
||||||
virtual void ModifyStatBoostChange(_par_ Creature* target, _par_ Library::Statistic stat,
|
_par_ bool* non_null prevent){};
|
||||||
_par_ i8* diffAmount){};
|
virtual void ModifyStatBoostChange(_par_ Creature* non_null target, _par_ Library::Statistic stat,
|
||||||
virtual void PreventSecondaryEffects(_par_ const ExecutingAttack* attack, _par_ Creature* target,
|
_par_ i8* non_null diffAmount){};
|
||||||
_par_ u8 hitNumber, _par_ bool* outResult){};
|
virtual void PreventSecondaryEffects(_par_ const ExecutingAttack* non_null attack,
|
||||||
virtual void OnSecondaryEffect(_par_ const ExecutingAttack* attack, _par_ Creature* target,
|
_par_ Creature* non_null target, _par_ u8 hitNumber,
|
||||||
|
_par_ bool* non_null outResult){};
|
||||||
|
virtual void OnSecondaryEffect(_par_ const ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ u8 hitNumber){};
|
_par_ u8 hitNumber){};
|
||||||
|
|
||||||
virtual void OnAfterHits(_par_ const ExecutingAttack* attack, _par_ Creature* target){};
|
virtual void OnAfterHits(_par_ const ExecutingAttack* non_null attack, _par_ Creature* non_null target){};
|
||||||
|
|
||||||
virtual void PreventSelfSwitch(_par_ const SwitchTurnChoice* choice, _par_ bool* outResult){};
|
virtual void PreventSelfSwitch(_par_ const SwitchTurnChoice* non_null choice, _par_ bool* non_null outResult){};
|
||||||
virtual void PreventOpponentSwitch(_par_ const SwitchTurnChoice* choice, _par_ bool* outResult){};
|
virtual void PreventOpponentSwitch(_par_ const SwitchTurnChoice* non_null choice,
|
||||||
|
_par_ bool* non_null outResult){};
|
||||||
|
|
||||||
virtual void ModifyEffectChance(_par_ const ExecutingAttack* attack, _par_ Creature* target,
|
virtual void ModifyEffectChance(_par_ const ExecutingAttack* non_null attack, _par_ Creature* non_null target,
|
||||||
_par_ float* chance){};
|
_par_ float* non_null chance){};
|
||||||
virtual void ModifyIncomingEffectChance(_par_ const ExecutingAttack* attack, _par_ Creature* target,
|
virtual void ModifyIncomingEffectChance(_par_ const ExecutingAttack* non_null attack,
|
||||||
_par_ float* chance){};
|
_par_ Creature* non_null target, _par_ float* non_null chance){};
|
||||||
|
|
||||||
virtual void OnFail(_par_ Creature* target){};
|
virtual void OnFail(_par_ Creature* non_null target){};
|
||||||
virtual void OnOpponentFail(_par_ Creature* target){};
|
virtual void OnOpponentFail(_par_ Creature* non_null target){};
|
||||||
|
|
||||||
virtual void PreventRunAway(_par_ const FleeTurnChoice* choice, _par_ bool* result){};
|
virtual void PreventRunAway(_par_ const FleeTurnChoice* non_null choice, _par_ bool* non_null result){};
|
||||||
virtual void PreventOpponentRunAway(_par_ const FleeTurnChoice* choice, _par_ bool* result){};
|
virtual void PreventOpponentRunAway(_par_ const FleeTurnChoice* non_null choice, _par_ bool* non_null result){};
|
||||||
|
|
||||||
virtual void OnEndTurn(){};
|
virtual void OnEndTurn(){};
|
||||||
virtual void OnDamage(Creature*, DamageSource, _par_ u32 oldHealth, _par_ u32 newHealth){};
|
virtual void OnDamage(Creature* non_null, DamageSource, _par_ u32 oldHealth, _par_ u32 newHealth){};
|
||||||
virtual void OnFaint(Creature*, DamageSource){};
|
virtual void OnFaint(Creature* non_null, DamageSource){};
|
||||||
virtual void OnSwitchIn(Creature*){};
|
virtual void OnSwitchIn(Creature* non_null){};
|
||||||
|
|
||||||
virtual void OnAfterHeldItemConsume(Creature*, const Library::Item*){};
|
virtual void OnAfterHeldItemConsume(Creature* non_null, const Library::Item* non_null){};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,20 +11,23 @@ namespace CreatureLib::Battling {
|
||||||
public:
|
public:
|
||||||
virtual ~ItemUseScript() = default;
|
virtual ~ItemUseScript() = default;
|
||||||
|
|
||||||
virtual void
|
virtual void OnInitialize(
|
||||||
OnInitialize([[maybe_unused]] const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
|
[[maybe_unused]] const ArbUt::List<CreatureLib::Library::EffectParameter * non_null>& parameters){};
|
||||||
/// @brief Is the item an item we are able to use?
|
/// @brief Is the item an item we are able to use?
|
||||||
[[nodiscard]] virtual bool IsItemUsable() const { return false; }
|
[[nodiscard]] virtual bool IsItemUsable() const { return false; }
|
||||||
/// @brief Do we need to use the item on a creature?
|
/// @brief Do we need to use the item on a creature?
|
||||||
[[nodiscard]] virtual bool IsCreatureUseItem() const { return false; }
|
[[nodiscard]] virtual bool IsCreatureUseItem() const { return false; }
|
||||||
/// @brief Can the item be used on the given creature.
|
/// @brief Can the item be used on the given creature.
|
||||||
[[nodiscard]] virtual bool IsUseValidForCreature([[maybe_unused]] Creature* creature) const { return false; }
|
[[nodiscard]] virtual bool IsUseValidForCreature([[maybe_unused]] Creature* non_null creature) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Can the item be held?
|
/// @brief Can the item be held?
|
||||||
[[nodiscard]] virtual bool IsHoldable() const { return false; }
|
[[nodiscard]] virtual bool IsHoldable() const { return false; }
|
||||||
|
|
||||||
virtual void OnUse([[maybe_unused]] Battle* battle) const {}
|
virtual void OnUse([[maybe_unused]] Battle* non_null battle) const {}
|
||||||
virtual void OnCreatureUse([[maybe_unused]] Creature* creature, [[maybe_unused]] bool isBattle) const {}
|
virtual void OnCreatureUse([[maybe_unused]] Creature* non_null creature, [[maybe_unused]] bool isBattle) const {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,15 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
virtual ~ScriptResolver() = default;
|
virtual ~ScriptResolver() = default;
|
||||||
|
|
||||||
virtual void Initialize([[maybe_unused]] BattleLibrary* library){};
|
virtual void Initialize([[maybe_unused]] BattleLibrary* non_null library){};
|
||||||
virtual BattleScript* LoadScript([[maybe_unused]] const ArbUt::OptionalBorrowedPtr<void>& owner,
|
virtual BattleScript* nullable LoadScript([[maybe_unused]] const ArbUt::OptionalBorrowedPtr<void>& owner,
|
||||||
[[maybe_unused]] ScriptCategory category,
|
[[maybe_unused]] ScriptCategory category,
|
||||||
[[maybe_unused]] const ArbUt::StringView& scriptName) {
|
[[maybe_unused]] const ArbUt::StringView& scriptName) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ItemUseScript* LoadItemScript([[maybe_unused]] const CreatureLib::Library::Item* item) {
|
virtual ItemUseScript* nullable
|
||||||
|
LoadItemScript([[maybe_unused]] const CreatureLib::Library::Item* non_null item) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BattleScript* Add(BattleScript* script) {
|
BattleScript* non_null Add(BattleScript* non_null script) {
|
||||||
auto v = _lookup.TryGet(script->GetName());
|
auto v = _lookup.TryGet(script->GetName());
|
||||||
if (v.has_value()) {
|
if (v.has_value()) {
|
||||||
_scripts[v.value()]->Stack();
|
_scripts[v.value()]->Stack();
|
||||||
|
|
|
@ -9,21 +9,23 @@ namespace CreatureLib::Battling {
|
||||||
bool _isSet;
|
bool _isSet;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
std::unique_ptr<BattleScript> const* _script;
|
std::unique_ptr<BattleScript> const* nullable _script;
|
||||||
const ScriptSet* _scriptSet;
|
const ScriptSet* nullable _scriptSet;
|
||||||
};
|
};
|
||||||
|
|
||||||
ScriptWrapper(std::unique_ptr<BattleScript>* s, bool isSet) : _isSet(isSet), _script(s){};
|
ScriptWrapper(std::unique_ptr<BattleScript>* nullable s, bool isSet) : _isSet(isSet), _script(s){};
|
||||||
ScriptWrapper(ScriptSet* s, bool isSet) : _isSet(isSet), _scriptSet(s){};
|
ScriptWrapper(ScriptSet* nullable s, bool isSet) : _isSet(isSet), _scriptSet(s){};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static inline ScriptWrapper FromScript(std::unique_ptr<BattleScript>* s) { return ScriptWrapper(s, false); }
|
static inline ScriptWrapper FromScript(std::unique_ptr<BattleScript>* nullable s) {
|
||||||
static inline ScriptWrapper FromSet(ScriptSet* s) { return ScriptWrapper(s, true); }
|
return ScriptWrapper(s, false);
|
||||||
|
}
|
||||||
|
static inline ScriptWrapper FromSet(ScriptSet* nullable s) { return ScriptWrapper(s, true); }
|
||||||
|
|
||||||
inline bool IsSet() const noexcept { return _isSet; }
|
inline bool IsSet() const noexcept { return _isSet; }
|
||||||
|
|
||||||
inline const std::unique_ptr<BattleScript>* GetScript() const noexcept { return _script; }
|
inline const std::unique_ptr<BattleScript>* nullable GetScript() const noexcept { return _script; }
|
||||||
inline const ScriptSet* GetScriptSet() const noexcept { return _scriptSet; }
|
inline const ScriptSet* nullable GetScriptSet() const noexcept { return _scriptSet; }
|
||||||
|
|
||||||
inline bool HasValue() const noexcept {
|
inline bool HasValue() const noexcept {
|
||||||
if (_isSet)
|
if (_isSet)
|
||||||
|
|
|
@ -3,16 +3,16 @@
|
||||||
#include <Arbutils/Defines.hpp>
|
#include <Arbutils/Defines.hpp>
|
||||||
|
|
||||||
#if LEVEL_U8
|
#if LEVEL_U8
|
||||||
using level_int_t = uint8_t;
|
using level_int_t = u8;
|
||||||
#elif LEVEL_U16
|
#elif LEVEL_U16
|
||||||
using level_int_t = uint16_t;
|
using level_int_t = u16;
|
||||||
#elif LEVEL_U32
|
#elif LEVEL_U32
|
||||||
using level_int_t = uint32_t;
|
using level_int_t = u32;
|
||||||
#elif LEVEL_U64
|
#elif LEVEL_U64
|
||||||
using level_int_t = uint64_t;
|
using level_int_t = u64;
|
||||||
#else
|
#else
|
||||||
#warning Level size was not specified, falling back to uint8_t
|
#warning Level size was not specified, falling back to uint8_t
|
||||||
using level_int_t = uint8_t;
|
using level_int_t = u8;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // CREATURELIB_DEFINES_HPP
|
#endif // CREATURELIB_DEFINES_HPP
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
#include "AttackLibrary.hpp"
|
|
|
@ -3,6 +3,6 @@
|
||||||
CreatureLib::Library::AttackData::AttackData(const ArbUt::StringView& name, u8 type,
|
CreatureLib::Library::AttackData::AttackData(const ArbUt::StringView& name, u8 type,
|
||||||
CreatureLib::Library::AttackCategory category, u8 power, u8 accuracy,
|
CreatureLib::Library::AttackCategory category, u8 power, u8 accuracy,
|
||||||
u8 baseUsage, CreatureLib::Library::AttackTarget target, i8 priority,
|
u8 baseUsage, CreatureLib::Library::AttackTarget target, i8 priority,
|
||||||
const SecondaryEffect* effect, std::unordered_set<u32> flags)
|
const SecondaryEffect* nullable effect, std::unordered_set<u32> flags)
|
||||||
: _name(name), _type(type), _category(category), _basePower(power), _accuracy(accuracy), _baseUsages(baseUsage),
|
: _name(name), _type(type), _category(category), _basePower(power), _accuracy(accuracy), _baseUsages(baseUsage),
|
||||||
_target(target), _priority(priority), _effect(effect), _flags(std::move(flags)) {}
|
_target(target), _priority(priority), _effect(effect), _flags(std::move(flags)) {}
|
||||||
|
|
|
@ -22,7 +22,8 @@ namespace CreatureLib::Library {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AttackData(const ArbUt::StringView& name, u8 type, AttackCategory category, u8 power, u8 accuracy, u8 baseUsage,
|
AttackData(const ArbUt::StringView& name, u8 type, AttackCategory category, u8 power, u8 accuracy, u8 baseUsage,
|
||||||
AttackTarget target, i8 priority, const SecondaryEffect* effect, std::unordered_set<u32> flags);
|
AttackTarget target, i8 priority, const SecondaryEffect* nullable effect,
|
||||||
|
std::unordered_set<u32> flags);
|
||||||
virtual ~AttackData() = default;
|
virtual ~AttackData() = default;
|
||||||
|
|
||||||
inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
||||||
|
|
|
@ -10,12 +10,12 @@ namespace CreatureLib::Library {
|
||||||
private:
|
private:
|
||||||
float _chance;
|
float _chance;
|
||||||
ArbUt::StringView _effectName;
|
ArbUt::StringView _effectName;
|
||||||
ArbUt::List<EffectParameter*> _parameters;
|
ArbUt::List<EffectParameter * non_null> _parameters;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SecondaryEffect() noexcept : _chance(0), _effectName() {}
|
SecondaryEffect() noexcept : _chance(0), _effectName() {}
|
||||||
SecondaryEffect(float chance, const ArbUt::StringView& effectName,
|
SecondaryEffect(float chance, const ArbUt::StringView& effectName,
|
||||||
const ArbUt::List<EffectParameter*>& parameters) noexcept
|
const ArbUt::List<EffectParameter * non_null>& parameters) noexcept
|
||||||
: _chance(chance), _effectName(effectName), _parameters(parameters) {}
|
: _chance(chance), _effectName(effectName), _parameters(parameters) {}
|
||||||
|
|
||||||
~SecondaryEffect() noexcept {
|
~SecondaryEffect() noexcept {
|
||||||
|
@ -26,7 +26,7 @@ namespace CreatureLib::Library {
|
||||||
|
|
||||||
constexpr inline float GetChance() const noexcept { return _chance; }
|
constexpr inline float GetChance() const noexcept { return _chance; }
|
||||||
constexpr inline const ArbUt::StringView& GetEffectName() const noexcept { return _effectName; }
|
constexpr inline const ArbUt::StringView& GetEffectName() const noexcept { return _effectName; }
|
||||||
const inline ArbUt::List<EffectParameter*>& GetParameters() const noexcept { return _parameters; }
|
const inline ArbUt::List<EffectParameter * non_null>& GetParameters() const noexcept { return _parameters; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
#include "BaseLibrary.hpp"
|
|
|
@ -18,12 +18,12 @@ namespace CreatureLib::Library {
|
||||||
|
|
||||||
virtual ~BaseLibrary() noexcept { _values.Clear(); }
|
virtual ~BaseLibrary() noexcept { _values.Clear(); }
|
||||||
|
|
||||||
inline virtual void Insert(const ArbUt::StringView& key, const T* value) {
|
inline virtual void Insert(const ArbUt::StringView& key, const T* non_null value) {
|
||||||
EnsureNotNull(value)
|
EnsureNotNull(value)
|
||||||
_values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)});
|
_values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)});
|
||||||
_listValues.Append(key);
|
_listValues.Append(key);
|
||||||
}
|
}
|
||||||
inline virtual void Insert(u32 hashedKey, const T* value) {
|
inline virtual void Insert(u32 hashedKey, const T* non_null value) {
|
||||||
EnsureNotNull(value)
|
EnsureNotNull(value)
|
||||||
_values.GetStdMap().insert({hashedKey, std::unique_ptr<const T>(value)});
|
_values.GetStdMap().insert({hashedKey, std::unique_ptr<const T>(value)});
|
||||||
_listValues.Append(hashedKey);
|
_listValues.Append(hashedKey);
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct CreatureSpecies::impl {
|
||||||
ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>> _variantsList;
|
ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>> _variantsList;
|
||||||
std::unordered_set<u32> _flags;
|
std::unordered_set<u32> _flags;
|
||||||
|
|
||||||
impl(u16 id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant, float genderRatio,
|
impl(u16 id, const ArbUt::StringView& name, const SpeciesVariant* non_null defaultVariant, float genderRatio,
|
||||||
const ArbUt::StringView& growthRate, u8 captureRate, std::unordered_set<u32> flags)
|
const ArbUt::StringView& growthRate, u8 captureRate, std::unordered_set<u32> flags)
|
||||||
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
|
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
|
||||||
_variantsLookup(1), _variantsList(1), _flags(std::move(flags)) {
|
_variantsLookup(1), _variantsList(1), _flags(std::move(flags)) {
|
||||||
|
@ -60,7 +60,7 @@ struct CreatureSpecies::impl {
|
||||||
}
|
}
|
||||||
[[nodiscard]] inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
[[nodiscard]] inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
||||||
|
|
||||||
void SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant) {
|
void SetVariant(const ArbUt::StringView& name, const SpeciesVariant* non_null variant) {
|
||||||
Ensure(!name.IsEmpty())
|
Ensure(!name.IsEmpty())
|
||||||
_variantsList.CreateBack(variant);
|
_variantsList.CreateBack(variant);
|
||||||
_variantsLookup.GetStdMap().emplace(name, variant);
|
_variantsLookup.GetStdMap().emplace(name, variant);
|
||||||
|
@ -106,7 +106,7 @@ ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(const ArbUt
|
||||||
}
|
}
|
||||||
ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(u32 key) const { return _impl->GetVariant(key); }
|
ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(u32 key) const { return _impl->GetVariant(key); }
|
||||||
Gender CreatureSpecies::GetRandomGender(ArbUt::Random& rand) const noexcept { return _impl->GetRandomGender(rand); }
|
Gender CreatureSpecies::GetRandomGender(ArbUt::Random& rand) const noexcept { return _impl->GetRandomGender(rand); }
|
||||||
void CreatureSpecies::SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant) {
|
void CreatureSpecies::SetVariant(const ArbUt::StringView& name, const SpeciesVariant* non_null variant) {
|
||||||
_impl->SetVariant(name, variant);
|
_impl->SetVariant(name, variant);
|
||||||
}
|
}
|
||||||
const ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>>& CreatureSpecies::GetVariantsIterator() const {
|
const ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>>& CreatureSpecies::GetVariantsIterator() const {
|
||||||
|
|
|
@ -23,8 +23,9 @@ namespace CreatureLib::Library {
|
||||||
/// @param captureRate The chance to capture the creature species, between 0 and 255. 255 means instant capture,
|
/// @param captureRate The chance to capture the creature species, between 0 and 255. 255 means instant capture,
|
||||||
/// 0 means impossible to capture.
|
/// 0 means impossible to capture.
|
||||||
/// @param flags A set of flags for use by the developer. These can be used for easy grouping.
|
/// @param flags A set of flags for use by the developer. These can be used for easy grouping.
|
||||||
CreatureSpecies(u16 id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant, float genderRatio,
|
CreatureSpecies(u16 id, const ArbUt::StringView& name, const SpeciesVariant* non_null defaultVariant,
|
||||||
const ArbUt::StringView& growthRate, u8 captureRate, std::unordered_set<u32> flags = {});
|
float genderRatio, const ArbUt::StringView& growthRate, u8 captureRate,
|
||||||
|
std::unordered_set<u32> flags = {});
|
||||||
|
|
||||||
virtual ~CreatureSpecies();
|
virtual ~CreatureSpecies();
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ namespace CreatureLib::Library {
|
||||||
/// @brief Appends a variant to the species.
|
/// @brief Appends a variant to the species.
|
||||||
/// @param name The unique name of the new variant.
|
/// @param name The unique name of the new variant.
|
||||||
/// @param variant The new variant to add.
|
/// @param variant The new variant to add.
|
||||||
void SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant);
|
void SetVariant(const ArbUt::StringView& name, const SpeciesVariant* non_null variant);
|
||||||
|
|
||||||
/// @brief Returns a list of variants of the species.
|
/// @brief Returns a list of variants of the species.
|
||||||
/// @return A list of variants of the species.
|
/// @return A list of variants of the species.
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace CreatureLib::Library {
|
||||||
public:
|
public:
|
||||||
impl(const ArbUt::StringView& name, float height, float weight, u32 baseExperience, ArbUt::List<u8> types,
|
impl(const ArbUt::StringView& name, float height, float weight, u32 baseExperience, ArbUt::List<u8> types,
|
||||||
Library::StatisticSet<u16> baseStats, ArbUt::List<ArbUt::BorrowedPtr<const Talent>> talents,
|
Library::StatisticSet<u16> baseStats, ArbUt::List<ArbUt::BorrowedPtr<const Talent>> talents,
|
||||||
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> secretTalents, const LearnableAttacks* attacks,
|
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> secretTalents, const LearnableAttacks* non_null attacks,
|
||||||
std::unordered_set<u32> flags)
|
std::unordered_set<u32> flags)
|
||||||
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience),
|
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience),
|
||||||
_types(std::move((types))), _baseStatistics(baseStats), _talents(std::move(talents)),
|
_types(std::move((types))), _baseStatistics(baseStats), _talents(std::move(talents)),
|
||||||
|
@ -99,7 +99,7 @@ namespace CreatureLib::Library {
|
||||||
const ArbUt::List<u8>& types, StatisticSet<u16> baseStats,
|
const ArbUt::List<u8>& types, StatisticSet<u16> baseStats,
|
||||||
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
|
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
|
||||||
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
|
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
|
||||||
const LearnableAttacks* attacks, const std::unordered_set<u32>& flags)
|
const LearnableAttacks* non_null attacks, const std::unordered_set<u32>& flags)
|
||||||
: _impl(new impl(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks,
|
: _impl(new impl(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks,
|
||||||
flags)) {}
|
flags)) {}
|
||||||
SpeciesVariant::~SpeciesVariant() = default;
|
SpeciesVariant::~SpeciesVariant() = default;
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace CreatureLib::Library {
|
||||||
const ArbUt::List<u8>& types, Library::StatisticSet<u16> baseStats,
|
const ArbUt::List<u8>& types, Library::StatisticSet<u16> baseStats,
|
||||||
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
|
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
|
||||||
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
|
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
|
||||||
const LearnableAttacks* attacks, const std::unordered_set<u32>& flags = {});
|
const LearnableAttacks* non_null attacks, const std::unordered_set<u32>& flags = {});
|
||||||
virtual ~SpeciesVariant();
|
virtual ~SpeciesVariant();
|
||||||
|
|
||||||
/// @brief Returns the unique name of the variant.
|
/// @brief Returns the unique name of the variant.
|
||||||
|
|
|
@ -8,12 +8,15 @@
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
class Talent {
|
class Talent {
|
||||||
public:
|
public:
|
||||||
Talent(const ArbUt::StringView& name, const ArbUt::StringView& effect, ArbUt::List<EffectParameter*> parameters)
|
Talent(const ArbUt::StringView& name, const ArbUt::StringView& effect,
|
||||||
|
ArbUt::List<EffectParameter * non_null> parameters)
|
||||||
: _name(name), _effect(effect), _parameters(std::move(parameters)) {}
|
: _name(name), _effect(effect), _parameters(std::move(parameters)) {}
|
||||||
|
|
||||||
[[nodiscard]] inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
[[nodiscard]] inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
||||||
[[nodiscard]] inline const ArbUt::StringView& GetEffect() const noexcept { return _effect; }
|
[[nodiscard]] inline const ArbUt::StringView& GetEffect() const noexcept { return _effect; }
|
||||||
[[nodiscard]] inline const ArbUt::List<EffectParameter*>& GetParameters() const noexcept { return _parameters; }
|
[[nodiscard]] inline const ArbUt::List<EffectParameter * non_null>& GetParameters() const noexcept {
|
||||||
|
return _parameters;
|
||||||
|
}
|
||||||
|
|
||||||
~Talent() noexcept {
|
~Talent() noexcept {
|
||||||
for (auto p : _parameters) {
|
for (auto p : _parameters) {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#include "DataLibrary.hpp"
|
#include "DataLibrary.hpp"
|
||||||
|
|
||||||
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
|
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* non_null settings,
|
||||||
CreatureLib::Library::AttackLibrary* attacks,
|
CreatureLib::Library::SpeciesLibrary* non_null species,
|
||||||
CreatureLib::Library::ItemLibrary* items,
|
CreatureLib::Library::AttackLibrary* non_null attacks,
|
||||||
CreatureLib::Library::GrowthRateLibrary* growthRates,
|
CreatureLib::Library::ItemLibrary* non_null items,
|
||||||
TypeLibrary* typeLibrary, TalentLibrary* talentLibrary)
|
CreatureLib::Library::GrowthRateLibrary* non_null growthRates,
|
||||||
|
TypeLibrary* typeLibrary, TalentLibrary* non_null talentLibrary)
|
||||||
: _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates),
|
: _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates),
|
||||||
_typeLibrary(typeLibrary), _talentLibrary(talentLibrary) {
|
_typeLibrary(typeLibrary), _talentLibrary(talentLibrary) {
|
||||||
EnsureNotNull(_settings)
|
EnsureNotNull(_settings)
|
||||||
|
|
|
@ -24,10 +24,11 @@ namespace CreatureLib::Library {
|
||||||
std::unique_ptr<const TalentLibrary> _talentLibrary;
|
std::unique_ptr<const TalentLibrary> _talentLibrary;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
|
DataLibrary(LibrarySettings* non_null settings, CreatureLib::Library::SpeciesLibrary* non_null species,
|
||||||
CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items,
|
CreatureLib::Library::AttackLibrary* non_null attacks,
|
||||||
CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary,
|
CreatureLib::Library::ItemLibrary* non_null items,
|
||||||
TalentLibrary* talentLibrary);
|
CreatureLib::Library::GrowthRateLibrary* non_null growthRates, TypeLibrary* non_null typeLibrary,
|
||||||
|
TalentLibrary* non_null talentLibrary);
|
||||||
|
|
||||||
virtual ~DataLibrary() {}
|
virtual ~DataLibrary() {}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,12 @@
|
||||||
|
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
class ExternGrowthRate : public GrowthRate {
|
class ExternGrowthRate : public GrowthRate {
|
||||||
level_int_t (*_calcLevel)(u32 experience);
|
level_int_t (*_calcLevel)(u32 experience) non_null;
|
||||||
u32 (*_calcExperience)(level_int_t level);
|
u32 (*_calcExperience)(level_int_t level) non_null;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline ExternGrowthRate(level_int_t (*calcLevel)(u32), u32 (*calcExperience)(level_int_t level))
|
inline ExternGrowthRate(level_int_t (*calcLevel)(u32) non_null,
|
||||||
|
u32 (*calcExperience)(level_int_t level) non_null)
|
||||||
: _calcLevel(calcLevel), _calcExperience(calcExperience) {
|
: _calcLevel(calcLevel), _calcExperience(calcExperience) {
|
||||||
EnsureNotNull(calcLevel)
|
EnsureNotNull(calcLevel)
|
||||||
EnsureNotNull(calcExperience)
|
EnsureNotNull(calcExperience)
|
||||||
|
|
|
@ -37,10 +37,12 @@ u32 CreatureLib::Library::GrowthRateLibrary::CalculateExperience(u32 hash, level
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ArbUt::StringView& name,
|
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ArbUt::StringView& name,
|
||||||
CreatureLib::Library::GrowthRate* rate) {
|
CreatureLib::Library::GrowthRate* non_null rate) {
|
||||||
|
EnsureNotNull(rate);
|
||||||
_growthRates.insert({name, std::unique_ptr<const GrowthRate>(rate)});
|
_growthRates.insert({name, std::unique_ptr<const GrowthRate>(rate)});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(u32 hash, CreatureLib::Library::GrowthRate* rate) {
|
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(u32 hash, CreatureLib::Library::GrowthRate* non_null rate) {
|
||||||
|
EnsureNotNull(rate);
|
||||||
_growthRates.insert({hash, std::unique_ptr<const GrowthRate>(rate)});
|
_growthRates.insert({hash, std::unique_ptr<const GrowthRate>(rate)});
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ namespace CreatureLib::Library {
|
||||||
[[nodiscard]] u32 CalculateExperience(const ArbUt::BasicStringView& growthRate, level_int_t level) const;
|
[[nodiscard]] u32 CalculateExperience(const ArbUt::BasicStringView& growthRate, level_int_t level) const;
|
||||||
[[nodiscard]] u32 CalculateExperience(u32 hash, level_int_t level) const;
|
[[nodiscard]] u32 CalculateExperience(u32 hash, level_int_t level) const;
|
||||||
|
|
||||||
void AddGrowthRate(u32 hash, GrowthRate* rate);
|
void AddGrowthRate(u32 hash, GrowthRate* non_null rate);
|
||||||
void AddGrowthRate(const ArbUt::StringView& name, GrowthRate* rate);
|
void AddGrowthRate(const ArbUt::StringView& name, GrowthRate* non_null rate);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
#include "ItemLibrary.hpp"
|
|
|
@ -13,7 +13,7 @@ namespace CreatureLib::Library {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, i32 price,
|
inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, i32 price,
|
||||||
const SecondaryEffect* effect, const SecondaryEffect* battleTriggerEffect,
|
const SecondaryEffect* nullable effect, const SecondaryEffect* nullable battleTriggerEffect,
|
||||||
const std::unordered_set<u32>& flags) noexcept
|
const std::unordered_set<u32>& flags) noexcept
|
||||||
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _effect(effect),
|
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _effect(effect),
|
||||||
_battleTriggerEffect(battleTriggerEffect), _flags(flags) {}
|
_battleTriggerEffect(battleTriggerEffect), _flags(flags) {}
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace CreatureLib::Library {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, i32 price,
|
Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, i32 price,
|
||||||
const SecondaryEffect* effect, const SecondaryEffect* battleTriggerEffect,
|
const SecondaryEffect* nullable effect, const SecondaryEffect* nullable battleTriggerEffect,
|
||||||
const std::unordered_set<u32>& flags) noexcept;
|
const std::unordered_set<u32>& flags) noexcept;
|
||||||
NO_COPY_OR_MOVE(Item)
|
NO_COPY_OR_MOVE(Item)
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
#include "SpeciesLibrary.hpp"
|
|
|
@ -12,11 +12,11 @@ namespace CreatureLib::Library {
|
||||||
public:
|
public:
|
||||||
SpeciesLibrary(size_t initialCapacity = 32) : BaseLibrary(initialCapacity){};
|
SpeciesLibrary(size_t initialCapacity = 32) : BaseLibrary(initialCapacity){};
|
||||||
|
|
||||||
void Insert(const ArbUt::StringView& key, const CreatureSpecies* value) override {
|
void Insert(const ArbUt::StringView& key, const CreatureSpecies* non_null value) override {
|
||||||
BaseLibrary::Insert(key, value);
|
BaseLibrary::Insert(key, value);
|
||||||
_valuesById.Insert(value->GetId(), value);
|
_valuesById.Insert(value->GetId(), value);
|
||||||
}
|
}
|
||||||
void Insert(u32 hashedKey, const CreatureSpecies* value) override {
|
void Insert(u32 hashedKey, const CreatureSpecies* non_null value) override {
|
||||||
BaseLibrary::Insert(hashedKey, value);
|
BaseLibrary::Insert(hashedKey, value);
|
||||||
_valuesById.Insert(value->GetId(), value);
|
_valuesById.Insert(value->GetId(), value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,11 @@
|
||||||
using namespace CreatureLib::Library;
|
using namespace CreatureLib::Library;
|
||||||
|
|
||||||
TEST_CASE("Set Variant") {
|
TEST_CASE("Set Variant") {
|
||||||
auto defaultVariant = new SpeciesVariant("default", 0, 0, 0, {0, 1}, StatisticSet<u16>(), {}, {}, nullptr);
|
auto defaultVariant =
|
||||||
|
new SpeciesVariant("default", 0, 0, 0, {0, 1}, StatisticSet<u16>(), {}, {}, new LearnableAttacks(0));
|
||||||
auto c = CreatureSpecies(0, "foo", defaultVariant, 0, "", 0);
|
auto c = CreatureSpecies(0, "foo", defaultVariant, 0, "", 0);
|
||||||
auto secondVariant = new SpeciesVariant("second", 0, 0, 0, {0, 1}, StatisticSet<u16>(), {}, {}, nullptr);
|
auto secondVariant =
|
||||||
|
new SpeciesVariant("second", 0, 0, 0, {0, 1}, StatisticSet<u16>(), {}, {}, new LearnableAttacks(0));
|
||||||
c.SetVariant("second"_cnc, secondVariant);
|
c.SetVariant("second"_cnc, secondVariant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue