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

@@ -4,7 +4,7 @@
#include <Arbutils/Enum.hpp>
namespace CreatureLib::Battling {
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, Miss, DisplayText,
ENUM(EventDataKind, u8, Damage, Heal, Faint, Switch, TurnStart, TurnEnd, ExperienceGain, Miss, DisplayText,
ChangeSpecies, ChangeVariant, AttackUse, ChangeStatBoost, Fail, Swap, StatusChange)
}

View File

@@ -21,7 +21,7 @@ namespace CreatureLib::Battling {
std::vector<EventHookFunc> _listeners;
size_t _offset;
size_t _capacity;
uint8_t* _memory = nullptr;
u8* _memory = nullptr;
static constexpr size_t initialSize = 2048;
static constexpr size_t stepSize = 1024;
@@ -32,7 +32,7 @@ namespace CreatureLib::Battling {
if (ptr == nullptr) {
THROW("Out of memory.");
}
_memory = static_cast<uint8_t*>(ptr);
_memory = static_cast<u8*>(ptr);
}
EventHook(const EventHook&) = delete;
EventHook& operator=(const EventHook&) = delete;
@@ -52,9 +52,9 @@ namespace CreatureLib::Battling {
if (newPtr == nullptr) {
THROW("Out of memory.");
}
_memory = static_cast<uint8_t*>(newPtr);
_memory = static_cast<u8*>(newPtr);
}
uint8_t* ptr = _memory + _offset;
u8* ptr = _memory + _offset;
T* event = new (ptr) T(args...);
_offset += sizeof(T);
for (const auto& listener : _listeners) {

View File

@@ -7,19 +7,19 @@ namespace CreatureLib::Battling {
class ChangeStatBoostEvent final : public EventData {
const ArbUt::BorrowedPtr<Creature> _creature;
const CreatureLib::Library::Statistic _statistic;
const int8_t _oldValue;
const int8_t _newValue;
const i8 _oldValue;
const i8 _newValue;
public:
ChangeStatBoostEvent(const ArbUt::BorrowedPtr<Creature>& creature, CreatureLib::Library::Statistic statistic,
int8_t oldValue, int8_t newValue) noexcept
i8 oldValue, i8 newValue) noexcept
: _creature(creature), _statistic(statistic), _oldValue(oldValue), _newValue(newValue) {}
EventDataKind GetKind() const noexcept override { return EventDataKind ::ChangeStatBoost; }
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
CreatureLib::Library::Statistic GetStatistic() const noexcept { return _statistic; }
int8_t GetOldValue() const noexcept { return _oldValue; }
int8_t GetNewValue() const noexcept { return _newValue; }
i8 GetOldValue() const noexcept { return _oldValue; }
i8 GetNewValue() const noexcept { return _newValue; }
};
}

View File

@@ -6,17 +6,17 @@ namespace CreatureLib::Battling {
class DamageEvent final : public EventData {
ArbUt::BorrowedPtr<Creature> _creature;
DamageSource _damageSource;
uint32_t _originalHealth;
uint32_t _newHealth;
u32 _originalHealth;
u32 _newHealth;
public:
DamageEvent(Creature* c, DamageSource s, uint32_t oHealth, uint32_t newHealth) noexcept
DamageEvent(Creature* c, DamageSource s, u32 oHealth, u32 newHealth) noexcept
: _creature(c), _damageSource(s), _originalHealth(oHealth), _newHealth(newHealth) {}
EventDataKind GetKind() const noexcept override { return EventDataKind ::Damage; }
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
DamageSource GetDamageSource() const noexcept { return _damageSource; }
uint32_t GetOriginalHealth() const noexcept { return _originalHealth; }
uint32_t GetNewHealth() const noexcept { return _newHealth; }
u32 GetOriginalHealth() const noexcept { return _originalHealth; }
u32 GetNewHealth() const noexcept { return _newHealth; }
};
}

View File

@@ -5,16 +5,16 @@
namespace CreatureLib::Battling {
class ExperienceGainEvent final : public EventData {
ArbUt::BorrowedPtr<Creature> _creature;
uint32_t _previousExperience;
uint32_t _newExperience;
u32 _previousExperience;
u32 _newExperience;
public:
ExperienceGainEvent(const ArbUt::BorrowedPtr<Creature>& creature, uint32_t previousExp, uint32_t newExp)
ExperienceGainEvent(const ArbUt::BorrowedPtr<Creature>& creature, u32 previousExp, u32 newExp)
: _creature(creature), _previousExperience(previousExp), _newExperience(newExp) {}
EventDataKind GetKind() const noexcept override { return EventDataKind ::ExperienceGain; }
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
uint32_t GetPreviousExperience() const noexcept { return _previousExperience; }
uint32_t GetNewExperience() const noexcept { return _newExperience; }
u32 GetPreviousExperience() const noexcept { return _previousExperience; }
u32 GetNewExperience() const noexcept { return _newExperience; }
};
}

View File

@@ -5,16 +5,16 @@
namespace CreatureLib::Battling {
class HealEvent final : public EventData {
ArbUt::BorrowedPtr<Creature> _creature;
uint32_t _originalHealth;
uint32_t _newHealth;
u32 _originalHealth;
u32 _newHealth;
public:
HealEvent(ArbUt::BorrowedPtr<Creature> c, uint32_t oHealth, uint32_t newHealth) noexcept
HealEvent(ArbUt::BorrowedPtr<Creature> c, u32 oHealth, u32 newHealth) noexcept
: _creature(c), _originalHealth(oHealth), _newHealth(newHealth) {}
EventDataKind GetKind() const noexcept override { return EventDataKind ::Heal; }
const ArbUt::BorrowedPtr<Creature>& GetCreature() const noexcept { return _creature; }
uint32_t GetOriginalHealth() const noexcept { return _originalHealth; }
uint32_t GetNewHealth() const noexcept { return _newHealth; }
u32 GetOriginalHealth() const noexcept { return _originalHealth; }
u32 GetNewHealth() const noexcept { return _newHealth; }
};
}

View File

@@ -5,7 +5,7 @@ using namespace CreatureLib::Battling;
using TargetList = List<OptionalBorrowedPtr<Creature>>;
static inline constexpr uint8_t GetOppositeSide(uint8_t v) {
static inline constexpr u8 GetOppositeSide(u8 v) {
if (v == 1) {
return 0;
}

View File

@@ -150,7 +150,7 @@ void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>
}
HOOK(OnBeforeAttack, attack, attack);
for (uint8_t i = 0; i < attack->GetTargetCount(); i++) {
for (u8 i = 0; i < attack->GetTargetCount(); i++) {
auto target = attack->GetTargets()[i];
if (target.HasValue()) {
try_creature(HandleAttackForTarget(attack, target.GetValue()), "Exception occurred during handling attack "
@@ -200,7 +200,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
EnsureNotNull(miscLibrary)
auto* hitIterator = attack->GetTargetIteratorBegin(target);
for (uint8_t hitIndex = 0; hitIndex < numberOfHits; hitIndex++) {
for (u8 hitIndex = 0; hitIndex < numberOfHits; hitIndex++) {
if (battle.GetValue()->HasEnded()) {
return;
}
@@ -211,7 +211,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
break;
}
auto& hit = hitIterator[hitIndex];
uint8_t hitType = attackData->GetType();
u8 hitType = attackData->GetType();
HOOK(ChangeAttackType, target, attack, target.GetRaw(), hitIndex, &hitType);
hit.SetType(hitType);
auto effectiveness = typeLibrary->GetEffectiveness(hitType, target->GetTypes());

View File

@@ -3,5 +3,5 @@
#include <Arbutils/Enum.hpp>
#include <cstdint>
ENUM(HistoryElementKind, uint8_t, AttackUse, Damage)
ENUM(HistoryElementKind, u8, AttackUse, Damage)
#endif // CREATURELIB_HISTORYELEMENTKIND_HPP

View File

@@ -3,47 +3,44 @@
using namespace CreatureLib;
Library::StatisticSet<uint32_t> Battling::BattleStatCalculator::CalculateFlatStats(Battling::Creature* creature) const {
return Library::StatisticSet<uint32_t>(CalculateFlatStat(creature, Library::Statistic::Health),
CalculateFlatStat(creature, Library::Statistic::PhysicalAttack),
CalculateFlatStat(creature, Library::Statistic::PhysicalDefense),
CalculateFlatStat(creature, Library::Statistic::MagicalAttack),
CalculateFlatStat(creature, Library::Statistic::MagicalDefense),
CalculateFlatStat(creature, Library::Statistic::Speed));
Library::StatisticSet<u32> Battling::BattleStatCalculator::CalculateFlatStats(Battling::Creature* creature) const {
return Library::StatisticSet<u32>(CalculateFlatStat(creature, Library::Statistic::Health),
CalculateFlatStat(creature, Library::Statistic::PhysicalAttack),
CalculateFlatStat(creature, Library::Statistic::PhysicalDefense),
CalculateFlatStat(creature, Library::Statistic::MagicalAttack),
CalculateFlatStat(creature, Library::Statistic::MagicalDefense),
CalculateFlatStat(creature, Library::Statistic::Speed));
}
Library::StatisticSet<uint32_t>
Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* creature) const {
return Library::StatisticSet<uint32_t>(CalculateBoostedStat(creature, Library::Statistic::Health),
CalculateBoostedStat(creature, Library::Statistic::PhysicalAttack),
CalculateBoostedStat(creature, Library::Statistic::PhysicalDefense),
CalculateBoostedStat(creature, Library::Statistic::MagicalAttack),
CalculateBoostedStat(creature, Library::Statistic::MagicalDefense),
CalculateBoostedStat(creature, Library::Statistic::Speed));
Library::StatisticSet<u32> Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* creature) const {
return Library::StatisticSet<u32>(CalculateBoostedStat(creature, Library::Statistic::Health),
CalculateBoostedStat(creature, Library::Statistic::PhysicalAttack),
CalculateBoostedStat(creature, Library::Statistic::PhysicalDefense),
CalculateBoostedStat(creature, Library::Statistic::MagicalAttack),
CalculateBoostedStat(creature, Library::Statistic::MagicalDefense),
CalculateBoostedStat(creature, Library::Statistic::Speed));
}
uint32_t CalculateHealthStat(Battling::Creature* creature) {
u32 CalculateHealthStat(Battling::Creature* creature) {
EnsureNotNull(creature)
auto level = creature->GetLevel();
float a = (creature->GetBaseStat(Library::Statistic::Health)) * 2.0 * level;
return static_cast<uint32_t>(floor(a / 100.0) + level + 10);
return static_cast<u32>(floor(a / 100.0) + level + 10);
}
uint32_t CalculateOtherStat(Battling::Creature* creature, Library::Statistic stat) {
u32 CalculateOtherStat(Battling::Creature* creature, Library::Statistic stat) {
EnsureNotNull(creature)
auto level = creature->GetLevel();
float a = (creature->GetBaseStat(stat)) * 2.0 * level;
return static_cast<uint32_t>(floor(a / 100.0) + 5);
return static_cast<u32>(floor(a / 100.0) + 5);
}
uint32_t Battling::BattleStatCalculator::CalculateFlatStat(Battling::Creature* creature,
Library::Statistic stat) const {
u32 Battling::BattleStatCalculator::CalculateFlatStat(Battling::Creature* creature, Library::Statistic stat) const {
if (stat == Library::Statistic::Health)
return CalculateHealthStat(creature);
return CalculateOtherStat(creature, stat);
}
uint32_t Battling::BattleStatCalculator::CalculateBoostedStat(Battling::Creature* creature,
Library::Statistic stat) const {
u32 Battling::BattleStatCalculator::CalculateBoostedStat(Battling::Creature* 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<uint32_t> CalculateFlatStats(Creature* creature) const;
virtual Library::StatisticSet<uint32_t> CalculateBoostedStats(Creature* creature) const;
virtual uint32_t CalculateFlatStat(Creature* creature, Library::Statistic stat) const;
virtual uint32_t CalculateBoostedStat(Creature* creature, Library::Statistic stat) const;
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;
};
}

View File

@@ -2,23 +2,23 @@
#include "../ScriptHandling/ScriptMacros.hpp"
using namespace CreatureLib::Battling;
uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
const ExecutingAttack::HitData& hitData) const {
u32 DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, u8 hitIndex,
const ExecutingAttack::HitData& hitData) const {
EnsureNotNull(attack)
EnsureNotNull(target)
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel()) / 5 + 2;
auto bp = hitData.GetBasePower();
auto statMod = GetStatModifier(attack, target, hitIndex, hitData);
HOOK(ModifyStatModifier, attack, attack, target, hitIndex, &statMod);
uint32_t damage = static_cast<uint32_t>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
GetDamageModifier(attack, target, hitIndex, hitData));
u32 damage = static_cast<u32>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
GetDamageModifier(attack, target, hitIndex, hitData));
HOOK(OverrideDamage, attack, attack, target, hitIndex, &damage);
HOOK(OverrideIncomingDamage, target, attack, target, hitIndex, &damage);
return damage;
}
uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
[[maybe_unused]] const ExecutingAttack::HitData& hitData) const {
u8 DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, u8 hitIndex,
[[maybe_unused]] const ExecutingAttack::HitData& hitData) const {
EnsureNotNull(attack)
EnsureNotNull(target)
auto bp = attack->GetUseAttack()->GetBasePower();
@@ -26,7 +26,7 @@ uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, u
return bp;
}
float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* 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, uint8_t hitIndex,
float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* 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 uint32_t GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
const ExecutingAttack::HitData& hitData) const;
virtual u32 GetDamage(ExecutingAttack* attack, Creature* target, u8 hitIndex,
const ExecutingAttack::HitData& hitData) const;
virtual uint8_t GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
const ExecutingAttack::HitData& hitData) const;
virtual float GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
virtual u8 GetBasePower(ExecutingAttack* attack, Creature* target, u8 hitIndex,
const ExecutingAttack::HitData& hitData) const;
virtual float GetStatModifier(ExecutingAttack* attack, Creature* target, u8 hitIndex,
const ExecutingAttack::HitData& hitData) const;
virtual float GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
virtual float GetDamageModifier(ExecutingAttack* attack, Creature* target, u8 hitIndex,
const ExecutingAttack::HitData& hitData) const;
};
}

View File

@@ -13,6 +13,6 @@ void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
if (levelDiff <= 0)
continue;
auto experienceGain = levelDiff * 10;
opponent->AddExperience(static_cast<uint32_t>(experienceGain));
opponent->AddExperience(static_cast<u32>(experienceGain));
}
}

