#ifndef CREATURELIB_TYPELIBRARY_HPP #define CREATURELIB_TYPELIBRARY_HPP #include #include #include #include #include #include "../Defines.hpp" #include "Exceptions/CreatureException.hpp" namespace CreatureLib::Library { class TypeLibrary { ArbUt::StringViewDictionary _types; ArbUt::List> _effectiveness; public: TypeLibrary(size_t initialCapacity = 20) : _types(ArbUt::StringViewDictionary(initialCapacity)) {} inline u8 GetTypeId(const ArbUt::StringView& key) const { return _types.Get(key); } inline u8 GetTypeIdByHash(u32 keyHash) const { return _types.GetFromHash(keyHash); } [[nodiscard]] inline float GetSingleEffectiveness(u8 attacking, u8 defensive) const { try { return _effectiveness[attacking][defensive]; } catch (const std::exception& e) { THROW("Unknown type indices were requested for effectiveness: ", (u32)attacking, " and ", (u32)defensive); } } [[nodiscard]] inline float GetEffectiveness(u8 attacking, const std::vector& defensive) const { return std::accumulate(defensive.begin(), defensive.end(), (float)1, [this, attacking](float init, u8 defense) { return init * GetSingleEffectiveness(attacking, defense); }); } const ArbUt::StringView& GetTypeName(u8 type) const; u8 RegisterType(const ArbUt::StringView& typeName); void SetEffectiveness(u8 attacking, u8 defensive, float effectiveness); }; } #endif // CREATURELIB_TYPELIBRARY_HPP