Update CreatureLib.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-05-27 17:26:25 +02:00
parent 0d111739f4
commit f42ce8865d
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
53 changed files with 316 additions and 269 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/cmake-build-debug/
/cmake-build-release/
/build-release-windows/
/.idea/

View File

@ -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) {

View File

@ -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<CreatureLib::Battling::BattleParty*> partiesList(parties, parties + partiesCount);
ArbUt::List<CreatureLib::Battling::BattleParty*> 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(); }

View File

@ -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<CreatureLib::Battling::LearnedAttack*> cMoves(moves, moves + moveCount);
ArbUt::List<CreatureLib::Battling::LearnedAttack*> cMoves(moves, moves + moveCount);
return new Pokemon(library, species, forme, level, experience, uid, gender, coloring, heldItem, nick,
CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves,

View File

@ -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<const CreatureLib::Library::EffectParameter*>(data, data + dataLength);
auto list = ArbUt::List<const CreatureLib::Library::EffectParameter*>(data, data + dataLength);
return EvolutionData::CreateCustomEvolution(list, into);
}

View File

@ -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<uint32_t> 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);
};

View File

@ -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();
}

View File

@ -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);)
}

View File

@ -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;

View File

@ -12,16 +12,16 @@ namespace PkmnLib::Battling {
CreatureLib::Battling::Script* _weatherScript = nullptr;
public:
Battle(const BattleLibrary* library, const List<CreatureLib::Battling::BattleParty*>& parties,
Battle(const BattleLibrary* library, const ArbUt::List<CreatureLib::Battling::BattleParty*>& 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<CreatureLib::Battling::ScriptWrapper>& scripts) override {
void GetActiveScripts(ArbUt::List<CreatureLib::Battling::ScriptWrapper>& scripts) override {
CreatureLib::Battling::Battle::GetActiveScripts(scripts);
scripts.Append(CreatureLib::Battling::ScriptWrapper(
CreatureLib::Battling::ScriptWrapper::FromScript(&_weatherScript)));

View File

@ -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<CreatureLib::Battling::EventDataKind>(PkmnEventDataKind::WeatherChange);
}
const Arbutils::CaseInsensitiveConstString GetWeatherName() const noexcept { return _weatherName; }
const ArbUt::CaseInsensitiveConstString GetWeatherName() const noexcept { return _weatherName; }
};
}

View File

@ -2,6 +2,7 @@
#define PKMNLIB_BATTLELIBRARY_HPP
#include <CreatureLib/Battling/Library/BattleLibrary.hpp>
#include <memory>
#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<const Library::LibrarySettings*>(_staticLib->GetSettings());
const std::unique_ptr<const Library::LibrarySettings>& GetSettings() const {
return reinterpret_cast<const std::unique_ptr<const Library::LibrarySettings>&>(_staticLib->GetSettings());
}
const Library::PokemonLibrary* GetStaticLib() const {
return dynamic_cast<const Library::PokemonLibrary*>(CreatureLib::Battling::BattleLibrary::_staticLib);
const std::unique_ptr<const Library::PokemonLibrary>& GetStaticLib() const {
return reinterpret_cast<const std::unique_ptr<const Library::PokemonLibrary>&>(_staticLib);
}
const Library::SpeciesLibrary* GetSpeciesLibrary() const {
return dynamic_cast<const Library::SpeciesLibrary*>(
CreatureLib::Battling::BattleLibrary::GetSpeciesLibrary());
const std::unique_ptr<const Library::SpeciesLibrary>& GetSpeciesLibrary() const {
return reinterpret_cast<const std::unique_ptr<const Library::SpeciesLibrary>&>(
_staticLib->GetSpeciesLibrary());
}
const Library::MoveLibrary* GetMoveLibrary() const {
return dynamic_cast<const Library::MoveLibrary*>(CreatureLib::Battling::BattleLibrary::GetAttackLibrary());
const std::unique_ptr<const Library::MoveLibrary>& GetMoveLibrary() const {
return reinterpret_cast<const std::unique_ptr<const Library::MoveLibrary>&>(_staticLib->GetAttackLibrary());
}
const Library::ItemLibrary* GetItemLibrary() const {
return dynamic_cast<const Library::ItemLibrary*>(CreatureLib::Battling::BattleLibrary::GetItemLibrary());
const std::unique_ptr<const Library::ItemLibrary>& GetItemLibrary() const {
return reinterpret_cast<const std::unique_ptr<const Library::ItemLibrary>&>(_staticLib->GetItemLibrary());
}
const Library::NatureLibrary* GetNatureLibrary() const { return GetStaticLib()->GetNatureLibrary(); }

View File

@ -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<const Library::PokemonSpecies> 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<const PkmnLib::Library::PokemonForme> 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<CreatureLib::Library::Gender>(-1)) {
gender = species->GetRandomGender(rand);
}
const Library::Item* heldItem = nullptr;
ArbUt::BorrowedPtr<const Library::Item> 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<CreatureLib::Battling::LearnedAttack*>(_attacks.Count());
auto attacks = ArbUt::List<CreatureLib::Battling::LearnedAttack*>(_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<const PkmnLib::Library::MoveData> move = nullptr;
if (!_library->GetMoveLibrary()->TryGet(moveName, move)) {
throw CreatureException("Invalid Move given: " + moveName.std_str());
}

View File

@ -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<CreatureLib::Library::Gender>(-1);
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc;
ArbUt::CaseInsensitiveConstString _heldItem = ""_cnc;
uint32_t _identifier = 0;
struct ToLearnMethod {
const Library::MoveData* Move;
ArbUt::BorrowedPtr<const Library::MoveData> 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<const Library::MoveData> move,
CreatureLib::Battling::AttackLearnMethod method)
: Move(move), LearnMethod(method){};
};
Arbutils::Collections::List<ToLearnMethod> _attacks;
ArbUt::List<ToLearnMethod> _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();

View File

@ -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<const Library::MoveData>& move,
CreatureLib::Battling::AttackLearnMethod learnMethod)
: CreatureLib::Battling::LearnedAttack(move.As<const CreatureLib::Library::AttackData>(), learnMethod) {}
const Library::MoveData* GetMoveData() const { return dynamic_cast<const Library::MoveData*>(GetAttack()); }
const ArbUt::BorrowedPtr<const Library::MoveData> GetMoveData() const {
return GetAttack().As<const Library::MoveData>();
}
};
}

View File

@ -18,26 +18,29 @@ namespace PkmnLib::Battling {
const BattleLibrary* GetLibrary() const { return reinterpret_cast<const BattleLibrary*>(_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<CreatureLib::Battling::LearnedAttack*>& moves,
Pokemon(const BattleLibrary* library, const ArbUt::BorrowedPtr<const Library::PokemonSpecies>& species,
const ArbUt::BorrowedPtr<const Library::PokemonForme>& forme, uint8_t level, uint32_t experience,
uint32_t uid, CreatureLib::Library::Gender gender, uint8_t coloring,
ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string& nickname,
const CreatureLib::Library::TalentIndex& talent,
const ArbUt::List<CreatureLib::Battling::LearnedAttack*>& moves,
CreatureLib::Library::StatisticSet<uint8_t> individualValues,
CreatureLib::Library::StatisticSet<uint8_t> 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<const CreatureLib::Library::CreatureSpecies>(),
forme.As<const CreatureLib::Library::SpeciesVariant>(), level, experience,
uid, gender, coloring, heldItem.As<const CreatureLib::Library::Item>(),
nickname, talent, moves, allowedExperienceGain),
_individualValues(individualValues), _effortValues(effortValues), _nature(nature) {}
const Library::PokemonForme* GetForme() const {
return dynamic_cast<const Library::PokemonForme*>(GetVariant());
const ArbUt::BorrowedPtr<const Library::PokemonForme> GetForme() const {
return _variant.As<const Library::PokemonForme>();
}
inline bool IsShiny() const noexcept { return _coloring == 1; }
const Arbutils::Collections::List<LearnedMove*>& GetMoves() const {
return reinterpret_cast<const Arbutils::Collections::List<LearnedMove*>&>(_attacks);
const ArbUt::List<LearnedMove*>& GetMoves() const {
return reinterpret_cast<const ArbUt::List<LearnedMove*>&>(_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<const Library::PokemonSpecies*>(_species);
inline ArbUt::BorrowedPtr<const PkmnLib::Library::PokemonSpecies> GetPokemonSpecies() const noexcept {
return _species.As<const PkmnLib::Library::PokemonSpecies>();
}
};
}

View File

@ -17,10 +17,9 @@ namespace PkmnLib::Library {
private:
const PokemonSpecies* _evolvesInto;
EvolutionMethod _method;
Arbutils::Collections::List<const CreatureLib::Library::EffectParameter*> _evolutionData;
ArbUt::List<const CreatureLib::Library::EffectParameter*> _evolutionData;
EvolutionData(EvolutionMethod method,
Arbutils::Collections::List<const CreatureLib::Library::EffectParameter*> data,
EvolutionData(EvolutionMethod method, ArbUt::List<const CreatureLib::Library::EffectParameter*> 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<const CreatureLib::Library::EffectParameter*>& data,
CreateCustomEvolution(const ArbUt::List<const CreatureLib::Library::EffectParameter*>& data,
const PokemonSpecies* into) {
return new EvolutionData(EvolutionMethod::Custom, data, into);
}

View File

@ -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<uint32_t>& flags, uint8_t flingPower) noexcept
: CreatureLib::Library::Item(name, category, battleCategory, price, flags), _flingPower(flingPower) {}

View File

@ -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<const Item>& item) const {
auto v = item.As<const CreatureLib::Library::Item>();
auto res = CreatureLib::Library::ItemLibrary::TryGet(name.GetHash(), v);
item = v.ForceAs<const Item>();
return res;
}
inline const Item* Get(const Arbutils::CaseInsensitiveConstString& name) const {
return reinterpret_cast<const Item*>(CreatureLib::Library::ItemLibrary::Get(name));
inline ArbUt::BorrowedPtr<const Item> Get(const ArbUt::CaseInsensitiveConstString& name) const {
return CreatureLib::Library::ItemLibrary::Get(name).ForceAs<const Item>();
}
inline ArbUt::BorrowedPtr<const Item> 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);
}
};

View File

@ -1,6 +1,6 @@
#include "MoveData.hpp"
#include <utility>
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,

View File

@ -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<uint32_t> 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<uint32_t> flags);
PkmnLib::Library::MoveCategory GetCategory() const;
};

View File

@ -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<const MoveData*>(ptr);
return true;
}
return false;
virtual ArbUt::BorrowedPtr<const MoveData> operator[](const ArbUt::CaseInsensitiveConstString& name) const {
return Get(name);
}
const MoveData* Get(const Arbutils::CaseInsensitiveConstString& name) const {
return dynamic_cast<const MoveData*>(CreatureLib::Library::AttackLibrary::Get(name));
inline bool TryGet(const ArbUt::CaseInsensitiveConstString& name,
ArbUt::BorrowedPtr<const MoveData>& move) const {
auto v = move.As<const MoveData::AttackData>();
auto res = CreatureLib::Library::AttackLibrary::TryGet(name, v);
move = v.As<const MoveData>();
return res;
}
inline ArbUt::BorrowedPtr<const MoveData> Get(const ArbUt::CaseInsensitiveConstString& name) const {
return CreatureLib::Library::AttackLibrary::Get(name).As<const MoveData>();
}
};
}

View File

@ -12,11 +12,11 @@
namespace PkmnLib::Library {
class NatureLibrary {
private:
Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*> _items;
ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, const Nature*> _items;
public:
explicit NatureLibrary(size_t size = 32) noexcept
: _items(Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*>(size)) {}
: _items(ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, const Nature*>(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;

View File

@ -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<const LibrarySettings*>(CreatureLib::Library::DataLibrary::GetSettings());
const std::unique_ptr<const PkmnLib::Library::LibrarySettings>& GetSettings() const {
return (const std::unique_ptr<const LibrarySettings>&)CreatureLib::Library::DataLibrary::GetSettings();
}
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const {
return (const SpeciesLibrary*)(CreatureLib::Library::DataLibrary::GetSpeciesLibrary());
[[nodiscard]] const std::unique_ptr<const SpeciesLibrary>& GetSpeciesLibrary() const {
return (const std::unique_ptr<const SpeciesLibrary>&)CreatureLib::Library::DataLibrary::GetSpeciesLibrary();
}
[[nodiscard]] const MoveLibrary* GetMoveLibrary() const {
return (const MoveLibrary*)(CreatureLib::Library::DataLibrary::GetAttackLibrary());
[[nodiscard]] const std::unique_ptr<const MoveLibrary>& GetMoveLibrary() const {
return (const std::unique_ptr<const MoveLibrary>&)CreatureLib::Library::DataLibrary::GetAttackLibrary();
}
[[nodiscard]] const ItemLibrary* GetItemLibrary() const {
return (const ItemLibrary*)(CreatureLib::Library::DataLibrary::GetItemLibrary());
[[nodiscard]] const std::unique_ptr<const ItemLibrary>& GetItemLibrary() const {
return (const std::unique_ptr<const ItemLibrary>&)CreatureLib::Library::DataLibrary::GetItemLibrary();
}
[[nodiscard]] const NatureLibrary* GetNatureLibrary() const noexcept { return _natures; }

View File

@ -1,7 +1,8 @@
#include "PokemonForme.hpp"
PkmnLib::Library::PokemonForme::PokemonForme(ConstString name, float height, float weight, uint32_t baseExperience,
const List<uint8_t>& types,
PkmnLib::Library::PokemonForme::PokemonForme(ArbUt::CaseInsensitiveConstString name, float height, float weight,
uint32_t baseExperience, const ArbUt::List<uint8_t>& types,
CreatureLib::Library::StatisticSet<uint16_t> baseStats,
const List<ConstString>& talents, const List<ConstString>& secretTalents,
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& talents,
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& secretTalents,
const CreatureLib::Library::LearnableAttacks* attacks)
: SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks) {}

View File

@ -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<uint8_t>& types,
CreatureLib::Library::StatisticSet<uint16_t> baseStats, const List<ConstString>& talents,
const List<ConstString>& secretTalents, const CreatureLib::Library::LearnableAttacks* attacks);
PokemonForme(ArbUt::CaseInsensitiveConstString name, float height, float weight, uint32_t baseExperience,
const ArbUt::List<uint8_t>& types, CreatureLib::Library::StatisticSet<uint16_t> baseStats,
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& talents,
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& 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);
}
};

View File

@ -8,11 +8,11 @@ namespace PkmnLib::Library {
class PokemonSpecies : public CreatureLib::Library::CreatureSpecies {
private:
uint8_t _baseHappiness;
Arbutils::Collections::List<const EvolutionData*> _evolutions;
ArbUt::List<const EvolutionData*> _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<const PokemonForme*>(CreatureSpecies::GetVariant("default"_cnc.GetHash()));
inline ArbUt::BorrowedPtr<const PokemonForme> GetDefaultForme() const {
return CreatureSpecies::GetVariant("default"_cnc.GetHash()).As<const PokemonForme>();
}
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<const PokemonForme>& forme) const {
auto v = forme.As<const PokemonForme::SpeciesVariant>();
auto res = TryGetVariant(key, v);
forme = v.As<const PokemonForme>();
return res;
}
inline const PokemonForme* GetForme(const Arbutils::CaseInsensitiveConstString& key) const {
return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant(key));
inline ArbUt::BorrowedPtr<const PokemonForme> GetForme(const ArbUt::CaseInsensitiveConstString& key) const {
return CreatureSpecies::GetVariant(key).As<const PokemonForme>();
}
inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); }
const Arbutils::Collections::List<const EvolutionData*>& GetEvolutions() const noexcept { return _evolutions; }
const ArbUt::List<const EvolutionData*>& GetEvolutions() const noexcept { return _evolutions; }
};
}

View File

@ -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<const PokemonSpecies>& outSpecies) const {
auto v = outSpecies.As<const PokemonSpecies::CreatureSpecies>();
auto res = CreatureLib::Library::SpeciesLibrary::TryGet(name, v);
outSpecies = v.As<const PokemonSpecies>();
return res;
}
inline const PokemonSpecies* Get(const Arbutils::CaseInsensitiveConstString& name) const {
return dynamic_cast<const PokemonSpecies*>(CreatureLib::Library::SpeciesLibrary::Get(name));
inline ArbUt::BorrowedPtr<const PokemonSpecies> Get(const ArbUt::CaseInsensitiveConstString& name) const {
return CreatureLib::Library::SpeciesLibrary::Get(name).As<const PokemonSpecies>();
}
const PokemonSpecies* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); }
ArbUt::BorrowedPtr<const PokemonSpecies> 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);
}
};