View File

@@ -4,7 +4,7 @@
bool CreatureLib::Battling::MiscLibrary::IsCritical([[maybe_unused]] CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target,
[[maybe_unused]] uint8_t hit) const {
[[maybe_unused]] u8 hit) const {
EnsureNotNull(target)
Ensure(target->GetBattle().HasValue())
auto rand = target->GetBattle().GetValue()->GetRandom();

View File

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

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 {

View File

@@ -49,8 +49,8 @@ namespace CreatureLib::Battling {
_par_ const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
virtual void OnBeforeTurn(_par_ const BaseTurnChoice* choice){};
virtual void ChangeSpeed(_par_ BaseTurnChoice* choice, _par_ uint32_t* speed){};
virtual void ChangePriority(_par_ AttackTurnChoice* choice, _par_ int8_t* priority){};
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){};
@@ -90,10 +90,10 @@ namespace CreatureLib::Battling {
virtual void OnFaintingOpponent(_par_ const ExecutingAttack* attack, _par_ Creature* target,
_par_ u8 hitNumber){};
virtual void PreventStatBoostChange(_par_ Creature* target, _par_ Library::Statistic stat,
_par_ int8_t diffAmount, _par_ bool selfInflicted, _par_ bool* prevent){};
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_ int8_t* diffAmount){};
_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,

View File

@@ -7,7 +7,7 @@
namespace CreatureLib::Battling {
class ScriptAggregator {
const ScriptWrapper* _scripts;
const ScriptWrapper* nullable _scripts;
i32 _size;
i32 _index = -1;
i32 _setIndex = -1;

View File

@@ -2,6 +2,6 @@
#define CREATURELIB_SCRIPTCATEGORY_HPP
#include <Arbutils/Enum.hpp>
ENUM(ScriptCategory, uint8_t, Attack, Talent, Status, Creature, Battle, Side, ItemBattleTrigger)
ENUM(ScriptCategory, u8, Attack, Talent, Status, Creature, Battle, Side, ItemBattleTrigger)
#endif // CREATURELIB_SCRIPTCATEGORY_HPP

View File

@@ -8,7 +8,7 @@
namespace CreatureLib::Battling {
class ScriptSet {
ArbUt::UniquePtrList<BattleScript> _scripts;
ArbUt::Dictionary<uint32_t, size_t> _lookup;
ArbUt::Dictionary<u32, size_t> _lookup;
public:
~ScriptSet() = default;
@@ -39,7 +39,7 @@ namespace CreatureLib::Battling {
return Get(key.GetHash());
}
ArbUt::OptionalBorrowedPtr<BattleScript> Get(uint32_t keyHash) const noexcept {
ArbUt::OptionalBorrowedPtr<BattleScript> Get(u32 keyHash) const noexcept {
auto v = _lookup.TryGet(keyHash);
if (v.has_value()) {
return _scripts[v.value()].GetRaw();
@@ -49,7 +49,7 @@ namespace CreatureLib::Battling {
void Remove(const ArbUt::BasicStringView& key) { Remove(key.GetHash()); }
void Remove(uint32_t keyHash) {
void Remove(u32 keyHash) {
auto v = _lookup.TryGet(keyHash);
if (v.has_value()) {
auto script = _scripts[v.value()];
@@ -69,7 +69,7 @@ namespace CreatureLib::Battling {
bool Has(const ArbUt::BasicStringView& key) const { return _lookup.Has(key); }
bool Has(uint32_t keyHash) const { return _lookup.Has(keyHash); }
bool Has(u32 keyHash) const { return _lookup.Has(keyHash); }
inline size_t Count() const { return _scripts.Count(); }

View File

@@ -13,7 +13,7 @@ namespace CreatureLib::Battling {
ArbUt::BorrowedPtr<LearnedAttack> _attack;
CreatureIndex _target;
std::unique_ptr<BattleScript> _attackScript = nullptr;
int8_t _priority = 0;
i8 _priority = 0;
bool _hasFailed = false;
void ResolveScript(ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> attack) {
@@ -59,8 +59,8 @@ namespace CreatureLib::Battling {
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
inline int8_t GetPriority() const noexcept { return _priority; }
inline void SetPriority(int8_t priority) noexcept { _priority = priority; }
inline i8 GetPriority() const noexcept { return _priority; }
inline void SetPriority(i8 priority) noexcept { _priority = priority; }
const CreatureIndex& GetTarget() const noexcept { return _target; }

View File

@@ -8,8 +8,8 @@ namespace CreatureLib::Battling {
class Creature;
class BaseTurnChoice : public ScriptSource {
int32_t _randomValue;
uint32_t _speed;
i32 _randomValue;
u32 _speed;
protected:
ArbUt::BorrowedPtr<Creature> _user;
@@ -20,11 +20,11 @@ namespace CreatureLib::Battling {
[[nodiscard]] virtual TurnChoiceKind GetKind() const noexcept = 0;
[[nodiscard]] inline const ArbUt::BorrowedPtr<Creature>& GetUser() const noexcept { return _user; }
inline void __SetRandomValue(int32_t val) noexcept { _randomValue = val; }
inline int32_t __GetRandomValue() const noexcept { return _randomValue; }
inline void __SetRandomValue(i32 val) noexcept { _randomValue = val; }
inline i32 __GetRandomValue() const noexcept { return _randomValue; }
inline void __SetSpeed(uint32_t val) noexcept { _speed = val; }
inline uint32_t __GetSpeed() const noexcept { return _speed; }
inline void __SetSpeed(u32 val) noexcept { _speed = val; }
inline u32 __GetSpeed() const noexcept { return _speed; }
};
}

View File

@@ -2,6 +2,6 @@
#define CREATURELIB_TURNCHOICEKIND_HPP
namespace CreatureLib::Battling {
ENUM(TurnChoiceKind, uint8_t, Pass, Attack, Item, Switch, Flee);
ENUM(TurnChoiceKind, u8, Pass, Attack, Item, Switch, Flee);
}
#endif // CREATURELIB_TURNCHOICEKIND_HPP