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

View File

@@ -1,6 +1,6 @@
#ifndef CREATURELIB_DEFINES_HPP
#define CREATURELIB_DEFINES_HPP
#include <cstdint>
#include <Arbutils/Defines.hpp>
#if LEVEL_U8
using level_int_t = uint8_t;
@@ -15,17 +15,14 @@ using level_int_t = uint64_t;
using level_int_t = uint8_t;
#endif
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
[[deprecated]] typedef uint8_t uint8_t;
[[deprecated]] typedef uint16_t uint16_t;
[[deprecated]] typedef uint32_t uint32_t;
[[deprecated]] typedef uint64_t uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
[[deprecated]] typedef int8_t int8_t;
[[deprecated]] typedef int16_t int16_t;
[[deprecated]] typedef int32_t int32_t;
[[deprecated]] typedef int64_t int64_t;
#endif // CREATURELIB_DEFINES_HPP

View File

@@ -3,7 +3,7 @@
#include <Arbutils/Enum.hpp>
namespace CreatureLib::Library {
ENUM(AttackCategory, uint8_t, Physical, Magical, Status)
ENUM(AttackCategory, u8, Physical, Magical, Status)
}
#endif // CREATURELIB_ATTACKCATEGORY_HPP

View File

@@ -1,9 +1,8 @@
#include "AttackData.hpp"
CreatureLib::Library::AttackData::AttackData(const ArbUt::StringView& name, uint8_t type,
CreatureLib::Library::AttackCategory category, uint8_t power,
uint8_t accuracy, uint8_t baseUsage,
CreatureLib::Library::AttackTarget target, int8_t priority,
const SecondaryEffect* effect, std::unordered_set<uint32_t> flags)
CreatureLib::Library::AttackData::AttackData(const ArbUt::StringView& name, u8 type,
CreatureLib::Library::AttackCategory category, u8 power, u8 accuracy,
u8 baseUsage, CreatureLib::Library::AttackTarget target, i8 priority,
const SecondaryEffect* effect, std::unordered_set<u32> flags)
: _name(name), _type(type), _category(category), _basePower(power), _accuracy(accuracy), _baseUsages(baseUsage),
_target(target), _priority(priority), _effect(effect), _flags(std::move(flags)) {}

View File

