More aggressive sanitization. Loads of integer definition fixes
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-03-25 19:08:42 +01:00
parent f6625a0bdf
commit 1b14f31bd7
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
68 changed files with 371 additions and 352 deletions

View File

@ -1,5 +1,4 @@
Checks: 'readability-*,clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,performance-*,cppcoreguidelines-*, Checks: 'readability-*,clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,performance-*,cppcoreguidelines-*,bugprone-*,modernize-*,-modernize-use-trailing-return-type,clang-analyzer-nullability-*'
bugprone-*,modernize-*,-modernize-use-trailing-return-type'
HeaderFilterRegex: '' HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false AnalyzeTemporaryDtors: false
CheckOptions: CheckOptions:

View File

@ -228,6 +228,7 @@ if (PKMNLIB_TESTS)
# Add a definition for the test library # Add a definition for the test library
target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD) target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD)
if (SANITIZER_TESTS AND NOT WINDOWS) if (SANITIZER_TESTS AND NOT WINDOWS)
target_compile_options(pkmnLib PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all -fno-sanitize=unsigned-integer-overflow)
target_compile_options(pkmnLibTests PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all) target_compile_options(pkmnLibTests PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all)
target_link_options(pkmnLibTests PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all) target_link_options(pkmnLibTests PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all)
endif () endif ()

View File

@ -13,8 +13,9 @@ namespace PkmnLib::Battling {
std::unique_ptr<CreatureLib::Battling::BattleScript> _weatherScript = nullptr; std::unique_ptr<CreatureLib::Battling::BattleScript> _weatherScript = nullptr;
public: public:
Battle(const BattleLibrary* library, const ArbUt::List<CreatureLib::Battling::BattleParty*>& parties, Battle(const BattleLibrary* non_null library,
bool canFlee = true, uint8_t numberOfSides = 2, uint8_t creaturesPerSide = 1, const ArbUt::List<CreatureLib::Battling::BattleParty * non_null>& parties, bool canFlee = true,
u8 numberOfSides = 2, u8 creaturesPerSide = 1,
uint_fast32_t randomSeed = std::chrono::duration_cast<std::chrono::milliseconds>( uint_fast32_t randomSeed = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()) std::chrono::system_clock::now().time_since_epoch())
.count()) .count())
@ -48,7 +49,7 @@ namespace PkmnLib::Battling {
CreatureLib::Battling::ScriptWrapper::FromScript(&_weatherScript))); CreatureLib::Battling::ScriptWrapper::FromScript(&_weatherScript)));
} }
Battle* Clone() const override; Battle* non_null Clone() const override;
}; };
} }

View File

@ -2,6 +2,6 @@
#define PKMNLIB_PKMNEVENTKIND_HPP #define PKMNLIB_PKMNEVENTKIND_HPP
#include <CreatureLib/Battling/EventHooks/EventDataKind.hpp> #include <CreatureLib/Battling/EventHooks/EventDataKind.hpp>
ENUM_WITH_START_VALUE(PkmnEventDataKind, uint8_t, 128, WeatherChange) ENUM_WITH_START_VALUE(PkmnEventDataKind, u8, 128, WeatherChange)
#endif // PKMNLIB_PKMNEVENTKIND_HPP #endif // PKMNLIB_PKMNEVENTKIND_HPP

View File

@ -1 +0,0 @@
#include "BattleLibrary.hpp"

View File

@ -12,9 +12,10 @@
namespace PkmnLib::Battling { namespace PkmnLib::Battling {
class BattleLibrary final : public CreatureLib::Battling::BattleLibrary { class BattleLibrary final : public CreatureLib::Battling::BattleLibrary {
public: public:
BattleLibrary(Library::PokemonLibrary* staticLib, StatCalculator* statCalculator, DamageLibrary* damageLibrary, BattleLibrary(Library::PokemonLibrary* non_null staticLib, StatCalculator* non_null statCalculator,
PkmnLib::Battling::ExperienceLibrary* experienceLibrary, ScriptResolver* scriptResolver, DamageLibrary* non_null damageLibrary,
PkmnLib::Battling::MiscLibrary* miscLibrary) PkmnLib::Battling::ExperienceLibrary* non_null experienceLibrary,
ScriptResolver* non_null scriptResolver, PkmnLib::Battling::MiscLibrary* non_null miscLibrary)
: CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary, : CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary,
scriptResolver, miscLibrary) {} scriptResolver, miscLibrary) {}
@ -43,7 +44,7 @@ namespace PkmnLib::Battling {
return GetStaticLib()->GetNatureLibrary(); return GetStaticLib()->GetNatureLibrary();
} }
static PkmnLib::Battling::ScriptResolver* CreateScriptResolver(); static PkmnLib::Battling::ScriptResolver* non_null CreateScriptResolver();
}; };
} }
#endif // PKMNLIB_BATTLELIBRARY_HPP #endif // PKMNLIB_BATTLELIBRARY_HPP

View File

@ -3,8 +3,8 @@
#include "../PkmnScriptHook.hpp" #include "../PkmnScriptHook.hpp"
namespace PkmnLib::Battling { namespace PkmnLib::Battling {
CaptureLibrary::CaptureResult CaptureLibrary::TryCatch(Pokemon* pokemon, Library::Item* catchItem, CaptureLibrary::CaptureResult CaptureLibrary::TryCatch(Pokemon* non_null pokemon, Library::Item* non_null catchItem,
ArbUt::Random* random) const { ArbUt::Random* non_null random) const {
auto hpMax = pokemon->GetMaxHealth(); auto hpMax = pokemon->GetMaxHealth();
auto hpCurrent = pokemon->GetCurrentHealth(); auto hpCurrent = pokemon->GetCurrentHealth();
auto rate = pokemon->GetSpecies()->GetCaptureRate(); auto rate = pokemon->GetSpecies()->GetCaptureRate();

View File

@ -12,9 +12,9 @@ namespace PkmnLib::Battling {
bool WasCritical; bool WasCritical;
}; };
CaptureResult TryCatch(Pokemon* pokemon, Library::Item* catchItem, ArbUt::Random* random) const; CaptureResult TryCatch(Pokemon* non_null pokemon, Library::Item* non_null catchItem,
ArbUt::Random* non_null random) const;
}; };
} }
#endif // PKMNLIB_CAPTURELIBRARY_HPP #endif // PKMNLIB_CAPTURELIBRARY_HPP

View File

@ -9,18 +9,18 @@ namespace PkmnLib::Battling {
public: public:
explicit DamageLibrary(bool hasRandomness = true) : _hasRandomness(hasRandomness) {} explicit DamageLibrary(bool hasRandomness = true) : _hasRandomness(hasRandomness) {}
uint32_t GetDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, uint32_t GetDamage(CreatureLib::Battling::ExecutingAttack* non_null attack,
uint8_t hitIndex, CreatureLib::Battling::Creature* non_null target, uint8_t hitIndex,
const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override; const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override;
uint8_t GetBasePower(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, uint8_t GetBasePower(CreatureLib::Battling::ExecutingAttack* non_null attack,
uint8_t hitIndex, CreatureLib::Battling::Creature* non_null target, uint8_t hitIndex,
const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override; const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override;
float GetStatModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, float GetStatModifier(CreatureLib::Battling::ExecutingAttack* non_null attack,
uint8_t hitIndex, CreatureLib::Battling::Creature* non_null target, uint8_t hitIndex,
const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override; const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override;
float GetDamageModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, float GetDamageModifier(CreatureLib::Battling::ExecutingAttack* non_null attack,
uint8_t hitIndex, CreatureLib::Battling::Creature* non_null target, uint8_t hitIndex,
const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override; const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override;
}; };
} }

View File

@ -8,7 +8,7 @@ namespace PkmnLib::Battling {
class ExperienceLibrary final : public CreatureLib::Battling::ExperienceLibrary { class ExperienceLibrary final : public CreatureLib::Battling::ExperienceLibrary {
public: public:
void HandleExperienceGain( void HandleExperienceGain(
CreatureLib::Battling::Creature* faintedMon, CreatureLib::Battling::Creature* non_null faintedMon,
const std::unordered_set<ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>>& opponents) const override; const std::unordered_set<ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>>& opponents) const override;
}; };
} }

View File

@ -6,8 +6,8 @@
#include "../Pokemon/LearnedMove.hpp" #include "../Pokemon/LearnedMove.hpp"
#include "../Pokemon/Pokemon.hpp" #include "../Pokemon/Pokemon.hpp"
bool PkmnLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack, bool PkmnLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* non_null attack,
CreatureLib::Battling::Creature* target, uint8_t hit) const { CreatureLib::Battling::Creature* non_null target, uint8_t hit) const {
bool preventCrit = false; bool preventCrit = false;
PKMN_HOOK(PreventIncomingCritical, target, attack, target, hit, &preventCrit); PKMN_HOOK(PreventIncomingCritical, target, attack, target, hit, &preventCrit);
if (preventCrit) { if (preventCrit) {
@ -26,13 +26,12 @@ bool PkmnLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::Executing
} }
} }
bool PkmnLib::Battling::MiscLibrary::CanFlee(CreatureLib::Battling::FleeTurnChoice* switchChoice) const { bool PkmnLib::Battling::MiscLibrary::CanFlee(CreatureLib::Battling::FleeTurnChoice* non_null switchChoice) const {
return CreatureLib::Battling::MiscLibrary::CanFlee(switchChoice); return CreatureLib::Battling::MiscLibrary::CanFlee(switchChoice);
} }
CreatureLib::Battling::BaseTurnChoice* CreatureLib::Battling::BaseTurnChoice* non_null PkmnLib::Battling::MiscLibrary::ReplacementAttack(
PkmnLib::Battling::MiscLibrary::ReplacementAttack(CreatureLib::Battling::Creature* user, CreatureLib::Battling::Creature* non_null user, CreatureLib::Battling::CreatureIndex target) const {
CreatureLib::Battling::CreatureIndex target) const {
return new CreatureLib::Battling::AttackTurnChoice(user, GetReplacementAttack(), target); return new CreatureLib::Battling::AttackTurnChoice(user, GetReplacementAttack(), target);
} }

View File

