Add nullability to large parts of the codebase
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-03-23 18:30:35 +01:00
parent beb2e44a0b
commit eccf2c9121
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
53 changed files with 240 additions and 206 deletions

View File

@ -15,13 +15,13 @@ namespace CreatureLib::Battling {
/// for it.
class EventHook {
public:
typedef std::function<void(const CreatureLib::Battling::EventData*)> EventHookFunc;
typedef std::function<void(const CreatureLib::Battling::EventData* non_null)> EventHookFunc;
private:
std::vector<EventHookFunc> _listeners;
size_t _offset;
size_t _capacity;
u8* _memory = nullptr;
u8* nullable _memory = nullptr;
static constexpr size_t initialSize = 2048;
static constexpr size_t stepSize = 1024;

View File

@ -1,6 +1,6 @@
#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)
// Find which index the creature choice is at.
size_t choiceIndex = SIZE_MAX;

View File

@ -21,7 +21,7 @@ namespace CreatureLib::Battling {
const std::vector<std::shared_ptr<BaseTurnChoice>>& GetInnerQueue() { return _queue; }
bool MoveCreatureChoiceNext(Creature* creature);
bool MoveCreatureChoiceNext(Creature* non_null creature);
};
}

View File

@ -19,7 +19,7 @@ namespace CreatureLib::Battling {
}
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;
auto turn = _getTurnNumber();
while (c.HasValue()) {

View File

@ -11,7 +11,7 @@ concept HistoryElementType = std::is_base_of<CreatureLib::Battling::HistoryEleme
namespace CreatureLib::Battling {
class HistoryHolder {
HistoryElement* _top = nullptr;
HistoryElement* nullable _top = nullptr;
std::function<u32()> _getTurnNumber;
public:
@ -33,7 +33,7 @@ namespace CreatureLib::Battling {
GetLastUsedAttack(u32 maxDepth = 0) const noexcept;
[[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>
GetLastDamageOnTarget(const ArbUt::BorrowedPtr<const Creature>& creature, u32 maxDepth = 0) const noexcept;

View File

@ -2,9 +2,10 @@
using namespace CreatureLib::Battling;
BattleLibrary::BattleLibrary(const CreatureLib::Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator,
DamageLibrary* damageLibrary, ExperienceLibrary* experienceLibrary,
ScriptResolver* scriptResolver, MiscLibrary* miscLibrary)
BattleLibrary::BattleLibrary(const CreatureLib::Library::DataLibrary* non_null staticLib,
BattleStatCalculator* non_null statCalculator, DamageLibrary* non_null damageLibrary,
ExperienceLibrary* non_null experienceLibrary, ScriptResolver* non_null scriptResolver,
MiscLibrary* non_null miscLibrary)
: _staticLib(staticLib), _statCalculator(statCalculator), _damageLibrary(damageLibrary),
_experienceLibrary(experienceLibrary), _scriptResolver(scriptResolver), _miscLibrary(miscLibrary) {
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; }
BattleScript* BattleLibrary::LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
const ArbUt::StringView& scriptName) const {
BattleScript* nullable BattleLibrary::LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
const ArbUt::StringView& scriptName) const {
return _scriptResolver->LoadScript(owner, category, scriptName);
}

View File

@ -19,9 +19,9 @@ namespace CreatureLib::Battling {
std::unique_ptr<const MiscLibrary> _miscLibrary = nullptr;
public:
BattleLibrary(const Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator,
DamageLibrary* damageLibrary, ExperienceLibrary* experienceLibrary,
ScriptResolver* scriptResolver, MiscLibrary* miscLibrary);
BattleLibrary(const Library::DataLibrary* non_null staticLib, BattleStatCalculator* non_null statCalculator,
DamageLibrary* non_null damageLibrary, ExperienceLibrary* non_null experienceLibrary,
ScriptResolver* non_null scriptResolver, MiscLibrary* non_null miscLibrary);
~BattleLibrary() = default;
inline const std::unique_ptr<const Library::DataLibrary>& GetStaticLib() const noexcept { return _staticLib; }
@ -44,8 +44,9 @@ namespace CreatureLib::Battling {
return _scriptResolver;
}
[[nodiscard]] BattleScript* LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
const ArbUt::StringView& scriptName) const;
[[nodiscard]] BattleScript* nullable LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner,
ScriptCategory category,
const ArbUt::StringView& scriptName) const;
};
}

View File

@ -3,7 +3,8 @@
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),
CalculateFlatStat(creature, Library::Statistic::PhysicalAttack),
CalculateFlatStat(creature, Library::Statistic::PhysicalDefense),
@ -12,7 +13,8 @@ Library::StatisticSet<u32> Battling::BattleStatCalculator::CalculateFlatStats(Ba
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),
CalculateBoostedStat(creature, Library::Statistic::PhysicalAttack),
CalculateBoostedStat(creature, Library::Statistic::PhysicalDefense),
@ -21,26 +23,29 @@ Library::StatisticSet<u32> Battling::BattleStatCalculator::CalculateBoostedStats
CalculateBoostedStat(creature, Library::Statistic::Speed));
}
u32 CalculateHealthStat(Battling::Creature* creature) {
u32 CalculateHealthStat(Battling::Creature* non_null creature) {
EnsureNotNull(creature)
auto level = creature->GetLevel();
float a = (creature->GetBaseStat(Library::Statistic::Health)) * 2.0 * level;
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)
auto level = creature->GetLevel();
float a = (creature->GetBaseStat(stat)) * 2.0 * level;
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)
return CalculateHealthStat(creature);
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));
}

