Updates CreatureLib, implements ConstStrings.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include "CreatePokemon.hpp"
|
||||
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(CreatureLib::Core::Random rand) {
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(Arbutils::Random rand) {
|
||||
_ivHp = rand.Get(0, 32);
|
||||
_ivAttack = rand.Get(0, 32);
|
||||
_ivDefense = rand.Get(0, 32);
|
||||
@@ -38,15 +37,15 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortVa
|
||||
}
|
||||
|
||||
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||
auto rand = CreatureLib::Core::Random();
|
||||
auto rand = Arbutils::Random();
|
||||
const PkmnLib::Library::PokemonSpecies* species = nullptr;
|
||||
if (!this->_library->GetSpeciesLibrary()->TryGet(this->_species.c_str(), species)) {
|
||||
if (!this->_library->GetSpeciesLibrary()->TryGet(this->_species, species)) {
|
||||
std::stringstream err;
|
||||
err << "Invalid species '" << _species << "'.";
|
||||
throw CreatureException(err.str());
|
||||
}
|
||||
const PkmnLib::Library::PokemonForme* forme;
|
||||
if (!species->TryGetForme(this->_forme, forme)){
|
||||
if (!species->TryGetForme(this->_forme, forme)) {
|
||||
std::stringstream err;
|
||||
err << "Invalid forme '" << _forme << "' for species '" << _forme << "'.";
|
||||
throw CreatureException(err.str());
|
||||
@@ -66,9 +65,9 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||
gender = species->GetRandomGender(rand);
|
||||
}
|
||||
const Library::Item* heldItem = nullptr;
|
||||
if (!this->_heldItem.empty()) {
|
||||
if (!_library->GetItemLibrary()->TryGet(this->_heldItem.c_str(), heldItem)) {
|
||||
throw CreatureException("Unknown Item: " + this->_heldItem);
|
||||
if (!this->_heldItem.Empty()) {
|
||||
if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) {
|
||||
throw CreatureException("Unknown Item: " + this->_heldItem.std_str());
|
||||
}
|
||||
}
|
||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
||||
@@ -123,7 +122,8 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortVa
|
||||
_evSpeed = speed;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithForme(const std::string& forme) {
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::WithForme(const Arbutils::CaseInsensitiveConstString& forme) {
|
||||
_forme = forme;
|
||||
return this;
|
||||
}
|
||||
@@ -136,17 +136,18 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::IsShiny(bool
|
||||
_isShiny = value;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem(const std::string& item) {
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem(const Arbutils::CaseInsensitiveConstString& item) {
|
||||
_heldItem = item;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::LearnMove(const std::string& moveName, CreatureLib::Battling::AttackLearnMethod method) {
|
||||
PkmnLib::Battling::CreatePokemon::LearnMove(const Arbutils::CaseInsensitiveConstString& moveName,
|
||||
CreatureLib::Battling::AttackLearnMethod method) {
|
||||
const PkmnLib::Library::MoveData* move;
|
||||
if (!_library->GetMoveLibrary()->TryGet(moveName.c_str(), move)){
|
||||
throw CreatureException("Invalid Move given: " + moveName);
|
||||
if (!_library->GetMoveLibrary()->TryGet(moveName, move)) {
|
||||
throw CreatureException("Invalid Move given: " + moveName.std_str());
|
||||
}
|
||||
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves()){
|
||||
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves()) {
|
||||
throw CreatureException("This pokemon already has the maximal allowed moves.");
|
||||
}
|
||||
_attacks.emplace_back(move, method);
|
||||
|
||||
@@ -7,15 +7,15 @@ namespace PkmnLib::Battling {
|
||||
class CreatePokemon {
|
||||
private:
|
||||
const BattleLibrary* _library;
|
||||
std::string _species;
|
||||
std::string _forme = "default";
|
||||
Arbutils::CaseInsensitiveConstString _species;
|
||||
Arbutils::CaseInsensitiveConstString _forme = "default"_cnc;
|
||||
uint8_t _level;
|
||||
std::string _nickname = "";
|
||||
|
||||
std::string _ability = "";
|
||||
uint8_t _nature = 255;
|
||||
CreatureLib::Library::Gender _gender = static_cast<CreatureLib::Library::Gender>(-1);
|
||||
std::string _heldItem = "";
|
||||
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc;
|
||||
uint32_t _identifier = 0;
|
||||
std::vector<std::tuple<const Library::MoveData*, CreatureLib::Battling::AttackLearnMethod>> _attacks = {};
|
||||
|
||||
@@ -37,16 +37,16 @@ namespace PkmnLib::Battling {
|
||||
bool _isShiny = false;
|
||||
|
||||
public:
|
||||
CreatePokemon(const BattleLibrary* library, std::string species, uint8_t level)
|
||||
: _library(library), _species(std::move(species)), _level(level) {}
|
||||
CreatePokemon(const BattleLibrary* library, const Arbutils::CaseInsensitiveConstString& species, uint8_t level)
|
||||
: _library(library), _species(species), _level(level) {}
|
||||
|
||||
CreatePokemon* WithForme(const std::string& forme);
|
||||
CreatePokemon* WithForme(const Arbutils::CaseInsensitiveConstString& forme);
|
||||
CreatePokemon* WithGender(CreatureLib::Library::Gender gender);
|
||||
CreatePokemon* IsShiny(bool value);
|
||||
CreatePokemon* WithHeldItem(const std::string& item);
|
||||
CreatePokemon* LearnMove(const std::string& move, CreatureLib::Battling::AttackLearnMethod method);
|
||||
CreatePokemon* WithHeldItem(const Arbutils::CaseInsensitiveConstString& item);
|
||||
CreatePokemon* LearnMove(const Arbutils::CaseInsensitiveConstString& move, CreatureLib::Battling::AttackLearnMethod method);
|
||||
|
||||
CreatePokemon* WithRandomIndividualValues(CreatureLib::Core::Random rand = CreatureLib::Core::Random());
|
||||
CreatePokemon* WithRandomIndividualValues(Arbutils::Random rand = Arbutils::Random());
|
||||
CreatePokemon* WithIndividualValue(CreatureLib::Core::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);
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace PkmnLib::Library {
|
||||
uint8_t _flingPower;
|
||||
|
||||
public:
|
||||
Item(std::string name, CreatureLib::Library::ItemCategory category,
|
||||
Item(const Arbutils::CaseInsensitiveConstString& name, CreatureLib::Library::ItemCategory category,
|
||||
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
|
||||
std::unordered_set<std::string> flags, uint8_t flingPower)
|
||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags, uint8_t flingPower)
|
||||
: CreatureLib::Library::Item(name, category, battleCategory, price, flags), _flingPower(flingPower) {}
|
||||
|
||||
inline uint8_t GetFlingPower() const { return _flingPower; }
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
namespace PkmnLib::Library {
|
||||
class ItemLibrary : public CreatureLib::Library::ItemLibrary {
|
||||
public:
|
||||
inline bool TryGet(const char* name, const Item*& item) const{
|
||||
inline bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const Item*& item) const {
|
||||
return CreatureLib::Library::ItemLibrary::TryGet(name, (const CreatureLib::Library::Item*&)item);
|
||||
}
|
||||
|
||||
inline const Item* Get(const char* name) const{
|
||||
inline const Item* Get(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return reinterpret_cast<const Item*>(CreatureLib::Library::ItemLibrary::Get(name));
|
||||
}
|
||||
const Item* operator[](const char* name) const { return Get(name); }
|
||||
const Item* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); }
|
||||
|
||||
void Insert(const char* name, const Item* item) {
|
||||
void Insert(const Arbutils::CaseInsensitiveConstString& name, const Item* item) {
|
||||
CreatureLib::Library::ItemLibrary::Insert(name, item);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
PkmnLib::Library::MoveData::MoveData(const std::string& name, uint8_t type,
|
||||
PkmnLib::Library::MoveCategory category, uint8_t power, uint8_t accuracy,
|
||||
uint8_t baseUsage, CreatureLib::Library::AttackTarget target, int8_t priority,
|
||||
std::unordered_set<std::string> flags)
|
||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags)
|
||||
: AttackData(name, type, static_cast<CreatureLib::Library::AttackCategory>(category), power, accuracy, baseUsage,
|
||||
target, priority, std::move(flags)) {}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace PkmnLib::Library {
|
||||
public:
|
||||
MoveData(const std::string& name, uint8_t type, PkmnLib::Library::MoveCategory category, uint8_t power,
|
||||
uint8_t accuracy, uint8_t baseUsage, CreatureLib::Library::AttackTarget target, int8_t priority,
|
||||
std::unordered_set<std::string> flags);
|
||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags);
|
||||
|
||||
PkmnLib::Library::MoveCategory GetCategory() const;
|
||||
};
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace PkmnLib::Library {
|
||||
public:
|
||||
MoveLibrary(size_t initialCapacity = 32) : CreatureLib::Library::AttackLibrary(initialCapacity) {}
|
||||
|
||||
virtual const MoveData* operator[](const char* name) const { return Get(name); }
|
||||
virtual const MoveData* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); }
|
||||
|
||||
inline bool TryGet(const char* name, const MoveData*& move) const {
|
||||
inline bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const MoveData*& move) const {
|
||||
return CreatureLib::Library::AttackLibrary::TryGet(name, (const CreatureLib::Library::AttackData*&)move);
|
||||
}
|
||||
const MoveData* Get(const char* name) const {
|
||||
const MoveData* Get(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return dynamic_cast<const MoveData*>(CreatureLib::Library::AttackLibrary::Get(name));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define PKMNLIB_NATURELIBRARY_HPP
|
||||
|
||||
#include <CreatureLib/Core/Exceptions/CreatureException.hpp>
|
||||
#include <CreatureLib/Core/Random.hpp>
|
||||
#include <Arbutils/Random.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "Nature.hpp"
|
||||
@@ -50,7 +50,7 @@ namespace PkmnLib::Library {
|
||||
return _keyLookup.at(name);
|
||||
}
|
||||
|
||||
uint8_t GetRandomNature(CreatureLib::Core::Random rand = CreatureLib::Core::Random()) const{
|
||||
uint8_t GetRandomNature(Arbutils::Random rand = Arbutils::Random()) const{
|
||||
return rand.Get(_current);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,8 +11,10 @@ namespace PkmnLib::Library {
|
||||
std::vector<EvolutionData> _evolutions;
|
||||
|
||||
public:
|
||||
PokemonSpecies(uint16_t id, const std::string& name, const PokemonForme* defaultVariant, float genderRatio,
|
||||
const std::string& growthRate, uint8_t captureRate, uint8_t baseHappiness)
|
||||
PokemonSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name,
|
||||
const PokemonForme* defaultVariant, float genderRatio,
|
||||
const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate,
|
||||
uint8_t baseHappiness)
|
||||
: CreatureSpecies(id, name, defaultVariant, genderRatio, growthRate, captureRate),
|
||||
_baseHappiness(baseHappiness) {}
|
||||
|
||||
@@ -21,20 +23,20 @@ namespace PkmnLib::Library {
|
||||
inline uint8_t GetBaseHappiness() const { return _baseHappiness; }
|
||||
|
||||
inline const PokemonForme* GetDefaultForme() const {
|
||||
return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant("default"));
|
||||
return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant("default"_cnc));
|
||||
}
|
||||
|
||||
inline bool HasForme(const std::string& key) const { return HasVariant(key); }
|
||||
inline bool HasForme(const Arbutils::CaseInsensitiveConstString& key) const { return HasVariant(key); }
|
||||
|
||||
inline bool TryGetForme(const std::string& key, const PokemonForme*& forme) const {
|
||||
inline bool TryGetForme(const Arbutils::CaseInsensitiveConstString& key, const PokemonForme*& forme) const {
|
||||
return TryGetVariant(key, (const CreatureLib::Library::SpeciesVariant*&)forme);
|
||||
}
|
||||
|
||||
inline const PokemonForme* GetForme(const std::string& key) const {
|
||||
inline const PokemonForme* GetForme(const Arbutils::CaseInsensitiveConstString& key) const {
|
||||
return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant(key));
|
||||
}
|
||||
|
||||
inline void AddEvolution(EvolutionData data) { _evolutions.push_back(data); }
|
||||
inline void AddEvolution(const EvolutionData& data) { _evolutions.push_back(data); }
|
||||
const std::vector<EvolutionData>& GetEvolutions() const { return _evolutions; }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,18 +7,18 @@
|
||||
namespace PkmnLib::Library {
|
||||
class SpeciesLibrary : public CreatureLib::Library::SpeciesLibrary {
|
||||
public:
|
||||
inline bool TryGet(const char* name, const PokemonSpecies*& outSpecies) const {
|
||||
inline bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const PokemonSpecies*& outSpecies) const {
|
||||
return CreatureLib::Library::SpeciesLibrary::TryGet(
|
||||
name, (const CreatureLib::Library::CreatureSpecies*&)outSpecies);
|
||||
}
|
||||
|
||||
inline const PokemonSpecies* Get(const char* name) const {
|
||||
inline const PokemonSpecies* Get(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return dynamic_cast<const PokemonSpecies*>(CreatureLib::Library::SpeciesLibrary::Get(name));
|
||||
}
|
||||
|
||||
const PokemonSpecies* operator[](const char* name) const { return Get(name); }
|
||||
const PokemonSpecies* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); }
|
||||
|
||||
void Insert(const char* name, const PokemonSpecies* species) {
|
||||
void Insert(const Arbutils::CaseInsensitiveConstString& name, const PokemonSpecies* species) {
|
||||
CreatureLib::Library::SpeciesLibrary::Insert(name, species);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef PKMNLIB_TIMEOFDAY_HPP
|
||||
#define PKMNLIB_TIMEOFDAY_HPP
|
||||
|
||||
#include <CreatureLib/Core/Enum.hpp>
|
||||
#include <Arbutils/Enum.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
namespace PkmnLib::Library {
|
||||
|
||||
@@ -113,13 +113,15 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||
r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const string &in name) const",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, HasHeldItem), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "void SetHeldItem(const string &in name)",
|
||||
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const std::string&), void),
|
||||
asCALL_THISCALL);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"Pokemon", "void SetHeldItem(const string &in name)",
|
||||
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const Arbutils::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 CreatureLib::Library::Item*), void),
|
||||
asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_CurrentHealth() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetCurrentHealth), asCALL_THISCALL);
|
||||
|
||||
@@ -40,6 +40,11 @@ void RegisterSpeciesTypes::RegisterStatisticEnum(asIScriptEngine* engine) {
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
void RegisterSpeciesTypes::RegisterSpeciesType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
@@ -59,13 +64,11 @@ void RegisterSpeciesTypes::RegisterSpeciesType(asIScriptEngine* engine) {
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetRandomGender), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Species", "const Forme@ GetForme(string key) const",
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetForme), asCALL_THISCALL);
|
||||
asFUNCTION(GetFormeWrapper), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Species", "const Forme@ GetDefaultForme() const",
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetDefaultForme), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
|
||||
}
|
||||
void RegisterSpeciesTypes::RegisterFormeType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("Forme", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
@@ -94,7 +97,6 @@ void RegisterSpeciesTypes::RegisterFormeType(asIScriptEngine* engine) {
|
||||
r = engine->RegisterObjectMethod("Forme", "const string& GetAbility(int index) const",
|
||||
asMETHOD(PkmnLib::Library::PokemonForme, GetTalent), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
}
|
||||
void RegisterSpeciesTypes::RegisterSpeciesLibrary(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("SpeciesLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
|
||||
Reference in New Issue
Block a user