Use vector instead of set for types.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2020-10-23 16:51:15 +02:00
parent de8b5de7b4
commit 1dc3aafd33
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
6 changed files with 10 additions and 9 deletions

View File

@ -56,6 +56,8 @@ BORROWED_GET_FUNC(Creature, GetBattleSide, BattleSide*);
SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool);
export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().data(); }
export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); }
export size_t CreatureLib_Creature_GetTypeCount(Creature* p) { return p->GetTypes().size(); }
export const uint8_t* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().data(); }
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_Damage(Creature* p, uint32_t damage, DamageSource source) {

View File

@ -27,7 +27,7 @@ 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, std::unordered_set<uint8_t>(defensive, defensive + defensiveCount));)
Try(out = p->GetEffectiveness(attacking, std::vector<uint8_t>(defensive, defensive + defensiveCount));)
}
export uint8_t CreatureLib_TypeLibrary_GetTypeName(const char*& out, TypeLibrary* p, uint8_t type) {
Try(out = p->GetTypeName(type).c_str();)

View File

@ -26,7 +26,7 @@ class CreatureLibConan(ConanFile):
self.output.info("Linking C libraries statically")
cmake.definitions["STATICC"] = "ON"
self.output.info("Using level size of: %s" % self.options.level_size)
cmake.definitions["LEVEL_SIZE"] = self.options.level_size;
cmake.definitions["LEVEL_SIZE"] = self.options.level_size
cmake.configure()
cmake.build()

View File

@ -23,7 +23,7 @@ namespace CreatureLib::Battling {
_activeTalent = std::unique_ptr<Script>(_library->LoadScript(ScriptCategory::Talent, GetActiveTalent()));
for (auto t : _variant->GetTypes()) {
_types.insert(t);
_types.push_back(t);
}
}
@ -61,7 +61,7 @@ namespace CreatureLib::Battling {
// Set the types to the new variant.
_types.clear();
for (auto t : variant->GetTypes()) {
_types.insert(t);
_types.push_back(t);
}
// Grab the new active talent.
@ -215,7 +215,7 @@ namespace CreatureLib::Battling {
_overridenTalentName = talent;
}
const std::unordered_set<uint8_t>& Creature::GetTypes() const noexcept { return _types; }
const std::vector<uint8_t>& Creature::GetTypes() const noexcept { return _types; }
bool Creature::HasType(uint8_t type) const noexcept {
return std::find(_types.begin(), _types.end(), type) != _types.end();

View File

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

View File

@ -21,8 +21,7 @@ namespace CreatureLib::Library {
<< (uint32_t)defensive);
}
}
[[nodiscard]] inline float GetEffectiveness(uint8_t attacking,
const std::unordered_set<uint8_t>& defensive) const {
[[nodiscard]] inline float GetEffectiveness(uint8_t attacking, const std::vector<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);