C interface for Battle Random.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-04 18:24:59 +02:00
parent 3dd5aeffd8
commit e2675d06fb
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 27 additions and 6 deletions

View File

@ -0,0 +1,20 @@
#include "../../src/Battling/Models/BattleRandom.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Battling;
export BattleRandom* CreatureLib_BattleRandom_Construct() { return new BattleRandom(); }
export BattleRandom* CreatureLib_BattleRandom_ConstructWithSeed(uint_fast32_t seed) { return new BattleRandom(seed); }
export void CreatureLib_BattleRandom_Destruct(BattleRandom* p) { delete p; }
export uint8_t CreatureLib_BattleRandom_EffectChance(bool& out, BattleRandom* p, float chance, ExecutingAttack* attack,
Creature* target) {
Try(out = p->EffectChance(chance, attack, target);)
}
export int32_t CreatureLib_BattleRandom_Get(BattleRandom* p) { return p->Get(); }
export int32_t CreatureLib_BattleRandom_GetMax(BattleRandom* p, int32_t max) { return p->Get(max); }
export int32_t CreatureLib_BattleRandom_GetMinMax(BattleRandom* p, int32_t min, int32_t max) {
return p->Get(min, max);
}
export uint_fast32_t CreatureLib_BattleRandom_GetSeed(BattleRandom* p) { return p->GetSeed(); }

View File

@ -12,14 +12,15 @@ namespace CreatureLib::Battling {
Arbutils::Random _random; Arbutils::Random _random;
public: public:
BattleRandom() : _random() {} BattleRandom() noexcept : _random() {}
BattleRandom(int32_t seed) : _random(seed) {} BattleRandom(uint_fast32_t seed) noexcept : _random(seed) {}
bool EffectChance(float chance, ExecutingAttack* attack, Creature* target); bool EffectChance(float chance, ExecutingAttack* attack, Creature* target);
int32_t Get() { return _random.Get(); } int32_t Get() noexcept { return _random.Get(); }
int32_t Get(int32_t max) { return _random.Get(max); } int32_t Get(int32_t max) noexcept { return _random.Get(max); }
int32_t Get(int32_t min, int32_t max) { return _random.Get(min, max); } int32_t Get(int32_t min, int32_t max) noexcept { return _random.Get(min, max); }
Arbutils::Random& GetRNG() { return _random; } Arbutils::Random& GetRNG() noexcept { return _random; }
uint_fast32_t GetSeed() const noexcept { return _random.GetSeed(); }
}; };
} }