Change types on Creature to List instead of vector
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-05-26 12:49:47 +02:00
parent e1c5460db4
commit 782e9b90a8
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 15 additions and 21 deletions

View File

@ -64,8 +64,8 @@ export_func const char* CreatureLib_Creature_GetNickname(Creature* p) {
} }
export_func void CreatureLib_Creature_SetNickname(Creature* p, const char* nickname) { p->SetNickname(nickname); } export_func void CreatureLib_Creature_SetNickname(Creature* p, const char* nickname) { p->SetNickname(nickname); }
export_func bool CreatureLib_Creature_HasType(Creature* p, u8 type) { return p->HasType(type); } export_func bool CreatureLib_Creature_HasType(Creature* p, u8 type) { return p->HasType(type); }
export_func size_t CreatureLib_Creature_GetTypeCount(Creature* p) { return p->GetTypes().size(); } export_func size_t CreatureLib_Creature_GetTypeCount(Creature* p) { return p->GetTypes().Count(); }
export_func const u8* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().data(); } export_func const u8* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().RawData(); }
SIMPLE_GET_FUNC(Creature, GetMaxHealth, u32); SIMPLE_GET_FUNC(Creature, GetMaxHealth, u32);
export_func u8 CreatureLib_Creature_ChangeLevelBy(Creature* p, i8 level) { Try(p->ChangeLevelBy(level);) } export_func u8 CreatureLib_Creature_ChangeLevelBy(Creature* p, i8 level) { Try(p->ChangeLevelBy(level);) }
export_func u8 CreatureLib_Creature_Damage(Creature* p, u32 damage, DamageSource source) { export_func u8 CreatureLib_Creature_Damage(Creature* p, u32 damage, DamageSource source) {

View File

@ -26,7 +26,7 @@ export_func u8 CreatureLib_TypeLibrary_GetSingleEffectiveness(float& out, TypeLi
export_func u8 CreatureLib_TypeLibrary_GetEffectiveness(float& out, TypeLibrary* p, u8 attacking, u8 defensive[], export_func u8 CreatureLib_TypeLibrary_GetEffectiveness(float& out, TypeLibrary* p, u8 attacking, u8 defensive[],
size_t defensiveCount) { size_t defensiveCount) {
Try(out = p->GetEffectiveness(attacking, std::vector<u8>(defensive, defensive + defensiveCount));) Try(out = p->GetEffectiveness(attacking, ArbUt::List<u8>(defensive, defensive + defensiveCount));)
} }
export_func u8 CreatureLib_TypeLibrary_GetTypeName(const char*& out, TypeLibrary* p, u8 type) { export_func u8 CreatureLib_TypeLibrary_GetTypeName(const char*& out, TypeLibrary* p, u8 type) {
Try(out = p->GetTypeName(type).c_str();) Try(out = p->GetTypeName(type).c_str();)

View File

@ -34,7 +34,7 @@ namespace CreatureLib::Battling {
.TakeOwnership(); .TakeOwnership();
} }
for (auto t : _variant->GetTypes()) { for (auto t : _variant->GetTypes()) {
_types.push_back(t); _types.Append(t);
} }
} }
@ -75,9 +75,9 @@ namespace CreatureLib::Battling {
_variant = variant; _variant = variant;
// Set the types to the new variant. // Set the types to the new variant.
_types.clear(); _types.Clear();
for (auto t : variant->GetTypes()) { for (auto t : variant->GetTypes()) {
_types.push_back(t); _types.Append(t);
} }
_weight = variant->GetWeight(); _weight = variant->GetWeight();
@ -136,9 +136,9 @@ namespace CreatureLib::Battling {
ResetActiveScripts(); ResetActiveScripts();
_weight = _variant->GetWeight(); _weight = _variant->GetWeight();
_height = _variant->GetHeight(); _height = _variant->GetHeight();
_types.clear(); _types.Clear();
for (auto t : _variant->GetTypes()) { for (auto t : _variant->GetTypes()) {
_types.push_back(t); _types.Append(t);
} }
} }
@ -273,17 +273,11 @@ namespace CreatureLib::Battling {
_overridenTalent = _library->GetStaticLib()->GetTalentLibrary()->Get(talent); _overridenTalent = _library->GetStaticLib()->GetTalentLibrary()->Get(talent);
} }
const std::vector<u8>& Creature::GetTypes() const noexcept { return _types; }
bool Creature::HasType(u8 type) const noexcept {
return std::find(_types.begin(), _types.end(), type) != _types.end();
}
void Creature::SetType(u8 index, u8 type) noexcept { void Creature::SetType(u8 index, u8 type) noexcept {
if (_types.size() > index) { if (_types.Count() > index) {
_types[index] = type; _types[index] = type;
} else { } else {
_types.push_back(type); _types.Append(type);
} }
} }
@ -474,7 +468,7 @@ namespace CreatureLib::Battling {
c->_status = _status.GetValue()->Clone(c); c->_status = _status.GetValue()->Clone(c);
} }
_volatile.Clone(c, c->_volatile); _volatile.Clone(c, c->_volatile);
c->_types = std::vector<u8>(_types); c->_types = ArbUt::List<u8>(_types);
c->RecalculateFlatStats(); c->RecalculateFlatStats();
return c; return c;

View File

@ -64,7 +64,7 @@ namespace CreatureLib::Battling {
ArbUt::OptionalUniquePtr<BattleScript> _status = nullptr; ArbUt::OptionalUniquePtr<BattleScript> _status = nullptr;
ScriptSet _volatile = {}; ScriptSet _volatile = {};
std::vector<u8> _types = {}; ArbUt::List<u8> _types = {};
ArbUt::OptionalBorrowedPtr<const Library::Item> _heldItem; ArbUt::OptionalBorrowedPtr<const Library::Item> _heldItem;
ArbUt::OptionalUniquePtr<BattleScript> _heldItemTriggerScript = nullptr; ArbUt::OptionalUniquePtr<BattleScript> _heldItemTriggerScript = nullptr;
@ -153,8 +153,8 @@ namespace CreatureLib::Battling {
/// Are we allowed to use this creature in a battle? /// Are we allowed to use this creature in a battle?
[[nodiscard]] virtual bool IsUsable() const noexcept; [[nodiscard]] virtual bool IsUsable() const noexcept;
[[nodiscard]] bool IsFainted() const noexcept; [[nodiscard]] bool IsFainted() const noexcept;
[[nodiscard]] const std::vector<u8>& GetTypes() const noexcept; [[nodiscard]] inline const ArbUt::List<u8>& GetTypes() const noexcept { return _types; }
[[nodiscard]] bool HasType(u8 type) const noexcept; [[nodiscard]] inline bool HasType(u8 type) const noexcept { return _types.Contains(type); }
void SetType(u8 index, u8 type) noexcept; void SetType(u8 index, u8 type) noexcept;
u32 GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); } u32 GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); }

View File

@ -27,7 +27,7 @@ namespace CreatureLib::Library {
(u32)defensive); (u32)defensive);
} }
} }
[[nodiscard]] inline float GetEffectiveness(u8 attacking, const std::vector<u8>& defensive) const { [[nodiscard]] inline float GetEffectiveness(u8 attacking, const ArbUt::List<u8>& defensive) const {
return std::accumulate(defensive.begin(), defensive.end(), (float)1, return std::accumulate(defensive.begin(), defensive.end(), (float)1,
[this, attacking](float init, u8 defense) { [this, attacking](float init, u8 defense) {
return init * GetSingleEffectiveness(attacking, defense); return init * GetSingleEffectiveness(attacking, defense);