Moved Creature types to creature itself, instead of using the variant types.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
3c5b3d5c03
commit
9e7607338f
|
@ -47,8 +47,6 @@ SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattle, Battle*);
|
|||
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetBattleSide, BattleSide*);
|
||||
SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool);
|
||||
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); }
|
||||
SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t);
|
||||
export uint8_t CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { Try(p->ChangeLevelBy(level);) }
|
||||
|
|
|
@ -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,
|
||||
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));)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "TurnHandler.hpp"
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <unordered_set>
|
||||
#include "../../Library/Exceptions/NotImplementedException.hpp"
|
||||
#include "../ScriptHandling/ScriptMacros.hpp"
|
||||
#include "ResolveTarget.hpp"
|
||||
|
|
|
@ -25,6 +25,9 @@ Battling::Creature::Creature(ArbUt::BorrowedPtr<const BattleLibrary> library,
|
|||
if (_nickname.empty()) {
|
||||
_nickname = species->GetName().std_str();
|
||||
}
|
||||
for (auto t : _variant->GetTypes()) {
|
||||
_types.insert(t);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
const ArbUt::List<uint8_t>& Battling::Creature::GetTypes() const noexcept {
|
||||
// HOOK: override types.
|
||||
return this->_variant->GetTypes();
|
||||
}
|
||||
const std::unordered_set<uint8_t>& Battling::Creature::GetTypes() const noexcept { return _types; }
|
||||
|
||||
bool Battling::Creature::HasType(uint8_t type) const noexcept {
|
||||
auto t = GetTypes();
|
||||
return std::find(t.begin(), t.end(), type) != t.end();
|
||||
return std::find(_types.begin(), _types.end(), type) != _types.end();
|
||||
}
|
||||
|
||||
size_t Battling::Creature::ScriptCount() const {
|
||||
|
|
|
@ -59,6 +59,8 @@ namespace CreatureLib::Battling {
|
|||
std::unique_ptr<Script> _status = nullptr;
|
||||
ScriptSet _volatile = {};
|
||||
|
||||
std::unordered_set<uint8_t> _types;
|
||||
|
||||
private:
|
||||
void OnFaint();
|
||||
|
||||
|
@ -109,7 +111,7 @@ namespace CreatureLib::Battling {
|
|||
const ArbUt::CaseInsensitiveConstString& GetActiveTalent() const;
|
||||
|
||||
[[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;
|
||||
|
||||
uint32_t GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); }
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
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(
|
||||
defensive.begin(), defensive.end(), (float)1,
|
||||
[this, attacking](float init, uint8_t defense) { return init * GetSingleEffectiveness(attacking, defense); });
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
|
@ -18,7 +18,7 @@ namespace CreatureLib::Library {
|
|||
uint8_t GetTypeId(const ArbUt::CaseInsensitiveConstString& s) const;
|
||||
uint8_t GetTypeId(uint32_t s) 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(uint32_t typeHash);
|
||||
|
|
Loading…
Reference in New Issue