Update to latest Arbutils, use new integer defines

This commit is contained in:
2022-03-23 13:56:45 +01:00
parent 52127f6555
commit 3cc19de61f
102 changed files with 687 additions and 742 deletions

View File

@@ -62,7 +62,7 @@ void Battle::CheckChoicesSetAndRun() {
EnsureNotNull(choice)
if (choice->GetKind() == TurnChoiceKind::Attack) {
auto attack = std::static_pointer_cast<AttackTurnChoice>(choice);
uint8_t uses = 1;
u8 uses = 1;
// HOOK: change number of uses needed.
if (attack->GetAttack()->GetRemainingUses() < uses) {
choice = std::shared_ptr<BaseTurnChoice>(_library->GetMiscLibrary()->ReplacementAttack(
@@ -110,19 +110,19 @@ bool Battle::CreatureInField(ArbUt::BorrowedPtr<Creature> creature) const {
return std::any_of(_sides.begin(), _sides.end(), [creature](auto c) { return c->CreatureOnSide(creature); });
}
void Battle::ForceRecall(uint8_t side, uint8_t index) { _sides[side]->SetCreature(nullptr, index); }
void Battle::ForceRecall(u8 side, u8 index) { _sides[side]->SetCreature(nullptr, index); }
size_t Battle::ScriptCount() const { return 1; }
void Battle::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) { GetOwnScripts(scripts); }
void Battle::GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) { scripts.Append(ScriptWrapper::FromSet(&_volatile)); }
void Battle::SwitchCreature(uint8_t sideIndex, uint8_t index, Creature* c) {
void Battle::SwitchCreature(u8 sideIndex, u8 index, Creature* c) {
auto side = this->_sides[sideIndex];
side->SetCreature(c, index);
}
bool Battle::CanSlotBeFilled(uint8_t side, uint8_t index) const {
bool Battle::CanSlotBeFilled(u8 side, u8 index) const {
for (const auto& party : _parties) {
if (party->IsResponsibleForIndex(side, index)) {
if (party->HasCreaturesNotInField())
@@ -137,8 +137,8 @@ void Battle::ValidateBattleState() {
return;
}
bool survivingSideExists = false;
uint8_t winningSide = 255;
for (uint8_t i = 0; i < _sides.Count(); i++) {
u8 winningSide = 255;
for (u8 i = 0; i < _sides.Count(); i++) {
auto side = _sides[i];
if (side->HasFled()) {
this->_battleResult = BattleResult::Inconclusive();
@@ -200,8 +200,8 @@ Battle* Battle::Clone() const {
continue;
}
auto partyIndex = party->GetParty()->GetParty().IndexOf(creature.GetValue());
if (partyIndex != -1U) {
auto c = battle->_parties.At(j)->GetParty()->GetParty()[partyIndex];
if (partyIndex.has_value()) {
auto c = battle->_parties.At(j)->GetParty()->GetParty()[partyIndex.value()];
battle->_sides.At(i)->SetCreature(c, creatureIndex);
j = _parties.Count();
break;

View File

@@ -18,8 +18,8 @@ namespace CreatureLib::Battling {
ArbUt::BorrowedPtr<const BattleLibrary> _library;
ArbUt::UniquePtrList<BattleParty> _parties;
bool _canFlee;
uint8_t _numberOfSides;
uint8_t _creaturesPerSide;
u8 _numberOfSides;
u8 _creaturesPerSide;
ArbUt::UniquePtrList<BattleSide> _sides;
BattleRandom _random;
std::unique_ptr<ChoiceQueue> _currentTurnQueue = nullptr;
@@ -28,14 +28,14 @@ namespace CreatureLib::Battling {
EventHook _eventHook;
ArbUt::UniquePtr<HistoryHolder> _historyHolder = new HistoryHolder([this]() { return GetCurrentTurn(); });
uint32_t _currentTurn = 0;
u32 _currentTurn = 0;
ScriptSet _volatile;
long _lastTurnTime;
public:
Battle(const BattleLibrary* library, ArbUt::List<BattleParty*> parties, bool canFlee = true,
uint8_t numberOfSides = 2, uint8_t creaturesPerSide = 1,
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())
.count())
@@ -51,8 +51,8 @@ namespace CreatureLib::Battling {
virtual ~Battle() { ClearBattle(); }
[[nodiscard]] const ArbUt::BorrowedPtr<const BattleLibrary>& GetLibrary() const noexcept;
[[nodiscard]] uint32_t GetCurrentTurn() const noexcept { return _currentTurn; }
inline uint8_t GetCreaturesPerSide() const noexcept { return _creaturesPerSide; }
[[nodiscard]] u32 GetCurrentTurn() const noexcept { return _currentTurn; }
inline u8 GetCreaturesPerSide() const noexcept { return _creaturesPerSide; }
virtual bool CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice);
virtual bool TrySetChoice(BaseTurnChoice* choice);
@@ -69,13 +69,13 @@ namespace CreatureLib::Battling {
const ArbUt::OptionalBorrowedPtr<Creature>& GetCreature(const CreatureIndex& target) const {
return _sides[target.GetSideIndex()]->GetCreature(target.GetCreatureIndex());
}
const ArbUt::OptionalBorrowedPtr<Creature>& GetCreature(uint8_t side, uint8_t target) const {
const ArbUt::OptionalBorrowedPtr<Creature>& GetCreature(u8 side, u8 target) const {
return _sides[side]->GetCreature(target);
}
void ForceRecall(uint8_t side, uint8_t index);
void SwitchCreature(uint8_t side, uint8_t index, Creature* c);
bool CanSlotBeFilled(uint8_t side, uint8_t index) const;
void ForceRecall(u8 side, u8 index);
void SwitchCreature(u8 side, u8 index, Creature* c);
bool CanSlotBeFilled(u8 side, u8 index) const;
size_t ScriptCount() const override;
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
@@ -93,16 +93,16 @@ namespace CreatureLib::Battling {
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(const ArbUt::StringView& key) const {
return _volatile.Get(key);
}
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(uint32_t keyHash) const noexcept {
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(u32 keyHash) const noexcept {
return _volatile.Get(keyHash);
}
BattleScript* AddVolatileScript(const ArbUt::StringView& key);
BattleScript* AddVolatileScript(BattleScript* script);
void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
void RemoveVolatileScript(uint32_t keyHash) { _volatile.Remove(keyHash); }
void RemoveVolatileScript(u32 keyHash) { _volatile.Remove(keyHash); }
void RemoveVolatileScript(BattleScript* script);
bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
bool HasVolatileScript(uint32_t keyHash) const { return _volatile.Has(keyHash); }
bool HasVolatileScript(u32 keyHash) const { return _volatile.Has(keyHash); }
void DisplayText(const ArbUt::StringView& text);

View File

@@ -22,7 +22,7 @@ namespace CreatureLib::Battling {
return _responsibleIndices.Contains(index);
}
inline bool IsResponsibleForIndex(uint8_t side, uint8_t index) const {
inline bool IsResponsibleForIndex(u8 side, u8 index) const {
return std::any_of(_responsibleIndices.begin(), _responsibleIndices.end(),
[side, index](const CreatureIndex& ci) {
return ci.GetSideIndex() == side && ci.GetCreatureIndex() == index;

View File

@@ -16,9 +16,9 @@ namespace CreatureLib::Battling {
explicit BattleRandom(uint_fast32_t seed) noexcept : _random(seed) {}
bool EffectChance(float chance, ExecutingAttack* attack, Creature* target);
int32_t Get() noexcept { return _random.Get(); }
int32_t Get(int32_t max) noexcept { return _random.Get(max); }
int32_t Get(int32_t min, int32_t max) noexcept { return _random.Get(min, max); }
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); }
ArbUt::Random& GetRNG() noexcept { return _random; }
uint_fast32_t GetSeed() const noexcept { return _random.GetSeed(); }
};

View File

@@ -4,20 +4,20 @@
namespace CreatureLib::Battling {
class BattleResult {
bool _conclusiveResult;
uint8_t _winningSide;
u8 _winningSide;
BattleResult(bool conclusiveResult, uint8_t winningSide)
BattleResult(bool conclusiveResult, u8 winningSide)
: _conclusiveResult(conclusiveResult), _winningSide(winningSide) {}
public:
static BattleResult Inconclusive() { return BattleResult(false, 0); }
static BattleResult Conclusive(uint8_t winner) { return BattleResult(true, winner); }
static BattleResult Conclusive(u8 winner) { return BattleResult(true, winner); }
static BattleResult Empty() { return BattleResult(false, 0); }
/// Whether or not the battle has ended with a conclusive result.
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 noexcept { return _winningSide; }
u8 GetWinningSide() const noexcept { return _winningSide; }
};
}

View File

@@ -25,7 +25,7 @@ bool BattleSide::AllPossibleSlotsFilled() const {
void BattleSide::ResetChoices() noexcept {
_choicesSet = 0;
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
for (u8 i = 0; i < _creaturesPerSide; i++) {
_choices[i] = nullptr;
}
}
@@ -50,7 +50,7 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) {
THROW("User not found");
}
void BattleSide::SetCreature(ArbUt::OptionalBorrowedPtr<Creature> creature, uint8_t index) {
void BattleSide::SetCreature(ArbUt::OptionalBorrowedPtr<Creature> creature, u8 index) {
auto old = _creatures[index];
if (old.HasValue()) {
HOOK(OnRemove, old.GetValue());
@@ -82,7 +82,7 @@ bool BattleSide::CreatureOnSide(const ArbUt::BorrowedPtr<Creature>& creature) co
return std::find(_creatures.begin(), _creatures.end(), creature.GetRaw()) != _creatures.end();
}
const ArbUt::OptionalBorrowedPtr<Creature>& BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; }
const ArbUt::OptionalBorrowedPtr<Creature>& BattleSide::GetCreature(u8 index) const { return _creatures[index]; }
void BattleSide::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) {
GetOwnScripts(scripts);
@@ -93,7 +93,7 @@ void BattleSide::GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) {
}
size_t BattleSide::ScriptCount() const { return _battle->ScriptCount() + 1; }
uint8_t BattleSide::GetRandomCreatureIndex() {
u8 BattleSide::GetRandomCreatureIndex() {
// TODO: Consider adding parameter to only get index for available creatures.
return _battle->GetRandom()->Get(_creaturesPerSide);
}

View File

@@ -6,18 +6,18 @@
namespace CreatureLib::Battling {
class BattleSide : public ScriptSource {
uint8_t _index;
uint8_t _creaturesPerSide;
u8 _index;
u8 _creaturesPerSide;
ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>> _creatures;
ArbUt::List<std::shared_ptr<BaseTurnChoice>> _choices;
ArbUt::List<bool> _fillableSlots;
uint8_t _choicesSet = 0;
u8 _choicesSet = 0;
ScriptSet _volatile;
ArbUt::BorrowedPtr<Battle> _battle;
bool _hasFled = false;
public:
BattleSide(uint8_t index, ArbUt::BorrowedPtr<Battle> battle, uint8_t creaturesPerSide) noexcept
BattleSide(u8 index, ArbUt::BorrowedPtr<Battle> battle, u8 creaturesPerSide) noexcept
: _index(index), _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide),
_choices(creaturesPerSide), _fillableSlots(creaturesPerSide), _battle(battle) {
for (size_t i = 0; i < creaturesPerSide; i++) {
@@ -42,10 +42,10 @@ namespace CreatureLib::Battling {
void SetChoice(BaseTurnChoice* choice);
void ResetChoices() noexcept;
void ForceClearCreature(uint8_t index) { _creatures[index] = {}; }
void SetCreature(ArbUt::OptionalBorrowedPtr<Creature> creature, uint8_t index);
void ForceClearCreature(u8 index) { _creatures[index] = {}; }
void SetCreature(ArbUt::OptionalBorrowedPtr<Creature> creature, u8 index);
const ArbUt::OptionalBorrowedPtr<Creature>& GetCreature(uint8_t index) const;
const ArbUt::OptionalBorrowedPtr<Creature>& GetCreature(u8 index) const;
bool CreatureOnSide(const ArbUt::BorrowedPtr<Creature>& creature) const;
size_t ScriptCount() const override;
@@ -56,8 +56,8 @@ namespace CreatureLib::Battling {
const ArbUt::OptionalBorrowedPtr<Creature>& GetCreature(u8 index) { return _creatures[index]; }
uint8_t GetSideIndex() noexcept { return _index; }
uint8_t GetCreatureIndex(const ArbUt::BorrowedPtr<Creature>& c) {
u8 GetSideIndex() noexcept { return _index; }
u8 GetCreatureIndex(const ArbUt::BorrowedPtr<Creature>& c) {
for (size_t i = 0; i < _creatures.Count(); i++) {
if (!_creatures[i].HasValue())
continue;
@@ -68,7 +68,7 @@ namespace CreatureLib::Battling {
}
void MarkSlotAsUnfillable(const ArbUt::BorrowedPtr<Creature>& creature) noexcept {
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
for (u8 i = 0; i < _creaturesPerSide; i++) {
if (!_creatures[i].HasValue())
continue;
if (_creatures[i].GetValue() == creature) {
@@ -90,7 +90,7 @@ namespace CreatureLib::Battling {
void MarkAsFled() noexcept { _hasFled = true; }
uint8_t GetRandomCreatureIndex();
u8 GetRandomCreatureIndex();
bool SwapPositions(u8 a, u8 b);
@@ -99,16 +99,16 @@ namespace CreatureLib::Battling {
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(const ArbUt::StringView& key) const {
return _volatile.Get(key);
}
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(uint32_t keyHash) const noexcept {
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(u32 keyHash) const noexcept {
return _volatile.Get(keyHash);
}
BattleScript* AddVolatileScript(const ArbUt::StringView& key);
BattleScript* AddVolatileScript(BattleScript* script);
void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
void RemoveVolatileScript(uint32_t keyHash) { _volatile.Remove(keyHash); }
void RemoveVolatileScript(u32 keyHash) { _volatile.Remove(keyHash); }
void RemoveVolatileScript(BattleScript* script);
bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
bool HasVolatileScript(uint32_t keyHash) const { return _volatile.Has(keyHash); }
bool HasVolatileScript(u32 keyHash) const { return _volatile.Has(keyHash); }
};
}

View File

@@ -10,18 +10,18 @@ namespace CreatureLib::Battling {
ArbUt::BorrowedPtr<const BattleLibrary> _library;
ArbUt::StringView _species;
ArbUt::StringView _variant = "default"_cnc;
uint8_t _level;
u8 _level;
std::optional<std::string> _nickname = "";
ArbUt::StringView _talent = ""_cnc;
Library::Gender _gender = static_cast<Library::Gender>(-1);
uint8_t _coloring = 0;
u8 _coloring = 0;
ArbUt::StringView _heldItem = ""_cnc;
uint32_t _identifier = 0;
u32 _identifier = 0;
ArbUt::List<std::tuple<ArbUt::BorrowedPtr<const Library::AttackData>, AttackLearnMethod>> _attacks;
public:
CreateCreature(ArbUt::BorrowedPtr<const BattleLibrary> library, const ArbUt::StringView& species, uint8_t level)
CreateCreature(ArbUt::BorrowedPtr<const BattleLibrary> library, const ArbUt::StringView& species, u8 level)
: _library(library), _species(species), _level(level),
_attacks(library->GetSettings()->GetMaximalAttacks()) {}

View File

@@ -12,7 +12,7 @@ namespace CreatureLib::Battling {
Creature::Creature(const ArbUt::BorrowedPtr<const BattleLibrary>& library,
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, level_int_t level,
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
u32 experience, u32 uid, Library::Gender gender, u8 coloring,
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, std::optional<std::string> nickname,
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
bool allowedExperienceGain)
@@ -91,8 +91,8 @@ namespace CreatureLib::Battling {
// We modify the health of the creature by the change in its max health.
auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health);
RecalculateFlatStats();
int32_t diffHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health) - prevHealth;
if (_currentHealth < static_cast<uint32_t>(INT32_MAX) && static_cast<int32_t>(_currentHealth) < -diffHealth) {
i32 diffHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health) - prevHealth;
if (_currentHealth < static_cast<u32>(INT32_MAX) && static_cast<i32>(_currentHealth) < -diffHealth) {
_currentHealth = 0;
} else {
_currentHealth += diffHealth;
@@ -105,7 +105,7 @@ namespace CreatureLib::Battling {
}
}
void Creature::ChangeLevelBy(int8_t amount) {
void Creature::ChangeLevelBy(i8 amount) {
auto level = _level + amount;
if (level > _library->GetSettings()->GetMaximalLevel())
level = _library->GetSettings()->GetMaximalLevel();
@@ -149,7 +149,7 @@ namespace CreatureLib::Battling {
}
}
bool Creature::ChangeStatBoost(Library::Statistic stat, int8_t diffAmount, bool selfInflicted) {
bool Creature::ChangeStatBoost(Library::Statistic stat, i8 diffAmount, bool selfInflicted) {
bool preventStatChange = false;
HOOK(PreventStatBoostChange, this, this, stat, diffAmount, selfInflicted, &preventStatChange);
if (preventStatChange) {
@@ -218,7 +218,7 @@ namespace CreatureLib::Battling {
}
}
void Creature::Damage(uint32_t damage, DamageSource source) {
void Creature::Damage(u32 damage, DamageSource source) {
if (damage > _currentHealth) {
damage = _currentHealth;
}
@@ -238,7 +238,7 @@ namespace CreatureLib::Battling {
}
}
void Creature::Heal(uint32_t amount, bool canRevive) {
void Creature::Heal(u32 amount, bool canRevive) {
if (_currentHealth == 0 && !canRevive) {
return;
}
@@ -271,9 +271,9 @@ namespace CreatureLib::Battling {
_overridenTalent = _library->GetStaticLib()->GetTalentLibrary()->Get(talent);
}
const std::vector<uint8_t>& Creature::GetTypes() const noexcept { return _types; }
const std::vector<u8>& Creature::GetTypes() const noexcept { return _types; }
bool Creature::HasType(uint8_t type) const noexcept {
bool Creature::HasType(u8 type) const noexcept {
return std::find(_types.begin(), _types.end(), type) != _types.end();
}
@@ -307,7 +307,7 @@ namespace CreatureLib::Battling {
}
void Creature::ClearVolatileScripts() { _volatile.Clear(); }
void Creature::AddExperience(uint32_t amount) {
void Creature::AddExperience(u32 amount) {
auto maxLevel = _library->GetSettings()->GetMaximalLevel();
if (_level >= maxLevel) {
return;
@@ -347,7 +347,7 @@ namespace CreatureLib::Battling {
_heldItem = v.value();
}
}
void Creature::SetHeldItem(uint32_t itemNameHash) {
void Creature::SetHeldItem(u32 itemNameHash) {
if (itemNameHash == ArbUt::StringView::CalculateHash("")) {
_heldItem = {};
_heldItemTriggerScript = {};
@@ -415,8 +415,8 @@ namespace CreatureLib::Battling {
}
THROW("Can't add attack. The creature already has the maximum amount of attacks.");
}
uint8_t Creature::GetAvailableAttackSlot() const noexcept {
for (uint8_t i = 0; i < (uint8_t)_attacks.Count(); i++) {
u8 Creature::GetAvailableAttackSlot() const noexcept {
for (u8 i = 0; i < (u8)_attacks.Count(); i++) {
if (_attacks[i] == nullptr) {
return i;
}

View File

@@ -29,19 +29,19 @@ namespace CreatureLib::Battling {
ArbUt::OptionalBorrowedPtr<const Library::SpeciesVariant> _displayVariant = nullptr;
level_int_t _level;
uint32_t _experience;
uint32_t _uniqueIdentifier;
u32 _experience;
u32 _uniqueIdentifier;
Library::Gender _gender;
uint8_t _coloring;
u8 _coloring;
uint32_t _currentHealth = -1;
u32 _currentHealth = -1;
f32 _weight;
f32 _height;
Library::ClampedStatisticSet<int8_t, -6, 6> _statBoost;
Library::StatisticSet<uint32_t> _flatStats;
Library::StatisticSet<uint32_t> _boostedStats;
Library::ClampedStatisticSet<i8, -6, 6> _statBoost;
Library::StatisticSet<u32> _flatStats;
Library::StatisticSet<u32> _boostedStats;
struct BattleData {
bool OnBattleField = false;
@@ -75,11 +75,10 @@ namespace CreatureLib::Battling {
public:
Creature(const ArbUt::BorrowedPtr<const BattleLibrary>& library,
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, level_int_t level,
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, std::optional<std::string> nickname,
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
bool allowedExperienceGain = true);
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, level_int_t level, u32 experience,
u32 uid, Library::Gender gender, u8 coloring, ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem,
std::optional<std::string> nickname, const Library::TalentIndex& talent,
const std::vector<LearnedAttack*>& attacks, bool allowedExperienceGain = true);
virtual ~Creature();
@@ -98,23 +97,23 @@ namespace CreatureLib::Battling {
virtual void ChangeVariant(const ArbUt::StringView& variantName);
virtual void ChangeVariant(const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant);
inline level_int_t GetLevel() const noexcept { return _level; }
inline uint32_t GetExperience() const noexcept { return _experience; }
inline uint32_t GetUniqueIdentifier() const noexcept { return _uniqueIdentifier; }
inline u32 GetExperience() const noexcept { return _experience; }
inline u32 GetUniqueIdentifier() const noexcept { return _uniqueIdentifier; }
inline Library::Gender GetGender() const noexcept { return _gender; }
inline uint8_t GetColoring() const noexcept { return _coloring; }
inline u8 GetColoring() const noexcept { return _coloring; }
inline bool HasHeldItem(const ArbUt::BasicStringView& name) const noexcept {
return _heldItem.HasValue() && _heldItem.GetValue()->GetName() == name;
}
inline bool HasHeldItem(uint32_t nameHash) const noexcept {
inline bool HasHeldItem(u32 nameHash) const noexcept {
return _heldItem.HasValue() && _heldItem.GetValue()->GetName() == nameHash;
}
inline const ArbUt::OptionalBorrowedPtr<const Library::Item>& GetHeldItem() const noexcept { return _heldItem; }
void SetHeldItem(const ArbUt::BasicStringView& itemName);
void SetHeldItem(uint32_t itemNameHash);
void SetHeldItem(u32 itemNameHash);
inline void SetHeldItem(const ArbUt::BorrowedPtr<const Library::Item>& item) noexcept { _heldItem = item; };
bool ConsumeHeldItem();
inline uint32_t GetCurrentHealth() const noexcept { return _currentHealth; }
inline u32 GetCurrentHealth() const noexcept { return _currentHealth; }
inline f32 GetWeight() const noexcept { return _weight; }
inline void SetWeight(f32 weight) noexcept {
@@ -154,17 +153,17 @@ namespace CreatureLib::Battling {
/// Are we allowed to use this creature in a battle?
[[nodiscard]] virtual bool IsUsable() const noexcept;
[[nodiscard]] bool IsFainted() const noexcept;
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const noexcept;
[[nodiscard]] bool HasType(uint8_t type) const noexcept;
[[nodiscard]] const std::vector<u8>& GetTypes() const noexcept;
[[nodiscard]] bool HasType(u8 type) const noexcept;
void SetType(u8 index, u8 type) noexcept;
uint32_t GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); }
void ChangeLevelBy(int8_t amount);
void Damage(uint32_t damage, DamageSource source);
void Heal(uint32_t amount, bool canRevive = false);
u32 GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); }
void ChangeLevelBy(i8 amount);
void Damage(u32 damage, DamageSource source);
void Heal(u32 amount, bool canRevive = false);
void RestoreAllAttackUses() noexcept;
void OverrideActiveTalent(const ArbUt::StringView& talent);
void AddExperience(uint32_t amount);
void AddExperience(u32 amount);
void MarkOpponentAsSeen(ArbUt::BorrowedPtr<Creature> creature) { _battleData.SeenOpponents.insert(creature); }
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& GetSeenOpponents() const {
@@ -205,7 +204,7 @@ namespace CreatureLib::Battling {
inline bool AllowedExperienceGain() const noexcept { return _allowedExperienceGain; }
inline void SetAllowedExperienceGain(bool allowed) noexcept { _allowedExperienceGain = allowed; }
uint8_t GetAvailableAttackSlot() const noexcept;
u8 GetAvailableAttackSlot() const noexcept;
void AddAttack(LearnedAttack* attack);
void ReplaceAttack(size_t index, LearnedAttack* attack);
void SwapAttacks(size_t a, size_t b) { _attacks.Swap(a, b); }
@@ -220,15 +219,11 @@ namespace CreatureLib::Battling {
// region Stat APIs
bool ChangeStatBoost(Library::Statistic stat, int8_t diffAmount, bool selfInflicted = false);
[[nodiscard]] inline uint32_t GetFlatStat(Library::Statistic stat) const { return _flatStats.GetStat(stat); }
[[nodiscard]] inline uint32_t GetBoostedStat(Library::Statistic stat) const {
return _boostedStats.GetStat(stat);
}
[[nodiscard]] inline uint32_t GetBaseStat(Library::Statistic stat) const {
return _variant->GetStatistic(stat);
}
[[nodiscard]] inline int8_t GetStatBoost(Library::Statistic stat) const { return _statBoost.GetStat(stat); }
bool ChangeStatBoost(Library::Statistic stat, i8 diffAmount, bool selfInflicted = false);
[[nodiscard]] inline u32 GetFlatStat(Library::Statistic stat) const { return _flatStats.GetStat(stat); }
[[nodiscard]] inline u32 GetBoostedStat(Library::Statistic stat) const { return _boostedStats.GetStat(stat); }
[[nodiscard]] inline u32 GetBaseStat(Library::Statistic stat) const { return _variant->GetStatistic(stat); }
[[nodiscard]] inline i8 GetStatBoost(Library::Statistic stat) const { return _statBoost.GetStat(stat); }
void RecalculateFlatStats();
void RecalculateBoostedStats();
void RecalculateFlatStat(Library::Statistic);

View File

@@ -9,11 +9,11 @@ namespace CreatureLib::Battling {
public:
CreatureIndex() noexcept : _side(0), _creature(0) {}
CreatureIndex(uint8_t side, u8 creature) noexcept : _side(side), _creature(creature) {}
CreatureIndex(u8 side, u8 creature) noexcept : _side(side), _creature(creature) {}
uint8_t GetSideIndex() const noexcept { return _side; }
u8 GetSideIndex() const noexcept { return _side; }
uint8_t GetCreatureIndex() const noexcept { return _creature; }
u8 GetCreatureIndex() const noexcept { return _creature; }
bool operator==(const CreatureIndex& rhs) const noexcept {
return (_side == rhs._side) && (_creature == rhs._creature);

View File

@@ -48,7 +48,7 @@ namespace CreatureLib::Battling {
size_t GetLength() const noexcept { return _party.Count(); }
void PackParty() {
int32_t firstNil = -1;
i32 firstNil = -1;
for (size_t i = 0; i < _party.Count(); i++) {
if (_party[i] == nullptr) {
if (firstNil == -1) {

View File

@@ -2,7 +2,7 @@
#define CREATURELIB_DAMAGESOURCE_HPP
namespace CreatureLib::Battling {
ENUM(DamageSource, uint8_t, AttackDamage, Misc);
ENUM(DamageSource, u8, AttackDamage, Misc);
}
#endif // CREATURELIB_DAMAGESOURCE_HPP

View File

@@ -8,32 +8,32 @@ namespace CreatureLib::Battling {
public:
class HitData {
bool _critical = false;
uint8_t _basePower = 0;
u8 _basePower = 0;
float _effectiveness = 1;
uint32_t _damage = 0;
uint8_t _type = 0;
u32 _damage = 0;
u8 _type = 0;
bool _hasFailed = false;
public:
HitData() noexcept {}
[[nodiscard]] inline bool IsCritical() const noexcept { return _critical; }
[[nodiscard]] inline uint8_t GetBasePower() const noexcept { return _basePower; }
[[nodiscard]] inline u8 GetBasePower() const noexcept { return _basePower; }
[[nodiscard]] inline float GetEffectiveness() const noexcept { return _effectiveness; }
[[nodiscard]] inline uint32_t GetDamage() const noexcept { return _damage; }
[[nodiscard]] inline uint8_t GetType() const noexcept { return _type; }
[[nodiscard]] inline u32 GetDamage() const noexcept { return _damage; }
[[nodiscard]] inline u8 GetType() const noexcept { return _type; }
[[nodiscard]] inline bool HasFailed() const noexcept { return _hasFailed; }
inline void SetCritical(bool value) noexcept { _critical = value; }
inline void SetBasePower(uint8_t value) noexcept { _basePower = value; }
inline void SetBasePower(u8 value) noexcept { _basePower = value; }
inline void SetEffectiveness(float value) noexcept { _effectiveness = value; }
inline void SetDamage(uint32_t value) noexcept { _damage = value; }
inline void SetType(uint8_t value) noexcept { _type = value; }
inline void SetDamage(u32 value) noexcept { _damage = value; }
inline void SetType(u8 value) noexcept { _type = value; }
inline void Fail() noexcept { _hasFailed = true; }
};
private:
uint8_t _numberHits;
u8 _numberHits;
std::unique_ptr<HitData[]> _hits;
ArbUt::BorrowedPtr<Creature> _user;
ArbUt::BorrowedPtr<LearnedAttack> _attack;
@@ -42,7 +42,7 @@ namespace CreatureLib::Battling {
ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>> _targets;
public:
ExecutingAttack(const ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>>& targets, uint8_t numberHits,
ExecutingAttack(const ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>>& targets, u8 numberHits,
ArbUt::BorrowedPtr<Creature> user, const ArbUt::BorrowedPtr<LearnedAttack>& attack,
const ArbUt::BorrowedPtr<const Library::AttackData>& useAttack,
const std::unique_ptr<BattleScript>& script)
@@ -56,8 +56,8 @@ namespace CreatureLib::Battling {
virtual ~ExecutingAttack() noexcept = default;
HitData& GetHitData(ArbUt::BorrowedPtr<Creature> creature, uint8_t hit) {
for (uint8_t i = 0; i < _targets.Count(); i++) {
HitData& GetHitData(ArbUt::BorrowedPtr<Creature> creature, u8 hit) {
for (u8 i = 0; i < _targets.Count(); i++) {
if (!_targets[i].HasValue()) {
continue;
}
@@ -69,7 +69,7 @@ namespace CreatureLib::Battling {
}
HitData* GetTargetIteratorBegin(ArbUt::BorrowedPtr<Creature> creature) {
for (uint8_t i = 0; i < _targets.Count(); i++) {
for (u8 i = 0; i < _targets.Count(); i++) {
if (!_targets[i].HasValue()) {
continue;
}
@@ -81,7 +81,7 @@ namespace CreatureLib::Battling {
}
bool IsCreatureTarget(ArbUt::BorrowedPtr<Creature> creature) noexcept {
for (uint8_t i = 0; i < _targets.Count(); i++) {
for (u8 i = 0; i < _targets.Count(); i++) {
if (!_targets[i].HasValue()) {
continue;
}
@@ -92,10 +92,10 @@ namespace CreatureLib::Battling {
return false;
}
inline uint8_t GetTargetCount() const noexcept { return _targets.Count(); }
inline u8 GetTargetCount() const noexcept { return _targets.Count(); }
inline const ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>>& GetTargets() const noexcept { return _targets; }
inline uint8_t GetNumberOfHits() const noexcept { return _numberHits; }
inline u8 GetNumberOfHits() const noexcept { return _numberHits; }
inline const ArbUt::BorrowedPtr<Creature>& GetUser() noexcept { return _user; }

View File

@@ -1,8 +1,7 @@
#include "LearnedAttack.hpp"
CreatureLib::Battling::LearnedAttack::LearnedAttack(
const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack, uint8_t maxUses,
AttackLearnMethod learnMethod)
const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack, u8 maxUses, AttackLearnMethod learnMethod)
: _attack(attack), _maxUses(maxUses), _remainingUses(maxUses), _learnMethod(learnMethod) {}
CreatureLib::Battling::LearnedAttack::LearnedAttack(
@@ -14,23 +13,23 @@ CreatureLib::Battling::LearnedAttack::GetAttack() const noexcept {
return _attack;
}
uint8_t CreatureLib::Battling::LearnedAttack::GetMaxUses() const noexcept { return _maxUses; }
u8 CreatureLib::Battling::LearnedAttack::GetMaxUses() const noexcept { return _maxUses; }
uint8_t CreatureLib::Battling::LearnedAttack::GetRemainingUses() const noexcept { return _remainingUses; }
u8 CreatureLib::Battling::LearnedAttack::GetRemainingUses() const noexcept { return _remainingUses; }
CreatureLib::Battling::AttackLearnMethod CreatureLib::Battling::LearnedAttack::GetLearnMethod() const noexcept {
return _learnMethod;
}
bool CreatureLib::Battling::LearnedAttack::TryUse(uint8_t uses) noexcept {
bool CreatureLib::Battling::LearnedAttack::TryUse(u8 uses) noexcept {
if (uses > _remainingUses)
return false;
_remainingUses -= uses;
return true;
}
void CreatureLib::Battling::LearnedAttack::DecreaseUses(uint8_t amount) noexcept { _remainingUses -= amount; }
void CreatureLib::Battling::LearnedAttack::DecreaseUses(u8 amount) noexcept { _remainingUses -= amount; }
void CreatureLib::Battling::LearnedAttack::RestoreUses(uint8_t amount) noexcept { _remainingUses += amount; }
void CreatureLib::Battling::LearnedAttack::RestoreUses(u8 amount) noexcept { _remainingUses += amount; }
void CreatureLib::Battling::LearnedAttack::RestoreAllUses() noexcept { _remainingUses = _maxUses; }

View File

@@ -8,12 +8,12 @@
namespace CreatureLib::Battling {
class LearnedAttack {
ArbUt::BorrowedPtr<const Library::AttackData> _attack;
uint8_t _maxUses;
uint8_t _remainingUses;
u8 _maxUses;
u8 _remainingUses;
AttackLearnMethod _learnMethod;
public:
LearnedAttack(const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack, uint8_t maxUses,
LearnedAttack(const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack, u8 maxUses,
AttackLearnMethod learnMethod);
LearnedAttack(const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack,
AttackLearnMethod learnMethod);
@@ -21,13 +21,13 @@ namespace CreatureLib::Battling {
virtual ~LearnedAttack() = default;
const ArbUt::BorrowedPtr<const Library::AttackData>& GetAttack() const noexcept;
uint8_t GetMaxUses() const noexcept;
uint8_t GetRemainingUses() const noexcept;
u8 GetMaxUses() const noexcept;
u8 GetRemainingUses() const noexcept;
AttackLearnMethod GetLearnMethod() const noexcept;
virtual bool TryUse(uint8_t uses) noexcept;
virtual void DecreaseUses(uint8_t amount) noexcept;
virtual void RestoreUses(uint8_t amount) noexcept;
virtual bool TryUse(u8 uses) noexcept;
virtual void DecreaseUses(u8 amount) noexcept;
virtual void RestoreUses(u8 amount) noexcept;
virtual void RestoreAllUses() noexcept;
virtual LearnedAttack* Clone() const {