Replace most collections with Arbutils collections for more safety.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-03-22 19:21:40 +01:00
parent f190121e74
commit 27288563cd
40 changed files with 234 additions and 226 deletions

View File

@@ -1,23 +1,26 @@
#ifndef CREATURELIB_TYPELIBRARY_HPP
#define CREATURELIB_TYPELIBRARY_HPP
#include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/Collections/List.hpp>
#include <Arbutils/ConstString.hpp>
#include <unordered_map>
#include <vector>
using ConstString = Arbutils::CaseInsensitiveConstString;
using namespace Arbutils::Collections;
namespace CreatureLib::Library {
class TypeLibrary {
std::unordered_map<uint32_t, uint8_t> _types;
std::vector<std::vector<float>> _effectiveness;
Dictionary<uint32_t, uint8_t> _types;
List<List<float>> _effectiveness;
public:
TypeLibrary(size_t initialCapacity = 20) : _types(std::unordered_map<uint32_t, uint8_t>(initialCapacity)) {}
TypeLibrary(size_t initialCapacity = 20) : _types(Dictionary<uint32_t, uint8_t>(initialCapacity)) {}
uint8_t GetTypeId(const ConstString& 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 std::vector<uint8_t>& defensive) const;
[[nodiscard]] float GetEffectiveness(uint8_t attacking, const List<uint8_t>& defensive) const;
uint8_t RegisterType(const ConstString& typeName);
uint8_t RegisterType(uint32_t typeHash);