Adds Angelscript interface for Battle History.
continuous-integration/drone/push Build is failing Details
continuous-integration/drone Build is passing Details

This commit is contained in:
Deukhoofd 2021-10-23 18:16:17 +02:00
parent 3ca665cb62
commit d172273b11
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 85 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include "ContextPool.hpp" #include "ContextPool.hpp"
#include "TypeRegistry/BasicScriptClass.hpp" #include "TypeRegistry/BasicScriptClass.hpp"
#include "TypeRegistry/Battling/RegisterBattleClass.hpp" #include "TypeRegistry/Battling/RegisterBattleClass.hpp"
#include "TypeRegistry/Battling/RegisterBattleHistory.hpp"
#include "TypeRegistry/Battling/RegisterBattleLibrary.hpp" #include "TypeRegistry/Battling/RegisterBattleLibrary.hpp"
#include "TypeRegistry/Battling/RegisterExecutingAttack.hpp" #include "TypeRegistry/Battling/RegisterExecutingAttack.hpp"
#include "TypeRegistry/Battling/RegisterParty.hpp" #include "TypeRegistry/Battling/RegisterParty.hpp"
@ -148,6 +149,7 @@ void AngelScriptResolver::RegisterTypes() {
RegisterExecutingAttack::Register(_engine); RegisterExecutingAttack::Register(_engine);
RegisterTurnChoices::Register(_engine); RegisterTurnChoices::Register(_engine);
RegisterBattleLibrary::Register(_engine); RegisterBattleLibrary::Register(_engine);
RegisterBattleHistory::Register(_engine);
RegisterBattleClass::Register(_engine); RegisterBattleClass::Register(_engine);
// Register base script // Register base script

View File

@ -112,6 +112,8 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
GetSides); GetSides);
REGISTER_GETTER("Battle", "narray<BattleParty>@ get_Parties() const property", CreatureLib::Battling::Battle, REGISTER_GETTER("Battle", "narray<BattleParty>@ get_Parties() const property", CreatureLib::Battling::Battle,
GetParties); GetParties);
REGISTER_GETTER("Battle", "BattleHistory@ get_History() const property", CreatureLib::Battling::Battle,
GetHistory);
auto r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)", auto r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)",
asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL); asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL);

View File

@ -0,0 +1,68 @@
#include "RegisterBattleHistory.hpp"
#include <CreatureLib/Battling/History/HistoryElements/AttackUseHistory.hpp>
#include <CreatureLib/Battling/History/HistoryElements/DamageHistory.hpp>
#include <CreatureLib/Battling/History/HistoryElements/HistoryElement.hpp>
#include "../HelperFile.hpp"
#include "../RefCast.hpp"
#include "CreatureLib/Battling/History/HistoryHolder.hpp"
using namespace CreatureLib::Battling;
void RegisterBattleHistory::Register(asIScriptEngine* engine) {
REGISTER_ENUM(HistoryElementKind, "HistoryElementKind");
RegisterHistoryElement(engine);
RegisterHistoryHolder(engine);
}
template <typename T> void RegisterHistoryElementType(asIScriptEngine* engine, const std::string& type) {
Ensure(engine->RegisterObjectType(type.c_str(), 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
RegisterGetter<HistoryElement, ArbUt::OptionalBorrowedPtr<HistoryElement>, &HistoryElement::GetPrevious>(
engine, type.c_str(), "const HistoryElement@ get_Previous() const property");
RegisterGetter<HistoryElement, HistoryElementKind, &HistoryElement::GetKind>(
engine, type.c_str(), "HistoryElementKind get_Kind() const property");
RegisterGetter<HistoryElement, u32, &HistoryElement::GetTurnNumber>(engine, type.c_str(),
"uint32 get_TurnNumber() const property");
Ensure(engine->RegisterObjectMethod("HistoryElement", ("const " + type + "@opCast() const").c_str(),
asFUNCTION((refCast<CreatureLib::Battling::HistoryElement, T>)),
asCALL_CDECL_OBJLAST) >= 0);
Ensure(engine->RegisterObjectMethod(type.c_str(), "const HistoryElement@ opImplCast() const",
asFUNCTION((refCast<T, CreatureLib::Battling::HistoryElement>)),
asCALL_CDECL_OBJLAST))
}
BORROWED_PTR_GETTER_FUNC(DamageHistory, Creature, GetTarget);
BORROWED_PTR_GETTER_FUNC(AttackUseHistory, const ExecutingAttack, GetAttack);
void RegisterBattleHistory::RegisterHistoryElement(asIScriptEngine* engine) {
Ensure(engine->RegisterObjectType("HistoryElement", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
RegisterHistoryElementType<DamageHistory>(engine, "DamageHistory");
Ensure(engine->RegisterObjectMethod("DamageHistory", "Pokemon@ get_Target() const property",
asFunctionPtr(GetTargetWrapper), asCALL_CDECL_OBJFIRST) >= 0);
Ensure(engine->RegisterObjectMethod("DamageHistory", "uint get_Amount() const property",
asMETHOD(DamageHistory, GetAmount), asCALL_THISCALL) >= 0);
Ensure(engine->RegisterObjectMethod("DamageHistory", "DamageSource get_Source() const property",
asMETHOD(DamageHistory, GetDamageSource), asCALL_THISCALL) >= 0);
RegisterHistoryElementType<AttackUseHistory>(engine, "AttackUseHistory");
Ensure(engine->RegisterObjectMethod("AttackUseHistory", "const ExecutingMove@ get_Move() const property",
asFunctionPtr(GetAttackWrapper), asCALL_CDECL_OBJFIRST) >= 0);
}
OPTIONAL_BORROWED_PTR_GETTER_FUNC(HistoryHolder, const HistoryElement, GetLastUsedAttack);
const HistoryElement* GetLastDamageOnTargetWrapper(const HistoryHolder* holder, const Creature* c) {
return holder->GetLastDamageOnTarget(c).GetValue();
}
void RegisterBattleHistory::RegisterHistoryHolder(asIScriptEngine* engine) {
Ensure(engine->RegisterObjectType("BattleHistory", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
REGISTER_GETTER("BattleHistory", "const HistoryElement@ get_TopElement() const property", HistoryHolder,
GetTopElement);
Ensure(engine->RegisterObjectMethod("BattleHistory", "const AttackUseHistory@ GetLastUsedAttack() const",
asFunctionPtr(GetLastUsedAttackWrapper), asCALL_CDECL_OBJFIRST) >= 0);
Ensure(engine->RegisterObjectMethod("BattleHistory",
"const DamageHistory@ GetLastDamageOnTarget(Pokemon@ target) const",
asFunctionPtr(GetLastDamageOnTargetWrapper), asCALL_CDECL_OBJFIRST) >= 0);
}

View File

@ -0,0 +1,13 @@
#ifndef PKMNLIB_REGISTERBATTLEHISTORY_HPP
#define PKMNLIB_REGISTERBATTLEHISTORY_HPP
#include <angelscript.h>
class RegisterBattleHistory {
static void RegisterHistoryElement(asIScriptEngine* engine);
static void RegisterHistoryHolder(asIScriptEngine* engine);
public:
static void Register(asIScriptEngine* engine);
};
#endif // PKMNLIB_REGISTERBATTLEHISTORY_HPP