Add support for Egg Groups.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-08-08 18:41:27 +02:00
parent 2a884a0a8b
commit ca087a7ed8
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 41 additions and 22 deletions

View File

@ -4,9 +4,16 @@ 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 = ArbUt::StringView(name); auto cGrowthRate = ArbUt::StringView(growthRate);
out = new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness);)
const char* growthRate, uint8_t captureRate, uint8_t baseHappiness,
const char* const* eggGroupsRaw, size_t eggGroupsLength) {
Try(
ArbUt::List<ArbUt::StringView> eggGroups(eggGroupsLength);
for (size_t i = 0; i < eggGroupsLength; i++) { eggGroups.Append(ArbUt::StringView(eggGroupsRaw[i])); }
auto cName = ArbUt::StringView(name);
auto cGrowthRate = ArbUt::StringView(growthRate);
out = new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness,
eggGroups);)
}
export void PkmnLib_PokemonSpecies_Destruct(const PokemonSpecies* p) { delete p; }
@ -22,4 +29,11 @@ export uint8_t PkmnLib_PokemonSpecies_GetEvolution(const PokemonSpecies* p, size
export uint8_t PkmnLib_PokemonSpecies_GetEvolutions(const PokemonSpecies* p, const EvolutionData* const*& out) {
Try(out = p->GetEvolutions().RawData());
}
export size_t PkmnLib_PokemonSpecies_GetEggGroupCount(const PokemonSpecies* p) {
return p->GetEggGroups().Count();
}
export const char* PkmnLib_PokemonSpecies_GetEggGroup(const PokemonSpecies* p, size_t index){
return p->GetEggGroups()[index].c_str();
}

View File

@ -10,12 +10,14 @@ namespace PkmnLib::Library {
private:
uint8_t _baseHappiness;
ArbUt::UniquePtrList<const EvolutionData> _evolutions;
ArbUt::List<ArbUt::StringView> _eggGroups;
public:
PokemonSpecies(uint16_t id, const ArbUt::StringView& name, const PokemonForme* defaultForme, float genderRatio,
const ArbUt::StringView& growthRate, uint8_t captureRate, uint8_t baseHappiness) noexcept
const ArbUt::StringView& growthRate, uint8_t captureRate, uint8_t baseHappiness,
const ArbUt::List<ArbUt::StringView>& eggGroups) noexcept
: CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate),
_baseHappiness(baseHappiness) {}
_baseHappiness(baseHappiness), _eggGroups(eggGroups) {}
~PokemonSpecies() override = default;
@ -41,6 +43,9 @@ namespace PkmnLib::Library {
inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); }
const ArbUt::UniquePtrList<const EvolutionData>& GetEvolutions() const noexcept { return _evolutions; }
bool HasEggGroup(const ArbUt::StringView& sv) const noexcept { return _eggGroups.Contains(sv); }
const ArbUt::List<ArbUt::StringView>& GetEggGroups() const noexcept { return _eggGroups; }
};
}

View File

@ -17,7 +17,7 @@ TEST_CASE("Able to build, destroy and insert library", "library") {
"default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100));
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}));
delete lib;
}
@ -30,7 +30,7 @@ TEST_CASE("Able to insert and retrieve from library", "library") {
"default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100));
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}));
auto val = lib->Get("foo"_cnc);
REQUIRE(val->GetName() == "foo");
delete lib;

View File

@ -9,7 +9,7 @@ TEST_CASE("Able to create and destroy species", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100);
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
delete species;
}
@ -20,7 +20,7 @@ TEST_CASE("Able to get default forme", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100);
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
auto forme = species->GetDefaultForme();
REQUIRE(forme != nullptr);
@ -35,7 +35,7 @@ TEST_CASE("Able to get default forme name", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100);
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
auto forme = species->GetDefaultForme();
REQUIRE(forme != nullptr);
@ -51,7 +51,7 @@ TEST_CASE("Able to get species name", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100);
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
REQUIRE(species->GetName() == "foo");
@ -65,7 +65,7 @@ TEST_CASE("Able to get species id", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100);
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
REQUIRE(species->GetId() == 1);
@ -79,7 +79,7 @@ TEST_CASE("Able to get species gender ratio", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100);
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
REQUIRE(species->GetGenderRate() == 0.5f);
@ -93,7 +93,7 @@ TEST_CASE("Able to get species growth rate", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100);
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
REQUIRE(species->GetGrowthRate() == "testGrowthRate");
@ -107,7 +107,7 @@ TEST_CASE("Able to get species capture rate", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100);
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
REQUIRE(species->GetCaptureRate() == 100);
@ -121,7 +121,7 @@ TEST_CASE("Able to get species base happiness", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100);
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
REQUIRE(species->GetBaseHappiness() == 100);
@ -135,14 +135,14 @@ TEST_CASE("Able to set and get evolution", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 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<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100);
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2));
auto& evolutions = species->GetEvolutions();

View File

@ -11,7 +11,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
"default"_cnc, 1.0f, 1.0f, 236, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100));
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}));
lib->Insert("testSpecies2"_cnc,
new PkmnLib::Library::PokemonSpecies(
2, "testSpecies2"_cnc,
@ -19,7 +19,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
"default"_cnc, 1.0f, 1.0f, 306, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100));
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}));
lib->Insert("statTestSpecies1"_cnc,
new PkmnLib::Library::PokemonSpecies(
3, "statTestSpecies1"_cnc,
@ -27,7 +27,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
"default"_cnc, 1.0f, 1.0f, 236, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100));
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}));
lib->Insert("testSpecies3"_cnc,
new PkmnLib::Library::PokemonSpecies(
2, "testSpecies3"_cnc,
@ -35,7 +35,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
"default"_cnc, 1.0f, 1.0f, 236, {0, 4},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100));
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}));
return lib;
}