Support for learnable moves
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-10-24 11:04:19 +02:00
parent cfb7663d78
commit bb8978314f
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
15 changed files with 155 additions and 23 deletions

View File

@ -1,6 +1,5 @@
#include "CreatureSpecies.hpp" #include "CreatureSpecies.hpp"
#include <utility>
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant,

View File

@ -0,0 +1,11 @@
#include "LearnableAttacks.hpp"
using namespace CreatureLib::Library;
void LearnableAttacks::AddLevelMove(uint8_t level, AttackData *attack) {
_learnedByLevel[level].push_back(attack);
}
const std::vector<const AttackData *> &LearnableAttacks::GetMovesForLevel(uint8_t level) const {
return _learnedByLevel[level];
}

View File

@ -0,0 +1,21 @@
#ifndef CREATURELIB_LEARNABLEATTACKS_HPP
#define CREATURELIB_LEARNABLEATTACKS_HPP
#include <vector>
#include "../Attacks/AttackData.hpp"
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)){}
void AddLevelMove(uint8_t level, AttackData* attack);
const std::vector<const AttackData*>& GetMovesForLevel(uint8_t level) const;
};
}
#endif //CREATURELIB_LEARNABLEATTACKS_HPP

View File

@ -42,11 +42,15 @@ int8_t CreatureLib::Library::SpeciesVariant::GetRandomTalent(CreatureLib::Core::
return rand->Get(_talents.size()); return rand->Get(_talents.size());
} }
const CreatureLib::Library::LearnableAttacks *CreatureLib::Library::SpeciesVariant::GetLearnableAttacks() const {
return _attacks;
}
CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float height, float weight, CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float height, float weight,
uint32_t baseExperience, std::vector<std::string> types, uint32_t baseExperience, std::vector<std::string> types,
CreatureLib::Core::StatisticSet<uint16_t > baseStats, CreatureLib::Core::StatisticSet<uint16_t > baseStats,
std::vector<std::string> talents, std::vector<std::string> talents,
std::vector<std::string> secretTalents) std::vector<std::string> secretTalents, const LearnableAttacks* attacks)
: __Name(name), : __Name(name),
__Height(height), __Height(height),
__Weight(weight), __Weight(weight),
@ -54,5 +58,10 @@ CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float hei
_types(types), _types(types),
_baseStatistics(baseStats), _baseStatistics(baseStats),
_talents(talents), _talents(talents),
_secretTalents(secretTalents) _secretTalents(secretTalents),
_attacks(attacks)
{} {}
CreatureLib::Library::SpeciesVariant::~SpeciesVariant() {
delete _attacks;
}

View File

