Moved Creature types to creature itself, instead of using the variant types.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-06-05 16:38:27 +02:00
parent 3c5b3d5c03
commit 9e7607338f
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
7 changed files with 13 additions and 13 deletions

View File

@ -47,8 +47,6 @@ SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattle, Battle*);
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattleSide, BattleSide*); SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattleSide, BattleSide*);
SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool); SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool);
export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().c_str(); } export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().c_str(); }
export size_t CreatureLib_Creature_GetTypesCount(Creature* p) { return p->GetTypes().Count(); }
export const uint8_t* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().RawData(); }
export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); } export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); }
SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t); SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t);
export uint8_t CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { Try(p->ChangeLevelBy(level);) } export uint8_t CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { Try(p->ChangeLevelBy(level);) }

View File

@ -34,5 +34,5 @@ export uint8_t CreatureLib_TypeLibrary_GetSingleEffectiveness(float& out, TypeLi
export uint8_t CreatureLib_TypeLibrary_GetEffectiveness(float& out, TypeLibrary* p, uint8_t attacking, export uint8_t CreatureLib_TypeLibrary_GetEffectiveness(float& out, TypeLibrary* p, uint8_t attacking,
uint8_t defensive[], size_t defensiveCount) { uint8_t defensive[], size_t defensiveCount) {
Try(out = p->GetEffectiveness(attacking, ArbUt::List<uint8_t>(defensive, defensive + defensiveCount));) Try(out = p->GetEffectiveness(attacking, std::unordered_set<uint8_t>(defensive, defensive + defensiveCount));)
} }

View File

@ -1,5 +1,6 @@
#include "TurnHandler.hpp" #include "TurnHandler.hpp"
#include <Arbutils/Assert.hpp> #include <Arbutils/Assert.hpp>
#include <unordered_set>
#include "../../Library/Exceptions/NotImplementedException.hpp" #include "../../Library/Exceptions/NotImplementedException.hpp"
#include "../ScriptHandling/ScriptMacros.hpp" #include "../ScriptHandling/ScriptMacros.hpp"
#include "ResolveTarget.hpp" #include "ResolveTarget.hpp"

View File

@ -25,6 +25,9 @@ Battling::Creature::Creature(ArbUt::BorrowedPtr<const BattleLibrary> library,
if (_nickname.empty()) { if (_nickname.empty()) {
_nickname = species->GetName().std_str(); _nickname = species->GetName().std_str();
} }
for (auto t : _variant->GetTypes()) {
_types.insert(t);
}
} }
void Battling::Creature::ChangeLevelBy(int8_t amount) { void Battling::Creature::ChangeLevelBy(int8_t amount) {
@ -146,14 +149,10 @@ void Battling::Creature::OverrideActiveTalent(const ConstString& talent) {
_activeTalent.reset(this->_library->LoadScript(ScriptCategory::Talent, talent)); _activeTalent.reset(this->_library->LoadScript(ScriptCategory::Talent, talent));
} }
const ArbUt::List<uint8_t>& Battling::Creature::GetTypes() const noexcept { const std::unordered_set<uint8_t>& Battling::Creature::GetTypes() const noexcept { return _types; }
// HOOK: override types.
return this->_variant->GetTypes();
}
bool Battling::Creature::HasType(uint8_t type) const noexcept { bool Battling::Creature::HasType(uint8_t type) const noexcept {
auto t = GetTypes(); return std::find(_types.begin(), _types.end(), type) != _types.end();
return std::find(t.begin(), t.end(), type) != t.end();
} }
size_t Battling::Creature::ScriptCount() const { size_t Battling::Creature::ScriptCount() const {

View File

@ -59,6 +59,8 @@ namespace CreatureLib::Battling {
std::unique_ptr<Script> _status = nullptr; std::unique_ptr<Script> _status = nullptr;
ScriptSet _volatile = {}; ScriptSet _volatile = {};
std::unordered_set<uint8_t> _types;
private: private:
void OnFaint(); void OnFaint();
@ -109,7 +111,7 @@ namespace CreatureLib::Battling {
const ArbUt::CaseInsensitiveConstString& GetActiveTalent() const; const ArbUt::CaseInsensitiveConstString& GetActiveTalent() const;
[[nodiscard]] bool IsFainted() const noexcept; [[nodiscard]] bool IsFainted() const noexcept;
[[nodiscard]] const ArbUt::List<uint8_t>& GetTypes() const noexcept; [[nodiscard]] const std::unordered_set<uint8_t>& GetTypes() const noexcept;
[[nodiscard]] bool HasType(uint8_t type) const noexcept; [[nodiscard]] bool HasType(uint8_t type) const noexcept;
uint32_t GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); } uint32_t GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); }

View File

@ -4,7 +4,7 @@
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
float TypeLibrary::GetEffectiveness(uint8_t attacking, const ArbUt::List<uint8_t>& defensive) const { float TypeLibrary::GetEffectiveness(uint8_t attacking, const std::unordered_set<uint8_t>& defensive) const {
return std::accumulate( return std::accumulate(
defensive.begin(), defensive.end(), (float)1, defensive.begin(), defensive.end(), (float)1,
[this, attacking](float init, uint8_t defense) { return init * GetSingleEffectiveness(attacking, defense); }); [this, attacking](float init, uint8_t defense) { return init * GetSingleEffectiveness(attacking, defense); });

View File

@ -4,7 +4,7 @@
#include <Arbutils/Collections/Dictionary.hpp> #include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/Collections/List.hpp> #include <Arbutils/Collections/List.hpp>
#include <Arbutils/ConstString.hpp> #include <Arbutils/ConstString.hpp>
#include <unordered_map> #include <unordered_set>
#include <vector> #include <vector>
namespace CreatureLib::Library { namespace CreatureLib::Library {
@ -18,7 +18,7 @@ namespace CreatureLib::Library {
uint8_t GetTypeId(const ArbUt::CaseInsensitiveConstString& s) const; uint8_t GetTypeId(const ArbUt::CaseInsensitiveConstString& s) const;
uint8_t GetTypeId(uint32_t s) const; uint8_t GetTypeId(uint32_t s) const;
[[nodiscard]] float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const; [[nodiscard]] float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
[[nodiscard]] float GetEffectiveness(uint8_t attacking, const ArbUt::List<uint8_t>& defensive) const; [[nodiscard]] float GetEffectiveness(uint8_t attacking, const std::unordered_set<uint8_t>& defensive) const;
uint8_t RegisterType(const ArbUt::CaseInsensitiveConstString& typeName); uint8_t RegisterType(const ArbUt::CaseInsensitiveConstString& typeName);
uint8_t RegisterType(uint32_t typeHash); uint8_t RegisterType(uint32_t typeHash);