View File

@ -11,10 +11,10 @@ namespace CreatureLib::Battling {
public:
virtual ~BattleStatCalculator() = default;
virtual Library::StatisticSet<u32> CalculateFlatStats(Creature* creature) const;
virtual Library::StatisticSet<u32> CalculateBoostedStats(Creature* creature) const;
virtual u32 CalculateFlatStat(Creature* creature, Library::Statistic stat) const;
virtual u32 CalculateBoostedStat(Creature* creature, Library::Statistic stat) const;
virtual Library::StatisticSet<u32> CalculateFlatStats(Creature* non_null creature) const;
virtual Library::StatisticSet<u32> CalculateBoostedStats(Creature* non_null creature) const;
virtual u32 CalculateFlatStat(Creature* non_null creature, Library::Statistic stat) const;
virtual u32 CalculateBoostedStat(Creature* non_null creature, Library::Statistic stat) const;
};
}

View File

@ -2,7 +2,7 @@
#include "../ScriptHandling/ScriptMacros.hpp"
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 {
EnsureNotNull(attack)
EnsureNotNull(target)
@ -17,7 +17,7 @@ u32 DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, u8 hitIn
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 {
EnsureNotNull(attack)
EnsureNotNull(target)
@ -26,7 +26,7 @@ u8 DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, u8 hit
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 {
EnsureNotNull(attack)
EnsureNotNull(target)
@ -65,7 +65,7 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
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 {
EnsureNotNull(attack)
EnsureNotNull(target)

View File

@ -8,14 +8,14 @@ namespace CreatureLib::Battling {
class DamageLibrary {
public:
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;
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;
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;
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;
};
}

View File

@ -2,7 +2,7 @@
#include "../Models/Creature.hpp"
void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
CreatureLib::Battling::Creature* faintedMon,
CreatureLib::Battling::Creature* non_null faintedMon,
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const {
for (const auto& opponent : opponents) {
if (opponent->IsFainted())

View File

@ -11,7 +11,7 @@ namespace CreatureLib::Battling {
public:
virtual ~ExperienceLibrary() = default;
virtual void HandleExperienceGain(Creature* faintedMon,
virtual void HandleExperienceGain(Creature* non_null faintedMon,
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const;
};
}

View File

@ -2,16 +2,16 @@
#include "../Models/Battle.hpp"
#include "../TurnChoices/AttackTurnChoice.hpp"
bool CreatureLib::Battling::MiscLibrary::IsCritical([[maybe_unused]] CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target,
[[maybe_unused]] u8 hit) const {
bool CreatureLib::Battling::MiscLibrary::IsCritical(
[[maybe_unused]] CreatureLib::Battling::ExecutingAttack* non_null attack,
CreatureLib::Battling::Creature* non_null target, [[maybe_unused]] u8 hit) const {
EnsureNotNull(target)
Ensure(target->GetBattle().HasValue())
auto rand = target->GetBattle().GetValue()->GetRandom();
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 ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> GetReplacementAttackData() {
@ -24,7 +24,7 @@ static ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> GetReplacement
return _replacementAttackData;
}
static CreatureLib::Battling::LearnedAttack* GetReplacementAttack() {
static CreatureLib::Battling::LearnedAttack* non_null GetReplacementAttack() {
if (_replacementAttack == nullptr) {
_replacementAttack = new CreatureLib::Battling::LearnedAttack(
GetReplacementAttackData(), CreatureLib::Battling::AttackLearnMethod::Unknown);
@ -32,9 +32,12 @@ static CreatureLib::Battling::LearnedAttack* GetReplacementAttack() {
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::MiscLibrary::ReplacementAttack(Creature* user, [[maybe_unused]] CreatureIndex target) const {
CreatureLib::Battling::MiscLibrary::ReplacementAttack(Creature* non_null user,
[[maybe_unused]] CreatureIndex target) const {
EnsureNotNull(user)
Ensure(user->GetBattleSide().HasValue())
auto sideTarget = 0;

View File

@ -9,9 +9,9 @@ namespace CreatureLib::Battling {
class MiscLibrary {
public:
virtual ~MiscLibrary() = default;
virtual bool IsCritical(ExecutingAttack* attack, Creature* target, u8 hit) const;
virtual bool CanFlee(FleeTurnChoice* switchChoice) const;
virtual BaseTurnChoice* ReplacementAttack(Creature* user, CreatureIndex target) const;
virtual bool IsCritical(ExecutingAttack* non_null attack, Creature* non_null target, u8 hit) const;
virtual bool CanFlee(FleeTurnChoice* non_null switchChoice) const;
virtual BaseTurnChoice* non_null ReplacementAttack(Creature* non_null user, CreatureIndex target) const;
};
}

View File

@ -2,7 +2,7 @@
#define CREATURELIB_ATTACKLEARNMETHOD_HPP
namespace CreatureLib::Battling {
enum class AttackLearnMethod { Unknown, Level };
ENUM(AttackLearnMethod, u8, Unknown, Level);
}
#endif // CREATURELIB_ATTACKLEARNMETHOD_HPP

View File

@ -24,7 +24,7 @@ bool Battle::CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice) {
return true;
}
bool Battle::TrySetChoice(BaseTurnChoice* choice) {
bool Battle::TrySetChoice(BaseTurnChoice* non_null choice) {
EnsureNotNull(choice)
if (!CanUse(choice)) {
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::SwitchCreature(u8 sideIndex, u8 index, Creature* c) {
void Battle::SwitchCreature(u8 sideIndex, u8 index, Creature* nullable c) {
auto side = this->_sides[sideIndex];
side->SetCreature(c, index);
}

View File

@ -34,7 +34,7 @@ namespace CreatureLib::Battling {
long _lastTurnTime;
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,
uint_fast32_t randomSeed = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
@ -55,14 +55,14 @@ namespace CreatureLib::Battling {
inline u8 GetCreaturesPerSide() const noexcept { return _creaturesPerSide; }
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; }
void CheckChoicesSetAndRun();
[[nodiscard]] ArbUt::BorrowedPtr<ChoiceQueue> GetCurrentTurnQueue() const noexcept;
BattleRandom* GetRandom() noexcept;
BattleRandom* non_null GetRandom() noexcept;
bool CreatureInField(ArbUt::BorrowedPtr<Creature> creature) const;
@ -74,7 +74,7 @@ namespace CreatureLib::Battling {
}
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;
size_t ScriptCount() const override;
@ -96,11 +96,11 @@ namespace CreatureLib::Battling {
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(u32 keyHash) const noexcept {
return _volatile.Get(keyHash);
}
BattleScript* AddVolatileScript(const ArbUt::StringView& key);
BattleScript* AddVolatileScript(BattleScript* script);
BattleScript* non_null AddVolatileScript(const ArbUt::StringView& key);
BattleScript* non_null AddVolatileScript(BattleScript* non_null script);
void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
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(u32 keyHash) const { return _volatile.Has(keyHash); }
@ -117,7 +117,7 @@ namespace CreatureLib::Battling {
try_creature(this->_historyHolder->Register<T>(this->GetCurrentTurn(), args...);
, "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; }
@ -136,7 +136,7 @@ namespace CreatureLib::Battling {
}
}
virtual Battle* Clone() const;
virtual Battle* non_null Clone() const;
};
}

View File

@ -10,7 +10,7 @@ namespace CreatureLib::Battling {
ArbUt::List<CreatureIndex> _responsibleIndices;
public:
BattleParty(CreatureParty* party, const ArbUt::List<CreatureIndex>& responsibleIndices)
BattleParty(CreatureParty* non_null party, const ArbUt::List<CreatureIndex>& responsibleIndices)
: _party(party), _responsibleIndices(responsibleIndices) {}
virtual ~BattleParty() = default;
@ -43,7 +43,7 @@ namespace CreatureLib::Battling {
return false;
}
virtual BattleParty* Clone() const { return new BattleParty(_party->Clone(), _responsibleIndices); }
virtual BattleParty* non_null Clone() const { return new BattleParty(_party->Clone(), _responsibleIndices); }
};
}

View File

@ -3,7 +3,10 @@
#include "Creature.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(ModifyIncomingEffectChance, target, attack, target, &chance);
chance /= 100;

View File

@ -15,7 +15,7 @@ namespace CreatureLib::Battling {
BattleRandom() noexcept : _random() {}
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(i32 max) noexcept { return _random.Get(max); }
i32 Get(i32 min, i32 max) noexcept { return _random.Get(min, max); }

View File

@ -39,7 +39,7 @@ namespace CreatureLib::Battling {
[[nodiscard]] bool AllPossibleSlotsFilled() const;
void SetChoice(BaseTurnChoice* choice);
void SetChoice(BaseTurnChoice* non_null choice);
void ResetChoices() noexcept;
void ForceClearCreature(u8 index) { _creatures[index] = {}; }
@ -94,7 +94,7 @@ namespace CreatureLib::Battling {
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 {
return _volatile.Get(key);
@ -102,11 +102,11 @@ namespace CreatureLib::Battling {
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(u32 keyHash) const noexcept {
return _volatile.Get(keyHash);
}
BattleScript* AddVolatileScript(const ArbUt::StringView& key);
BattleScript* AddVolatileScript(BattleScript* script);
BattleScript* non_null AddVolatileScript(const ArbUt::StringView& key);
BattleScript* non_null AddVolatileScript(BattleScript* non_null script);
void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
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(u32 keyHash) const { return _volatile.Has(keyHash); }
};

View File

@ -174,10 +174,10 @@ namespace CreatureLib::Battling {
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override;
void ClearVolatileScripts();
BattleScript* AddVolatileScript(const ArbUt::StringView& name);
BattleScript* AddVolatileScript(BattleScript* script);
BattleScript* non_null AddVolatileScript(const ArbUt::StringView& name);
BattleScript* non_null AddVolatileScript(BattleScript* non_null script);
void RemoveVolatileScript(const ArbUt::BasicStringView& name);
void RemoveVolatileScript(BattleScript* script);
void RemoveVolatileScript(BattleScript* non_null script);
bool HasVolatileScript(const ArbUt::BasicStringView& name) const;
const ArbUt::OptionalUniquePtrList<LearnedAttack>& GetAttacks() noexcept { return _attacks; }
@ -205,8 +205,8 @@ namespace CreatureLib::Battling {
inline void SetAllowedExperienceGain(bool allowed) noexcept { _allowedExperienceGain = allowed; }
u8 GetAvailableAttackSlot() const noexcept;
void AddAttack(LearnedAttack* attack);
void ReplaceAttack(size_t index, LearnedAttack* attack);
void AddAttack(LearnedAttack* non_null attack);
void ReplaceAttack(size_t index, LearnedAttack* non_null attack);
void SwapAttacks(size_t a, size_t b) { _attacks.Swap(a, b); }
void SetStatus(const ArbUt::StringView& name);
@ -231,7 +231,7 @@ namespace CreatureLib::Battling {
// endregion
virtual Creature* Clone() const;
virtual Creature* non_null Clone() const;
};
}

View File

@ -13,7 +13,7 @@ namespace CreatureLib::Battling {
_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) {}
virtual ~CreatureParty() = default;
@ -22,7 +22,7 @@ namespace CreatureLib::Battling {
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()) {
THROW("Index was out of bounds for party.")
}
@ -67,7 +67,7 @@ namespace CreatureLib::Battling {
return _party.Contains(creature);
}
virtual CreatureParty* Clone() const {
virtual CreatureParty* non_null Clone() const {
auto party = new CreatureParty(_party.Count());
auto i = 0;
for (auto c : _party) {

View File

@ -68,7 +68,7 @@ namespace CreatureLib::Battling {
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++) {
if (!_targets[i].HasValue()) {
continue;

View File

@ -36,7 +36,7 @@ namespace CreatureLib::Battling {
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 OnRemove(){};
@ -45,82 +45,89 @@ namespace CreatureLib::Battling {
#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){};
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 ChangePriority(_par_ AttackTurnChoice* choice, _par_ i8* priority){};
virtual void ChangeAttack(_par_ AttackTurnChoice* choice, _par_ ArbUt::StringView* outAttack){};
virtual void ModifyNumberOfHits(_par_ AttackTurnChoice* choice, _par_ u8* numberOfHits){};
virtual void PreventAttack(_par_ ExecutingAttack* attack, _par_ bool* outResult){};
virtual void FailAttack(_par_ ExecutingAttack* attack, _par_ bool* outFailed){};
virtual void StopBeforeAttack(_par_ ExecutingAttack* attack, _par_ bool* outResult){};
virtual void OnBeforeAttack(_par_ ExecutingAttack* attack){};
virtual void ChangeSpeed(_par_ BaseTurnChoice* non_null choice, _par_ u32* non_null speed){};
virtual void ChangePriority(_par_ AttackTurnChoice* non_null choice, _par_ i8* non_null priority){};
virtual void ChangeAttack(_par_ AttackTurnChoice* non_null choice,
_par_ ArbUt::StringView* non_null outAttack){};
virtual void ModifyNumberOfHits(_par_ AttackTurnChoice* non_null choice, _par_ u8* non_null numberOfHits){};
virtual void PreventAttack(_par_ ExecutingAttack* non_null attack, _par_ bool* non_null outResult){};
virtual void FailAttack(_par_ ExecutingAttack* non_null attack, _par_ bool* non_null outFailed){};
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 IsInvulnerable(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ bool* outResult){};
virtual void OnAttackMiss(_par_ ExecutingAttack* attack, _par_ Creature* target){};
virtual void ChangeAttackType(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber,
_par_ u8* outType){};
virtual void ChangeEffectiveness(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber,
_par_ float* effectiveness){};
virtual void BlockCritical(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber,
_par_ bool* blockCritical){};
virtual void FailIncomingAttack(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ bool* non_null outResult){};
virtual void IsInvulnerable(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ bool* non_null outResult){};
virtual void OnAttackMiss(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target){};
virtual void ChangeAttackType(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitNumber, _par_ u8* non_null outType){};
virtual void ChangeEffectiveness(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_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,
_par_ u8* basePower){};
virtual void ChangeDamageStatsUser(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ Creature** statsUser){};
virtual void OverrideBasePower(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitIndex, _par_ u8* non_null basePower){};
virtual void ChangeDamageStatsUser(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitIndex, _par_ Creature* non_null* non_null statsUser){};
virtual void BypassDefensiveStat(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ bool* bypass){};
virtual void BypassOffensiveStat(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ bool* bypass){};
virtual void ModifyStatModifier(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ float* modifier){};
virtual void ModifyDamageModifier(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ float* modifier){};
virtual void OverrideDamage(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ u32* damage){};
virtual void OverrideIncomingDamage(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ u32* damage){};
virtual void BypassDefensiveStat(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitIndex, _par_ bool* non_null bypass){};
virtual void BypassOffensiveStat(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitIndex, _par_ bool* non_null bypass){};
virtual void ModifyStatModifier(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitIndex, _par_ float* non_null modifier){};
virtual void ModifyDamageModifier(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitIndex, _par_ float* non_null modifier){};
virtual void OverrideDamage(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitIndex, _par_ u32* non_null damage){};
virtual void OverrideIncomingDamage(_par_ ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitIndex, _par_ u32* non_null damage){};
virtual void OnIncomingHit(_par_ const ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber){};
virtual void OnFaintingOpponent(_par_ const ExecutingAttack* attack, _par_ Creature* target,
virtual void OnIncomingHit(_par_ const ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitNumber){};
virtual void OnFaintingOpponent(_par_ const ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ u8 hitNumber){};
virtual void PreventStatBoostChange(_par_ Creature* target, _par_ Library::Statistic stat, _par_ i8 diffAmount,
_par_ bool selfInflicted, _par_ bool* prevent){};
virtual void ModifyStatBoostChange(_par_ Creature* target, _par_ Library::Statistic stat,
_par_ i8* diffAmount){};
virtual void PreventSecondaryEffects(_par_ const ExecutingAttack* attack, _par_ Creature* target,
_par_ u8 hitNumber, _par_ bool* outResult){};
virtual void OnSecondaryEffect(_par_ const ExecutingAttack* attack, _par_ Creature* target,
virtual void PreventStatBoostChange(_par_ Creature* non_null target, _par_ Library::Statistic stat,
_par_ i8 diffAmount, _par_ bool selfInflicted,
_par_ bool* non_null prevent){};
virtual void ModifyStatBoostChange(_par_ Creature* non_null target, _par_ Library::Statistic stat,
_par_ i8* non_null diffAmount){};
virtual void PreventSecondaryEffects(_par_ const ExecutingAttack* non_null attack,
_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){};
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 PreventOpponentSwitch(_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* non_null choice,
_par_ bool* non_null outResult){};
virtual void ModifyEffectChance(_par_ const ExecutingAttack* attack, _par_ Creature* target,
_par_ float* chance){};
virtual void ModifyIncomingEffectChance(_par_ const ExecutingAttack* attack, _par_ Creature* target,
_par_ float* chance){};
virtual void ModifyEffectChance(_par_ const ExecutingAttack* non_null attack, _par_ Creature* non_null target,
_par_ float* non_null chance){};
virtual void ModifyIncomingEffectChance(_par_ const ExecutingAttack* non_null attack,
_par_ Creature* non_null target, _par_ float* non_null chance){};
virtual void OnFail(_par_ Creature* target){};
virtual void OnOpponentFail(_par_ Creature* target){};
virtual void OnFail(_par_ Creature* non_null target){};
virtual void OnOpponentFail(_par_ Creature* non_null target){};
virtual void PreventRunAway(_par_ const FleeTurnChoice* choice, _par_ bool* result){};
virtual void PreventOpponentRunAway(_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* non_null choice, _par_ bool* non_null result){};
virtual void OnEndTurn(){};
virtual void OnDamage(Creature*, DamageSource, _par_ u32 oldHealth, _par_ u32 newHealth){};
virtual void OnFaint(Creature*, DamageSource){};
virtual void OnSwitchIn(Creature*){};
virtual void OnDamage(Creature* non_null, DamageSource, _par_ u32 oldHealth, _par_ u32 newHealth){};
virtual void OnFaint(Creature* non_null, DamageSource){};
virtual void OnSwitchIn(Creature* non_null){};
virtual void OnAfterHeldItemConsume(Creature*, const Library::Item*){};
virtual void OnAfterHeldItemConsume(Creature* non_null, const Library::Item* non_null){};
};
}

View File

@ -11,20 +11,23 @@ namespace CreatureLib::Battling {
public:
virtual ~ItemUseScript() = default;
virtual void
OnInitialize([[maybe_unused]] const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
virtual void OnInitialize(
[[maybe_unused]] const ArbUt::List<CreatureLib::Library::EffectParameter * non_null>& parameters){};
/// @brief Is the item an item we are able to use?
[[nodiscard]] virtual bool IsItemUsable() const { return false; }
/// @brief Do we need to use the item on a creature?
[[nodiscard]] virtual bool IsCreatureUseItem() const { return false; }
/// @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?
[[nodiscard]] virtual bool IsHoldable() const { return false; }
virtual void OnUse([[maybe_unused]] Battle* battle) const {}
virtual void OnCreatureUse([[maybe_unused]] Creature* creature, [[maybe_unused]] bool isBattle) const {}
virtual void OnUse([[maybe_unused]] Battle* non_null battle) const {}
virtual void OnCreatureUse([[maybe_unused]] Creature* non_null creature, [[maybe_unused]] bool isBattle) const {
}
};
}

View File

@ -17,14 +17,15 @@ namespace CreatureLib::Battling {
virtual ~ScriptResolver() = default;
virtual void Initialize([[maybe_unused]] BattleLibrary* library){};
virtual BattleScript* LoadScript([[maybe_unused]] const ArbUt::OptionalBorrowedPtr<void>& owner,
[[maybe_unused]] ScriptCategory category,
[[maybe_unused]] const ArbUt::StringView& scriptName) {
virtual void Initialize([[maybe_unused]] BattleLibrary* non_null library){};
virtual BattleScript* nullable LoadScript([[maybe_unused]] const ArbUt::OptionalBorrowedPtr<void>& owner,
[[maybe_unused]] ScriptCategory category,
[[maybe_unused]] const ArbUt::StringView& scriptName) {
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;
};
};

View File

@ -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());
if (v.has_value()) {
_scripts[v.value()]->Stack();

View File

@ -9,21 +9,23 @@ namespace CreatureLib::Battling {
bool _isSet;
union {
std::unique_ptr<BattleScript> const* _script;
const ScriptSet* _scriptSet;
std::unique_ptr<BattleScript> const* nullable _script;
const ScriptSet* nullable _scriptSet;
};
ScriptWrapper(std::unique_ptr<BattleScript>* s, bool isSet) : _isSet(isSet), _script(s){};
ScriptWrapper(ScriptSet* s, bool isSet) : _isSet(isSet), _scriptSet(s){};
ScriptWrapper(std::unique_ptr<BattleScript>* nullable s, bool isSet) : _isSet(isSet), _script(s){};
ScriptWrapper(ScriptSet* nullable s, bool isSet) : _isSet(isSet), _scriptSet(s){};
public:
static inline ScriptWrapper FromScript(std::unique_ptr<BattleScript>* s) { return ScriptWrapper(s, false); }
static inline ScriptWrapper FromSet(ScriptSet* s) { return ScriptWrapper(s, true); }
static inline ScriptWrapper FromScript(std::unique_ptr<BattleScript>* nullable s) {
return ScriptWrapper(s, false);
}
static inline ScriptWrapper FromSet(ScriptSet* nullable s) { return ScriptWrapper(s, true); }
inline bool IsSet() const noexcept { return _isSet; }
inline const std::unique_ptr<BattleScript>* GetScript() const noexcept { return _script; }
inline const ScriptSet* GetScriptSet() const noexcept { return _scriptSet; }
inline const std::unique_ptr<BattleScript>* nullable GetScript() const noexcept { return _script; }
inline const ScriptSet* nullable GetScriptSet() const noexcept { return _scriptSet; }
inline bool HasValue() const noexcept {
if (_isSet)

View File

@ -3,16 +3,16 @@
#include <Arbutils/Defines.hpp>
#if LEVEL_U8
using level_int_t = uint8_t;
using level_int_t = u8;
#elif LEVEL_U16
using level_int_t = uint16_t;
using level_int_t = u16;
#elif LEVEL_U32
using level_int_t = uint32_t;
using level_int_t = u32;
#elif LEVEL_U64
using level_int_t = uint64_t;
using level_int_t = u64;
#else
#warning Level size was not specified, falling back to uint8_t
using level_int_t = uint8_t;
using level_int_t = u8;
#endif
#endif // CREATURELIB_DEFINES_HPP

View File

@ -1 +0,0 @@
#include "AttackLibrary.hpp"

View File

@ -3,6 +3,6 @@
CreatureLib::Library::AttackData::AttackData(const ArbUt::StringView& name, u8 type,
CreatureLib::Library::AttackCategory category, u8 power, u8 accuracy,
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),
_target(target), _priority(priority), _effect(effect), _flags(std::move(flags)) {}

View File

@ -22,7 +22,8 @@ namespace CreatureLib::Library {
public:
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;
inline const ArbUt::StringView& GetName() const noexcept { return _name; }

View File

@ -10,12 +10,12 @@ namespace CreatureLib::Library {
private:
float _chance;
ArbUt::StringView _effectName;
ArbUt::List<EffectParameter*> _parameters;
ArbUt::List<EffectParameter * non_null> _parameters;
public:
SecondaryEffect() noexcept : _chance(0), _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) {}
~SecondaryEffect() noexcept {
@ -26,7 +26,7 @@ namespace CreatureLib::Library {
constexpr inline float GetChance() const noexcept { return _chance; }
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; }
};
}

View File

@ -1 +0,0 @@
#include "BaseLibrary.hpp"

View File

@ -18,12 +18,12 @@ namespace CreatureLib::Library {
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)
_values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)});
_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)
_values.GetStdMap().insert({hashedKey, std::unique_ptr<const T>(value)});
_listValues.Append(hashedKey);

View File

@ -14,7 +14,7 @@ struct CreatureSpecies::impl {
ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>> _variantsList;
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)
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
_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; }
void SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant) {
void SetVariant(const ArbUt::StringView& name, const SpeciesVariant* non_null variant) {
Ensure(!name.IsEmpty())
_variantsList.CreateBack(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); }
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);
}
const ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>>& CreatureSpecies::GetVariantsIterator() const {

View File

@ -23,8 +23,9 @@ namespace CreatureLib::Library {
/// @param captureRate The chance to capture the creature species, between 0 and 255. 255 means instant capture,
/// 0 means impossible to capture.
/// @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,
const ArbUt::StringView& growthRate, u8 captureRate, std::unordered_set<u32> flags = {});
CreatureSpecies(u16 id, const ArbUt::StringView& name, const SpeciesVariant* non_null defaultVariant,
float genderRatio, const ArbUt::StringView& growthRate, u8 captureRate,
std::unordered_set<u32> flags = {});
virtual ~CreatureSpecies();
@ -84,7 +85,7 @@ namespace CreatureLib::Library {
/// @brief Appends a variant to the species.
/// @param name The unique name of the new variant.
/// @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.
/// @return A list of variants of the species.

View File

@ -17,7 +17,7 @@ namespace CreatureLib::Library {
public:
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,
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)
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience),
_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<ArbUt::BorrowedPtr<const Talent>>& talents,
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,
flags)) {}
SpeciesVariant::~SpeciesVariant() = default;

View File

@ -31,7 +31,7 @@ namespace CreatureLib::Library {
const ArbUt::List<u8>& types, Library::StatisticSet<u16> baseStats,
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
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();
/// @brief Returns the unique name of the variant.

View File

@ -8,12 +8,15 @@
namespace CreatureLib::Library {
class Talent {
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)) {}
[[nodiscard]] inline const ArbUt::StringView& GetName() const noexcept { return _name; }
[[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 {
for (auto p : _parameters) {

View File

@ -1,10 +1,11 @@
#include "DataLibrary.hpp"
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
CreatureLib::Library::AttackLibrary* attacks,
CreatureLib::Library::ItemLibrary* items,
CreatureLib::Library::GrowthRateLibrary* growthRates,
TypeLibrary* typeLibrary, TalentLibrary* talentLibrary)
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* non_null settings,
CreatureLib::Library::SpeciesLibrary* non_null species,
CreatureLib::Library::AttackLibrary* non_null attacks,
CreatureLib::Library::ItemLibrary* non_null items,
CreatureLib::Library::GrowthRateLibrary* non_null growthRates,
TypeLibrary* typeLibrary, TalentLibrary* non_null talentLibrary)
: _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates),
_typeLibrary(typeLibrary), _talentLibrary(talentLibrary) {
EnsureNotNull(_settings)

View File

@ -24,10 +24,11 @@ namespace CreatureLib::Library {
std::unique_ptr<const TalentLibrary> _talentLibrary;
public:
DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items,
CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary,
TalentLibrary* talentLibrary);
DataLibrary(LibrarySettings* non_null settings, CreatureLib::Library::SpeciesLibrary* non_null species,
CreatureLib::Library::AttackLibrary* non_null attacks,
CreatureLib::Library::ItemLibrary* non_null items,
CreatureLib::Library::GrowthRateLibrary* non_null growthRates, TypeLibrary* non_null typeLibrary,
TalentLibrary* non_null talentLibrary);
virtual ~DataLibrary() {}

View File

@ -7,11 +7,12 @@
namespace CreatureLib::Library {
class ExternGrowthRate : public GrowthRate {
level_int_t (*_calcLevel)(u32 experience);
u32 (*_calcExperience)(level_int_t level);
level_int_t (*_calcLevel)(u32 experience) non_null;
u32 (*_calcExperience)(level_int_t level) non_null;
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) {
EnsureNotNull(calcLevel)
EnsureNotNull(calcExperience)

View File

@ -37,10 +37,12 @@ u32 CreatureLib::Library::GrowthRateLibrary::CalculateExperience(u32 hash, level
}
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)});
}
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)});
}

View File

@ -21,8 +21,8 @@ namespace CreatureLib::Library {
[[nodiscard]] u32 CalculateExperience(const ArbUt::BasicStringView& growthRate, level_int_t level) const;
[[nodiscard]] u32 CalculateExperience(u32 hash, level_int_t level) const;
void AddGrowthRate(u32 hash, GrowthRate* rate);
void AddGrowthRate(const ArbUt::StringView& name, GrowthRate* rate);
void AddGrowthRate(u32 hash, GrowthRate* non_null rate);
void AddGrowthRate(const ArbUt::StringView& name, GrowthRate* non_null rate);
};
}

View File

@ -1 +0,0 @@
#include "ItemLibrary.hpp"

View File

@ -13,7 +13,7 @@ namespace CreatureLib::Library {
public:
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
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _effect(effect),
_battleTriggerEffect(battleTriggerEffect), _flags(flags) {}

View File

@ -16,7 +16,7 @@ namespace CreatureLib::Library {
public:
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;
NO_COPY_OR_MOVE(Item)

View File

@ -1 +0,0 @@
#include "SpeciesLibrary.hpp"

View File

@ -12,11 +12,11 @@ namespace CreatureLib::Library {
public:
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);
_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);
_valuesById.Insert(value->GetId(), value);
}

View File

@ -6,9 +6,11 @@
using namespace CreatureLib::Library;
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 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);
}