@ -7,6 +7,7 @@
#include "../../Core/StatisticSet.hpp" #include "../../Core/StatisticSet.hpp"
#include "../../GenericTemplates.cpp" #include "../../GenericTemplates.cpp"
#include "../../Core/Random.hpp" #include "../../Core/Random.hpp"
#include "LearnableAttacks.hpp"
namespace CreatureLib::Library { namespace CreatureLib::Library {
/*! /*!
@ -22,17 +23,19 @@ namespace CreatureLib::Library {
const Core::StatisticSet<uint16_t > _baseStatistics; const Core::StatisticSet<uint16_t > _baseStatistics;
std::vector<std::string> _talents; std::vector<std::string> _talents;
std::vector<std::string> _secretTalents; std::vector<std::string> _secretTalents;
//CreatureMoves _moves; const LearnableAttacks* _attacks;
public: public:
SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience, SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience,
std::vector<std::string> types, Core::StatisticSet<uint16_t > baseStats, std::vector<std::string> talents, std::vector<std::string> types, Core::StatisticSet<uint16_t > baseStats, std::vector<std::string> talents,
std::vector<std::string> secretTalents); std::vector<std::string> secretTalents, const LearnableAttacks* attacks);
~SpeciesVariant();
[[nodiscard]] size_t GetTypeCount() const; [[nodiscard]] size_t GetTypeCount() const;
[[nodiscard]] std::string GetType(size_t index) const; [[nodiscard]] std::string GetType(size_t index) const;
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const; [[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;
[[nodiscard]] std::string GetTalent(int32_t index) const; [[nodiscard]] std::string GetTalent(int32_t index) const;
//[[nodiscard]] const CreatureMoves* GetCreatureMoves() const; [[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const;
[[nodiscard]] int8_t GetTalentIndex(std::string talent) const; [[nodiscard]] int8_t GetTalentIndex(std::string talent) const;
[[nodiscard]] int8_t GetRandomTalent(Core::Random* rand) const; [[nodiscard]] int8_t GetRandomTalent(Core::Random* rand) const;
}; };

View File

@ -1,14 +1,19 @@
#include "DataLibrary.hpp" #include "DataLibrary.hpp"
CreatureLib::Library::DataLibrary::DataLibrary(CreatureLib::Library::SpeciesLibrary *species, CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings settings,
CreatureLib::Library::SpeciesLibrary *species,
CreatureLib::Library::AttackLibrary *attacks, CreatureLib::Library::AttackLibrary *attacks,
CreatureLib::Library::ItemLibrary *items, CreatureLib::Library::ItemLibrary *items,
CreatureLib::Library::GrowthRateLibrary *growthRates) CreatureLib::Library::GrowthRateLibrary *growthRates)
: _species(species), _attacks(attacks), _items(items), : _settings(settings), _species(species), _attacks(attacks), _items(items),
_growthRates(growthRates){ _growthRates(growthRates){
} }
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; return _species;
} }
@ -26,3 +31,4 @@ const CreatureLib::Library::GrowthRateLibrary *CreatureLib::Library::DataLibrary
} }

View File

@ -5,6 +5,7 @@
#include "AttackLibrary.hpp" #include "AttackLibrary.hpp"
#include "ItemLibrary.hpp" #include "ItemLibrary.hpp"
#include "GrowthRates/GrowthRateLibrary.hpp" #include "GrowthRates/GrowthRateLibrary.hpp"
#include "LibrarySettings.hpp"
namespace CreatureLib::Library { namespace CreatureLib::Library {
/*! /*!
@ -12,12 +13,14 @@ namespace CreatureLib::Library {
*/ */
class DataLibrary { class DataLibrary {
private: private:
const LibrarySettings _settings;
const SpeciesLibrary* _species; const SpeciesLibrary* _species;
const AttackLibrary* _attacks; const AttackLibrary* _attacks;
const ItemLibrary* _items; const ItemLibrary* _items;
const GrowthRateLibrary* _growthRates; const GrowthRateLibrary* _growthRates;
public: public:
DataLibrary(CreatureLib::Library::SpeciesLibrary *species, DataLibrary(LibrarySettings settings,
CreatureLib::Library::SpeciesLibrary *species,
CreatureLib::Library::AttackLibrary *attacks, CreatureLib::Library::AttackLibrary *attacks,
CreatureLib::Library::ItemLibrary *items, CreatureLib::Library::ItemLibrary *items,
CreatureLib::Library::GrowthRateLibrary *growthRates CreatureLib::Library::GrowthRateLibrary *growthRates
@ -30,6 +33,7 @@ namespace CreatureLib::Library {
delete _growthRates; delete _growthRates;
} }
[[nodiscard]] const LibrarySettings& GetSettings() const;
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const; [[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const;
[[nodiscard]] const AttackLibrary* GetAttackLibrary() const; [[nodiscard]] const AttackLibrary* GetAttackLibrary() const;
[[nodiscard]] const ItemLibrary* GetItemLibrary() const; [[nodiscard]] const ItemLibrary* GetItemLibrary() const;

View File

@ -0,0 +1,24 @@
#ifndef CREATURELIB_LIBRARYSETTINGS_HPP
#define CREATURELIB_LIBRARYSETTINGS_HPP
#include <cstdint>
namespace CreatureLib::Library {
class LibrarySettings{
uint8_t _maximalLevel;
uint8_t _maximalMoves;
public:
LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves)
: _maximalLevel(maximalLevel), _maximalMoves(maximalMoves){}
inline uint8_t GetMaximalLevel() const{
return _maximalLevel;
}
inline uint8_t GetMaximalMoves() const{
return _maximalMoves;
}
};
}
#endif //CREATURELIB_LIBRARYSETTINGS_HPP

View File

@ -0,0 +1,11 @@
#ifndef CREATURELIB_ATTACKLEARNMETHOD_HPP
#define CREATURELIB_ATTACKLEARNMETHOD_HPP
namespace CreatureLib::Library {
enum class AttackLearnMethod {
Unknown,
Level
};
}
#endif //CREATURELIB_ATTACKLEARNMETHOD_HPP

View File

@ -93,5 +93,5 @@ Creature *CreateCreature::Create() {
_magAttackExperience, _magDefenseExperience, _speedExperience), _magAttackExperience, _magDefenseExperience, _speedExperience),
Core::StatisticSet(_healthPotential, _physAttackPotential, _physDefensePotential, Core::StatisticSet(_healthPotential, _physAttackPotential, _physDefensePotential,
_magAttackPotential, _magDefensePotential, _speedPotential), _magAttackPotential, _magDefensePotential, _speedPotential),
identifier, gender, _coloring, heldItem); identifier, gender, _coloring, {}, heldItem);
} }

View File

@ -1,3 +1,4 @@
#include <assert.h>
#include "Creature.hpp" #include "Creature.hpp"
CreatureLib::Library::Creature::Creature(const CreatureLib::Library::DataLibrary *library, CreatureLib::Library::Creature::Creature(const CreatureLib::Library::DataLibrary *library,
@ -7,6 +8,7 @@ CreatureLib::Library::Creature::Creature(const CreatureLib::Library::DataLibrary
CreatureLib::Core::StatisticSet<uint8_t > statExperience, CreatureLib::Core::StatisticSet<uint8_t > statExperience,
CreatureLib::Core::StatisticSet<uint8_t > statPotential, CreatureLib::Core::StatisticSet<uint8_t > statPotential,
uint32_t identifier, CreatureLib::Library::Gender gender, uint8_t coloring, uint32_t identifier, CreatureLib::Library::Gender gender, uint8_t coloring,
std::vector<LearnedAttack*> attacks,
const CreatureLib::Library::Item *heldItem) const CreatureLib::Library::Item *heldItem)
: :
__Library(library), __Library(library),
@ -20,9 +22,18 @@ CreatureLib::Library::Creature::Creature(const CreatureLib::Library::DataLibrary
__Coloring(coloring), __Coloring(coloring),
__HeldItem(heldItem), __HeldItem(heldItem),
_nickname(nickname), _nickname(nickname),
_talentIndex(talentIndex) _talentIndex(talentIndex),
_attacks(attacks)
{ {
if (_attacks.size() == 0){
//TODO: give random moves
}
}
CreatureLib::Library::Creature::~Creature() {
for (auto i: _attacks){
delete i;
}
} }
std::string CreatureLib::Library::Creature::GetTalent() const { std::string CreatureLib::Library::Creature::GetTalent() const {
@ -69,3 +80,4 @@ uint8_t CreatureLib::Library::Creature::GetStatPotential(CreatureLib::Core::Stat
uint8_t CreatureLib::Library::Creature::GetStatExperience(CreatureLib::Core::Statistic stat) const { uint8_t CreatureLib::Library::Creature::GetStatExperience(CreatureLib::Core::Statistic stat) const {
return this->__StatExperience.GetStat(stat); return this->__StatExperience.GetStat(stat);
} }

View File

@ -5,6 +5,7 @@
#include "../Gender.hpp" #include "../Gender.hpp"
#include "../../GenericTemplates.cpp" #include "../../GenericTemplates.cpp"
#include "../../Core/StatisticSet.hpp" #include "../../Core/StatisticSet.hpp"
#include "LearnedAttack.hpp"
namespace CreatureLib::Library{ namespace CreatureLib::Library{
class Creature { class Creature {
@ -24,13 +25,14 @@ namespace CreatureLib::Library{
private: private:
std::string _nickname = ""; std::string _nickname = "";
int8_t _talentIndex; int8_t _talentIndex;
std::vector<LearnedAttack*> _attacks;
public: public:
Creature(const DataLibrary* library, const CreatureSpecies* species, const SpeciesVariant* variant, Creature(const DataLibrary* library, const CreatureSpecies* species, const SpeciesVariant* variant,
uint8_t level, std::string nickname, int8_t talentIndex, Core::StatisticSet<uint8_t > statExperience, uint8_t level, std::string nickname, int8_t talentIndex, Core::StatisticSet<uint8_t > statExperience,
Core::StatisticSet<uint8_t > statPotential, uint32_t identifier, Gender gender, Core::StatisticSet<uint8_t > statPotential, uint32_t identifier, Gender gender,
uint8_t coloring, const Item* heldItem); uint8_t coloring, std::vector<LearnedAttack*> attacks, const Item* heldItem);
virtual ~Creature(){} virtual ~Creature();
std::string GetTalent() const; std::string GetTalent() const;
std::string GetNickname() const; std::string GetNickname() const;

View File

@ -1,7 +1,7 @@
#include "LearnedAttack.hpp" #include "LearnedAttack.hpp"
CreatureLib::Library::LearnedAttack::LearnedAttack(CreatureLib::Library::AttackData *attack, uint8_t maxUses) CreatureLib::Library::LearnedAttack::LearnedAttack(CreatureLib::Library::AttackData *attack, uint8_t maxUses, AttackLearnMethod learnMethod)
:_attack(attack), _maxUses(maxUses), _remainingUses(maxUses) :_attack(attack), _maxUses(maxUses), _remainingUses(maxUses), _learnMethod(learnMethod)
{ {
} }
@ -17,3 +17,28 @@ uint8_t CreatureLib::Library::LearnedAttack::GetMaxUses() const {
uint8_t CreatureLib::Library::LearnedAttack::GetRemainingUses() const { uint8_t CreatureLib::Library::LearnedAttack::GetRemainingUses() const {
return _remainingUses; return _remainingUses;
} }
CreatureLib::Library::AttackLearnMethod CreatureLib::Library::LearnedAttack::GetLearnMethod() const {
return _learnMethod;
}
bool CreatureLib::Library::LearnedAttack::TryUse(uint8_t uses) {
if (uses > _remainingUses) return false;
_remainingUses -= uses;
return true;
}
void CreatureLib::Library::LearnedAttack::DecreaseUses(uint8_t amount) {
_remainingUses -= amount;
}
void CreatureLib::Library::LearnedAttack::RestoreUses(uint8_t amount) {
_remainingUses += amount;
}
void CreatureLib::Library::LearnedAttack::RestoreUses() {
_remainingUses = _maxUses;
}

View File

@ -2,18 +2,26 @@
#define CREATURELIB_LEARNEDATTACK_HPP #define CREATURELIB_LEARNEDATTACK_HPP
#include "../Attacks/AttackData.hpp" #include "../Attacks/AttackData.hpp"
#include "AttackLearnMethod.hpp"
namespace CreatureLib::Library{ namespace CreatureLib::Library{
class LearnedAttack { class LearnedAttack {
const AttackData* _attack; const AttackData* _attack;
uint8_t _maxUses; uint8_t _maxUses;
uint8_t _remainingUses; uint8_t _remainingUses;
AttackLearnMethod _learnMethod;
public: public:
LearnedAttack(AttackData* attack, uint8_t maxUses); LearnedAttack(AttackData* attack, uint8_t maxUses, AttackLearnMethod learnMethod);
const AttackData* GetAttack() const; const AttackData* GetAttack() const;
uint8_t GetMaxUses() const; uint8_t GetMaxUses() const;
uint8_t GetRemainingUses() const; uint8_t GetRemainingUses() const;
AttackLearnMethod GetLearnMethod() const;
bool TryUse(uint8_t uses);
void DecreaseUses(uint8_t amount);
void RestoreUses(uint8_t amount);
void RestoreUses();
}; };
} }

View File

@ -11,7 +11,8 @@ static SpeciesLibrary* BuildSpeciesLibrary(){
l->LoadSpecies("testSpecies1", new CreatureSpecies(0, "testSpecies1", l->LoadSpecies("testSpecies1", new CreatureSpecies(0, "testSpecies1",
new SpeciesVariant("default", 1,1, 10, {"fire", "water"}, new SpeciesVariant("default", 1,1, 10, {"fire", "water"},
StatisticSet<uint16_t >(10,10,10,10,10,10), StatisticSet<uint16_t >(10,10,10,10,10,10),
{"testTalent"}, {"testSecretTalent"}), {"testTalent"}, {"testSecretTalent"},
new LearnableAttacks(100)),
0.5f, "testGrowthRate", 5, 100)); 0.5f, "testGrowthRate", 5, 100));
return l; return l;
} }
@ -33,7 +34,8 @@ static GrowthRateLibrary* BuildGrowthRateLibrary(){
static DataLibrary* BuildLibrary(){ static DataLibrary* BuildLibrary(){
auto l = new DataLibrary(BuildSpeciesLibrary(), BuildAttackLibrary(), BuildItemLibrary(), BuildGrowthRateLibrary()); auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
BuildItemLibrary(), BuildGrowthRateLibrary());
return l; return l;
} }
@ -44,9 +46,4 @@ static DataLibrary* GetLibrary(){
} }
return __library; return __library;
} }
#ifndef LIBRARY_BUILD_TESTS
#define LIBRARY_BUILD_TESTS
#endif
#endif #endif