Update CreatureLib.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-05-27 17:26:25 +02:00
parent 0d111739f4
commit f42ce8865d
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
53 changed files with 316 additions and 269 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/cmake-build-debug/ /cmake-build-debug/
/cmake-build-release/ /cmake-build-release/
/build-release-windows/
/.idea/ /.idea/

View File

@ -15,7 +15,7 @@ export uint8_t PkmnLib_AngelScriptResolver_CreateScript(AngelScriptResolver* p,
export uint8_t PkmnLib_AngelScriptResolver_FinalizeModule(AngelScriptResolver* p) { Try(p->FinalizeModule();) } export uint8_t PkmnLib_AngelScriptResolver_FinalizeModule(AngelScriptResolver* p) { Try(p->FinalizeModule();) }
export uint8_t PkmnLib_AngelScriptResolver_LoadScript(CreatureLib::Battling::Script*& out, AngelScriptResolver* p, export uint8_t PkmnLib_AngelScriptResolver_LoadScript(CreatureLib::Battling::Script*& out, AngelScriptResolver* p,
ScriptCategory category, const char* scriptName) { ScriptCategory category, const char* scriptName) {
Try(out = p->LoadScript(category, Arbutils::CaseInsensitiveConstString(scriptName));) Try(out = p->LoadScript(category, ArbUt::CaseInsensitiveConstString(scriptName));)
} }
export uint8_t PkmnLib_AngelScriptResolver_WriteByteCodeToFile(AngelScriptResolver* p, const char* file, export uint8_t PkmnLib_AngelScriptResolver_WriteByteCodeToFile(AngelScriptResolver* p, const char* file,
bool stripDebugInfo) { bool stripDebugInfo) {

View File

@ -5,13 +5,13 @@ using namespace PkmnLib::Battling;
export uint8_t PkmnLib_Battle_Construct(Battle*& out, const BattleLibrary* library, export uint8_t PkmnLib_Battle_Construct(Battle*& out, const BattleLibrary* library,
CreatureLib::Battling::BattleParty* const* parties, size_t partiesCount, CreatureLib::Battling::BattleParty* const* parties, size_t partiesCount,
bool canFlee, uint8_t numberOfSides, uint8_t creaturesPerSide) { bool canFlee, uint8_t numberOfSides, uint8_t creaturesPerSide) {
List<CreatureLib::Battling::BattleParty*> partiesList(parties, parties + partiesCount); ArbUt::List<CreatureLib::Battling::BattleParty*> partiesList(parties, parties + partiesCount);
Try(out = new Battle(library, partiesList, canFlee, numberOfSides, creaturesPerSide)); Try(out = new Battle(library, partiesList, canFlee, numberOfSides, creaturesPerSide));
} }
export void PkmnLib_Battle_Destruct(Battle* p) { delete p; } export void PkmnLib_Battle_Destruct(Battle* p) { delete p; }
export uint8_t PkmnLib_Battle_SetWeather(Battle* p, const char* name) { export uint8_t PkmnLib_Battle_SetWeather(Battle* p, const char* name) {
Try(p->SetWeather(Arbutils::CaseInsensitiveConstString(name))); Try(p->SetWeather(ArbUt::CaseInsensitiveConstString(name)));
}; };
export uint8_t PkmnLib_Battle_ClearWeather(Battle* p) { Try(p->ClearWeather()); }; export uint8_t PkmnLib_Battle_ClearWeather(Battle* p) { Try(p->ClearWeather()); };
export const char* PkmnLib_Battle_GetWeatherName(Battle* p) { return p->GetWeatherName().c_str(); } export const char* PkmnLib_Battle_GetWeatherName(Battle* p) { return p->GetWeatherName().c_str(); }

View File

@ -12,7 +12,7 @@ export Pokemon* PkmnLib_Pokemon_Construct(const BattleLibrary* library, const Pk
uint8_t spIv, uint8_t hpEv, uint8_t attEv, uint8_t defEv, uint8_t sAtEv, uint8_t spIv, uint8_t hpEv, uint8_t attEv, uint8_t defEv, uint8_t sAtEv,
uint8_t sDeEv, uint8_t spEv, const PkmnLib::Library::Nature* nature) { uint8_t sDeEv, uint8_t spEv, const PkmnLib::Library::Nature* nature) {
std::string nick(nickname); std::string nick(nickname);
Arbutils::Collections::List<CreatureLib::Battling::LearnedAttack*> cMoves(moves, moves + moveCount); ArbUt::List<CreatureLib::Battling::LearnedAttack*> cMoves(moves, moves + moveCount);
return new Pokemon(library, species, forme, level, experience, uid, gender, coloring, heldItem, nick, return new Pokemon(library, species, forme, level, experience, uid, gender, coloring, heldItem, nick,
CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves, CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves,

View File

@ -15,7 +15,7 @@ export const EvolutionData* PkmnLib_EvolutionData_CreateKnownMoveEvolution(const
} }
export const EvolutionData* PkmnLib_EvolutionData_CreateLocationEvolution(const char* location, export const EvolutionData* PkmnLib_EvolutionData_CreateLocationEvolution(const char* location,
const PokemonSpecies* into) { const PokemonSpecies* into) {
return EvolutionData::CreateLocationEvolution(Arbutils::CaseInsensitiveConstString(location), into); return EvolutionData::CreateLocationEvolution(ArbUt::CaseInsensitiveConstString(location), into);
} }
export const EvolutionData* PkmnLib_Evolution_CreateTimeEvolution(TimeOfDay time, const PokemonSpecies* into) { export const EvolutionData* PkmnLib_Evolution_CreateTimeEvolution(TimeOfDay time, const PokemonSpecies* into) {
return EvolutionData::CreateTimeEvolution(time, into); return EvolutionData::CreateTimeEvolution(time, into);
@ -49,7 +49,7 @@ export const EvolutionData* PkmnLib_Evolution_CreateTradeWithSpeciesEvolution(co
} }
export const EvolutionData* PkmnLib_Evolution_CreateCustomEvolution(const CreatureLib::Library::EffectParameter** data, export const EvolutionData* PkmnLib_Evolution_CreateCustomEvolution(const CreatureLib::Library::EffectParameter** data,
size_t dataLength, const PokemonSpecies* into) { size_t dataLength, const PokemonSpecies* into) {
auto list = Arbutils::Collections::List<const CreatureLib::Library::EffectParameter*>(data, data + dataLength); auto list = ArbUt::List<const CreatureLib::Library::EffectParameter*>(data, data + dataLength);
return EvolutionData::CreateCustomEvolution(list, into); return EvolutionData::CreateCustomEvolution(list, into);
} }

View File

@ -8,10 +8,10 @@ export Item* PkmnLib_Item_Construct(const char* name, CreatureLib::Library::Item
const char* flags[], size_t flagsCount, uint8_t flingPower) { const char* flags[], size_t flagsCount, uint8_t flingPower) {
std::unordered_set<uint32_t> conversedFlags(flagsCount); std::unordered_set<uint32_t> conversedFlags(flagsCount);
for (size_t i = 0; i < flagsCount; i++) { for (size_t i = 0; i < flagsCount; i++) {
conversedFlags.insert(Arbutils::CaseInsensitiveConstString::GetHash(flags[i])); conversedFlags.insert(ArbUt::CaseInsensitiveConstString::GetHash(flags[i]));
} }
return new Item(Arbutils::CaseInsensitiveConstString(name), category, battleCategory, price, conversedFlags, return new Item(ArbUt::CaseInsensitiveConstString(name), category, battleCategory, price, conversedFlags,
flingPower); flingPower);
}; };

View File

@ -8,13 +8,13 @@ export NatureLibrary* PkmnLib_NatureLibrary_Construct(size_t initialCapacity) {
export void PkmnLib_NatureLibrary_Destruct(const NatureLibrary* p) { delete p; } export void PkmnLib_NatureLibrary_Destruct(const NatureLibrary* p) { delete p; }
export uint8_t PkmnLib_NatureLibrary_LoadNature(NatureLibrary* p, const char* name, const Nature* nature) { export uint8_t PkmnLib_NatureLibrary_LoadNature(NatureLibrary* p, const char* name, const Nature* nature) {
Try(p->LoadNature(Arbutils::CaseInsensitiveConstString(name), nature);) Try(p->LoadNature(ArbUt::CaseInsensitiveConstString(name), nature);)
} }
export uint8_t PkmnLib_NatureLibrary_GetNatureByName(NatureLibrary* p, const char* name, const Nature*& out) { export uint8_t PkmnLib_NatureLibrary_GetNatureByName(NatureLibrary* p, const char* name, const Nature*& out) {
Try(out = p->GetNatureByName(Arbutils::CaseInsensitiveConstString(name))); Try(out = p->GetNatureByName(ArbUt::CaseInsensitiveConstString(name)));
} }
export const char* PkmnLib_NatureLibrary_GetRandomNatureName(NatureLibrary* p, Arbutils::Random* rand) { export const char* PkmnLib_NatureLibrary_GetRandomNatureName(NatureLibrary* p, ArbUt::Random* rand) {
return p->GetRandomNatureName(rand).c_str(); return p->GetRandomNatureName(rand).c_str();
} }

View File

@ -5,8 +5,8 @@ using namespace PkmnLib::Library;
export uint8_t PkmnLib_PokemonSpecies_Construct(const PokemonSpecies*& out, uint16_t id, const char* name, export uint8_t PkmnLib_PokemonSpecies_Construct(const PokemonSpecies*& out, uint16_t id, const char* name,
const PokemonForme* defaultForme, float genderRatio, const PokemonForme* defaultForme, float genderRatio,
const char* growthRate, uint8_t captureRate, uint8_t baseHappiness) { const char* growthRate, uint8_t captureRate, uint8_t baseHappiness) {
Try(auto cName = Arbutils::CaseInsensitiveConstString(name); Try(auto cName = ArbUt::CaseInsensitiveConstString(name);
auto cGrowthRate = Arbutils::CaseInsensitiveConstString(growthRate); auto cGrowthRate = ArbUt::CaseInsensitiveConstString(growthRate);
out = new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness);) out = new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness);)
} }

View File

@ -1,5 +1,5 @@
#include "Battle.hpp" #include "Battle.hpp"
void PkmnLib::Battling::Battle::SetWeather(const Arbutils::CaseInsensitiveConstString& name) { void PkmnLib::Battling::Battle::SetWeather(const ArbUt::CaseInsensitiveConstString& name) {
if (_weatherScript != nullptr) { if (_weatherScript != nullptr) {
_weatherScript->OnRemove(); _weatherScript->OnRemove();
delete _weatherScript; delete _weatherScript;

View File

@ -12,16 +12,16 @@ namespace PkmnLib::Battling {
CreatureLib::Battling::Script* _weatherScript = nullptr; CreatureLib::Battling::Script* _weatherScript = nullptr;
public: public:
Battle(const BattleLibrary* library, const List<CreatureLib::Battling::BattleParty*>& parties, Battle(const BattleLibrary* library, const ArbUt::List<CreatureLib::Battling::BattleParty*>& parties,
bool canFlee = true, uint8_t numberOfSides = 2, uint8_t creaturesPerSide = 1) bool canFlee = true, uint8_t numberOfSides = 2, uint8_t creaturesPerSide = 1)
: CreatureLib::Battling::Battle(library, parties, canFlee, numberOfSides, creaturesPerSide) {} : CreatureLib::Battling::Battle(library, parties, canFlee, numberOfSides, creaturesPerSide) {}
void SetWeather(const Arbutils::CaseInsensitiveConstString& name); void SetWeather(const ArbUt::CaseInsensitiveConstString& name);
void ClearWeather(); void ClearWeather();
const Arbutils::CaseInsensitiveConstString& GetWeatherName() noexcept { return _weatherScript->GetName(); } const ArbUt::CaseInsensitiveConstString& GetWeatherName() noexcept { return _weatherScript->GetName(); }
size_t ScriptCount() const override { return CreatureLib::Battling::Battle::ScriptCount() + 1; } size_t ScriptCount() const override { return CreatureLib::Battling::Battle::ScriptCount() + 1; }
void GetActiveScripts(List<CreatureLib::Battling::ScriptWrapper>& scripts) override { void GetActiveScripts(ArbUt::List<CreatureLib::Battling::ScriptWrapper>& scripts) override {
CreatureLib::Battling::Battle::GetActiveScripts(scripts); CreatureLib::Battling::Battle::GetActiveScripts(scripts);
scripts.Append(CreatureLib::Battling::ScriptWrapper( scripts.Append(CreatureLib::Battling::ScriptWrapper(
CreatureLib::Battling::ScriptWrapper::FromScript(&_weatherScript))); CreatureLib::Battling::ScriptWrapper::FromScript(&_weatherScript)));

View File

@ -6,16 +6,16 @@
namespace PkmnLib::Battling { namespace PkmnLib::Battling {
class WeatherChangeEvent : public CreatureLib::Battling::EventData { class WeatherChangeEvent : public CreatureLib::Battling::EventData {
Arbutils::CaseInsensitiveConstString _weatherName; ArbUt::CaseInsensitiveConstString _weatherName;
public: public:
explicit WeatherChangeEvent(const Arbutils::CaseInsensitiveConstString& name) : _weatherName(name) {} explicit WeatherChangeEvent(const ArbUt::CaseInsensitiveConstString& name) : _weatherName(name) {}
[[nodiscard]] CreatureLib::Battling::EventDataKind GetKind() const noexcept override { [[nodiscard]] CreatureLib::Battling::EventDataKind GetKind() const noexcept override {
return static_cast<CreatureLib::Battling::EventDataKind>(PkmnEventDataKind::WeatherChange); return static_cast<CreatureLib::Battling::EventDataKind>(PkmnEventDataKind::WeatherChange);
} }
const Arbutils::CaseInsensitiveConstString GetWeatherName() const noexcept { return _weatherName; } const ArbUt::CaseInsensitiveConstString GetWeatherName() const noexcept { return _weatherName; }
}; };
} }

View File

@ -2,6 +2,7 @@
#define PKMNLIB_BATTLELIBRARY_HPP #define PKMNLIB_BATTLELIBRARY_HPP
#include <CreatureLib/Battling/Library/BattleLibrary.hpp> #include <CreatureLib/Battling/Library/BattleLibrary.hpp>
#include <memory>
#include "../../Library/PokemonLibrary.hpp" #include "../../Library/PokemonLibrary.hpp"
#include "DamageLibrary.hpp" #include "DamageLibrary.hpp"
#include "ExperienceLibrary.hpp" #include "ExperienceLibrary.hpp"
@ -18,25 +19,25 @@ namespace PkmnLib::Battling {
: CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary, : CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary,
scriptResolver, miscLibrary) {} scriptResolver, miscLibrary) {}
const Library::LibrarySettings* GetSettings() const { const std::unique_ptr<const Library::LibrarySettings>& GetSettings() const {
return static_cast<const Library::LibrarySettings*>(_staticLib->GetSettings()); return reinterpret_cast<const std::unique_ptr<const Library::LibrarySettings>&>(_staticLib->GetSettings());
} }
const Library::PokemonLibrary* GetStaticLib() const { const std::unique_ptr<const Library::PokemonLibrary>& GetStaticLib() const {
return dynamic_cast<const Library::PokemonLibrary*>(CreatureLib::Battling::BattleLibrary::_staticLib); return reinterpret_cast<const std::unique_ptr<const Library::PokemonLibrary>&>(_staticLib);
} }
const Library::SpeciesLibrary* GetSpeciesLibrary() const { const std::unique_ptr<const Library::SpeciesLibrary>& GetSpeciesLibrary() const {
return dynamic_cast<const Library::SpeciesLibrary*>( return reinterpret_cast<const std::unique_ptr<const Library::SpeciesLibrary>&>(
CreatureLib::Battling::BattleLibrary::GetSpeciesLibrary()); _staticLib->GetSpeciesLibrary());
} }
const Library::MoveLibrary* GetMoveLibrary() const { const std::unique_ptr<const Library::MoveLibrary>& GetMoveLibrary() const {
return dynamic_cast<const Library::MoveLibrary*>(CreatureLib::Battling::BattleLibrary::GetAttackLibrary()); return reinterpret_cast<const std::unique_ptr<const Library::MoveLibrary>&>(_staticLib->GetAttackLibrary());
} }
const Library::ItemLibrary* GetItemLibrary() const { const std::unique_ptr<const Library::ItemLibrary>& GetItemLibrary() const {
return dynamic_cast<const Library::ItemLibrary*>(CreatureLib::Battling::BattleLibrary::GetItemLibrary()); return reinterpret_cast<const std::unique_ptr<const Library::ItemLibrary>&>(_staticLib->GetItemLibrary());
} }
const Library::NatureLibrary* GetNatureLibrary() const { return GetStaticLib()->GetNatureLibrary(); } const Library::NatureLibrary* GetNatureLibrary() const { return GetStaticLib()->GetNatureLibrary(); }

View File

@ -1,6 +1,6 @@
#include "CreatePokemon.hpp" #include "CreatePokemon.hpp"
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(Arbutils::Random rand) { PkmnLib::Battling::CreatePokemon PkmnLib::Battling::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);
@ -37,19 +37,20 @@ PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithEffortVal
} }
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() { PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
auto rand = Arbutils::Random(); auto rand = ArbUt::Random();
const PkmnLib::Library::PokemonSpecies* species = nullptr; ArbUt::BorrowedPtr<const Library::PokemonSpecies> species = nullptr;
if (!this->_library->GetSpeciesLibrary()->TryGet(this->_species, species)) { if (!this->_library->GetSpeciesLibrary()->TryGet(this->_species, species)) {
std::stringstream err; std::stringstream err;
err << "Invalid species '" << _species << "'."; err << "Invalid species '" << _species << "'.";
throw CreatureException(err.str()); throw CreatureException(err.str());
} }
const PkmnLib::Library::PokemonForme* forme; ArbUt::BorrowedPtr<const PkmnLib::Library::PokemonForme> forme;
if (!species->TryGetForme(this->_forme, forme)) { if (!species->TryGetForme(this->_forme, forme)) {
std::stringstream err; std::stringstream err;
err << "Invalid forme '" << _forme << "' for species '" << _forme << "'."; err << "Invalid forme '" << _forme << "' for species '" << _forme << "'.";
throw CreatureException(err.str()); throw CreatureException(err.str());
} }
AssertNotNull(forme);
CreatureLib::Library::TalentIndex ability; CreatureLib::Library::TalentIndex ability;
if (this->_ability.Empty()) { if (this->_ability.Empty()) {
ability = forme->GetRandomTalent(&rand); ability = forme->GetRandomTalent(&rand);
@ -64,15 +65,16 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
if (gender == static_cast<CreatureLib::Library::Gender>(-1)) { if (gender == static_cast<CreatureLib::Library::Gender>(-1)) {
gender = species->GetRandomGender(rand); gender = species->GetRandomGender(rand);
} }
const Library::Item* heldItem = nullptr; ArbUt::BorrowedPtr<const Library::Item> heldItem = nullptr;
if (!this->_heldItem.Empty()) { if (!this->_heldItem.Empty()) {
if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) { if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) {
throw CreatureException("Unknown Item: " + this->_heldItem.std_str()); throw CreatureException("Unknown Item: " + this->_heldItem.std_str());
} }
AssertNotNull(heldItem);
} }
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level); auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
auto attacks = List<CreatureLib::Battling::LearnedAttack*>(_attacks.Count()); auto attacks = ArbUt::List<CreatureLib::Battling::LearnedAttack*>(_attacks.Count());
for (size_t i = 0; i < _attacks.Count(); i++) { for (size_t i = 0; i < _attacks.Count(); i++) {
auto& kv = _attacks[i]; auto& kv = _attacks[i];
auto move = kv.Move; auto move = kv.Move;
@ -102,7 +104,7 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
return pkmn; return pkmn;
} }
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon
PkmnLib::Battling::CreatePokemon::WithNature(const Arbutils::CaseInsensitiveConstString& nature) { PkmnLib::Battling::CreatePokemon::WithNature(const ArbUt::CaseInsensitiveConstString& nature) {
_nature = nature; _nature = nature;
return *this; return *this;
} }
@ -129,7 +131,7 @@ PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithEffortVal
return *this; return *this;
} }
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon
PkmnLib::Battling::CreatePokemon::WithForme(const Arbutils::CaseInsensitiveConstString& forme) { PkmnLib::Battling::CreatePokemon::WithForme(const ArbUt::CaseInsensitiveConstString& forme) {
_forme = forme; _forme = forme;
return *this; return *this;
} }
@ -143,14 +145,14 @@ PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::IsShiny(bool
return *this; return *this;
} }
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon
PkmnLib::Battling::CreatePokemon::WithHeldItem(const Arbutils::CaseInsensitiveConstString& item) { PkmnLib::Battling::CreatePokemon::WithHeldItem(const ArbUt::CaseInsensitiveConstString& item) {
_heldItem = item; _heldItem = item;
return *this; return *this;
} }
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon
PkmnLib::Battling::CreatePokemon::LearnMove(const Arbutils::CaseInsensitiveConstString& moveName, PkmnLib::Battling::CreatePokemon::LearnMove(const ArbUt::CaseInsensitiveConstString& moveName,
CreatureLib::Battling::AttackLearnMethod method) { CreatureLib::Battling::AttackLearnMethod method) {
const PkmnLib::Library::MoveData* move = nullptr; ArbUt::BorrowedPtr<const PkmnLib::Library::MoveData> move = nullptr;
if (!_library->GetMoveLibrary()->TryGet(moveName, move)) { if (!_library->GetMoveLibrary()->TryGet(moveName, move)) {
throw CreatureException("Invalid Move given: " + moveName.std_str()); throw CreatureException("Invalid Move given: " + moveName.std_str());
} }

View File

@ -7,25 +7,26 @@ namespace PkmnLib::Battling {
class CreatePokemon { class CreatePokemon {
private: private:
const BattleLibrary* _library; const BattleLibrary* _library;
Arbutils::CaseInsensitiveConstString _species = ""_cnc; ArbUt::CaseInsensitiveConstString _species = ""_cnc;
Arbutils::CaseInsensitiveConstString _forme = "default"_cnc; ArbUt::CaseInsensitiveConstString _forme = "default"_cnc;
uint8_t _level; uint8_t _level;
std::string _nickname = ""; std::string _nickname = "";
Arbutils::CaseInsensitiveConstString _ability = ""_cnc; ArbUt::CaseInsensitiveConstString _ability = ""_cnc;
Arbutils::CaseInsensitiveConstString _nature; ArbUt::CaseInsensitiveConstString _nature;
CreatureLib::Library::Gender _gender = static_cast<CreatureLib::Library::Gender>(-1); CreatureLib::Library::Gender _gender = static_cast<CreatureLib::Library::Gender>(-1);
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc; ArbUt::CaseInsensitiveConstString _heldItem = ""_cnc;
uint32_t _identifier = 0; uint32_t _identifier = 0;
struct ToLearnMethod { struct ToLearnMethod {
const Library::MoveData* Move; ArbUt::BorrowedPtr<const Library::MoveData> Move;
CreatureLib::Battling::AttackLearnMethod LearnMethod; CreatureLib::Battling::AttackLearnMethod LearnMethod;
ToLearnMethod() : Move(nullptr), LearnMethod(CreatureLib::Battling::AttackLearnMethod::Unknown){}; ToLearnMethod() : Move(nullptr), LearnMethod(CreatureLib::Battling::AttackLearnMethod::Unknown){};
ToLearnMethod(const Library::MoveData* move, CreatureLib::Battling::AttackLearnMethod method) ToLearnMethod(ArbUt::BorrowedPtr<const Library::MoveData> move,
CreatureLib::Battling::AttackLearnMethod method)
: Move(move), LearnMethod(method){}; : Move(move), LearnMethod(method){};
}; };
Arbutils::Collections::List<ToLearnMethod> _attacks; ArbUt::List<ToLearnMethod> _attacks;
uint8_t _currentMove = 0; uint8_t _currentMove = 0;
uint8_t _ivHp = 0; uint8_t _ivHp = 0;
@ -47,18 +48,18 @@ namespace PkmnLib::Battling {
bool _allowedExperienceGain = true; bool _allowedExperienceGain = true;
public: public:
CreatePokemon(const BattleLibrary* library, const Arbutils::CaseInsensitiveConstString& species, uint8_t level) CreatePokemon(const BattleLibrary* library, const ArbUt::CaseInsensitiveConstString& species, uint8_t level)
: _library(library), _species(species), _level(level), _attacks(library->GetSettings()->GetMaximalMoves()) { : _library(library), _species(species), _level(level), _attacks(library->GetSettings()->GetMaximalMoves()) {
} }
CreatePokemon WithForme(const Arbutils::CaseInsensitiveConstString& forme); CreatePokemon WithForme(const ArbUt::CaseInsensitiveConstString& forme);
CreatePokemon WithGender(CreatureLib::Library::Gender gender); CreatePokemon WithGender(CreatureLib::Library::Gender gender);
CreatePokemon IsShiny(bool value); CreatePokemon IsShiny(bool value);
CreatePokemon WithHeldItem(const Arbutils::CaseInsensitiveConstString& item); CreatePokemon WithHeldItem(const ArbUt::CaseInsensitiveConstString& item);
CreatePokemon LearnMove(const Arbutils::CaseInsensitiveConstString& move, CreatePokemon LearnMove(const ArbUt::CaseInsensitiveConstString& move,
CreatureLib::Battling::AttackLearnMethod method); CreatureLib::Battling::AttackLearnMethod method);
CreatePokemon WithRandomIndividualValues(Arbutils::Random rand = Arbutils::Random()); CreatePokemon WithRandomIndividualValues(ArbUt::Random rand = ArbUt::Random());
CreatePokemon WithIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value); CreatePokemon WithIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value);
CreatePokemon WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef, CreatePokemon WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef,
uint8_t speed); uint8_t speed);
@ -66,7 +67,7 @@ namespace PkmnLib::Battling {
CreatePokemon WithEffortValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef, CreatePokemon WithEffortValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef,
uint8_t speed); uint8_t speed);
CreatePokemon WithNature(const Arbutils::CaseInsensitiveConstString& nature); CreatePokemon WithNature(const ArbUt::CaseInsensitiveConstString& nature);
CreatePokemon IsAllowedExperienceGain(bool value); CreatePokemon IsAllowedExperienceGain(bool value);
Pokemon* Build(); Pokemon* Build();

View File

@ -6,10 +6,13 @@
namespace PkmnLib::Battling { namespace PkmnLib::Battling {
class LearnedMove : public CreatureLib::Battling::LearnedAttack { class LearnedMove : public CreatureLib::Battling::LearnedAttack {
public: public:
LearnedMove(const Library::MoveData* move, CreatureLib::Battling::AttackLearnMethod learnMethod) LearnedMove(const ArbUt::BorrowedPtr<const Library::MoveData>& move,
: CreatureLib::Battling::LearnedAttack(move, learnMethod) {} CreatureLib::Battling::AttackLearnMethod learnMethod)
: CreatureLib::Battling::LearnedAttack(move.As<const CreatureLib::Library::AttackData>(), learnMethod) {}
const Library::MoveData* GetMoveData() const { return dynamic_cast<const Library::MoveData*>(GetAttack()); } const ArbUt::BorrowedPtr<const Library::MoveData> GetMoveData() const {
return GetAttack().As<const Library::MoveData>();
}
}; };
} }

View File

@ -18,26 +18,29 @@ namespace PkmnLib::Battling {
const BattleLibrary* GetLibrary() const { return reinterpret_cast<const BattleLibrary*>(_library); } const BattleLibrary* GetLibrary() const { return reinterpret_cast<const BattleLibrary*>(_library); }
public: public:
Pokemon(const BattleLibrary* library, const Library::PokemonSpecies* species, Pokemon(const BattleLibrary* library, const ArbUt::BorrowedPtr<const Library::PokemonSpecies>& species,
const Library::PokemonForme* forme, uint8_t level, uint32_t experience, uint32_t uid, const ArbUt::BorrowedPtr<const Library::PokemonForme>& forme, uint8_t level, uint32_t experience,
CreatureLib::Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, uint32_t uid, CreatureLib::Library::Gender gender, uint8_t coloring,
const std::string& nickname, const CreatureLib::Library::TalentIndex& talent, ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string& nickname,
const List<CreatureLib::Battling::LearnedAttack*>& moves, const CreatureLib::Library::TalentIndex& talent,
const ArbUt::List<CreatureLib::Battling::LearnedAttack*>& moves,
CreatureLib::Library::StatisticSet<uint8_t> individualValues, CreatureLib::Library::StatisticSet<uint8_t> individualValues,
CreatureLib::Library::StatisticSet<uint8_t> effortValues, const PkmnLib::Library::Nature* nature, CreatureLib::Library::StatisticSet<uint8_t> effortValues, const PkmnLib::Library::Nature* nature,
bool allowedExperienceGain = true) bool allowedExperienceGain = true)
: CreatureLib::Battling::Creature(library, species, forme, level, experience, uid, gender, coloring, : CreatureLib::Battling::Creature(library, species.As<const CreatureLib::Library::CreatureSpecies>(),
heldItem, nickname, talent, moves, allowedExperienceGain), forme.As<const CreatureLib::Library::SpeciesVariant>(), level, experience,
uid, gender, coloring, heldItem.As<const CreatureLib::Library::Item>(),
nickname, talent, moves, allowedExperienceGain),
_individualValues(individualValues), _effortValues(effortValues), _nature(nature) {} _individualValues(individualValues), _effortValues(effortValues), _nature(nature) {}
const Library::PokemonForme* GetForme() const { const ArbUt::BorrowedPtr<const Library::PokemonForme> GetForme() const {
return dynamic_cast<const Library::PokemonForme*>(GetVariant()); return _variant.As<const Library::PokemonForme>();
} }
inline bool IsShiny() const noexcept { return _coloring == 1; } inline bool IsShiny() const noexcept { return _coloring == 1; }
const Arbutils::Collections::List<LearnedMove*>& GetMoves() const { const ArbUt::List<LearnedMove*>& GetMoves() const {
return reinterpret_cast<const Arbutils::Collections::List<LearnedMove*>&>(_attacks); return reinterpret_cast<const ArbUt::List<LearnedMove*>&>(_attacks);
} }
inline const Library::Nature* GetNature() const noexcept { return _nature; } inline const Library::Nature* GetNature() const noexcept { return _nature; }
@ -48,8 +51,8 @@ namespace PkmnLib::Battling {
return _effortValues.GetStat(stat); return _effortValues.GetStat(stat);
} }
inline const PkmnLib::Library::PokemonSpecies* GetPokemonSpecies() const noexcept { inline ArbUt::BorrowedPtr<const PkmnLib::Library::PokemonSpecies> GetPokemonSpecies() const noexcept {
return dynamic_cast<const Library::PokemonSpecies*>(_species); return _species.As<const PkmnLib::Library::PokemonSpecies>();
} }
}; };
} }

View File

@ -17,10 +17,9 @@ namespace PkmnLib::Library {
private: private:
const PokemonSpecies* _evolvesInto; const PokemonSpecies* _evolvesInto;
EvolutionMethod _method; EvolutionMethod _method;
Arbutils::Collections::List<const CreatureLib::Library::EffectParameter*> _evolutionData; ArbUt::List<const CreatureLib::Library::EffectParameter*> _evolutionData;
EvolutionData(EvolutionMethod method, EvolutionData(EvolutionMethod method, ArbUt::List<const CreatureLib::Library::EffectParameter*> data,
Arbutils::Collections::List<const CreatureLib::Library::EffectParameter*> data,
const PokemonSpecies* next) const PokemonSpecies* next)
: _evolvesInto(next), _method(method), _evolutionData(std::move(data)) {} : _evolvesInto(next), _method(method), _evolutionData(std::move(data)) {}
@ -40,7 +39,7 @@ namespace PkmnLib::Library {
{new CreatureLib::Library::EffectParameter((int64_t)friendship)}, into); {new CreatureLib::Library::EffectParameter((int64_t)friendship)}, into);
} }
static const EvolutionData* CreateKnownMoveEvolution(const MoveData* move, const PokemonSpecies* into); static const EvolutionData* CreateKnownMoveEvolution(const MoveData* move, const PokemonSpecies* into);
static inline const EvolutionData* CreateLocationEvolution(const Arbutils::CaseInsensitiveConstString& location, static inline const EvolutionData* CreateLocationEvolution(const ArbUt::CaseInsensitiveConstString& location,
const PokemonSpecies* into) { const PokemonSpecies* into) {
return new EvolutionData(EvolutionMethod::LocationBased, return new EvolutionData(EvolutionMethod::LocationBased,
{new CreatureLib::Library::EffectParameter(location)}, into); {new CreatureLib::Library::EffectParameter(location)}, into);
@ -68,7 +67,7 @@ namespace PkmnLib::Library {
static const EvolutionData* CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded, static const EvolutionData* CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded,
const PokemonSpecies* into); const PokemonSpecies* into);
static inline const EvolutionData* static inline const EvolutionData*
CreateCustomEvolution(const Arbutils::Collections::List<const CreatureLib::Library::EffectParameter*>& data, CreateCustomEvolution(const ArbUt::List<const CreatureLib::Library::EffectParameter*>& data,
const PokemonSpecies* into) { const PokemonSpecies* into) {
return new EvolutionData(EvolutionMethod::Custom, data, into); return new EvolutionData(EvolutionMethod::Custom, data, into);
} }

View File

@ -7,7 +7,7 @@ namespace PkmnLib::Library {
uint8_t _flingPower; uint8_t _flingPower;
public: public:
Item(const Arbutils::CaseInsensitiveConstString& name, CreatureLib::Library::ItemCategory category, Item(const ArbUt::CaseInsensitiveConstString& name, CreatureLib::Library::ItemCategory category,
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price, CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
const std::unordered_set<uint32_t>& flags, uint8_t flingPower) noexcept const std::unordered_set<uint32_t>& flags, uint8_t flingPower) noexcept
: CreatureLib::Library::Item(name, category, battleCategory, price, flags), _flingPower(flingPower) {} : CreatureLib::Library::Item(name, category, battleCategory, price, flags), _flingPower(flingPower) {}

View File

@ -6,16 +6,21 @@
namespace PkmnLib::Library { namespace PkmnLib::Library {
class ItemLibrary : public CreatureLib::Library::ItemLibrary { class ItemLibrary : public CreatureLib::Library::ItemLibrary {
public: public:
inline bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const Item*& item) const { inline bool TryGet(const ArbUt::CaseInsensitiveConstString& name, ArbUt::BorrowedPtr<const Item>& item) const {
return CreatureLib::Library::ItemLibrary::TryGet(name, (const CreatureLib::Library::Item*&)item); auto v = item.As<const CreatureLib::Library::Item>();
auto res = CreatureLib::Library::ItemLibrary::TryGet(name.GetHash(), v);
item = v.ForceAs<const Item>();
return res;
} }
inline const Item* Get(const Arbutils::CaseInsensitiveConstString& name) const { inline ArbUt::BorrowedPtr<const Item> Get(const ArbUt::CaseInsensitiveConstString& name) const {
return reinterpret_cast<const Item*>(CreatureLib::Library::ItemLibrary::Get(name)); return CreatureLib::Library::ItemLibrary::Get(name).ForceAs<const Item>();
}
inline ArbUt::BorrowedPtr<const Item> operator[](const ArbUt::CaseInsensitiveConstString& name) const {
return Get(name);
} }
const Item* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); }
void Insert(const Arbutils::CaseInsensitiveConstString& name, const Item* item) { void Insert(const ArbUt::CaseInsensitiveConstString& name, const Item* item) {
CreatureLib::Library::ItemLibrary::Insert(name, item); CreatureLib::Library::ItemLibrary::Insert(name, item);
} }
}; };

View File

@ -1,6 +1,6 @@
#include "MoveData.hpp" #include "MoveData.hpp"
#include <utility> #include <utility>
PkmnLib::Library::MoveData::MoveData(const Arbutils::CaseInsensitiveConstString& name, uint8_t type, PkmnLib::Library::MoveData::MoveData(const ArbUt::CaseInsensitiveConstString& name, uint8_t type,
PkmnLib::Library::MoveCategory category, uint8_t power, uint8_t accuracy, PkmnLib::Library::MoveCategory category, uint8_t power, uint8_t accuracy,
uint8_t baseUsage, CreatureLib::Library::AttackTarget target, int8_t priority, uint8_t baseUsage, CreatureLib::Library::AttackTarget target, int8_t priority,
const CreatureLib::Library::SecondaryEffect* effect, const CreatureLib::Library::SecondaryEffect* effect,

View File

@ -8,10 +8,10 @@ namespace PkmnLib::Library {
class MoveData : public CreatureLib::Library::AttackData { class MoveData : public CreatureLib::Library::AttackData {
private: private:
public: public:
MoveData(const Arbutils::CaseInsensitiveConstString& name, uint8_t type, MoveData(const ArbUt::CaseInsensitiveConstString& name, uint8_t type, PkmnLib::Library::MoveCategory category,
PkmnLib::Library::MoveCategory category, uint8_t power, uint8_t accuracy, uint8_t baseUsage, uint8_t power, uint8_t accuracy, uint8_t baseUsage, CreatureLib::Library::AttackTarget target,
CreatureLib::Library::AttackTarget target, int8_t priority, int8_t priority, const CreatureLib::Library::SecondaryEffect* effect,
const CreatureLib::Library::SecondaryEffect* effect, std::unordered_set<uint32_t> flags); std::unordered_set<uint32_t> flags);
PkmnLib::Library::MoveCategory GetCategory() const; PkmnLib::Library::MoveCategory GetCategory() const;
}; };

View File

@ -8,18 +8,19 @@ namespace PkmnLib::Library {
public: public:
MoveLibrary(size_t initialCapacity = 32) : CreatureLib::Library::AttackLibrary(initialCapacity) {} MoveLibrary(size_t initialCapacity = 32) : CreatureLib::Library::AttackLibrary(initialCapacity) {}
virtual const MoveData* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); } virtual ArbUt::BorrowedPtr<const MoveData> operator[](const ArbUt::CaseInsensitiveConstString& name) const {
return Get(name);
}
inline bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const MoveData*& move) const { inline bool TryGet(const ArbUt::CaseInsensitiveConstString& name,
const CreatureLib::Library::AttackData* ptr; ArbUt::BorrowedPtr<const MoveData>& move) const {
if (CreatureLib::Library::AttackLibrary::TryGet(name, ptr)) { auto v = move.As<const MoveData::AttackData>();
move = dynamic_cast<const MoveData*>(ptr); auto res = CreatureLib::Library::AttackLibrary::TryGet(name, v);
return true; move = v.As<const MoveData>();
return res;
} }
return false; inline ArbUt::BorrowedPtr<const MoveData> Get(const ArbUt::CaseInsensitiveConstString& name) const {
} return CreatureLib::Library::AttackLibrary::Get(name).As<const MoveData>();
const MoveData* Get(const Arbutils::CaseInsensitiveConstString& name) const {
return dynamic_cast<const MoveData*>(CreatureLib::Library::AttackLibrary::Get(name));
} }
}; };
} }

