File formatting.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-28 14:48:56 +02:00
parent 686f898259
commit c4b866cb38
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
45 changed files with 140 additions and 157 deletions

View File

@ -2,7 +2,8 @@
#include "../Core.hpp" #include "../Core.hpp"
using namespace PkmnLib::Library; using namespace PkmnLib::Library;
export const LibrarySettings* PkmnLib_LibrarySettings_Construct(uint8_t maximalLevel, uint8_t maximalMoves, uint16_t shinyRate) { export const LibrarySettings* PkmnLib_LibrarySettings_Construct(uint8_t maximalLevel, uint8_t maximalMoves,
uint16_t shinyRate) {
return new LibrarySettings(maximalLevel, maximalMoves, shinyRate); return new LibrarySettings(maximalLevel, maximalMoves, shinyRate);
} }

View File

@ -2,8 +2,9 @@
#include "../Core.hpp" #include "../Core.hpp"
using namespace PkmnLib::Library; using namespace PkmnLib::Library;
export Nature* PkmnLib_Nature_Construct(CreatureLib::Library::Statistic increasedStat, CreatureLib::Library::Statistic decreasedStat, export Nature* PkmnLib_Nature_Construct(CreatureLib::Library::Statistic increasedStat,
float increasedModifier, float decreasedModifier) { CreatureLib::Library::Statistic decreasedStat, float increasedModifier,
float decreasedModifier) {
return new Nature(increasedStat, decreasedStat, increasedModifier, decreasedModifier); return new Nature(increasedStat, decreasedStat, increasedModifier, decreasedModifier);
} }
export void PkmnLib_Nature_Destruct(const Nature* p) { delete p; } export void PkmnLib_Nature_Destruct(const Nature* p) { delete p; }

View File

