diff --git a/CInterface/Library/PokemonForme.cpp b/CInterface/Library/PokemonForme.cpp new file mode 100644 index 0000000..26b3253 --- /dev/null +++ b/CInterface/Library/PokemonForme.cpp @@ -0,0 +1,34 @@ +#include "../../src/Library/Species/PokemonForme.hpp" +#include "../../src/Library/Species/LearnableMoves.hpp" +#include "../Core.hpp" +using namespace PkmnLib::Library; + +export PokemonForme* PkmnLib_PokemonForme_Construct(const char* name, float height, float weight, + uint32_t baseExperience, uint8_t types[], size_t typeLength, + uint16_t baseHealth, uint16_t baseAttack, uint16_t baseDefense, + uint16_t baseMagicalAttack, uint16_t baseMagicalDefense, + uint16_t baseSpeed, const char* talents[], size_t talentsLength, + const char* secretTalents[], size_t secretTalentsLength, + const LearnableMoves* attacks, const char* flags[], + size_t flagsCount) { + + std::unordered_set conversedFlags(flagsCount); + for (size_t i = 0; i < flagsCount; i++) { + conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i])); + } + + auto talentsWrapped = ArbUt::List(talentsLength); + for (size_t i = 0; i < talentsLength; i++) { + talentsWrapped.Append(ArbUt::StringView(talents[i])); + } + auto secretTalentsWrapped = ArbUt::List(secretTalentsLength); + for (size_t i = 0; i < secretTalentsLength; i++) { + secretTalentsWrapped.Append(ArbUt::StringView(secretTalents[i])); + } + + return new PokemonForme(ArbUt::StringView(name), height, weight, baseExperience, + ArbUt::List(types, types + typeLength), + CreatureLib::Library::StatisticSet( + baseHealth, baseAttack, baseDefense, baseMagicalAttack, baseMagicalDefense, baseSpeed), + talentsWrapped, secretTalentsWrapped, attacks, conversedFlags); +} diff --git a/src/Battling/Battle/Battle.hpp b/src/Battling/Battle/Battle.hpp index 3768240..ccfd873 100644 --- a/src/Battling/Battle/Battle.hpp +++ b/src/Battling/Battle/Battle.hpp @@ -21,7 +21,11 @@ namespace PkmnLib::Battling { void SetWeather(const ArbUt::StringView& name); void ClearWeather(); - const ArbUt::StringView& GetWeatherName() noexcept { return _weatherScript->GetName(); } + const ArbUt::StringView& GetWeatherName() noexcept { + if (_weatherScript == nullptr) + return ArbUt::StringView::EmptyString(); + return _weatherScript->GetName(); + } size_t ScriptCount() const override { return CreatureLib::Battling::Battle::ScriptCount() + 1; } void GetActiveScripts(ArbUt::List& scripts) override { diff --git a/src/Battling/Library/ExperienceLibrary.cpp b/src/Battling/Library/ExperienceLibrary.cpp index 118bad6..20865a9 100644 --- a/src/Battling/Library/ExperienceLibrary.cpp +++ b/src/Battling/Library/ExperienceLibrary.cpp @@ -20,12 +20,15 @@ void PkmnLib::Battling::ExperienceLibrary::HandleExperienceGain( const std::unordered_set>& opponents) const { auto fainted = dynamic_cast(faintedMon); - auto expGain = fainted->GetForme()->GetBaseExperience(); + AssertNotNull(fainted); + auto& forme = fainted->GetForme(); + AssertNotNull(forme); + auto expGain = forme->GetBaseExperience(); auto level = fainted->GetLevel(); float v1 = (expGain * level) / 5; - for (auto op : opponents) { + for (const auto& op : opponents) { if (!op->AllowedExperienceGain()) continue; auto experienceGain = CalculateDynamicExperience(level, v1, op, fainted); diff --git a/src/Battling/Pokemon/Pokemon.hpp b/src/Battling/Pokemon/Pokemon.hpp index 9b8ff47..dcf94fe 100644 --- a/src/Battling/Pokemon/Pokemon.hpp +++ b/src/Battling/Pokemon/Pokemon.hpp @@ -37,7 +37,7 @@ namespace PkmnLib::Battling { _friendship(species->GetBaseHappiness()) {} const ArbUt::BorrowedPtr GetForme() const { - return _variant.As(); + return _variant.ForceAs(); } inline bool IsShiny() const noexcept { return _coloring == 1; } diff --git a/src/Library/Species/LearnableMoves.hpp b/src/Library/Species/LearnableMoves.hpp index 2cdcbe4..91cdc30 100644 --- a/src/Library/Species/LearnableMoves.hpp +++ b/src/Library/Species/LearnableMoves.hpp @@ -7,7 +7,7 @@ #include "../Moves/MoveData.hpp" namespace PkmnLib::Library { - class LearnableMoves : CreatureLib::Library::LearnableAttacks { + class LearnableMoves : public CreatureLib::Library::LearnableAttacks { ArbUt::List> _eggMoves; public: diff --git a/src/Library/Species/PokemonForme.cpp b/src/Library/Species/PokemonForme.cpp index 4f169fe..3d83872 100644 --- a/src/Library/Species/PokemonForme.cpp +++ b/src/Library/Species/PokemonForme.cpp @@ -5,7 +5,6 @@ PkmnLib::Library::PokemonForme::PokemonForme(const ArbUt::StringView& name, floa CreatureLib::Library::StatisticSet baseStats, const ArbUt::List& talents, const ArbUt::List& secretTalents, - const CreatureLib::Library::LearnableAttacks* attacks, - std::unordered_set flags) - : SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks, + const LearnableMoves* moves, std::unordered_set flags) + : SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, moves, std::move(flags)) {} diff --git a/src/Library/Species/PokemonForme.hpp b/src/Library/Species/PokemonForme.hpp index 5e5138e..ec183ea 100644 --- a/src/Library/Species/PokemonForme.hpp +++ b/src/Library/Species/PokemonForme.hpp @@ -3,6 +3,7 @@ #include #include +#include "LearnableMoves.hpp" namespace PkmnLib::Library { class PokemonForme : public CreatureLib::Library::SpeciesVariant { @@ -10,7 +11,7 @@ namespace PkmnLib::Library { PokemonForme(const ArbUt::StringView& 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, std::unordered_set flags = {}); + const LearnableMoves* moves, std::unordered_set flags = {}); private: public: diff --git a/tests/LibraryTests/SpeciesLibraryTests.cpp b/tests/LibraryTests/SpeciesLibraryTests.cpp index c2c1523..dc1f56b 100644 --- a/tests/LibraryTests/SpeciesLibraryTests.cpp +++ b/tests/LibraryTests/SpeciesLibraryTests.cpp @@ -16,7 +16,7 @@ TEST_CASE("Able to build, destroy and insert library", "library") { new PkmnLib::Library::PokemonForme( "default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, - {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), + {"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); delete lib; } @@ -29,7 +29,7 @@ TEST_CASE("Able to insert and retrieve from library", "library") { new PkmnLib::Library::PokemonForme( "default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, - {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), + {"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); auto val = lib->Get("foo"_cnc); REQUIRE(val->GetName() == "foo"); diff --git a/tests/LibraryTests/SpeciesTests.cpp b/tests/LibraryTests/SpeciesTests.cpp index 7508bfc..05ebb8a 100644 --- a/tests/LibraryTests/SpeciesTests.cpp +++ b/tests/LibraryTests/SpeciesTests.cpp @@ -8,7 +8,7 @@ TEST_CASE("Able to create and destroy species", "library") { new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); delete species; } @@ -19,7 +19,7 @@ TEST_CASE("Able to get default forme", "library") { new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); auto forme = species->GetDefaultForme(); @@ -34,7 +34,7 @@ TEST_CASE("Able to get default forme name", "library") { new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); auto forme = species->GetDefaultForme(); @@ -50,7 +50,7 @@ TEST_CASE("Able to get species name", "library") { new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetName() == "foo"); @@ -64,7 +64,7 @@ TEST_CASE("Able to get species id", "library") { new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetId() == 1); @@ -78,7 +78,7 @@ TEST_CASE("Able to get species gender ratio", "library") { new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetGenderRate() == 0.5f); @@ -92,7 +92,7 @@ TEST_CASE("Able to get species growth rate", "library") { new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetGrowthRate() == "testGrowthRate"); @@ -106,7 +106,7 @@ TEST_CASE("Able to get species capture rate", "library") { new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetCaptureRate() == 100); @@ -120,7 +120,7 @@ TEST_CASE("Able to get species base happiness", "library") { new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetBaseHappiness() == 100); @@ -134,14 +134,14 @@ TEST_CASE("Able to set and get evolution", "library") { new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); auto species2 = new PkmnLib::Library::PokemonSpecies( 2, "bar"_cnc, new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, - new CreatureLib::Library::LearnableAttacks(100)), + new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2)); diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index 27cb62c..3cce7af 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -10,7 +10,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { new PkmnLib::Library::PokemonForme( "default"_cnc, 1.0f, 1.0f, 236, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, - {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), + {"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); lib->Insert("testSpecies2"_cnc, new PkmnLib::Library::PokemonSpecies( @@ -18,7 +18,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { new PkmnLib::Library::PokemonForme( "default"_cnc, 1.0f, 1.0f, 306, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, - {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), + {"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); lib->Insert("statTestSpecies1"_cnc, new PkmnLib::Library::PokemonSpecies( @@ -26,7 +26,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { new PkmnLib::Library::PokemonForme( "default"_cnc, 1.0f, 1.0f, 236, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, - {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), + {"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); lib->Insert("testSpecies3"_cnc, new PkmnLib::Library::PokemonSpecies( @@ -34,7 +34,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { new PkmnLib::Library::PokemonForme( "default"_cnc, 1.0f, 1.0f, 236, {0, 4}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, - {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), + {"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); return lib;