View File

@ -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<ConstString, AngelScriptTypeInfo*> innerDb;
ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*> 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<ScriptCategory, Dictionary<ConstString, uint32_t>>& types) {
asIBinaryStream* stream, const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, uint32_t>>& types) {
auto typeCount = _mainModule->GetObjectTypeCount();
Dictionary<uint32_t, asITypeInfo*> objectTypes;
ArbUt::Dictionary<uint32_t, asITypeInfo*> objectTypes;
for (asUINT i = 0; i < typeCount; i++) {
auto t = _mainModule->GetObjectTypeByIndex(i);
objectTypes.Insert(ConstString::GetHash(t->GetName()), t);
}
Dictionary<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>> typeDatabase;
ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*>> typeDatabase;
for (const auto& innerDb : types) {
Dictionary<ConstString, AngelScriptTypeInfo*> newInnerDb;
ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*> newInnerDb;
for (const auto& val : innerDb.second) {
auto decl = val.second;
auto type = objectTypes[decl];

View File

@ -10,7 +10,6 @@
#include <iostream>
#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<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>> _typeDatabase;
Dictionary<ConstString, asITypeInfo*> _baseTypes;
ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, AngelScriptTypeInfo*>>
_typeDatabase;
ArbUt::Dictionary<ConstString, asITypeInfo*> _baseTypes;
void RegisterTypes();
void InitializeByteCode(asIBinaryStream* stream,
const Dictionary<ScriptCategory, Dictionary<ConstString, uint32_t>>& types);
void InitializeByteCode(
asIBinaryStream* stream,
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, uint32_t>>& 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<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>>& GetTypeDatabase() const noexcept {
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, AngelScriptTypeInfo*>>&
GetTypeDatabase() const noexcept {
return _typeDatabase;
}

View File

@ -42,8 +42,7 @@
ctx->PopState(); \
}
CScriptArray*
AngelScriptScript::GetEffectParameters(const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& ls) {
CScriptArray* AngelScriptScript::GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls) {
asITypeInfo* t = _resolver->GetBaseType("array<EffectParameter@>"_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<Creatur
return arr;
}
void AngelScriptScript::OnInitialize(const List<CreatureLib::Library::EffectParameter*>& parameters) {
void AngelScriptScript::OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) {
CScriptArray* arr = nullptr;
CALL_HOOK(OnInitialize, {
arr = GetEffectParameters(parameters);

View File

@ -18,7 +18,7 @@ private:
ContextPool* _ctxPool = nullptr;
asIScriptObject* _obj = nullptr;
CScriptArray* GetEffectParameters(const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& ls);
CScriptArray* GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& 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<CreatureLib::Library::EffectParameter*>& parameters) override;
void OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& 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;

View File

@ -10,13 +10,11 @@
#include <unordered_map>
#include <utility>
using ConstString = Arbutils::CaseInsensitiveConstString;
class AngelScriptTypeInfo {
private:
asITypeInfo* _type = nullptr;
Arbutils::Collections::Dictionary<uint32_t, asIScriptFunction*> _functions;
ConstString _name;
ArbUt::Dictionary<uint32_t, asIScriptFunction*> _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;

View File

@ -13,7 +13,8 @@ protected:
IPkmnBinaryStream(size_t angelScriptBound) : _angelScriptBound(angelScriptBound) {}
public:
virtual void WriteTypes(const Dictionary<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>>& types) {
virtual void
WriteTypes(const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, AngelScriptTypeInfo*>>& 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<ScriptCategory, Dictionary<ConstString, uint32_t>> ReadTypes() {
virtual ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, uint32_t>> ReadTypes() {
_angelScriptBound = SIZE_MAX;
Dictionary<ScriptCategory, Dictionary<ConstString, uint32_t>> types;
ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ConstString, uint32_t>> 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<ConstString, uint32_t> innerDb;
ArbUt::Dictionary<ConstString, uint32_t> 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;

View File

@ -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);
}

View File

@ -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<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);

View File

@ -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);

View File

@ -0,0 +1,2 @@
#define SMART_PTR_GETTER_FUNC(o, returns, funcName) \
static returns* funcName##Wrapper(o* obj) { return obj->funcName().operator->(); }

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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<const PkmnLib::Library::PokemonForme>()
.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) {

View File

@ -1,6 +1,7 @@
#include "RegisterStaticLibraryTypes.hpp"
#include <cassert>
#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);
}

View File

@ -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);
}

View File

@ -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];

View File

@ -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;

View File

@ -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);

View File

@ -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<PkmnLib::Battling::Pokemon*>(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<PkmnLib::Battling::Pokemon*>(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<PkmnLib::Battling::Pokemon*>(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());

View File

@ -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<PkmnLib::Library::PokemonForme*>(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<PkmnLib::Library::PokemonForme*>(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<PkmnLib::Library::PokemonForme*>(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<PkmnLib::Library::PokemonForme*>(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<PkmnLib::Library::PokemonForme*>(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<PkmnLib::Library::PokemonForme*>(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<PkmnLib::Library::PokemonForme*>(forme));
data.Context->SetArgObject(0, (void*)forme.GetRaw());
data.Context->SetArgDWord(1, static_cast<asDWORD>(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<PkmnLib::Library::PokemonForme*>(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);

View File

@ -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<PkmnLib::Library::Item*>(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<PkmnLib::Library::Item*>(item));
data.Context->SetArgObject(0, (void*)item.GetRaw());
data.Context->SetArgDWord(1, static_cast<int32_t>(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<PkmnLib::Library::Item*>(item));
data.Context->SetArgObject(0, (void*)item.GetRaw());
data.Context->SetArgDWord(1, static_cast<int32_t>(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<PkmnLib::Library::Item*>(item));
data.Context->SetArgObject(0, (void*)item.GetRaw());
data.Context->SetArgDWord(1, static_cast<int32_t>(item->GetPrice()));
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);

View File

@ -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<PkmnLib::Library::MoveData*>(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<PkmnLib::Library::MoveData*>(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<PkmnLib::Library::MoveData*>(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<PkmnLib::Library::MoveData*>(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<PkmnLib::Library::MoveData*>(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<PkmnLib::Library::MoveData*>(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<PkmnLib::Library::MoveData*>(move));
data.Context->SetArgObject(0, (void*)move.GetRaw());
data.Context->SetArgByte(1, move->GetPriority());
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);

View File

@ -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<PkmnLib::Library::PokemonSpecies*>(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<PkmnLib::Library::PokemonSpecies*>(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<PkmnLib::Library::PokemonSpecies*>(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<PkmnLib::Library::PokemonSpecies*>(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<PkmnLib::Library::PokemonSpecies*>(species));
data.Context->SetArgObject(1, const_cast<PkmnLib::Library::PokemonForme*>(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<PkmnLib::Library::PokemonSpecies*>(species));
data.Context->SetArgObject(1, const_cast<PkmnLib::Library::PokemonForme*>(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);

View File

@ -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<PkmnLib::Library::PokemonLibrary*>(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<PkmnLib::Library::PokemonLibrary*>(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<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
data.Context->SetArgObject(
1, const_cast<PkmnLib::Library::SpeciesLibrary*>(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<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
data.Context->SetArgObject(1,
const_cast<PkmnLib::Library::MoveLibrary*>(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<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
data.Context->SetArgObject(1,
const_cast<PkmnLib::Library::ItemLibrary*>(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<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
data.Context->SetArgObject(
1, const_cast<CreatureLib::Library::GrowthRateLibrary*>(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<PkmnLib::Library::PokemonLibrary*>(mainLib->GetStaticLib()));
data.Context->SetArgObject(
1, const_cast<CreatureLib::Library::TypeLibrary*>(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);