@ -14,8 +14,7 @@ uint32_t PkmnLib::Battling::StatCalculator::CalculateOtherStat(const Pokemon* pk
uint32_t iv = pkmn->GetIndividualValue(stat); uint32_t iv = pkmn->GetIndividualValue(stat);
uint32_t ev = pkmn->GetEffortValue(stat); uint32_t ev = pkmn->GetEffortValue(stat);
uint8_t level = pkmn->GetLevel(); uint8_t level = pkmn->GetLevel();
uint32_t unmodified = uint32_t unmodified = static_cast<uint32_t>(((2 * base + iv + static_cast<uint32_t>(ev / 4)) * level) / 100) + 5;
static_cast<uint32_t>(((2 * base + iv + static_cast<uint32_t>(ev / 4)) * level) / 100) + 5;
return static_cast<uint32_t>(unmodified * pkmn->GetNature()->GetStatModifier(stat)); return static_cast<uint32_t>(unmodified * pkmn->GetNature()->GetStatModifier(stat));
} }
float PkmnLib::Battling::StatCalculator::GetStatBoostModifier(const CreatureLib::Battling::Creature* pkmn, float PkmnLib::Battling::StatCalculator::GetStatBoostModifier(const CreatureLib::Battling::Creature* pkmn,
@ -41,8 +40,8 @@ float PkmnLib::Battling::StatCalculator::GetStatBoostModifier(const CreatureLib:
CreatureLib::Library::StatisticSet<uint32_t> CreatureLib::Library::StatisticSet<uint32_t>
PkmnLib::Battling::StatCalculator::CalculateFlatStats(CreatureLib::Battling::Creature* creature) const { PkmnLib::Battling::StatCalculator::CalculateFlatStats(CreatureLib::Battling::Creature* creature) const {
auto pkmn = dynamic_cast<Pokemon*>(creature); auto pkmn = dynamic_cast<Pokemon*>(creature);
return CreatureLib::Library::StatisticSet<uint32_t>( return CreatureLib::Library::StatisticSet<uint32_t>(CalculateHealthStat(pkmn),
CalculateHealthStat(pkmn), CalculateOtherStat(pkmn, Library::Statistic::PhysicalAttack), CalculateOtherStat(pkmn, Library::Statistic::PhysicalAttack),
CalculateOtherStat(pkmn, Library::Statistic::PhysicalDefense), CalculateOtherStat(pkmn, Library::Statistic::PhysicalDefense),
CalculateOtherStat(pkmn, Library::Statistic::SpecialAttack), CalculateOtherStat(pkmn, Library::Statistic::SpecialAttack),
CalculateOtherStat(pkmn, Library::Statistic::SpecialDefense), CalculateOtherStat(pkmn, Library::Statistic::SpecialDefense),

View File

@ -29,7 +29,8 @@ const EvolutionData* EvolutionData::CreateTradeWithItemEvolution(const Item* ite
return new EvolutionData(EvolutionMethod::TradeWithHeldItem, return new EvolutionData(EvolutionMethod::TradeWithHeldItem,
{new CreatureLib::Library::EffectParameter(item->GetName())}, into); {new CreatureLib::Library::EffectParameter(item->GetName())}, into);
} }
const EvolutionData* EvolutionData::CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded, const PokemonSpecies* into) { const EvolutionData* EvolutionData::CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded,
const PokemonSpecies* into) {
return new EvolutionData(EvolutionMethod::TradeWithSpecificPokemon, return new EvolutionData(EvolutionMethod::TradeWithSpecificPokemon,
{new CreatureLib::Library::EffectParameter(traded->GetName())}, into); {new CreatureLib::Library::EffectParameter(traded->GetName())}, into);
} }

View File

@ -5,8 +5,7 @@
namespace PkmnLib::Library { namespace PkmnLib::Library {
ENUM(EvolutionMethod, uint8_t, Level, HighFriendship, KnownMove, LocationBased, TimeBased, HoldsItem, ENUM(EvolutionMethod, uint8_t, Level, HighFriendship, KnownMove, LocationBased, TimeBased, HoldsItem,
IsGenderAndLevel, EvolutionItemUse, EvolutionItemUseWithGender, Trade, TradeWithHeldItem, IsGenderAndLevel, EvolutionItemUse, EvolutionItemUseWithGender, Trade, TradeWithHeldItem,
TradeWithSpecificPokemon, Custom TradeWithSpecificPokemon, Custom)
)
} }
#endif // PKMNLIB_EVOLUTIONMETHOD_HPP #endif // PKMNLIB_EVOLUTIONMETHOD_HPP

View File

@ -38,8 +38,7 @@ namespace PkmnLib::Library {
auto& map = _items.GetStdMap(); auto& map = _items.GetStdMap();
return std::next(std::begin(map), i)->first; return std::next(std::begin(map), i)->first;
} }
inline const Arbutils::CaseInsensitiveConstString& inline const Arbutils::CaseInsensitiveConstString& GetRandomNatureName(Arbutils::Random* rand) const {
GetRandomNatureName(Arbutils::Random* rand) const {
auto i = rand->Get(_items.Count()); auto i = rand->Get(_items.Count());
auto& map = _items.GetStdMap(); auto& map = _items.GetStdMap();
return std::next(std::begin(map), i)->first; return std::next(std::begin(map), i)->first;

View File

@ -14,9 +14,7 @@ namespace PkmnLib::Library {
const NatureLibrary* _natures; const NatureLibrary* _natures;
public: public:
~PokemonLibrary() override { ~PokemonLibrary() override { delete _natures; }
delete _natures;
}
PokemonLibrary(PkmnLib::Library::LibrarySettings* settings, SpeciesLibrary* species, MoveLibrary* moves, PokemonLibrary(PkmnLib::Library::LibrarySettings* settings, SpeciesLibrary* species, MoveLibrary* moves,
ItemLibrary* items, CreatureLib::Library::GrowthRateLibrary* growthRates, ItemLibrary* items, CreatureLib::Library::GrowthRateLibrary* growthRates,
@ -39,9 +37,7 @@ namespace PkmnLib::Library {
return (const ItemLibrary*)(CreatureLib::Library::DataLibrary::GetItemLibrary()); return (const ItemLibrary*)(CreatureLib::Library::DataLibrary::GetItemLibrary());
} }
[[nodiscard]] const NatureLibrary* GetNatureLibrary() const { [[nodiscard]] const NatureLibrary* GetNatureLibrary() const { return _natures; }
return _natures;
}
}; };
} }

View File

@ -19,6 +19,7 @@ private:
asIScriptObject* _obj = nullptr; asIScriptObject* _obj = nullptr;
CScriptArray* GetEffectParameters(const List<CreatureLib::Library::EffectParameter*>& ls); CScriptArray* GetEffectParameters(const List<CreatureLib::Library::EffectParameter*>& ls);
public: public:
AngelScriptScript(AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj, AngelScriptScript(AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj,
ContextPool* ctxPool) ContextPool* ctxPool)

View File

@ -6,6 +6,7 @@ class RegisterBattleClass {
static void RegisterChoiceQueue(asIScriptEngine* engine); static void RegisterChoiceQueue(asIScriptEngine* engine);
static void RegisterBattle(asIScriptEngine* engine); static void RegisterBattle(asIScriptEngine* engine);
static void RegisterBattleRandom(asIScriptEngine* engine); static void RegisterBattleRandom(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);
}; };

View File

@ -5,6 +5,7 @@
class RegisterBattleLibrary { class RegisterBattleLibrary {
static void RegisterDamageLibrary(asIScriptEngine* engine); static void RegisterDamageLibrary(asIScriptEngine* engine);
static void RegisterLibrary(asIScriptEngine* engine); static void RegisterLibrary(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);
}; };

View File

@ -1,6 +1,6 @@
#include "RegisterExecutingAttack.hpp" #include "RegisterExecutingAttack.hpp"
#include <CreatureLib/Battling/Models/ExecutingAttack.hpp>
#include <Arbutils/Assert.hpp> #include <Arbutils/Assert.hpp>
#include <CreatureLib/Battling/Models/ExecutingAttack.hpp>
void RegisterExecutingAttack::Register(asIScriptEngine* engine) { void RegisterExecutingAttack::Register(asIScriptEngine* engine) {
RegisterHitData(engine); RegisterHitData(engine);
@ -34,20 +34,16 @@ void RegisterExecutingAttack::RegisterExecutingAttackType(asIScriptEngine* engin
[[maybe_unused]] int r = engine->RegisterObjectType("ExecutingMove", 0, asOBJ_REF | asOBJ_NOCOUNT); [[maybe_unused]] int r = engine->RegisterObjectType("ExecutingMove", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "HitData@ GetHitData(Pokemon@ target, uint8 hit) const", r = engine->RegisterObjectMethod("ExecutingMove", "HitData@ GetHitData(Pokemon@ target, uint8 hit) const",
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetHitData), asMETHOD(CreatureLib::Battling::ExecutingAttack, GetHitData), asCALL_THISCALL);
asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "bool IsPokemonTarget(Pokemon@ pkmn) const", r = engine->RegisterObjectMethod("ExecutingMove", "bool IsPokemonTarget(Pokemon@ pkmn) const",
asMETHOD(CreatureLib::Battling::ExecutingAttack, IsCreatureTarget), asMETHOD(CreatureLib::Battling::ExecutingAttack, IsCreatureTarget),
asCALL_THISCALL); asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "Pokemon@ get_User() const property", r = engine->RegisterObjectMethod("ExecutingMove", "Pokemon@ get_User() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetUser), asMETHOD(CreatureLib::Battling::ExecutingAttack, GetUser), asCALL_THISCALL);
asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "LearnedMove@ get_Move() const property", r = engine->RegisterObjectMethod("ExecutingMove", "LearnedMove@ get_Move() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetAttack), asMETHOD(CreatureLib::Battling::ExecutingAttack, GetAttack), asCALL_THISCALL);
asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);
} }

View File

@ -6,6 +6,7 @@
class RegisterExecutingAttack { class RegisterExecutingAttack {
static void RegisterHitData(asIScriptEngine* engine); static void RegisterHitData(asIScriptEngine* engine);
static void RegisterExecutingAttackType(asIScriptEngine* engine); static void RegisterExecutingAttackType(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);
}; };

View File

@ -1,9 +1,9 @@
#include "RegisterPokemonClass.hpp" #include "RegisterPokemonClass.hpp"
#include <CreatureLib/Battling/Models/LearnedAttack.hpp>
#include <Arbutils/Assert.hpp> #include <Arbutils/Assert.hpp>
#include <CreatureLib/Battling/Models/LearnedAttack.hpp>
#include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h" #include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h"
#include "../../../../Battling/Pokemon/Pokemon.hpp"
#include "../../../../Battling/PkmnDamageSource.hpp" #include "../../../../Battling/PkmnDamageSource.hpp"
#include "../../../../Battling/Pokemon/Pokemon.hpp"
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it. // 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) \ #define ENUM__SIZE_WRAPPER(name, type, func) \
@ -20,12 +20,10 @@ void RegisterPokemonClass::RegisterDamageSource(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("DamageSource"); [[maybe_unused]] int r = engine->RegisterEnum("DamageSource");
Assert(r >= 0); Assert(r >= 0);
for (auto v : CreatureLib::Battling::DamageSourceHelper::GetValues()) { for (auto v : CreatureLib::Battling::DamageSourceHelper::GetValues()) {
r = engine->RegisterEnumValue("DamageSource", CreatureLib::Battling::DamageSourceHelper::ToString(v), r = engine->RegisterEnumValue("DamageSource", CreatureLib::Battling::DamageSourceHelper::ToString(v), (int)v);
(int)v);
} }
for (auto v : PkmnDamageSourceHelper::GetValues()) { for (auto v : PkmnDamageSourceHelper::GetValues()) {
r = engine->RegisterEnumValue("DamageSource", PkmnDamageSourceHelper::ToString(v), r = engine->RegisterEnumValue("DamageSource", PkmnDamageSourceHelper::ToString(v), (int)v);
(int)v);
} }
Assert(r >= 0); Assert(r >= 0);
@ -94,7 +92,6 @@ static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ConstString
return obj->HasHeldItem(str.GetHash()); return obj->HasHeldItem(str.GetHash());
} }
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);
Assert(r >= 0); Assert(r >= 0);

View File

@ -7,6 +7,7 @@ class RegisterPokemonClass {
static void RegisterMoveLearnMethod(asIScriptEngine* engine); static void RegisterMoveLearnMethod(asIScriptEngine* engine);
static void RegisterLearnedAttack(asIScriptEngine* engine); static void RegisterLearnedAttack(asIScriptEngine* engine);
static void RegisterPokemonType(asIScriptEngine* engine); static void RegisterPokemonType(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);
}; };

View File

@ -73,7 +73,8 @@ void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) {
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetUser), asCALL_THISCALL); asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetUser), asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod("SwitchTurnChoice", "Pokemon@ get_NewPokemon() const property", r = engine->RegisterObjectMethod("SwitchTurnChoice", "Pokemon@ get_NewPokemon() const property",
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetNewCreature), asCALL_THISCALL); asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetNewCreature),
asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(

View File

@ -7,6 +7,7 @@ class RegisterTurnChoices {
static void RegisterBaseTurnChoice(asIScriptEngine* engine); static void RegisterBaseTurnChoice(asIScriptEngine* engine);
static void RegisterMoveTurnChoice(asIScriptEngine* engine); static void RegisterMoveTurnChoice(asIScriptEngine* engine);
static void RegisterSwitchTurnChoice(asIScriptEngine* engine); static void RegisterSwitchTurnChoice(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);
}; };

