Rework for C Interfaces to handle exceptions a bit better.
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:
@@ -7,7 +7,7 @@
|
||||
using namespace CreatureLib;
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
const BattleLibrary* Battle::GetLibrary() const { return _library; }
|
||||
const BattleLibrary* Battle::GetLibrary() const noexcept { return _library; }
|
||||
|
||||
bool Battle::CanUse(const BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice)
|
||||
@@ -69,9 +69,9 @@ void Battle::CheckChoicesSetAndRun() {
|
||||
}
|
||||
}
|
||||
|
||||
ChoiceQueue* Battle::GetCurrentTurnQueue() const { return _currentTurnQueue; }
|
||||
ChoiceQueue* Battle::GetCurrentTurnQueue() const noexcept { return _currentTurnQueue; }
|
||||
|
||||
BattleRandom* Battle::GetRandom() { return &_random; }
|
||||
BattleRandom* Battle::GetRandom() noexcept { return &_random; }
|
||||
|
||||
bool Battle::CreatureInField(const Creature* creature) const {
|
||||
AssertNotNull(creature)
|
||||
@@ -87,7 +87,6 @@ void Battle::ForceRecall(uint8_t side, uint8_t index) { _sides[side]->SetCreatur
|
||||
void Battle::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) { scripts.Append(&_volatile); }
|
||||
|
||||
void Battle::SwitchCreature(uint8_t sideIndex, uint8_t index, Creature* c) {
|
||||
AssertNotNull(c)
|
||||
auto side = this->_sides[sideIndex];
|
||||
side->SetCreature(c, index);
|
||||
}
|
||||
|
||||
@@ -57,18 +57,18 @@ namespace CreatureLib::Battling {
|
||||
delete _currentTurnQueue;
|
||||
}
|
||||
|
||||
[[nodiscard]] const BattleLibrary* GetLibrary() const;
|
||||
[[nodiscard]] const BattleLibrary* GetLibrary() const noexcept;
|
||||
[[nodiscard]] uint32_t GetCurrentTurn() const noexcept { return _currentTurn; }
|
||||
|
||||
virtual bool CanUse(const BaseTurnChoice* choice);
|
||||
virtual bool TrySetChoice(BaseTurnChoice* choice);
|
||||
|
||||
bool CanFlee() const { return _canFlee; }
|
||||
bool CanFlee() const noexcept { return _canFlee; }
|
||||
|
||||
void CheckChoicesSetAndRun();
|
||||
|
||||
[[nodiscard]] ChoiceQueue* GetCurrentTurnQueue() const;
|
||||
BattleRandom* GetRandom();
|
||||
[[nodiscard]] ChoiceQueue* GetCurrentTurnQueue() const noexcept;
|
||||
BattleRandom* GetRandom() noexcept;
|
||||
|
||||
bool CreatureInField(const Creature* creature) const;
|
||||
|
||||
@@ -84,12 +84,12 @@ namespace CreatureLib::Battling {
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
||||
|
||||
void ValidateBattleState();
|
||||
inline bool HasEnded() const { return _hasEnded; }
|
||||
inline const BattleResult& GetResult() const { return _battleResult; }
|
||||
inline bool HasEnded() const noexcept { return _hasEnded; }
|
||||
inline const BattleResult& GetResult() const noexcept { return _battleResult; }
|
||||
|
||||
const List<BattleSide*>& GetSides() const { return _sides; }
|
||||
const List<BattleSide*>& GetSides() const noexcept { return _sides; }
|
||||
Script* GetVolatileScript(const ConstString& key) const { return _volatile.Get(key); }
|
||||
Script* GetVolatileScript(uint32_t keyHash) const { return _volatile.Get(keyHash); }
|
||||
Script* GetVolatileScript(uint32_t keyHash) const noexcept { return _volatile.Get(keyHash); }
|
||||
void AddVolatileScript(const ConstString& key);
|
||||
void AddVolatileScript(Script* script);
|
||||
void RemoveVolatileScript(const ConstString& name) { _volatile.Remove(name); }
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace CreatureLib::Battling {
|
||||
static BattleResult Empty() { return BattleResult(false, 0); }
|
||||
|
||||
/// Whether or not the battle has ended with a conclusive result.
|
||||
bool IsConclusiveResult() const { return _conclusiveResult; }
|
||||
bool IsConclusiveResult() const noexcept { return _conclusiveResult; }
|
||||
/// Get the index of the side that has won the battle. Only valid if the battle has a conclusive result.
|
||||
uint8_t GetWinningSide() const { return _winningSide; }
|
||||
uint8_t GetWinningSide() const noexcept { return _winningSide; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -39,14 +39,15 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) {
|
||||
}
|
||||
|
||||
void BattleSide::SetCreature(Creature* creature, uint8_t index) {
|
||||
AssertNotNull(creature)
|
||||
auto old = _creatures[index];
|
||||
if (old != nullptr) {
|
||||
old->SetOnBattleField(false);
|
||||
}
|
||||
_creatures[index] = creature;
|
||||
creature->SetBattleData(_battle, this);
|
||||
creature->SetOnBattleField(true);
|
||||
if (creature != nullptr) {
|
||||
creature->SetBattleData(_battle, this);
|
||||
creature->SetOnBattleField(true);
|
||||
}
|
||||
if (_battle == nullptr)
|
||||
return;
|
||||
for (auto side : _battle->GetSides()) {
|
||||
|
||||
@@ -24,7 +24,12 @@ Battling::Creature::Creature(const BattleLibrary* library, const Library::Creatu
|
||||
}
|
||||
|
||||
void Battling::Creature::ChangeLevelBy(int8_t amount) {
|
||||
this->_level += amount;
|
||||
auto level = _level + amount;
|
||||
if (level > _library->GetSettings()->GetMaximalLevel())
|
||||
level = _library->GetSettings()->GetMaximalLevel();
|
||||
if (level < 1)
|
||||
level = 1;
|
||||
_level = level;
|
||||
_experience = _library->GetGrowthRateLibrary()->CalculateExperience(_species->GetGrowthRate(), _level);
|
||||
RecalculateFlatStats();
|
||||
}
|
||||
@@ -52,13 +57,17 @@ void Battling::Creature::ChangeStatBoost(Library::Statistic stat, int8_t diffAmo
|
||||
this->RecalculateBoostedStat(stat);
|
||||
}
|
||||
|
||||
uint32_t Battling::Creature::GetFlatStat(Library::Statistic stat) const { return _flatStats.GetStat(stat); }
|
||||
uint32_t Battling::Creature::GetFlatStat(Library::Statistic stat) const noexcept { return _flatStats.GetStat(stat); }
|
||||
|
||||
uint32_t Battling::Creature::GetBoostedStat(Library::Statistic stat) const { return _boostedStats.GetStat(stat); }
|
||||
uint32_t Battling::Creature::GetBoostedStat(Library::Statistic stat) const noexcept {
|
||||
return _boostedStats.GetStat(stat);
|
||||
}
|
||||
|
||||
uint32_t Battling::Creature::GetBaseStat(Library::Statistic stat) const { return _variant->GetStatistic(stat); }
|
||||
uint32_t Battling::Creature::GetBaseStat(Library::Statistic stat) const noexcept {
|
||||
return _variant->GetStatistic(stat);
|
||||
}
|
||||
|
||||
int8_t Battling::Creature::GetStatBoost(Library::Statistic stat) const { return _statBoost.GetStat(stat); }
|
||||
int8_t Battling::Creature::GetStatBoost(Library::Statistic stat) const noexcept { return _statBoost.GetStat(stat); }
|
||||
|
||||
void Battling::Creature::RecalculateFlatStats() {
|
||||
auto statCalc = this->_library->GetStatCalculator();
|
||||
@@ -174,13 +183,13 @@ void Battling::Creature::AddExperience(uint32_t amount) {
|
||||
_experience = exp;
|
||||
_level = level;
|
||||
}
|
||||
const Library::CreatureSpecies* Battling::Creature::GetDisplaySpecies() const {
|
||||
const Library::CreatureSpecies* Battling::Creature::GetDisplaySpecies() const noexcept {
|
||||
auto species = _displaySpecies;
|
||||
if (species == nullptr)
|
||||
species = _species;
|
||||
return species;
|
||||
}
|
||||
const Library::SpeciesVariant* Battling::Creature::GetDisplayVariant() const {
|
||||
const Library::SpeciesVariant* Battling::Creature::GetDisplayVariant() const noexcept {
|
||||
auto variant = _displayVariant;
|
||||
if (variant == nullptr)
|
||||
variant = _variant;
|
||||
|
||||
@@ -129,21 +129,21 @@ namespace CreatureLib::Battling {
|
||||
void RemoveVolatileScript(Script* script);
|
||||
bool HasVolatileScript(const ConstString& name) const;
|
||||
|
||||
List<LearnedAttack*>& GetAttacks() { return _attacks; }
|
||||
List<LearnedAttack*>& GetAttacks() noexcept { return _attacks; }
|
||||
|
||||
const Library::CreatureSpecies* GetDisplaySpecies() const;
|
||||
const Library::SpeciesVariant* GetDisplayVariant() const;
|
||||
const Library::CreatureSpecies* GetDisplaySpecies() const noexcept;
|
||||
const Library::SpeciesVariant* GetDisplayVariant() const noexcept;
|
||||
|
||||
const void SetDisplaySpecies(const Library::CreatureSpecies* species) { _displaySpecies = species; }
|
||||
const void SetDisplayVariant(const Library::SpeciesVariant* variant) { _displayVariant = variant; };
|
||||
const void SetDisplaySpecies(const Library::CreatureSpecies* species) noexcept { _displaySpecies = species; }
|
||||
const void SetDisplayVariant(const Library::SpeciesVariant* variant) noexcept { _displayVariant = variant; };
|
||||
|
||||
// region Stat APIs
|
||||
|
||||
void ChangeStatBoost(Library::Statistic stat, int8_t diffAmount);
|
||||
[[nodiscard]] uint32_t GetFlatStat(Library::Statistic stat) const;
|
||||
[[nodiscard]] uint32_t GetBoostedStat(Library::Statistic stat) const;
|
||||
[[nodiscard]] uint32_t GetBaseStat(Library::Statistic stat) const;
|
||||
[[nodiscard]] int8_t GetStatBoost(Library::Statistic stat) const;
|
||||
[[nodiscard]] uint32_t GetFlatStat(Library::Statistic stat) const noexcept;
|
||||
[[nodiscard]] uint32_t GetBoostedStat(Library::Statistic stat) const noexcept;
|
||||
[[nodiscard]] uint32_t GetBaseStat(Library::Statistic stat) const noexcept;
|
||||
[[nodiscard]] int8_t GetStatBoost(Library::Statistic stat) const noexcept;
|
||||
void RecalculateFlatStats();
|
||||
void RecalculateBoostedStats();
|
||||
void RecalculateFlatStat(Library::Statistic);
|
||||
|
||||
@@ -10,16 +10,18 @@ namespace CreatureLib::Battling {
|
||||
uint8_t _creature;
|
||||
|
||||
public:
|
||||
CreatureIndex() : _side(0), _creature(0) {}
|
||||
CreatureIndex(uint8_t side, uint8_t creature) : _side(side), _creature(creature) {}
|
||||
CreatureIndex() noexcept : _side(0), _creature(0) {}
|
||||
CreatureIndex(uint8_t side, uint8_t creature) noexcept : _side(side), _creature(creature) {}
|
||||
|
||||
uint8_t GetSideIndex() const { return _side; }
|
||||
uint8_t GetSideIndex() const noexcept { return _side; }
|
||||
|
||||
uint8_t GetCreatureIndex() const { return _creature; }
|
||||
uint8_t GetCreatureIndex() const noexcept { return _creature; }
|
||||
|
||||
bool operator==(const CreatureIndex& rhs) const { return (_side == rhs._side) && (_creature == rhs._creature); }
|
||||
bool operator==(const CreatureIndex& rhs) const noexcept {
|
||||
return (_side == rhs._side) && (_creature == rhs._creature);
|
||||
}
|
||||
|
||||
bool operator!=(const CreatureIndex& rhs) const { return !operator==(rhs); }
|
||||
bool operator!=(const CreatureIndex& rhs) const noexcept { return !operator==(rhs); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,25 +9,25 @@ namespace CreatureLib::Battling {
|
||||
Arbutils::Collections::List<Creature*> _party;
|
||||
|
||||
public:
|
||||
CreatureParty(size_t size) : _party(size) {}
|
||||
CreatureParty(Arbutils::Collections::List<Creature*> party) : _party(party) {}
|
||||
CreatureParty(std::initializer_list<Creature*> party) : _party(party) {}
|
||||
CreatureParty(size_t size) noexcept : _party(size) {}
|
||||
CreatureParty(Arbutils::Collections::List<Creature*> party) noexcept : _party(party) {}
|
||||
CreatureParty(std::initializer_list<Creature*> party) noexcept : _party(party) {}
|
||||
|
||||
virtual ~CreatureParty() {
|
||||
virtual ~CreatureParty() noexcept {
|
||||
for (auto c : _party) {
|
||||
delete c;
|
||||
}
|
||||
}
|
||||
|
||||
Creature* GetAtIndex(size_t index) const { return _party[index]; }
|
||||
Creature* GetAtIndex(size_t index) const noexcept { return _party[index]; }
|
||||
|
||||
void Switch(size_t a, size_t b) {
|
||||
void Switch(size_t a, size_t b) noexcept {
|
||||
auto ca = _party[a];
|
||||
_party[a] = _party[b];
|
||||
_party[b] = ca;
|
||||
}
|
||||
|
||||
bool HasAvailableCreatures() const {
|
||||
bool HasAvailableCreatures() const noexcept {
|
||||
for (Creature* c : _party) {
|
||||
if (c == nullptr)
|
||||
continue;
|
||||
@@ -38,10 +38,10 @@ namespace CreatureLib::Battling {
|
||||
return false;
|
||||
}
|
||||
|
||||
Arbutils::Collections::List<Creature*>& GetParty() { return _party; }
|
||||
const Arbutils::Collections::List<Creature*>& GetParty() const { return _party; }
|
||||
Arbutils::Collections::List<Creature*>& GetParty() noexcept { return _party; }
|
||||
const Arbutils::Collections::List<Creature*>& GetParty() const noexcept { return _party; }
|
||||
|
||||
size_t GetLength() const { return _party.Count(); }
|
||||
size_t GetLength() const noexcept { return _party.Count(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user