@@ -10,30 +10,29 @@ namespace CreatureLib::Library {
class AttackData {
protected:
ArbUt::StringView _name;
uint8_t _type;
u8 _type;
AttackCategory _category;
uint8_t _basePower;
uint8_t _accuracy;
uint8_t _baseUsages;
u8 _basePower;
u8 _accuracy;
u8 _baseUsages;
AttackTarget _target;
int8_t _priority;
i8 _priority;
std::unique_ptr<const SecondaryEffect> _effect = nullptr;
std::unordered_set<uint32_t> _flags;
std::unordered_set<u32> _flags;
public:
AttackData(const ArbUt::StringView& name, uint8_t type, AttackCategory category, uint8_t power,
uint8_t accuracy, uint8_t baseUsage, AttackTarget target, int8_t priority,
const SecondaryEffect* effect, std::unordered_set<uint32_t> flags);
AttackData(const ArbUt::StringView& name, u8 type, AttackCategory category, u8 power, u8 accuracy, u8 baseUsage,
AttackTarget target, i8 priority, const SecondaryEffect* effect, std::unordered_set<u32> flags);
virtual ~AttackData() = default;
inline const ArbUt::StringView& GetName() const noexcept { return _name; }
inline uint8_t GetType() const noexcept { return _type; }
inline u8 GetType() const noexcept { return _type; }
inline AttackCategory GetCategory() const noexcept { return _category; }
inline uint8_t GetBasePower() const noexcept { return _basePower; }
inline uint8_t GetAccuracy() const noexcept { return _accuracy; }
inline uint8_t GetBaseUsages() const noexcept { return _baseUsages; }
inline u8 GetBasePower() const noexcept { return _basePower; }
inline u8 GetAccuracy() const noexcept { return _accuracy; }
inline u8 GetBaseUsages() const noexcept { return _baseUsages; }
inline AttackTarget GetTarget() const noexcept { return _target; }
inline int8_t GetPriority() const noexcept { return _priority; }
inline i8 GetPriority() const noexcept { return _priority; }
inline bool HasSecondaryEffect() const noexcept {
return _effect != nullptr && !_effect->GetEffectName().IsEmpty();
}
@@ -42,9 +41,7 @@ namespace CreatureLib::Library {
inline bool HasFlag(const ArbUt::StringView& key) const noexcept {
return this->_flags.find(key) != this->_flags.end();
}
inline bool HasFlag(uint32_t keyHash) const noexcept {
return this->_flags.find(keyHash) != this->_flags.end();
}
inline bool HasFlag(u32 keyHash) const noexcept { return this->_flags.find(keyHash) != this->_flags.end(); }
};
}

View File

@@ -4,7 +4,7 @@
#include <Arbutils/Enum.hpp>
namespace CreatureLib::Library {
ENUM(AttackTarget, uint8_t, Adjacent, AdjacentAlly, AdjacentAllySelf, AdjacentOpponent,
ENUM(AttackTarget, u8, Adjacent, AdjacentAlly, AdjacentAllySelf, AdjacentOpponent,
All, AllAdjacent, AllAdjacentOpponent, AllAlly, AllOpponent,

View File

@@ -10,8 +10,8 @@
namespace CreatureLib::Library {
template <class T> class BaseLibrary {
protected:
ArbUt::Dictionary<uint32_t, std::unique_ptr<const T>> _values;
ArbUt::List<uint32_t> _listValues;
ArbUt::Dictionary<u32, std::unique_ptr<const T>> _values;
ArbUt::List<u32> _listValues;
public:
BaseLibrary(size_t initialCapacity = 32) : _values(initialCapacity), _listValues(initialCapacity) {}
@@ -23,7 +23,7 @@ namespace CreatureLib::Library {
_values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)});
_listValues.Append(key);
}
inline virtual void Insert(uint32_t hashedKey, const T* value) {
inline virtual void Insert(u32 hashedKey, const T* value) {
EnsureNotNull(value)
_values.GetStdMap().insert({hashedKey, std::unique_ptr<const T>(value)});
_listValues.Append(hashedKey);
@@ -32,18 +32,22 @@ namespace CreatureLib::Library {
inline void Delete(const ArbUt::StringView& key) noexcept {
_values.erase(key.GetHash());
auto k = _listValues.IndexOf(key);
_listValues.Remove(k);
if (k.has_value()) {
_listValues.Remove(k.value());
}
}
inline void Delete(uint32_t hashedKey) noexcept {
inline void Delete(u32 hashedKey) noexcept {
_values.Remove(hashedKey);
auto k = _listValues.IndexOf(hashedKey);
_listValues.Remove(k);
if (k.has_value()) {
_listValues.Remove(k.value());
}
}
std::optional<ArbUt::BorrowedPtr<const T>> TryGet(const ArbUt::BasicStringView& name) const noexcept {
return TryGet(name.GetHash());
}
std::optional<ArbUt::BorrowedPtr<const T>> TryGet(uint32_t hashedKey) const noexcept {
std::optional<ArbUt::BorrowedPtr<const T>> TryGet(u32 hashedKey) const noexcept {
auto find = _values.GetStdMap().find(hashedKey);
if (find == _values.GetStdMap().end())
return {};
@@ -53,29 +57,25 @@ namespace CreatureLib::Library {
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(const ArbUt::BasicStringView& name) const {
return _values.Get(name.GetHash());
}
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(uint32_t hashedKey) const {
return _values.Get(hashedKey);
}
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(u32 hashedKey) const { return _values.Get(hashedKey); }
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](const ArbUt::BasicStringView& name) const {
return Get(name);
}
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](uint32_t hashedKey) const { return Get(hashedKey); }
[[nodiscard]] inline const ArbUt::Dictionary<uint32_t, const std::unique_ptr<const T>>&
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](u32 hashedKey) const { return Get(hashedKey); }
[[nodiscard]] inline const ArbUt::Dictionary<u32, const std::unique_ptr<const T>>&
GetIterator() const noexcept {
return _values;
}
using const_iterator = typename std::unordered_map<uint32_t, ArbUt::BorrowedPtr<const T>>::const_iterator;
using const_iterator = typename std::unordered_map<u32, ArbUt::BorrowedPtr<const T>>::const_iterator;
inline const_iterator begin() const {
return reinterpret_cast<const std::unordered_map<uint32_t, ArbUt::BorrowedPtr<const T>>&>(
_values.GetStdMap())
return reinterpret_cast<const std::unordered_map<u32, ArbUt::BorrowedPtr<const T>>&>(_values.GetStdMap())
.begin();
}
inline const_iterator end() const {
return reinterpret_cast<const std::unordered_map<uint32_t, ArbUt::BorrowedPtr<const T>>&>(
_values.GetStdMap())
return reinterpret_cast<const std::unordered_map<u32, ArbUt::BorrowedPtr<const T>>&>(_values.GetStdMap())
.end();
}

View File

@@ -5,17 +5,17 @@ using namespace CreatureLib::Library;
struct CreatureSpecies::impl {
const ArbUt::StringView _name;
uint16_t _id;
u16 _id;
float _genderRate;
const ArbUt::StringView _growthRate;
uint8_t _captureRate;
u8 _captureRate;
ArbUt::Dictionary<uint32_t, ArbUt::UniquePtr<const SpeciesVariant>> _variantsLookup;
ArbUt::Dictionary<u32, ArbUt::UniquePtr<const SpeciesVariant>> _variantsLookup;
ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>> _variantsList;
std::unordered_set<uint32_t> _flags;
std::unordered_set<u32> _flags;
impl(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant, float genderRatio,
const ArbUt::StringView& growthRate, uint8_t captureRate, std::unordered_set<uint32_t> flags)
impl(u16 id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant, float genderRatio,
const ArbUt::StringView& growthRate, u8 captureRate, std::unordered_set<u32> flags)
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
_variantsLookup(1), _variantsList(1), _flags(std::move(flags)) {
EnsureNotNull(defaultVariant)
@@ -24,20 +24,20 @@ struct CreatureSpecies::impl {
~impl() { _variantsLookup.Clear(); }
inline uint16_t GetId() const noexcept { return _id; }
inline u16 GetId() const noexcept { return _id; }
inline float GetGenderRate() const noexcept { return _genderRate; }
inline const ArbUt::StringView& GetGrowthRate() const noexcept { return _growthRate; }
inline uint8_t GetCaptureRate() const noexcept { return _captureRate; }
inline u8 GetCaptureRate() const noexcept { return _captureRate; }
[[nodiscard]] inline bool HasVariant(const ArbUt::BasicStringView& key) const noexcept {
return _variantsLookup.Has(key);
}
[[nodiscard]] inline bool HasVariant(uint32_t hash) const noexcept { return _variantsLookup.Has(hash); }
[[nodiscard]] inline bool HasVariant(u32 hash) const noexcept { return _variantsLookup.Has(hash); }
[[nodiscard]] inline std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>>
TryGetVariant(const ArbUt::BasicStringView& name) const noexcept {
return TryGetVariant(name.GetHash());
}
[[nodiscard]] std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>> TryGetVariant(uint32_t hash) const noexcept {
[[nodiscard]] std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>> TryGetVariant(u32 hash) const noexcept {
auto find = _variantsLookup.GetStdMap().find(hash);
if (find == _variantsLookup.end())
return {};
@@ -46,7 +46,7 @@ struct CreatureSpecies::impl {
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(const ArbUt::BasicStringView& key) const {
return _variantsLookup.Get(key).GetRaw();
}
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const {
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(u32 key) const {
return _variantsLookup.Get(key).GetRaw();
}
[[nodiscard]] Gender GetRandomGender(ArbUt::Random& rand) const noexcept {
@@ -73,40 +73,38 @@ struct CreatureSpecies::impl {
inline bool HasFlag(const ArbUt::StringView& key) const noexcept {
return this->_flags.find(key) != this->_flags.end();
}
inline bool HasFlag(uint32_t keyHash) const noexcept { return this->_flags.find(keyHash) != this->_flags.end(); }
inline bool HasFlag(u32 keyHash) const noexcept { return this->_flags.find(keyHash) != this->_flags.end(); }
};
CreatureSpecies::CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate,
std::unordered_set<uint32_t> flags)
CreatureSpecies::CreatureSpecies(u16 id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
float genderRatio, const ArbUt::StringView& growthRate, u8 captureRate,
std::unordered_set<u32> flags)
: _impl(new impl(id, name, defaultVariant, genderRatio, growthRate, captureRate, flags)) {}
#define ImplGetter(type, func) \
type CreatureSpecies::func() const noexcept { return _impl->func(); }
CreatureSpecies::~CreatureSpecies() = default;
ImplGetter(uint16_t, GetId);
ImplGetter(u16, GetId);
ImplGetter(float, GetGenderRate);
ImplGetter(const ArbUt::StringView&, GetGrowthRate);
ImplGetter(uint8_t, GetCaptureRate);
ImplGetter(u8, GetCaptureRate);
ImplGetter(const ArbUt::StringView&, GetName);
bool CreatureSpecies::HasVariant(const ArbUt::BasicStringView& key) const noexcept { return _impl->HasVariant(key); }
bool CreatureSpecies::HasVariant(uint32_t hash) const noexcept { return _impl->HasVariant(hash); }
bool CreatureSpecies::HasVariant(u32 hash) const noexcept { return _impl->HasVariant(hash); }
std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>>
CreatureSpecies::TryGetVariant(const ArbUt::BasicStringView& name) const noexcept {
return _impl->TryGetVariant(name);
}
std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>> CreatureSpecies::TryGetVariant(uint32_t hash) const noexcept {
std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>> CreatureSpecies::TryGetVariant(u32 hash) const noexcept {
return _impl->TryGetVariant(hash);
}
ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(const ArbUt::BasicStringView& key) const {
return _impl->GetVariant(key);
}
ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(uint32_t key) const {
return _impl->GetVariant(key);
}
ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(u32 key) const { return _impl->GetVariant(key); }
Gender CreatureSpecies::GetRandomGender(ArbUt::Random& rand) const noexcept { return _impl->GetRandomGender(rand); }
void CreatureSpecies::SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant) {
_impl->SetVariant(name, variant);
@@ -116,4 +114,4 @@ const ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>>& CreatureSpecies::Ge
}
bool CreatureSpecies::HasFlag(const ArbUt::StringView& key) const noexcept { return _impl->HasFlag(key); }
bool CreatureSpecies::HasFlag(uint32_t keyHash) const noexcept { return _impl->HasFlag(keyHash); }
bool CreatureSpecies::HasFlag(u32 keyHash) const noexcept { return _impl->HasFlag(keyHash); }

View File

@@ -23,15 +23,14 @@ namespace CreatureLib::Library {
/// @param captureRate The chance to capture the creature species, between 0 and 255. 255 means instant capture,
/// 0 means impossible to capture.
/// @param flags A set of flags for use by the developer. These can be used for easy grouping.
CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate,
std::unordered_set<uint32_t> flags = {});
CreatureSpecies(u16 id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant, float genderRatio,
const ArbUt::StringView& growthRate, u8 captureRate, std::unordered_set<u32> flags = {});
virtual ~CreatureSpecies();
/// @brief Returns the unique id of the creature species.
/// @return The unique id of the creature species
uint16_t GetId() const noexcept;
u16 GetId() const noexcept;
/// @brief Returns the name of the species.
/// @return The name of the species.
[[nodiscard]] const ArbUt::StringView& GetName() const noexcept;
@@ -45,7 +44,7 @@ namespace CreatureLib::Library {
/// @brief Returns the capture rate of the creature species.
/// @return The base capture rate of the creature species. 255 means instant capture, 0 means impossible to
/// capture.
uint8_t GetCaptureRate() const noexcept;
u8 GetCaptureRate() const noexcept;
/// @brief Checks whether the species contains a variant with a specific name.
/// @param key The name of the variant that's being looked for.
@@ -55,7 +54,7 @@ namespace CreatureLib::Library {
/// @param hash The string hash of the variant that's being looked for. This hash can be retrieved from the
/// StringView class.
/// @return True if the species contains the variant, false otherwise.
[[nodiscard]] bool HasVariant(uint32_t hash) const noexcept;
[[nodiscard]] bool HasVariant(u32 hash) const noexcept;
/// @brief Try to get a variant of the species with a specific name.
/// @param name The name of the variant that's being looked for.
/// @param out If a variant is found, it will be put in this variable. If not, this will remain unchanged.
@@ -67,8 +66,7 @@ namespace CreatureLib::Library {
/// StringView class.
/// @param out If a variant is found, it will be put in this variable. If not, this will remain unchanged.
/// @return True if the species contains the variant, false otherwise.
[[nodiscard]] std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>>
TryGetVariant(uint32_t hash) const noexcept;
[[nodiscard]] std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>> TryGetVariant(u32 hash) const noexcept;
/// @brief Returns a variant with a specific name. Throws if no variant with the name exists.
/// @param key The name of the variant that's being looked for.
/// @return The specified variant.
@@ -76,7 +74,7 @@ namespace CreatureLib::Library {
/// @brief Returns a variant with a specific name. Throws if no variant with the name exists.
/// @param key The string hash of the variant that's being looked for.
/// @return The specified variant.
[[nodiscard]] ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const;
[[nodiscard]] ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(u32 key) const;
/// @brief Returns a random gender based on the gender ratio of the species.
/// @param rand A random number generator class.
/// @return A random gender. If gender ratio is -1 this will return Genderless, otherwise it will be either male
@@ -99,7 +97,7 @@ namespace CreatureLib::Library {
/// @brief Checks whether the species has a specific flag.
/// @param keyHash The flag to check for.
/// @return True if the species has the flag, false otherwise.
bool HasFlag(uint32_t keyHash) const noexcept;
bool HasFlag(u32 keyHash) const noexcept;
};
}

View File

@@ -28,7 +28,7 @@ namespace CreatureLib::Library {
inline bool HasAttacksForLevel(level_int_t level) const noexcept { return _learnedByLevel.Has(level); }
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(level_int_t level) const {
if (!_learnedByLevel.Has(level)) {
THROW("No attacks found for level ", (uint32_t)level, ".");
THROW("No attacks found for level ", (u32)level, ".");
}
return _learnedByLevel.Get(level);
}

View File

@@ -6,20 +6,19 @@ namespace CreatureLib::Library {
ArbUt::StringView _name;
float _height;
float _weight;
uint32_t _baseExperience;
ArbUt::List<uint8_t> _types;
Library::StatisticSet<uint16_t> _baseStatistics;
u32 _baseExperience;
ArbUt::List<u8> _types;
Library::StatisticSet<u16> _baseStatistics;
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> _talents;
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> _secretTalents;
std::unique_ptr<const LearnableAttacks> _attacks;
std::unordered_set<uint32_t> _flags;
std::unordered_set<u32> _flags;
public:
impl(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
ArbUt::List<uint8_t> types, Library::StatisticSet<uint16_t> baseStats,
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> talents,
impl(const ArbUt::StringView& name, float height, float weight, u32 baseExperience, ArbUt::List<u8> types,
Library::StatisticSet<u16> baseStats, ArbUt::List<ArbUt::BorrowedPtr<const Talent>> talents,
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> secretTalents, const LearnableAttacks* attacks,
std::unordered_set<uint32_t> flags)
std::unordered_set<u32> flags)
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience),
_types(std::move((types))), _baseStatistics(baseStats), _talents(std::move(talents)),
_secretTalents(std::move(secretTalents)), _attacks(attacks), _flags(std::move(flags)){};
@@ -27,14 +26,12 @@ namespace CreatureLib::Library {
inline const ArbUt::StringView& GetName() const { return _name; }
inline float GetHeight() const { return _height; }
inline float GetWeight() const { return _weight; }
inline uint32_t GetBaseExperience() const { return _baseExperience; }
inline u32 GetBaseExperience() const { return _baseExperience; }
[[nodiscard]] inline size_t GetTypeCount() const { return _types.Count(); }
[[nodiscard]] inline uint8_t GetType(size_t index) const { return _types[index]; }
[[nodiscard]] inline const ArbUt::List<uint8_t>& GetTypes() const { return _types; }
[[nodiscard]] inline uint16_t GetStatistic(Library::Statistic stat) const {
return _baseStatistics.GetStat(stat);
}
[[nodiscard]] inline u8 GetType(size_t index) const { return _types[index]; }
[[nodiscard]] inline const ArbUt::List<u8>& GetTypes() const { return _types; }
[[nodiscard]] inline u16 GetStatistic(Library::Statistic stat) const { return _baseStatistics.GetStat(stat); }
[[nodiscard]] inline size_t GetTalentCount() const noexcept { return _talents.Count(); }
[[nodiscard]] inline size_t GetSecretTalentCount() const noexcept { return _secretTalents.Count(); }
[[nodiscard]] const ArbUt::BorrowedPtr<const Talent>& GetTalent(const TalentIndex& index) const {
@@ -95,16 +92,14 @@ namespace CreatureLib::Library {
inline bool HasFlag(const ArbUt::StringView& key) const noexcept {
return this->_flags.find(key) != this->_flags.end();
}
inline bool HasFlag(uint32_t keyHash) const noexcept {
return this->_flags.find(keyHash) != this->_flags.end();
}
inline bool HasFlag(u32 keyHash) const noexcept { return this->_flags.find(keyHash) != this->_flags.end(); }
};
SpeciesVariant::SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
const ArbUt::List<uint8_t>& types, StatisticSet<uint16_t> baseStats,
SpeciesVariant::SpeciesVariant(const ArbUt::StringView& name, float height, float weight, u32 baseExperience,
const ArbUt::List<u8>& types, StatisticSet<u16> baseStats,
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
const LearnableAttacks* attacks, const std::unordered_set<uint32_t>& flags)
const LearnableAttacks* attacks, const std::unordered_set<u32>& flags)
: _impl(new impl(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks,
flags)) {}
SpeciesVariant::~SpeciesVariant() = default;
@@ -115,11 +110,11 @@ namespace CreatureLib::Library {
ImplGetter(const ArbUt::StringView&, GetName);
ImplGetter(float, GetHeight);
ImplGetter(float, GetWeight);
ImplGetter(uint32_t, GetBaseExperience);
ImplGetter(u32, GetBaseExperience);
ImplGetter(size_t, GetTypeCount);
uint8_t SpeciesVariant::GetType(size_t index) const { return _impl->GetType(index); }
ImplGetter(const ArbUt::List<uint8_t>&, GetTypes);
uint16_t SpeciesVariant::GetStatistic(Library::Statistic stat) const noexcept { return _impl->GetStatistic(stat); }
u8 SpeciesVariant::GetType(size_t index) const { return _impl->GetType(index); }
ImplGetter(const ArbUt::List<u8>&, GetTypes);
u16 SpeciesVariant::GetStatistic(Library::Statistic stat) const noexcept { return _impl->GetStatistic(stat); }
ImplGetter(size_t, GetTalentCount);
ImplGetter(size_t, GetSecretTalentCount);
@@ -140,5 +135,5 @@ namespace CreatureLib::Library {
ImplGetter(const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>&, GetSecretTalents);
bool SpeciesVariant::HasFlag(const ArbUt::StringView& key) const noexcept { return _impl->HasFlag(key); }
bool SpeciesVariant::HasFlag(uint32_t keyHash) const noexcept { return _impl->HasFlag(keyHash); }
bool SpeciesVariant::HasFlag(u32 keyHash) const noexcept { return _impl->HasFlag(keyHash); }
}

View File

@@ -27,11 +27,11 @@ namespace CreatureLib::Library {
/// scripts when battling.
/// @param attacks The attacks that this variant can learn.
/// @param flags A set of flags for use by the developer. These can be used for easy grouping.
SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
const ArbUt::List<uint8_t>& types, Library::StatisticSet<uint16_t> baseStats,
SpeciesVariant(const ArbUt::StringView& name, float height, float weight, u32 baseExperience,
const ArbUt::List<u8>& types, Library::StatisticSet<u16> baseStats,
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
const LearnableAttacks* attacks, const std::unordered_set<uint32_t>& flags = {});
const LearnableAttacks* attacks, const std::unordered_set<u32>& flags = {});
virtual ~SpeciesVariant();
/// @brief Returns the unique name of the variant.
@@ -45,7 +45,7 @@ namespace CreatureLib::Library {
float GetWeight() const noexcept;
/// @brief Returns the amount of base experience gained when defeating a creature with this variant.
/// @return The amount of base experience gained when defeating a creature with this variant.
uint32_t GetBaseExperience() const noexcept;
u32 GetBaseExperience() const noexcept;
/// @brief Returns the amount of types this variant has.
/// @return The amount of types this variant has.
@@ -53,14 +53,14 @@ namespace CreatureLib::Library {
/// @brief Returns a type index at a specified index.
/// @param index The index of the type requested.
/// @return A type index, as defined in TypeLibrary.
[[nodiscard]] uint8_t GetType(size_t index) const;
[[nodiscard]] u8 GetType(size_t index) const;
/// @brief Returns a list of the types on this variant.
/// @return A list of types on the variant,
[[nodiscard]] const ArbUt::List<uint8_t>& GetTypes() const noexcept;
[[nodiscard]] const ArbUt::List<u8>& GetTypes() const noexcept;
/// @brief Returns the value of a base statistic.
/// @param stat The desired statistic.
/// @return The base statistic value.
[[nodiscard]] uint16_t GetStatistic(Library::Statistic stat) const noexcept;
[[nodiscard]] u16 GetStatistic(Library::Statistic stat) const noexcept;
/// @brief Returns the amount of talents this variant has.
/// @return The amount of talents this variant has.
@@ -102,7 +102,7 @@ namespace CreatureLib::Library {
/// @brief Checks whether the species has a specific flag.
/// @param keyHash The flag to check for.
/// @return True if the species has the flag, false otherwise.
bool HasFlag(uint32_t keyHash) const noexcept;
bool HasFlag(u32 keyHash) const noexcept;
};
}

View File

@@ -10,17 +10,17 @@ namespace CreatureLib::Library {
/// @brief Initialises a Talent Index from whether or not this is a secret talent, and it's index.
/// @param secret Whether or not this is a secret talent.
/// @param index The index of the talent on the species variant.
inline TalentIndex(bool secret, uint8_t index) noexcept : _secret(secret), _index(index) {}
inline TalentIndex(bool secret, u8 index) noexcept : _secret(secret), _index(index) {}
/// @brief Returns whether or not this is a secret talent.
/// @return Whether or not this is a secret talent.
[[nodiscard]] constexpr inline bool IsSecret() const noexcept { return _secret; }
/// @brief Returns the index of the talent on the species variant.
/// @return The index of the talent on the species variant.
[[nodiscard]] constexpr inline uint8_t GetIndex() const noexcept { return _index; }
[[nodiscard]] constexpr inline u8 GetIndex() const noexcept { return _index; }
private:
bool _secret = false;
uint8_t _index;
u8 _index;
};
}

View File

@@ -12,12 +12,12 @@ namespace CreatureLib::Library {
class EffectParameter {
private:
EffectParameterType _type = EffectParameterType::None;
std::variant<bool, int64_t, float, ArbUt::StringView> _value;
std::variant<bool, i64, float, ArbUt::StringView> _value;
public:
inline EffectParameter() : _type(EffectParameterType::None){};
inline explicit EffectParameter(bool b) : _type(EffectParameterType::Bool), _value(b){};
inline explicit EffectParameter(int64_t i) : _type(EffectParameterType::Int), _value(i){};
inline explicit EffectParameter(i64 i) : _type(EffectParameterType::Int), _value(i){};
inline explicit EffectParameter(float f) : _type(EffectParameterType::Float), _value(f){};
inline explicit EffectParameter(const ArbUt::StringView& s) : _type(EffectParameterType::String), _value(s){};
EffectParameter(const EffectParameter& other) = delete;
@@ -30,19 +30,19 @@ namespace CreatureLib::Library {
}
return std::get<bool>(_value);
}
int64_t AsInt() const {
i64 AsInt() const {
if (_type != EffectParameterType::Int) {
if (_type == EffectParameterType::Float) {
return static_cast<int64_t>(std::get<float>(_value));
return static_cast<i64>(std::get<float>(_value));
}
THROW("Cast effect parameter to int, but was ", EffectParameterTypeHelper::ToString(_type));
}
return std::get<int64_t>(_value);
return std::get<i64>(_value);
}
float AsFloat() const {
if (_type != EffectParameterType::Float) {
if (_type == EffectParameterType::Int) {
return static_cast<float>(std::get<int64_t>(_value));
return static_cast<float>(std::get<i64>(_value));
}
THROW("Cast effect parameter to float, but was ", EffectParameterTypeHelper::ToString(_type));
}

View File

@@ -7,7 +7,7 @@ namespace CreatureLib::Library {
\brief Might be somewhat controversial nowadays, but as many creature battling games only have two genders, we'll
hardcode those.
*/
ENUM(Gender, uint8_t, Male, Female, Genderless)
ENUM(Gender, u8, Male, Female, Genderless)
}
#endif // CREATURELIB_GENDER_HPP

View File

@@ -7,18 +7,18 @@
namespace CreatureLib::Library {
class ExternGrowthRate : public GrowthRate {
level_int_t (*_calcLevel)(uint32_t experience);
uint32_t (*_calcExperience)(level_int_t level);
level_int_t (*_calcLevel)(u32 experience);
u32 (*_calcExperience)(level_int_t level);
public:
inline ExternGrowthRate(level_int_t (*calcLevel)(uint32_t), uint32_t (*calcExperience)(level_int_t level))
inline ExternGrowthRate(level_int_t (*calcLevel)(u32), u32 (*calcExperience)(level_int_t level))
: _calcLevel(calcLevel), _calcExperience(calcExperience) {
EnsureNotNull(calcLevel)
EnsureNotNull(calcExperience)
}
level_int_t CalculateLevel(uint32_t experience) const override { return _calcLevel(experience); }
uint32_t CalculateExperience(level_int_t level) const override { return _calcExperience(level); }
level_int_t CalculateLevel(u32 experience) const override { return _calcLevel(experience); }
u32 CalculateExperience(level_int_t level) const override { return _calcExperience(level); }
};
}

View File

@@ -9,8 +9,8 @@ namespace CreatureLib::Library {
public:
virtual ~GrowthRate() = default;
[[nodiscard]] virtual level_int_t CalculateLevel(uint32_t experience) const = 0;
[[nodiscard]] virtual uint32_t CalculateExperience(level_int_t level) const = 0;
[[nodiscard]] virtual level_int_t CalculateLevel(u32 experience) const = 0;
[[nodiscard]] virtual u32 CalculateExperience(level_int_t level) const = 0;
};
}

View File

@@ -2,8 +2,8 @@
#include <Arbutils/Exception.hpp>
#include "../Exceptions/CreatureException.hpp"
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::BasicStringView& growthRate,
uint32_t experience) const {
u8 CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::BasicStringView& growthRate,
u32 experience) const {
auto find = _growthRates.find(growthRate);
if (find == _growthRates.end()) {
THROW("Invalid growth rate was requested.");
@@ -11,7 +11,7 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::Bas
return find->second->CalculateLevel(experience);
}
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, uint32_t experience) const {
u8 CreatureLib::Library::GrowthRateLibrary::CalculateLevel(u32 hash, u32 experience) const {
auto find = _growthRates.find(hash);
if (find == _growthRates.end()) {
THROW("Invalid growth rate was requested.");
@@ -19,8 +19,8 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, u
return find->second->CalculateLevel(experience);
}
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbUt::BasicStringView& growthRate,
level_int_t level) const {
u32 CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbUt::BasicStringView& growthRate,
level_int_t level) const {
auto find = _growthRates.find(growthRate);
if (find == _growthRates.end()) {
THROW("Invalid growth rate was requested.");
@@ -28,7 +28,7 @@ uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbU
return find->second->CalculateExperience(level);
}
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t hash, level_int_t level) const {
u32 CreatureLib::Library::GrowthRateLibrary::CalculateExperience(u32 hash, level_int_t level) const {
auto find = _growthRates.find(hash);
if (find == _growthRates.end()) {
THROW("Invalid growth rate was requested.");
@@ -41,6 +41,6 @@ void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ArbUt::StringV
_growthRates.insert({name, std::unique_ptr<const GrowthRate>(rate)});
}
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(uint32_t hash, CreatureLib::Library::GrowthRate* rate) {
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(u32 hash, CreatureLib::Library::GrowthRate* rate) {
_growthRates.insert({hash, std::unique_ptr<const GrowthRate>(rate)});
}

View File

@@ -8,20 +8,20 @@
namespace CreatureLib::Library {
class GrowthRateLibrary {
private:
std::unordered_map<uint32_t, std::unique_ptr<const GrowthRate>> _growthRates;
std::unordered_map<u32, std::unique_ptr<const GrowthRate>> _growthRates;
public:
GrowthRateLibrary(size_t initialCapacity = 10)
: _growthRates(std::unordered_map<uint32_t, std::unique_ptr<const GrowthRate>>(initialCapacity)) {}
: _growthRates(std::unordered_map<u32, std::unique_ptr<const GrowthRate>>(initialCapacity)) {}
virtual ~GrowthRateLibrary() = default;
[[nodiscard]] level_int_t CalculateLevel(const ArbUt::BasicStringView& growthRate, uint32_t experience) const;
[[nodiscard]] level_int_t CalculateLevel(uint32_t hash, uint32_t experience) const;
[[nodiscard]] uint32_t CalculateExperience(const ArbUt::BasicStringView& growthRate, level_int_t level) const;
[[nodiscard]] uint32_t CalculateExperience(uint32_t hash, level_int_t level) const;
[[nodiscard]] level_int_t CalculateLevel(const ArbUt::BasicStringView& growthRate, u32 experience) const;
[[nodiscard]] level_int_t CalculateLevel(u32 hash, u32 experience) const;
[[nodiscard]] u32 CalculateExperience(const ArbUt::BasicStringView& growthRate, level_int_t level) const;
[[nodiscard]] u32 CalculateExperience(u32 hash, level_int_t level) const;
void AddGrowthRate(uint32_t hash, GrowthRate* rate);
void AddGrowthRate(u32 hash, GrowthRate* rate);
void AddGrowthRate(const ArbUt::StringView& name, GrowthRate* rate);
};
}

View File

@@ -7,12 +7,12 @@
namespace CreatureLib::Library {
class LookupGrowthRate : public GrowthRate {
protected:
ArbUt::List<uint32_t> _experience;
ArbUt::List<u32> _experience;
public:
LookupGrowthRate(const ArbUt::List<uint32_t>& experience) : _experience(experience) {}
LookupGrowthRate(const ArbUt::List<u32>& experience) : _experience(experience) {}
level_int_t CalculateLevel(uint32_t experience) const override {
level_int_t CalculateLevel(u32 experience) const override {
for (level_int_t i = 0; i < (level_int_t)_experience.Count(); i++) {
if (_experience[i] > experience) {
return i;
@@ -21,7 +21,7 @@ namespace CreatureLib::Library {
return _experience.Count() - 1;
}
uint32_t CalculateExperience(level_int_t level) const override { return _experience[level - 1]; }
u32 CalculateExperience(level_int_t level) const override { return _experience[level - 1]; }
};
}

View File

@@ -2,7 +2,7 @@
#define CREATURELIB_BATTLEITEMCATEGORY_HPP
namespace CreatureLib::Library {
ENUM(BattleItemCategory, uint8_t, None, Healing, StatusHealing, CaptureDevice, MiscBattleItem)
ENUM(BattleItemCategory, u8, None, Healing, StatusHealing, CaptureDevice, MiscBattleItem)
}
#endif // CREATURELIB_BATTLEITEMCATEGORY_HPP

View File

@@ -5,41 +5,41 @@ namespace CreatureLib::Library {
ArbUt::StringView _name;
ItemCategory _category;
BattleItemCategory _battleCategory;
int32_t _price;
i32 _price;
ArbUt::OptionalUniquePtr<const SecondaryEffect> _effect = nullptr;
ArbUt::OptionalUniquePtr<const SecondaryEffect> _battleTriggerEffect = nullptr;
std::unordered_set<uint32_t> _flags;
std::unordered_set<u32> _flags;
public:
inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory,
int32_t price, const SecondaryEffect* effect, const SecondaryEffect* battleTriggerEffect,
const std::unordered_set<uint32_t>& flags) noexcept
inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, i32 price,
const SecondaryEffect* effect, const SecondaryEffect* battleTriggerEffect,
const std::unordered_set<u32>& flags) noexcept
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _effect(effect),
_battleTriggerEffect(battleTriggerEffect), _flags(flags) {}
inline const ArbUt::StringView& GetName() const noexcept { return _name; }
inline ItemCategory GetCategory() const noexcept { return _category; }
inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; }
inline int32_t GetPrice() const noexcept { return _price; }
inline i32 GetPrice() const noexcept { return _price; }
inline const ArbUt::OptionalUniquePtr<const SecondaryEffect>& GetEffect() const noexcept { return _effect; }
inline const ArbUt::OptionalUniquePtr<const SecondaryEffect>& GetBattleTriggerEffect() const noexcept {
return _battleTriggerEffect;
}
inline bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return this->_flags.contains(flag); }
inline bool HasFlag(uint32_t flag) const noexcept { return this->_flags.contains(flag); }
inline bool HasFlag(u32 flag) const noexcept { return this->_flags.contains(flag); }
};
Item::Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
Item::Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, i32 price,
const SecondaryEffect* effect, const SecondaryEffect* battleTriggerEffect,
const std::unordered_set<uint32_t>& flags) noexcept
const std::unordered_set<u32>& flags) noexcept
: _impl(new impl(name, category, battleCategory, price, effect, battleTriggerEffect, flags)) {}
Item::~Item() = default;
const ArbUt::StringView& Item::GetName() const noexcept { return _impl->GetName(); }
ItemCategory Item::GetCategory() const noexcept { return _impl->GetCategory(); }
BattleItemCategory Item::GetBattleCategory() const noexcept { return _impl->GetBattleCategory(); }
int32_t Item::GetPrice() const noexcept { return _impl->GetPrice(); }
i32 Item::GetPrice() const noexcept { return _impl->GetPrice(); }
const ArbUt::OptionalUniquePtr<const SecondaryEffect>& Item::GetEffect() const noexcept {
return _impl->GetEffect();
}
@@ -48,6 +48,6 @@ namespace CreatureLib::Library {
}
bool Item::HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return _impl->HasFlag(flag); }
bool Item::HasFlag(uint32_t flag) const noexcept { return _impl->HasFlag(flag); }
bool Item::HasFlag(u32 flag) const noexcept { return _impl->HasFlag(flag); }
}

View File

@@ -15,9 +15,9 @@ namespace CreatureLib::Library {
std::unique_ptr<impl> _impl;
public:
Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, i32 price,
const SecondaryEffect* effect, const SecondaryEffect* battleTriggerEffect,
const std::unordered_set<uint32_t>& flags) noexcept;
const std::unordered_set<u32>& flags) noexcept;
NO_COPY_OR_MOVE(Item)
virtual ~Item();
@@ -25,12 +25,12 @@ namespace CreatureLib::Library {
const ArbUt::StringView& GetName() const noexcept;
ItemCategory GetCategory() const noexcept;
BattleItemCategory GetBattleCategory() const noexcept;
int32_t GetPrice() const noexcept;
i32 GetPrice() const noexcept;
const ArbUt::OptionalUniquePtr<const SecondaryEffect>& GetEffect() const noexcept;
const ArbUt::OptionalUniquePtr<const SecondaryEffect>& GetBattleTriggerEffect() const noexcept;
bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept;
bool HasFlag(uint32_t flag) const noexcept;
bool HasFlag(u32 flag) const noexcept;
};
}

View File

@@ -2,7 +2,7 @@
#define CREATURELIB_ITEMCATEGORY_HPP
namespace CreatureLib::Library {
ENUM(ItemCategory, uint8_t, MiscItem, CaptureDevice, Medicine, Berry, MoveLearner, VariantChanger, KeyItem, Mail)
ENUM(ItemCategory, u8, MiscItem, CaptureDevice, Medicine, Berry, MoveLearner, VariantChanger, KeyItem, Mail)
}
#endif // CREATURELIB_ITEMCATEGORY_HPP

View File

@@ -3,20 +3,20 @@
namespace CreatureLib::Library {
struct LibrarySettings::impl {
level_int_t _maximalLevel;
uint8_t _maximalAttacks;
u8 _maximalAttacks;
public:
impl(level_int_t maximalLevel, uint8_t maximalAttacks)
impl(level_int_t maximalLevel, u8 maximalAttacks)
: _maximalLevel(maximalLevel), _maximalAttacks(maximalAttacks) {}
[[nodiscard]] inline level_int_t GetMaximalLevel() const noexcept { return _maximalLevel; }
[[nodiscard]] inline uint8_t GetMaximalAttacks() const noexcept { return _maximalAttacks; }
[[nodiscard]] inline u8 GetMaximalAttacks() const noexcept { return _maximalAttacks; }
};
LibrarySettings::LibrarySettings(level_int_t maximalLevel, uint8_t maximalAttacks)
LibrarySettings::LibrarySettings(level_int_t maximalLevel, u8 maximalAttacks)
: _impl(new impl(maximalLevel, maximalAttacks)) {}
LibrarySettings::~LibrarySettings() = default;
level_int_t LibrarySettings::GetMaximalLevel() const noexcept { return _impl->GetMaximalLevel(); }
uint8_t LibrarySettings::GetMaximalAttacks() const noexcept { return _impl->GetMaximalAttacks(); }
u8 LibrarySettings::GetMaximalAttacks() const noexcept { return _impl->GetMaximalAttacks(); }
}

View File

@@ -14,7 +14,7 @@ namespace CreatureLib::Library {
/// @brief Initialises LibrarySettings.
/// @param maximalLevel The maximal level a creature can be.
/// @param maximalAttacks The maximal number of attacks a creature can have.
LibrarySettings(level_int_t maximalLevel, uint8_t maximalAttacks);
LibrarySettings(level_int_t maximalLevel, u8 maximalAttacks);
virtual ~LibrarySettings();
/// @brief Returns the maximal level a creature can be in the current library.
@@ -22,7 +22,7 @@ namespace CreatureLib::Library {
[[nodiscard]] level_int_t GetMaximalLevel() const noexcept;
/// @brief Returns the maximal number of attacks a creature can have.
/// @return The maximal number of attacks a creature can have.
[[nodiscard]] uint8_t GetMaximalAttacks() const noexcept;
[[nodiscard]] u8 GetMaximalAttacks() const noexcept;
};
}

View File

@@ -7,7 +7,7 @@
namespace CreatureLib::Library {
class SpeciesLibrary : public BaseLibrary<CreatureSpecies> {
private:
ArbUt::Dictionary<uint16_t, ArbUt::BorrowedPtr<const CreatureSpecies>> _valuesById;
ArbUt::Dictionary<u16, ArbUt::BorrowedPtr<const CreatureSpecies>> _valuesById;
public:
SpeciesLibrary(size_t initialCapacity = 32) : BaseLibrary(initialCapacity){};
@@ -16,12 +16,12 @@ namespace CreatureLib::Library {
BaseLibrary::Insert(key, value);
_valuesById.Insert(value->GetId(), value);
}
void Insert(uint32_t hashedKey, const CreatureSpecies* value) override {
void Insert(u32 hashedKey, const CreatureSpecies* value) override {
BaseLibrary::Insert(hashedKey, value);
_valuesById.Insert(value->GetId(), value);
}
const ArbUt::BorrowedPtr<const CreatureSpecies>& GetById(uint16_t id) const { return _valuesById[id]; }
const ArbUt::BorrowedPtr<const CreatureSpecies>& GetById(u16 id) const { return _valuesById[id]; }
};
}

View File

@@ -3,7 +3,7 @@
#include <Arbutils/Enum.hpp>
namespace CreatureLib::Library {
ENUM(Statistic, uint8_t, Health, PhysicalAttack, PhysicalDefense, MagicalAttack, MagicalDefense, Speed)
ENUM(Statistic, u8, Health, PhysicalAttack, PhysicalDefense, MagicalAttack, MagicalDefense, Speed)
}
#endif // CREATURELIB_STATISTIC_HPP

View File

@@ -2,7 +2,7 @@
using namespace CreatureLib::Library;
uint8_t TypeLibrary::RegisterType(const ArbUt::StringView& key) {
u8 TypeLibrary::RegisterType(const ArbUt::StringView& key) {
_types.Insert(key, _types.Count());
_effectiveness.Resize(_types.Count());
for (auto& eff : _effectiveness) {
@@ -11,14 +11,14 @@ uint8_t TypeLibrary::RegisterType(const ArbUt::StringView& key) {
return _types.Count() - 1;
}
void TypeLibrary::SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness) {
void TypeLibrary::SetEffectiveness(u8 attacking, u8 defensive, float effectiveness) {
_effectiveness[attacking][defensive] = effectiveness;
}
const ArbUt::StringView& TypeLibrary::GetTypeName(uint8_t type) const {
const ArbUt::StringView& TypeLibrary::GetTypeName(u8 type) const {
for (auto& kv : _types) {
if (kv.second == type) {
return kv.first;
}
}
THROW("Name requested for unknown type: ", (uint32_t)type);
THROW("Name requested for unknown type: ", (u32)type);
}

View File

@@ -16,25 +16,25 @@ namespace CreatureLib::Library {
public:
TypeLibrary(size_t initialCapacity = 20) : _types(ArbUt::Dictionary<ArbUt::StringView, u8>(initialCapacity)) {}
inline uint8_t GetTypeId(const ArbUt::StringView& key) const { return _types.Get(key); }
inline u8 GetTypeId(const ArbUt::StringView& key) const { return _types.Get(key); }
[[nodiscard]] inline float GetSingleEffectiveness(u8 attacking, u8 defensive) const {
try {
return _effectiveness[attacking][defensive];
} catch (const std::exception& e) {
THROW("Unknown type indices were requested for effectiveness: ", (uint32_t)attacking, " and ",
(uint32_t)defensive);
THROW("Unknown type indices were requested for effectiveness: ", (u32)attacking, " and ",
(u32)defensive);
}
}
[[nodiscard]] inline float GetEffectiveness(uint8_t attacking, const std::vector<u8>& defensive) const {
[[nodiscard]] inline float GetEffectiveness(u8 attacking, const std::vector<u8>& defensive) const {
return std::accumulate(defensive.begin(), defensive.end(), (float)1,
[this, attacking](float init, uint8_t defense) {
[this, attacking](float init, u8 defense) {
return init * GetSingleEffectiveness(attacking, defense);
});
}
const ArbUt::StringView& GetTypeName(u8 type) const;
uint8_t RegisterType(const ArbUt::StringView& typeName);
void SetEffectiveness(uint8_t attacking, u8 defensive, float effectiveness);
u8 RegisterType(const ArbUt::StringView& typeName);
void SetEffectiveness(u8 attacking, u8 defensive, float effectiveness);
};
}