View File

@ -3,9 +3,7 @@ using ConstString = Arbutils::CaseInsensitiveConstString;
static void ConstructConstString(void* self) { new (self) ConstString(); } static void ConstructConstString(void* self) { new (self) ConstString(); }
static void CopyConstructConstString(const ConstString& other, void* self) { new (self) ConstString(other); } static void CopyConstructConstString(const ConstString& other, void* self) { new (self) ConstString(other); }
static void DestructConstString(void* self) { static void DestructConstString(void* self) { ((ConstString*)self)->~ConstString(); }
((ConstString*)self)->~ConstString();
}
static bool ConstStringEquality(const ConstString& a, const ConstString& b) { return a == b; } static bool ConstStringEquality(const ConstString& a, const ConstString& b) { return a == b; }
static bool ConstStringStdStringEquality(const ConstString& a, const std::string& b) { return a == b; } static bool ConstStringStdStringEquality(const ConstString& a, const std::string& b) { return a == b; }
static ConstString ImplStdStringConstStringConv(const std::string& s) { return ConstString(s); } static ConstString ImplStdStringConstStringConv(const std::string& s) { return ConstString(s); }

View File

@ -34,8 +34,8 @@ void RegisterGrowthRateTypes::RegisterGrowthRateLibrary(asIScriptEngine* engine)
"uint8 CalculateLevel(const constString &in growthRate, uint experience) const", "uint8 CalculateLevel(const constString &in growthRate, uint experience) const",
asFUNCTION(CalculateLevel), asCALL_CDECL_OBJLAST); asFUNCTION(CalculateLevel), asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("GrowthRateLibrary", r = engine->RegisterObjectMethod(
"uint CalculateExperience(const constString &in growthRate, uint8 experience) const", "GrowthRateLibrary", "uint CalculateExperience(const constString &in growthRate, uint8 experience) const",
asFUNCTION(CalculateExperience), asCALL_CDECL_OBJLAST); asFUNCTION(CalculateExperience), asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
} }

