Initial commit
This commit is contained in:
16
src/Library/CreatureData/CreatureMoves.cpp
Normal file
16
src/Library/CreatureData/CreatureMoves.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "CreatureMoves.hpp"
|
||||
#include <utility>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
32
src/Library/CreatureData/CreatureMoves.hpp
Normal file
32
src/Library/CreatureData/CreatureMoves.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef CREATURELIB_CREATUREMOVES_HPP
|
||||
#define CREATURELIB_CREATUREMOVES_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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;
|
||||
[[nodiscard]] inline std::string GetName() const;
|
||||
};
|
||||
|
||||
class CreatureMoves {
|
||||
private:
|
||||
std::vector<LevelMove> _levelMoves;
|
||||
std::vector<std::string> _eggMoves;
|
||||
std::vector<std::string> _machineMoves;
|
||||
std::vector<std::string> _tutorMoves;
|
||||
std::vector<std::string> _variantDependentMoves;
|
||||
public:
|
||||
//TODO: Public API funcs
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_CREATUREMOVES_HPP
|
||||
28
src/Library/CreatureData/CreatureSpecies.cpp
Normal file
28
src/Library/CreatureData/CreatureSpecies.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "CreatureSpecies.hpp"
|
||||
|
||||
#include <utility>
|
||||
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),
|
||||
__Name(std::move(name)),
|
||||
__GenderRate(genderRatio),
|
||||
__GrowthRate(std::move(growthRate)),
|
||||
__CaptureRate(captureRate),
|
||||
__BaseHappiness(baseHappiness),
|
||||
_variants({{"default", defaultVariant}})
|
||||
{}
|
||||
|
||||
const SpeciesVariant *CreatureSpecies::GetVariant(const std::string& key) const {
|
||||
return _variants.at(key);
|
||||
}
|
||||
|
||||
Gender CreatureSpecies::GetRandomGender(CreatureLib::Core::Random &rand) const {
|
||||
// TODO: Genderless creatures
|
||||
auto val = rand.GetDouble();
|
||||
if (val >= this->__GenderRate) return Gender ::Female;
|
||||
return Gender ::Male;
|
||||
}
|
||||
|
||||
31
src/Library/CreatureData/CreatureSpecies.hpp
Normal file
31
src/Library/CreatureData/CreatureSpecies.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef CREATURELIB_CREATURESPECIES_HPP
|
||||
#define CREATURELIB_CREATURESPECIES_HPP
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "SpeciesVariant.hpp"
|
||||
#include "../Gender.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.
|
||||
*/
|
||||
class CreatureSpecies {
|
||||
GetProperty(uint16_t, Id);
|
||||
GetProperty(std::string, Name);
|
||||
GetProperty(float, GenderRate);
|
||||
GetProperty(std::string, GrowthRate);
|
||||
GetProperty(uint8_t, CaptureRate);
|
||||
GetProperty(uint8_t, BaseHappiness);
|
||||
private:
|
||||
std::unordered_map<std::string, const SpeciesVariant*> _variants;
|
||||
public:
|
||||
CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, std::string growthRate, uint8_t captureRate, uint8_t baseHappiness);
|
||||
|
||||
[[nodiscard]] const SpeciesVariant* GetVariant(const std::string& key) const;
|
||||
[[nodiscard]] Gender GetRandomGender(Core::Random& rand) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_CREATURESPECIES_HPP
|
||||
58
src/Library/CreatureData/SpeciesVariant.cpp
Normal file
58
src/Library/CreatureData/SpeciesVariant.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "SpeciesVariant.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const {
|
||||
return _types.size();
|
||||
}
|
||||
|
||||
std::string 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);
|
||||
}
|
||||
|
||||
std::string CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index) const {
|
||||
if (index < 0){
|
||||
index = -index - 1;
|
||||
return _secretTalents[index];
|
||||
}
|
||||
return _talents[index];
|
||||
}
|
||||
|
||||
/*const CreatureLib::Library::CreatureMoves *CreatureLib::Library::SpeciesVariant::GetCreatureMoves() const {
|
||||
return &_moves;
|
||||
}*/
|
||||
|
||||
int8_t CreatureLib::Library::SpeciesVariant::GetTalentIndex(std::string talent) const{
|
||||
auto i = std::find(_talents.begin(), _talents.end(), talent);
|
||||
if (i != _talents.end()){
|
||||
return std::distance(_talents.begin(), i);
|
||||
}
|
||||
i = std::find(_secretTalents.begin(), _secretTalents.end(), talent);
|
||||
if (i != _secretTalents.end()){
|
||||
return std::distance(_secretTalents.begin(), i);
|
||||
}
|
||||
//TODO: implement better exception.
|
||||
throw;
|
||||
}
|
||||
|
||||
int8_t CreatureLib::Library::SpeciesVariant::GetRandomTalent(CreatureLib::Core::Random *rand) const {
|
||||
return rand->Get(_talents.size());
|
||||
}
|
||||
|
||||
CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float height, float weight,
|
||||
uint32_t baseExperience, std::vector<std::string> types,
|
||||
CreatureLib::Core::StatisticSet baseStats,
|
||||
std::vector<std::string> talents,
|
||||
std::vector<std::string> secretTalents)
|
||||
: __Name(name),
|
||||
__Height(height),
|
||||
__Weight(weight),
|
||||
__BaseExperience(baseExperience),
|
||||
_types(types),
|
||||
_baseStatistics(baseStats),
|
||||
_talents(talents),
|
||||
_secretTalents(secretTalents)
|
||||
{}
|
||||
40
src/Library/CreatureData/SpeciesVariant.hpp
Normal file
40
src/Library/CreatureData/SpeciesVariant.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef CREATURELIB_SPECIESVARIANT_HPP
|
||||
#define CREATURELIB_SPECIESVARIANT_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "CreatureMoves.hpp"
|
||||
#include "../../Core/StatisticSet.hpp"
|
||||
#include "../../GenericTemplates.cpp"
|
||||
#include "../../Core/Random.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
\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<std::string> _types;
|
||||
const Core::StatisticSet _baseStatistics;
|
||||
std::vector<std::string> _talents;
|
||||
std::vector<std::string> _secretTalents;
|
||||
//CreatureMoves _moves;
|
||||
public:
|
||||
SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience,
|
||||
std::vector<std::string> types, Core::StatisticSet baseStats, std::vector<std::string> talents,
|
||||
std::vector<std::string> secretTalents);
|
||||
[[nodiscard]] size_t GetTypeCount() const;
|
||||
[[nodiscard]] std::string GetType(size_t index) const;
|
||||
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;
|
||||
[[nodiscard]] std::string GetTalent(int32_t index) const;
|
||||
//[[nodiscard]] const CreatureMoves* GetCreatureMoves() const;
|
||||
[[nodiscard]] int8_t GetTalentIndex(std::string talent) const;
|
||||
[[nodiscard]] int8_t GetRandomTalent(Core::Random* rand) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_SPECIESVARIANT_HPP
|
||||
Reference in New Issue
Block a user