Update to latest Arbutils.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-12-13 12:32:52 +01:00
parent ecf8582c59
commit bbb2691b91
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
18 changed files with 152 additions and 164 deletions

View File

@ -83,7 +83,7 @@ float PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling:
PKMN_HOOK(OverrideCriticalModifier, attack, attack, target, hitIndex, &critModifier);
mod *= critModifier;
}
Assert(attack->GetUser()->GetBattle().GetValue());
Ensure(attack->GetUser()->GetBattle().GetValue());
float randPercentage = 85 + attack->GetUser()->GetBattle().GetValue()->GetRandom()->Get(0, 16);
mod *= randPercentage / 100.0;
if (attack->GetUser()->HasType(hitData.GetType())) {

View File

@ -20,9 +20,8 @@ void PkmnLib::Battling::ExperienceLibrary::HandleExperienceGain(
const std::unordered_set<ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>>& opponents) const {
auto fainted = dynamic_cast<Pokemon*>(faintedMon);
AssertNotNull(fainted);
EnsureNotNull(fainted);
auto& forme = fainted->GetForme();
AssertNotNull(forme);
auto expGain = forme->GetBaseExperience();
auto level = fainted->GetLevel();

View File

@ -7,7 +7,7 @@ bool PkmnLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::Executing
CreatureLib::Battling::Creature* target, uint8_t hit) const {
uint8_t critStage = 0;
PKMN_HOOK(ModifyCriticalStage, attack, attack, target, hit, &critStage);
Assert(target->GetBattle().HasValue());
Ensure(target->GetBattle().HasValue());
auto rand = target->GetBattle().GetValue()->GetRandom();
switch (critStage) {
case 0: return rand->Get(24) == 0;

View File

@ -5,8 +5,6 @@
auto aggregator = source->GetScriptIterator(); \
while (aggregator.HasNext()) { \
auto next = aggregator.GetNext(); \
if (next == nullptr) \
continue; \
auto castNext = next.ForceAs<PkmnLib::Battling::PkmnScript>(); \
castNext->hookName(__VA_ARGS__); \
} \

View File

@ -49,7 +49,6 @@ namespace PkmnLib::Battling {
err << "Invalid forme '" << _forme << "' for species '" << _forme << "'.";
throw ArbUt::Exception(err.str());
}
AssertNotNull(forme);
CreatureLib::Library::TalentIndex ability;
if (this->_ability.IsEmpty()) {
ability = forme.value()->GetRandomTalent(rand);
@ -79,10 +78,7 @@ namespace PkmnLib::Battling {
for (size_t i = 0; i < _attacks.Count(); i++) {
auto& kv = _attacks[i];
auto move = kv.Move;
if (move != nullptr)
attacks[i] = new LearnedMove(move, kv.LearnMethod);
else
attacks[i] = nullptr;
attacks[i] = new LearnedMove(move, kv.LearnMethod);
}
auto ivs = CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31>(_ivHp, _ivAttack, _ivDefense, _ivSpAtt,
_ivSpDef, _ivSpeed);
@ -156,7 +152,6 @@ namespace PkmnLib::Battling {
if (_currentMove >= _library->GetSettings()->GetMaximalAttacks()) {
throw ArbUt::Exception("This pokemon already has the maximal allowed moves.");
}
Assert(v.value() != nullptr);
_attacks.Append(ToLearnMethod(v.value(), method));
return *this;
}

View File

@ -111,7 +111,7 @@ void AngelScriptResolver::RegisterTypes() {
RegisterBattleClass::Register(_engine);
[[maybe_unused]] int r = _engine->RegisterObjectMethod("Pokemon", "const Battle@ get_Battle() const property",
asFUNCTION(GetBattleWrapper), asCALL_CDECL_OBJFIRST);
assert(r >= 0);
Ensure(r >= 0);
// Register base script
BasicScriptClass::Register(_engine);
@ -223,7 +223,7 @@ void AngelScriptResolver::WriteByteCodeToFile(const char* file, bool stripDebugI
// Open file in write binary mode.
wFile = fopen(file, "wb");
// Ensure we opened it.
AssertNotNull(wFile);
EnsureNotNull(wFile);
// Save the initial position, as we need to write here later.
fpos_t startPos;
fgetpos(wFile, &startPos);
@ -248,7 +248,7 @@ void AngelScriptResolver::WriteByteCodeToFile(const char* file, bool stripDebugI
fwrite(byteCodeSizeArr, sizeof(uint64_t), 1, wFile);
// Close the file
Assert(fclose(wFile) == 0);
Ensure(fclose(wFile) == 0);
delete stream;
}
void AngelScriptResolver::LoadByteCodeFromFile(const char* file) {
@ -256,7 +256,7 @@ void AngelScriptResolver::LoadByteCodeFromFile(const char* file) {
// Open the file in read binary mode
rFile = fopen(file, "rb");
// Ensure it opened
AssertNotNull(rFile);
EnsureNotNull(rFile);
// the first 8 bytes are position of the types database, everything before that is the angelscript byte code.
uint64_t byteCodeSize[]{0};
fread(byteCodeSize, sizeof(uint64_t), 1, rFile);
@ -265,13 +265,13 @@ void AngelScriptResolver::LoadByteCodeFromFile(const char* file) {
// And load the angelscript byte code.
int result = _mainModule->LoadByteCode(stream);
// Ensure we succeeded in this.
Assert(result == asSUCCESS);
Ensure(result == asSUCCESS);
// Begin loading the type database
auto types = stream->ReadTypes();
InitializeByteCode(types);
Assert(fclose(rFile) == 0);
Ensure(fclose(rFile) == 0);
delete stream;
}
uint8_t* AngelScriptResolver::WriteByteCodeToMemory(size_t& size, bool stripDebugInfo) {
@ -279,7 +279,7 @@ uint8_t* AngelScriptResolver::WriteByteCodeToMemory(size_t& size, bool stripDebu
size_t byteCodeSize[]{0};
stream->Write(byteCodeSize, sizeof(uint64_t));
auto result = _mainModule->SaveByteCode(stream, stripDebugInfo);
Assert(result == asSUCCESS);
Ensure(result == asSUCCESS);
byteCodeSize[0] = (uint64_t)stream->GetWrittenSize();
stream->WriteTypes(_typeDatabase);
stream->WriteToPosition(byteCodeSize, sizeof(uint64_t), 0);
@ -297,7 +297,7 @@ void AngelScriptResolver::LoadByteCodeFromMemory(uint8_t* byte, size_t size) {
// And load the angelscript byte code.
int result = _mainModule->LoadByteCode(stream);
// Ensure we succeeded in this.
Assert(result == asSUCCESS);
Ensure(result == asSUCCESS);
// Begin loading the type database
auto types = stream->ReadTypes();

View File

@ -58,15 +58,15 @@ public:
void RegisterType(const char* type) {
int r = _engine->RegisterObjectType(type, 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
}
void RegisterTypeMethod(const char* type, const char* decl, void*(func)(void*)) {
int r = _engine->RegisterObjectMethod(type, decl, asFunctionPtr(func), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
}
void RegisterGlobalMethod(const char*, void*(func)(void*)) {
auto r = _engine->RegisterGlobalFunction("decl", asFunctionPtr(func), asCALL_CDECL);
Assert(r >= 0);
Ensure(r >= 0);
}
asITypeInfo* GetBaseType(const ArbUt::StringView& name) {

View File

@ -45,5 +45,5 @@ shared abstract class PkmnScript {
void DoesShareExperience(Pokemon@ faintedMon, Pokemon@ winningMon, bool& shareExperience){};
}
)");
Assert(r >= 0);
Ensure(r >= 0);
}

View File

@ -11,75 +11,75 @@ 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);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ChoiceQueue", "bool MovePokemonChoiceNext(Pokemon@ target)",
asMETHOD(CreatureLib::Battling::ChoiceQueue, MoveCreatureChoiceNext),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ChoiceQueue", "const BaseTurnChoice@ Peek() const",
asMETHOD(CreatureLib::Battling::ChoiceQueue, Peek), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
}
void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("BattleRandom", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BattleRandom",
"bool EffectChance(float chance, ExecutingMove@ move, Pokemon@ target )",
asMETHOD(CreatureLib::Battling::BattleRandom, EffectChance), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BattleRandom", "int Get()",
asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (), int32_t),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BattleRandom", "int Get(int max)",
asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (int32_t), int32_t),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(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);
Ensure(r >= 0);
}
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Battle, CreatureLib::Battling::ChoiceQueue, GetCurrentTurnQueue);
void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Battle", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "const BattleLibrary@ get_Library() const property",
asMETHOD(PkmnLib::Battling::Battle, GetLibrary), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)",
asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "bool get_CanFlee() const property",
asMETHOD(PkmnLib::Battling::Battle, CanFlee), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "BattleRandom@ get_Random() const property",
asMETHOD(PkmnLib::Battling::Battle, GetRandom), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "ChoiceQueue@ get_TurnQueue() const property",
asFUNCTION(GetCurrentTurnQueueWrapper), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "void AddVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Battle, AddVolatileScript, (const ArbUt::StringView&), void), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "void RemoveVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Battle, RemoveVolatileScript, (const ArbUt::BasicStringView&), void),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "void SetWeather(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ArbUt::StringView&), void), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "void ClearWeather(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Battle, ClearWeather, (), void), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "const constString& GetWeatherName() const",
asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::StringView&), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
}

View File

@ -15,42 +15,42 @@ GetHitDataWrapper(CreatureLib::Battling::ExecutingAttack* obj, CreatureLib::Batt
void RegisterExecutingAttack::RegisterHitData(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("HitData", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "bool get_IsCritical() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, IsCritical),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "uint8 get_BasePower() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetBasePower),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "float get_Effectiveness() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetEffectiveness),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "uint get_Damage() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetDamage),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "uint8 get_Type() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetType),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
}
void RegisterExecutingAttack::RegisterExecutingAttackType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("ExecutingMove", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "HitData@ GetHitData(Pokemon@ target, uint8 hit) const",
asFUNCTION(GetHitDataWrapper), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "bool IsPokemonTarget(Pokemon@ pkmn) const",
asMETHOD(CreatureLib::Battling::ExecutingAttack, IsCreatureTarget),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "Pokemon@ get_User() const property", asFUNCTION(GetUserWrapper),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "LearnedMove@ get_Move() const property",
asFUNCTION(GetAttackWrapper), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
}

View File

@ -18,7 +18,7 @@ void RegisterPokemonClass::Register(asIScriptEngine* engine) {
void RegisterPokemonClass::RegisterDamageSource(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("DamageSource");
Assert(r >= 0);
Ensure(r >= 0);
for (auto v : CreatureLib::Battling::DamageSourceHelper::GetValues()) {
r = engine->RegisterEnumValue("DamageSource", CreatureLib::Battling::DamageSourceHelper::ToString(v).c_str(),
(int)v);
@ -27,16 +27,16 @@ void RegisterPokemonClass::RegisterDamageSource(asIScriptEngine* engine) {
r = engine->RegisterEnumValue("DamageSource", PkmnDamageSourceHelper::ToString(v).c_str(), (int)v);
}
Assert(r >= 0);
Ensure(r >= 0);
}
void RegisterPokemonClass::RegisterMoveLearnMethod(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("MoveLearnMethod");
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("MoveLearnMethod", "Unknown", (int)CreatureLib::Battling::AttackLearnMethod::Unknown);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("MoveLearnMethod", "Level", (int)CreatureLib::Battling::AttackLearnMethod::Level);
Assert(r >= 0);
Ensure(r >= 0);
}
ENUM__SIZE_WRAPPER(LearnedMove_LearnMethodWrapper, CreatureLib::Battling::LearnedAttack, GetLearnMethod)
@ -44,19 +44,19 @@ BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::LearnedAttack, const CreatureLib
void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("LearnedMove", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("LearnedMove", "const MoveData@ get_MoveData() const property",
asFUNCTION(GetAttackWrapper), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_MaxUses() const property",
asMETHOD(CreatureLib::Battling::LearnedAttack, GetMaxUses), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_RemainingUses() const property",
asMETHOD(CreatureLib::Battling::LearnedAttack, GetRemainingUses), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("LearnedMove", "Gender get_LearnMethod() const property",
asFUNCTION(LearnedMove_LearnMethodWrapper), asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
}
ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender)
@ -87,101 +87,101 @@ OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib:
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_Species() const property",
asFUNCTION(GetSpeciesWrapper), asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Forme@ get_Forme() const property", asFUNCTION(GetFormeWrapper),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Level() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetLevel), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_Experience() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetExperience), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "Gender get_Gender() const property", asFUNCTION(Pkmn_GenderWrapper),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Coloring() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetColoring), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "bool get_Shiny() const property",
asMETHOD(PkmnLib::Battling::Pokemon, IsShiny), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property",
asFUNCTION(GetHeldItemWrapper), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const",
asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"Pokemon", "void SetHeldItem(const string &in name)",
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem, (const ArbUt::BasicStringView&), void), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void SetHeldItem(const Item@ item)",
asMETHODPR(PkmnLib::Battling::Pokemon, SetHeldItem,
(const ArbUt::BorrowedPtr<const CreatureLib::Library::Item>&), void),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_CurrentHealth() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetCurrentHealth), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const string& get_Nickname() const property",
asFUNCTION(NicknameWrapper), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const constString& get_ActiveAbility() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetActiveTalent), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "bool get_IsFainted() const property",
asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const",
asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_MaxHealth() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetMaxHealth), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void Damage(uint32 type, DamageSource source)",
asMETHOD(PkmnLib::Battling::Pokemon, Damage), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void Heal(uint32 type)", asMETHOD(PkmnLib::Battling::Pokemon, Heal),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void OverrideActiveAbility(const string &in ability)",
asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ GetMoves() const", asFUNCTION(GetMoves),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void ChangeStatBoost(Statistic stat, int8 amount)",
asMETHOD(PkmnLib::Battling::Pokemon, ChangeStatBoost), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplaySpecies() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetDisplaySpecies), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplayForme() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetDisplayVariant), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 GetFlatStat(Statistic stat) const",
asMETHOD(PkmnLib::Battling::Pokemon, GetFlatStat), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 GetBoostedStat(Statistic stat) const",
asMETHOD(PkmnLib::Battling::Pokemon, GetBoostedStat), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 GetBaseStat(Statistic stat) const",
asMETHOD(PkmnLib::Battling::Pokemon, GetBaseStat), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "int8 GetStatBoost(Statistic stat) const",
asMETHOD(PkmnLib::Battling::Pokemon, GetStatBoost), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"Pokemon", "void AddVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const ArbUt::StringView&), void), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"Pokemon", "void RemoveVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const ArbUt::BasicStringView&), void),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
}

