Used ClangFormat style guide I'm happy with.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,20 +1,16 @@
|
||||
#include "AttackLibrary.hpp"
|
||||
|
||||
const CreatureLib::Library::AttackData *CreatureLib::Library::AttackLibrary::GetAttack(const std::string &name) const {
|
||||
const CreatureLib::Library::AttackData* CreatureLib::Library::AttackLibrary::GetAttack(const std::string& name) const {
|
||||
return this->_attacks.at(name);
|
||||
}
|
||||
|
||||
const CreatureLib::Library::AttackData *CreatureLib::Library::AttackLibrary::operator[](const std::string &name) const {
|
||||
const CreatureLib::Library::AttackData* CreatureLib::Library::AttackLibrary::operator[](const std::string& name) const {
|
||||
return GetAttack(name);
|
||||
}
|
||||
|
||||
void CreatureLib::Library::AttackLibrary::LoadAttack(const std::string &name,
|
||||
void CreatureLib::Library::AttackLibrary::LoadAttack(const std::string& name,
|
||||
const CreatureLib::Library::AttackData* attack) {
|
||||
this->_attacks.insert({name, attack});
|
||||
}
|
||||
|
||||
void CreatureLib::Library::AttackLibrary::DeleteAttack(const std::string &name) {
|
||||
this->_attacks.erase(name);
|
||||
}
|
||||
|
||||
|
||||
void CreatureLib::Library::AttackLibrary::DeleteAttack(const std::string& name) { this->_attacks.erase(name); }
|
||||
|
||||
@@ -9,22 +9,23 @@ namespace CreatureLib::Library {
|
||||
class AttackLibrary {
|
||||
private:
|
||||
std::unordered_map<std::string, const AttackData*> _attacks;
|
||||
|
||||
public:
|
||||
AttackLibrary() = default;
|
||||
|
||||
~AttackLibrary(){
|
||||
for (auto attack: _attacks){
|
||||
~AttackLibrary() {
|
||||
for (auto attack : _attacks) {
|
||||
delete attack.second;
|
||||
}
|
||||
_attacks.clear();
|
||||
}
|
||||
|
||||
[[nodiscard]] const AttackData* GetAttack(const std::string& name) const;
|
||||
[[nodiscard]] const AttackData* operator[] (const std::string& name) const;
|
||||
[[nodiscard]] const AttackData* operator[](const std::string& name) const;
|
||||
|
||||
void LoadAttack(const std::string& name, const AttackData* attack);
|
||||
void DeleteAttack(const std::string& name);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_ATTACKLIBRARY_HPP
|
||||
#endif // CREATURELIB_ATTACKLIBRARY_HPP
|
||||
|
||||
@@ -4,11 +4,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
enum class AttackCategory : uint8_t {
|
||||
Physical,
|
||||
Magical,
|
||||
Status
|
||||
};
|
||||
enum class AttackCategory : uint8_t { Physical, Magical, Status };
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_ATTACKCATEGORY_HPP
|
||||
#endif // CREATURELIB_ATTACKCATEGORY_HPP
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "AttackData.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
CreatureLib::Library::AttackData::AttackData(std::string name, std::string type,
|
||||
@@ -7,19 +6,9 @@ CreatureLib::Library::AttackData::AttackData(std::string name, std::string type,
|
||||
uint8_t accuracy, uint8_t baseUsage,
|
||||
CreatureLib::Library::AttackTarget target, uint8_t priority,
|
||||
std::unordered_set<std::string> flags)
|
||||
:
|
||||
__Name(std::move(name)),
|
||||
__Type(std::move(type)),
|
||||
__Category(category),
|
||||
__BasePower(power),
|
||||
__Accuracy(accuracy),
|
||||
__BaseUsages(baseUsage),
|
||||
__Target(target),
|
||||
__Priority(priority),
|
||||
_flags(std::move(flags))
|
||||
{}
|
||||
: __Name(std::move(name)), __Type(std::move(type)), __Category(category), __BasePower(power), __Accuracy(accuracy),
|
||||
__BaseUsages(baseUsage), __Target(target), __Priority(priority), _flags(std::move(flags)) {}
|
||||
|
||||
bool CreatureLib::Library::AttackData::HasFlag(const std::string& key) const{
|
||||
bool CreatureLib::Library::AttackData::HasFlag(const std::string& key) const {
|
||||
return this->_flags.find(key) != this->_flags.end();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,23 +3,24 @@
|
||||
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include "../../GenericTemplates.cpp"
|
||||
#include "AttackCategory.hpp"
|
||||
#include "AttackTarget.hpp"
|
||||
|
||||
#include "../../GenericTemplates.cpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class AttackData {
|
||||
GetProperty(std::string, Name);
|
||||
GetProperty(std::string, Type);
|
||||
GetProperty(AttackCategory , Category);
|
||||
GetProperty(uint8_t , BasePower);
|
||||
GetProperty(uint8_t , Accuracy);
|
||||
GetProperty(uint8_t , BaseUsages);
|
||||
GetProperty(AttackCategory, Category);
|
||||
GetProperty(uint8_t, BasePower);
|
||||
GetProperty(uint8_t, Accuracy);
|
||||
GetProperty(uint8_t, BaseUsages);
|
||||
GetProperty(AttackTarget, Target);
|
||||
GetProperty(uint8_t , Priority);
|
||||
GetProperty(uint8_t, Priority);
|
||||
|
||||
private:
|
||||
std::unordered_set<std::string> _flags;
|
||||
|
||||
public:
|
||||
AttackData(std::string name, std::string type, AttackCategory category, uint8_t power, uint8_t accuracy,
|
||||
uint8_t baseUsage, AttackTarget target, uint8_t priority, std::unordered_set<std::string> flags);
|
||||
@@ -28,5 +29,4 @@ namespace CreatureLib::Library {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_ATTACKDATA_HPP
|
||||
#endif // CREATURELIB_ATTACKDATA_HPP
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
enum class AttackTarget : uint8_t{
|
||||
enum class AttackTarget : uint8_t {
|
||||
Adjacent,
|
||||
AdjacentAlly,
|
||||
AdjacentAllySelf,
|
||||
@@ -23,4 +23,4 @@ namespace CreatureLib::Library {
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_ATTACKTARGET_HPP
|
||||
#endif // CREATURELIB_ATTACKTARGET_HPP
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
#include "CreatureMoves.hpp"
|
||||
#include <utility>
|
||||
|
||||
CreatureLib::Library::LevelMove::LevelMove(uint8_t level, std::string name)
|
||||
:_level(level),
|
||||
_name(std::move(name))
|
||||
{}
|
||||
CreatureLib::Library::LevelMove::LevelMove(uint8_t level, std::string name) : _level(level), _name(std::move(name)) {}
|
||||
|
||||
uint8_t CreatureLib::Library::LevelMove::GetLevel() const {
|
||||
return this->_level;
|
||||
}
|
||||
|
||||
std::string CreatureLib::Library::LevelMove::GetName() const {
|
||||
return this->_name;
|
||||
}
|
||||
uint8_t CreatureLib::Library::LevelMove::GetLevel() const { return this->_level; }
|
||||
|
||||
std::string CreatureLib::Library::LevelMove::GetName() const { return this->_name; }
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace CreatureLib::Library{
|
||||
class LevelMove{
|
||||
namespace CreatureLib::Library {
|
||||
class LevelMove {
|
||||
private:
|
||||
uint8_t _level;
|
||||
std::string _name;
|
||||
|
||||
public:
|
||||
LevelMove(uint8_t level, std::string name);
|
||||
[[nodiscard]] inline uint8_t GetLevel() const;
|
||||
@@ -23,10 +24,10 @@ namespace CreatureLib::Library{
|
||||
std::vector<std::string> _machineMoves;
|
||||
std::vector<std::string> _tutorMoves;
|
||||
std::vector<std::string> _variantDependentMoves;
|
||||
|
||||
public:
|
||||
//TODO: Public API funcs
|
||||
// TODO: Public API funcs
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_CREATUREMOVES_HPP
|
||||
#endif // CREATURELIB_CREATUREMOVES_HPP
|
||||
|
||||
@@ -2,30 +2,19 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, std::string growthRate, uint8_t captureRate, uint8_t baseHappiness)
|
||||
:
|
||||
__Id(id),
|
||||
__GenderRate(genderRatio),
|
||||
__GrowthRate(std::move(growthRate)),
|
||||
__CaptureRate(captureRate),
|
||||
__BaseHappiness(baseHappiness),
|
||||
_variants({{"default", defaultVariant}}),
|
||||
_name(std::move(name))
|
||||
{}
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
std::string growthRate, uint8_t captureRate, uint8_t baseHappiness)
|
||||
: __Id(id), __GenderRate(genderRatio), __GrowthRate(std::move(growthRate)), __CaptureRate(captureRate),
|
||||
__BaseHappiness(baseHappiness), _variants({{"default", defaultVariant}}), _name(std::move(name)) {}
|
||||
|
||||
const SpeciesVariant *CreatureSpecies::GetVariant(const std::string& key) const {
|
||||
return _variants.at(key);
|
||||
}
|
||||
const SpeciesVariant* CreatureSpecies::GetVariant(const std::string& key) const { return _variants.at(key); }
|
||||
|
||||
Gender CreatureSpecies::GetRandomGender(CreatureLib::Core::Random &rand) const {
|
||||
Gender CreatureSpecies::GetRandomGender(CreatureLib::Core::Random& rand) const {
|
||||
// TODO: Genderless creatures
|
||||
auto val = rand.GetDouble();
|
||||
if (val >= this->__GenderRate) return Gender ::Female;
|
||||
if (val >= this->__GenderRate)
|
||||
return Gender ::Female;
|
||||
return Gender ::Male;
|
||||
}
|
||||
|
||||
const std::string &CreatureSpecies::GetName() const {
|
||||
return _name;
|
||||
}
|
||||
|
||||
const std::string& CreatureSpecies::GetName() const { return _name; }
|
||||
|
||||
@@ -3,28 +3,31 @@
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "SpeciesVariant.hpp"
|
||||
#include "../Gender.hpp"
|
||||
#include "SpeciesVariant.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
\brief This holds the data required for a species of a creature, so the general data we can describe different creatures with.
|
||||
*/
|
||||
/*!
|
||||
\brief This holds the data required for a species of a creature, so the general data we can describe different
|
||||
creatures with.
|
||||
*/
|
||||
class CreatureSpecies {
|
||||
GetProperty(uint16_t, Id);
|
||||
GetProperty(float, GenderRate);
|
||||
GetProperty(std::string, GrowthRate);
|
||||
GetProperty(uint8_t, CaptureRate);
|
||||
GetProperty(uint8_t, BaseHappiness);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, const SpeciesVariant*> _variants;
|
||||
std::string _name;
|
||||
public:
|
||||
CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, std::string growthRate, uint8_t captureRate, uint8_t baseHappiness);
|
||||
|
||||
~CreatureSpecies(){
|
||||
for (auto v: _variants)
|
||||
public:
|
||||
CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
std::string growthRate, uint8_t captureRate, uint8_t baseHappiness);
|
||||
|
||||
~CreatureSpecies() {
|
||||
for (auto v : _variants)
|
||||
delete v.second;
|
||||
_variants.clear();
|
||||
}
|
||||
@@ -35,4 +38,4 @@ namespace CreatureLib::Library {
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_CREATURESPECIES_HPP
|
||||
#endif // CREATURELIB_CREATURESPECIES_HPP
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
void LearnableAttacks::AddLevelMove(uint8_t level, AttackData *attack) {
|
||||
_learnedByLevel[level].push_back(attack);
|
||||
}
|
||||
void LearnableAttacks::AddLevelMove(uint8_t level, AttackData* attack) { _learnedByLevel[level].push_back(attack); }
|
||||
|
||||
const std::vector<const AttackData *> &LearnableAttacks::GetMovesForLevel(uint8_t level) const {
|
||||
const std::vector<const AttackData*>& LearnableAttacks::GetMovesForLevel(uint8_t level) const {
|
||||
return _learnedByLevel[level];
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
namespace CreatureLib::Library {
|
||||
class LearnableAttacks {
|
||||
std::vector<std::vector<const AttackData*>> _learnedByLevel;
|
||||
|
||||
public:
|
||||
LearnableAttacks(uint8_t maxLevel)
|
||||
:_learnedByLevel(std::vector<std::vector<const AttackData*>>(maxLevel)){}
|
||||
LearnableAttacks(uint8_t maxLevel) : _learnedByLevel(std::vector<std::vector<const AttackData*>>(maxLevel)) {}
|
||||
|
||||
void AddLevelMove(uint8_t level, AttackData* attack);
|
||||
|
||||
@@ -17,5 +17,4 @@ namespace CreatureLib::Library {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_LEARNABLEATTACKS_HPP
|
||||
#endif // CREATURELIB_LEARNABLEATTACKS_HPP
|
||||
|
||||
@@ -2,24 +2,18 @@
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
const std::vector<uint8_t>& CreatureLib::Library::SpeciesVariant::GetTypes() const {
|
||||
return _types;
|
||||
}
|
||||
const std::vector<uint8_t>& CreatureLib::Library::SpeciesVariant::GetTypes() const { return _types; }
|
||||
|
||||
size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const {
|
||||
return _types.size();
|
||||
}
|
||||
size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const { return _types.size(); }
|
||||
|
||||
uint8_t CreatureLib::Library::SpeciesVariant::GetType(size_t index) const {
|
||||
return _types[index];
|
||||
}
|
||||
uint8_t CreatureLib::Library::SpeciesVariant::GetType(size_t index) const { return _types[index]; }
|
||||
|
||||
uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Core::Statistic stat) const {
|
||||
return _baseStatistics.GetStat(stat);
|
||||
}
|
||||
|
||||
const std::string& CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index) const {
|
||||
if (index < 0){
|
||||
if (index < 0) {
|
||||
index = -index - 1;
|
||||
return _secretTalents[index];
|
||||
}
|
||||
@@ -30,42 +24,34 @@ const std::string& CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index
|
||||
return &_moves;
|
||||
}*/
|
||||
|
||||
int8_t CreatureLib::Library::SpeciesVariant::GetTalentIndex(const std::string& talent) const{
|
||||
int8_t CreatureLib::Library::SpeciesVariant::GetTalentIndex(const std::string& talent) const {
|
||||
auto i = std::find(_talents.begin(), _talents.end(), talent);
|
||||
if (i != _talents.end()){
|
||||
if (i != _talents.end()) {
|
||||
return std::distance(_talents.begin(), i);
|
||||
}
|
||||
i = std::find(_secretTalents.begin(), _secretTalents.end(), talent);
|
||||
if (i != _secretTalents.end()){
|
||||
if (i != _secretTalents.end()) {
|
||||
return std::distance(_secretTalents.begin(), i);
|
||||
}
|
||||
throw CreatureException("The given talent is not a valid talent for this creature.");
|
||||
}
|
||||
|
||||
int8_t CreatureLib::Library::SpeciesVariant::GetRandomTalent(CreatureLib::Core::Random *rand) const {
|
||||
int8_t CreatureLib::Library::SpeciesVariant::GetRandomTalent(CreatureLib::Core::Random* rand) const {
|
||||
return rand->Get(_talents.size());
|
||||
}
|
||||
|
||||
const CreatureLib::Library::LearnableAttacks *CreatureLib::Library::SpeciesVariant::GetLearnableAttacks() const {
|
||||
const CreatureLib::Library::LearnableAttacks* CreatureLib::Library::SpeciesVariant::GetLearnableAttacks() const {
|
||||
return _attacks;
|
||||
}
|
||||
|
||||
CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float height, float weight,
|
||||
uint32_t baseExperience, std::vector<uint8_t> types,
|
||||
CreatureLib::Core::StatisticSet<uint16_t > baseStats,
|
||||
CreatureLib::Core::StatisticSet<uint16_t> baseStats,
|
||||
std::vector<std::string> talents,
|
||||
std::vector<std::string> secretTalents, const LearnableAttacks* attacks)
|
||||
: __Name(std::move(name)),
|
||||
__Height(height),
|
||||
__Weight(weight),
|
||||
__BaseExperience(baseExperience),
|
||||
_types(std::move(types)),
|
||||
_baseStatistics(baseStats),
|
||||
_talents(std::move(talents)),
|
||||
_secretTalents(std::move(secretTalents)),
|
||||
_attacks(attacks)
|
||||
{}
|
||||
std::vector<std::string> secretTalents,
|
||||
const LearnableAttacks* attacks)
|
||||
: __Name(std::move(name)), __Height(height), __Weight(weight), __BaseExperience(baseExperience),
|
||||
_types(std::move(types)), _baseStatistics(baseStats), _talents(std::move(talents)),
|
||||
_secretTalents(std::move(secretTalents)), _attacks(attacks) {}
|
||||
|
||||
CreatureLib::Library::SpeciesVariant::~SpeciesVariant() {
|
||||
delete _attacks;
|
||||
}
|
||||
CreatureLib::Library::SpeciesVariant::~SpeciesVariant() { delete _attacks; }
|
||||
@@ -3,37 +3,40 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "CreatureMoves.hpp"
|
||||
#include "../../Core/Random.hpp"
|
||||
#include "../../Core/StatisticSet.hpp"
|
||||
#include "../../GenericTemplates.cpp"
|
||||
#include "../../Core/Random.hpp"
|
||||
#include "CreatureMoves.hpp"
|
||||
#include "LearnableAttacks.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
\brief A single species can have more than one variant. This class holds the data for those variants.
|
||||
*/
|
||||
/*!
|
||||
\brief A single species can have more than one variant. This class holds the data for those variants.
|
||||
*/
|
||||
class SpeciesVariant {
|
||||
GetProperty(std::string, Name);
|
||||
GetProperty(float, Height);
|
||||
GetProperty(float, Weight);
|
||||
GetProperty(uint32_t, BaseExperience);
|
||||
|
||||
private:
|
||||
std::vector<uint8_t > _types;
|
||||
const Core::StatisticSet<uint16_t > _baseStatistics;
|
||||
std::vector<uint8_t> _types;
|
||||
const Core::StatisticSet<uint16_t> _baseStatistics;
|
||||
std::vector<std::string> _talents;
|
||||
std::vector<std::string> _secretTalents;
|
||||
const LearnableAttacks* _attacks;
|
||||
|
||||
public:
|
||||
SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience,
|
||||
std::vector<uint8_t> types, Core::StatisticSet<uint16_t > baseStats, std::vector<std::string> talents,
|
||||
std::vector<std::string> secretTalents, const LearnableAttacks* attacks);
|
||||
std::vector<uint8_t> types, Core::StatisticSet<uint16_t> baseStats,
|
||||
std::vector<std::string> talents, std::vector<std::string> secretTalents,
|
||||
const LearnableAttacks* attacks);
|
||||
|
||||
~SpeciesVariant();
|
||||
|
||||
[[nodiscard]] size_t GetTypeCount() const;
|
||||
[[nodiscard]] uint8_t GetType(size_t index) const;
|
||||
[[nodiscard]] const std::vector<uint8_t >& GetTypes() const;
|
||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;
|
||||
[[nodiscard]] const std::string& GetTalent(int32_t index) const;
|
||||
[[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const;
|
||||
@@ -42,4 +45,4 @@ namespace CreatureLib::Library {
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_SPECIESVARIANT_HPP
|
||||
#endif // CREATURELIB_SPECIESVARIANT_HPP
|
||||
|
||||
@@ -1,39 +1,31 @@
|
||||
#include "DataLibrary.hpp"
|
||||
|
||||
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings settings,
|
||||
CreatureLib::Library::SpeciesLibrary *species,
|
||||
CreatureLib::Library::AttackLibrary *attacks,
|
||||
CreatureLib::Library::ItemLibrary *items,
|
||||
CreatureLib::Library::GrowthRateLibrary *growthRates,
|
||||
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings settings, CreatureLib::Library::SpeciesLibrary* species,
|
||||
CreatureLib::Library::AttackLibrary* attacks,
|
||||
CreatureLib::Library::ItemLibrary* items,
|
||||
CreatureLib::Library::GrowthRateLibrary* growthRates,
|
||||
TypeLibrary* typeLibrary)
|
||||
: _settings(settings), _species(species), _attacks(attacks), _items(items),
|
||||
_growthRates(growthRates), _typeLibrary(typeLibrary){
|
||||
: _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates),
|
||||
_typeLibrary(typeLibrary) {}
|
||||
|
||||
}
|
||||
|
||||
const CreatureLib::Library::LibrarySettings &CreatureLib::Library::DataLibrary::GetSettings() const {
|
||||
const CreatureLib::Library::LibrarySettings& CreatureLib::Library::DataLibrary::GetSettings() const {
|
||||
return _settings;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::SpeciesLibrary *CreatureLib::Library::DataLibrary::GetSpeciesLibrary() const {
|
||||
const CreatureLib::Library::SpeciesLibrary* CreatureLib::Library::DataLibrary::GetSpeciesLibrary() const {
|
||||
return _species;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::AttackLibrary *CreatureLib::Library::DataLibrary::GetAttackLibrary() const {
|
||||
const CreatureLib::Library::AttackLibrary* CreatureLib::Library::DataLibrary::GetAttackLibrary() const {
|
||||
return _attacks;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::ItemLibrary *CreatureLib::Library::DataLibrary::GetItemLibrary() const {
|
||||
return _items;
|
||||
}
|
||||
const CreatureLib::Library::ItemLibrary* CreatureLib::Library::DataLibrary::GetItemLibrary() const { return _items; }
|
||||
|
||||
const CreatureLib::Library::GrowthRateLibrary *CreatureLib::Library::DataLibrary::GetGrowthRates() const {
|
||||
const CreatureLib::Library::GrowthRateLibrary* CreatureLib::Library::DataLibrary::GetGrowthRates() const {
|
||||
return _growthRates;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::TypeLibrary *CreatureLib::Library::DataLibrary::GetTypeLibrary() const {
|
||||
const CreatureLib::Library::TypeLibrary* CreatureLib::Library::DataLibrary::GetTypeLibrary() const {
|
||||
return _typeLibrary;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#ifndef CREATURELIB_DATALIBRARY_HPP
|
||||
#define CREATURELIB_DATALIBRARY_HPP
|
||||
|
||||
#include "SpeciesLibrary.hpp"
|
||||
#include "AttackLibrary.hpp"
|
||||
#include "ItemLibrary.hpp"
|
||||
#include "GrowthRates/GrowthRateLibrary.hpp"
|
||||
#include "ItemLibrary.hpp"
|
||||
#include "LibrarySettings.hpp"
|
||||
#include "SpeciesLibrary.hpp"
|
||||
#include "TypeLibrary.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
/*!
|
||||
\brief The core library. This library holds all static data for a creature set.
|
||||
*/
|
||||
class DataLibrary {
|
||||
@@ -20,16 +20,13 @@ namespace CreatureLib::Library {
|
||||
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,
|
||||
TypeLibrary* typeLibrary
|
||||
);
|
||||
|
||||
~DataLibrary(){
|
||||
public:
|
||||
DataLibrary(LibrarySettings settings, CreatureLib::Library::SpeciesLibrary* species,
|
||||
CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items,
|
||||
CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary);
|
||||
|
||||
~DataLibrary() {
|
||||
delete _species;
|
||||
delete _attacks;
|
||||
delete _items;
|
||||
@@ -46,5 +43,4 @@ namespace CreatureLib::Library {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_DATALIBRARY_HPP
|
||||
#endif // CREATURELIB_DATALIBRARY_HPP
|
||||
|
||||
@@ -3,16 +3,12 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace CreatureLib::Library{
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
\brief Might be somewhat controversial nowadays, but as many creature battling games only have two genders, we'll
|
||||
hardcode those.
|
||||
*/
|
||||
enum class Gender : uint8_t {
|
||||
Male,
|
||||
Female,
|
||||
Genderless
|
||||
};
|
||||
enum class Gender : uint8_t { Male, Female, Genderless };
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_GENDER_HPP
|
||||
#endif // CREATURELIB_GENDER_HPP
|
||||
|
||||
@@ -11,4 +11,4 @@ namespace CreatureLib::Library {
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_GROWTHRATE_HPP
|
||||
#endif // CREATURELIB_GROWTHRATE_HPP
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "GrowthRateLibrary.hpp"
|
||||
|
||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const std::string &growthRate, uint32_t experience) const {
|
||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const std::string& growthRate,
|
||||
uint32_t experience) const {
|
||||
return _growthRates.at(growthRate)->CalculateLevel(experience);
|
||||
}
|
||||
|
||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const std::string &growthRate, uint8_t level) const {
|
||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const std::string& growthRate,
|
||||
uint8_t level) const {
|
||||
return _growthRates.at(growthRate)->CalculateExperience(level);
|
||||
}
|
||||
|
||||
@@ -6,14 +6,15 @@
|
||||
#include <unordered_map>
|
||||
#include "GrowthRate.hpp"
|
||||
|
||||
namespace CreatureLib::Library{
|
||||
namespace CreatureLib::Library {
|
||||
class GrowthRateLibrary {
|
||||
private:
|
||||
std::unordered_map<std::string, GrowthRate*> _growthRates;
|
||||
|
||||
public:
|
||||
[[nodiscard]] uint8_t CalculateLevel(const std::string& growthRate, uint32_t experience) const;
|
||||
[[nodiscard]] uint32_t CalculateExperience(const std::string& growthRate, uint8_t level) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_GROWTHRATELIBRARY_HPP
|
||||
#endif // CREATURELIB_GROWTHRATELIBRARY_HPP
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
#include "ItemLibrary.hpp"
|
||||
|
||||
const CreatureLib::Library::Item *CreatureLib::Library::ItemLibrary::GetItem(const std::string &name) const {
|
||||
const CreatureLib::Library::Item* CreatureLib::Library::ItemLibrary::GetItem(const std::string& name) const {
|
||||
return this->_items.at(name);
|
||||
}
|
||||
|
||||
const CreatureLib::Library::Item *CreatureLib::Library::ItemLibrary::operator[](const std::string &name) const {
|
||||
const CreatureLib::Library::Item* CreatureLib::Library::ItemLibrary::operator[](const std::string& name) const {
|
||||
return this->GetItem(name);
|
||||
}
|
||||
|
||||
void CreatureLib::Library::ItemLibrary::LoadItem(const std::string &name, const CreatureLib::Library::Item *item) {
|
||||
void CreatureLib::Library::ItemLibrary::LoadItem(const std::string& name, const CreatureLib::Library::Item* item) {
|
||||
this->_items.insert({name, item});
|
||||
}
|
||||
|
||||
void CreatureLib::Library::ItemLibrary::DeleteItem(const std::string &name) {
|
||||
this->_items.erase(name);
|
||||
}
|
||||
void CreatureLib::Library::ItemLibrary::DeleteItem(const std::string& name) { this->_items.erase(name); }
|
||||
|
||||
@@ -8,21 +8,18 @@
|
||||
namespace CreatureLib::Library {
|
||||
class ItemLibrary {
|
||||
private:
|
||||
std::unordered_map<std::string, const Item *> _items;
|
||||
std::unordered_map<std::string, const Item*> _items;
|
||||
|
||||
public:
|
||||
ItemLibrary() = default;
|
||||
~ItemLibrary(){
|
||||
_items.clear();
|
||||
}
|
||||
~ItemLibrary() { _items.clear(); }
|
||||
|
||||
[[nodiscard]] const Item* GetItem(const std::string& name) const;
|
||||
[[nodiscard]] const Item* operator[] (const std::string& name) const;
|
||||
[[nodiscard]] const Item* operator[](const std::string& name) const;
|
||||
|
||||
void LoadItem(const std::string& name, const Item* item);
|
||||
void DeleteItem(const std::string& name);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_ITEMLIBRARY_HPP
|
||||
#endif // CREATURELIB_ITEMLIBRARY_HPP
|
||||
|
||||
@@ -4,13 +4,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
enum class BattleItemCategory : uint8_t {
|
||||
None,
|
||||
Healing,
|
||||
StatusHealing,
|
||||
CaptureDevice,
|
||||
MiscBattleItem
|
||||
};
|
||||
enum class BattleItemCategory : uint8_t { None, Healing, StatusHealing, CaptureDevice, MiscBattleItem };
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_BATTLEITEMCATEGORY_HPP
|
||||
#endif // CREATURELIB_BATTLEITEMCATEGORY_HPP
|
||||
|
||||
@@ -3,18 +3,20 @@
|
||||
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include "ItemCategory.hpp"
|
||||
#include "BattleItemCategory.hpp"
|
||||
#include "../../GenericTemplates.cpp"
|
||||
#include "BattleItemCategory.hpp"
|
||||
#include "ItemCategory.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class Item {
|
||||
GetProperty(std::string, Name);
|
||||
GetProperty(ItemCategory, Category);
|
||||
GetProperty(BattleItemCategory, BattleCategory);
|
||||
GetProperty(int32_t , Price);
|
||||
GetProperty(int32_t, Price);
|
||||
|
||||
private:
|
||||
std::unordered_set<std::string> _flags;
|
||||
|
||||
public:
|
||||
Item(std::string name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
|
||||
std::unordered_set<std::string> flags);
|
||||
@@ -23,4 +25,4 @@ namespace CreatureLib::Library {
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_ITEM_HPP
|
||||
#endif // CREATURELIB_ITEM_HPP
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace CreatureLib::Library{
|
||||
namespace CreatureLib::Library {
|
||||
enum class ItemCategory : uint8_t {
|
||||
MiscItem,
|
||||
CaptureDevice,
|
||||
@@ -16,4 +16,4 @@ namespace CreatureLib::Library{
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_ITEMCATEGORY_HPP
|
||||
#endif // CREATURELIB_ITEMCATEGORY_HPP
|
||||
|
||||
@@ -4,21 +4,18 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class LibrarySettings{
|
||||
class LibrarySettings {
|
||||
uint8_t _maximalLevel;
|
||||
uint8_t _maximalMoves;
|
||||
|
||||
public:
|
||||
LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves)
|
||||
: _maximalLevel(maximalLevel), _maximalMoves(maximalMoves){}
|
||||
: _maximalLevel(maximalLevel), _maximalMoves(maximalMoves) {}
|
||||
|
||||
inline uint8_t GetMaximalLevel() const{
|
||||
return _maximalLevel;
|
||||
}
|
||||
inline uint8_t GetMaximalLevel() const { return _maximalLevel; }
|
||||
|
||||
inline uint8_t GetMaximalMoves() const{
|
||||
return _maximalMoves;
|
||||
}
|
||||
inline uint8_t GetMaximalMoves() const { return _maximalMoves; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_LIBRARYSETTINGS_HPP
|
||||
#endif // CREATURELIB_LIBRARYSETTINGS_HPP
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
#include "SpeciesLibrary.hpp"
|
||||
|
||||
const CreatureLib::Library::CreatureSpecies *CreatureLib::Library::SpeciesLibrary::GetSpecies(const std::string& name) const{
|
||||
const CreatureLib::Library::CreatureSpecies*
|
||||
CreatureLib::Library::SpeciesLibrary::GetSpecies(const std::string& name) const {
|
||||
return _species.at(name);
|
||||
}
|
||||
|
||||
const CreatureLib::Library::CreatureSpecies* CreatureLib::Library::SpeciesLibrary::operator[](const std::string &name) const{
|
||||
const CreatureLib::Library::CreatureSpecies*
|
||||
CreatureLib::Library::SpeciesLibrary::operator[](const std::string& name) const {
|
||||
return GetSpecies(name);
|
||||
}
|
||||
|
||||
void CreatureLib::Library::SpeciesLibrary::LoadSpecies(const std::string &name,
|
||||
void CreatureLib::Library::SpeciesLibrary::LoadSpecies(const std::string& name,
|
||||
const CreatureLib::Library::CreatureSpecies* species) {
|
||||
_species.insert({name, species});
|
||||
}
|
||||
|
||||
void CreatureLib::Library::SpeciesLibrary::DeleteSpecies(const std::string &name) {
|
||||
_species.erase(name);
|
||||
}
|
||||
|
||||
void CreatureLib::Library::SpeciesLibrary::DeleteSpecies(const std::string& name) { _species.erase(name); }
|
||||
|
||||
@@ -9,22 +9,22 @@ namespace CreatureLib::Library {
|
||||
class SpeciesLibrary {
|
||||
private:
|
||||
std::unordered_map<std::string, const CreatureSpecies*> _species;
|
||||
|
||||
public:
|
||||
SpeciesLibrary() = default;
|
||||
|
||||
~SpeciesLibrary(){
|
||||
for (auto s: _species)
|
||||
~SpeciesLibrary() {
|
||||
for (auto s : _species)
|
||||
delete s.second;
|
||||
_species.clear();
|
||||
}
|
||||
|
||||
[[nodiscard]] const CreatureSpecies* GetSpecies(const std::string& name) const;
|
||||
[[nodiscard]] const CreatureSpecies* operator[] (const std::string& name) const;
|
||||
[[nodiscard]] const CreatureSpecies* operator[](const std::string& name) const;
|
||||
|
||||
void LoadSpecies(const std::string& name, const CreatureSpecies* species);
|
||||
void DeleteSpecies(const std::string& name);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_SPECIESLIBRARY_HPP
|
||||
#endif // CREATURELIB_SPECIESLIBRARY_HPP
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
float TypeLibrary::GetEffectiveness(uint8_t attacking, const std::vector<uint8_t> &defensive) const {
|
||||
float TypeLibrary::GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const {
|
||||
auto eff = 1;
|
||||
for (auto def: defensive){
|
||||
for (auto def : defensive) {
|
||||
eff *= GetSingleEffectiveness(attacking, def);
|
||||
}
|
||||
return eff;
|
||||
@@ -14,14 +14,12 @@ float TypeLibrary::GetSingleEffectiveness(uint8_t attacking, uint8_t defensive)
|
||||
return _effectiveness[attacking][defensive];
|
||||
}
|
||||
|
||||
uint8_t TypeLibrary::GetTypeId(const std::string &s) const {
|
||||
return _types.at(s);
|
||||
}
|
||||
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){
|
||||
for (auto& eff : _effectiveness) {
|
||||
eff.resize(_types.size(), 1);
|
||||
}
|
||||
return _types.size() - 1;
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace CreatureLib::Library{
|
||||
namespace CreatureLib::Library {
|
||||
class TypeLibrary {
|
||||
std::unordered_map<std::string, uint8_t > _types;
|
||||
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;
|
||||
@@ -18,5 +19,4 @@ namespace CreatureLib::Library{
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_TYPELIBRARY_HPP
|
||||
#endif // CREATURELIB_TYPELIBRARY_HPP
|
||||
|
||||
Reference in New Issue
Block a user