From f42ce8865dda1169217914437d36030d3874a96c Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Wed, 27 May 2020 17:26:25 +0200 Subject: [PATCH] Update CreatureLib. --- .gitignore | 1 + .../AngelScript/AngelScriptResolver.cpp | 2 +- CInterface/Battling/Battle.cpp | 4 +-- CInterface/Battling/Pokemon.cpp | 2 +- CInterface/Library/EvolutionData.cpp | 4 +-- CInterface/Library/Item.cpp | 4 +-- CInterface/Library/NatureLibrary.cpp | 6 ++-- CInterface/Library/PokemonSpecies.cpp | 4 +-- src/Battling/Battle/Battle.cpp | 2 +- src/Battling/Battle/Battle.hpp | 8 ++--- .../EventHooks/WeatherChangeEvent.hpp | 6 ++-- src/Battling/Library/BattleLibrary.hpp | 23 ++++++++------- src/Battling/Pokemon/CreatePokemon.cpp | 24 ++++++++------- src/Battling/Pokemon/CreatePokemon.hpp | 29 ++++++++++--------- src/Battling/Pokemon/LearnedMove.hpp | 9 ++++-- src/Battling/Pokemon/Pokemon.hpp | 29 ++++++++++--------- src/Library/Evolutions/EvolutionData.hpp | 9 +++--- src/Library/Items/Item.hpp | 2 +- src/Library/Items/ItemLibrary.hpp | 17 +++++++---- src/Library/Moves/MoveData.cpp | 2 +- src/Library/Moves/MoveData.hpp | 8 ++--- src/Library/Moves/MoveLibrary.hpp | 23 ++++++++------- src/Library/Natures/NatureLibrary.hpp | 16 +++++----- src/Library/PokemonLibrary.hpp | 16 +++++----- src/Library/Species/PokemonForme.cpp | 7 +++-- src/Library/Species/PokemonForme.hpp | 11 ++++--- src/Library/Species/PokemonSpecies.hpp | 26 ++++++++++------- src/Library/Species/SpeciesLibrary.hpp | 19 +++++++----- .../AngelScript/AngelScriptResolver.cpp | 18 ++++++------ .../AngelScript/AngelScriptResolver.hpp | 14 +++++---- .../AngelScript/AngelScriptScript.cpp | 5 ++-- .../AngelScript/AngelScriptScript.hpp | 13 +++++---- .../AngelScript/AngelScriptTypeInfo.hpp | 13 ++++----- .../ByteCodeHandling/IPkmnBinaryStream.hpp | 17 ++++++----- .../Battling/RegisterBattleClass.cpp | 2 +- .../Battling/RegisterPokemonClass.cpp | 23 +++++++++------ .../AngelScript/TypeRegistry/ConstString.cpp | 4 +-- .../AngelScript/TypeRegistry/HelperFile.hpp | 2 ++ .../Library/RegisterEffectParameter.cpp | 4 +-- .../Library/RegisterItemTypes.cpp | 2 +- .../Library/RegisterMoveTypes.cpp | 2 +- .../Library/RegisterSpeciesTypes.cpp | 21 +++++++++----- .../Library/RegisterStaticLibraryTypes.cpp | 20 +++++++++---- .../Library/RegisterTypeLibrary.cpp | 2 +- tests/PokemonTests/BasicPokemonTests.cpp | 11 ++++--- tests/PokemonTests/ExperienceGainTests.cpp | 2 +- tests/ScriptTests/BaseScriptClassTests.cpp | 2 +- .../ScriptTypeTests/Battle/PokemonTests.cpp | 8 ++--- .../ScriptTypeTests/Library/FormesTests.cpp | 16 +++++----- .../ScriptTypeTests/Library/ItemDataTests.cpp | 8 ++--- .../ScriptTypeTests/Library/MoveTests.cpp | 16 +++++----- .../ScriptTypeTests/Library/SpeciesTests.cpp | 18 ++++++------ .../Library/StaticLibraryTests.cpp | 29 ++++++++----------- 53 files changed, 316 insertions(+), 269 deletions(-) create mode 100644 src/ScriptResolving/AngelScript/TypeRegistry/HelperFile.hpp diff --git a/.gitignore b/.gitignore index 27e4eed..baf251a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /cmake-build-debug/ /cmake-build-release/ +/build-release-windows/ /.idea/ \ No newline at end of file diff --git a/CInterface/AngelScript/AngelScriptResolver.cpp b/CInterface/AngelScript/AngelScriptResolver.cpp index 1aac192..576c267 100644 --- a/CInterface/AngelScript/AngelScriptResolver.cpp +++ b/CInterface/AngelScript/AngelScriptResolver.cpp @@ -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_LoadScript(CreatureLib::Battling::Script*& out, AngelScriptResolver* p, 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, bool stripDebugInfo) { diff --git a/CInterface/Battling/Battle.cpp b/CInterface/Battling/Battle.cpp index ca6ab15..72e792a 100644 --- a/CInterface/Battling/Battle.cpp +++ b/CInterface/Battling/Battle.cpp @@ -5,13 +5,13 @@ using namespace PkmnLib::Battling; export uint8_t PkmnLib_Battle_Construct(Battle*& out, const BattleLibrary* library, CreatureLib::Battling::BattleParty* const* parties, size_t partiesCount, bool canFlee, uint8_t numberOfSides, uint8_t creaturesPerSide) { - List partiesList(parties, parties + partiesCount); + ArbUt::List partiesList(parties, parties + partiesCount); Try(out = new Battle(library, partiesList, canFlee, numberOfSides, creaturesPerSide)); } export void PkmnLib_Battle_Destruct(Battle* p) { delete p; } 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 const char* PkmnLib_Battle_GetWeatherName(Battle* p) { return p->GetWeatherName().c_str(); } \ No newline at end of file diff --git a/CInterface/Battling/Pokemon.cpp b/CInterface/Battling/Pokemon.cpp index 86b46f2..186fe09 100644 --- a/CInterface/Battling/Pokemon.cpp +++ b/CInterface/Battling/Pokemon.cpp @@ -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 sDeEv, uint8_t spEv, const PkmnLib::Library::Nature* nature) { std::string nick(nickname); - Arbutils::Collections::List cMoves(moves, moves + moveCount); + ArbUt::List cMoves(moves, moves + moveCount); return new Pokemon(library, species, forme, level, experience, uid, gender, coloring, heldItem, nick, CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves, diff --git a/CInterface/Library/EvolutionData.cpp b/CInterface/Library/EvolutionData.cpp index 64829cd..e6a0830 100644 --- a/CInterface/Library/EvolutionData.cpp +++ b/CInterface/Library/EvolutionData.cpp @@ -15,7 +15,7 @@ export const EvolutionData* PkmnLib_EvolutionData_CreateKnownMoveEvolution(const } export const EvolutionData* PkmnLib_EvolutionData_CreateLocationEvolution(const char* location, 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) { 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, size_t dataLength, const PokemonSpecies* into) { - auto list = Arbutils::Collections::List(data, data + dataLength); + auto list = ArbUt::List(data, data + dataLength); return EvolutionData::CreateCustomEvolution(list, into); } diff --git a/CInterface/Library/Item.cpp b/CInterface/Library/Item.cpp index f67d7a7..6048a53 100644 --- a/CInterface/Library/Item.cpp +++ b/CInterface/Library/Item.cpp @@ -8,10 +8,10 @@ export Item* PkmnLib_Item_Construct(const char* name, CreatureLib::Library::Item const char* flags[], size_t flagsCount, uint8_t flingPower) { std::unordered_set conversedFlags(flagsCount); 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); }; diff --git a/CInterface/Library/NatureLibrary.cpp b/CInterface/Library/NatureLibrary.cpp index fc3f669..55f140e 100644 --- a/CInterface/Library/NatureLibrary.cpp +++ b/CInterface/Library/NatureLibrary.cpp @@ -8,13 +8,13 @@ export NatureLibrary* PkmnLib_NatureLibrary_Construct(size_t initialCapacity) { export void PkmnLib_NatureLibrary_Destruct(const NatureLibrary* p) { delete p; } 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) { - 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(); } diff --git a/CInterface/Library/PokemonSpecies.cpp b/CInterface/Library/PokemonSpecies.cpp index 6f95d33..631f4c3 100644 --- a/CInterface/Library/PokemonSpecies.cpp +++ b/CInterface/Library/PokemonSpecies.cpp @@ -5,8 +5,8 @@ using namespace PkmnLib::Library; export uint8_t PkmnLib_PokemonSpecies_Construct(const PokemonSpecies*& out, uint16_t id, const char* name, const PokemonForme* defaultForme, float genderRatio, const char* growthRate, uint8_t captureRate, uint8_t baseHappiness) { - Try(auto cName = Arbutils::CaseInsensitiveConstString(name); - auto cGrowthRate = Arbutils::CaseInsensitiveConstString(growthRate); + Try(auto cName = ArbUt::CaseInsensitiveConstString(name); + auto cGrowthRate = ArbUt::CaseInsensitiveConstString(growthRate); out = new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness);) } diff --git a/src/Battling/Battle/Battle.cpp b/src/Battling/Battle/Battle.cpp index b888018..f9d8f75 100644 --- a/src/Battling/Battle/Battle.cpp +++ b/src/Battling/Battle/Battle.cpp @@ -1,5 +1,5 @@ #include "Battle.hpp" -void PkmnLib::Battling::Battle::SetWeather(const Arbutils::CaseInsensitiveConstString& name) { +void PkmnLib::Battling::Battle::SetWeather(const ArbUt::CaseInsensitiveConstString& name) { if (_weatherScript != nullptr) { _weatherScript->OnRemove(); delete _weatherScript; diff --git a/src/Battling/Battle/Battle.hpp b/src/Battling/Battle/Battle.hpp index 9a3ceee..903c24d 100644 --- a/src/Battling/Battle/Battle.hpp +++ b/src/Battling/Battle/Battle.hpp @@ -12,16 +12,16 @@ namespace PkmnLib::Battling { CreatureLib::Battling::Script* _weatherScript = nullptr; public: - Battle(const BattleLibrary* library, const List& parties, + Battle(const BattleLibrary* library, const ArbUt::List& parties, bool canFlee = true, uint8_t numberOfSides = 2, uint8_t creaturesPerSide = 1) : CreatureLib::Battling::Battle(library, parties, canFlee, numberOfSides, creaturesPerSide) {} - void SetWeather(const Arbutils::CaseInsensitiveConstString& name); + void SetWeather(const ArbUt::CaseInsensitiveConstString& name); 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; } - void GetActiveScripts(List& scripts) override { + void GetActiveScripts(ArbUt::List& scripts) override { CreatureLib::Battling::Battle::GetActiveScripts(scripts); scripts.Append(CreatureLib::Battling::ScriptWrapper( CreatureLib::Battling::ScriptWrapper::FromScript(&_weatherScript))); diff --git a/src/Battling/EventHooks/WeatherChangeEvent.hpp b/src/Battling/EventHooks/WeatherChangeEvent.hpp index 752828b..2ac13b3 100644 --- a/src/Battling/EventHooks/WeatherChangeEvent.hpp +++ b/src/Battling/EventHooks/WeatherChangeEvent.hpp @@ -6,16 +6,16 @@ namespace PkmnLib::Battling { class WeatherChangeEvent : public CreatureLib::Battling::EventData { - Arbutils::CaseInsensitiveConstString _weatherName; + ArbUt::CaseInsensitiveConstString _weatherName; 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 { return static_cast(PkmnEventDataKind::WeatherChange); } - const Arbutils::CaseInsensitiveConstString GetWeatherName() const noexcept { return _weatherName; } + const ArbUt::CaseInsensitiveConstString GetWeatherName() const noexcept { return _weatherName; } }; } diff --git a/src/Battling/Library/BattleLibrary.hpp b/src/Battling/Library/BattleLibrary.hpp index d434e22..1fc7cdd 100644 --- a/src/Battling/Library/BattleLibrary.hpp +++ b/src/Battling/Library/BattleLibrary.hpp @@ -2,6 +2,7 @@ #define PKMNLIB_BATTLELIBRARY_HPP #include +#include #include "../../Library/PokemonLibrary.hpp" #include "DamageLibrary.hpp" #include "ExperienceLibrary.hpp" @@ -18,25 +19,25 @@ namespace PkmnLib::Battling { : CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary, scriptResolver, miscLibrary) {} - const Library::LibrarySettings* GetSettings() const { - return static_cast(_staticLib->GetSettings()); + const std::unique_ptr& GetSettings() const { + return reinterpret_cast&>(_staticLib->GetSettings()); } - const Library::PokemonLibrary* GetStaticLib() const { - return dynamic_cast(CreatureLib::Battling::BattleLibrary::_staticLib); + const std::unique_ptr& GetStaticLib() const { + return reinterpret_cast&>(_staticLib); } - const Library::SpeciesLibrary* GetSpeciesLibrary() const { - return dynamic_cast( - CreatureLib::Battling::BattleLibrary::GetSpeciesLibrary()); + const std::unique_ptr& GetSpeciesLibrary() const { + return reinterpret_cast&>( + _staticLib->GetSpeciesLibrary()); } - const Library::MoveLibrary* GetMoveLibrary() const { - return dynamic_cast(CreatureLib::Battling::BattleLibrary::GetAttackLibrary()); + const std::unique_ptr& GetMoveLibrary() const { + return reinterpret_cast&>(_staticLib->GetAttackLibrary()); } - const Library::ItemLibrary* GetItemLibrary() const { - return dynamic_cast(CreatureLib::Battling::BattleLibrary::GetItemLibrary()); + const std::unique_ptr& GetItemLibrary() const { + return reinterpret_cast&>(_staticLib->GetItemLibrary()); } const Library::NatureLibrary* GetNatureLibrary() const { return GetStaticLib()->GetNatureLibrary(); } diff --git a/src/Battling/Pokemon/CreatePokemon.cpp b/src/Battling/Pokemon/CreatePokemon.cpp index 5e50de2..75df60e 100644 --- a/src/Battling/Pokemon/CreatePokemon.cpp +++ b/src/Battling/Pokemon/CreatePokemon.cpp @@ -1,6 +1,6 @@ #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); _ivAttack = 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() { - auto rand = Arbutils::Random(); - const PkmnLib::Library::PokemonSpecies* species = nullptr; + auto rand = ArbUt::Random(); + ArbUt::BorrowedPtr species = nullptr; if (!this->_library->GetSpeciesLibrary()->TryGet(this->_species, species)) { std::stringstream err; err << "Invalid species '" << _species << "'."; throw CreatureException(err.str()); } - const PkmnLib::Library::PokemonForme* forme; + ArbUt::BorrowedPtr forme; if (!species->TryGetForme(this->_forme, forme)) { std::stringstream err; err << "Invalid forme '" << _forme << "' for species '" << _forme << "'."; throw CreatureException(err.str()); } + AssertNotNull(forme); CreatureLib::Library::TalentIndex ability; if (this->_ability.Empty()) { ability = forme->GetRandomTalent(&rand); @@ -64,15 +65,16 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() { if (gender == static_cast(-1)) { gender = species->GetRandomGender(rand); } - const Library::Item* heldItem = nullptr; + ArbUt::BorrowedPtr heldItem = nullptr; if (!this->_heldItem.Empty()) { if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) { throw CreatureException("Unknown Item: " + this->_heldItem.std_str()); } + AssertNotNull(heldItem); } auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level); - auto attacks = List(_attacks.Count()); + auto attacks = ArbUt::List(_attacks.Count()); for (size_t i = 0; i < _attacks.Count(); i++) { auto& kv = _attacks[i]; auto move = kv.Move; @@ -102,7 +104,7 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() { return pkmn; } PkmnLib::Battling::CreatePokemon -PkmnLib::Battling::CreatePokemon::WithNature(const Arbutils::CaseInsensitiveConstString& nature) { +PkmnLib::Battling::CreatePokemon::WithNature(const ArbUt::CaseInsensitiveConstString& nature) { _nature = nature; return *this; } @@ -129,7 +131,7 @@ PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::WithEffortVal return *this; } PkmnLib::Battling::CreatePokemon -PkmnLib::Battling::CreatePokemon::WithForme(const Arbutils::CaseInsensitiveConstString& forme) { +PkmnLib::Battling::CreatePokemon::WithForme(const ArbUt::CaseInsensitiveConstString& forme) { _forme = forme; return *this; } @@ -143,14 +145,14 @@ PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::IsShiny(bool return *this; } PkmnLib::Battling::CreatePokemon -PkmnLib::Battling::CreatePokemon::WithHeldItem(const Arbutils::CaseInsensitiveConstString& item) { +PkmnLib::Battling::CreatePokemon::WithHeldItem(const ArbUt::CaseInsensitiveConstString& item) { _heldItem = item; return *this; } PkmnLib::Battling::CreatePokemon -PkmnLib::Battling::CreatePokemon::LearnMove(const Arbutils::CaseInsensitiveConstString& moveName, +PkmnLib::Battling::CreatePokemon::LearnMove(const ArbUt::CaseInsensitiveConstString& moveName, CreatureLib::Battling::AttackLearnMethod method) { - const PkmnLib::Library::MoveData* move = nullptr; + ArbUt::BorrowedPtr move = nullptr; if (!_library->GetMoveLibrary()->TryGet(moveName, move)) { throw CreatureException("Invalid Move given: " + moveName.std_str()); } diff --git a/src/Battling/Pokemon/CreatePokemon.hpp b/src/Battling/Pokemon/CreatePokemon.hpp index 383f2ba..3baeb52 100644 --- a/src/Battling/Pokemon/CreatePokemon.hpp +++ b/src/Battling/Pokemon/CreatePokemon.hpp @@ -7,25 +7,26 @@ namespace PkmnLib::Battling { class CreatePokemon { private: const BattleLibrary* _library; - Arbutils::CaseInsensitiveConstString _species = ""_cnc; - Arbutils::CaseInsensitiveConstString _forme = "default"_cnc; + ArbUt::CaseInsensitiveConstString _species = ""_cnc; + ArbUt::CaseInsensitiveConstString _forme = "default"_cnc; uint8_t _level; std::string _nickname = ""; - Arbutils::CaseInsensitiveConstString _ability = ""_cnc; - Arbutils::CaseInsensitiveConstString _nature; + ArbUt::CaseInsensitiveConstString _ability = ""_cnc; + ArbUt::CaseInsensitiveConstString _nature; CreatureLib::Library::Gender _gender = static_cast(-1); - Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc; + ArbUt::CaseInsensitiveConstString _heldItem = ""_cnc; uint32_t _identifier = 0; struct ToLearnMethod { - const Library::MoveData* Move; + ArbUt::BorrowedPtr Move; CreatureLib::Battling::AttackLearnMethod LearnMethod; ToLearnMethod() : Move(nullptr), LearnMethod(CreatureLib::Battling::AttackLearnMethod::Unknown){}; - ToLearnMethod(const Library::MoveData* move, CreatureLib::Battling::AttackLearnMethod method) + ToLearnMethod(ArbUt::BorrowedPtr move, + CreatureLib::Battling::AttackLearnMethod method) : Move(move), LearnMethod(method){}; }; - Arbutils::Collections::List _attacks; + ArbUt::List _attacks; uint8_t _currentMove = 0; uint8_t _ivHp = 0; @@ -47,18 +48,18 @@ namespace PkmnLib::Battling { bool _allowedExperienceGain = true; 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()) { } - CreatePokemon WithForme(const Arbutils::CaseInsensitiveConstString& forme); + CreatePokemon WithForme(const ArbUt::CaseInsensitiveConstString& forme); CreatePokemon WithGender(CreatureLib::Library::Gender gender); CreatePokemon IsShiny(bool value); - CreatePokemon WithHeldItem(const Arbutils::CaseInsensitiveConstString& item); - CreatePokemon LearnMove(const Arbutils::CaseInsensitiveConstString& move, + CreatePokemon WithHeldItem(const ArbUt::CaseInsensitiveConstString& item); + CreatePokemon LearnMove(const ArbUt::CaseInsensitiveConstString& move, 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 WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef, 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, uint8_t speed); - CreatePokemon WithNature(const Arbutils::CaseInsensitiveConstString& nature); + CreatePokemon WithNature(const ArbUt::CaseInsensitiveConstString& nature); CreatePokemon IsAllowedExperienceGain(bool value); Pokemon* Build(); diff --git a/src/Battling/Pokemon/LearnedMove.hpp b/src/Battling/Pokemon/LearnedMove.hpp index 21e2285..91ccf89 100644 --- a/src/Battling/Pokemon/LearnedMove.hpp +++ b/src/Battling/Pokemon/LearnedMove.hpp @@ -6,10 +6,13 @@ namespace PkmnLib::Battling { class LearnedMove : public CreatureLib::Battling::LearnedAttack { public: - LearnedMove(const Library::MoveData* move, CreatureLib::Battling::AttackLearnMethod learnMethod) - : CreatureLib::Battling::LearnedAttack(move, learnMethod) {} + LearnedMove(const ArbUt::BorrowedPtr& move, + CreatureLib::Battling::AttackLearnMethod learnMethod) + : CreatureLib::Battling::LearnedAttack(move.As(), learnMethod) {} - const Library::MoveData* GetMoveData() const { return dynamic_cast(GetAttack()); } + const ArbUt::BorrowedPtr GetMoveData() const { + return GetAttack().As(); + } }; } diff --git a/src/Battling/Pokemon/Pokemon.hpp b/src/Battling/Pokemon/Pokemon.hpp index 080758d..c757718 100644 --- a/src/Battling/Pokemon/Pokemon.hpp +++ b/src/Battling/Pokemon/Pokemon.hpp @@ -18,26 +18,29 @@ namespace PkmnLib::Battling { const BattleLibrary* GetLibrary() const { return reinterpret_cast(_library); } public: - Pokemon(const BattleLibrary* library, const Library::PokemonSpecies* species, - const Library::PokemonForme* forme, uint8_t level, uint32_t experience, uint32_t uid, - CreatureLib::Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, - const std::string& nickname, const CreatureLib::Library::TalentIndex& talent, - const List& moves, + Pokemon(const BattleLibrary* library, const ArbUt::BorrowedPtr& species, + const ArbUt::BorrowedPtr& forme, uint8_t level, uint32_t experience, + uint32_t uid, CreatureLib::Library::Gender gender, uint8_t coloring, + ArbUt::BorrowedPtr heldItem, const std::string& nickname, + const CreatureLib::Library::TalentIndex& talent, + const ArbUt::List& moves, CreatureLib::Library::StatisticSet individualValues, CreatureLib::Library::StatisticSet effortValues, const PkmnLib::Library::Nature* nature, bool allowedExperienceGain = true) - : CreatureLib::Battling::Creature(library, species, forme, level, experience, uid, gender, coloring, - heldItem, nickname, talent, moves, allowedExperienceGain), + : CreatureLib::Battling::Creature(library, species.As(), + forme.As(), level, experience, + uid, gender, coloring, heldItem.As(), + nickname, talent, moves, allowedExperienceGain), _individualValues(individualValues), _effortValues(effortValues), _nature(nature) {} - const Library::PokemonForme* GetForme() const { - return dynamic_cast(GetVariant()); + const ArbUt::BorrowedPtr GetForme() const { + return _variant.As(); } inline bool IsShiny() const noexcept { return _coloring == 1; } - const Arbutils::Collections::List& GetMoves() const { - return reinterpret_cast&>(_attacks); + const ArbUt::List& GetMoves() const { + return reinterpret_cast&>(_attacks); } inline const Library::Nature* GetNature() const noexcept { return _nature; } @@ -48,8 +51,8 @@ namespace PkmnLib::Battling { return _effortValues.GetStat(stat); } - inline const PkmnLib::Library::PokemonSpecies* GetPokemonSpecies() const noexcept { - return dynamic_cast(_species); + inline ArbUt::BorrowedPtr GetPokemonSpecies() const noexcept { + return _species.As(); } }; } diff --git a/src/Library/Evolutions/EvolutionData.hpp b/src/Library/Evolutions/EvolutionData.hpp index b089ae5..31e1abf 100644 --- a/src/Library/Evolutions/EvolutionData.hpp +++ b/src/Library/Evolutions/EvolutionData.hpp @@ -17,10 +17,9 @@ namespace PkmnLib::Library { private: const PokemonSpecies* _evolvesInto; EvolutionMethod _method; - Arbutils::Collections::List _evolutionData; + ArbUt::List _evolutionData; - EvolutionData(EvolutionMethod method, - Arbutils::Collections::List data, + EvolutionData(EvolutionMethod method, ArbUt::List data, const PokemonSpecies* next) : _evolvesInto(next), _method(method), _evolutionData(std::move(data)) {} @@ -40,7 +39,7 @@ namespace PkmnLib::Library { {new CreatureLib::Library::EffectParameter((int64_t)friendship)}, 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) { return new EvolutionData(EvolutionMethod::LocationBased, {new CreatureLib::Library::EffectParameter(location)}, into); @@ -68,7 +67,7 @@ namespace PkmnLib::Library { static const EvolutionData* CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded, const PokemonSpecies* into); static inline const EvolutionData* - CreateCustomEvolution(const Arbutils::Collections::List& data, + CreateCustomEvolution(const ArbUt::List& data, const PokemonSpecies* into) { return new EvolutionData(EvolutionMethod::Custom, data, into); } diff --git a/src/Library/Items/Item.hpp b/src/Library/Items/Item.hpp index db56b49..6481d60 100644 --- a/src/Library/Items/Item.hpp +++ b/src/Library/Items/Item.hpp @@ -7,7 +7,7 @@ namespace PkmnLib::Library { uint8_t _flingPower; 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, const std::unordered_set& flags, uint8_t flingPower) noexcept : CreatureLib::Library::Item(name, category, battleCategory, price, flags), _flingPower(flingPower) {} diff --git a/src/Library/Items/ItemLibrary.hpp b/src/Library/Items/ItemLibrary.hpp index 6bfc23e..fc191b5 100644 --- a/src/Library/Items/ItemLibrary.hpp +++ b/src/Library/Items/ItemLibrary.hpp @@ -6,16 +6,21 @@ namespace PkmnLib::Library { class ItemLibrary : public CreatureLib::Library::ItemLibrary { public: - inline bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const Item*& item) const { - return CreatureLib::Library::ItemLibrary::TryGet(name, (const CreatureLib::Library::Item*&)item); + inline bool TryGet(const ArbUt::CaseInsensitiveConstString& name, ArbUt::BorrowedPtr& item) const { + auto v = item.As(); + auto res = CreatureLib::Library::ItemLibrary::TryGet(name.GetHash(), v); + item = v.ForceAs(); + return res; } - inline const Item* Get(const Arbutils::CaseInsensitiveConstString& name) const { - return reinterpret_cast(CreatureLib::Library::ItemLibrary::Get(name)); + inline ArbUt::BorrowedPtr Get(const ArbUt::CaseInsensitiveConstString& name) const { + return CreatureLib::Library::ItemLibrary::Get(name).ForceAs(); + } + inline ArbUt::BorrowedPtr 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); } }; diff --git a/src/Library/Moves/MoveData.cpp b/src/Library/Moves/MoveData.cpp index 9c2faf2..72432ec 100644 --- a/src/Library/Moves/MoveData.cpp +++ b/src/Library/Moves/MoveData.cpp @@ -1,6 +1,6 @@ #include "MoveData.hpp" #include -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, uint8_t baseUsage, CreatureLib::Library::AttackTarget target, int8_t priority, const CreatureLib::Library::SecondaryEffect* effect, diff --git a/src/Library/Moves/MoveData.hpp b/src/Library/Moves/MoveData.hpp index 2a359a1..798dbe8 100644 --- a/src/Library/Moves/MoveData.hpp +++ b/src/Library/Moves/MoveData.hpp @@ -8,10 +8,10 @@ namespace PkmnLib::Library { class MoveData : public CreatureLib::Library::AttackData { private: public: - MoveData(const Arbutils::CaseInsensitiveConstString& name, uint8_t type, - PkmnLib::Library::MoveCategory category, uint8_t power, uint8_t accuracy, uint8_t baseUsage, - CreatureLib::Library::AttackTarget target, int8_t priority, - const CreatureLib::Library::SecondaryEffect* effect, std::unordered_set flags); + MoveData(const ArbUt::CaseInsensitiveConstString& name, uint8_t type, PkmnLib::Library::MoveCategory category, + uint8_t power, uint8_t accuracy, uint8_t baseUsage, CreatureLib::Library::AttackTarget target, + int8_t priority, const CreatureLib::Library::SecondaryEffect* effect, + std::unordered_set flags); PkmnLib::Library::MoveCategory GetCategory() const; }; diff --git a/src/Library/Moves/MoveLibrary.hpp b/src/Library/Moves/MoveLibrary.hpp index 63af8b2..fb0f44d 100644 --- a/src/Library/Moves/MoveLibrary.hpp +++ b/src/Library/Moves/MoveLibrary.hpp @@ -8,18 +8,19 @@ namespace PkmnLib::Library { public: MoveLibrary(size_t initialCapacity = 32) : CreatureLib::Library::AttackLibrary(initialCapacity) {} - virtual const MoveData* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); } - - inline bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const MoveData*& move) const { - const CreatureLib::Library::AttackData* ptr; - if (CreatureLib::Library::AttackLibrary::TryGet(name, ptr)) { - move = dynamic_cast(ptr); - return true; - } - return false; + virtual ArbUt::BorrowedPtr operator[](const ArbUt::CaseInsensitiveConstString& name) const { + return Get(name); } - const MoveData* Get(const Arbutils::CaseInsensitiveConstString& name) const { - return dynamic_cast(CreatureLib::Library::AttackLibrary::Get(name)); + + inline bool TryGet(const ArbUt::CaseInsensitiveConstString& name, + ArbUt::BorrowedPtr& move) const { + auto v = move.As(); + auto res = CreatureLib::Library::AttackLibrary::TryGet(name, v); + move = v.As(); + return res; + } + inline ArbUt::BorrowedPtr Get(const ArbUt::CaseInsensitiveConstString& name) const { + return CreatureLib::Library::AttackLibrary::Get(name).As(); } }; } diff --git a/src/Library/Natures/NatureLibrary.hpp b/src/Library/Natures/NatureLibrary.hpp index 83b23e5..d781aec 100644 --- a/src/Library/Natures/NatureLibrary.hpp +++ b/src/Library/Natures/NatureLibrary.hpp @@ -12,11 +12,11 @@ namespace PkmnLib::Library { class NatureLibrary { private: - Arbutils::Collections::Dictionary _items; + ArbUt::Dictionary _items; public: explicit NatureLibrary(size_t size = 32) noexcept - : _items(Arbutils::Collections::Dictionary(size)) {} + : _items(ArbUt::Dictionary(size)) {} ~NatureLibrary() { 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); } - inline const Nature* GetNatureByName(const Arbutils::CaseInsensitiveConstString& name) const { + inline const Nature* GetNatureByName(const ArbUt::CaseInsensitiveConstString& name) const { return _items[name]; } - inline const Arbutils::CaseInsensitiveConstString& - GetRandomNatureName(Arbutils::Random rand = Arbutils::Random()) const { + inline const ArbUt::CaseInsensitiveConstString& + GetRandomNatureName(ArbUt::Random rand = ArbUt::Random()) const { auto i = rand.Get(_items.Count()); auto& map = _items.GetStdMap(); 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& map = _items.GetStdMap(); 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) { if (v.second == nature) { return v.first; diff --git a/src/Library/PokemonLibrary.hpp b/src/Library/PokemonLibrary.hpp index 6a3f6a7..9f702d6 100644 --- a/src/Library/PokemonLibrary.hpp +++ b/src/Library/PokemonLibrary.hpp @@ -21,20 +21,20 @@ namespace PkmnLib::Library { CreatureLib::Library::TypeLibrary* typeLibrary, NatureLibrary* natures) : DataLibrary(settings, species, moves, items, growthRates, typeLibrary), _natures(natures) {} - const PkmnLib::Library::LibrarySettings* GetSettings() const { - return static_cast(CreatureLib::Library::DataLibrary::GetSettings()); + const std::unique_ptr& GetSettings() const { + return (const std::unique_ptr&)CreatureLib::Library::DataLibrary::GetSettings(); } - [[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const { - return (const SpeciesLibrary*)(CreatureLib::Library::DataLibrary::GetSpeciesLibrary()); + [[nodiscard]] const std::unique_ptr& GetSpeciesLibrary() const { + return (const std::unique_ptr&)CreatureLib::Library::DataLibrary::GetSpeciesLibrary(); } - [[nodiscard]] const MoveLibrary* GetMoveLibrary() const { - return (const MoveLibrary*)(CreatureLib::Library::DataLibrary::GetAttackLibrary()); + [[nodiscard]] const std::unique_ptr& GetMoveLibrary() const { + return (const std::unique_ptr&)CreatureLib::Library::DataLibrary::GetAttackLibrary(); } - [[nodiscard]] const ItemLibrary* GetItemLibrary() const { - return (const ItemLibrary*)(CreatureLib::Library::DataLibrary::GetItemLibrary()); + [[nodiscard]] const std::unique_ptr& GetItemLibrary() const { + return (const std::unique_ptr&)CreatureLib::Library::DataLibrary::GetItemLibrary(); } [[nodiscard]] const NatureLibrary* GetNatureLibrary() const noexcept { return _natures; } diff --git a/src/Library/Species/PokemonForme.cpp b/src/Library/Species/PokemonForme.cpp index de5267b..9561921 100644 --- a/src/Library/Species/PokemonForme.cpp +++ b/src/Library/Species/PokemonForme.cpp @@ -1,7 +1,8 @@ #include "PokemonForme.hpp" -PkmnLib::Library::PokemonForme::PokemonForme(ConstString name, float height, float weight, uint32_t baseExperience, - const List& types, +PkmnLib::Library::PokemonForme::PokemonForme(ArbUt::CaseInsensitiveConstString name, float height, float weight, + uint32_t baseExperience, const ArbUt::List& types, CreatureLib::Library::StatisticSet baseStats, - const List& talents, const List& secretTalents, + const ArbUt::List& talents, + const ArbUt::List& secretTalents, const CreatureLib::Library::LearnableAttacks* attacks) : SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks) {} diff --git a/src/Library/Species/PokemonForme.hpp b/src/Library/Species/PokemonForme.hpp index 3deb17d..9ac7aa7 100644 --- a/src/Library/Species/PokemonForme.hpp +++ b/src/Library/Species/PokemonForme.hpp @@ -7,13 +7,16 @@ namespace PkmnLib::Library { class PokemonForme : public CreatureLib::Library::SpeciesVariant { public: - PokemonForme(ConstString name, float height, float weight, uint32_t baseExperience, const List& types, - CreatureLib::Library::StatisticSet baseStats, const List& talents, - const List& secretTalents, const CreatureLib::Library::LearnableAttacks* attacks); + PokemonForme(ArbUt::CaseInsensitiveConstString name, float height, float weight, uint32_t baseExperience, + const ArbUt::List& types, CreatureLib::Library::StatisticSet baseStats, + const ArbUt::List& talents, + const ArbUt::List& secretTalents, + const CreatureLib::Library::LearnableAttacks* attacks); private: 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); } }; diff --git a/src/Library/Species/PokemonSpecies.hpp b/src/Library/Species/PokemonSpecies.hpp index c36cc17..a9ee7f7 100644 --- a/src/Library/Species/PokemonSpecies.hpp +++ b/src/Library/Species/PokemonSpecies.hpp @@ -8,11 +8,11 @@ namespace PkmnLib::Library { class PokemonSpecies : public CreatureLib::Library::CreatureSpecies { private: uint8_t _baseHappiness; - Arbutils::Collections::List _evolutions; + ArbUt::List _evolutions; public: - PokemonSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name, const PokemonForme* defaultForme, - float genderRatio, const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate, + PokemonSpecies(uint16_t id, const ArbUt::CaseInsensitiveConstString& name, const PokemonForme* defaultForme, + float genderRatio, const ArbUt::CaseInsensitiveConstString& growthRate, uint8_t captureRate, uint8_t baseHappiness) noexcept : CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate), _baseHappiness(baseHappiness) {} @@ -25,22 +25,26 @@ namespace PkmnLib::Library { inline uint8_t GetBaseHappiness() const { return _baseHappiness; } - inline const PokemonForme* GetDefaultForme() const { - return reinterpret_cast(CreatureSpecies::GetVariant("default"_cnc.GetHash())); + inline ArbUt::BorrowedPtr GetDefaultForme() const { + return CreatureSpecies::GetVariant("default"_cnc.GetHash()).As(); } - 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 { - return TryGetVariant(key, (const CreatureLib::Library::SpeciesVariant*&)forme); + inline bool TryGetForme(const ArbUt::CaseInsensitiveConstString& key, + ArbUt::BorrowedPtr& forme) const { + auto v = forme.As(); + auto res = TryGetVariant(key, v); + forme = v.As(); + return res; } - inline const PokemonForme* GetForme(const Arbutils::CaseInsensitiveConstString& key) const { - return reinterpret_cast(CreatureSpecies::GetVariant(key)); + inline ArbUt::BorrowedPtr GetForme(const ArbUt::CaseInsensitiveConstString& key) const { + return CreatureSpecies::GetVariant(key).As(); } inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); } - const Arbutils::Collections::List& GetEvolutions() const noexcept { return _evolutions; } + const ArbUt::List& GetEvolutions() const noexcept { return _evolutions; } }; } diff --git a/src/Library/Species/SpeciesLibrary.hpp b/src/Library/Species/SpeciesLibrary.hpp index 2d3f13c..a1d9376 100644 --- a/src/Library/Species/SpeciesLibrary.hpp +++ b/src/Library/Species/SpeciesLibrary.hpp @@ -7,18 +7,23 @@ namespace PkmnLib::Library { class SpeciesLibrary : public CreatureLib::Library::SpeciesLibrary { public: - inline bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const PokemonSpecies*& outSpecies) const { - return CreatureLib::Library::SpeciesLibrary::TryGet( - name, (const CreatureLib::Library::CreatureSpecies*&)outSpecies); + inline bool TryGet(const ArbUt::CaseInsensitiveConstString& name, + ArbUt::BorrowedPtr& outSpecies) const { + auto v = outSpecies.As(); + auto res = CreatureLib::Library::SpeciesLibrary::TryGet(name, v); + outSpecies = v.As(); + return res; } - inline const PokemonSpecies* Get(const Arbutils::CaseInsensitiveConstString& name) const { - return dynamic_cast(CreatureLib::Library::SpeciesLibrary::Get(name)); + inline ArbUt::BorrowedPtr Get(const ArbUt::CaseInsensitiveConstString& name) const { + return CreatureLib::Library::SpeciesLibrary::Get(name).As(); } - const PokemonSpecies* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); } + ArbUt::BorrowedPtr 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); } }; diff --git a/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp b/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp index 3e1ba1b..3d4ed75 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp @@ -82,8 +82,8 @@ void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg) RegisterTypes(); RegisterExceptionRoutines(_engine); - auto staticLib = library->GetStaticLib(); - _engine->RegisterGlobalProperty("const StaticLibrary@ StaticLib", &staticLib); + auto& staticLib = library->GetStaticLib(); + _engine->RegisterGlobalProperty("const StaticLibrary@ StaticLib", (void*)staticLib.get()); _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) { - Dictionary innerDb; + ArbUt::Dictionary innerDb; if (!_typeDatabase.TryGet(category, innerDb)) { _typeDatabase.Insert(category, innerDb); return nullptr; @@ -156,14 +156,14 @@ void AngelScriptResolver::FinalizeModule() { for (size_t m = 0; m < metadata.size(); m++) { auto data = metadata[m]; 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(); if (!std::regex_match(metadataVariables, base_match, variableMatcher)) { continue; } ConstString effectName; 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(); effectName = ConstString(val); } @@ -296,17 +296,17 @@ void AngelScriptResolver::LoadByteCodeFromMemory(uint8_t* byte, size_t size) { delete stream; } void AngelScriptResolver::InitializeByteCode( - asIBinaryStream* stream, const Dictionary>& types) { + asIBinaryStream* stream, const ArbUt::Dictionary>& types) { auto typeCount = _mainModule->GetObjectTypeCount(); - Dictionary objectTypes; + ArbUt::Dictionary objectTypes; for (asUINT i = 0; i < typeCount; i++) { auto t = _mainModule->GetObjectTypeByIndex(i); objectTypes.Insert(ConstString::GetHash(t->GetName()), t); } - Dictionary> typeDatabase; + ArbUt::Dictionary> typeDatabase; for (const auto& innerDb : types) { - Dictionary newInnerDb; + ArbUt::Dictionary newInnerDb; for (const auto& val : innerDb.second) { auto decl = val.second; auto type = objectTypes[decl]; diff --git a/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp b/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp index e1e30ba..a7e073b 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp @@ -10,7 +10,6 @@ #include #include "AngelScriptScript.hpp" #include "AngelScriptTypeInfo.hpp" -using namespace Arbutils::Collections; class AngelScriptResolver : public CreatureLib::Battling::ScriptResolver { private: @@ -21,12 +20,14 @@ private: static void MessageCallback(const asSMessageInfo* msg, void* param); static void Print(const std::string& str) { std::cout << str << std::endl; } - Dictionary> _typeDatabase; - Dictionary _baseTypes; + ArbUt::Dictionary> + _typeDatabase; + ArbUt::Dictionary _baseTypes; void RegisterTypes(); - void InitializeByteCode(asIBinaryStream* stream, - const Dictionary>& types); + void InitializeByteCode( + asIBinaryStream* stream, + const ArbUt::Dictionary>& types); public: ~AngelScriptResolver() override { @@ -51,7 +52,8 @@ public: uint8_t* WriteByteCodeToMemory(size_t& size, bool stripDebugInfo = false); void LoadByteCodeFromMemory(uint8_t*, size_t size); - const Dictionary>& GetTypeDatabase() const noexcept { + const ArbUt::Dictionary>& + GetTypeDatabase() const noexcept { return _typeDatabase; } diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp index c6879c1..c5eb6de 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp @@ -42,8 +42,7 @@ ctx->PopState(); \ } -CScriptArray* -AngelScriptScript::GetEffectParameters(const Arbutils::Collections::List& ls) { +CScriptArray* AngelScriptScript::GetEffectParameters(const ArbUt::List& ls) { asITypeInfo* t = _resolver->GetBaseType("array"_cnc); CScriptArray* arr = CScriptArray::Create(t, ls.Count()); for (size_t i = 0; i < ls.Count(); i++) { @@ -52,7 +51,7 @@ AngelScriptScript::GetEffectParameters(const Arbutils::Collections::List& parameters) { +void AngelScriptScript::OnInitialize(const ArbUt::List& parameters) { CScriptArray* arr = nullptr; CALL_HOOK(OnInitialize, { arr = GetEffectParameters(parameters); diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp index 27bdc13..fe7e6b9 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp @@ -18,7 +18,7 @@ private: ContextPool* _ctxPool = nullptr; asIScriptObject* _obj = nullptr; - CScriptArray* GetEffectParameters(const Arbutils::Collections::List& ls); + CScriptArray* GetEffectParameters(const ArbUt::List& ls); public: AngelScriptScript(AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj, @@ -27,9 +27,11 @@ public: ~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); ctx->Prepare(func); ctx->SetObject(_obj); @@ -38,14 +40,15 @@ public: ContextPool* GetContextPool() { return _ctxPool; } - void OnInitialize(const Arbutils::Collections::List& parameters) override; + void OnInitialize(const ArbUt::List& parameters) override; void Stack() override; void OnRemove() 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; diff --git a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp index 2ebb203..fd69825 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp @@ -10,13 +10,11 @@ #include #include -using ConstString = Arbutils::CaseInsensitiveConstString; - class AngelScriptTypeInfo { private: asITypeInfo* _type = nullptr; - Arbutils::Collections::Dictionary _functions; - ConstString _name; + ArbUt::Dictionary _functions; + ArbUt::CaseInsensitiveConstString _name; struct FunctionInfo { bool Exists = false; @@ -35,7 +33,8 @@ private: } 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() { for (const auto& f : _functions) { f.second->Release(); @@ -43,11 +42,11 @@ public: _functions.Clear(); } - const ConstString& GetName() const noexcept { return _name; } + const ArbUt::CaseInsensitiveConstString& GetName() const noexcept { return _name; } const char* GetDecl() { return _type->GetName(); } - asIScriptFunction* GetFunction(const ConstString& functionName) { + asIScriptFunction* GetFunction(const ArbUt::CaseInsensitiveConstString& functionName) { asIScriptFunction* func; if (_functions.TryGet(functionName, func)) { return func; diff --git a/src/ScriptResolving/AngelScript/ByteCodeHandling/IPkmnBinaryStream.hpp b/src/ScriptResolving/AngelScript/ByteCodeHandling/IPkmnBinaryStream.hpp index 5c1342f..8227955 100644 --- a/src/ScriptResolving/AngelScript/ByteCodeHandling/IPkmnBinaryStream.hpp +++ b/src/ScriptResolving/AngelScript/ByteCodeHandling/IPkmnBinaryStream.hpp @@ -13,7 +13,8 @@ protected: IPkmnBinaryStream(size_t angelScriptBound) : _angelScriptBound(angelScriptBound) {} public: - virtual void WriteTypes(const Dictionary>& types) { + virtual void + WriteTypes(const ArbUt::Dictionary>& types) { // We serialize our types in the format // "[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)); } } - virtual Dictionary> ReadTypes() { + virtual ArbUt::Dictionary> ReadTypes() { _angelScriptBound = SIZE_MAX; - Dictionary> types; + ArbUt::Dictionary> types; ScriptCategory categoryArr[1]; while (true) { // Every inner database starts with the category, of known size. Read that. @@ -48,7 +49,7 @@ public: if (read == 0) { break; } - Dictionary innerDb; + ArbUt::Dictionary innerDb; // We don't know the sizes of the name and decl. Allocate 128 characters for them, as that should be enough. char name[128]; @@ -67,8 +68,8 @@ public: if (isDecl) { // Insert the name and decl into the dictionary. Close off the decl with eof as well. decl[pos] = '\0'; - innerDb.Insert(Arbutils::CaseInsensitiveConstString(name), - Arbutils::CaseInsensitiveConstString::GetHash(decl)); + innerDb.Insert(ArbUt::CaseInsensitiveConstString(name), + ArbUt::CaseInsensitiveConstString::GetHash(decl)); } // If we have found \1, we are done with the current category, so break. break; @@ -79,8 +80,8 @@ public: if (isDecl) { // Insert the name and decl into the dictionary. Close off the decl with eof as well. decl[pos] = '\0'; - innerDb.Insert(Arbutils::CaseInsensitiveConstString(name), - Arbutils::CaseInsensitiveConstString::GetHash(decl)); + innerDb.Insert(ArbUt::CaseInsensitiveConstString(name), + ArbUt::CaseInsensitiveConstString::GetHash(decl)); // Reset our position and toggle back to name. pos = 0; isDecl = false; diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp index 2975ea5..4b168af 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp @@ -77,7 +77,7 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { Assert(r >= 0); r = engine->RegisterObjectMethod( "Battle", "const constString& GetWeatherName() const", - asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const Arbutils::CaseInsensitiveConstString&), + asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::CaseInsensitiveConstString&), asCALL_THISCALL); Assert(r >= 0); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp index fbf44a0..4739ec6 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp @@ -4,6 +4,7 @@ #include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h" #include "../../../../Battling/PkmnDamageSource.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. #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()); } +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) { [[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT); Assert(r >= 0); 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); - r = engine->RegisterObjectMethod("Pokemon", "const Forme@ get_Forme() const property", - asMETHOD(PkmnLib::Battling::Pokemon, GetForme), asCALL_THISCALL); + r = engine->RegisterObjectMethod("Pokemon", "const Forme@ get_Forme() const property", asFUNCTION(GetFormeWrapper), + asCALL_CDECL_OBJLAST); Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Level() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetLevel), asCALL_THISCALL); @@ -117,20 +122,20 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { asMETHOD(PkmnLib::Battling::Pokemon, IsShiny), asCALL_THISCALL); Assert(r >= 0); 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); r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const", asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST); Assert(r >= 0); r = engine->RegisterObjectMethod( "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); Assert(r >= 0); - r = engine->RegisterObjectMethod( - "Pokemon", "void SetHeldItem(const Item@ item)", - asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const CreatureLib::Library::Item*), void), - asCALL_THISCALL); + r = engine->RegisterObjectMethod("Pokemon", "void SetHeldItem(const Item@ item)", + asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, + (const ArbUt::BorrowedPtr&), void), + asCALL_THISCALL); Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint32 get_CurrentHealth() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetCurrentHealth), asCALL_THISCALL); diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/ConstString.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/ConstString.cpp index d152308..ef4a8f2 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/ConstString.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/ConstString.cpp @@ -1,5 +1,5 @@ #include "ConstString.hpp" -using ConstString = Arbutils::CaseInsensitiveConstString; +using ConstString = ArbUt::CaseInsensitiveConstString; static void ConstructConstString(void* self) { new (self) ConstString(); } 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(); } 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); Assert(r >= 0); diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/HelperFile.hpp b/src/ScriptResolving/AngelScript/TypeRegistry/HelperFile.hpp new file mode 100644 index 0000000..230138f --- /dev/null +++ b/src/ScriptResolving/AngelScript/TypeRegistry/HelperFile.hpp @@ -0,0 +1,2 @@ +#define SMART_PTR_GETTER_FUNC(o, returns, funcName) \ + static returns* funcName##Wrapper(o* obj) { return obj->funcName().operator->(); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterEffectParameter.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterEffectParameter.cpp index 46d7a04..2105260 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterEffectParameter.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterEffectParameter.cpp @@ -4,7 +4,7 @@ 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(); } @@ -38,7 +38,7 @@ void RegisterEffectParameter::Register(asIScriptEngine* engine) { Assert(r >= 0); r = engine->RegisterObjectMethod("EffectParameter", "const constString& AsString() const", asFUNCTIONPR(AsString, (const CreatureLib::Library::EffectParameter*), - const Arbutils::CaseInsensitiveConstString&), + const ArbUt::CaseInsensitiveConstString&), asCALL_CDECL_OBJFIRST); Assert(r >= 0); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterItemTypes.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterItemTypes.cpp index 6c9760b..b6f3b76 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterItemTypes.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterItemTypes.cpp @@ -58,7 +58,7 @@ void RegisterItemTypes::RegisterBattleItemCategoryEnum(asIScriptEngine* engine) ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::Item, GetCategory) 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); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterMoveTypes.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterMoveTypes.cpp index 2cd966f..fe5b86a 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterMoveTypes.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterMoveTypes.cpp @@ -46,7 +46,7 @@ void RegisterMoveTypes::RegisterMoveTarget(asIScriptEngine* engine) { ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::MoveData, GetCategory) 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); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterSpeciesTypes.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterSpeciesTypes.cpp index cb25663..bb187f3 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterSpeciesTypes.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterSpeciesTypes.cpp @@ -3,6 +3,7 @@ #include "../../../../Library/Species/PokemonSpecies.hpp" #include "../../../../Library/Species/SpeciesLibrary.hpp" #include "../../../../Library/Statistic.hpp" +#include "../HelperFile.hpp" void RegisterSpeciesTypes::Register(asIScriptEngine* engine) { RegisterGenderEnum(engine); @@ -42,8 +43,11 @@ void RegisterSpeciesTypes::RegisterStatisticEnum(asIScriptEngine* engine) { static const PkmnLib::Library::PokemonForme* GetFormeWrapper(const std::string& s, 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() + .GetRaw(); } +SMART_PTR_GETTER_FUNC(PkmnLib::Library::PokemonSpecies, const PkmnLib::Library::PokemonForme, GetDefaultForme); void RegisterSpeciesTypes::RegisterSpeciesType(asIScriptEngine* engine) { [[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), asCALL_CDECL_OBJLAST); assert(r >= 0); - r = engine->RegisterObjectMethod("Species", "const Forme@ GetDefaultForme() const", - asMETHOD(PkmnLib::Library::PokemonSpecies, GetDefaultForme), asCALL_THISCALL); + r = engine->RegisterObjectMethod("Species", "const Forme@ get_DefaultForme() const property", + asFUNCTION(GetDefaultFormeWrapper), asCALL_CDECL_OBJLAST); 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)); } @@ -99,10 +103,11 @@ void RegisterSpeciesTypes::RegisterFormeType(asIScriptEngine* engine) { r = engine->RegisterObjectMethod("Forme", "uint GetStatistic(Statistic stat) const", asMETHOD(PkmnLib::Library::PokemonForme, GetStatistic), asCALL_THISCALL); assert(r >= 0); - r = engine->RegisterObjectMethod( - "Forme", "const constString& GetAbility(bool hidden, uint8 index) const", - asFUNCTIONPR(GetAbility, (PkmnLib::Library::PokemonForme * p, bool hidden, uint8_t index), const ConstString&), - asCALL_CDECL_OBJFIRST); + r = engine->RegisterObjectMethod("Forme", "const constString& GetAbility(bool hidden, uint8 index) const", + asFUNCTIONPR(GetAbility, + (PkmnLib::Library::PokemonForme * p, bool hidden, uint8_t index), + const ArbUt::CaseInsensitiveConstString&), + asCALL_CDECL_OBJFIRST); assert(r >= 0); } void RegisterSpeciesTypes::RegisterSpeciesLibrary(asIScriptEngine* engine) { diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterStaticLibraryTypes.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterStaticLibraryTypes.cpp index efca0e8..571a26c 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterStaticLibraryTypes.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterStaticLibraryTypes.cpp @@ -1,6 +1,7 @@ #include "RegisterStaticLibraryTypes.hpp" #include #include "../../../../Library/PokemonLibrary.hpp" +#include "../HelperFile.hpp" void RegisterStaticLibraryTypes::Register(asIScriptEngine* engine) { RegisterLibrarySettingsType(engine); @@ -20,25 +21,32 @@ void RegisterStaticLibraryTypes::RegisterLibrarySettingsType(asIScriptEngine* en 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) { [[maybe_unused]] int r = engine->RegisterObjectType("StaticLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); 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); 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); 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); 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); 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); 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); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterTypeLibrary.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterTypeLibrary.cpp index 32d6a02..e70a988 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterTypeLibrary.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Library/RegisterTypeLibrary.cpp @@ -4,7 +4,7 @@ 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); } diff --git a/tests/PokemonTests/BasicPokemonTests.cpp b/tests/PokemonTests/BasicPokemonTests.cpp index 29aaf77..73a4e92 100644 --- a/tests/PokemonTests/BasicPokemonTests.cpp +++ b/tests/PokemonTests/BasicPokemonTests.cpp @@ -20,12 +20,11 @@ TEST_CASE("Get Nature from Pokemon") { TEST_CASE("Get Attack name from Pokemon") { auto lib = TestLibrary::GetLibrary(); - auto mon = PkmnLib::Battling::CreatePokemon(lib, "testSpecies"_cnc, 1) - .LearnMove(Arbutils::CaseInsensitiveConstString("testMove"), - CreatureLib::Battling::AttackLearnMethod::Level) - .LearnMove(Arbutils::CaseInsensitiveConstString("testMove2"), - CreatureLib::Battling::AttackLearnMethod::Level) - .Build(); + auto mon = + PkmnLib::Battling::CreatePokemon(lib, "testSpecies"_cnc, 1) + .LearnMove(ArbUt::CaseInsensitiveConstString("testMove"), CreatureLib::Battling::AttackLearnMethod::Level) + .LearnMove(ArbUt::CaseInsensitiveConstString("testMove2"), CreatureLib::Battling::AttackLearnMethod::Level) + .Build(); auto move = mon->GetMoves()[0]; REQUIRE(move->GetMoveData()->GetName() == "testMove"_cnc); auto move2 = mon->GetMoves()[1]; diff --git a/tests/PokemonTests/ExperienceGainTests.cpp b/tests/PokemonTests/ExperienceGainTests.cpp index f132a37..9ef782f 100644 --- a/tests/PokemonTests/ExperienceGainTests.cpp +++ b/tests/PokemonTests/ExperienceGainTests.cpp @@ -10,7 +10,7 @@ TEST_CASE("Basic Experience gain test", "battling") { auto mon1 = CreatePokemon(lib, "testSpecies"_cnc, 55).Build(); auto initialExp = mon1->GetExperience(); auto mon2 = CreatePokemon(lib, "testSpecies2"_cnc, 62).Build(); - auto expLib = lib->GetExperienceLibrary(); + auto& expLib = lib->GetExperienceLibrary(); expLib->HandleExperienceGain(mon2, {mon1}); REQUIRE(mon1->GetExperience() - initialExp == 4339); delete mon1; diff --git a/tests/ScriptTests/BaseScriptClassTests.cpp b/tests/ScriptTests/BaseScriptClassTests.cpp index c1cad68..77e340e 100644 --- a/tests/ScriptTests/BaseScriptClassTests.cpp +++ b/tests/ScriptTests/BaseScriptClassTests.cpp @@ -113,7 +113,7 @@ TEST_CASE("Invoke OnInitialize script function") { auto parameters = {new CreatureLib::Library::EffectParameter(true), new CreatureLib::Library::EffectParameter((int64_t)684), - new CreatureLib::Library::EffectParameter(Arbutils::CaseInsensitiveConstString("foobar"))}; + new CreatureLib::Library::EffectParameter(ArbUt::CaseInsensitiveConstString("foobar"))}; script->OnInitialize(parameters); diff --git a/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp b/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp index 0546677..7f21966 100644 --- a/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp +++ b/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp @@ -74,7 +74,7 @@ TEST_CASE("Validate Pokemon Species in Script") { auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies"_cnc, 30).Build(); data.Context->SetArgObject(0, const_cast(mon)); - data.Context->SetArgObject(1, (void*)mon->GetSpecies()); + data.Context->SetArgObject(1, (void*)mon->GetSpecies().GetRaw()); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE((bool)data.Context->GetReturnWord()); @@ -86,8 +86,8 @@ TEST_CASE("Validate Pokemon Forme in Script") { auto data = GetScript(mainLib, "testForme"_cnc); auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies"_cnc, 30).WithForme("default"_cnc).Build(); - data.Context->SetArgObject(0, const_cast(mon)); - data.Context->SetArgObject(1, (void*)mon->GetForme()); + data.Context->SetArgObject(0, (void*)mon); + data.Context->SetArgObject(1, (void*)mon->GetForme().GetRaw()); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE((bool)data.Context->GetReturnWord()); @@ -162,7 +162,7 @@ TEST_CASE("Validate Pokemon HeldItem in Script") { .WithGender(CreatureLib::Library::Gender::Male) .Build(); data.Context->SetArgObject(0, const_cast(mon)); - data.Context->SetArgObject(1, (void*)mon->GetHeldItem()); + data.Context->SetArgObject(1, (void*)mon->GetHeldItem().GetRaw()); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE((bool)data.Context->GetReturnWord()); diff --git a/tests/ScriptTests/ScriptTypeTests/Library/FormesTests.cpp b/tests/ScriptTests/ScriptTypeTests/Library/FormesTests.cpp index 3ba9ded..e644a54 100644 --- a/tests/ScriptTests/ScriptTypeTests/Library/FormesTests.cpp +++ b/tests/ScriptTests/ScriptTypeTests/Library/FormesTests.cpp @@ -62,7 +62,7 @@ TEST_CASE("Validate Forme Name in Script") { auto data = GetScript(mainLib, "testName"_cnc); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); - data.Context->SetArgObject(0, const_cast(forme)); + data.Context->SetArgObject(0, (void*)forme.GetRaw()); auto name = forme->GetName(); data.Context->SetArgAddress(1, &name); @@ -77,7 +77,7 @@ TEST_CASE("Validate Forme Weight in Script") { auto data = GetScript(mainLib, "testWeight"_cnc); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); - data.Context->SetArgObject(0, const_cast(forme)); + data.Context->SetArgObject(0, (void*)forme.GetRaw()); data.Context->SetArgFloat(1, forme->GetWeight()); auto result = data.Context->Execute(); @@ -91,7 +91,7 @@ TEST_CASE("Validate Forme Height in Script") { auto data = GetScript(mainLib, "testHeight"_cnc); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); - data.Context->SetArgObject(0, const_cast(forme)); + data.Context->SetArgObject(0, (void*)forme.GetRaw()); data.Context->SetArgFloat(1, forme->GetHeight()); auto result = data.Context->Execute(); @@ -105,7 +105,7 @@ TEST_CASE("Validate Forme Base Experience in Script") { auto data = GetScript(mainLib, "testBaseExperience"_cnc); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); - data.Context->SetArgObject(0, const_cast(forme)); + data.Context->SetArgObject(0, (void*)forme.GetRaw()); data.Context->SetArgDWord(1, forme->GetBaseExperience()); auto result = data.Context->Execute(); @@ -119,7 +119,7 @@ TEST_CASE("Validate Forme Type Count in Script") { auto data = GetScript(mainLib, "testTypeCount"_cnc); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); - data.Context->SetArgObject(0, const_cast(forme)); + data.Context->SetArgObject(0, (void*)forme.GetRaw()); data.Context->SetArgDWord(1, forme->GetTypeCount()); auto result = data.Context->Execute(); @@ -133,7 +133,7 @@ TEST_CASE("Validate Forme GetType in Script") { auto data = GetScript(mainLib, "testGetType"_cnc); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); - data.Context->SetArgObject(0, const_cast(forme)); + data.Context->SetArgObject(0, (void*)forme.GetRaw()); data.Context->SetArgByte(1, forme->GetType(0)); auto result = data.Context->Execute(); @@ -152,7 +152,7 @@ TEST_CASE("Validate Forme GetStatistic in Script") { auto data = GetScript(mainLib, "testGetStatistic"_cnc); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); - data.Context->SetArgObject(0, const_cast(forme)); + data.Context->SetArgObject(0, (void*)forme.GetRaw()); data.Context->SetArgDWord(1, static_cast(stat)); data.Context->SetArgDWord(2, forme->GetStatistic(stat)); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); @@ -165,7 +165,7 @@ TEST_CASE("Validate Forme GetAbility in Script") { auto data = GetScript(mainLib, "testGetAbility"_cnc); auto forme = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc)->GetDefaultForme(); - data.Context->SetArgObject(0, const_cast(forme)); + data.Context->SetArgObject(0, (void*)forme.GetRaw()); auto ability = forme->GetAbility(CreatureLib::Library::TalentIndex(false, 0)); data.Context->SetArgAddress(1, &ability); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); diff --git a/tests/ScriptTests/ScriptTypeTests/Library/ItemDataTests.cpp b/tests/ScriptTests/ScriptTypeTests/Library/ItemDataTests.cpp index a0f3887..ffa329d 100644 --- a/tests/ScriptTests/ScriptTypeTests/Library/ItemDataTests.cpp +++ b/tests/ScriptTests/ScriptTypeTests/Library/ItemDataTests.cpp @@ -58,7 +58,7 @@ TEST_CASE("Validate Item Name in Script") { auto data = GetScript(mainLib, "testName"_cnc); auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc); - data.Context->SetArgObject(0, const_cast(item)); + data.Context->SetArgObject(0, (void*)item.GetRaw()); auto name = item->GetName(); data.Context->SetArgAddress(1, &name); @@ -71,7 +71,7 @@ TEST_CASE("Validate Item Category in Script") { auto data = GetScript(mainLib, "testCategory"_cnc); auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc); - data.Context->SetArgObject(0, const_cast(item)); + data.Context->SetArgObject(0, (void*)item.GetRaw()); data.Context->SetArgDWord(1, static_cast(item->GetCategory())); 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 item = mainLib->GetItemLibrary()->Get("testItem"_cnc); - data.Context->SetArgObject(0, const_cast(item)); + data.Context->SetArgObject(0, (void*)item.GetRaw()); data.Context->SetArgDWord(1, static_cast(item->GetBattleCategory())); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); @@ -95,7 +95,7 @@ TEST_CASE("Validate Item Price in Script") { auto data = GetScript(mainLib, "testPrice"_cnc); auto item = mainLib->GetItemLibrary()->Get("testItem"_cnc); - data.Context->SetArgObject(0, const_cast(item)); + data.Context->SetArgObject(0, (void*)item.GetRaw()); data.Context->SetArgDWord(1, static_cast(item->GetPrice())); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); diff --git a/tests/ScriptTests/ScriptTypeTests/Library/MoveTests.cpp b/tests/ScriptTests/ScriptTypeTests/Library/MoveTests.cpp index 7f421a2..c0f89b3 100644 --- a/tests/ScriptTests/ScriptTypeTests/Library/MoveTests.cpp +++ b/tests/ScriptTests/ScriptTypeTests/Library/MoveTests.cpp @@ -62,7 +62,7 @@ TEST_CASE("Validate Move Name in Script") { auto data = GetScript(mainLib, "testName"_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(); data.Context->SetArgAddress(1, &name); @@ -75,7 +75,7 @@ TEST_CASE("Validate Move Type in Script") { auto data = GetScript(mainLib, "testType"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); - data.Context->SetArgObject(0, const_cast(move)); + data.Context->SetArgObject(0, (void*)move.GetRaw()); data.Context->SetArgByte(1, move->GetType()); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); @@ -88,7 +88,7 @@ TEST_CASE("Validate Move Category in Script") { auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); - data.Context->SetArgObject(0, const_cast(move)); + data.Context->SetArgObject(0, (void*)move.GetRaw()); data.Context->SetArgDWord(1, (asDWORD)move->GetCategory()); auto result = data.Context->Execute(); @@ -102,7 +102,7 @@ TEST_CASE("Validate Move BasePower in Script") { auto data = GetScript(mainLib, "testBasePower"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); - data.Context->SetArgObject(0, const_cast(move)); + data.Context->SetArgObject(0, (void*)move.GetRaw()); data.Context->SetArgByte(1, move->GetBasePower()); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); @@ -114,7 +114,7 @@ TEST_CASE("Validate Move Accuracy in Script") { auto data = GetScript(mainLib, "testAccuracy"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); - data.Context->SetArgObject(0, const_cast(move)); + data.Context->SetArgObject(0, (void*)move.GetRaw()); data.Context->SetArgByte(1, move->GetAccuracy()); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); @@ -126,7 +126,7 @@ TEST_CASE("Validate Move BaseUsages in Script") { auto data = GetScript(mainLib, "testBaseUsages"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); - data.Context->SetArgObject(0, const_cast(move)); + data.Context->SetArgObject(0, (void*)move.GetRaw()); data.Context->SetArgByte(1, move->GetBaseUsages()); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); @@ -138,7 +138,7 @@ TEST_CASE("Validate Move Target in Script") { auto data = GetScript(mainLib, "testTarget"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); - data.Context->SetArgObject(0, const_cast(move)); + data.Context->SetArgObject(0, (void*)move.GetRaw()); data.Context->SetArgDWord(1, (uint32_t)move->GetTarget()); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); @@ -150,7 +150,7 @@ TEST_CASE("Validate Move Priority in Script") { auto data = GetScript(mainLib, "testPriority"_cnc); auto move = mainLib->GetMoveLibrary()->Get("testMove"_cnc); - data.Context->SetArgObject(0, const_cast(move)); + data.Context->SetArgObject(0, (void*)move.GetRaw()); data.Context->SetArgByte(1, move->GetPriority()); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); diff --git a/tests/ScriptTests/ScriptTypeTests/Library/SpeciesTests.cpp b/tests/ScriptTests/ScriptTypeTests/Library/SpeciesTests.cpp index 2f65e11..e0b3dd7 100644 --- a/tests/ScriptTests/ScriptTypeTests/Library/SpeciesTests.cpp +++ b/tests/ScriptTests/ScriptTypeTests/Library/SpeciesTests.cpp @@ -13,7 +13,7 @@ class testScript1 { bool testGenderRate(const Species@ s, float rate){ return s.GenderRate == 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 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 species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); - data.Context->SetArgObject(0, const_cast(species)); + data.Context->SetArgObject(0, (void*)species.GetRaw()); auto name = species->GetName(); data.Context->SetArgAddress(1, &name); @@ -75,7 +75,7 @@ TEST_CASE("Validate Species Id in Script") { auto data = GetScript(mainLib, "testId"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); - data.Context->SetArgObject(0, const_cast(species)); + data.Context->SetArgObject(0, (void*)species.GetRaw()); data.Context->SetArgWord(1, species->GetId()); auto result = data.Context->Execute(); @@ -89,7 +89,7 @@ TEST_CASE("Validate Species Gender Rate in Script") { auto data = GetScript(mainLib, "testGenderRate"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); - data.Context->SetArgObject(0, const_cast(species)); + data.Context->SetArgObject(0, (void*)species.GetRaw()); data.Context->SetArgFloat(1, species->GetGenderRate()); auto result = data.Context->Execute(); @@ -103,7 +103,7 @@ TEST_CASE("Validate Species Capture Rate in Script") { auto data = GetScript(mainLib, "testCaptureRate"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); - data.Context->SetArgObject(0, const_cast(species)); + data.Context->SetArgObject(0, (void*)species.GetRaw()); data.Context->SetArgByte(1, species->GetCaptureRate()); auto result = data.Context->Execute(); @@ -117,8 +117,8 @@ TEST_CASE("Validate Species Get Forme in Script") { auto data = GetScript(mainLib, "testGetForme"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); - data.Context->SetArgObject(0, const_cast(species)); - data.Context->SetArgObject(1, const_cast(species->GetForme("default"_cnc))); + data.Context->SetArgObject(0, (void*)species.GetRaw()); + data.Context->SetArgObject(1, (void*)species->GetForme("default"_cnc).GetRaw()); auto result = data.Context->Execute(); if (result == asEXECUTION_EXCEPTION) { @@ -134,8 +134,8 @@ TEST_CASE("Validate Species Get Default Forme in Script") { auto data = GetScript(mainLib, "testGetDefaultForme"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); - data.Context->SetArgObject(0, const_cast(species)); - data.Context->SetArgObject(1, const_cast(species->GetDefaultForme())); + data.Context->SetArgObject(0, (void*)species.GetRaw()); + data.Context->SetArgObject(1, (void*)species->GetDefaultForme().GetRaw()); auto result = data.Context->Execute(); REQUIRE(result == asEXECUTION_FINISHED); diff --git a/tests/ScriptTests/ScriptTypeTests/Library/StaticLibraryTests.cpp b/tests/ScriptTests/ScriptTypeTests/Library/StaticLibraryTests.cpp index b2c0184..4c47f85 100644 --- a/tests/ScriptTests/ScriptTypeTests/Library/StaticLibraryTests.cpp +++ b/tests/ScriptTests/ScriptTypeTests/Library/StaticLibraryTests.cpp @@ -60,7 +60,7 @@ TEST_CASE("Validate StaticLibrary Maximum Level in Script") { auto mainLib = TestLibrary::GetLibrary(); auto data = GetScript(mainLib, "testMaximumLevel"_cnc); - data.Context->SetArgObject(0, const_cast(mainLib->GetStaticLib())); + data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get()); data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings()->GetMaximalLevel()); auto result = data.Context->Execute(); @@ -73,7 +73,7 @@ TEST_CASE("Validate StaticLibrary Maximum Moves in Script") { auto mainLib = TestLibrary::GetLibrary(); auto data = GetScript(mainLib, "testMaximumMoves"_cnc); - data.Context->SetArgObject(0, const_cast(mainLib->GetStaticLib())); + data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get()); data.Context->SetArgByte(1, mainLib->GetStaticLib()->GetSettings()->GetMaximalMoves()); auto result = data.Context->Execute(); @@ -86,9 +86,8 @@ TEST_CASE("Validate StaticLibrary Species Library in Script") { auto mainLib = TestLibrary::GetLibrary(); auto data = GetScript(mainLib, "testSpeciesLibrary"_cnc); - data.Context->SetArgObject(0, const_cast(mainLib->GetStaticLib())); - data.Context->SetArgObject( - 1, const_cast(mainLib->GetStaticLib()->GetSpeciesLibrary())); + data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get()); + data.Context->SetArgObject(1, (void*)mainLib->GetStaticLib()->GetSpeciesLibrary().get()); auto result = data.Context->Execute(); REQUIRE(result == asEXECUTION_FINISHED); @@ -100,9 +99,8 @@ TEST_CASE("Validate StaticLibrary Move Library in Script") { auto mainLib = TestLibrary::GetLibrary(); auto data = GetScript(mainLib, "testMoveLibrary"_cnc); - data.Context->SetArgObject(0, const_cast(mainLib->GetStaticLib())); - data.Context->SetArgObject(1, - const_cast(mainLib->GetStaticLib()->GetMoveLibrary())); + data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get()); + data.Context->SetArgObject(1, (void*)mainLib->GetStaticLib()->GetMoveLibrary().get()); auto result = data.Context->Execute(); REQUIRE(result == asEXECUTION_FINISHED); @@ -114,9 +112,8 @@ TEST_CASE("Validate StaticLibrary Item Library in Script") { auto mainLib = TestLibrary::GetLibrary(); auto data = GetScript(mainLib, "testItemLibrary"_cnc); - data.Context->SetArgObject(0, const_cast(mainLib->GetStaticLib())); - data.Context->SetArgObject(1, - const_cast(mainLib->GetStaticLib()->GetItemLibrary())); + data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get()); + data.Context->SetArgObject(1, (void*)mainLib->GetStaticLib()->GetItemLibrary().get()); auto result = data.Context->Execute(); REQUIRE(result == asEXECUTION_FINISHED); @@ -128,9 +125,8 @@ TEST_CASE("Validate StaticLibrary Growth Rate Library in Script") { auto mainLib = TestLibrary::GetLibrary(); auto data = GetScript(mainLib, "testGrowthRateLibrary"_cnc); - data.Context->SetArgObject(0, const_cast(mainLib->GetStaticLib())); - data.Context->SetArgObject( - 1, const_cast(mainLib->GetStaticLib()->GetGrowthRates())); + data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get()); + data.Context->SetArgObject(1, (void*)mainLib->GetStaticLib()->GetGrowthRates().get()); auto result = data.Context->Execute(); REQUIRE(result == asEXECUTION_FINISHED); @@ -142,9 +138,8 @@ TEST_CASE("Validate StaticLibrary Type Library in Script") { auto mainLib = TestLibrary::GetLibrary(); auto data = GetScript(mainLib, "testTypeLibrary"_cnc); - data.Context->SetArgObject(0, const_cast(mainLib->GetStaticLib())); - data.Context->SetArgObject( - 1, const_cast(mainLib->GetStaticLib()->GetTypeLibrary())); + data.Context->SetArgObject(0, (void*)mainLib->GetStaticLib().get()); + data.Context->SetArgObject(1, (void*)mainLib->GetStaticLib()->GetTypeLibrary().get()); auto result = data.Context->Execute(); REQUIRE(result == asEXECUTION_FINISHED);