View File

@ -12,79 +12,79 @@ void RegisterTurnChoices::Register(asIScriptEngine* engine) {
}
void RegisterTurnChoices::RegisterTurnChoiceKindEnum(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("TurnChoiceKind");
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Pass", (int)CreatureLib::Battling::TurnChoiceKind::Pass);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Attack", (int)CreatureLib::Battling::TurnChoiceKind::Attack);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Item", (int)CreatureLib::Battling::TurnChoiceKind::Item);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Switch", (int)CreatureLib::Battling::TurnChoiceKind::Switch);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Flee", (int)CreatureLib::Battling::TurnChoiceKind::Flee);
Assert(r >= 0);
Ensure(r >= 0);
}
void RegisterTurnChoices::RegisterBaseTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("BaseTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BaseTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::BaseTurnChoice, GetKind), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BaseTurnChoice", "Pokemon@ get_User() const property",
asMETHOD(CreatureLib::Battling::BaseTurnChoice, GetUser), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
}
void RegisterTurnChoices::RegisterMoveTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetKind), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "Pokemon@ get_User() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetUser), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "LearnedMove@ get_Move() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetAttack), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "int8 get_Priority() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetPriority), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"BaseTurnChoice", "MoveTurnChoice@ opCast()",
asFUNCTION((refCast<CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::AttackTurnChoice>)),
asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"MoveTurnChoice", "BaseTurnChoice@ opImplCast()",
asFUNCTION((refCast<CreatureLib::Battling::AttackTurnChoice, CreatureLib::Battling::BaseTurnChoice>)),
asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
}
void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("SwitchTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("SwitchTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetKind), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("SwitchTurnChoice", "Pokemon@ get_User() const property",
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetUser), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("SwitchTurnChoice", "Pokemon@ get_NewPokemon() const property",
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetNewCreature),
asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"SwitchTurnChoice", "MoveTurnChoice@ opCast()",
asFUNCTION((refCast<CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::SwitchTurnChoice>)),
asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"SwitchTurnChoice", "BaseTurnChoice@ opImplCast()",
asFUNCTION((refCast<CreatureLib::Battling::AttackTurnChoice, CreatureLib::Battling::SwitchTurnChoice>)),
asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
}

