diff --git a/src/Battling/Battle/Battle.hpp b/src/Battling/Battle/Battle.hpp index c69bd07..44ea342 100644 --- a/src/Battling/Battle/Battle.hpp +++ b/src/Battling/Battle/Battle.hpp @@ -3,13 +3,36 @@ #include #include "../Library/BattleLibrary.hpp" +#include "../PkmnScriptCategory.hpp" namespace PkmnLib::Battling { class Battle : public CreatureLib::Battling::Battle { + private: + CreatureLib::Battling::Script* _weatherScript = nullptr; + public: Battle(const BattleLibrary* library, const List& 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) { + if (_weatherScript != nullptr) { + _weatherScript->OnRemove(); + delete _weatherScript; + } + _weatherScript = _library->LoadScript(static_cast(PkmnScriptCategory::Weather), name); + } + void ClearWeather() { + _weatherScript->OnRemove(); + delete _weatherScript; + _weatherScript = nullptr; + } + const Arbutils::CaseInsensitiveConstString& GetWeatherName() noexcept { return _weatherScript->GetName(); } + + void GetActiveScripts(List& scripts) override { + CreatureLib::Battling::Battle::GetActiveScripts(scripts); + scripts.Append(CreatureLib::Battling::ScriptWrapper(&_weatherScript)); + } }; } diff --git a/src/Battling/PkmnScriptCategory.hpp b/src/Battling/PkmnScriptCategory.hpp new file mode 100644 index 0000000..c325d45 --- /dev/null +++ b/src/Battling/PkmnScriptCategory.hpp @@ -0,0 +1,8 @@ +#ifndef PKMNLIB_PKMNSCRIPTCATEGORY_HPP +#define PKMNLIB_PKMNSCRIPTCATEGORY_HPP +#include +#include + +ENUM_WITH_START_VALUE(PkmnScriptCategory, uint8_t, ((uint8_t)ScriptCategoryHelper::Highest()) + 1, Weather) + +#endif // PKMNLIB_PKMNSCRIPTCATEGORY_HPP diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp index d147743..2975ea5 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp @@ -1,7 +1,7 @@ #include "RegisterBattleClass.hpp" #include -#include #include +#include "../../../../Battling/Battle/Battle.hpp" void RegisterBattleClass::Register(asIScriptEngine* engine) { RegisterChoiceQueue(engine); @@ -11,61 +11,73 @@ void RegisterBattleClass::Register(asIScriptEngine* engine) { void RegisterBattleClass::RegisterChoiceQueue(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterObjectType("ChoiceQueue", 0, asOBJ_REF | asOBJ_NOCOUNT); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("ChoiceQueue", "bool MovePokemonChoiceNext(Pokemon@ target)", asMETHOD(CreatureLib::Battling::ChoiceQueue, MoveCreatureChoiceNext), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("ChoiceQueue", "const BaseTurnChoice@ Peek() const", asMETHOD(CreatureLib::Battling::ChoiceQueue, Peek), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); } void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterObjectType("BattleRandom", 0, asOBJ_REF | asOBJ_NOCOUNT); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("BattleRandom", "bool EffectChance(float chance, ExecutingMove@ move, Pokemon@ target )", asMETHOD(CreatureLib::Battling::BattleRandom, EffectChance), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("BattleRandom", "int Get()", asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (), int32_t), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("BattleRandom", "int Get(int max)", asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (int32_t), int32_t), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("BattleRandom", "int Get(int min, int max)", asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (int32_t, int32_t), int32_t), asCALL_THISCALL); - assert(r >= 0); + Assert(r >= 0); } void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterObjectType("Battle", 0, asOBJ_REF | asOBJ_NOCOUNT); - assert(r >= 0); + Assert(r >= 0); r = engine->RegisterObjectMethod("Battle", "const BattleLibrary@ get_Library() const property", - asMETHOD(CreatureLib::Battling::Battle, GetLibrary), asCALL_THISCALL); - assert(r >= 0); + asMETHOD(PkmnLib::Battling::Battle, GetLibrary), asCALL_THISCALL); + Assert(r >= 0); r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)", - asMETHOD(CreatureLib::Battling::Battle, CanUse), asCALL_THISCALL); - assert(r >= 0); + asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL); + Assert(r >= 0); r = engine->RegisterObjectMethod("Battle", "bool get_CanFlee() const property", - asMETHOD(CreatureLib::Battling::Battle, CanFlee), asCALL_THISCALL); - assert(r >= 0); + asMETHOD(PkmnLib::Battling::Battle, CanFlee), asCALL_THISCALL); + Assert(r >= 0); r = engine->RegisterObjectMethod("Battle", "BattleRandom@ get_Random() const property", - asMETHOD(CreatureLib::Battling::Battle, GetRandom), asCALL_THISCALL); - assert(r >= 0); + asMETHOD(PkmnLib::Battling::Battle, GetRandom), asCALL_THISCALL); + Assert(r >= 0); r = engine->RegisterObjectMethod("Battle", "ChoiceQueue@ get_TurnQueue() const property", - asMETHOD(CreatureLib::Battling::Battle, GetCurrentTurnQueue), asCALL_THISCALL); - assert(r >= 0); + asMETHOD(PkmnLib::Battling::Battle, GetCurrentTurnQueue), asCALL_THISCALL); + Assert(r >= 0); r = engine->RegisterObjectMethod( "Battle", "void AddVolatile(const constString &in name) const", - asMETHODPR(CreatureLib::Battling::Battle, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL); - assert(r >= 0); + asMETHODPR(PkmnLib::Battling::Battle, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL); + Assert(r >= 0); r = engine->RegisterObjectMethod( "Battle", "void RemoveVolatile(const constString &in name) const", - asMETHODPR(CreatureLib::Battling::Battle, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL); - assert(r >= 0); + asMETHODPR(PkmnLib::Battling::Battle, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL); + Assert(r >= 0); + r = engine->RegisterObjectMethod("Battle", "void SetWeather(const constString &in name) const", + asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ConstString&), void), + asCALL_THISCALL); + Assert(r >= 0); + r = engine->RegisterObjectMethod("Battle", "void ClearWeather(const constString &in name) const", + asMETHODPR(PkmnLib::Battling::Battle, ClearWeather, (), void), asCALL_THISCALL); + Assert(r >= 0); + r = engine->RegisterObjectMethod( + "Battle", "const constString& GetWeatherName() const", + asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const Arbutils::CaseInsensitiveConstString&), + asCALL_THISCALL); + Assert(r >= 0); }