@ -30,12 +30,11 @@ namespace PkmnLib::Battling {
MiscLibrary(std::function<PkmnLib::Library::TimeOfDay()> getTime) : _getTime(getTime) {} MiscLibrary(std::function<PkmnLib::Library::TimeOfDay()> getTime) : _getTime(getTime) {}
~MiscLibrary() override = default; ~MiscLibrary() override = default;
bool IsCritical(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, bool IsCritical(CreatureLib::Battling::ExecutingAttack* non_null attack,
uint8_t hit) const override; CreatureLib::Battling::Creature* non_null target, uint8_t hit) const override;
bool CanFlee(CreatureLib::Battling::FleeTurnChoice* switchChoice) const override; bool CanFlee(CreatureLib::Battling::FleeTurnChoice* non_null switchChoice) const override;
CreatureLib::Battling::BaseTurnChoice* CreatureLib::Battling::BaseTurnChoice* non_null ReplacementAttack(
ReplacementAttack(CreatureLib::Battling::Creature* user, CreatureLib::Battling::Creature* non_null user, CreatureLib::Battling::CreatureIndex target) const override;
CreatureLib::Battling::CreatureIndex target) const override;
bool CanEvolveFromLevelUp(const ArbUt::BorrowedPtr<const PkmnLib::Library::EvolutionData>& evolution, bool CanEvolveFromLevelUp(const ArbUt::BorrowedPtr<const PkmnLib::Library::EvolutionData>& evolution,
const ArbUt::BorrowedPtr<const Pokemon>& pokemon); const ArbUt::BorrowedPtr<const Pokemon>& pokemon);

View File

@ -1,21 +1,21 @@
#include "StatCalculator.hpp" #include "StatCalculator.hpp"
#include "../Pokemon/Pokemon.hpp" #include "../Pokemon/Pokemon.hpp"
uint32_t PkmnLib::Battling::StatCalculator::CalculateHealthStat(const Pokemon* pkmn) const { u32 PkmnLib::Battling::StatCalculator::CalculateHealthStat(const Pokemon* pkmn) const {
uint32_t base = pkmn->GetBaseStat(Library::Statistic::HealthPoints); u32 base = pkmn->GetBaseStat(Library::Statistic::HealthPoints);
uint32_t iv = pkmn->GetIndividualValue(Library::Statistic::HealthPoints); u32 iv = pkmn->GetIndividualValue(Library::Statistic::HealthPoints);
uint32_t ev = pkmn->GetEffortValue(Library::Statistic::HealthPoints); u32 ev = pkmn->GetEffortValue(Library::Statistic::HealthPoints);
uint8_t level = pkmn->GetLevel(); uint8_t level = pkmn->GetLevel();
return static_cast<uint32_t>(((2 * base + iv + static_cast<uint32_t>(ev / 4)) * level) / 100) + level + 10; return static_cast<u32>(((2 * base + iv + static_cast<u32>(ev / 4)) * level) / 100) + level + 10;
} }
uint32_t PkmnLib::Battling::StatCalculator::CalculateOtherStat(const Pokemon* pkmn, u32 PkmnLib::Battling::StatCalculator::CalculateOtherStat(const Pokemon* pkmn,
CreatureLib::Library::Statistic stat) const { CreatureLib::Library::Statistic stat) const {
uint32_t base = pkmn->GetBaseStat(stat); u32 base = pkmn->GetBaseStat(stat);
uint32_t iv = pkmn->GetIndividualValue(stat); u32 iv = pkmn->GetIndividualValue(stat);
uint32_t ev = pkmn->GetEffortValue(stat); u32 ev = pkmn->GetEffortValue(stat);
uint8_t level = pkmn->GetLevel(); uint8_t level = pkmn->GetLevel();
uint32_t unmodified = static_cast<uint32_t>(((2 * base + iv + static_cast<uint32_t>(ev / 4)) * level) / 100) + 5; u32 unmodified = static_cast<u32>(((2 * base + iv + static_cast<u32>(ev / 4)) * level) / 100) + 5;
return static_cast<uint32_t>(unmodified * pkmn->GetNature()->GetStatModifier(stat)); return static_cast<u32>(unmodified * pkmn->GetNature()->GetStatModifier(stat));
} }
float PkmnLib::Battling::StatCalculator::GetStatBoostModifier(const CreatureLib::Battling::Creature* pkmn, float PkmnLib::Battling::StatCalculator::GetStatBoostModifier(const CreatureLib::Battling::Creature* pkmn,
CreatureLib::Library::Statistic stat) const { CreatureLib::Library::Statistic stat) const {
@ -37,33 +37,32 @@ float PkmnLib::Battling::StatCalculator::GetStatBoostModifier(const CreatureLib:
default: throw ArbUt::Exception("Stat boost was out of expected range of -6 till 6."); default: throw ArbUt::Exception("Stat boost was out of expected range of -6 till 6.");
} }
} }
CreatureLib::Library::StatisticSet<uint32_t> CreatureLib::Library::StatisticSet<u32>
PkmnLib::Battling::StatCalculator::CalculateFlatStats(CreatureLib::Battling::Creature* creature) const { PkmnLib::Battling::StatCalculator::CalculateFlatStats(CreatureLib::Battling::Creature* creature) const {
auto pkmn = dynamic_cast<Pokemon*>(creature); auto pkmn = dynamic_cast<Pokemon*>(creature);
return CreatureLib::Library::StatisticSet<uint32_t>(CalculateHealthStat(pkmn), return CreatureLib::Library::StatisticSet<u32>(CalculateHealthStat(pkmn),
CalculateOtherStat(pkmn, Library::Statistic::PhysicalAttack), CalculateOtherStat(pkmn, Library::Statistic::PhysicalAttack),
CalculateOtherStat(pkmn, Library::Statistic::PhysicalDefense), CalculateOtherStat(pkmn, Library::Statistic::PhysicalDefense),
CalculateOtherStat(pkmn, Library::Statistic::SpecialAttack), CalculateOtherStat(pkmn, Library::Statistic::SpecialAttack),
CalculateOtherStat(pkmn, Library::Statistic::SpecialDefense), CalculateOtherStat(pkmn, Library::Statistic::SpecialDefense),
CalculateOtherStat(pkmn, Library::Statistic::Speed)); CalculateOtherStat(pkmn, Library::Statistic::Speed));
} }
CreatureLib::Library::StatisticSet<uint32_t> CreatureLib::Library::StatisticSet<u32>
PkmnLib::Battling::StatCalculator::CalculateBoostedStats(CreatureLib::Battling::Creature* creature) const { PkmnLib::Battling::StatCalculator::CalculateBoostedStats(CreatureLib::Battling::Creature* creature) const {
return CreatureLib::Library::StatisticSet<uint32_t>( return CreatureLib::Library::StatisticSet<u32>(CalculateBoostedStat(creature, Library::Statistic::HealthPoints),
CalculateBoostedStat(creature, Library::Statistic::HealthPoints),
CalculateBoostedStat(creature, Library::Statistic::PhysicalAttack), CalculateBoostedStat(creature, Library::Statistic::PhysicalAttack),
CalculateBoostedStat(creature, Library::Statistic::PhysicalDefense), CalculateBoostedStat(creature, Library::Statistic::PhysicalDefense),
CalculateBoostedStat(creature, Library::Statistic::SpecialAttack), CalculateBoostedStat(creature, Library::Statistic::SpecialAttack),
CalculateBoostedStat(creature, Library::Statistic::SpecialDefense), CalculateBoostedStat(creature, Library::Statistic::SpecialDefense),
CalculateBoostedStat(creature, Library::Statistic::Speed)); CalculateBoostedStat(creature, Library::Statistic::Speed));
} }
uint32_t PkmnLib::Battling::StatCalculator::CalculateFlatStat(CreatureLib::Battling::Creature* creature, u32 PkmnLib::Battling::StatCalculator::CalculateFlatStat(CreatureLib::Battling::Creature* creature,
CreatureLib::Library::Statistic stat) const { CreatureLib::Library::Statistic stat) const {
if (stat == Library::Statistic::HealthPoints) if (stat == Library::Statistic::HealthPoints)
return CalculateHealthStat(dynamic_cast<Pokemon*>(creature)); return CalculateHealthStat(dynamic_cast<Pokemon*>(creature));
return CalculateOtherStat(dynamic_cast<Pokemon*>(creature), stat); return CalculateOtherStat(dynamic_cast<Pokemon*>(creature), stat);
} }
uint32_t PkmnLib::Battling::StatCalculator::CalculateBoostedStat(CreatureLib::Battling::Creature* creature, u32 PkmnLib::Battling::StatCalculator::CalculateBoostedStat(CreatureLib::Battling::Creature* creature,
CreatureLib::Library::Statistic stat) const { CreatureLib::Library::Statistic stat) const {
return creature->GetFlatStat(stat) * GetStatBoostModifier(creature, stat); return creature->GetFlatStat(stat) * GetStatBoostModifier(creature, stat);
} }

View File

@ -9,23 +9,23 @@ namespace PkmnLib::Battling {
class StatCalculator final : public CreatureLib::Battling::BattleStatCalculator { class StatCalculator final : public CreatureLib::Battling::BattleStatCalculator {
protected: protected:
virtual uint32_t CalculateHealthStat(const Pokemon* pkmn) const; virtual u32 CalculateHealthStat(const Pokemon* non_null pkmn) const;
virtual uint32_t CalculateOtherStat(const Pokemon* pkmn, CreatureLib::Library::Statistic stat) const; virtual u32 CalculateOtherStat(const Pokemon* non_null pkmn, CreatureLib::Library::Statistic stat) const;
virtual float GetStatBoostModifier(const CreatureLib::Battling::Creature* pkmn, virtual float GetStatBoostModifier(const CreatureLib::Battling::Creature* non_null pkmn,
CreatureLib::Library::Statistic stat) const; CreatureLib::Library::Statistic stat) const;
public: public:
~StatCalculator() override = default; ~StatCalculator() override = default;
CreatureLib::Library::StatisticSet<uint32_t> CreatureLib::Library::StatisticSet<u32>
CalculateFlatStats(CreatureLib::Battling::Creature* creature) const override; CalculateFlatStats(CreatureLib::Battling::Creature* non_null creature) const override;
CreatureLib::Library::StatisticSet<uint32_t> CreatureLib::Library::StatisticSet<u32>
CalculateBoostedStats(CreatureLib::Battling::Creature* creature) const override; CalculateBoostedStats(CreatureLib::Battling::Creature* non_null creature) const override;
uint32_t CalculateFlatStat(CreatureLib::Battling::Creature* creature, u32 CalculateFlatStat(CreatureLib::Battling::Creature* non_null creature,
CreatureLib::Library::Statistic stat) const override; CreatureLib::Library::Statistic stat) const override;
uint32_t CalculateBoostedStat(CreatureLib::Battling::Creature* creature, u32 CalculateBoostedStat(CreatureLib::Battling::Creature* non_null creature,
CreatureLib::Library::Statistic stat) const override; CreatureLib::Library::Statistic stat) const override;
}; };
} }

View File

@ -3,6 +3,5 @@
#include <CreatureLib/Battling/Models/DamageSource.hpp> #include <CreatureLib/Battling/Models/DamageSource.hpp>
ENUM_WITH_START_VALUE(PkmnDamageSource, uint8_t, ((uint8_t)CreatureLib::Battling::DamageSourceHelper::Highest()) + 1, ENUM_WITH_START_VALUE(PkmnDamageSource, u8, ((u8)CreatureLib::Battling::DamageSourceHelper::Highest()) + 1, Struggle);
Struggle);
#endif // PKMNLIB_PKMNDAMAGESOURCE_HPP #endif // PKMNLIB_PKMNDAMAGESOURCE_HPP

View File

@ -7,7 +7,7 @@ namespace PkmnLib::Battling {
class PkmnItemUseScript : public CreatureLib::Battling::ItemUseScript { class PkmnItemUseScript : public CreatureLib::Battling::ItemUseScript {
public: public:
virtual void ModifyPokeballCatchBonus(Pokemon* pokemon, u8* catchBonus) const { virtual void ModifyPokeballCatchBonus(Pokemon* non_null pokemon, u8* non_null catchBonus) const {
(void)pokemon; (void)pokemon;
(void)catchBonus; (void)catchBonus;
} }

View File

@ -16,28 +16,35 @@ namespace PkmnLib::Battling {
public: public:
PkmnScript(const ArbUt::OptionalBorrowedPtr<void>& owner) : CreatureLib::Battling::BattleScript(owner) {} PkmnScript(const ArbUt::OptionalBorrowedPtr<void>& owner) : CreatureLib::Battling::BattleScript(owner) {}
virtual void PreventIncomingCritical(CreatureLib::Battling::ExecutingAttack* attack, virtual void PreventIncomingCritical(CreatureLib::Battling::ExecutingAttack* non_null attack,
CreatureLib::Battling::Creature* target, uint8_t hit, bool* preventCrit){}; CreatureLib::Battling::Creature* non_null target, u8 hit,
virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, bool* non_null preventCrit){};
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){}; virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* non_null attack,
virtual void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* non_null target, u8 hit,
CreatureLib::Battling::Creature* target, uint8_t hit, u8* non_null critStage){};
float* critModifier){}; virtual void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* non_null attack,
virtual void OverrideSTABModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* non_null target, u8 hit,
CreatureLib::Battling::Creature* target, uint8_t hit, float* stabModifier){}; float* non_null critModifier){};
virtual void OverrideSTABModifier(CreatureLib::Battling::ExecutingAttack* non_null attack,
CreatureLib::Battling::Creature* non_null target, u8 hit,
float* non_null stabModifier){};
virtual void ModifyExperienceGain(CreatureLib::Battling::Creature* faintedMon, virtual void ModifyExperienceGain(CreatureLib::Battling::Creature* non_null faintedMon,
CreatureLib::Battling::Creature* winningMon, uint32_t* experienceGain){}; CreatureLib::Battling::Creature* non_null winningMon,
virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon, uint32_t* non_null experienceGain){};
CreatureLib::Battling::Creature* winningMon, bool* shareExperience){}; virtual void DoesShareExperience(CreatureLib::Battling::Creature* non_null faintedMon,
virtual void BlockWeather(CreatureLib::Battling::Battle* battle, bool* blockWeather){}; CreatureLib::Battling::Creature* non_null winningMon,
bool* non_null shareExperience){};
virtual void BlockWeather(CreatureLib::Battling::Battle* non_null battle, bool* non_null blockWeather){};
virtual void ModifyOffensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack, virtual void ModifyOffensiveStatValue(CreatureLib::Battling::ExecutingAttack* non_null attack,
CreatureLib::Battling::Creature* target, u8 hitIndex, float* modifier){}; CreatureLib::Battling::Creature* non_null target, u8 hitIndex,
virtual void ModifyDefensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack, float* non_null modifier){};
CreatureLib::Battling::Creature* target, u8 hitIndex, float* modifier){}; virtual void ModifyDefensiveStatValue(CreatureLib::Battling::ExecutingAttack* non_null attack,
virtual void ModifyCaptureRateBonus(CreatureLib::Battling::Creature* pokemon, CreatureLib::Battling::Creature* non_null target, u8 hitIndex,
CreatureLib::Library::Item* catchItem, u8* modifier){}; float* non_null modifier){};
virtual void ModifyCaptureRateBonus(CreatureLib::Battling::Creature* non_null pokemon,
CreatureLib::Library::Item* non_null catchItem, u8* non_null modifier){};
}; };
} }

