diff --git a/CInterface/Battling/Battle.cpp b/CInterface/Battling/Battle.cpp new file mode 100644 index 0000000..ca6ab15 --- /dev/null +++ b/CInterface/Battling/Battle.cpp @@ -0,0 +1,17 @@ +#include "../../src/Battling/Battle/Battle.hpp" +#include "../Core.hpp" +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 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))); +}; +export uint8_t PkmnLib_Battle_ClearWeather(Battle* p) { Try(p->ClearWeather()); }; +export const char* PkmnLib_Battle_GetWeatherName(Battle* p) { return p->GetWeatherName().c_str(); } \ No newline at end of file diff --git a/src/Battling/Battle/Battle.cpp b/src/Battling/Battle/Battle.cpp index 6a50a07..b888018 100644 --- a/src/Battling/Battle/Battle.cpp +++ b/src/Battling/Battle/Battle.cpp @@ -1 +1,15 @@ #include "Battle.hpp" +void PkmnLib::Battling::Battle::SetWeather(const Arbutils::CaseInsensitiveConstString& name) { + if (_weatherScript != nullptr) { + _weatherScript->OnRemove(); + delete _weatherScript; + } + _weatherScript = _library->LoadScript(static_cast(PkmnScriptCategory::Weather), name); + _eventHook.TriggerEvent(new WeatherChangeEvent(name)); +} +void PkmnLib::Battling::Battle::ClearWeather() { + _weatherScript->OnRemove(); + delete _weatherScript; + _weatherScript = nullptr; + _eventHook.TriggerEvent(new WeatherChangeEvent(""_cnc)); +} diff --git a/src/Battling/Battle/Battle.hpp b/src/Battling/Battle/Battle.hpp index bfcc8ed..9a3ceee 100644 --- a/src/Battling/Battle/Battle.hpp +++ b/src/Battling/Battle/Battle.hpp @@ -16,20 +16,8 @@ namespace PkmnLib::Battling { 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) { - if (_weatherScript != nullptr) { - _weatherScript->OnRemove(); - delete _weatherScript; - } - _weatherScript = _library->LoadScript(static_cast(PkmnScriptCategory::Weather), name); - _eventHook.TriggerEvent(new WeatherChangeEvent(name)); - } - void ClearWeather() { - _weatherScript->OnRemove(); - delete _weatherScript; - _weatherScript = nullptr; - _eventHook.TriggerEvent(new WeatherChangeEvent(""_cnc)); - } + void SetWeather(const Arbutils::CaseInsensitiveConstString& name); + void ClearWeather(); const Arbutils::CaseInsensitiveConstString& GetWeatherName() noexcept { return _weatherScript->GetName(); } size_t ScriptCount() const override { return CreatureLib::Battling::Battle::ScriptCount() + 1; } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterExecutingAttack.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterExecutingAttack.cpp index 2ff786d..2df352f 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterExecutingAttack.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterExecutingAttack.cpp @@ -1,6 +1,6 @@ #include "RegisterExecutingAttack.hpp" #include -#include +#include void RegisterExecutingAttack::Register(asIScriptEngine* engine) { RegisterHitData(engine); @@ -8,46 +8,46 @@ void RegisterExecutingAttack::Register(asIScriptEngine* engine) { } void RegisterExecutingAttack::RegisterHitData(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterObjectType("HitData", 0, asOBJ_REF | asOBJ_NOCOUNT); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("HitData", "bool get_IsCritical() const property", asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, IsCritical), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("HitData", "uint8 get_BasePower() const property", asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetBasePower), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("HitData", "float get_Effectiveness() const property", asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetEffectiveness), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("HitData", "uint get_Damage() const property", asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetDamage), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("HitData", "uint8 get_Type() const property", asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetType), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); } void RegisterExecutingAttack::RegisterExecutingAttackType(asIScriptEngine* engine) { [[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", asMETHOD(CreatureLib::Battling::ExecutingAttack, GetHitData), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("ExecutingMove", "bool IsPokemonTarget(Pokemon@ pkmn) const", asMETHOD(CreatureLib::Battling::ExecutingAttack, IsCreatureTarget), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("ExecutingMove", "Pokemon@ get_User() const property", asMETHOD(CreatureLib::Battling::ExecutingAttack, GetUser), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("ExecutingMove", "LearnedMove@ get_Move() const property", asMETHOD(CreatureLib::Battling::ExecutingAttack, GetAttack), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); }