View File

@ -5,6 +5,7 @@
class RegisterGrowthRateTypes { class RegisterGrowthRateTypes {
static void RegisterGrowthRateType(asIScriptEngine* engine); static void RegisterGrowthRateType(asIScriptEngine* engine);
static void RegisterGrowthRateLibrary(asIScriptEngine* engine); static void RegisterGrowthRateLibrary(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);
}; };

View File

@ -23,7 +23,8 @@ void RegisterItemTypes::RegisterItemCategoryEnum(asIScriptEngine* engine) {
assert(r >= 0); assert(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "TM", (int)CreatureLib::Library::ItemCategory::MoveLearner); r = engine->RegisterEnumValue("ItemCategory", "TM", (int)CreatureLib::Library::ItemCategory::MoveLearner);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "VariantChanger", (int)CreatureLib::Library::ItemCategory::VariantChanger); r = engine->RegisterEnumValue("ItemCategory", "VariantChanger",
(int)CreatureLib::Library::ItemCategory::VariantChanger);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "KeyItem", (int)CreatureLib::Library::ItemCategory::KeyItem); r = engine->RegisterEnumValue("ItemCategory", "KeyItem", (int)CreatureLib::Library::ItemCategory::KeyItem);
assert(r >= 0); assert(r >= 0);
@ -36,13 +37,17 @@ void RegisterItemTypes::RegisterBattleItemCategoryEnum(asIScriptEngine* engine)
assert(r >= 0); assert(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "None", (int)CreatureLib::Library::BattleItemCategory::None); r = engine->RegisterEnumValue("BattleItemCategory", "None", (int)CreatureLib::Library::BattleItemCategory::None);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "Healing", (int)CreatureLib::Library::BattleItemCategory::Healing); r = engine->RegisterEnumValue("BattleItemCategory", "Healing",
(int)CreatureLib::Library::BattleItemCategory::Healing);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "StatusHealing", (int)CreatureLib::Library::BattleItemCategory::StatusHealing); r = engine->RegisterEnumValue("BattleItemCategory", "StatusHealing",
(int)CreatureLib::Library::BattleItemCategory::StatusHealing);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "CaptureDevice", (int)CreatureLib::Library::BattleItemCategory::CaptureDevice); r = engine->RegisterEnumValue("BattleItemCategory", "CaptureDevice",
(int)CreatureLib::Library::BattleItemCategory::CaptureDevice);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "Misc", (int)CreatureLib::Library::BattleItemCategory::MiscBattleItem); r = engine->RegisterEnumValue("BattleItemCategory", "Misc",
(int)CreatureLib::Library::BattleItemCategory::MiscBattleItem);
assert(r >= 0); assert(r >= 0);
} }
@ -57,7 +62,6 @@ static bool HasFlag(const PkmnLib::Library::Item* obj, const Arbutils::CaseInsen
return obj->HasFlag(str); return obj->HasFlag(str);
} }
void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) { void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Item", 0, asOBJ_REF | asOBJ_NOCOUNT); [[maybe_unused]] int r = engine->RegisterObjectType("Item", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0); assert(r >= 0);
@ -73,11 +77,9 @@ void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Item", "int get_Price() const property", r = engine->RegisterObjectMethod("Item", "int get_Price() const property",
asMETHOD(PkmnLib::Library::Item, GetPrice), asCALL_THISCALL); asMETHOD(PkmnLib::Library::Item, GetPrice), asCALL_THISCALL);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("Item", "bool HasFlag(const constString &in flag) const", r = engine->RegisterObjectMethod("Item", "bool HasFlag(const constString &in flag) const", asFUNCTION(HasFlag),
asFUNCTION(HasFlag), asCALL_CDECL_OBJLAST); asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
} }
void RegisterItemTypes::RegisterItemLibrary(asIScriptEngine* engine) { void RegisterItemTypes::RegisterItemLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("ItemLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT); [[maybe_unused]] int r = engine->RegisterObjectType("ItemLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);

View File

@ -7,6 +7,7 @@ class RegisterItemTypes {
static void RegisterBattleItemCategoryEnum(asIScriptEngine* engine); static void RegisterBattleItemCategoryEnum(asIScriptEngine* engine);
static void RegisterItemType(asIScriptEngine* engine); static void RegisterItemType(asIScriptEngine* engine);
static void RegisterItemLibrary(asIScriptEngine* engine); static void RegisterItemLibrary(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);
}; };