View File

@ -2,6 +2,6 @@
#define PKMNLIB_PKMNSCRIPTCATEGORY_HPP #define PKMNLIB_PKMNSCRIPTCATEGORY_HPP
#include <CreatureLib/Battling/ScriptHandling/ScriptCategory.hpp> #include <CreatureLib/Battling/ScriptHandling/ScriptCategory.hpp>
ENUM_WITH_START_VALUE(PkmnScriptCategory, uint8_t, 128, Weather) ENUM_WITH_START_VALUE(PkmnScriptCategory, u8, 128, Weather)
#endif // PKMNLIB_PKMNSCRIPTCATEGORY_HPP #endif // PKMNLIB_PKMNSCRIPTCATEGORY_HPP

View File

@ -1,6 +1,6 @@
#include "CreatePokemon.hpp" #include "CreatePokemon.hpp"
namespace PkmnLib::Battling { namespace PkmnLib::Battling {
CreatePokemon& CreatePokemon::WithRandomIndividualValues(ArbUt::Random rand) { CreatePokemon& CreatePokemon::WithRandomIndividualValues(ArbUt::Random& rand) {
_ivHp = rand.Get(0, 32); _ivHp = rand.Get(0, 32);
_ivAttack = rand.Get(0, 32); _ivAttack = rand.Get(0, 32);
_ivDefense = rand.Get(0, 32); _ivDefense = rand.Get(0, 32);
@ -10,7 +10,7 @@ namespace PkmnLib::Battling {
return *this; return *this;
} }
CreatePokemon& CreatePokemon::WithIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value) { CreatePokemon& CreatePokemon::WithIndividualValue(CreatureLib::Library::Statistic stat, u8 value) {
switch (stat) { switch (stat) {
case PkmnLib::Library::Statistic::HealthPoints: _ivHp = value; break; case PkmnLib::Library::Statistic::HealthPoints: _ivHp = value; break;
case PkmnLib::Library::Statistic::PhysicalAttack: _ivAttack = value; break; case PkmnLib::Library::Statistic::PhysicalAttack: _ivAttack = value; break;
@ -22,7 +22,7 @@ namespace PkmnLib::Battling {
return *this; return *this;
} }
CreatePokemon& CreatePokemon::WithEffortValue(CreatureLib::Library::Statistic stat, uint8_t value) { CreatePokemon& CreatePokemon::WithEffortValue(CreatureLib::Library::Statistic stat, u8 value) {
switch (stat) { switch (stat) {
case PkmnLib::Library::Statistic::HealthPoints: _evHp = value; break; case PkmnLib::Library::Statistic::HealthPoints: _evHp = value; break;
case PkmnLib::Library::Statistic::PhysicalAttack: _evAttack = value; break; case PkmnLib::Library::Statistic::PhysicalAttack: _evAttack = value; break;
@ -55,7 +55,7 @@ namespace PkmnLib::Battling {
} }
auto identifier = this->_identifier; auto identifier = this->_identifier;
if (identifier == 0) { if (identifier == 0) {
identifier = rand.Get(); identifier = rand.GetUnsigned();
} }
auto gender = this->_gender; auto gender = this->_gender;
if (gender == static_cast<CreatureLib::Library::Gender>(-1)) { if (gender == static_cast<CreatureLib::Library::Gender>(-1)) {
@ -80,9 +80,9 @@ namespace PkmnLib::Battling {
attacks[i] = new LearnedMove(move.GetValue(), kv.LearnMethod); attacks[i] = new LearnedMove(move.GetValue(), kv.LearnMethod);
} }
} }
auto ivs = CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31>(_ivHp, _ivAttack, _ivDefense, _ivSpAtt, auto ivs = CreatureLib::Library::ClampedStatisticSet<u8, 0, 31>(_ivHp, _ivAttack, _ivDefense, _ivSpAtt,
_ivSpDef, _ivSpeed); _ivSpDef, _ivSpeed);
auto evs = CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252>(_evHp, _evAttack, _evDefense, _evSpAtt, auto evs = CreatureLib::Library::ClampedStatisticSet<u8, 0, 252>(_evHp, _evAttack, _evDefense, _evSpAtt,
_evSpDef, _evSpeed); _evSpDef, _evSpeed);
if (_nature.IsEmpty()) { if (_nature.IsEmpty()) {
@ -106,8 +106,7 @@ namespace PkmnLib::Battling {
_nature = nature; _nature = nature;
return *this; return *this;
} }
CreatePokemon& CreatePokemon::WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, CreatePokemon& CreatePokemon::WithIndividualValues(u8 hp, u8 att, u8 def, u8 spAtt, u8 spDef, u8 speed) {
uint8_t spDef, uint8_t speed) {
_ivHp = hp; _ivHp = hp;
_ivAttack = att; _ivAttack = att;
_ivDefense = def; _ivDefense = def;
@ -116,8 +115,7 @@ namespace PkmnLib::Battling {
_ivSpeed = speed; _ivSpeed = speed;
return *this; return *this;
} }
CreatePokemon& CreatePokemon::WithEffortValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef, CreatePokemon& CreatePokemon::WithEffortValues(u8 hp, u8 att, u8 def, u8 spAtt, u8 spDef, u8 speed) {
uint8_t speed) {
_evHp = hp; _evHp = hp;
_evAttack = att; _evAttack = att;
_evDefense = def; _evDefense = def;

View File

@ -15,7 +15,7 @@ namespace PkmnLib::Battling {
ArbUt::StringView _nature; ArbUt::StringView _nature;
CreatureLib::Library::Gender _gender = static_cast<CreatureLib::Library::Gender>(-1); CreatureLib::Library::Gender _gender = static_cast<CreatureLib::Library::Gender>(-1);
ArbUt::StringView _heldItem = ""_cnc; ArbUt::StringView _heldItem = ""_cnc;
uint32_t _identifier = 0; u32 _identifier = 0;
struct ToLearnMethod { struct ToLearnMethod {
ArbUt::OptionalBorrowedPtr<const Library::MoveData> Move; ArbUt::OptionalBorrowedPtr<const Library::MoveData> Move;
@ -25,28 +25,28 @@ namespace PkmnLib::Battling {
: Move(move), LearnMethod(method){}; : Move(move), LearnMethod(method){};
}; };
ArbUt::List<ToLearnMethod> _attacks; ArbUt::List<ToLearnMethod> _attacks;
uint8_t _currentMove = 0; u8 _currentMove = 0;
uint8_t _ivHp = 0; u8 _ivHp = 0;
uint8_t _ivAttack = 0; u8 _ivAttack = 0;
uint8_t _ivDefense = 0; u8 _ivDefense = 0;
uint8_t _ivSpAtt = 0; u8 _ivSpAtt = 0;
uint8_t _ivSpDef = 0; u8 _ivSpDef = 0;
uint8_t _ivSpeed = 0; u8 _ivSpeed = 0;
uint8_t _evHp = 0; u8 _evHp = 0;
uint8_t _evAttack = 0; u8 _evAttack = 0;
uint8_t _evDefense = 0; u8 _evDefense = 0;
uint8_t _evSpAtt = 0; u8 _evSpAtt = 0;
uint8_t _evSpDef = 0; u8 _evSpDef = 0;
uint8_t _evSpeed = 0; u8 _evSpeed = 0;
bool _shininessSet = false; bool _shininessSet = false;
bool _isShiny = false; bool _isShiny = false;
bool _allowedExperienceGain = true; bool _allowedExperienceGain = true;
public: public:
CreatePokemon(const BattleLibrary* library, const ArbUt::StringView& species, uint8_t level) CreatePokemon(const BattleLibrary* library, const ArbUt::StringView& species, u8 level)
: _library(library), _species(species), _level(level), : _library(library), _species(species), _level(level),
_attacks(library->GetSettings()->GetMaximalAttacks()) {} _attacks(library->GetSettings()->GetMaximalAttacks()) {}
@ -56,13 +56,11 @@ namespace PkmnLib::Battling {
CreatePokemon& WithHeldItem(const ArbUt::StringView& item); CreatePokemon& WithHeldItem(const ArbUt::StringView& item);
CreatePokemon& LearnMove(const ArbUt::StringView& move, CreatureLib::Battling::AttackLearnMethod method); CreatePokemon& LearnMove(const ArbUt::StringView& move, CreatureLib::Battling::AttackLearnMethod method);
CreatePokemon& WithRandomIndividualValues(ArbUt::Random rand = ArbUt::Random()); CreatePokemon& WithRandomIndividualValues(ArbUt::Random& rand);
CreatePokemon& WithIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value); CreatePokemon& WithIndividualValue(CreatureLib::Library::Statistic stat, u8 value);
CreatePokemon& WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef, CreatePokemon& WithIndividualValues(u8 hp, u8 att, u8 def, u8 spAtt, u8 spDef, u8 speed);
uint8_t speed); CreatePokemon& WithEffortValue(CreatureLib::Library::Statistic stat, u8 value);
CreatePokemon& WithEffortValue(CreatureLib::Library::Statistic stat, uint8_t value); CreatePokemon& WithEffortValues(u8 hp, u8 att, u8 def, u8 spAtt, u8 spDef, u8 speed);
CreatePokemon& WithEffortValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef,
uint8_t speed);
CreatePokemon& WithNature(const ArbUt::StringView& nature); CreatePokemon& WithNature(const ArbUt::StringView& nature);
CreatePokemon& IsAllowedExperienceGain(bool value); CreatePokemon& IsAllowedExperienceGain(bool value);

View File

@ -1 +0,0 @@
#include "LearnedMove.hpp"

View File

@ -14,7 +14,7 @@ namespace PkmnLib::Battling {
return GetAttack().ForceAs<const Library::MoveData>(); return GetAttack().ForceAs<const Library::MoveData>();
} }
LearnedAttack* Clone() const override { LearnedAttack* non_null Clone() const override {
auto move = new LearnedMove(GetAttack().ForceAs<const Library::MoveData>(), GetLearnMethod()); auto move = new LearnedMove(GetAttack().ForceAs<const Library::MoveData>(), GetLearnMethod());
move->DecreaseUses(GetMaxUses() - GetRemainingUses()); move->DecreaseUses(GetMaxUses() - GetRemainingUses());
return move; return move;

View File

@ -10,23 +10,23 @@
namespace PkmnLib::Battling { namespace PkmnLib::Battling {
class Pokemon : public CreatureLib::Battling::Creature { class Pokemon : public CreatureLib::Battling::Creature {
private: private:
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31> _individualValues; CreatureLib::Library::ClampedStatisticSet<u8, 0, 31> _individualValues;
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252> _effortValues; CreatureLib::Library::ClampedStatisticSet<u8, 0, 252> _effortValues;
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> _nature; ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> _nature;
uint8_t _friendship = 0; u8 _friendship = 0;
bool _isEgg; bool _isEgg;
public: public:
Pokemon(ArbUt::BorrowedPtr<const BattleLibrary> library, Pokemon(ArbUt::BorrowedPtr<const BattleLibrary> library,
const ArbUt::BorrowedPtr<const Library::PokemonSpecies>& species, const ArbUt::BorrowedPtr<const Library::PokemonSpecies>& species,
const ArbUt::BorrowedPtr<const Library::PokemonForme>& forme, level_int_t level, uint32_t experience, const ArbUt::BorrowedPtr<const Library::PokemonForme>& forme, level_int_t level, u32 experience,
uint32_t uid, CreatureLib::Library::Gender gender, uint8_t coloring, u32 uid, CreatureLib::Library::Gender gender, u8 coloring,
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, const std::optional<std::string>& nickname, ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, const std::optional<std::string>& nickname,
const CreatureLib::Library::TalentIndex& talent, const CreatureLib::Library::TalentIndex& talent,
const std::vector<CreatureLib::Battling::LearnedAttack*>& moves, const std::vector<CreatureLib::Battling::LearnedAttack*>& moves,
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31> individualValues, CreatureLib::Library::ClampedStatisticSet<u8, 0, 31> individualValues,
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252> effortValues, CreatureLib::Library::ClampedStatisticSet<u8, 0, 252> effortValues,
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> nature, bool allowedExperienceGain = true, ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> nature, bool allowedExperienceGain = true,
bool isEgg = false) bool isEgg = false)
: CreatureLib::Battling::Creature( : CreatureLib::Battling::Creature(
@ -48,16 +48,14 @@ namespace PkmnLib::Battling {
} }
inline const ArbUt::BorrowedPtr<const PkmnLib::Library::Nature>& GetNature() const noexcept { return _nature; } inline const ArbUt::BorrowedPtr<const PkmnLib::Library::Nature>& GetNature() const noexcept { return _nature; }
inline uint8_t GetIndividualValue(CreatureLib::Library::Statistic stat) const { inline u8 GetIndividualValue(CreatureLib::Library::Statistic stat) const {
return _individualValues.GetStat(stat); return _individualValues.GetStat(stat);
} }
inline void SetIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value) { inline void SetIndividualValue(CreatureLib::Library::Statistic stat, u8 value) {
return _individualValues.SetStat(stat, value); return _individualValues.SetStat(stat, value);
} }
inline uint8_t GetEffortValue(CreatureLib::Library::Statistic stat) const { inline u8 GetEffortValue(CreatureLib::Library::Statistic stat) const { return _effortValues.GetStat(stat); }
return _effortValues.GetStat(stat); inline void SetEffortValue(CreatureLib::Library::Statistic stat, u8 value) {
}
inline void SetEffortValue(CreatureLib::Library::Statistic stat, uint8_t value) {
return _effortValues.SetStat(stat, value); return _effortValues.SetStat(stat, value);
} }
inline bool IsEgg() const noexcept { return _isEgg; } inline bool IsEgg() const noexcept { return _isEgg; }
@ -70,10 +68,10 @@ namespace PkmnLib::Battling {
void Evolve(ArbUt::BorrowedPtr<const Library::PokemonSpecies> mon, void Evolve(ArbUt::BorrowedPtr<const Library::PokemonSpecies> mon,
ArbUt::BorrowedPtr<const Library::PokemonForme> forme); ArbUt::BorrowedPtr<const Library::PokemonForme> forme);
uint8_t GetFriendship() const noexcept { return _friendship; } u8 GetFriendship() const noexcept { return _friendship; }
void SetFriendship(uint8_t value) noexcept { _friendship = value; } void SetFriendship(u8 value) noexcept { _friendship = value; }
void ChangeFriendship(int8_t amount) noexcept { void ChangeFriendship(i8 amount) noexcept {
uint8_t newValue; u8 newValue;
if (__builtin_add_overflow(_friendship, amount, &newValue)) { if (__builtin_add_overflow(_friendship, amount, &newValue)) {
if (amount < 0) if (amount < 0)
newValue = 0; newValue = 0;
@ -85,7 +83,7 @@ namespace PkmnLib::Battling {
bool IsUsable() const noexcept override; bool IsUsable() const noexcept override;
Creature* Clone() const override; Creature* non_null Clone() const override;
}; };
} }

View File

@ -6,9 +6,9 @@
namespace PkmnLib::Battling { namespace PkmnLib::Battling {
class PokemonParty : public CreatureLib::Battling::CreatureParty { class PokemonParty : public CreatureLib::Battling::CreatureParty {
public: public:
PokemonParty(ArbUt::List<CreatureLib::Battling::Creature*> party) PokemonParty(ArbUt::List<CreatureLib::Battling::Creature * nullable> party)
: CreatureLib::Battling::CreatureParty(std::move(party)) {} : CreatureLib::Battling::CreatureParty(std::move(party)) {}
PokemonParty(std::initializer_list<CreatureLib::Battling::Creature*> party) PokemonParty(std::initializer_list<CreatureLib::Battling::Creature* nullable> party)
: CreatureLib::Battling::CreatureParty(party) {} : CreatureLib::Battling::CreatureParty(party) {}
PokemonParty(size_t size) : CreatureLib::Battling::CreatureParty(size) {} PokemonParty(size_t size) : CreatureLib::Battling::CreatureParty(size) {}
@ -16,7 +16,7 @@ namespace PkmnLib::Battling {
return CreatureLib::Battling::CreatureParty::GetAtIndex(index).As<Pokemon>(); return CreatureLib::Battling::CreatureParty::GetAtIndex(index).As<Pokemon>();
} }
CreatureParty* Clone() const override { CreatureParty* non_null Clone() const override {
auto party = new PokemonParty(GetParty().Count()); auto party = new PokemonParty(GetParty().Count());
auto i = 0; auto i = 0;
for (auto c : GetParty()) { for (auto c : GetParty()) {

View File

@ -18,38 +18,42 @@ namespace PkmnLib::Library {
EvolutionMethod _method; EvolutionMethod _method;
ArbUt::UniquePtrList<const CreatureLib::Library::EffectParameter> _evolutionData; ArbUt::UniquePtrList<const CreatureLib::Library::EffectParameter> _evolutionData;
EvolutionData(EvolutionMethod method, std::vector<const CreatureLib::Library::EffectParameter*> data, EvolutionData(EvolutionMethod method, std::vector<const CreatureLib::Library::EffectParameter * non_null> data,
const PokemonSpecies* next) const PokemonSpecies* non_null next)
: _evolvesInto(next), _method(method), _evolutionData(std::move(data)) {} : _evolvesInto(next), _method(method), _evolutionData(std::move(data)) {}
public: public:
~EvolutionData() = default; ~EvolutionData() = default;
static inline const EvolutionData* CreateLevelEvolution(uint8_t level, const PokemonSpecies* into) { static inline const EvolutionData* non_null CreateLevelEvolution(uint8_t level,
const PokemonSpecies* non_null into) {
return new EvolutionData(EvolutionMethod::Level, return new EvolutionData(EvolutionMethod::Level,
{new CreatureLib::Library::EffectParameter((int64_t)level)}, into); {new CreatureLib::Library::EffectParameter((int64_t)level)}, into);
} }
static inline const EvolutionData* CreateFriendshipEvolution(uint8_t friendship, const PokemonSpecies* into) { static inline const EvolutionData* non_null CreateFriendshipEvolution(uint8_t friendship,
const PokemonSpecies* non_null into) {
return new EvolutionData(EvolutionMethod::HighFriendship, return new EvolutionData(EvolutionMethod::HighFriendship,
{new CreatureLib::Library::EffectParameter((int64_t)friendship)}, into); {new CreatureLib::Library::EffectParameter((int64_t)friendship)}, into);
} }
static inline const EvolutionData* CreateFriendshipTimeEvolution(uint8_t friendship, TimeOfDay startTime, static inline const EvolutionData* non_null CreateFriendshipTimeEvolution(uint8_t friendship,
TimeOfDay startTime,
TimeOfDay endTime, TimeOfDay endTime,
const PokemonSpecies* into) { const PokemonSpecies* non_null into) {
return new EvolutionData(EvolutionMethod::HighFriendshipTime, return new EvolutionData(EvolutionMethod::HighFriendshipTime,
{new CreatureLib::Library::EffectParameter((int64_t)friendship), {new CreatureLib::Library::EffectParameter((int64_t)friendship),
new CreatureLib::Library::EffectParameter((int64_t)startTime), new CreatureLib::Library::EffectParameter((int64_t)startTime),
new CreatureLib::Library::EffectParameter((int64_t)endTime)}, new CreatureLib::Library::EffectParameter((int64_t)endTime)},
into); into);
} }
static const EvolutionData* CreateKnownMoveEvolution(const MoveData* move, const PokemonSpecies* into); static const EvolutionData* non_null CreateKnownMoveEvolution(const MoveData* non_null move,
static inline const EvolutionData* CreateLocationEvolution(const ArbUt::StringView& location, const PokemonSpecies* non_null into);
const PokemonSpecies* into) { static inline const EvolutionData* non_null CreateLocationEvolution(const ArbUt::StringView& location,
const PokemonSpecies* non_null into) {
return new EvolutionData(EvolutionMethod::LocationBased, return new EvolutionData(EvolutionMethod::LocationBased,
{new CreatureLib::Library::EffectParameter(location)}, into); {new CreatureLib::Library::EffectParameter(location)}, into);
} }
static inline const EvolutionData* CreateTimeEvolution(TimeOfDay startTime, TimeOfDay endTime, static inline const EvolutionData* non_null CreateTimeEvolution(TimeOfDay startTime, TimeOfDay endTime,
const PokemonSpecies* into) { const PokemonSpecies* non_null into) {
return new EvolutionData(EvolutionMethod::TimeBased, return new EvolutionData(EvolutionMethod::TimeBased,
{ {
new CreatureLib::Library::EffectParameter((int64_t)startTime), new CreatureLib::Library::EffectParameter((int64_t)startTime),
@ -57,29 +61,34 @@ namespace PkmnLib::Library {
}, },
into); into);
} }
static const EvolutionData* CreateHeldItemEvolution(const Item* item, const PokemonSpecies* into); static const EvolutionData* non_null CreateHeldItemEvolution(const Item* non_null item,
static const EvolutionData* CreateHeldItemTimeEvolution(const Item* item, TimeOfDay startTime, const PokemonSpecies* non_null into);
TimeOfDay endTime, const PokemonSpecies* into); static const EvolutionData* non_null CreateHeldItemTimeEvolution(const Item* non_null item, TimeOfDay startTime,
static inline const EvolutionData* CreateGenderBasedEvolution(CreatureLib::Library::Gender gender, TimeOfDay endTime,
uint8_t level, const PokemonSpecies* into) { const PokemonSpecies* non_null into);
static inline const EvolutionData* non_null CreateGenderBasedEvolution(CreatureLib::Library::Gender gender,
uint8_t level,
const PokemonSpecies* non_null into) {
return new EvolutionData(EvolutionMethod::IsGenderAndLevel, return new EvolutionData(EvolutionMethod::IsGenderAndLevel,
{new CreatureLib::Library::EffectParameter((int64_t)gender), {new CreatureLib::Library::EffectParameter((int64_t)gender),
new CreatureLib::Library::EffectParameter((int64_t)level)}, new CreatureLib::Library::EffectParameter((int64_t)level)},
into); into);
} }
static const EvolutionData* CreateItemUseEvolution(const Item* item, const PokemonSpecies* into); static const EvolutionData* non_null CreateItemUseEvolution(const Item* non_null item,
static const EvolutionData* CreateItemUseWithGenderEvolution(const Item* item, const PokemonSpecies* non_null into);
static const EvolutionData* non_null CreateItemUseWithGenderEvolution(const Item* non_null item,
CreatureLib::Library::Gender gender, CreatureLib::Library::Gender gender,
const PokemonSpecies* into); const PokemonSpecies* non_null into);
static inline const EvolutionData* CreateTradeEvolution(const PokemonSpecies* into) { static inline const EvolutionData* non_null CreateTradeEvolution(const PokemonSpecies* non_null into) {
return new EvolutionData(EvolutionMethod::Trade, {}, into); return new EvolutionData(EvolutionMethod::Trade, {}, into);
} }
static const EvolutionData* CreateTradeWithItemEvolution(const Item* item, const PokemonSpecies* into); static const EvolutionData* non_null CreateTradeWithItemEvolution(const Item* non_null item,
static const EvolutionData* CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded, const PokemonSpecies* non_null into);
const PokemonSpecies* into); static const EvolutionData* non_null CreateTradeWithSpeciesEvolution(const PokemonSpecies* non_null traded,
static inline const EvolutionData* const PokemonSpecies* non_null into);
static inline const EvolutionData* non_null
CreateCustomEvolution(const std::vector<const CreatureLib::Library::EffectParameter*>& data, CreateCustomEvolution(const std::vector<const CreatureLib::Library::EffectParameter*>& data,
const PokemonSpecies* into) { const PokemonSpecies* non_null into) {
return new EvolutionData(EvolutionMethod::Custom, data, into); return new EvolutionData(EvolutionMethod::Custom, data, into);
} }

View File

@ -2,9 +2,9 @@
#define PKMNLIB_EVOLUTIONMETHOD_HPP #define PKMNLIB_EVOLUTIONMETHOD_HPP
namespace PkmnLib::Library { namespace PkmnLib::Library {
ENUM(EvolutionMethod, uint8_t, Level, HighFriendship, HighFriendshipTime, KnownMove, LocationBased, TimeBased, ENUM(EvolutionMethod, u8, Level, HighFriendship, HighFriendshipTime, KnownMove, LocationBased, TimeBased, HoldsItem,
HoldsItem, HoldsItemTime, IsGenderAndLevel, EvolutionItemUse, EvolutionItemUseWithGender, Trade, HoldsItemTime, IsGenderAndLevel, EvolutionItemUse, EvolutionItemUseWithGender, Trade, TradeWithHeldItem,
TradeWithHeldItem, TradeWithSpecificPokemon, Custom) TradeWithSpecificPokemon, Custom)
} }
#endif // PKMNLIB_EVOLUTIONMETHOD_HPP #endif // PKMNLIB_EVOLUTIONMETHOD_HPP

View File

@ -1 +0,0 @@
#include "Item.hpp"

View File

@ -4,18 +4,18 @@
#include <CreatureLib/Library/Items/Item.hpp> #include <CreatureLib/Library/Items/Item.hpp>
namespace PkmnLib::Library { namespace PkmnLib::Library {
class Item final : public CreatureLib::Library::Item { class Item final : public CreatureLib::Library::Item {
uint8_t _flingPower; u8 _flingPower;
public: public:
Item(const ArbUt::StringView& name, CreatureLib::Library::ItemCategory category, Item(const ArbUt::StringView& name, CreatureLib::Library::ItemCategory category,
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price, CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
const CreatureLib::Library::SecondaryEffect* effect, const CreatureLib::Library::SecondaryEffect* nullable effect,
const CreatureLib::Library::SecondaryEffect* battleTriggerEffect, const CreatureLib::Library::SecondaryEffect* nullable battleTriggerEffect,
const std::unordered_set<uint32_t>& flags, uint8_t flingPower) noexcept const std::unordered_set<uint32_t>& flags, u8 flingPower) noexcept
: CreatureLib::Library::Item(name, category, battleCategory, price, battleTriggerEffect, effect, flags), : CreatureLib::Library::Item(name, category, battleCategory, price, battleTriggerEffect, effect, flags),
_flingPower(flingPower) {} _flingPower(flingPower) {}
inline uint8_t GetFlingPower() const noexcept { return _flingPower; } inline u8 GetFlingPower() const noexcept { return _flingPower; }
}; };
} }

View File

@ -1 +0,0 @@
#include "ItemLibrary.hpp"

View File

@ -5,13 +5,13 @@
namespace PkmnLib::Library { namespace PkmnLib::Library {
class LibrarySettings final : public CreatureLib::Library::LibrarySettings { class LibrarySettings final : public CreatureLib::Library::LibrarySettings {
uint16_t _shinyRate; u16 _shinyRate;
public: public:
LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves, uint16_t shinyRate) noexcept LibrarySettings(u8 maximalLevel, u8 maximalMoves, u16 shinyRate) noexcept
: CreatureLib::Library::LibrarySettings(maximalLevel, maximalMoves), _shinyRate(shinyRate) {} : CreatureLib::Library::LibrarySettings(maximalLevel, maximalMoves), _shinyRate(shinyRate) {}
uint16_t GetShinyRate() const noexcept { return _shinyRate; } u16 GetShinyRate() const noexcept { return _shinyRate; }
}; };
} }

View File

@ -1,12 +0,0 @@
#include "MoveData.hpp"
PkmnLib::Library::MoveData::MoveData(const ArbUt::StringView& name, uint8_t type,
PkmnLib::Library::MoveCategory category, uint8_t power, uint8_t accuracy,
uint8_t baseUsage, CreatureLib::Library::AttackTarget target, int8_t priority,
const CreatureLib::Library::SecondaryEffect* effect,
std::unordered_set<uint32_t> flags)
: AttackData(name, type, static_cast<CreatureLib::Library::AttackCategory>(category), power, accuracy, baseUsage,
target, priority, effect, std::move(flags)) {}
PkmnLib::Library::MoveCategory PkmnLib::Library::MoveData::GetCategory() const {
return static_cast<PkmnLib::Library::MoveCategory>(AttackData::GetCategory());
}

View File

@ -8,11 +8,15 @@ namespace PkmnLib::Library {
class MoveData final : public CreatureLib::Library::AttackData { class MoveData final : public CreatureLib::Library::AttackData {
private: private:
public: public:
MoveData(const ArbUt::StringView& name, uint8_t type, PkmnLib::Library::MoveCategory category, uint8_t power, MoveData(const ArbUt::StringView& name, u8 type, PkmnLib::Library::MoveCategory category, u8 power, u8 accuracy,
uint8_t accuracy, uint8_t baseUsage, CreatureLib::Library::AttackTarget target, int8_t priority, u8 baseUsage, CreatureLib::Library::AttackTarget target, i8 priority,
const CreatureLib::Library::SecondaryEffect* effect, std::unordered_set<uint32_t> flags); const CreatureLib::Library::SecondaryEffect* nullable effect, std::unordered_set<u32> flags)
: AttackData(name, type, static_cast<CreatureLib::Library::AttackCategory>(category), power, accuracy, baseUsage,
target, priority, effect, std::move(flags)) {};
PkmnLib::Library::MoveCategory GetCategory() const; inline PkmnLib::Library::MoveCategory GetCategory() const {
return static_cast<PkmnLib::Library::MoveCategory>(AttackData::GetCategory());
}
}; };
} }

View File

@ -1 +0,0 @@
#include "MoveLibrary.hpp"

View File

@ -1 +0,0 @@
#include "Nature.hpp"

View File

@ -1 +0,0 @@
#include "NatureLibrary.hpp"

View File

@ -16,10 +16,11 @@ namespace PkmnLib::Library {
public: public:
~PokemonLibrary() override = default; ~PokemonLibrary() override = default;
PokemonLibrary(PkmnLib::Library::LibrarySettings* settings, SpeciesLibrary* species, MoveLibrary* moves, PokemonLibrary(PkmnLib::Library::LibrarySettings* non_null settings, SpeciesLibrary* non_null species,
ItemLibrary* items, CreatureLib::Library::GrowthRateLibrary* growthRates, MoveLibrary* non_null moves, ItemLibrary* non_null items,
CreatureLib::Library::TypeLibrary* typeLibrary, CreatureLib::Library::GrowthRateLibrary* non_null growthRates,
CreatureLib::Library::TalentLibrary* talentLibrary, NatureLibrary* natures) CreatureLib::Library::TypeLibrary* non_null typeLibrary,
CreatureLib::Library::TalentLibrary* non_null talentLibrary, NatureLibrary* non_null natures)
: DataLibrary(settings, species, moves, items, growthRates, typeLibrary, talentLibrary), _natures(natures) { : DataLibrary(settings, species, moves, items, growthRates, typeLibrary, talentLibrary), _natures(natures) {
} }

View File

@ -1 +0,0 @@
#include "LearnableMoves.hpp"

View File

@ -1,12 +0,0 @@
#include "PokemonForme.hpp"
using namespace CreatureLib::Library;
PkmnLib::Library::PokemonForme::PokemonForme(const ArbUt::StringView& name, float height, float weight,
uint32_t baseExperience, const ArbUt::List<uint8_t>& types,
StatisticSet<uint16_t> baseStats,
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
const LearnableMoves* moves, std::unordered_set<uint32_t> flags)
: SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, moves,
std::move(flags)) {}

View File

@ -7,11 +7,13 @@
namespace PkmnLib::Library { namespace PkmnLib::Library {
class PokemonForme final : public CreatureLib::Library::SpeciesVariant { class PokemonForme final : public CreatureLib::Library::SpeciesVariant {
public: public:
PokemonForme(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience, PokemonForme(const ArbUt::StringView& name, float height, float weight, u32 baseExperience,
const ArbUt::List<uint8_t>& types, CreatureLib::Library::StatisticSet<uint16_t> baseStats, const ArbUt::List<u8>& types, CreatureLib::Library::StatisticSet<u16> baseStats,
const ArbUt::List<ArbUt::BorrowedPtr<const CreatureLib::Library::Talent>>& talents, const ArbUt::List<ArbUt::BorrowedPtr<const CreatureLib::Library::Talent>>& talents,
const ArbUt::List<ArbUt::BorrowedPtr<const CreatureLib::Library::Talent>>& secretTalents, const ArbUt::List<ArbUt::BorrowedPtr<const CreatureLib::Library::Talent>>& secretTalents,
const LearnableMoves* moves, std::unordered_set<uint32_t> flags = {}); const LearnableMoves* moves, std::unordered_set<u32> flags = {})
: SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, moves,
std::move(flags)){};
private: private:
public: public:

View File

@ -1 +0,0 @@
#include "PokemonSpecies.hpp"

View File

@ -7,21 +7,21 @@
namespace PkmnLib::Library { namespace PkmnLib::Library {
class PokemonSpecies final : public CreatureLib::Library::CreatureSpecies { class PokemonSpecies final : public CreatureLib::Library::CreatureSpecies {
private: private:
uint8_t _baseHappiness; u8 _baseHappiness;
ArbUt::UniquePtrList<const EvolutionData> _evolutions; ArbUt::UniquePtrList<const EvolutionData> _evolutions;
ArbUt::List<ArbUt::StringView> _eggGroups; ArbUt::List<ArbUt::StringView> _eggGroups;
public: public:
PokemonSpecies(uint16_t id, const ArbUt::StringView& name, const PokemonForme* defaultForme, float genderRatio, PokemonSpecies(u16 id, const ArbUt::StringView& name, const PokemonForme* non_null defaultForme, float genderRatio,
const ArbUt::StringView& growthRate, uint8_t captureRate, uint8_t baseHappiness, const ArbUt::StringView& growthRate, u8 captureRate, u8 baseHappiness,
const ArbUt::List<ArbUt::StringView>& eggGroups, const ArbUt::List<ArbUt::StringView>& eggGroups,
std::unordered_set<uint32_t> flags = {}) noexcept std::unordered_set<u32> flags = {}) noexcept
: CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate, flags), : CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate, flags),
_baseHappiness(baseHappiness), _eggGroups(eggGroups) {} _baseHappiness(baseHappiness), _eggGroups(eggGroups) {}
~PokemonSpecies() override = default; ~PokemonSpecies() override = default;
inline uint8_t GetBaseHappiness() const { return _baseHappiness; } inline u8 GetBaseHappiness() const { return _baseHappiness; }
inline ArbUt::BorrowedPtr<const PokemonForme> GetDefaultForme() const { inline ArbUt::BorrowedPtr<const PokemonForme> GetDefaultForme() const {
return CreatureSpecies::GetVariant("default"_cnc.GetHash()).As<const PokemonForme>(); return CreatureSpecies::GetVariant("default"_cnc.GetHash()).As<const PokemonForme>();
@ -41,7 +41,7 @@ namespace PkmnLib::Library {
return CreatureSpecies::GetVariant(key).As<const PokemonForme>(); return CreatureSpecies::GetVariant(key).As<const PokemonForme>();
} }
inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); } inline void AddEvolution(const EvolutionData* non_null data) noexcept { _evolutions.Append(data); }
const ArbUt::UniquePtrList<const EvolutionData>& GetEvolutions() const noexcept { return _evolutions; } const ArbUt::UniquePtrList<const EvolutionData>& GetEvolutions() const noexcept { return _evolutions; }
bool HasEggGroup(const ArbUt::StringView& sv) const noexcept { return _eggGroups.Contains(sv); } bool HasEggGroup(const ArbUt::StringView& sv) const noexcept { return _eggGroups.Contains(sv); }

View File

@ -7,7 +7,7 @@ namespace PkmnLib::Library {
return tryGet->get(); return tryGet->get();
} }
for (const auto& s : _values) { for (const auto& s : _values) {
const auto* pkmn = dynamic_cast<const PokemonSpecies*>(s.second.get()); const auto* pkmn = dynamic_cast<const PokemonSpecies* nullable>(s.second.get());
if (pkmn == nullptr) { if (pkmn == nullptr) {
continue; continue;
} }

View File

@ -2,7 +2,7 @@
#define PKMNLIB_TIMEOFDAY_HPP #define PKMNLIB_TIMEOFDAY_HPP
namespace PkmnLib::Library { namespace PkmnLib::Library {
ENUM(TimeOfDay, uint8_t, Night, Morning, Afternoon, Evening) ENUM(TimeOfDay, u8, Night, Morning, Afternoon, Evening)
} }
#endif // PKMNLIB_TIMEOFDAY_HPP #endif // PKMNLIB_TIMEOFDAY_HPP

View File

@ -7,12 +7,12 @@
class AngelScriptResolver; class AngelScriptResolver;
class AngelScriptEvolutionScript final : public PkmnLib::Battling::EvolutionScript { class AngelScriptEvolutionScript final : public PkmnLib::Battling::EvolutionScript {
asIScriptObject* _scriptObject; asIScriptObject* non_null _scriptObject;
AngelScriptResolver* _resolver; AngelScriptResolver* non_null _resolver;
struct FunctionInfo { struct FunctionInfo {
bool Exists = false; bool Exists = false;
asIScriptFunction* Function = nullptr; asIScriptFunction* nullable Function = nullptr;
}; };
#define EVO_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl); #define EVO_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl);
@ -30,7 +30,7 @@ class AngelScriptEvolutionScript final : public PkmnLib::Battling::EvolutionScri
"const Pokemon@ pokemon)"); "const Pokemon@ pokemon)");
public: public:
AngelScriptEvolutionScript(asIScriptObject* scriptObject, AngelScriptResolver* resolver) AngelScriptEvolutionScript(asIScriptObject* non_null scriptObject, AngelScriptResolver* non_null resolver)
: _scriptObject(scriptObject), _resolver(resolver) {} : _scriptObject(scriptObject), _resolver(resolver) {}
~AngelScriptEvolutionScript() { ~AngelScriptEvolutionScript() {
@ -41,7 +41,7 @@ public:
void DoesEvolveFromLevelUp(const ArbUt::BorrowedPtr<const PkmnLib::Library::EvolutionData>& evolution, void DoesEvolveFromLevelUp(const ArbUt::BorrowedPtr<const PkmnLib::Library::EvolutionData>& evolution,
const ArbUt::BorrowedPtr<const PkmnLib::Battling::Pokemon>& pokemon, const ArbUt::BorrowedPtr<const PkmnLib::Battling::Pokemon>& pokemon,
bool* out) const override; bool* non_null out) const override;
}; };
#endif // PKMNLIB_ANGELSCRIPTEVOLUTIONSCRIPT_HPP #endif // PKMNLIB_ANGELSCRIPTEVOLUTIONSCRIPT_HPP

View File

@ -321,6 +321,9 @@ void AngelScriptResolver::RegisterScriptType(asITypeInfo* typeInfo, const ArbUt:
} }
} }
void AngelScriptResolver::CreateScript(const std::string& name, const std::string& script) { void AngelScriptResolver::CreateScript(const std::string& name, const std::string& script) {
if (script.empty()) {
return;
}
EnsureGreater(_builder.AddSectionFromMemory(name.c_str(), script.c_str()), 0); EnsureGreater(_builder.AddSectionFromMemory(name.c_str(), script.c_str()), 0);
} }
void AngelScriptResolver::WriteByteCodeToFile(const char* file, bool stripDebugInfo) { void AngelScriptResolver::WriteByteCodeToFile(const char* file, bool stripDebugInfo) {

View File

@ -6,18 +6,18 @@
class FileByteCodeStream : public IPkmnBinaryStream { class FileByteCodeStream : public IPkmnBinaryStream {
private: private:
FILE* _file; FILE* non_null _file;
size_t _readPosition = 0; size_t _readPosition = 0;
public: public:
explicit FileByteCodeStream(FILE* file, size_t bound) : IPkmnBinaryStream(bound), _file(file) {} explicit FileByteCodeStream(FILE* non_null file, size_t bound) : IPkmnBinaryStream(bound), _file(file) {}
int Write(const void* ptr, asUINT size) override { int Write(const void* non_null ptr, asUINT size) override {
if (size == 0) if (size == 0)
return 0; return 0;
return fwrite(ptr, size, 1, _file); return fwrite(ptr, size, 1, _file);
} }
int Read(void* ptr, asUINT size) override { int Read(void* non_null ptr, asUINT size) override {
if (size == 0) if (size == 0)
return 0; return 0;
if (_readPosition + size >= _angelScriptBound) { if (_readPosition + size >= _angelScriptBound) {

View File

@ -14,9 +14,9 @@ protected:
public: public:
virtual void WriteTypes( virtual void WriteTypes(
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*>>& types, const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo* non_null>>& types,
const ArbUt::Dictionary<ArbUt::StringView, asITypeInfo*>& itemUseTypes, const ArbUt::Dictionary<ArbUt::StringView, asITypeInfo* non_null>& itemUseTypes,
const ArbUt::Dictionary<ArbUt::StringView, asITypeInfo*>& evolutionTypes) { const ArbUt::Dictionary<ArbUt::StringView, asITypeInfo* non_null>& evolutionTypes) {
// We serialize our types in the format // We serialize our types in the format
// "[category(byte)][name(str)]\2[decl(str)]\2[name(str)]\2[decl(str)]\1[category(byte)]...." // "[category(byte)][name(str)]\2[decl(str)]\2[name(str)]\2[decl(str)]\1[category(byte)]...."
@ -73,7 +73,7 @@ public:
Write("\1", sizeof(char)); Write("\1", sizeof(char));
} }
virtual ArbUt::Dictionary<i16, ArbUt::Dictionary<ArbUt::StringView, uint32_t>> ReadTypes() { virtual ArbUt::Dictionary<i16, ArbUt::Dictionary<ArbUt::StringView, u32>> ReadTypes() {
_angelScriptBound = SIZE_MAX; _angelScriptBound = SIZE_MAX;
ArbUt::Dictionary<i16, ArbUt::Dictionary<ArbUt::StringView, uint32_t>> types; ArbUt::Dictionary<i16, ArbUt::Dictionary<ArbUt::StringView, uint32_t>> types;
i16 categoryArr[1]; i16 categoryArr[1];

View File

@ -5,7 +5,7 @@
class MemoryByteCodeStream : public IPkmnBinaryStream { class MemoryByteCodeStream : public IPkmnBinaryStream {
private: private:
uint8_t* _out; uint8_t* non_null _out;
size_t _index = 0; size_t _index = 0;
size_t _size = 0; size_t _size = 0;
size_t _capacity = 0; size_t _capacity = 0;
@ -15,14 +15,14 @@ private:
public: public:
MemoryByteCodeStream() MemoryByteCodeStream()
: IPkmnBinaryStream(SIZE_MAX), _out((uint8_t*)malloc(MEM_STEPS * sizeof(uint8_t))), _capacity(MEM_STEPS){}; : IPkmnBinaryStream(SIZE_MAX), _out((uint8_t*)malloc(MEM_STEPS * sizeof(uint8_t))), _capacity(MEM_STEPS){};
MemoryByteCodeStream(uint8_t* in, size_t size) : IPkmnBinaryStream(SIZE_MAX), _out(in), _size(size) {} MemoryByteCodeStream(uint8_t* non_null in, size_t size) : IPkmnBinaryStream(SIZE_MAX), _out(in), _size(size) {}
uint8_t* GetOut() const { return _out; } uint8_t* non_null GetOut() const { return _out; }
size_t GetWrittenSize() const { return _size; } size_t GetWrittenSize() const { return _size; }
void SetAngelScriptBound(size_t bound) noexcept { _angelScriptBound = bound; } void SetAngelScriptBound(size_t bound) noexcept { _angelScriptBound = bound; }
int Write(const void* ptr, asUINT size) final { int Write(const void* non_null ptr, asUINT size) final {
if (size == 0) if (size == 0)
return 0; return 0;
auto initialSize = _size; auto initialSize = _size;
@ -42,14 +42,14 @@ public:
return size; return size;
} }
void WriteToPosition(const void* ptr, asUINT size, size_t position) { void WriteToPosition(const void* non_null ptr, asUINT size, size_t position) {
auto start = reinterpret_cast<const uint8_t*>(ptr); auto start = reinterpret_cast<const uint8_t*>(ptr);
for (asUINT index = 0; index < size; index++) { for (asUINT index = 0; index < size; index++) {
_out[position + index] = *(start + index); _out[position + index] = *(start + index);
} }
} }
int Read(void* ptr, asUINT size) final { int Read(void* non_null ptr, asUINT size) final {
if (size == 0) if (size == 0)
return 0; return 0;
auto toRead = size; auto toRead = size;

View File

@ -1,11 +1,12 @@
#ifndef PKMNLIB_BASICSCRIPTCLASS_HPP #ifndef PKMNLIB_BASICSCRIPTCLASS_HPP
#define PKMNLIB_BASICSCRIPTCLASS_HPP #define PKMNLIB_BASICSCRIPTCLASS_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class BasicScriptClass { class BasicScriptClass {
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_BASICSCRIPTCLASS_HPP #endif // PKMNLIB_BASICSCRIPTCLASS_HPP

View File

@ -1,24 +1,22 @@
#include "RegisterBattleClass.hpp" #include "RegisterBattleClass.hpp"
#include <CreatureLib/Battling/Models/Battle.hpp> #include <CreatureLib/Battling/Models/Battle.hpp>
#include <CreatureLib/Battling/Models/BattleSide.hpp> #include <CreatureLib/Battling/Models/BattleSide.hpp>
#include <type_traits>
#include <scripthandle/scripthandle.h> #include <scripthandle/scripthandle.h>
#include <type_traits>
#include "../../../../Battling/Battle/Battle.hpp" #include "../../../../Battling/Battle/Battle.hpp"
#include "../../../../Battling/Pokemon/Pokemon.hpp" #include "../../../../Battling/Pokemon/Pokemon.hpp"
#include "../../AngelScriptResolver.hpp" #include "../../AngelScriptResolver.hpp"
#include "../../AngelScriptScript.hpp"
#include "../../AngelscriptUserdata.hpp" #include "../../AngelscriptUserdata.hpp"
#include "../HelperFile.hpp" #include "../HelperFile.hpp"
#include "../NativeArray.hpp"
void RegisterBattleClass::Register(asIScriptEngine* engine) { void RegisterBattleClass::Register(asIScriptEngine* non_null engine) {
RegisterChoiceQueue(engine); RegisterChoiceQueue(engine);
RegisterBattleRandom(engine); RegisterBattleRandom(engine);
RegisterBattleSide(engine); RegisterBattleSide(engine);
RegisterBattle(engine); RegisterBattle(engine);
} }
void RegisterBattleClass::RegisterChoiceQueue(asIScriptEngine* engine) { void RegisterBattleClass::RegisterChoiceQueue(asIScriptEngine* non_null engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("ChoiceQueue", 0, asOBJ_REF | asOBJ_NOCOUNT); [[maybe_unused]] int r = engine->RegisterObjectType("ChoiceQueue", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod("ChoiceQueue", "bool MovePokemonChoiceNext(Pokemon@ target)", r = engine->RegisterObjectMethod("ChoiceQueue", "bool MovePokemonChoiceNext(Pokemon@ target)",
@ -33,7 +31,7 @@ void RegisterBattleClass::RegisterChoiceQueue(asIScriptEngine* engine) {
Ensure(r >= 0); Ensure(r >= 0);
} }
void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* engine) { void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* non_null engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("BattleRandom", 0, asOBJ_REF | asOBJ_NOCOUNT); [[maybe_unused]] int r = engine->RegisterObjectType("BattleRandom", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod("BattleRandom", r = engine->RegisterObjectMethod("BattleRandom",
@ -54,15 +52,20 @@ void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* engine) {
Ensure(r >= 0); Ensure(r >= 0);
} }
CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battle* battle, u8 index) { CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battle* non_null battle, u8 index) {
EnsureNotNull(battle);
return battle->GetSides()[index]; return battle->GetSides()[index];
} }
CreatureLib::Battling::BattleParty* GetPartyWrapper(PkmnLib::Battling::Battle* battle, u8 index) { CreatureLib::Battling::BattleParty* GetPartyWrapper(PkmnLib::Battling::Battle* non_null battle, u8 index) {
EnsureNotNull(battle);
return battle->GetParties()[index]; return battle->GetParties()[index];
} }
CreatureLib::Battling::BattleParty* FindPartyWrapper(PkmnLib::Battling::Battle* battle, PkmnLib::Battling::Pokemon* p) { CreatureLib::Battling::BattleParty* FindPartyWrapper(PkmnLib::Battling::Battle* non_null battle,
PkmnLib::Battling::Pokemon* non_null p) {
EnsureNotNull(battle);
EnsureNotNull(p);
auto v = battle->FindPartyForCreature(p); auto v = battle->FindPartyForCreature(p);
if (v.HasValue()) { if (v.HasValue()) {
return v.GetValue(); return v.GetValue();
@ -70,7 +73,8 @@ CreatureLib::Battling::BattleParty* FindPartyWrapper(PkmnLib::Battling::Battle*
return {}; return {};
} }
static CScriptHandle Battle_AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) { static CScriptHandle Battle_AddVolatileWrapper(PkmnLib::Battling::Battle* non_null obj, const ArbUt::StringView& name) {
EnsureNotNull(obj);
auto handle = CScriptHandle(); auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get()); auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject(); auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
@ -78,7 +82,8 @@ static CScriptHandle Battle_AddVolatileWrapper(PkmnLib::Battling::Battle* obj, c
return handle; return handle;
} }
static CScriptHandle Battle_GetVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) { static CScriptHandle Battle_GetVolatileWrapper(PkmnLib::Battling::Battle* non_null obj, const ArbUt::StringView& name) {
EnsureNotNull(obj);
auto handle = CScriptHandle(); auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get()); auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
auto* s = static_cast<AngelScriptScript*>(obj->GetVolatileScript(name).GetValue()); auto* s = static_cast<AngelScriptScript*>(obj->GetVolatileScript(name).GetValue());
@ -90,8 +95,9 @@ static CScriptHandle Battle_GetVolatileWrapper(PkmnLib::Battling::Battle* obj, c
return handle; return handle;
} }
static CScriptHandle BattleSide_AddVolatileWrapper(CreatureLib::Battling::BattleSide* obj, static CScriptHandle BattleSide_AddVolatileWrapper(CreatureLib::Battling::BattleSide* non_null obj,
const ArbUt::StringView& name) { const ArbUt::StringView& name) {
EnsureNotNull(obj);
auto handle = CScriptHandle(); auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetBattle()->GetLibrary()->GetScriptResolver().get()); auto* resolver = static_cast<AngelScriptResolver*>(obj->GetBattle()->GetLibrary()->GetScriptResolver().get());
auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject(); auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
@ -99,31 +105,37 @@ static CScriptHandle BattleSide_AddVolatileWrapper(CreatureLib::Battling::Battle
return handle; return handle;
} }
static CScriptHandle BattleSide_GetVolatileWrapper(CreatureLib::Battling::BattleSide* obj, static CScriptHandle BattleSide_GetVolatileWrapper(CreatureLib::Battling::BattleSide* non_null obj,
const ArbUt::StringView& name) { const ArbUt::StringView& name) {
EnsureNotNull(obj);
auto handle = CScriptHandle(); auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetBattle()->GetLibrary()->GetScriptResolver().get()); auto* resolver = static_cast<AngelScriptResolver*>(obj->GetBattle()->GetLibrary()->GetScriptResolver().get());
auto* s = static_cast<AngelScriptScript*>(obj->GetVolatileScript(name).GetValue()); auto s = obj->GetVolatileScript(name).ForceAs<AngelScriptScript>();
if (s == nullptr) { if (!s.HasValue()) {
return handle; return handle;
} }
auto* script = s->GetRawAngelscriptObject(); auto* script = s.GetValue()->GetRawAngelscriptObject();
handle.Set(script, resolver->GetBaseType("PkmnScript")); handle.Set(script, resolver->GetBaseType("PkmnScript"));
return handle; return handle;
} }
static bool Battle_HasVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) { static bool Battle_HasVolatileWrapper(PkmnLib::Battling::Battle* non_null obj, const ArbUt::StringView& name) {
EnsureNotNull(obj);
return obj->HasVolatileScript(name); return obj->HasVolatileScript(name);
} }
static bool BattleSide_HasVolatileWrapper(CreatureLib::Battling::BattleSide* obj, const ArbUt::StringView& name) { static bool BattleSide_HasVolatileWrapper(CreatureLib::Battling::BattleSide* non_null obj,
const ArbUt::StringView& name) {
EnsureNotNull(obj);
return obj->HasVolatileScript(name); return obj->HasVolatileScript(name);
} }
static u8 GetPokemonIndexWrapper(CreatureLib::Battling::BattleSide* obj, PkmnLib::Battling::Pokemon* pokemon) { static u8 GetPokemonIndexWrapper(CreatureLib::Battling::BattleSide* non_null obj, PkmnLib::Battling::Pokemon* pokemon) {
EnsureNotNull(obj);
return obj->GetCreatureIndex(pokemon); return obj->GetCreatureIndex(pokemon);
} }
static PkmnLib::Battling::Pokemon* GetPokemonWrapper(CreatureLib::Battling::BattleSide* obj, u8 index) { static PkmnLib::Battling::Pokemon* GetPokemonWrapper(CreatureLib::Battling::BattleSide* non_null obj, u8 index) {
EnsureNotNull(obj);
return dynamic_cast<PkmnLib::Battling::Pokemon*>(obj->GetCreature(index).GetValue()); return dynamic_cast<PkmnLib::Battling::Pokemon*>(obj->GetCreature(index).GetValue());
} }

View File

@ -1,15 +1,17 @@
#ifndef PKMNLIB_REGISTERBATTLECLASS_HPP #ifndef PKMNLIB_REGISTERBATTLECLASS_HPP
#define PKMNLIB_REGISTERBATTLECLASS_HPP #define PKMNLIB_REGISTERBATTLECLASS_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterBattleClass { class RegisterBattleClass {
static void RegisterChoiceQueue(asIScriptEngine* engine); static void RegisterChoiceQueue(asIScriptEngine* non_null engine);
static void RegisterBattle(asIScriptEngine* engine); static void RegisterBattle(asIScriptEngine* non_null engine);
static void RegisterBattleSide(asIScriptEngine* engine); static void RegisterBattleSide(asIScriptEngine* non_null engine);
static void RegisterBattleRandom(asIScriptEngine* engine); static void RegisterBattleRandom(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERBATTLECLASS_HPP #endif // PKMNLIB_REGISTERBATTLECLASS_HPP

View File

@ -1,13 +1,14 @@
#ifndef PKMNLIB_REGISTERBATTLEHISTORY_HPP #ifndef PKMNLIB_REGISTERBATTLEHISTORY_HPP
#define PKMNLIB_REGISTERBATTLEHISTORY_HPP #define PKMNLIB_REGISTERBATTLEHISTORY_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterBattleHistory { class RegisterBattleHistory {
static void RegisterHistoryElement(asIScriptEngine* engine); static void RegisterHistoryElement(asIScriptEngine* non_null engine);
static void RegisterHistoryHolder(asIScriptEngine* engine); static void RegisterHistoryHolder(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERBATTLEHISTORY_HPP #endif // PKMNLIB_REGISTERBATTLEHISTORY_HPP

View File

@ -1,14 +1,15 @@
#ifndef PKMNLIB_REGISTERBATTLELIBRARY_HPP #ifndef PKMNLIB_REGISTERBATTLELIBRARY_HPP
#define PKMNLIB_REGISTERBATTLELIBRARY_HPP #define PKMNLIB_REGISTERBATTLELIBRARY_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterBattleLibrary { class RegisterBattleLibrary {
static void RegisterDamageLibrary(asIScriptEngine* engine); static void RegisterDamageLibrary(asIScriptEngine* non_null engine);
static void RegisterLibrary(asIScriptEngine* engine); static void RegisterLibrary(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERBATTLELIBRARY_HPP #endif // PKMNLIB_REGISTERBATTLELIBRARY_HPP

View File

@ -1,14 +1,15 @@
#ifndef PKMNLIB_REGISTEREXECUTINGATTACK_HPP #ifndef PKMNLIB_REGISTEREXECUTINGATTACK_HPP
#define PKMNLIB_REGISTEREXECUTINGATTACK_HPP #define PKMNLIB_REGISTEREXECUTINGATTACK_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterExecutingAttack { class RegisterExecutingAttack {
static void RegisterHitData(asIScriptEngine* engine); static void RegisterHitData(asIScriptEngine* non_null engine);
static void RegisterExecutingAttackType(asIScriptEngine* engine); static void RegisterExecutingAttackType(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTEREXECUTINGATTACK_HPP #endif // PKMNLIB_REGISTEREXECUTINGATTACK_HPP

View File

@ -1,13 +1,14 @@
#ifndef PKMNLIB_REGISTERPARTY_HPP #ifndef PKMNLIB_REGISTERPARTY_HPP
#define PKMNLIB_REGISTERPARTY_HPP #define PKMNLIB_REGISTERPARTY_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterParty { class RegisterParty {
static void RegisterPartyClass(asIScriptEngine* engine); static void RegisterPartyClass(asIScriptEngine* non_null engine);
static void RegisterBattleParty(asIScriptEngine* engine); static void RegisterBattleParty(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERPARTY_HPP #endif // PKMNLIB_REGISTERPARTY_HPP

View File

@ -73,12 +73,15 @@ static const ArbUt::StringView& GetActiveAbilityWrapper(PkmnLib::Battling::Pokem
static size_t GetTypesLengthWrapper(PkmnLib::Battling::Pokemon* p) { return p->GetTypes().size(); } static size_t GetTypesLengthWrapper(PkmnLib::Battling::Pokemon* p) { return p->GetTypes().size(); }
static uint8_t GetTypeWrapper(PkmnLib::Battling::Pokemon* p, size_t index) { return p->GetTypes()[index]; } static uint8_t GetTypeWrapper(PkmnLib::Battling::Pokemon* p, size_t index) { return p->GetTypes()[index]; }
#if defined(__clang__)
// Angelscript aligns this wrong (aligned on 4 bytes, wants 8). While this is a slight performance hit, we can ignore it for now.
[[clang::no_sanitize("alignment")]]
#endif
static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const ArbUt::StringView& name) { static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const ArbUt::StringView& name) {
auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get()); auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject(); auto* script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
handle.Set(script, resolver->GetBaseType("PkmnScript"));
return handle; return {script, resolver->GetBaseType("PkmnScript")};
} }
static bool HasTypeStringWrapper(PkmnLib::Battling::Pokemon* p, const ArbUt::StringView& sv) { static bool HasTypeStringWrapper(PkmnLib::Battling::Pokemon* p, const ArbUt::StringView& sv) {
@ -190,7 +193,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Pokemon", "bool HasVolatile(const constString &in name) const", r = engine->RegisterObjectMethod("Pokemon", "bool HasVolatile(const constString &in name) const",
asMETHOD(PkmnLib::Battling::Pokemon, HasVolatileScript), asCALL_THISCALL); asMETHOD(PkmnLib::Battling::Pokemon, HasVolatileScript), asCALL_THISCALL);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "ref@ AddVolatile(const constString &in name)", r = engine->RegisterObjectMethod("Pokemon", "ref AddVolatile(const constString &in name)",
asFUNCTION(AddVolatileWrapper), asCALL_CDECL_OBJFIRST); asFUNCTION(AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(

View File

@ -1,16 +1,17 @@
#ifndef PKMNLIB_REGISTERPOKEMONCLASS_HPP #ifndef PKMNLIB_REGISTERPOKEMONCLASS_HPP
#define PKMNLIB_REGISTERPOKEMONCLASS_HPP #define PKMNLIB_REGISTERPOKEMONCLASS_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterPokemonClass { class RegisterPokemonClass {
static void RegisterDamageSource(asIScriptEngine* engine); static void RegisterDamageSource(asIScriptEngine* non_null engine);
static void RegisterMoveLearnMethod(asIScriptEngine* engine); static void RegisterMoveLearnMethod(asIScriptEngine* non_null engine);
static void RegisterLearnedAttack(asIScriptEngine* engine); static void RegisterLearnedAttack(asIScriptEngine* non_null engine);
static void RegisterPokemonType(asIScriptEngine* engine); static void RegisterPokemonType(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERPOKEMONCLASS_HPP #endif // PKMNLIB_REGISTERPOKEMONCLASS_HPP

View File

@ -1,17 +1,18 @@
#ifndef PKMNLIB_REGISTERTURNCHOICES_HPP #ifndef PKMNLIB_REGISTERTURNCHOICES_HPP
#define PKMNLIB_REGISTERTURNCHOICES_HPP #define PKMNLIB_REGISTERTURNCHOICES_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterTurnChoices { class RegisterTurnChoices {
static void RegisterTurnChoiceKindEnum(asIScriptEngine* engine); static void RegisterTurnChoiceKindEnum(asIScriptEngine* non_null engine);
static void RegisterBaseTurnChoice(asIScriptEngine* engine); static void RegisterBaseTurnChoice(asIScriptEngine* non_null engine);
static void RegisterMoveTurnChoice(asIScriptEngine* engine); static void RegisterMoveTurnChoice(asIScriptEngine* non_null engine);
static void RegisterSwitchTurnChoice(asIScriptEngine* engine); static void RegisterSwitchTurnChoice(asIScriptEngine* non_null engine);
static void RegisterFleeTurnChoice(asIScriptEngine* engine); static void RegisterFleeTurnChoice(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERTURNCHOICES_HPP #endif // PKMNLIB_REGISTERTURNCHOICES_HPP

View File

@ -1,11 +1,12 @@
#ifndef PKMNLIB_CONSTSTRING_HPP #ifndef PKMNLIB_CONSTSTRING_HPP
#define PKMNLIB_CONSTSTRING_HPP #define PKMNLIB_CONSTSTRING_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class ConstStringRegister { class ConstStringRegister {
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_CONSTSTRING_HPP #endif // PKMNLIB_CONSTSTRING_HPP

View File

@ -1,11 +1,12 @@
#ifndef PKMNLIB_REGISTEREFFECTPARAMETER_HPP #ifndef PKMNLIB_REGISTEREFFECTPARAMETER_HPP
#define PKMNLIB_REGISTEREFFECTPARAMETER_HPP #define PKMNLIB_REGISTEREFFECTPARAMETER_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterEffectParameter { class RegisterEffectParameter {
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTEREFFECTPARAMETER_HPP #endif // PKMNLIB_REGISTEREFFECTPARAMETER_HPP

View File

@ -1,14 +1,15 @@
#ifndef PKMNLIB_REGISTERGROWTHRATETYPES_HPP #ifndef PKMNLIB_REGISTERGROWTHRATETYPES_HPP
#define PKMNLIB_REGISTERGROWTHRATETYPES_HPP #define PKMNLIB_REGISTERGROWTHRATETYPES_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterGrowthRateTypes { class RegisterGrowthRateTypes {
static void RegisterGrowthRateType(asIScriptEngine* engine); static void RegisterGrowthRateType(asIScriptEngine* non_null engine);
static void RegisterGrowthRateLibrary(asIScriptEngine* engine); static void RegisterGrowthRateLibrary(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERGROWTHRATETYPES_HPP #endif // PKMNLIB_REGISTERGROWTHRATETYPES_HPP

View File

@ -1,16 +1,17 @@
#ifndef PKMNLIB_REGISTERITEMTYPES_HPP #ifndef PKMNLIB_REGISTERITEMTYPES_HPP
#define PKMNLIB_REGISTERITEMTYPES_HPP #define PKMNLIB_REGISTERITEMTYPES_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterItemTypes { class RegisterItemTypes {
static void RegisterItemCategoryEnum(asIScriptEngine* engine); static void RegisterItemCategoryEnum(asIScriptEngine* non_null engine);
static void RegisterBattleItemCategoryEnum(asIScriptEngine* engine); static void RegisterBattleItemCategoryEnum(asIScriptEngine* non_null engine);
static void RegisterItemType(asIScriptEngine* engine); static void RegisterItemType(asIScriptEngine* non_null engine);
static void RegisterItemLibrary(asIScriptEngine* engine); static void RegisterItemLibrary(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERITEMTYPES_HPP #endif // PKMNLIB_REGISTERITEMTYPES_HPP

View File

@ -1,16 +1,17 @@
#ifndef PKMNLIB_REGISTERMOVETYPES_HPP #ifndef PKMNLIB_REGISTERMOVETYPES_HPP
#define PKMNLIB_REGISTERMOVETYPES_HPP #define PKMNLIB_REGISTERMOVETYPES_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterMoveTypes { class RegisterMoveTypes {
static void RegisterMoveCategory(asIScriptEngine* engine); static void RegisterMoveCategory(asIScriptEngine* non_null engine);
static void RegisterMoveTarget(asIScriptEngine* engine); static void RegisterMoveTarget(asIScriptEngine* non_null engine);
static void RegisterMoveType(asIScriptEngine* engine); static void RegisterMoveType(asIScriptEngine* non_null engine);
static void RegisterMoveLibrary(asIScriptEngine* engine); static void RegisterMoveLibrary(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERMOVETYPES_HPP #endif // PKMNLIB_REGISTERMOVETYPES_HPP

View File

@ -1,19 +1,20 @@
#ifndef PKMNLIB_REGISTERSPECIESTYPES_HPP #ifndef PKMNLIB_REGISTERSPECIESTYPES_HPP
#define PKMNLIB_REGISTERSPECIESTYPES_HPP #define PKMNLIB_REGISTERSPECIESTYPES_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterSpeciesTypes { class RegisterSpeciesTypes {
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
private: private:
static void RegisterGenderEnum(asIScriptEngine* engine); static void RegisterGenderEnum(asIScriptEngine* non_null engine);
static void RegisterStatisticEnum(asIScriptEngine* engine); static void RegisterStatisticEnum(asIScriptEngine* non_null engine);
static void RegisterSpeciesType(asIScriptEngine* engine); static void RegisterSpeciesType(asIScriptEngine* non_null engine);
static void RegisterFormeType(asIScriptEngine* engine); static void RegisterFormeType(asIScriptEngine* non_null engine);
static void RegisterEvolutionData(asIScriptEngine* engine); static void RegisterEvolutionData(asIScriptEngine* non_null engine);
static void RegisterSpeciesLibrary(asIScriptEngine* engine); static void RegisterSpeciesLibrary(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERSPECIESTYPES_HPP #endif // PKMNLIB_REGISTERSPECIESTYPES_HPP

View File

@ -1,14 +1,15 @@
#ifndef PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP #ifndef PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP
#define PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP #define PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterStaticLibraryTypes { class RegisterStaticLibraryTypes {
static void RegisterLibrarySettingsType(asIScriptEngine* engine); static void RegisterLibrarySettingsType(asIScriptEngine* non_null engine);
static void RegisterLibraryType(asIScriptEngine* engine); static void RegisterLibraryType(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP #endif // PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP

View File

@ -1,13 +1,14 @@
#ifndef PKMNLIB_REGISTERTYPELIBRARY_HPP #ifndef PKMNLIB_REGISTERTYPELIBRARY_HPP
#define PKMNLIB_REGISTERTYPELIBRARY_HPP #define PKMNLIB_REGISTERTYPELIBRARY_HPP
#include <CreatureLib/Defines.hpp>
#include <angelscript.h> #include <angelscript.h>
class RegisterTypeLibrary { class RegisterTypeLibrary {
static void RegisterTypeLibraryType(asIScriptEngine* engine); static void RegisterTypeLibraryType(asIScriptEngine* non_null engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* non_null engine);
}; };
#endif // PKMNLIB_REGISTERTYPELIBRARY_HPP #endif // PKMNLIB_REGISTERTYPELIBRARY_HPP

View File

@ -8,7 +8,7 @@
template <typename T> class NativeArray { template <typename T> class NativeArray {
private: private:
const T* _array; const T* non_null _array;
std::atomic<u64> _refCount; std::atomic<u64> _refCount;
void AddRef() { _refCount++; } void AddRef() { _refCount++; }
@ -20,13 +20,13 @@ private:
~NativeArray() = default; ~NativeArray() = default;
public: public:
explicit NativeArray(const T* array) : _array(array), _refCount(1) {} explicit NativeArray(const T* non_null array) : _array(array), _refCount(1) {}
size_t Length() const { return _array->Count(); } size_t Length() const { return _array->Count(); }
[[nodiscard]] void* At(size_t index) { return _array->At(index).GetRaw(); } [[nodiscard]] void* nullable At(size_t index) { return _array->At(index).GetRaw(); }
static void Register(asIScriptEngine* engine) { static void Register(asIScriptEngine* non_null engine) {
Ensure(engine->RegisterObjectType("narray<class T>", sizeof(NativeArray), asOBJ_REF | asOBJ_TEMPLATE) >= 0); Ensure(engine->RegisterObjectType("narray<class T>", sizeof(NativeArray), asOBJ_REF | asOBJ_TEMPLATE) >= 0);
Ensure(engine->RegisterObjectBehaviour("narray<T>", asBEHAVE_ADDREF, "void f()", asMETHOD(NativeArray, AddRef), Ensure(engine->RegisterObjectBehaviour("narray<T>", asBEHAVE_ADDREF, "void f()", asMETHOD(NativeArray, AddRef),

View File

@ -1,6 +1,8 @@
#ifndef PKMNLIB_REFCAST_HPP #ifndef PKMNLIB_REFCAST_HPP
#define PKMNLIB_REFCAST_HPP #define PKMNLIB_REFCAST_HPP
template <class A, class B> B* refCast(A* a) { #include <CreatureLib/Defines.hpp>
template <class A, class B> B* nullable refCast(A* nullable a) {
if (!a) if (!a)
return 0; return 0;
B* b = dynamic_cast<B*>(a); B* b = dynamic_cast<B*>(a);