View File

@ -15,41 +15,41 @@ static uint32_t ImplConstStringHashConv(const ArbUt::StringView& s) { return s.G
void ConstStringRegister::Register(asIScriptEngine* engine) {
auto r = engine->RegisterObjectType("constString", sizeof(ArbUt::StringView),
asOBJ_VALUE | asGetTypeTraits<ArbUt::StringView>());
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructConstString),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_CONSTRUCT, "void f(const string &in s)",
asFUNCTION(ConstructConstStringFromStd), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_CONSTRUCT, "void f(const constString &in)",
asFUNCTION(CopyConstructConstString), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectBehaviour("constString", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructConstString),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"constString", "constString &opAssign(const constString &in)",
asMETHODPR(ArbUt::StringView, operator=, (const ArbUt::StringView&), ArbUt::StringView&), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"constString", "bool opEquals(const constString &in) const",
asFUNCTIONPR(ConstStringEquality, (const ArbUt::StringView&, const ArbUt::StringView&), bool),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"constString", "bool opEquals(const string &in) const",
asFUNCTIONPR(ConstStringStdStringEquality, (const ArbUt::StringView&, const std::string&), bool),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("constString", "uint opImplConv()",
asFUNCTIONPR(ImplConstStringHashConv, (const ArbUt::StringView&), uint32_t),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
}

View File

@ -7,35 +7,35 @@ static const ArbUt::StringView& AsString(const CreatureLib::Library::EffectParam
void RegisterEffectParameter::Register(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("EffectParameterType");
Assert(r >= 0);
Ensure(r >= 0);
for (auto val : CreatureLib::Library::EffectParameterTypeHelper::GetValues()) {
r = engine->RegisterEnumValue("EffectParameterType",
CreatureLib::Library::EffectParameterTypeHelper::ToString(val).c_str(), (int)val);
Assert(r >= 0);
Ensure(r >= 0);
}
r = engine->RegisterObjectType("EffectParameter", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectBehaviour("EffectParameter", asBEHAVE_FACTORY, "EffectParameter@ f()",
asFUNCTION(Ref_Factory), asCALL_CDECL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("EffectParameter", "EffectParameterType GetType() const",
asMETHOD(CreatureLib::Library::EffectParameter, GetType), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("EffectParameter", "bool AsBool() const",
asMETHOD(CreatureLib::Library::EffectParameter, AsBool), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("EffectParameter", "int64 AsInt() const",
asMETHOD(CreatureLib::Library::EffectParameter, AsInt), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("EffectParameter", "float AsFloat() const",
asMETHOD(CreatureLib::Library::EffectParameter, AsFloat), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"EffectParameter", "const constString& AsString() const",
asFUNCTIONPR(AsString, (const CreatureLib::Library::EffectParameter*), const ArbUt::StringView&),
asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
Ensure(r >= 0);
}

View File

@ -8,13 +8,13 @@ void RegisterGrowthRateTypes::Register(asIScriptEngine* engine) {
}
void RegisterGrowthRateTypes::RegisterGrowthRateType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("GrowthRate", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("GrowthRate", "uint8 CalculateLevel(uint experience) const",
asMETHOD(CreatureLib::Library::GrowthRate, CalculateLevel), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("GrowthRate", "uint CalculateExperience(uint8 level) const",
asMETHOD(CreatureLib::Library::GrowthRate, CalculateExperience), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
}
static uint8_t CalculateLevel(const CreatureLib::Library::GrowthRateLibrary* obj, const ArbUt::StringView& str,
@ -28,13 +28,13 @@ static uint32_t CalculateExperience(const CreatureLib::Library::GrowthRateLibrar
void RegisterGrowthRateTypes::RegisterGrowthRateLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("GrowthRateLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("GrowthRateLibrary",
"uint8 CalculateLevel(const constString &in growthRate, uint experience) const",
asFUNCTION(CalculateLevel), asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"GrowthRateLibrary", "uint CalculateExperience(const constString &in growthRate, uint8 experience) const",
asFUNCTION(CalculateExperience), asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
}

View File

@ -1,5 +1,4 @@
#include "RegisterMoveTypes.hpp"
#include <Arbutils/Assert.hpp>
#include "../../../../Library/Moves/MoveData.hpp"
#include "../../../../Library/Moves/MoveLibrary.hpp"
@ -12,11 +11,11 @@ void RegisterMoveTypes::Register(asIScriptEngine* engine) {
#define REGISTER_ENUM_VALUE(asName, cName, valueName) \
r = engine->RegisterEnumValue(#asName, #valueName, (int)cName::valueName); \
Assert(r >= 0);
Ensure(r >= 0);
void RegisterMoveTypes::RegisterMoveCategory(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("MoveCategory");
Assert(r >= 0);
Ensure(r >= 0);
REGISTER_ENUM_VALUE(MoveCategory, PkmnLib::Library::MoveCategory, Physical)
REGISTER_ENUM_VALUE(MoveCategory, PkmnLib::Library::MoveCategory, Special)
REGISTER_ENUM_VALUE(MoveCategory, PkmnLib::Library::MoveCategory, Status)
@ -24,7 +23,7 @@ void RegisterMoveTypes::RegisterMoveCategory(asIScriptEngine* engine) {
void RegisterMoveTypes::RegisterMoveTarget(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("MoveTarget");
Assert(r >= 0);
Ensure(r >= 0);
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, Adjacent)
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AdjacentAlly)
REGISTER_ENUM_VALUE(MoveTarget, CreatureLib::Library::AttackTarget, AdjacentAllySelf)
@ -52,41 +51,41 @@ static bool HasFlag(const PkmnLib::Library::MoveData* obj, const ArbUt::BasicStr
void RegisterMoveTypes::RegisterMoveType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveData", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "const constString& get_Name() const property",
asMETHOD(PkmnLib::Library::MoveData, GetName), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_Type() const property",
asMETHOD(PkmnLib::Library::MoveData, GetType), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "MoveCategory get_Category() const property",
asFUNCTION(Move_CategoryWrapper), asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_BasePower() const property",
asMETHOD(PkmnLib::Library::MoveData, GetBasePower), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_Accuracy() const property",
asMETHOD(PkmnLib::Library::MoveData, GetAccuracy), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_BaseUsages() const property",
asMETHOD(PkmnLib::Library::MoveData, GetBaseUsages), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "MoveTarget get_Target() const property",
asFUNCTION(Move_TargetWrapper), asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "int8 get_Priority() const property",
asMETHOD(PkmnLib::Library::MoveData, GetPriority), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "bool HasFlag(const constString &in flag) const", asFUNCTION(HasFlag),
asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
}
void RegisterMoveTypes::RegisterMoveLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveLibrary", "const MoveData@ Get(const constString &in name) const",
asMETHOD(PkmnLib::Library::MoveLibrary, Get), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
}
#undef REGISTER_ENUM_VALUE

View File

@ -9,13 +9,13 @@ static bool GetTypeId(const CreatureLib::Library::TypeLibrary* obj, const ArbUt:
void RegisterTypeLibrary::RegisterTypeLibraryType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("TypeLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("TypeLibrary", "uint8 GetTypeId(const constString &in name) const",
asFUNCTION(GetTypeId), asCALL_CDECL_OBJLAST);
Assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"TypeLibrary", "float GetSingleEffectiveness(uint8 attacking, uint8 defensive) const",
asMETHOD(CreatureLib::Library::TypeLibrary, GetSingleEffectiveness), asCALL_THISCALL);
Assert(r >= 0);
Ensure(r >= 0);
// TODO: Register get full effectiveness method.
}

View File

@ -22,9 +22,7 @@ TEST_CASE("Able to get default forme") {
new PkmnLib::Library::LearnableMoves(100)),
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
auto forme = species->GetDefaultForme();
REQUIRE(forme != nullptr);
[[maybe_unused]] auto forme = species->GetDefaultForme();
delete species;
}
@ -38,7 +36,6 @@ TEST_CASE("Able to get default forme name") {
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc});
auto forme = species->GetDefaultForme();
REQUIRE(forme != nullptr);
REQUIRE(forme->GetName() == "default");
delete species;