View File

@ -12,11 +12,11 @@
namespace PkmnLib::Library { namespace PkmnLib::Library {
class NatureLibrary { class NatureLibrary {
private: private:
Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*> _items; ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, const Nature*> _items;
public: public:
explicit NatureLibrary(size_t size = 32) noexcept explicit NatureLibrary(size_t size = 32) noexcept
: _items(Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*>(size)) {} : _items(ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, const Nature*>(size)) {}
~NatureLibrary() { ~NatureLibrary() {
for (auto& kv : _items) { for (auto& kv : _items) {
@ -24,27 +24,27 @@ namespace PkmnLib::Library {
} }
} }
inline void LoadNature(const Arbutils::CaseInsensitiveConstString& name, const Nature* nature) { inline void LoadNature(const ArbUt::CaseInsensitiveConstString& name, const Nature* nature) {
_items.Insert(name, nature); _items.Insert(name, nature);
} }
inline const Nature* GetNatureByName(const Arbutils::CaseInsensitiveConstString& name) const { inline const Nature* GetNatureByName(const ArbUt::CaseInsensitiveConstString& name) const {
return _items[name]; return _items[name];
} }
inline const Arbutils::CaseInsensitiveConstString& inline const ArbUt::CaseInsensitiveConstString&
GetRandomNatureName(Arbutils::Random rand = Arbutils::Random()) const { GetRandomNatureName(ArbUt::Random rand = ArbUt::Random()) const {
auto i = rand.Get(_items.Count()); auto i = rand.Get(_items.Count());
auto& map = _items.GetStdMap(); auto& map = _items.GetStdMap();
return std::next(std::begin(map), i)->first; return std::next(std::begin(map), i)->first;
} }
inline const Arbutils::CaseInsensitiveConstString& GetRandomNatureName(Arbutils::Random* rand) const { inline const ArbUt::CaseInsensitiveConstString& GetRandomNatureName(ArbUt::Random* rand) const {
auto i = rand->Get(_items.Count()); auto i = rand->Get(_items.Count());
auto& map = _items.GetStdMap(); auto& map = _items.GetStdMap();
return std::next(std::begin(map), i)->first; return std::next(std::begin(map), i)->first;
} }
inline Arbutils::CaseInsensitiveConstString GetNatureName(const Nature* nature) { inline ArbUt::CaseInsensitiveConstString GetNatureName(const Nature* nature) {
for (const auto& v : _items) { for (const auto& v : _items) {
if (v.second == nature) { if (v.second == nature) {
return v.first; return v.first;

View File

@ -21,20 +21,20 @@ namespace PkmnLib::Library {
CreatureLib::Library::TypeLibrary* typeLibrary, NatureLibrary* natures) CreatureLib::Library::TypeLibrary* typeLibrary, NatureLibrary* natures)
: DataLibrary(settings, species, moves, items, growthRates, typeLibrary), _natures(natures) {} : DataLibrary(settings, species, moves, items, growthRates, typeLibrary), _natures(natures) {}
const PkmnLib::Library::LibrarySettings* GetSettings() const { const std::unique_ptr<const PkmnLib::Library::LibrarySettings>& GetSettings() const {
return static_cast<const LibrarySettings*>(CreatureLib::Library::DataLibrary::GetSettings()); return (const std::unique_ptr<const LibrarySettings>&)CreatureLib::Library::DataLibrary::GetSettings();
} }
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const { [[nodiscard]] const std::unique_ptr<const SpeciesLibrary>& GetSpeciesLibrary() const {
return (const SpeciesLibrary*)(CreatureLib::Library::DataLibrary::GetSpeciesLibrary()); return (const std::unique_ptr<const SpeciesLibrary>&)CreatureLib::Library::DataLibrary::GetSpeciesLibrary();
} }
[[nodiscard]] const MoveLibrary* GetMoveLibrary() const { [[nodiscard]] const std::unique_ptr<const MoveLibrary>& GetMoveLibrary() const {
return (const MoveLibrary*)(CreatureLib::Library::DataLibrary::GetAttackLibrary()); return (const std::unique_ptr<const MoveLibrary>&)CreatureLib::Library::DataLibrary::GetAttackLibrary();
} }
[[nodiscard]] const ItemLibrary* GetItemLibrary() const { [[nodiscard]] const std::unique_ptr<const ItemLibrary>& GetItemLibrary() const {
return (const ItemLibrary*)(CreatureLib::Library::DataLibrary::GetItemLibrary()); return (const std::unique_ptr<const ItemLibrary>&)CreatureLib::Library::DataLibrary::GetItemLibrary();
} }
[[nodiscard]] const NatureLibrary* GetNatureLibrary() const noexcept { return _natures; } [[nodiscard]] const NatureLibrary* GetNatureLibrary() const noexcept { return _natures; }

View File

@ -1,7 +1,8 @@
#include "PokemonForme.hpp" #include "PokemonForme.hpp"
PkmnLib::Library::PokemonForme::PokemonForme(ConstString name, float height, float weight, uint32_t baseExperience, PkmnLib::Library::PokemonForme::PokemonForme(ArbUt::CaseInsensitiveConstString name, float height, float weight,
const List<uint8_t>& types, uint32_t baseExperience, const ArbUt::List<uint8_t>& types,
CreatureLib::Library::StatisticSet<uint16_t> baseStats, CreatureLib::Library::StatisticSet<uint16_t> baseStats,
const List<ConstString>& talents, const List<ConstString>& secretTalents, const ArbUt::List<ArbUt::CaseInsensitiveConstString>& talents,
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& secretTalents,
const CreatureLib::Library::LearnableAttacks* attacks) const CreatureLib::Library::LearnableAttacks* attacks)
: SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks) {} : SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks) {}

View File

@ -7,13 +7,16 @@
namespace PkmnLib::Library { namespace PkmnLib::Library {
class PokemonForme : public CreatureLib::Library::SpeciesVariant { class PokemonForme : public CreatureLib::Library::SpeciesVariant {
public: public:
PokemonForme(ConstString name, float height, float weight, uint32_t baseExperience, const List<uint8_t>& types, PokemonForme(ArbUt::CaseInsensitiveConstString name, float height, float weight, uint32_t baseExperience,
CreatureLib::Library::StatisticSet<uint16_t> baseStats, const List<ConstString>& talents, const ArbUt::List<uint8_t>& types, CreatureLib::Library::StatisticSet<uint16_t> baseStats,
const List<ConstString>& secretTalents, const CreatureLib::Library::LearnableAttacks* attacks); const ArbUt::List<ArbUt::CaseInsensitiveConstString>& talents,
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& secretTalents,
const CreatureLib::Library::LearnableAttacks* attacks);
private: private:
public: public:
inline const ConstString& GetAbility(const CreatureLib::Library::TalentIndex& index) const { inline const ArbUt::CaseInsensitiveConstString&
GetAbility(const CreatureLib::Library::TalentIndex& index) const {
return GetTalent(index); return GetTalent(index);
} }
}; };

View File

@ -8,11 +8,11 @@ namespace PkmnLib::Library {
class PokemonSpecies : public CreatureLib::Library::CreatureSpecies { class PokemonSpecies : public CreatureLib::Library::CreatureSpecies {
private: private:
uint8_t _baseHappiness; uint8_t _baseHappiness;
Arbutils::Collections::List<const EvolutionData*> _evolutions; ArbUt::List<const EvolutionData*> _evolutions;
public: public:
PokemonSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name, const PokemonForme* defaultForme, PokemonSpecies(uint16_t id, const ArbUt::CaseInsensitiveConstString& name, const PokemonForme* defaultForme,
float genderRatio, const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate, float genderRatio, const ArbUt::CaseInsensitiveConstString& growthRate, uint8_t captureRate,
uint8_t baseHappiness) noexcept uint8_t baseHappiness) noexcept
: CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate), : CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate),
_baseHappiness(baseHappiness) {} _baseHappiness(baseHappiness) {}
@ -25,22 +25,26 @@ namespace PkmnLib::Library {
inline uint8_t GetBaseHappiness() const { return _baseHappiness; } inline uint8_t GetBaseHappiness() const { return _baseHappiness; }
inline const PokemonForme* GetDefaultForme() const { inline ArbUt::BorrowedPtr<const PokemonForme> GetDefaultForme() const {
return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant("default"_cnc.GetHash())); return CreatureSpecies::GetVariant("default"_cnc.GetHash()).As<const PokemonForme>();
} }
inline bool HasForme(const Arbutils::CaseInsensitiveConstString& key) const { return HasVariant(key); } inline bool HasForme(const ArbUt::CaseInsensitiveConstString& key) const { return HasVariant(key); }
inline bool TryGetForme(const Arbutils::CaseInsensitiveConstString& key, const PokemonForme*& forme) const { inline bool TryGetForme(const ArbUt::CaseInsensitiveConstString& key,
return TryGetVariant(key, (const CreatureLib::Library::SpeciesVariant*&)forme); ArbUt::BorrowedPtr<const PokemonForme>& forme) const {
auto v = forme.As<const PokemonForme::SpeciesVariant>();
auto res = TryGetVariant(key, v);
forme = v.As<const PokemonForme>();
return res;
} }
inline const PokemonForme* GetForme(const Arbutils::CaseInsensitiveConstString& key) const { inline ArbUt::BorrowedPtr<const PokemonForme> GetForme(const ArbUt::CaseInsensitiveConstString& key) const {
return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant(key)); return CreatureSpecies::GetVariant(key).As<const PokemonForme>();
} }
inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); } inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); }
const Arbutils::Collections::List<const EvolutionData*>& GetEvolutions() const noexcept { return _evolutions; } const ArbUt::List<const EvolutionData*>& GetEvolutions() const noexcept { return _evolutions; }
}; };
} }

View File

@ -7,18 +7,23 @@
namespace PkmnLib::Library { namespace PkmnLib::Library {
class SpeciesLibrary : public CreatureLib::Library::SpeciesLibrary { class SpeciesLibrary : public CreatureLib::Library::SpeciesLibrary {
public: public:
inline bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const PokemonSpecies*& outSpecies) const { inline bool TryGet(const ArbUt::CaseInsensitiveConstString& name,
return CreatureLib::Library::SpeciesLibrary::TryGet( ArbUt::BorrowedPtr<const PokemonSpecies>& outSpecies) const {
name, (const CreatureLib::Library::CreatureSpecies*&)outSpecies); auto v = outSpecies.As<const PokemonSpecies::CreatureSpecies>();
auto res = CreatureLib::Library::SpeciesLibrary::TryGet(name, v);
outSpecies = v.As<const PokemonSpecies>();
return res;
} }
inline const PokemonSpecies* Get(const Arbutils::CaseInsensitiveConstString& name) const { inline ArbUt::BorrowedPtr<const PokemonSpecies> Get(const ArbUt::CaseInsensitiveConstString& name) const {
return dynamic_cast<const PokemonSpecies*>(CreatureLib::Library::SpeciesLibrary::Get(name)); return CreatureLib::Library::SpeciesLibrary::Get(name).As<const PokemonSpecies>();
} }
const PokemonSpecies* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); } ArbUt::BorrowedPtr<const PokemonSpecies> operator[](const ArbUt::CaseInsensitiveConstString& name) const {
return Get(name);
}
void Insert(const Arbutils::CaseInsensitiveConstString& name, const PokemonSpecies* species) { void Insert(const ArbUt::CaseInsensitiveConstString& name, const PokemonSpecies* species) {
CreatureLib::Library::SpeciesLibrary::Insert(name, species); CreatureLib::Library::SpeciesLibrary::Insert(name, species);
} }
}; };

