Add nullability to large parts of the codebase
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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); }
|
||||
|
||||
@@ -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); }
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user