Added LearnedAttack C Interface.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-04 13:36:13 +02:00
parent aee5bcb088
commit 91bea44113
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 43 additions and 17 deletions

View File

@ -0,0 +1,22 @@
#include "../../src/Battling/Models/LearnedAttack.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Battling;
export uint8_t CreatureLib_LearnedAttack_Construct(LearnedAttack*& out, CreatureLib::Library::AttackData* attack,
uint8_t maxUses, AttackLearnMethod learnMethod) {
Try(out = new LearnedAttack(attack, maxUses, learnMethod);)
}
export void CreatureLib_LearnedAttack_Destruct(LearnedAttack* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
SIMPLE_GET_FUNC(LearnedAttack, GetAttack, const CreatureLib::Library::AttackData*);
SIMPLE_GET_FUNC(LearnedAttack, GetMaxUses, uint8_t);
SIMPLE_GET_FUNC(LearnedAttack, GetRemainingUses, uint8_t);
SIMPLE_GET_FUNC(LearnedAttack, GetLearnMethod, AttackLearnMethod);
export bool CreatureLib_LearnedAttack_TryUse(LearnedAttack* p, uint8_t uses) { return p->TryUse(uses); }
export void CreatureLib_LearnedAttack_DecreaseUses(LearnedAttack* p, uint8_t uses) { p->DecreaseUses(uses); }
export void CreatureLib_LearnedAttack_RestoreUses(LearnedAttack* p, uint8_t uses) { p->RestoreUses(uses); }
export void CreatureLib_LearnedAttack_RestoreAllUses(LearnedAttack* p) { p->RestoreAllUses(); }

View File

@ -8,27 +8,31 @@ CreatureLib::Battling::LearnedAttack::LearnedAttack(CreatureLib::Library::Attack
CreatureLib::Battling::LearnedAttack::LearnedAttack(const CreatureLib::Library::AttackData* attack, CreatureLib::Battling::LearnedAttack::LearnedAttack(const CreatureLib::Library::AttackData* attack,
AttackLearnMethod learnMethod) AttackLearnMethod learnMethod)
: _attack(attack), _maxUses(attack->GetBaseUsages()), _remainingUses(_maxUses), _learnMethod(learnMethod) {} : _attack(attack), _maxUses(attack->GetBaseUsages()), _remainingUses(_maxUses), _learnMethod(learnMethod) {
AssertNotNull(_attack)
}
const CreatureLib::Library::AttackData* CreatureLib::Battling::LearnedAttack::GetAttack() const { return _attack; } const CreatureLib::Library::AttackData* CreatureLib::Battling::LearnedAttack::GetAttack() const noexcept {
return _attack;
}
uint8_t CreatureLib::Battling::LearnedAttack::GetMaxUses() const { return _maxUses; } uint8_t CreatureLib::Battling::LearnedAttack::GetMaxUses() const noexcept { return _maxUses; }
uint8_t CreatureLib::Battling::LearnedAttack::GetRemainingUses() const { return _remainingUses; } uint8_t CreatureLib::Battling::LearnedAttack::GetRemainingUses() const noexcept { return _remainingUses; }
CreatureLib::Battling::AttackLearnMethod CreatureLib::Battling::LearnedAttack::GetLearnMethod() const { CreatureLib::Battling::AttackLearnMethod CreatureLib::Battling::LearnedAttack::GetLearnMethod() const noexcept {
return _learnMethod; return _learnMethod;
} }
bool CreatureLib::Battling::LearnedAttack::TryUse(uint8_t uses) { bool CreatureLib::Battling::LearnedAttack::TryUse(uint8_t uses) noexcept {
if (uses > _remainingUses) if (uses > _remainingUses)
return false; return false;
_remainingUses -= uses; _remainingUses -= uses;
return true; return true;
} }
void CreatureLib::Battling::LearnedAttack::DecreaseUses(uint8_t amount) { _remainingUses -= amount; } void CreatureLib::Battling::LearnedAttack::DecreaseUses(uint8_t amount) noexcept { _remainingUses -= amount; }
void CreatureLib::Battling::LearnedAttack::RestoreUses(uint8_t amount) { _remainingUses += amount; } void CreatureLib::Battling::LearnedAttack::RestoreUses(uint8_t amount) noexcept { _remainingUses += amount; }
void CreatureLib::Battling::LearnedAttack::RestoreUses() { _remainingUses = _maxUses; } void CreatureLib::Battling::LearnedAttack::RestoreAllUses() noexcept { _remainingUses = _maxUses; }

View File

@ -17,15 +17,15 @@ namespace CreatureLib::Battling {
virtual ~LearnedAttack() = default; virtual ~LearnedAttack() = default;
const Library::AttackData* GetAttack() const; const Library::AttackData* GetAttack() const noexcept;
uint8_t GetMaxUses() const; uint8_t GetMaxUses() const noexcept;
uint8_t GetRemainingUses() const; uint8_t GetRemainingUses() const noexcept;
AttackLearnMethod GetLearnMethod() const; AttackLearnMethod GetLearnMethod() const noexcept;
virtual bool TryUse(uint8_t uses); virtual bool TryUse(uint8_t uses) noexcept;
virtual void DecreaseUses(uint8_t amount); virtual void DecreaseUses(uint8_t amount) noexcept;
virtual void RestoreUses(uint8_t amount); virtual void RestoreUses(uint8_t amount) noexcept;
virtual void RestoreUses(); virtual void RestoreAllUses() noexcept;
}; };
} }