View File

@ -77,8 +77,8 @@ void RegisterMoveTypes::RegisterMoveType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("MoveData", "int8 get_Priority() const property", r = engine->RegisterObjectMethod("MoveData", "int8 get_Priority() const property",
asMETHOD(PkmnLib::Library::MoveData, GetPriority), asCALL_THISCALL); asMETHOD(PkmnLib::Library::MoveData, GetPriority), asCALL_THISCALL);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "bool HasFlag(const constString &in flag) const", r = engine->RegisterObjectMethod("MoveData", "bool HasFlag(const constString &in flag) const", asFUNCTION(HasFlag),
asFUNCTION(HasFlag), asCALL_CDECL_OBJLAST); asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
} }
void RegisterMoveTypes::RegisterMoveLibrary(asIScriptEngine* engine) { void RegisterMoveTypes::RegisterMoveLibrary(asIScriptEngine* engine) {

View File

@ -7,6 +7,7 @@ class RegisterMoveTypes {
static void RegisterMoveTarget(asIScriptEngine* engine); static void RegisterMoveTarget(asIScriptEngine* engine);
static void RegisterMoveType(asIScriptEngine* engine); static void RegisterMoveType(asIScriptEngine* engine);
static void RegisterMoveLibrary(asIScriptEngine* engine); static void RegisterMoveLibrary(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);
}; };

View File

@ -41,6 +41,4 @@ void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("StaticLibrary", "const TypeLibrary@ get_TypeLibrary() const property", r = engine->RegisterObjectMethod("StaticLibrary", "const TypeLibrary@ get_TypeLibrary() const property",
asMETHOD(PkmnLib::Library::PokemonLibrary, GetTypeLibrary), asCALL_THISCALL); asMETHOD(PkmnLib::Library::PokemonLibrary, GetTypeLibrary), asCALL_THISCALL);
assert(r >= 0); assert(r >= 0);
} }

