Implement basic type library.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
b4e08049ce
commit
168e14d394
|
@ -4,9 +4,10 @@ CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings settings,
|
|||
CreatureLib::Library::SpeciesLibrary *species,
|
||||
CreatureLib::Library::AttackLibrary *attacks,
|
||||
CreatureLib::Library::ItemLibrary *items,
|
||||
CreatureLib::Library::GrowthRateLibrary *growthRates)
|
||||
CreatureLib::Library::GrowthRateLibrary *growthRates,
|
||||
TypeLibrary* typeLibrary)
|
||||
: _settings(settings), _species(species), _attacks(attacks), _items(items),
|
||||
_growthRates(growthRates){
|
||||
_growthRates(growthRates), _typeLibrary(typeLibrary){
|
||||
|
||||
}
|
||||
|
||||
|
@ -30,5 +31,9 @@ const CreatureLib::Library::GrowthRateLibrary *CreatureLib::Library::DataLibrary
|
|||
return _growthRates;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::TypeLibrary *CreatureLib::Library::DataLibrary::GetTypeLibrary() const {
|
||||
return _typeLibrary;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "ItemLibrary.hpp"
|
||||
#include "GrowthRates/GrowthRateLibrary.hpp"
|
||||
#include "LibrarySettings.hpp"
|
||||
#include "TypeLibrary.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
|
@ -18,12 +19,14 @@ namespace CreatureLib::Library {
|
|||
const AttackLibrary* _attacks;
|
||||
const ItemLibrary* _items;
|
||||
const GrowthRateLibrary* _growthRates;
|
||||
const TypeLibrary* _typeLibrary;
|
||||
public:
|
||||
DataLibrary(LibrarySettings settings,
|
||||
CreatureLib::Library::SpeciesLibrary *species,
|
||||
CreatureLib::Library::AttackLibrary *attacks,
|
||||
CreatureLib::Library::ItemLibrary *items,
|
||||
CreatureLib::Library::GrowthRateLibrary *growthRates
|
||||
CreatureLib::Library::GrowthRateLibrary *growthRates,
|
||||
TypeLibrary* typeLibrary
|
||||
);
|
||||
|
||||
~DataLibrary(){
|
||||
|
@ -31,6 +34,7 @@ namespace CreatureLib::Library {
|
|||
delete _attacks;
|
||||
delete _items;
|
||||
delete _growthRates;
|
||||
delete _typeLibrary;
|
||||
}
|
||||
|
||||
[[nodiscard]] const LibrarySettings& GetSettings() const;
|
||||
|
@ -38,6 +42,7 @@ namespace CreatureLib::Library {
|
|||
[[nodiscard]] const AttackLibrary* GetAttackLibrary() const;
|
||||
[[nodiscard]] const ItemLibrary* GetItemLibrary() const;
|
||||
[[nodiscard]] const GrowthRateLibrary* GetGrowthRates() const;
|
||||
[[nodiscard]] const TypeLibrary* GetTypeLibrary() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#include "TypeLibrary.hpp"
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
float TypeLibrary::GetEffectiveness(uint8_t attacking, const std::vector<uint8_t> &defensive) const {
|
||||
auto eff = 1;
|
||||
for (auto def: defensive){
|
||||
eff *= GetSingleEffectiveness(attacking, def);
|
||||
}
|
||||
return eff;
|
||||
}
|
||||
|
||||
float TypeLibrary::GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const {
|
||||
return _effectiveness[attacking][defensive];
|
||||
}
|
||||
|
||||
uint8_t TypeLibrary::GetTypeId(const std::string &s) const {
|
||||
return _types.at(s);
|
||||
}
|
||||
|
||||
uint8_t TypeLibrary::RegisterType(const std::string& typeName) {
|
||||
_types.insert({typeName, _types.size()});
|
||||
_effectiveness.resize(_types.size());
|
||||
for (auto & eff : _effectiveness){
|
||||
eff.resize(_types.size(), 1);
|
||||
}
|
||||
return _types.size() - 1;
|
||||
}
|
||||
|
||||
void TypeLibrary::SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness) {
|
||||
_effectiveness[attacking][defensive] = effectiveness;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef CREATURELIB_TYPELIBRARY_HPP
|
||||
#define CREATURELIB_TYPELIBRARY_HPP
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace CreatureLib::Library{
|
||||
class TypeLibrary {
|
||||
std::unordered_map<std::string, uint8_t > _types;
|
||||
std::vector<std::vector<float>> _effectiveness;
|
||||
public:
|
||||
uint8_t GetTypeId(const std::string& s) const;
|
||||
float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
|
||||
float GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const;
|
||||
|
||||
uint8_t RegisterType(const std::string& typeName);
|
||||
void SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_TYPELIBRARY_HPP
|
|
@ -41,10 +41,17 @@ static GrowthRateLibrary* BuildGrowthRateLibrary(){
|
|||
return l;
|
||||
}
|
||||
|
||||
static TypeLibrary* BuildTypeLibrary(){
|
||||
auto l = new TypeLibrary();
|
||||
l->RegisterType("testType1");
|
||||
l->RegisterType("testType2");
|
||||
l->RegisterType("testType3");
|
||||
return l;
|
||||
}
|
||||
|
||||
static BattleLibrary* BuildLibrary(){
|
||||
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
|
||||
BuildItemLibrary(), BuildGrowthRateLibrary());
|
||||
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary());
|
||||
auto battleLib = new BattleLibrary(l, new BattleStatCalculator());
|
||||
return battleLib;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue