Update to new Arbutils memory model.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
b6a5e41b51
commit
53bd6e7a94
|
@ -4,5 +4,8 @@ using namespace PkmnLib::Library;
|
||||||
|
|
||||||
export const PokemonSpecies* PkmnLib_SpeciesLibrary_FindPreEvolution(const SpeciesLibrary* p,
|
export const PokemonSpecies* PkmnLib_SpeciesLibrary_FindPreEvolution(const SpeciesLibrary* p,
|
||||||
const PokemonSpecies* species) {
|
const PokemonSpecies* species) {
|
||||||
return p->FindPreEvolution(species).GetRaw();
|
auto v = p->FindPreEvolution(species);
|
||||||
|
if (!v.has_value())
|
||||||
|
return nullptr;
|
||||||
|
return v.value().GetRaw();
|
||||||
}
|
}
|
|
@ -83,7 +83,8 @@ float PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling:
|
||||||
PKMN_HOOK(OverrideCriticalModifier, attack, attack, target, hitIndex, &critModifier);
|
PKMN_HOOK(OverrideCriticalModifier, attack, attack, target, hitIndex, &critModifier);
|
||||||
mod *= critModifier;
|
mod *= critModifier;
|
||||||
}
|
}
|
||||||
float randPercentage = 85 + attack->GetUser()->GetBattle()->GetRandom()->Get(0, 16);
|
Assert(attack->GetUser()->GetBattle().GetValue());
|
||||||
|
float randPercentage = 85 + attack->GetUser()->GetBattle().GetValue()->GetRandom()->Get(0, 16);
|
||||||
mod *= randPercentage / 100.0;
|
mod *= randPercentage / 100.0;
|
||||||
if (attack->GetUser()->HasType(hitData.GetType())) {
|
if (attack->GetUser()->HasType(hitData.GetType())) {
|
||||||
float stabModifier = 1.5;
|
float stabModifier = 1.5;
|
||||||
|
|
|
@ -36,12 +36,12 @@ void PkmnLib::Battling::ExperienceLibrary::HandleExperienceGain(
|
||||||
}
|
}
|
||||||
|
|
||||||
auto battle = fainted->GetBattle();
|
auto battle = fainted->GetBattle();
|
||||||
if (battle == nullptr) {
|
if (!battle.HasValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_set<CreatureLib::Battling::Creature*> shareExperience;
|
std::unordered_set<CreatureLib::Battling::Creature*> shareExperience;
|
||||||
for (const auto& party : battle->GetParties()) {
|
for (const auto& party : battle.GetValue()->GetParties()) {
|
||||||
for (const auto& mon : party->GetParty()->GetParty()) {
|
for (const auto& mon : party->GetParty()->GetParty()) {
|
||||||
if (mon == nullptr)
|
if (mon == nullptr)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -7,7 +7,8 @@ bool PkmnLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::Executing
|
||||||
CreatureLib::Battling::Creature* target, uint8_t hit) const {
|
CreatureLib::Battling::Creature* target, uint8_t hit) const {
|
||||||
uint8_t critStage = 0;
|
uint8_t critStage = 0;
|
||||||
PKMN_HOOK(ModifyCriticalStage, attack, attack, target, hit, &critStage);
|
PKMN_HOOK(ModifyCriticalStage, attack, attack, target, hit, &critStage);
|
||||||
auto rand = target->GetBattle()->GetRandom();
|
Assert(target->GetBattle().HasValue());
|
||||||
|
auto rand = target->GetBattle().GetValue()->GetRandom();
|
||||||
switch (critStage) {
|
switch (critStage) {
|
||||||
case 0: return rand->Get(24) == 0;
|
case 0: return rand->Get(24) == 0;
|
||||||
case 1: return rand->Get(8) == 0;
|
case 1: return rand->Get(8) == 0;
|
||||||
|
|
|
@ -36,14 +36,15 @@ namespace PkmnLib::Battling {
|
||||||
|
|
||||||
Pokemon* CreatePokemon::Build() {
|
Pokemon* CreatePokemon::Build() {
|
||||||
auto rand = ArbUt::Random();
|
auto rand = ArbUt::Random();
|
||||||
ArbUt::BorrowedPtr<const Library::PokemonSpecies> species = nullptr;
|
|
||||||
if (!this->_library->GetSpeciesLibrary()->TryGet(this->_species, species)) {
|
auto species = this->_library->GetSpeciesLibrary()->TryGet(this->_species);
|
||||||
|
if (!species.has_value()) {
|
||||||
std::stringstream err;
|
std::stringstream err;
|
||||||
err << "Invalid species '" << _species << "'.";
|
err << "Invalid species '" << _species << "'.";
|
||||||
throw ArbUt::Exception(err.str());
|
throw ArbUt::Exception(err.str());
|
||||||
}
|
}
|
||||||
ArbUt::BorrowedPtr<const PkmnLib::Library::PokemonForme> forme;
|
auto forme = species.value()->TryGetForme(this->_forme);
|
||||||
if (!species->TryGetForme(this->_forme, forme)) {
|
if (!forme.has_value()) {
|
||||||
std::stringstream err;
|
std::stringstream err;
|
||||||
err << "Invalid forme '" << _forme << "' for species '" << _forme << "'.";
|
err << "Invalid forme '" << _forme << "' for species '" << _forme << "'.";
|
||||||
throw ArbUt::Exception(err.str());
|
throw ArbUt::Exception(err.str());
|
||||||
|
@ -51,9 +52,9 @@ namespace PkmnLib::Battling {
|
||||||
AssertNotNull(forme);
|
AssertNotNull(forme);
|
||||||
CreatureLib::Library::TalentIndex ability;
|
CreatureLib::Library::TalentIndex ability;
|
||||||
if (this->_ability.IsEmpty()) {
|
if (this->_ability.IsEmpty()) {
|
||||||
ability = forme->GetRandomTalent(rand);
|
ability = forme.value()->GetRandomTalent(rand);
|
||||||
} else {
|
} else {
|
||||||
ability = forme->GetTalentIndex(this->_ability);
|
ability = forme.value()->GetTalentIndex(this->_ability);
|
||||||
}
|
}
|
||||||
auto identifier = this->_identifier;
|
auto identifier = this->_identifier;
|
||||||
if (identifier == 0) {
|
if (identifier == 0) {
|
||||||
|
@ -61,16 +62,18 @@ namespace PkmnLib::Battling {
|
||||||
}
|
}
|
||||||
auto gender = this->_gender;
|
auto gender = this->_gender;
|
||||||
if (gender == static_cast<CreatureLib::Library::Gender>(-1)) {
|
if (gender == static_cast<CreatureLib::Library::Gender>(-1)) {
|
||||||
gender = species->GetRandomGender(rand);
|
gender = species.value()->GetRandomGender(rand);
|
||||||
}
|
}
|
||||||
ArbUt::BorrowedPtr<const Library::Item> heldItem = nullptr;
|
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem = nullptr;
|
||||||
if (!this->_heldItem.IsEmpty()) {
|
if (!this->_heldItem.IsEmpty()) {
|
||||||
if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) {
|
auto item = _library->GetItemLibrary()->TryGet(this->_heldItem);
|
||||||
|
if (!item.has_value()) {
|
||||||
THROW("Unknown Item: " << this->_heldItem.std_str());
|
THROW("Unknown Item: " << this->_heldItem.std_str());
|
||||||
}
|
}
|
||||||
AssertNotNull(heldItem);
|
heldItem = item.value();
|
||||||
}
|
}
|
||||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
auto experience =
|
||||||
|
_library->GetGrowthRateLibrary()->CalculateExperience(species.value()->GetGrowthRate(), _level);
|
||||||
|
|
||||||
auto attacks = std::vector<CreatureLib::Battling::LearnedAttack*>(_attacks.Count());
|
auto attacks = std::vector<CreatureLib::Battling::LearnedAttack*>(_attacks.Count());
|
||||||
for (size_t i = 0; i < _attacks.Count(); i++) {
|
for (size_t i = 0; i < _attacks.Count(); i++) {
|
||||||
|
@ -98,8 +101,8 @@ namespace PkmnLib::Battling {
|
||||||
shiny = rand.Get(_library->GetSettings()->GetShinyRate()) == 0;
|
shiny = rand.Get(_library->GetSettings()->GetShinyRate()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, shiny, heldItem,
|
auto pkmn = new Pokemon(_library, species.value(), forme.value(), _level, experience, identifier, gender, shiny,
|
||||||
_nickname, ability, attacks, ivs, evs, nature, _allowedExperienceGain);
|
heldItem, _nickname, ability, attacks, ivs, evs, nature, _allowedExperienceGain);
|
||||||
pkmn->Initialize();
|
pkmn->Initialize();
|
||||||
return pkmn;
|
return pkmn;
|
||||||
}
|
}
|
||||||
|
@ -146,15 +149,15 @@ namespace PkmnLib::Battling {
|
||||||
}
|
}
|
||||||
CreatePokemon& CreatePokemon::LearnMove(const ArbUt::StringView& moveName,
|
CreatePokemon& CreatePokemon::LearnMove(const ArbUt::StringView& moveName,
|
||||||
CreatureLib::Battling::AttackLearnMethod method) {
|
CreatureLib::Battling::AttackLearnMethod method) {
|
||||||
ArbUt::BorrowedPtr<const PkmnLib::Library::MoveData> move = nullptr;
|
auto v = _library->GetMoveLibrary()->TryGet(moveName);
|
||||||
if (!_library->GetMoveLibrary()->TryGet(moveName, move)) {
|
if (!v.has_value()) {
|
||||||
THROW("Invalid Move given: " << moveName.std_str());
|
THROW("Invalid Move given: " << moveName.std_str());
|
||||||
}
|
}
|
||||||
if (_currentMove >= _library->GetSettings()->GetMaximalAttacks()) {
|
if (_currentMove >= _library->GetSettings()->GetMaximalAttacks()) {
|
||||||
throw ArbUt::Exception("This pokemon already has the maximal allowed moves.");
|
throw ArbUt::Exception("This pokemon already has the maximal allowed moves.");
|
||||||
}
|
}
|
||||||
Assert(move != nullptr);
|
Assert(v.value() != nullptr);
|
||||||
_attacks.Append(ToLearnMethod(move, method));
|
_attacks.Append(ToLearnMethod(v.value(), method));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
CreatePokemon& CreatePokemon::IsAllowedExperienceGain(bool value) {
|
CreatePokemon& CreatePokemon::IsAllowedExperienceGain(bool value) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ namespace PkmnLib::Battling {
|
||||||
struct ToLearnMethod {
|
struct ToLearnMethod {
|
||||||
ArbUt::BorrowedPtr<const Library::MoveData> Move;
|
ArbUt::BorrowedPtr<const Library::MoveData> Move;
|
||||||
CreatureLib::Battling::AttackLearnMethod LearnMethod;
|
CreatureLib::Battling::AttackLearnMethod LearnMethod;
|
||||||
ToLearnMethod() : Move(nullptr), LearnMethod(CreatureLib::Battling::AttackLearnMethod::Unknown){};
|
|
||||||
ToLearnMethod(ArbUt::BorrowedPtr<const Library::MoveData> move,
|
ToLearnMethod(ArbUt::BorrowedPtr<const Library::MoveData> move,
|
||||||
CreatureLib::Battling::AttackLearnMethod method)
|
CreatureLib::Battling::AttackLearnMethod method)
|
||||||
: Move(move), LearnMethod(method){};
|
: Move(move), LearnMethod(method){};
|
||||||
|
|
|
@ -12,8 +12,8 @@ void PkmnLib::Battling::Pokemon::Evolve(ArbUt::BorrowedPtr<const Library::Pokemo
|
||||||
// If the pokemon is genderless, but it's new evolution is not, we want to set its gender
|
// If the pokemon is genderless, but it's new evolution is not, we want to set its gender
|
||||||
if (_gender != CreatureLib::Library::Gender::Genderless && _species->GetGenderRate() != -1) {
|
if (_gender != CreatureLib::Library::Gender::Genderless && _species->GetGenderRate() != -1) {
|
||||||
// If we are currently in battle, use the battle random so we can get predictable events.
|
// If we are currently in battle, use the battle random so we can get predictable events.
|
||||||
if (!_battle.IsNull()) {
|
if (_battle.HasValue()) {
|
||||||
_gender = _species->GetRandomGender(_battle->GetRandom()->GetRNG());
|
_gender = _species->GetRandomGender(_battle.GetValue()->GetRandom()->GetRNG());
|
||||||
}
|
}
|
||||||
// Else create a new random.
|
// Else create a new random.
|
||||||
else {
|
else {
|
||||||
|
@ -34,8 +34,8 @@ void PkmnLib::Battling::Pokemon::SetStatus(const ArbUt::StringView& name) {
|
||||||
}
|
}
|
||||||
_statusScript = std::unique_ptr<CreatureLib::Battling::Script>(
|
_statusScript = std::unique_ptr<CreatureLib::Battling::Script>(
|
||||||
_library->LoadScript(static_cast<ScriptCategory>(PkmnScriptCategory::Status), name));
|
_library->LoadScript(static_cast<ScriptCategory>(PkmnScriptCategory::Status), name));
|
||||||
if (_battle != nullptr) {
|
if (_battle.HasValue()) {
|
||||||
_battle->TriggerEventListener<StatusChangeEvent>(this, name);
|
_battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void PkmnLib::Battling::Pokemon::ClearStatus() {
|
void PkmnLib::Battling::Pokemon::ClearStatus() {
|
||||||
|
@ -43,7 +43,7 @@ void PkmnLib::Battling::Pokemon::ClearStatus() {
|
||||||
return;
|
return;
|
||||||
_statusScript->OnRemove();
|
_statusScript->OnRemove();
|
||||||
_statusScript = nullptr;
|
_statusScript = nullptr;
|
||||||
if (_battle != nullptr) {
|
if (_battle.HasValue()) {
|
||||||
_battle->TriggerEventListener<StatusChangeEvent>(this, ""_cnc);
|
_battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, ""_cnc);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ namespace PkmnLib::Battling {
|
||||||
const ArbUt::BorrowedPtr<const Library::PokemonSpecies>& species,
|
const ArbUt::BorrowedPtr<const Library::PokemonSpecies>& species,
|
||||||
const ArbUt::BorrowedPtr<const Library::PokemonForme>& forme, level_int_t level, uint32_t experience,
|
const ArbUt::BorrowedPtr<const Library::PokemonForme>& forme, level_int_t level, uint32_t experience,
|
||||||
uint32_t uid, CreatureLib::Library::Gender gender, uint8_t coloring,
|
uint32_t uid, CreatureLib::Library::Gender gender, uint8_t coloring,
|
||||||
ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string& nickname,
|
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, const std::string& nickname,
|
||||||
const CreatureLib::Library::TalentIndex& talent,
|
const CreatureLib::Library::TalentIndex& talent,
|
||||||
const std::vector<CreatureLib::Battling::LearnedAttack*>& moves,
|
const std::vector<CreatureLib::Battling::LearnedAttack*>& moves,
|
||||||
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31> individualValues,
|
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31> individualValues,
|
||||||
|
|
|
@ -6,11 +6,9 @@
|
||||||
namespace PkmnLib::Library {
|
namespace PkmnLib::Library {
|
||||||
class ItemLibrary final : public CreatureLib::Library::ItemLibrary {
|
class ItemLibrary final : public CreatureLib::Library::ItemLibrary {
|
||||||
public:
|
public:
|
||||||
inline bool TryGet(const ArbUt::BasicStringView& name, ArbUt::BorrowedPtr<const Item>& item) const {
|
inline std::optional<ArbUt::BorrowedPtr<const Item>> TryGet(const ArbUt::BasicStringView& name) const {
|
||||||
auto v = item.As<const CreatureLib::Library::Item>();
|
auto res = CreatureLib::Library::ItemLibrary::TryGet(name.GetHash());
|
||||||
auto res = CreatureLib::Library::ItemLibrary::TryGet(name.GetHash(), v);
|
return reinterpret_cast<const std::optional<ArbUt::BorrowedPtr<const Item>>&>(res);
|
||||||
item = v.ForceAs<const Item>();
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ArbUt::BorrowedPtr<const Item> Get(const ArbUt::BasicStringView& name) const {
|
inline ArbUt::BorrowedPtr<const Item> Get(const ArbUt::BasicStringView& name) const {
|
||||||
|
|
|
@ -12,11 +12,11 @@ namespace PkmnLib::Library {
|
||||||
return Get(name);
|
return Get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool TryGet(const ArbUt::BasicStringView& name, ArbUt::BorrowedPtr<const MoveData>& move) const {
|
inline std::optional<ArbUt::BorrowedPtr<const MoveData>> TryGet(const ArbUt::BasicStringView& name) const {
|
||||||
auto v = move.As<const MoveData::AttackData>();
|
auto res = CreatureLib::Library::AttackLibrary::TryGet(name);
|
||||||
auto res = CreatureLib::Library::AttackLibrary::TryGet(name, v);
|
if (!res.has_value())
|
||||||
move = v.As<const MoveData>();
|
return {};
|
||||||
return res;
|
return res.value().ForceAs<const MoveData>();
|
||||||
}
|
}
|
||||||
inline ArbUt::BorrowedPtr<const MoveData> Get(const ArbUt::BasicStringView& name) const {
|
inline ArbUt::BorrowedPtr<const MoveData> Get(const ArbUt::BasicStringView& name) const {
|
||||||
return CreatureLib::Library::AttackLibrary::Get(name).As<const MoveData>();
|
return CreatureLib::Library::AttackLibrary::Get(name).As<const MoveData>();
|
||||||
|
|
|
@ -29,12 +29,12 @@ namespace PkmnLib::Library {
|
||||||
|
|
||||||
inline bool HasForme(const ArbUt::BasicStringView& key) const { return HasVariant(key); }
|
inline bool HasForme(const ArbUt::BasicStringView& key) const { return HasVariant(key); }
|
||||||
|
|
||||||
inline bool TryGetForme(const ArbUt::BasicStringView& key,
|
inline std::optional<ArbUt::BorrowedPtr<const PokemonForme>>
|
||||||
ArbUt::BorrowedPtr<const PokemonForme>& forme) const {
|
TryGetForme(const ArbUt::BasicStringView& key) const {
|
||||||
auto v = forme.As<const PokemonForme::SpeciesVariant>();
|
auto res = TryGetVariant(key);
|
||||||
auto res = TryGetVariant(key, v);
|
if (!res.has_value())
|
||||||
forme = v.As<const PokemonForme>();
|
return {};
|
||||||
return res;
|
return res.value().As<const PokemonForme>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ArbUt::BorrowedPtr<const PokemonForme> GetForme(const ArbUt::BasicStringView& key) const {
|
inline ArbUt::BorrowedPtr<const PokemonForme> GetForme(const ArbUt::BasicStringView& key) const {
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
#include "SpeciesLibrary.hpp"
|
#include "SpeciesLibrary.hpp"
|
||||||
namespace PkmnLib::Library {
|
namespace PkmnLib::Library {
|
||||||
ArbUt::BorrowedPtr<const PokemonSpecies>
|
std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>>
|
||||||
SpeciesLibrary::FindPreEvolution(const ArbUt::BorrowedPtr<const PokemonSpecies>& species) const noexcept {
|
SpeciesLibrary::FindPreEvolution(const ArbUt::BorrowedPtr<const PokemonSpecies>& species) const noexcept {
|
||||||
if (_preEvolutionCache.Has(species)) {
|
if (_preEvolutionCache.Has(species)) {
|
||||||
return _preEvolutionCache[species];
|
return _preEvolutionCache[species];
|
||||||
}
|
}
|
||||||
for (auto& s : _values) {
|
for (const auto& s : _values) {
|
||||||
auto pkmn = (PokemonSpecies*)s.second.get();
|
auto* pkmn = (PokemonSpecies*)s.second.get();
|
||||||
for (auto& evo : pkmn->GetEvolutions()) {
|
for (const auto& evo : pkmn->GetEvolutions()) {
|
||||||
if (evo->GetNewSpecies() == species) {
|
if (evo->GetNewSpecies() == species) {
|
||||||
auto non_const = const_cast<SpeciesLibrary*>(this);
|
auto* non_const = const_cast<SpeciesLibrary*>(this);
|
||||||
non_const->_preEvolutionCache[species] = pkmn;
|
non_const->_preEvolutionCache[species] = pkmn;
|
||||||
return pkmn;
|
return pkmn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,12 @@ namespace PkmnLib::Library {
|
||||||
_preEvolutionCache;
|
_preEvolutionCache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline bool TryGet(const ArbUt::BasicStringView& name,
|
inline std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>>
|
||||||
ArbUt::BorrowedPtr<const PokemonSpecies>& outSpecies) const {
|
TryGet(const ArbUt::BasicStringView& name) const {
|
||||||
auto v = outSpecies.As<const PokemonSpecies::CreatureSpecies>();
|
auto res = CreatureLib::Library::SpeciesLibrary::TryGet(name);
|
||||||
auto res = CreatureLib::Library::SpeciesLibrary::TryGet(name, v);
|
if (!res.has_value())
|
||||||
outSpecies = v.As<const PokemonSpecies>();
|
return {};
|
||||||
return res;
|
return res.value().ForceAs<const PokemonSpecies>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ArbUt::BorrowedPtr<const PokemonSpecies> Get(const ArbUt::BasicStringView& name) const {
|
inline ArbUt::BorrowedPtr<const PokemonSpecies> Get(const ArbUt::BasicStringView& name) const {
|
||||||
|
@ -26,7 +26,7 @@ namespace PkmnLib::Library {
|
||||||
return Get(name);
|
return Get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArbUt::BorrowedPtr<const PokemonSpecies>
|
std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>>
|
||||||
FindPreEvolution(const ArbUt::BorrowedPtr<const PokemonSpecies>& species) const noexcept;
|
FindPreEvolution(const ArbUt::BorrowedPtr<const PokemonSpecies>& species) const noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg,
|
||||||
|
|
||||||
_contextPool = new ContextPool(_engine);
|
_contextPool = new ContextPool(_engine);
|
||||||
}
|
}
|
||||||
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, CreatureLib::Battling::Battle, GetBattle);
|
OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, CreatureLib::Battling::Battle, GetBattle);
|
||||||
|
|
||||||
void AngelScriptResolver::RegisterTypes() {
|
void AngelScriptResolver::RegisterTypes() {
|
||||||
// Register static library types
|
// Register static library types
|
||||||
|
@ -129,23 +129,26 @@ void AngelScriptResolver::MessageCallback(const asSMessageInfo* msg, void*) {
|
||||||
CreatureLib::Battling::Script* AngelScriptResolver::LoadScript(ScriptCategory category,
|
CreatureLib::Battling::Script* AngelScriptResolver::LoadScript(ScriptCategory category,
|
||||||
const ArbUt::StringView& scriptName) {
|
const ArbUt::StringView& scriptName) {
|
||||||
ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*> innerDb;
|
ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*> innerDb;
|
||||||
if (!_typeDatabase.TryGet(category, innerDb)) {
|
auto v = _typeDatabase.TryGet(category);
|
||||||
|
if (!v.has_value()) {
|
||||||
innerDb.Insert(scriptName, nullptr);
|
innerDb.Insert(scriptName, nullptr);
|
||||||
_typeDatabase.Insert(category, innerDb);
|
_typeDatabase.Insert(category, innerDb);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
} else {
|
||||||
|
innerDb = v.value();
|
||||||
}
|
}
|
||||||
AngelScriptTypeInfo* t;
|
auto t = innerDb.TryGet(scriptName);
|
||||||
if (!innerDb.TryGet(scriptName, t)) {
|
if (!t.has_value()) {
|
||||||
innerDb.Insert(scriptName, nullptr);
|
innerDb.Insert(scriptName, nullptr);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (t == nullptr) {
|
if (!t.has_value()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto ctx = _contextPool->RequestContext();
|
auto ctx = _contextPool->RequestContext();
|
||||||
auto obj = t->Instantiate(ctx);
|
auto obj = const_cast<AngelScriptTypeInfo*>(t.value().get())->Instantiate(ctx);
|
||||||
_contextPool->ReturnContextToPool(ctx);
|
_contextPool->ReturnContextToPool(ctx);
|
||||||
return new AngelScriptScript(this, t, obj, _contextPool);
|
return new AngelScriptScript(this, t.value(), obj, _contextPool);
|
||||||
}
|
}
|
||||||
void AngelScriptResolver::FinalizeModule() {
|
void AngelScriptResolver::FinalizeModule() {
|
||||||
int r = _builder.BuildModule();
|
int r = _builder.BuildModule();
|
||||||
|
|
|
@ -70,10 +70,13 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
asITypeInfo* GetBaseType(const ArbUt::StringView& name) {
|
asITypeInfo* GetBaseType(const ArbUt::StringView& name) {
|
||||||
asITypeInfo* t = nullptr;
|
asITypeInfo* t;
|
||||||
if (!_baseTypes.TryGet(name, t)) {
|
auto v = _baseTypes.TryGet(name);
|
||||||
|
if (!v.has_value()) {
|
||||||
t = this->_engine->GetTypeInfoByDecl(name.c_str());
|
t = this->_engine->GetTypeInfoByDecl(name.c_str());
|
||||||
_baseTypes.Insert(name, t);
|
_baseTypes.Insert(name, t);
|
||||||
|
} else {
|
||||||
|
t = v.value();
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,11 @@ public:
|
||||||
const char* GetDecl() { return _type->GetName(); }
|
const char* GetDecl() { return _type->GetName(); }
|
||||||
|
|
||||||
asIScriptFunction* GetFunction(const ArbUt::BasicStringView& functionName) {
|
asIScriptFunction* GetFunction(const ArbUt::BasicStringView& functionName) {
|
||||||
asIScriptFunction* func;
|
auto v = _functions.TryGet(functionName);
|
||||||
if (_functions.TryGet(functionName, func)) {
|
if (v.has_value()) {
|
||||||
return func;
|
return v.value();
|
||||||
}
|
}
|
||||||
func = _type->GetMethodByName(functionName.c_str());
|
auto func = _type->GetMethodByName(functionName.c_str());
|
||||||
if (func != nullptr) {
|
if (func != nullptr) {
|
||||||
func->AddRef();
|
func->AddRef();
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ static std::string NicknameWrapper(const PkmnLib::Battling::Pokemon* obj) { retu
|
||||||
|
|
||||||
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::CreatureSpecies, GetSpecies);
|
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::CreatureSpecies, GetSpecies);
|
||||||
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const PkmnLib::Library::PokemonForme, GetForme);
|
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const PkmnLib::Library::PokemonForme, GetForme);
|
||||||
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::Item, GetHeldItem);
|
OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::Item, GetHeldItem);
|
||||||
|
|
||||||
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||||
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#define BORROWED_PTR_GETTER_FUNC(o, returns, funcName) \
|
#define BORROWED_PTR_GETTER_FUNC(o, returns, funcName) \
|
||||||
static returns* funcName##Wrapper(o* obj) { return obj->funcName().GetRaw(); }
|
static returns* funcName##Wrapper(o* obj) { return obj->funcName().GetRaw(); }
|
||||||
|
#define OPTIONAL_BORROWED_PTR_GETTER_FUNC(o, returns, funcName) \
|
||||||
|
static returns* funcName##Wrapper(o* obj) { return obj->funcName().GetValue(); }
|
||||||
#define UNIQUE_PTR_GETTER_FUNC(o, returns, funcName) \
|
#define UNIQUE_PTR_GETTER_FUNC(o, returns, funcName) \
|
||||||
static returns* funcName##Wrapper(o* obj) { return obj->funcName().get(); }
|
static returns* funcName##Wrapper(o* obj) { return obj->funcName().get(); }
|
||||||
|
|
|
@ -161,7 +161,7 @@ TEST_CASE("Validate Pokemon HeldItem in Script") {
|
||||||
.WithGender(CreatureLib::Library::Gender::Male)
|
.WithGender(CreatureLib::Library::Gender::Male)
|
||||||
.Build();
|
.Build();
|
||||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
data.Context->SetArgObject(1, (void*)mon->GetHeldItem().GetRaw());
|
data.Context->SetArgObject(1, (void*)mon->GetHeldItem().GetValue());
|
||||||
|
|
||||||
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
REQUIRE((bool)data.Context->GetReturnWord());
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
|
Loading…
Reference in New Issue