View File

@ -5,6 +5,7 @@
class RegisterStaticLibraryTypes { class RegisterStaticLibraryTypes {
static void RegisterLibrarySettingsType(asIScriptEngine* engine); static void RegisterLibrarySettingsType(asIScriptEngine* engine);
static void RegisterLibraryType(asIScriptEngine* engine); static void RegisterLibraryType(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);
}; };

View File

@ -2,9 +2,7 @@
#include <CreatureLib/Library/TypeLibrary.hpp> #include <CreatureLib/Library/TypeLibrary.hpp>
#include <cassert> #include <cassert>
void RegisterTypeLibrary::Register(asIScriptEngine* engine) { void RegisterTypeLibrary::Register(asIScriptEngine* engine) { RegisterTypeLibraryType(engine); }
RegisterTypeLibraryType(engine);
}
static bool GetTypeId(const CreatureLib::Library::TypeLibrary* obj, const Arbutils::CaseInsensitiveConstString& str) { static bool GetTypeId(const CreatureLib::Library::TypeLibrary* obj, const Arbutils::CaseInsensitiveConstString& str) {
return obj->GetTypeId(str); return obj->GetTypeId(str);
@ -16,7 +14,8 @@ void RegisterTypeLibrary::RegisterTypeLibraryType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("TypeLibrary", "uint8 GetTypeId(const constString &in name) const", r = engine->RegisterObjectMethod("TypeLibrary", "uint8 GetTypeId(const constString &in name) const",
asFUNCTION(GetTypeId), asCALL_CDECL_OBJLAST); asFUNCTION(GetTypeId), asCALL_CDECL_OBJLAST);
assert(r >= 0); assert(r >= 0);
r = engine->RegisterObjectMethod("TypeLibrary", "float GetSingleEffectiveness(uint8 attacking, uint8 defensive) const", r = engine->RegisterObjectMethod(
"TypeLibrary", "float GetSingleEffectiveness(uint8 attacking, uint8 defensive) const",
asMETHOD(CreatureLib::Library::TypeLibrary, GetSingleEffectiveness), asCALL_THISCALL); asMETHOD(CreatureLib::Library::TypeLibrary, GetSingleEffectiveness), asCALL_THISCALL);
assert(r >= 0); assert(r >= 0);
// TODO: Register get full effectiveness method. // TODO: Register get full effectiveness method.

View File

@ -4,6 +4,7 @@
class RegisterTypeLibrary { class RegisterTypeLibrary {
static void RegisterTypeLibraryType(asIScriptEngine* engine); static void RegisterTypeLibraryType(asIScriptEngine* engine);
public: public:
static void Register(asIScriptEngine* engine); static void Register(asIScriptEngine* engine);
}; };

View File

@ -1,9 +1,8 @@
#ifndef PKMNLIB_REFCAST_HPP #ifndef PKMNLIB_REFCAST_HPP
#define PKMNLIB_REFCAST_HPP #define PKMNLIB_REFCAST_HPP
template<class A, class B> template <class A, class B> B* refCast(A* a) {
B* refCast(A* a) if (!a)
{ return 0;
if( !a ) return 0;
B* b = dynamic_cast<B*>(a); B* b = dynamic_cast<B*>(a);
return b; return b;
} }

View File

@ -36,5 +36,4 @@ TEST_CASE("Able to insert and retrieve from library", "library") {
delete lib; delete lib;
} }
#endif #endif

View File

@ -351,9 +351,7 @@ TEST_CASE("Validate Pokemon HasHeldItem in Script") {
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
REQUIRE((bool)data.Context->GetReturnDWord()); REQUIRE((bool)data.Context->GetReturnDWord());
delete mon; delete mon;
} }
#endif #endif