View File

@ -82,8 +82,8 @@ void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg)
RegisterTypes(); RegisterTypes();
RegisterExceptionRoutines(_engine); RegisterExceptionRoutines(_engine);
auto staticLib = library->GetStaticLib(); auto& staticLib = library->GetStaticLib();
_engine->RegisterGlobalProperty("const StaticLibrary@ StaticLib", &staticLib); _engine->RegisterGlobalProperty("const StaticLibrary@ StaticLib", (void*)staticLib.get());
_contextPool = new ContextPool(_engine); _contextPool = new ContextPool(_engine);
} }
@ -123,7 +123,7 @@ void AngelScriptResolver::MessageCallback(const asSMessageInfo* msg, void* param
} }
CreatureLib::Battling::Script* AngelScriptResolver::LoadScript(ScriptCategory category, const ConstString& scriptName) { CreatureLib::Battling::Script* AngelScriptResolver::LoadScript(ScriptCategory category, const ConstString& scriptName) {
Dictionary<ConstString, AngelScriptTypeInfo*> innerDb; ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*> innerDb;
if (!_typeDatabase.TryGet(category, innerDb)) { if (!_typeDatabase.TryGet(category, innerDb)) {
_typeDatabase.Insert(category, innerDb); _typeDatabase.Insert(category, innerDb);
return nullptr; return nullptr;
@ -156,14 +156,14 @@ void AngelScriptResolver::FinalizeModule() {
for (size_t m = 0; m < metadata.size(); m++) { for (size_t m = 0; m < metadata.size(); m++) {
auto data = metadata[m]; auto data = metadata[m];
if (std::regex_match(data, base_match, metadataMatcher)) { if (std::regex_match(data, base_match, metadataMatcher)) {
auto metadataKind = Arbutils::CaseInsensitiveConstString(base_match[1].str()); auto metadataKind = ArbUt::CaseInsensitiveConstString(base_match[1].str());
auto metadataVariables = base_match[2].str(); auto metadataVariables = base_match[2].str();
if (!std::regex_match(metadataVariables, base_match, variableMatcher)) { if (!std::regex_match(metadataVariables, base_match, variableMatcher)) {
continue; continue;
} }
ConstString effectName; ConstString effectName;
for (size_t variableIndex = 1; variableIndex < base_match.size(); variableIndex += 2) { for (size_t variableIndex = 1; variableIndex < base_match.size(); variableIndex += 2) {
if (Arbutils::CaseInsensitiveConstString::GetHash(base_match[variableIndex]) == "effect"_cnc) { if (ArbUt::CaseInsensitiveConstString::GetHash(base_match[variableIndex]) == "effect"_cnc) {
auto val = base_match[variableIndex + 1].str(); auto val = base_match[variableIndex + 1].str();
effectName = ConstString(val); effectName = ConstString(val);
} }
@ -296,17 +296,17 @@ void AngelScriptResolver::LoadByteCodeFromMemory(uint8_t* byte, size_t size) {
delete stream; delete stream;
} }
void AngelScriptResolver::InitializeByteCode( void AngelScriptResolver::InitializeByteCode(
asIBinaryStream* stream, const Dictionary<ScriptCategory, Dictionary<ConstString, uint32_t>>& types) { asIBinaryStream* stream, const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, uint32_t>>& types) {
auto typeCount = _mainModule->GetObjectTypeCount(); auto typeCount = _mainModule->GetObjectTypeCount();
Dictionary<uint32_t, asITypeInfo*> objectTypes; ArbUt::Dictionary<uint32_t, asITypeInfo*> objectTypes;
for (asUINT i = 0; i < typeCount; i++) { for (asUINT i = 0; i < typeCount; i++) {
auto t = _mainModule->GetObjectTypeByIndex(i); auto t = _mainModule->GetObjectTypeByIndex(i);
objectTypes.Insert(ConstString::GetHash(t->GetName()), t); objectTypes.Insert(ConstString::GetHash(t->GetName()), t);
} }
Dictionary<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>> typeDatabase; ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*>> typeDatabase;
for (const auto& innerDb : types) { for (const auto& innerDb : types) {
Dictionary<ConstString, AngelScriptTypeInfo*> newInnerDb; ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*> newInnerDb;
for (const auto& val : innerDb.second) { for (const auto& val : innerDb.second) {
auto decl = val.second; auto decl = val.second;
auto type = objectTypes[decl]; auto type = objectTypes[decl];

View File

@ -10,7 +10,6 @@
#include <iostream> #include <iostream>
#include "AngelScriptScript.hpp" #include "AngelScriptScript.hpp"
#include "AngelScriptTypeInfo.hpp" #include "AngelScriptTypeInfo.hpp"
using namespace Arbutils::Collections;
class AngelScriptResolver : public CreatureLib::Battling::ScriptResolver { class AngelScriptResolver : public CreatureLib::Battling::ScriptResolver {
private: private:
@ -21,12 +20,14 @@ private:
static void MessageCallback(const asSMessageInfo* msg, void* param); static void MessageCallback(const asSMessageInfo* msg, void* param);
static void Print(const std::string& str) { std::cout << str << std::endl; } static void Print(const std::string& str) { std::cout << str << std::endl; }
Dictionary<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>> _typeDatabase; ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, AngelScriptTypeInfo*>>
Dictionary<ConstString, asITypeInfo*> _baseTypes; _typeDatabase;
ArbUt::Dictionary<ConstString, asITypeInfo*> _baseTypes;
void RegisterTypes(); void RegisterTypes();
void InitializeByteCode(asIBinaryStream* stream, void InitializeByteCode(
const Dictionary<ScriptCategory, Dictionary<ConstString, uint32_t>>& types); asIBinaryStream* stream,
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, uint32_t>>& types);
public: public:
~AngelScriptResolver() override { ~AngelScriptResolver() override {
@ -51,7 +52,8 @@ public:
uint8_t* WriteByteCodeToMemory(size_t& size, bool stripDebugInfo = false); uint8_t* WriteByteCodeToMemory(size_t& size, bool stripDebugInfo = false);
void LoadByteCodeFromMemory(uint8_t*, size_t size); void LoadByteCodeFromMemory(uint8_t*, size_t size);
const Dictionary<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>>& GetTypeDatabase() const noexcept { const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, AngelScriptTypeInfo*>>&
GetTypeDatabase() const noexcept {
return _typeDatabase; return _typeDatabase;
} }

View File

@ -42,8 +42,7 @@
ctx->PopState(); \ ctx->PopState(); \
} }
CScriptArray* CScriptArray* AngelScriptScript::GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls) {
AngelScriptScript::GetEffectParameters(const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& ls) {
asITypeInfo* t = _resolver->GetBaseType("array<EffectParameter@>"_cnc); asITypeInfo* t = _resolver->GetBaseType("array<EffectParameter@>"_cnc);
CScriptArray* arr = CScriptArray::Create(t, ls.Count()); CScriptArray* arr = CScriptArray::Create(t, ls.Count());
for (size_t i = 0; i < ls.Count(); i++) { for (size_t i = 0; i < ls.Count(); i++) {
@ -52,7 +51,7 @@ AngelScriptScript::GetEffectParameters(const Arbutils::Collections::List<Creatur
return arr; return arr;
} }
void AngelScriptScript::OnInitialize(const List<CreatureLib::Library::EffectParameter*>& parameters) { void AngelScriptScript::OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) {
CScriptArray* arr = nullptr; CScriptArray* arr = nullptr;
CALL_HOOK(OnInitialize, { CALL_HOOK(OnInitialize, {
arr = GetEffectParameters(parameters); arr = GetEffectParameters(parameters);

View File

@ -18,7 +18,7 @@ private:
ContextPool* _ctxPool = nullptr; ContextPool* _ctxPool = nullptr;
asIScriptObject* _obj = nullptr; asIScriptObject* _obj = nullptr;
CScriptArray* GetEffectParameters(const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& ls); CScriptArray* GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls);
public: public:
AngelScriptScript(AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj, AngelScriptScript(AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj,
@ -27,9 +27,11 @@ public:
~AngelScriptScript() override { _obj->Release(); } ~AngelScriptScript() override { _obj->Release(); }
[[nodiscard]] const ConstString& GetName() const noexcept override { return _type->GetName(); } [[nodiscard]] const ArbUt::CaseInsensitiveConstString& GetName() const noexcept override {
return _type->GetName();
}
asIScriptFunction* PrepareMethod(const ConstString& name, asIScriptContext* ctx) { asIScriptFunction* PrepareMethod(const ArbUt::CaseInsensitiveConstString& name, asIScriptContext* ctx) {
auto func = _type->GetFunction(name); auto func = _type->GetFunction(name);
ctx->Prepare(func); ctx->Prepare(func);
ctx->SetObject(_obj); ctx->SetObject(_obj);
@ -38,14 +40,15 @@ public:
ContextPool* GetContextPool() { return _ctxPool; } ContextPool* GetContextPool() { return _ctxPool; }
void OnInitialize(const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& parameters) override; void OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) override;
void Stack() override; void Stack() override;
void OnRemove() override; void OnRemove() override;
void OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) override; void OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) override;
void ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, ConstString* outAttack) override; void ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice,
ArbUt::CaseInsensitiveConstString* outAttack) override;
void PreventAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override; void PreventAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override;

View File

@ -10,13 +10,11 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
using ConstString = Arbutils::CaseInsensitiveConstString;
class AngelScriptTypeInfo { class AngelScriptTypeInfo {
private: private:
asITypeInfo* _type = nullptr; asITypeInfo* _type = nullptr;
Arbutils::Collections::Dictionary<uint32_t, asIScriptFunction*> _functions; ArbUt::Dictionary<uint32_t, asIScriptFunction*> _functions;
ConstString _name; ArbUt::CaseInsensitiveConstString _name;
struct FunctionInfo { struct FunctionInfo {
bool Exists = false; bool Exists = false;
@ -35,7 +33,8 @@ private:
} }
public: public:
explicit AngelScriptTypeInfo(const ConstString& name, asITypeInfo* type) : _type(type), _name(name) {} explicit AngelScriptTypeInfo(const ArbUt::CaseInsensitiveConstString& name, asITypeInfo* type)
: _type(type), _name(name) {}
~AngelScriptTypeInfo() { ~AngelScriptTypeInfo() {
for (const auto& f : _functions) { for (const auto& f : _functions) {
f.second->Release(); f.second->Release();
@ -43,11 +42,11 @@ public:
_functions.Clear(); _functions.Clear();
} }
const ConstString& GetName() const noexcept { return _name; } const ArbUt::CaseInsensitiveConstString& GetName() const noexcept { return _name; }
const char* GetDecl() { return _type->GetName(); } const char* GetDecl() { return _type->GetName(); }
asIScriptFunction* GetFunction(const ConstString& functionName) { asIScriptFunction* GetFunction(const ArbUt::CaseInsensitiveConstString& functionName) {
asIScriptFunction* func; asIScriptFunction* func;
if (_functions.TryGet(functionName, func)) { if (_functions.TryGet(functionName, func)) {
return func; return func;

View File

@ -13,7 +13,8 @@ protected:
IPkmnBinaryStream(size_t angelScriptBound) : _angelScriptBound(angelScriptBound) {} IPkmnBinaryStream(size_t angelScriptBound) : _angelScriptBound(angelScriptBound) {}
public: public:
virtual void WriteTypes(const Dictionary<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>>& types) { virtual void
WriteTypes(const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*>>& types) {
// 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)]...."
@ -37,9 +38,9 @@ public:
Write("\1", sizeof(char)); Write("\1", sizeof(char));
} }
} }
virtual Dictionary<ScriptCategory, Dictionary<ConstString, uint32_t>> ReadTypes() { virtual ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, uint32_t>> ReadTypes() {
_angelScriptBound = SIZE_MAX; _angelScriptBound = SIZE_MAX;
Dictionary<ScriptCategory, Dictionary<ConstString, uint32_t>> types; ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, uint32_t>> types;
ScriptCategory categoryArr[1]; ScriptCategory categoryArr[1];
while (true) { while (true) {
// Every inner database starts with the category, of known size. Read that. // Every inner database starts with the category, of known size. Read that.
@ -48,7 +49,7 @@ public:
if (read == 0) { if (read == 0) {
break; break;
} }
Dictionary<ConstString, uint32_t> innerDb; ArbUt::Dictionary<ConstString, uint32_t> innerDb;
// We don't know the sizes of the name and decl. Allocate 128 characters for them, as that should be enough. // We don't know the sizes of the name and decl. Allocate 128 characters for them, as that should be enough.
char name[128]; char name[128];
@ -67,8 +68,8 @@ public:
if (isDecl) { if (isDecl) {
// Insert the name and decl into the dictionary. Close off the decl with eof as well. // Insert the name and decl into the dictionary. Close off the decl with eof as well.
decl[pos] = '\0'; decl[pos] = '\0';
innerDb.Insert(Arbutils::CaseInsensitiveConstString(name), innerDb.Insert(ArbUt::CaseInsensitiveConstString(name),
Arbutils::CaseInsensitiveConstString::GetHash(decl)); ArbUt::CaseInsensitiveConstString::GetHash(decl));
} }
// If we have found \1, we are done with the current category, so break. // If we have found \1, we are done with the current category, so break.
break; break;
@ -79,8 +80,8 @@ public:
if (isDecl) { if (isDecl) {
// Insert the name and decl into the dictionary. Close off the decl with eof as well. // Insert the name and decl into the dictionary. Close off the decl with eof as well.
decl[pos] = '\0'; decl[pos] = '\0';
innerDb.Insert(Arbutils::CaseInsensitiveConstString(name), innerDb.Insert(ArbUt::CaseInsensitiveConstString(name),
Arbutils::CaseInsensitiveConstString::GetHash(decl)); ArbUt::CaseInsensitiveConstString::GetHash(decl));
// Reset our position and toggle back to name. // Reset our position and toggle back to name.
pos = 0; pos = 0;
isDecl = false; isDecl = false;

View File

@ -77,7 +77,7 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(
"Battle", "const constString& GetWeatherName() const", "Battle", "const constString& GetWeatherName() const",
asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const Arbutils::CaseInsensitiveConstString&), asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::CaseInsensitiveConstString&),
asCALL_THISCALL); asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);
} }

View File

@ -4,6 +4,7 @@
#include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h" #include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h"
#include "../../../../Battling/PkmnDamageSource.hpp" #include "../../../../Battling/PkmnDamageSource.hpp"
#include "../../../../Battling/Pokemon/Pokemon.hpp" #include "../../../../Battling/Pokemon/Pokemon.hpp"
#include "../HelperFile.hpp"
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it. // Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
#define ENUM__SIZE_WRAPPER(name, type, func) \ #define ENUM__SIZE_WRAPPER(name, type, func) \
@ -92,14 +93,18 @@ static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ConstString
return obj->HasHeldItem(str.GetHash()); return obj->HasHeldItem(str.GetHash());
} }
SMART_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::CreatureSpecies, GetSpecies);
SMART_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const PkmnLib::Library::PokemonForme, GetForme);
SMART_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::Item, GetHeldItem);
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT); [[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_Species() const property", r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_Species() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetSpecies), asCALL_THISCALL); asFUNCTION(GetSpeciesWrapper), asCALL_CDECL_OBJLAST);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Forme@ get_Forme() const property", r = engine->RegisterObjectMethod("Pokemon", "const Forme@ get_Forme() const property", asFUNCTION(GetFormeWrapper),
asMETHOD(PkmnLib::Battling::Pokemon, GetForme), asCALL_THISCALL); asCALL_CDECL_OBJLAST);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Level() const property", r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Level() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetLevel), asCALL_THISCALL); asMETHOD(PkmnLib::Battling::Pokemon, GetLevel), asCALL_THISCALL);
@ -117,19 +122,19 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
asMETHOD(PkmnLib::Battling::Pokemon, IsShiny), asCALL_THISCALL); asMETHOD(PkmnLib::Battling::Pokemon, IsShiny), asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property", r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetHeldItem), asCALL_THISCALL); asFUNCTION(GetHeldItemWrapper), asCALL_CDECL_OBJLAST);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const", r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const",
asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST); asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(
"Pokemon", "void SetHeldItem(const string &in name)", "Pokemon", "void SetHeldItem(const string &in name)",
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const Arbutils::CaseInsensitiveConstString&), void), asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const ArbUt::CaseInsensitiveConstString&), void),
asCALL_THISCALL); asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod("Pokemon", "void SetHeldItem(const Item@ item)",
"Pokemon", "void SetHeldItem(const Item@ item)", asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem,
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const CreatureLib::Library::Item*), void), (const ArbUt::BorrowedPtr<const CreatureLib::Library::Item>&), void),
asCALL_THISCALL); asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_CurrentHealth() const property", r = engine->RegisterObjectMethod("Pokemon", "uint32 get_CurrentHealth() const property",

View File

@ -1,5 +1,5 @@
#include "ConstString.hpp" #include "ConstString.hpp"
using ConstString = Arbutils::CaseInsensitiveConstString; using ConstString = ArbUt::CaseInsensitiveConstString;
static void ConstructConstString(void* self) { new (self) ConstString(); } static void ConstructConstString(void* self) { new (self) ConstString(); }
static void CopyConstructConstString(const ConstString& other, void* self) { new (self) ConstString(other); } static void CopyConstructConstString(const ConstString& other, void* self) { new (self) ConstString(other); }
@ -11,7 +11,7 @@ static std::string ImplConstStringStdStringConv(const ConstString& s) { return s
static uint32_t ImplConstStringHashConv(const ConstString& s) { return s.GetHash(); } static uint32_t ImplConstStringHashConv(const ConstString& s) { return s.GetHash(); }
void ConstStringRegister::Register(asIScriptEngine* engine) { void ConstStringRegister::Register(asIScriptEngine* engine) {
auto r = engine->RegisterObjectType("constString", sizeof(Arbutils::CaseInsensitiveConstString), auto r = engine->RegisterObjectType("constString", sizeof(ArbUt::CaseInsensitiveConstString),
asOBJ_VALUE | asOBJ_APP_CLASS_CDAK); asOBJ_VALUE | asOBJ_APP_CLASS_CDAK);
Assert(r >= 0); Assert(r >= 0);

View File

@ -0,0 +1,2 @@
#define SMART_PTR_GETTER_FUNC(o, returns, funcName) \
static returns* funcName##Wrapper(o* obj) { return obj->funcName().operator->(); }

View File

@ -4,7 +4,7 @@
static CreatureLib::Library::EffectParameter* Ref_Factory() { return new CreatureLib::Library::EffectParameter(); } static CreatureLib::Library::EffectParameter* Ref_Factory() { return new CreatureLib::Library::EffectParameter(); }
static const Arbutils::CaseInsensitiveConstString& AsString(const CreatureLib::Library::EffectParameter* p) { static const ArbUt::CaseInsensitiveConstString& AsString(const CreatureLib::Library::EffectParameter* p) {
return p->AsString(); return p->AsString();
} }
@ -38,7 +38,7 @@ void RegisterEffectParameter::Register(asIScriptEngine* engine) {
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("EffectParameter", "const constString& AsString() const", r = engine->RegisterObjectMethod("EffectParameter", "const constString& AsString() const",
asFUNCTIONPR(AsString, (const CreatureLib::Library::EffectParameter*), asFUNCTIONPR(AsString, (const CreatureLib::Library::EffectParameter*),
const Arbutils::CaseInsensitiveConstString&), const ArbUt::CaseInsensitiveConstString&),
asCALL_CDECL_OBJFIRST); asCALL_CDECL_OBJFIRST);
Assert(r >= 0); Assert(r >= 0);
} }

View File

@ -58,7 +58,7 @@ void RegisterItemTypes::RegisterBattleItemCategoryEnum(asIScriptEngine* engine)
ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::Item, GetCategory) ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::Item, GetCategory)
ENUM__SIZE_WRAPPER(Move_BattleCategoryWrapper, PkmnLib::Library::Item, GetBattleCategory) ENUM__SIZE_WRAPPER(Move_BattleCategoryWrapper, PkmnLib::Library::Item, GetBattleCategory)
static bool HasFlag(const PkmnLib::Library::Item* obj, const Arbutils::CaseInsensitiveConstString& str) { static bool HasFlag(const PkmnLib::Library::Item* obj, const ArbUt::CaseInsensitiveConstString& str) {
return obj->HasFlag(str); return obj->HasFlag(str);
} }

View File

@ -46,7 +46,7 @@ void RegisterMoveTypes::RegisterMoveTarget(asIScriptEngine* engine) {
ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::MoveData, GetCategory) ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::MoveData, GetCategory)
ENUM__SIZE_WRAPPER(Move_TargetWrapper, PkmnLib::Library::MoveData, GetTarget) ENUM__SIZE_WRAPPER(Move_TargetWrapper, PkmnLib::Library::MoveData, GetTarget)
static bool HasFlag(const PkmnLib::Library::MoveData* obj, const Arbutils::CaseInsensitiveConstString& str) { static bool HasFlag(const PkmnLib::Library::MoveData* obj, const ArbUt::CaseInsensitiveConstString& str) {
return obj->HasFlag(str); return obj->HasFlag(str);
} }

View File

@ -3,6 +3,7 @@
#include "../../../../Library/Species/PokemonSpecies.hpp" #include "../../../../Library/Species/PokemonSpecies.hpp"
#include "../../../../Library/Species/SpeciesLibrary.hpp" #include "../../../../Library/Species/SpeciesLibrary.hpp"
#include "../../../../Library/Statistic.hpp" #include "../../../../Library/Statistic.hpp"
#include "../HelperFile.hpp"
void RegisterSpeciesTypes::Register(asIScriptEngine* engine) { void RegisterSpeciesTypes::Register(asIScriptEngine* engine) {
RegisterGenderEnum(engine); RegisterGenderEnum(engine);
@ -42,8 +43,11 @@ void RegisterSpeciesTypes::RegisterStatisticEnum(asIScriptEngine* engine) {
static const PkmnLib::Library::PokemonForme* GetFormeWrapper(const std::string& s, static const PkmnLib::Library::PokemonForme* GetFormeWrapper(const std::string& s,
const PkmnLib::Library::PokemonSpecies* species) { const PkmnLib::Library::PokemonSpecies* species) {
return species->GetForme(Arbutils::CaseInsensitiveConstString(s.c_str(), s.length())); return species->GetForme(ArbUt::CaseInsensitiveConstString(s.c_str(), s.length()))
.As<const PkmnLib::Library::PokemonForme>()
.GetRaw();
} }
SMART_PTR_GETTER_FUNC(PkmnLib::Library::PokemonSpecies, const PkmnLib::Library::PokemonForme, GetDefaultForme);
void RegisterSpeciesTypes::RegisterSpeciesType(asIScriptEngine* engine) { void RegisterSpeciesTypes::RegisterSpeciesType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT); [[maybe_unused]] int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT);
@ -66,12 +70,12 @@ void RegisterSpeciesTypes::RegisterSpeciesType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Species", "const Forme@ GetForme(string key) const", asFUNCTION(GetFormeWrapper), r = engine->RegisterObjectMethod("Species", "const Forme@ GetForme(string key) const", asFUNCTION(GetFormeWrapper),
asCALL_CDECL_OBJLAST); asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("Species", "const Forme@ GetDefaultForme() const", r = engine->RegisterObjectMethod("Species", "const Forme@ get_DefaultForme() const property",
asMETHOD(PkmnLib::Library::PokemonSpecies, GetDefaultForme), asCALL_THISCALL); asFUNCTION(GetDefaultFormeWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
} }
const ConstString& GetAbility(PkmnLib::Library::PokemonForme* p, bool hidden, uint8_t index) { const ArbUt::CaseInsensitiveConstString& GetAbility(PkmnLib::Library::PokemonForme* p, bool hidden, uint8_t index) {
return p->GetAbility(CreatureLib::Library::TalentIndex(hidden, index)); return p->GetAbility(CreatureLib::Library::TalentIndex(hidden, index));
} }
@ -99,9 +103,10 @@ void RegisterSpeciesTypes::RegisterFormeType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Forme", "uint GetStatistic(Statistic stat) const", r = engine->RegisterObjectMethod("Forme", "uint GetStatistic(Statistic stat) const",
asMETHOD(PkmnLib::Library::PokemonForme, GetStatistic), asCALL_THISCALL); asMETHOD(PkmnLib::Library::PokemonForme, GetStatistic), asCALL_THISCALL);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod("Forme", "const constString& GetAbility(bool hidden, uint8 index) const",
"Forme", "const constString& GetAbility(bool hidden, uint8 index) const", asFUNCTIONPR(GetAbility,
asFUNCTIONPR(GetAbility, (PkmnLib::Library::PokemonForme * p, bool hidden, uint8_t index), const ConstString&), (PkmnLib::Library::PokemonForme * p, bool hidden, uint8_t index),
const ArbUt::CaseInsensitiveConstString&),
asCALL_CDECL_OBJFIRST); asCALL_CDECL_OBJFIRST);
assert(r >= 0); assert(r >= 0);
} }

View File

@ -1,6 +1,7 @@
#include "RegisterStaticLibraryTypes.hpp" #include "RegisterStaticLibraryTypes.hpp"
#include <cassert> #include <cassert>
#include "../../../../Library/PokemonLibrary.hpp" #include "../../../../Library/PokemonLibrary.hpp"
#include "../HelperFile.hpp"
void RegisterStaticLibraryTypes::Register(asIScriptEngine* engine) { void RegisterStaticLibraryTypes::Register(asIScriptEngine* engine) {
RegisterLibrarySettingsType(engine); RegisterLibrarySettingsType(engine);
@ -20,25 +21,32 @@ void RegisterStaticLibraryTypes::RegisterLibrarySettingsType(asIScriptEngine* en
assert(r >= 0); assert(r >= 0);
} }
SMART_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const PkmnLib::Library::LibrarySettings, GetSettings);
SMART_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const PkmnLib::Library::SpeciesLibrary, GetSpeciesLibrary);
SMART_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const PkmnLib::Library::MoveLibrary, GetMoveLibrary);
SMART_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const PkmnLib::Library::ItemLibrary, GetItemLibrary);
SMART_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const CreatureLib::Library::GrowthRateLibrary, GetGrowthRates);
SMART_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const CreatureLib::Library::TypeLibrary, GetTypeLibrary);
void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) { void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("StaticLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT); [[maybe_unused]] int r = engine->RegisterObjectType("StaticLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("StaticLibrary", "const LibrarySettings@ get_Settings() const property", r = engine->RegisterObjectMethod("StaticLibrary", "const LibrarySettings@ get_Settings() const property",
asMETHOD(PkmnLib::Library::PokemonLibrary, GetSettings), asCALL_THISCALL); asFUNCTION(GetSettingsWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("StaticLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property", r = engine->RegisterObjectMethod("StaticLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property",
asMETHOD(PkmnLib::Library::PokemonLibrary, GetSpeciesLibrary), asCALL_THISCALL); asFUNCTION(GetSpeciesLibraryWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("StaticLibrary", "const MoveLibrary@ get_MoveLibrary() const property", r = engine->RegisterObjectMethod("StaticLibrary", "const MoveLibrary@ get_MoveLibrary() const property",
asMETHOD(PkmnLib::Library::PokemonLibrary, GetMoveLibrary), asCALL_THISCALL); asFUNCTION(GetMoveLibraryWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("StaticLibrary", "const ItemLibrary@ get_ItemLibrary() const property", r = engine->RegisterObjectMethod("StaticLibrary", "const ItemLibrary@ get_ItemLibrary() const property",
asMETHOD(PkmnLib::Library::PokemonLibrary, GetItemLibrary), asCALL_THISCALL); asFUNCTION(GetItemLibraryWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("StaticLibrary", "const GrowthRateLibrary@ get_GrowthRateLibrary() const property", r = engine->RegisterObjectMethod("StaticLibrary", "const GrowthRateLibrary@ get_GrowthRateLibrary() const property",
asMETHOD(PkmnLib::Library::PokemonLibrary, GetGrowthRates), asCALL_THISCALL); asFUNCTION(GetGrowthRatesWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("StaticLibrary", "const TypeLibrary@ get_TypeLibrary() const property", r = engine->RegisterObjectMethod("StaticLibrary", "const TypeLibrary@ get_TypeLibrary() const property",
asMETHOD(PkmnLib::Library::PokemonLibrary, GetTypeLibrary), asCALL_THISCALL); asFUNCTION(GetTypeLibraryWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
} }

View File

@ -4,7 +4,7 @@
void RegisterTypeLibrary::Register(asIScriptEngine* engine) { RegisterTypeLibraryType(engine); } void RegisterTypeLibrary::Register(asIScriptEngine* engine) { RegisterTypeLibraryType(engine); }
static bool GetTypeId(const CreatureLib::Library::TypeLibrary* obj, const Arbutils::CaseInsensitiveConstString& str) { static bool GetTypeId(const CreatureLib::Library::TypeLibrary* obj, const ArbUt::CaseInsensitiveConstString& str) {
return obj->GetTypeId(str); return obj->GetTypeId(str);
} }

View File

@ -20,11 +20,10 @@ TEST_CASE("Get Nature from Pokemon") {
TEST_CASE("Get Attack name from Pokemon") { TEST_CASE("Get Attack name from Pokemon") {
auto lib = TestLibrary::GetLibrary(); auto lib = TestLibrary::GetLibrary();
auto mon = PkmnLib::Battling::CreatePokemon(lib, "testSpecies"_cnc, 1) auto mon =
.LearnMove(Arbutils::CaseInsensitiveConstString("testMove"), PkmnLib::Battling::CreatePokemon(lib, "testSpecies"_cnc, 1)
CreatureLib::Battling::AttackLearnMethod::Level) .LearnMove(ArbUt::CaseInsensitiveConstString("testMove"), CreatureLib::Battling::AttackLearnMethod::Level)
.LearnMove(Arbutils::CaseInsensitiveConstString("testMove2"), .LearnMove(ArbUt::CaseInsensitiveConstString("testMove2"), CreatureLib::Battling::AttackLearnMethod::Level)
CreatureLib::Battling::AttackLearnMethod::Level)
.Build(); .Build();
auto move = mon->GetMoves()[0]; auto move = mon->GetMoves()[0];
REQUIRE(move->GetMoveData()->GetName() == "testMove"_cnc); REQUIRE(move->GetMoveData()->GetName() == "testMove"_cnc);

View File

@ -10,7 +10,7 @@ TEST_CASE("Basic Experience gain test", "battling") {
auto mon1 = CreatePokemon(lib, "testSpecies"_cnc, 55).Build(); auto mon1 = CreatePokemon(lib, "testSpecies"_cnc, 55).Build();
auto initialExp = mon1->GetExperience(); auto initialExp = mon1->GetExperience();
auto mon2 = CreatePokemon(lib, "testSpecies2"_cnc, 62).Build(); auto mon2 = CreatePokemon(lib, "testSpecies2"_cnc, 62).Build();
auto expLib = lib->GetExperienceLibrary(); auto& expLib = lib->GetExperienceLibrary();
expLib->HandleExperienceGain(mon2, {mon1}); expLib->HandleExperienceGain(mon2, {mon1});
REQUIRE(mon1->GetExperience() - initialExp == 4339); REQUIRE(mon1->GetExperience() - initialExp == 4339);
delete mon1; delete mon1;

View File

@ -113,7 +113,7 @@ TEST_CASE("Invoke OnInitialize script function") {
auto parameters = {new CreatureLib::Library::EffectParameter(true), auto parameters = {new CreatureLib::Library::EffectParameter(true),
new CreatureLib::Library::EffectParameter((int64_t)684), new CreatureLib::Library::EffectParameter((int64_t)684),
new CreatureLib::Library::EffectParameter(Arbutils::CaseInsensitiveConstString("foobar"))}; new CreatureLib::Library::EffectParameter(ArbUt::CaseInsensitiveConstString("foobar"))};
script->OnInitialize(parameters); script->OnInitialize(parameters);

View File

@ -74,7 +74,7 @@ TEST_CASE("Validate Pokemon Species in Script") {
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies"_cnc, 30).Build(); auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies"_cnc, 30).Build();
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon)); data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
data.Context->SetArgObject(1, (void*)mon->GetSpecies()); data.Context->SetArgObject(1, (void*)mon->GetSpecies().GetRaw());
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
REQUIRE((bool)data.Context->GetReturnWord()); REQUIRE((bool)data.Context->GetReturnWord());
@ -86,8 +86,8 @@ TEST_CASE("Validate Pokemon Forme in Script") {
auto data = GetScript(mainLib, "testForme"_cnc); auto data = GetScript(mainLib, "testForme"_cnc);
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies"_cnc, 30).WithForme("default"_cnc).Build(); auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies"_cnc, 30).WithForme("default"_cnc).Build();
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon)); data.Context->SetArgObject(0, (void*)mon);
data.Context->SetArgObject(1, (void*)mon->GetForme()); data.Context->SetArgObject(1, (void*)mon->GetForme().GetRaw());
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
REQUIRE((bool)data.Context->GetReturnWord()); REQUIRE((bool)data.Context->GetReturnWord());
@ -162,7 +162,7 @@ TEST_CASE("Validate Pokemon HeldItem in Script") {
.WithGender(CreatureLib::Library::Gender::Male) .WithGender(CreatureLib::Library::Gender::Male)
.Build(); .Build();
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon)); data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
data.Context->SetArgObject(1, (void*)mon->GetHeldItem()); data.Context->SetArgObject(1, (void*)mon->GetHeldItem().GetRaw());
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
REQUIRE((bool)data.Context->GetReturnWord()); REQUIRE((bool)data.Context->GetReturnWord());

View File

@ -62,7 +62,7 @@ TEST_CASE("Validate Forme Name in Script") {
auto data = GetScript(mainLib, "testName"_cnc); auto data = GetScript(mainLib, "testName"_cnc);
auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme();
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonForme*>(forme)); data.Context->SetArgObject(0, (void*)forme.GetRaw());
auto name = forme->GetName(); auto name = forme->GetName();
data.Context->SetArgAddress(1, &name); data.Context->SetArgAddress(1, &name);
@ -77,7 +77,7 @@ TEST_CASE("Validate Forme Weight in Script") {
auto data = GetScript(mainLib, "testWeight"_cnc); auto data = GetScript(mainLib, "testWeight"_cnc);
auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme();
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonForme*>(forme)); data.Context->SetArgObject(0, (void*)forme.GetRaw());
data.Context->SetArgFloat(1, forme->GetWeight()); data.Context->SetArgFloat(1, forme->GetWeight());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -91,7 +91,7 @@ TEST_CASE("Validate Forme Height in Script") {
auto data = GetScript(mainLib, "testHeight"_cnc); auto data = GetScript(mainLib, "testHeight"_cnc);
auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme();
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonForme*>(forme)); data.Context->SetArgObject(0, (void*)forme.GetRaw());
data.Context->SetArgFloat(1, forme->GetHeight()); data.Context->SetArgFloat(1, forme->GetHeight());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -105,7 +105,7 @@ TEST_CASE("Validate Forme Base Experience in Script") {
auto data = GetScript(mainLib, "testBaseExperience"_cnc); auto data = GetScript(mainLib, "testBaseExperience"_cnc);
auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme();
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonForme*>(forme)); data.Context->SetArgObject(0, (void*)forme.GetRaw());
data.Context->SetArgDWord(1, forme->GetBaseExperience()); data.Context->SetArgDWord(1, forme->GetBaseExperience());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -119,7 +119,7 @@ TEST_CASE("Validate Forme Type Count in Script") {
auto data = GetScript(mainLib, "testTypeCount"_cnc); auto data = GetScript(mainLib, "testTypeCount"_cnc);
auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme();
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonForme*>(forme)); data.Context->SetArgObject(0, (void*)forme.GetRaw());
data.Context->SetArgDWord(1, forme->GetTypeCount()); data.Context->SetArgDWord(1, forme->GetTypeCount());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -133,7 +133,7 @@ TEST_CASE("Validate Forme GetType in Script") {
auto data = GetScript(mainLib, "testGetType"_cnc); auto data = GetScript(mainLib, "testGetType"_cnc);
auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme();
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonForme*>(forme)); data.Context->SetArgObject(0, (void*)forme.GetRaw());
data.Context->SetArgByte(1, forme->GetType(0)); data.Context->SetArgByte(1, forme->GetType(0));
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -152,7 +152,7 @@ TEST_CASE("Validate Forme GetStatistic in Script") {
auto data = GetScript(mainLib, "testGetStatistic"_cnc); auto data = GetScript(mainLib, "testGetStatistic"_cnc);
auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme();
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonForme*>(forme)); data.Context->SetArgObject(0, (void*)forme.GetRaw());
data.Context->SetArgDWord(1, static_cast<asDWORD>(stat)); data.Context->SetArgDWord(1, static_cast<asDWORD>(stat));
data.Context->SetArgDWord(2, forme->GetStatistic(stat)); data.Context->SetArgDWord(2, forme->GetStatistic(stat));
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
@ -165,7 +165,7 @@ TEST_CASE("Validate Forme GetAbility in Script") {
auto data = GetScript(mainLib, "testGetAbility"_cnc); auto data = GetScript(mainLib, "testGetAbility"_cnc);
auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme();
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonForme*>(forme)); data.Context->SetArgObject(0, (void*)forme.GetRaw());
auto ability = forme->GetAbility(CreatureLib::Library::TalentIndex(false, 0)); auto ability = forme->GetAbility(CreatureLib::Library::TalentIndex(false, 0));
data.Context->SetArgAddress(1, &ability); data.Context->SetArgAddress(1, &ability);
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);

View File

@ -58,7 +58,7 @@ TEST_CASE("Validate Item Name in Script") {
auto data = GetScript(mainLib, "testName"_cnc); auto data = GetScript(mainLib, "testName"_cnc);
auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc); auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::Item*>(item)); data.Context->SetArgObject(0, (void*)item.GetRaw());
auto name = item->GetName(); auto name = item->GetName();
data.Context->SetArgAddress(1, &name); data.Context->SetArgAddress(1, &name);
@ -71,7 +71,7 @@ TEST_CASE("Validate Item Category in Script") {
auto data = GetScript(mainLib, "testCategory"_cnc); auto data = GetScript(mainLib, "testCategory"_cnc);
auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc); auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::Item*>(item)); data.Context->SetArgObject(0, (void*)item.GetRaw());
data.Context->SetArgDWord(1, static_cast<int32_t>(item->GetCategory())); data.Context->SetArgDWord(1, static_cast<int32_t>(item->GetCategory()));
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
@ -83,7 +83,7 @@ TEST_CASE("Validate Item Battle Category in Script") {
auto data = GetScript(mainLib, "testBattleCategory"_cnc); auto data = GetScript(mainLib, "testBattleCategory"_cnc);
auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc); auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::Item*>(item)); data.Context->SetArgObject(0, (void*)item.GetRaw());
data.Context->SetArgDWord(1, static_cast<int32_t>(item->GetBattleCategory())); data.Context->SetArgDWord(1, static_cast<int32_t>(item->GetBattleCategory()));
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
@ -95,7 +95,7 @@ TEST_CASE("Validate Item Price in Script") {
auto data = GetScript(mainLib, "testPrice"_cnc); auto data = GetScript(mainLib, "testPrice"_cnc);
auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc); auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::Item*>(item)); data.Context->SetArgObject(0, (void*)item.GetRaw());
data.Context->SetArgDWord(1, static_cast<int32_t>(item->GetPrice())); data.Context->SetArgDWord(1, static_cast<int32_t>(item->GetPrice()));
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);

View File

@ -62,7 +62,7 @@ TEST_CASE("Validate Move Name in Script") {
auto data = GetScript(mainLib, "testName"_cnc); auto data = GetScript(mainLib, "testName"_cnc);
auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc);
data.Context->SetArgObject(0, (void*)move); data.Context->SetArgObject(0, (void*)move.GetRaw());
auto name = move->GetName(); auto name = move->GetName();
data.Context->SetArgAddress(1, &name); data.Context->SetArgAddress(1, &name);
@ -75,7 +75,7 @@ TEST_CASE("Validate Move Type in Script") {
auto data = GetScript(mainLib, "testType"_cnc); auto data = GetScript(mainLib, "testType"_cnc);
auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::MoveData*>(move)); data.Context->SetArgObject(0, (void*)move.GetRaw());
data.Context->SetArgByte(1, move->GetType()); data.Context->SetArgByte(1, move->GetType());
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
@ -88,7 +88,7 @@ TEST_CASE("Validate Move Category in Script") {
auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::MoveData*>(move)); data.Context->SetArgObject(0, (void*)move.GetRaw());
data.Context->SetArgDWord(1, (asDWORD)move->GetCategory()); data.Context->SetArgDWord(1, (asDWORD)move->GetCategory());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -102,7 +102,7 @@ TEST_CASE("Validate Move BasePower in Script") {
auto data = GetScript(mainLib, "testBasePower"_cnc); auto data = GetScript(mainLib, "testBasePower"_cnc);
auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::MoveData*>(move)); data.Context->SetArgObject(0, (void*)move.GetRaw());
data.Context->SetArgByte(1, move->GetBasePower()); data.Context->SetArgByte(1, move->GetBasePower());
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
@ -114,7 +114,7 @@ TEST_CASE("Validate Move Accuracy in Script") {
auto data = GetScript(mainLib, "testAccuracy"_cnc); auto data = GetScript(mainLib, "testAccuracy"_cnc);
auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::MoveData*>(move)); data.Context->SetArgObject(0, (void*)move.GetRaw());
data.Context->SetArgByte(1, move->GetAccuracy()); data.Context->SetArgByte(1, move->GetAccuracy());
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
@ -126,7 +126,7 @@ TEST_CASE("Validate Move BaseUsages in Script") {
auto data = GetScript(mainLib, "testBaseUsages"_cnc); auto data = GetScript(mainLib, "testBaseUsages"_cnc);
auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::MoveData*>(move)); data.Context->SetArgObject(0, (void*)move.GetRaw());
data.Context->SetArgByte(1, move->GetBaseUsages()); data.Context->SetArgByte(1, move->GetBaseUsages());
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
@ -138,7 +138,7 @@ TEST_CASE("Validate Move Target in Script") {
auto data = GetScript(mainLib, "testTarget"_cnc); auto data = GetScript(mainLib, "testTarget"_cnc);
auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::MoveData*>(move)); data.Context->SetArgObject(0, (void*)move.GetRaw());
data.Context->SetArgDWord(1, (uint32_t)move->GetTarget()); data.Context->SetArgDWord(1, (uint32_t)move->GetTarget());
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
@ -150,7 +150,7 @@ TEST_CASE("Validate Move Priority in Script") {
auto data = GetScript(mainLib, "testPriority"_cnc); auto data = GetScript(mainLib, "testPriority"_cnc);
auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::MoveData*>(move)); data.Context->SetArgObject(0, (void*)move.GetRaw());
data.Context->SetArgByte(1, move->GetPriority()); data.Context->SetArgByte(1, move->GetPriority());
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);

View File

@ -13,7 +13,7 @@ class testScript1 {
bool testGenderRate(const Species@ s, float rate){ return s.GenderRate == rate; } bool testGenderRate(const Species@ s, float rate){ return s.GenderRate == rate; }
bool testCaptureRate(const Species@ s, uint8 rate){ return s.CaptureRate == rate; } bool testCaptureRate(const Species@ s, uint8 rate){ return s.CaptureRate == rate; }
bool testGetForme(const Species@ s, const Forme@ forme){ return s.GetForme("default") is forme; } bool testGetForme(const Species@ s, const Forme@ forme){ return s.GetForme("default") is forme; }
bool testGetDefaultForme(const Species@ s, const Forme@ forme){ return s.GetDefaultForme() is forme; } bool testGetDefaultForme(const Species@ s, const Forme@ forme){ return s.DefaultForme is forme; }
}} }}
)"}}; )"}};
@ -60,7 +60,7 @@ TEST_CASE("Validate Species Name in Script") {
auto data = GetScript(mainLib, "testName"_cnc); auto data = GetScript(mainLib, "testName"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species)); data.Context->SetArgObject(0, (void*)species.GetRaw());
auto name = species->GetName(); auto name = species->GetName();
data.Context->SetArgAddress(1, &name); data.Context->SetArgAddress(1, &name);
@ -75,7 +75,7 @@ TEST_CASE("Validate Species Id in Script") {
auto data = GetScript(mainLib, "testId"_cnc); auto data = GetScript(mainLib, "testId"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species)); data.Context->SetArgObject(0, (void*)species.GetRaw());
data.Context->SetArgWord(1, species->GetId()); data.Context->SetArgWord(1, species->GetId());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -89,7 +89,7 @@ TEST_CASE("Validate Species Gender Rate in Script") {
auto data = GetScript(mainLib, "testGenderRate"_cnc); auto data = GetScript(mainLib, "testGenderRate"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species)); data.Context->SetArgObject(0, (void*)species.GetRaw());
data.Context->SetArgFloat(1, species->GetGenderRate()); data.Context->SetArgFloat(1, species->GetGenderRate());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -103,7 +103,7 @@ TEST_CASE("Validate Species Capture Rate in Script") {
auto data = GetScript(mainLib, "testCaptureRate"_cnc); auto data = GetScript(mainLib, "testCaptureRate"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species)); data.Context->SetArgObject(0, (void*)species.GetRaw());
data.Context->SetArgByte(1, species->GetCaptureRate()); data.Context->SetArgByte(1, species->GetCaptureRate());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -117,8 +117,8 @@ TEST_CASE("Validate Species Get Forme in Script") {
auto data = GetScript(mainLib, "testGetForme"_cnc); auto data = GetScript(mainLib, "testGetForme"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species)); data.Context->SetArgObject(0, (void*)species.GetRaw());
data.Context->SetArgObject(1, const_cast<PkmnLib::Library::PokemonForme*>(species->GetForme("default"_cnc))); data.Context->SetArgObject(1, (void*)species->GetForme("default"_cnc).GetRaw());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
if (result == asEXECUTION_EXCEPTION) { if (result == asEXECUTION_EXCEPTION) {
@ -134,8 +134,8 @@ TEST_CASE("Validate Species Get Default Forme in Script") {
auto data = GetScript(mainLib, "testGetDefaultForme"_cnc); auto data = GetScript(mainLib, "testGetDefaultForme"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species)); data.Context->SetArgObject(0, (void*)species.GetRaw());
data.Context->SetArgObject(1, const_cast<PkmnLib::Library::PokemonForme*>(species->GetDefaultForme())); data.Context->SetArgObject(1, (void*)species->GetDefaultForme().GetRaw());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
REQUIRE(result == asEXECUTION_FINISHED); REQUIRE(result == asEXECUTION_FINISHED);

View File

@ -60,7 +60,7 @@ TEST_CASE("Validate StaticLibrary Maximum Level in Script") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto data = GetScript(mainLib, "testMaximumLevel"_cnc); auto data = GetScript(mainLib, "testMaximumLevel"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib())); data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get());
data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings()->GetMaximalLevel()); data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings()->GetMaximalLevel());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -73,7 +73,7 @@ TEST_CASE("Validate StaticLibrary Maximum Moves in Script") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto data = GetScript(mainLib, "testMaximumMoves"_cnc); auto data = GetScript(mainLib, "testMaximumMoves"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib())); data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get());
data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings()->GetMaximalMoves()); data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings()->GetMaximalMoves());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -86,9 +86,8 @@ TEST_CASE("Validate StaticLibrary Species Library in Script") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto data = GetScript(mainLib, "testSpeciesLibrary"_cnc); auto data = GetScript(mainLib, "testSpeciesLibrary"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib())); data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get());
data.Context->SetArgObject( data.Context->SetArgObject(1, (void*)mainLib->GetStaticLib()->GetSpeciesLibrary().get());
1, const_cast<PkmnLib::Library::SpeciesLibrary*>(mainLib->GetStaticLib()->GetSpeciesLibrary()));
auto result = data.Context->Execute(); auto result = data.Context->Execute();
REQUIRE(result == asEXECUTION_FINISHED); REQUIRE(result == asEXECUTION_FINISHED);
@ -100,9 +99,8 @@ TEST_CASE("Validate StaticLibrary Move Library in Script") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto data = GetScript(mainLib, "testMoveLibrary"_cnc); auto data = GetScript(mainLib, "testMoveLibrary"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib())); data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get());
data.Context->SetArgObject(1, data.Context->SetArgObject(1, (void*)mainLib->GetStaticLib()->GetMoveLibrary().get());
const_cast<PkmnLib::Library::MoveLibrary*>(mainLib->GetStaticLib()->GetMoveLibrary()));
auto result = data.Context->Execute(); auto result = data.Context->Execute();
REQUIRE(result == asEXECUTION_FINISHED); REQUIRE(result == asEXECUTION_FINISHED);
@ -114,9 +112,8 @@ TEST_CASE("Validate StaticLibrary Item Library in Script") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto data = GetScript(mainLib, "testItemLibrary"_cnc); auto data = GetScript(mainLib, "testItemLibrary"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib())); data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get());
data.Context->SetArgObject(1, data.Context->SetArgObject(1, (void*)mainLib->GetStaticLib()->GetItemLibrary().get());
const_cast<PkmnLib::Library::ItemLibrary*>(mainLib->GetStaticLib()->GetItemLibrary()));
auto result = data.Context->Execute(); auto result = data.Context->Execute();
REQUIRE(result == asEXECUTION_FINISHED); REQUIRE(result == asEXECUTION_FINISHED);
@ -128,9 +125,8 @@ TEST_CASE("Validate StaticLibrary Growth Rate Library in Script") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto data = GetScript(mainLib, "testGrowthRateLibrary"_cnc); auto data = GetScript(mainLib, "testGrowthRateLibrary"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib())); data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get());
data.Context->SetArgObject( data.Context->SetArgObject(1, (void*)mainLib->GetStaticLib()->GetGrowthRates().get());
1, const_cast<CreatureLib::Library::GrowthRateLibrary*>(mainLib->GetStaticLib()->GetGrowthRates()));
auto result = data.Context->Execute(); auto result = data.Context->Execute();
REQUIRE(result == asEXECUTION_FINISHED); REQUIRE(result == asEXECUTION_FINISHED);
@ -142,9 +138,8 @@ TEST_CASE("Validate StaticLibrary Type Library in Script") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto data = GetScript(mainLib, "testTypeLibrary"_cnc); auto data = GetScript(mainLib, "testTypeLibrary"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib())); data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get());
data.Context->SetArgObject( data.Context->SetArgObject(1, (void*)mainLib->GetStaticLib()->GetTypeLibrary().get());
1, const_cast<CreatureLib::Library::TypeLibrary*>(mainLib->GetStaticLib()->GetTypeLibrary()));
auto result = data.Context->Execute(); auto result = data.Context->Execute();
REQUIRE(result == asEXECUTION_FINISHED); REQUIRE(result == asEXECUTION_FINISHED);