diff --git a/src/Battling/PkmnDamageSource.hpp b/src/Battling/PkmnDamageSource.hpp new file mode 100644 index 0000000..bdf8a3d --- /dev/null +++ b/src/Battling/PkmnDamageSource.hpp @@ -0,0 +1,9 @@ +#ifndef PKMNLIB_PKMNDAMAGESOURCE_HPP +#define PKMNLIB_PKMNDAMAGESOURCE_HPP + +#include +#include + +ENUM_WITH_START_VALUE(PkmnDamageSource, uint8_t, ((uint8_t)CreatureLib::Battling::DamageSourceHelper::Highest()) + 1, + Struggle); +#endif // PKMNLIB_PKMNDAMAGESOURCE_HPP diff --git a/src/ScriptResolving/AngelScript/AngelScripResolver.cpp b/src/ScriptResolving/AngelScript/AngelScripResolver.cpp index c10abaf..e4280fb 100644 --- a/src/ScriptResolving/AngelScript/AngelScripResolver.cpp +++ b/src/ScriptResolving/AngelScript/AngelScripResolver.cpp @@ -146,8 +146,8 @@ void AngelScripResolver::FinalizeModule() { if (r < 0) throw CreatureException("Building Script Module failed."); asUINT count = _mainModule->GetObjectTypeCount(); - std::regex metadataMatcher("^\\s*(\\w+)([\\w\\s=]*)$", std::regex_constants::icase); - std::regex variableMatcher("\\s*(\\w+)=(\\w+)", std::regex_constants::icase); + std::regex metadataMatcher(R"(^\s*(\w+)([\w\s=]*)$)", std::regex_constants::icase); + std::regex variableMatcher(R"(\s*(\w+)=(\w+))", std::regex_constants::icase); std::smatch base_match; for (asUINT n = 0; n < count; n++) { diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp index 4c526cd..ab0a35c 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp @@ -1,8 +1,9 @@ #include "RegisterPokemonClass.hpp" #include -#include +#include #include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h" #include "../../../../Battling/Pokemon/Pokemon.hpp" +#include "../../../../Battling/PkmnDamageSource.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) \ @@ -17,38 +18,45 @@ void RegisterPokemonClass::Register(asIScriptEngine* engine) { void RegisterPokemonClass::RegisterDamageSource(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterEnum("DamageSource"); - assert(r >= 0); - r = engine->RegisterEnumValue("DamageSource", "AttackDamage", - (int)CreatureLib::Battling::DamageSource::AttackDamage); - assert(r >= 0); + Assert(r >= 0); + for (auto v: CreatureLib::Battling::DamageSourceHelper::GetValues()){ + r = engine->RegisterEnumValue("DamageSource", CreatureLib::Battling::DamageSourceHelper::ToString(v), + (int)v); + } + for (auto v: PkmnDamageSourceHelper::GetValues()){ + r = engine->RegisterEnumValue("DamageSource", PkmnDamageSourceHelper::ToString(v), + (int)v); + } + + Assert(r >= 0); } void RegisterPokemonClass::RegisterMoveLearnMethod(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterEnum("MoveLearnMethod"); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterEnumValue("MoveLearnMethod", "Unknown", (int)CreatureLib::Battling::AttackLearnMethod::Unknown); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterEnumValue("MoveLearnMethod", "Level", (int)CreatureLib::Battling::AttackLearnMethod::Level); - assert(r >= 0); + Assert(r >= 0); } ENUM__SIZE_WRAPPER(LearnedMove_LearnMethodWrapper, CreatureLib::Battling::LearnedAttack, GetLearnMethod) void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterObjectType("LearnedMove", 0, asOBJ_REF | asOBJ_NOCOUNT); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("LearnedMove", "const MoveData@ get_MoveData() const property", asMETHOD(CreatureLib::Battling::LearnedAttack, GetAttack), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_MaxUses() const property", asMETHOD(CreatureLib::Battling::LearnedAttack, GetMaxUses), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_RemainingUses() const property", asMETHOD(CreatureLib::Battling::LearnedAttack, GetRemainingUses), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("LearnedMove", "Gender get_LearnMethod() const property", asFUNCTION(LearnedMove_LearnMethodWrapper), asCALL_CDECL_OBJLAST); - assert(r >= 0); + Assert(r >= 0); } ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender) @@ -89,104 +97,104 @@ static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ConstString void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_Species() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetSpecies), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "const Forme@ get_Forme() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetForme), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Level() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetLevel), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint32 get_Experience() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetExperience), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "Gender get_Gender() const property", asFUNCTION(Pkmn_GenderWrapper), asCALL_CDECL_OBJLAST); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Coloring() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetColoring), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "bool get_Shiny() const property", asMETHOD(PkmnLib::Battling::Pokemon, IsShiny), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetHeldItem), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const", asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod( "Pokemon", "void SetHeldItem(const string &in name)", asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const Arbutils::CaseInsensitiveConstString&), void), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod( "Pokemon", "void SetHeldItem(const Item@ item)", asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const CreatureLib::Library::Item*), void), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint32 get_CurrentHealth() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetCurrentHealth), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "const string& get_Nickname() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetNickname), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "const constString& get_ActiveAbility() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetActiveTalent), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "bool get_IsFainted() const property", asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint8[]@ GetTypes() const", asFUNCTION(GetTypes), asCALL_CDECL_OBJLAST); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const", asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint32 get_MaxHealth() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetMaxHealth), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "void Damage(uint32 type, DamageSource source)", asMETHOD(PkmnLib::Battling::Pokemon, Damage), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "void Heal(uint32 type)", asMETHOD(PkmnLib::Battling::Pokemon, Heal), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "void OverrideActiveAbility(const string &in ability)", asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ GetMoves() const", asFUNCTION(GetMoves), asCALL_CDECL_OBJLAST); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "void ChangeStatBoost(Statistic stat, int8 amount)", asMETHOD(PkmnLib::Battling::Pokemon, ChangeStatBoost), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplaySpecies() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetDisplaySpecies), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplayForme() const property", asMETHOD(PkmnLib::Battling::Pokemon, GetDisplayVariant), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint32 GetFlatStat(Statistic stat) const", asMETHOD(PkmnLib::Battling::Pokemon, GetFlatStat), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint32 GetBoostedStat(Statistic stat) const", asMETHOD(PkmnLib::Battling::Pokemon, GetBoostedStat), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "uint32 GetBaseStat(Statistic stat) const", asMETHOD(PkmnLib::Battling::Pokemon, GetBaseStat), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "int8 GetStatBoost(Statistic stat) const", asMETHOD(PkmnLib::Battling::Pokemon, GetStatBoost), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod( "Pokemon", "void AddVolatile(const constString &in name) const", asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod( "Pokemon", "void RemoveVolatile(const constString &in name) const", asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); } \ No newline at end of file