View File

@ -102,7 +102,4 @@ TEST_CASE("Validate Item Price in Script") {
REQUIRE((bool)data.Context->GetReturnWord()); REQUIRE((bool)data.Context->GetReturnWord());
} }
#endif #endif

View File

@ -157,5 +157,4 @@ TEST_CASE("Validate Move Priority in Script") {
REQUIRE((bool)data.Context->GetReturnWord()); REQUIRE((bool)data.Context->GetReturnWord());
} }
#endif #endif

View File

@ -60,8 +60,7 @@ TEST_CASE("Validate Species Name in Script") {
auto data = GetScript(mainLib, "testName"_cnc); auto data = GetScript(mainLib, "testName"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject( data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
auto name = species->GetName(); auto name = species->GetName();
data.Context->SetArgAddress(1, &name); data.Context->SetArgAddress(1, &name);
@ -76,8 +75,7 @@ TEST_CASE("Validate Species Id in Script") {
auto data = GetScript(mainLib, "testId"_cnc); auto data = GetScript(mainLib, "testId"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject( data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
data.Context->SetArgWord(1, species->GetId()); data.Context->SetArgWord(1, species->GetId());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -91,8 +89,7 @@ TEST_CASE("Validate Species Gender Rate in Script") {
auto data = GetScript(mainLib, "testGenderRate"_cnc); auto data = GetScript(mainLib, "testGenderRate"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject( data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
data.Context->SetArgFloat(1, species->GetGenderRate()); data.Context->SetArgFloat(1, species->GetGenderRate());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -106,8 +103,7 @@ TEST_CASE("Validate Species Capture Rate in Script") {
auto data = GetScript(mainLib, "testCaptureRate"_cnc); auto data = GetScript(mainLib, "testCaptureRate"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject( data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
data.Context->SetArgByte(1, species->GetCaptureRate()); data.Context->SetArgByte(1, species->GetCaptureRate());
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -121,8 +117,7 @@ TEST_CASE("Validate Species Get Forme in Script") {
auto data = GetScript(mainLib, "testGetForme"_cnc); auto data = GetScript(mainLib, "testGetForme"_cnc);
auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc); auto species = mainLib->GetSpeciesLibrary()->Get("testSpecies2"_cnc);
data.Context->SetArgObject( data.Context->SetArgObject(0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
0, const_cast<PkmnLib::Library::PokemonSpecies*>(species));
data.Context->SetArgObject(1, const_cast<PkmnLib::Library::PokemonForme*>(species->GetForme("default"_cnc))); data.Context->SetArgObject(1, const_cast<PkmnLib::Library::PokemonForme*>(species->GetForme("default"_cnc)));
auto result = data.Context->Execute(); auto result = data.Context->Execute();
@ -148,6 +143,4 @@ TEST_CASE("Validate Species Get Default Forme in Script") {
REQUIRE(v); REQUIRE(v);
} }
#endif #endif