Implements Weather
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-18 15:35:01 +02:00
parent caa353191d
commit c6d31e09a1
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 67 additions and 24 deletions

View File

@ -3,13 +3,36 @@
#include <CreatureLib/Battling/Models/Battle.hpp>
#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<CreatureLib::Battling::BattleParty*>& 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<ScriptCategory>(PkmnScriptCategory::Weather), name);
}
void ClearWeather() {
_weatherScript->OnRemove();
delete _weatherScript;
_weatherScript = nullptr;
}
const Arbutils::CaseInsensitiveConstString& GetWeatherName() noexcept { return _weatherScript->GetName(); }
void GetActiveScripts(List<CreatureLib::Battling::ScriptWrapper>& scripts) override {
CreatureLib::Battling::Battle::GetActiveScripts(scripts);
scripts.Append(CreatureLib::Battling::ScriptWrapper(&_weatherScript));
}
};
}

View File

@ -0,0 +1,8 @@
#ifndef PKMNLIB_PKMNSCRIPTCATEGORY_HPP
#define PKMNLIB_PKMNSCRIPTCATEGORY_HPP
#include <Arbutils/Enum.hpp>
#include <CreatureLib/Battling/ScriptHandling/ScriptCategory.hpp>
ENUM_WITH_START_VALUE(PkmnScriptCategory, uint8_t, ((uint8_t)ScriptCategoryHelper::Highest()) + 1, Weather)
#endif // PKMNLIB_PKMNSCRIPTCATEGORY_HPP

View File

@ -1,7 +1,7 @@
#include "RegisterBattleClass.hpp"
#include <CreatureLib/Battling/Models/Battle.hpp>
#include <cassert>
#include <cstdint>
#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);
}