From 8f73a9a43a38a1e1e8656dca1e4bf961d228fe78 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 30 Aug 2020 13:53:15 +0200 Subject: [PATCH] Several fixes. --- CInterface/Battling/Pokemon.cpp | 5 +++++ src/Battling/Battle/Battle.cpp | 2 ++ src/Library/Items/ItemLibrary.hpp | 4 ---- src/Library/Species/SpeciesLibrary.hpp | 4 ---- tests/LibraryTests/SpeciesLibraryTests.cpp | 4 ++-- tests/TestLibrary/TestLibrary.cpp | 15 ++++++++------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CInterface/Battling/Pokemon.cpp b/CInterface/Battling/Pokemon.cpp index 7c52e24..b0da1f3 100644 --- a/CInterface/Battling/Pokemon.cpp +++ b/CInterface/Battling/Pokemon.cpp @@ -47,3 +47,8 @@ export const char* PkmnLib_Pokemon_GetStatusName(Pokemon* p) { return p->GetStat SIMPLE_GET_FUNC(Pokemon, GetFriendship, uint8_t) export void PkmnLib_Pokemon_SetFriendship(Pokemon* p, uint8_t value) { p->SetFriendship(value); } export void PkmnLib_Pokemon_ChangeFriendship(Pokemon* p, int8_t amount) { p->ChangeFriendship(amount); } + +export uint8_t PkmnLib_Pokemon_Evolve(Pokemon* p, const PkmnLib::Library::PokemonSpecies* species, + const PkmnLib::Library::PokemonForme* forme) { + Try(p->Evolve(species, forme);) +} \ No newline at end of file diff --git a/src/Battling/Battle/Battle.cpp b/src/Battling/Battle/Battle.cpp index 7937bd7..d349a1b 100644 --- a/src/Battling/Battle/Battle.cpp +++ b/src/Battling/Battle/Battle.cpp @@ -8,6 +8,8 @@ void PkmnLib::Battling::Battle::SetWeather(const ArbUt::StringView& name) { _eventHook.Trigger(name); } void PkmnLib::Battling::Battle::ClearWeather() { + if (_weatherScript == nullptr) + return; _weatherScript->OnRemove(); _weatherScript = nullptr; _eventHook.Trigger(""_cnc); diff --git a/src/Library/Items/ItemLibrary.hpp b/src/Library/Items/ItemLibrary.hpp index ad2925b..829a150 100644 --- a/src/Library/Items/ItemLibrary.hpp +++ b/src/Library/Items/ItemLibrary.hpp @@ -17,10 +17,6 @@ namespace PkmnLib::Library { return CreatureLib::Library::ItemLibrary::Get(name).ForceAs(); } inline ArbUt::BorrowedPtr operator[](const ArbUt::BasicStringView& name) const { return Get(name); } - - void Insert(const ArbUt::StringView& name, const Item* item) { - CreatureLib::Library::ItemLibrary::Insert(name, item); - } }; } diff --git a/src/Library/Species/SpeciesLibrary.hpp b/src/Library/Species/SpeciesLibrary.hpp index 722d0d9..8f25d5b 100644 --- a/src/Library/Species/SpeciesLibrary.hpp +++ b/src/Library/Species/SpeciesLibrary.hpp @@ -26,10 +26,6 @@ namespace PkmnLib::Library { return Get(name); } - void Insert(const ArbUt::StringView& name, const PokemonSpecies* species) { - CreatureLib::Library::SpeciesLibrary::Insert(name, species); - } - ArbUt::BorrowedPtr FindPreEvolution(const ArbUt::BorrowedPtr& species) const noexcept; }; diff --git a/tests/LibraryTests/SpeciesLibraryTests.cpp b/tests/LibraryTests/SpeciesLibraryTests.cpp index dc1f56b..11969f4 100644 --- a/tests/LibraryTests/SpeciesLibraryTests.cpp +++ b/tests/LibraryTests/SpeciesLibraryTests.cpp @@ -10,7 +10,7 @@ TEST_CASE("Able to build and destroy empty library", "library") { TEST_CASE("Able to build, destroy and insert library", "library") { auto lib = new PkmnLib::Library::SpeciesLibrary(); - lib->Insert("foo"_cnc, + lib->Insert("foo"_cnc.GetHash(), new PkmnLib::Library::PokemonSpecies( 1, "foo"_cnc, new PkmnLib::Library::PokemonForme( @@ -23,7 +23,7 @@ TEST_CASE("Able to build, destroy and insert library", "library") { TEST_CASE("Able to insert and retrieve from library", "library") { auto lib = new PkmnLib::Library::SpeciesLibrary(); - lib->Insert("foo"_cnc, + lib->Insert("foo"_cnc.GetHash(), new PkmnLib::Library::PokemonSpecies( 1, "foo"_cnc, new PkmnLib::Library::PokemonForme( diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index 3cce7af..97e4ff5 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -4,7 +4,7 @@ PkmnLib::Battling::BattleLibrary* TestLibrary::_library = nullptr; PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { auto lib = new PkmnLib::Library::SpeciesLibrary(); - lib->Insert("testSpecies"_cnc, + lib->Insert("testSpecies"_cnc.GetHash(), new PkmnLib::Library::PokemonSpecies( 1, "testSpecies"_cnc, new PkmnLib::Library::PokemonForme( @@ -12,7 +12,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); - lib->Insert("testSpecies2"_cnc, + lib->Insert("testSpecies2"_cnc.GetHash(), new PkmnLib::Library::PokemonSpecies( 2, "testSpecies2"_cnc, new PkmnLib::Library::PokemonForme( @@ -20,7 +20,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); - lib->Insert("statTestSpecies1"_cnc, + lib->Insert("statTestSpecies1"_cnc.GetHash(), new PkmnLib::Library::PokemonSpecies( 3, "statTestSpecies1"_cnc, new PkmnLib::Library::PokemonForme( @@ -28,9 +28,9 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)), 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); - lib->Insert("testSpecies3"_cnc, + lib->Insert("testSpecies3"_cnc.GetHash(), new PkmnLib::Library::PokemonSpecies( - 2, "testSpecies3"_cnc, + 4, "testSpecies3"_cnc, new PkmnLib::Library::PokemonForme( "default"_cnc, 1.0f, 1.0f, 236, {0, 4}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, @@ -53,7 +53,8 @@ PkmnLib::Library::MoveLibrary* TestLibrary::BuildMoveLibrary() { } PkmnLib::Library::ItemLibrary* TestLibrary::BuildItemLibrary() { auto lib = new PkmnLib::Library::ItemLibrary(); - lib->Insert("testItem"_cnc, new PkmnLib::Library::Item("testItem"_cnc, CreatureLib::Library::ItemCategory::MiscItem, - CreatureLib::Library::BattleItemCategory::None, 0, {}, 0)); + lib->Insert("testItem"_cnc.GetHash(), + new PkmnLib::Library::Item("testItem"_cnc, CreatureLib::Library::ItemCategory::MiscItem, + CreatureLib::Library::BattleItemCategory::None, 0, {}, 0)); return lib; }