Implements ConstString in several core places in the library, improving performance.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
1d3a8da99e
commit
412e0a4d63
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
using namespace CreatureLib::Battling;
|
using namespace CreatureLib::Battling;
|
||||||
|
|
||||||
CreateCreature* CreateCreature::WithVariant(std::string variant) {
|
CreateCreature* CreateCreature::WithVariant(const Arbutils::CaseInsensitiveConstString& variant) {
|
||||||
this->_variant = std::move(variant);
|
this->_variant = variant;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,18 +20,19 @@ CreateCreature* CreateCreature::WithGender(Library::Gender gender) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateCreature* CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) {
|
CreateCreature* CreateCreature::WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
|
||||||
|
AttackLearnMethod learnMethod) {
|
||||||
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves())
|
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves())
|
||||||
throw CreatureException("You have already set the maximum amount of allowed moves.");
|
throw CreatureException("You have already set the maximum amount of allowed moves.");
|
||||||
|
|
||||||
auto attackData = _library->GetAttackLibrary()->Get(attackName.c_str());
|
auto attackData = _library->GetAttackLibrary()->Get(attackName);
|
||||||
_attacks.emplace_back(attackData, learnMethod);
|
_attacks.emplace_back(attackData, learnMethod);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Creature* CreateCreature::Create() {
|
Creature* CreateCreature::Create() {
|
||||||
auto rand = Arbutils::Random();
|
auto rand = Arbutils::Random();
|
||||||
auto species = this->_library->GetSpeciesLibrary()->Get(this->_species.c_str());
|
auto species = this->_library->GetSpeciesLibrary()->Get(this->_species);
|
||||||
auto variant = species->GetVariant(this->_variant);
|
auto variant = species->GetVariant(this->_variant);
|
||||||
int8_t talent;
|
int8_t talent;
|
||||||
if (this->_talent.empty()) {
|
if (this->_talent.empty()) {
|
||||||
|
@ -48,8 +49,8 @@ Creature* CreateCreature::Create() {
|
||||||
gender = species->GetRandomGender(rand);
|
gender = species->GetRandomGender(rand);
|
||||||
}
|
}
|
||||||
const Library::Item* heldItem = nullptr;
|
const Library::Item* heldItem = nullptr;
|
||||||
if (!this->_heldItem.empty()) {
|
if (!this->_heldItem.Empty()) {
|
||||||
if (!_library->GetItemLibrary()->TryGet(this->_heldItem.c_str(), heldItem)) {
|
if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) {
|
||||||
throw CreatureException("Invalid held item.");
|
throw CreatureException("Invalid held item.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,15 @@
|
||||||
namespace CreatureLib::Battling {
|
namespace CreatureLib::Battling {
|
||||||
class CreateCreature {
|
class CreateCreature {
|
||||||
const BattleLibrary* _library;
|
const BattleLibrary* _library;
|
||||||
std::string _species;
|
Arbutils::CaseInsensitiveConstString _species;
|
||||||
std::string _variant = "default";
|
Arbutils::CaseInsensitiveConstString _variant = "default"_cnc;
|
||||||
uint8_t _level;
|
uint8_t _level;
|
||||||
std::string _nickname = "";
|
std::string _nickname = "";
|
||||||
|
|
||||||
std::string _talent = "";
|
std::string _talent = "";
|
||||||
Library::Gender _gender = static_cast<Library::Gender>(-1);
|
Library::Gender _gender = static_cast<Library::Gender>(-1);
|
||||||
uint8_t _coloring = 0;
|
uint8_t _coloring = 0;
|
||||||
std::string _heldItem = "";
|
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc;
|
||||||
uint32_t _identifier = 0;
|
uint32_t _identifier = 0;
|
||||||
std::vector<std::tuple<const Library::AttackData*, AttackLearnMethod>> _attacks = {};
|
std::vector<std::tuple<const Library::AttackData*, AttackLearnMethod>> _attacks = {};
|
||||||
|
|
||||||
|
@ -23,10 +23,11 @@ namespace CreatureLib::Battling {
|
||||||
CreateCreature(const BattleLibrary* library, std::string species, uint8_t level)
|
CreateCreature(const BattleLibrary* library, std::string species, uint8_t level)
|
||||||
: _library(library), _species(std::move(species)), _level(level) {}
|
: _library(library), _species(std::move(species)), _level(level) {}
|
||||||
|
|
||||||
CreateCreature* WithVariant(std::string variant);
|
CreateCreature* WithVariant(const Arbutils::CaseInsensitiveConstString& variant);
|
||||||
CreateCreature* WithNickname(std::string nickname);
|
CreateCreature* WithNickname(std::string nickname);
|
||||||
CreateCreature* WithGender(Library::Gender gender);
|
CreateCreature* WithGender(Library::Gender gender);
|
||||||
CreateCreature* WithAttack(const std::string& attackName, AttackLearnMethod learnMethod);
|
CreateCreature* WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
|
||||||
|
AttackLearnMethod learnMethod);
|
||||||
|
|
||||||
Creature* Create();
|
Creature* Create();
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,11 @@ Battling::Creature::Creature(const BattleLibrary* library, const Library::Creatu
|
||||||
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience),
|
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience),
|
||||||
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _nickname(std::move(nickname)),
|
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _nickname(std::move(nickname)),
|
||||||
_talentIndex(talent), _hasOverridenTalent(false), _attacks(std::move(attacks)) {
|
_talentIndex(talent), _hasOverridenTalent(false), _attacks(std::move(attacks)) {
|
||||||
|
|
||||||
_activeTalent = _library->LoadScript(ScriptCategory::Talent, GetActiveTalent());
|
_activeTalent = _library->LoadScript(ScriptCategory::Talent, GetActiveTalent());
|
||||||
|
if (_nickname.empty()) {
|
||||||
|
_nickname = species->GetName().std_str();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battling::Creature::ChangeLevel(int8_t amount) {
|
void Battling::Creature::ChangeLevel(int8_t amount) {
|
||||||
|
@ -21,12 +25,6 @@ void Battling::Creature::ChangeLevel(int8_t amount) {
|
||||||
RecalculateFlatStats();
|
RecalculateFlatStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Battling::Creature::GetNickname() const {
|
|
||||||
if (_nickname.empty())
|
|
||||||
return _species->GetName();
|
|
||||||
return _nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& Battling::Creature::GetActiveTalent() const {
|
const std::string& Battling::Creature::GetActiveTalent() const {
|
||||||
if (_hasOverridenTalent) {
|
if (_hasOverridenTalent) {
|
||||||
return _overridenTalentName;
|
return _overridenTalentName;
|
||||||
|
@ -178,7 +176,7 @@ const Library::SpeciesVariant* Battling::Creature::GetDisplayVariant() const {
|
||||||
variant = _variant;
|
variant = _variant;
|
||||||
return variant;
|
return variant;
|
||||||
}
|
}
|
||||||
void Battling::Creature::SetHeldItem(const std::string& itemName) {
|
void Battling::Creature::SetHeldItem(const Arbutils::CaseInsensitiveConstString& itemName) {
|
||||||
const Library::Item* item;
|
const Library::Item* item;
|
||||||
if (!_library->GetItemLibrary()->TryGet(itemName, item)) {
|
if (!_library->GetItemLibrary()->TryGet(itemName, item)) {
|
||||||
throw CreatureException("Item not found.");
|
throw CreatureException("Item not found.");
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace CreatureLib::Battling {
|
||||||
return _heldItem != nullptr && _heldItem->GetName() == name;
|
return _heldItem != nullptr && _heldItem->GetName() == name;
|
||||||
}
|
}
|
||||||
inline const Library::Item* GetHeldItem() const { return _heldItem; }
|
inline const Library::Item* GetHeldItem() const { return _heldItem; }
|
||||||
void SetHeldItem(const std::string& itemName);
|
void SetHeldItem(const Arbutils::CaseInsensitiveConstString& itemName);
|
||||||
inline void SetHeldItem(const Library::Item* item) { _heldItem = item; };
|
inline void SetHeldItem(const Library::Item* item) { _heldItem = item; };
|
||||||
|
|
||||||
inline uint32_t GetCurrentHealth() const { return _currentHealth; }
|
inline uint32_t GetCurrentHealth() const { return _currentHealth; }
|
||||||
|
@ -97,7 +97,7 @@ namespace CreatureLib::Battling {
|
||||||
void SetOnBattleField(bool value) { _onBattleField = value; }
|
void SetOnBattleField(bool value) { _onBattleField = value; }
|
||||||
bool IsOnBattleField() const { return _onBattleField; }
|
bool IsOnBattleField() const { return _onBattleField; }
|
||||||
|
|
||||||
const std::string& GetNickname() const;
|
const std::string& GetNickname() const { return _nickname; }
|
||||||
const std::string& GetActiveTalent() const;
|
const std::string& GetActiveTalent() const;
|
||||||
|
|
||||||
[[nodiscard]] bool IsFainted() const;
|
[[nodiscard]] bool IsFainted() const;
|
||||||
|
|
|
@ -5,10 +5,10 @@ CreatureLib::Library::AttackData::AttackData(std::string name, uint8_t type,
|
||||||
CreatureLib::Library::AttackCategory category, uint8_t power,
|
CreatureLib::Library::AttackCategory category, uint8_t power,
|
||||||
uint8_t accuracy, uint8_t baseUsage,
|
uint8_t accuracy, uint8_t baseUsage,
|
||||||
CreatureLib::Library::AttackTarget target, int8_t priority,
|
CreatureLib::Library::AttackTarget target, int8_t priority,
|
||||||
std::unordered_set<std::string> flags)
|
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags)
|
||||||
: _name(std::move(name)), _type(type), _category(category), _basePower(power), _accuracy(accuracy),
|
: _name(std::move(name)), _type(type), _category(category), _basePower(power), _accuracy(accuracy),
|
||||||
_baseUsages(baseUsage), _target(target), _priority(priority), _flags(std::move(flags)) {}
|
_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 Arbutils::CaseInsensitiveConstString& key) const {
|
||||||
return this->_flags.find(key) != this->_flags.end();
|
return this->_flags.find(key) != this->_flags.end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef CREATURELIB_ATTACKDATA_HPP
|
#ifndef CREATURELIB_ATTACKDATA_HPP
|
||||||
#define CREATURELIB_ATTACKDATA_HPP
|
#define CREATURELIB_ATTACKDATA_HPP
|
||||||
|
|
||||||
|
#include <Arbutils/ConstString.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include "AttackCategory.hpp"
|
#include "AttackCategory.hpp"
|
||||||
|
@ -17,11 +18,12 @@ namespace CreatureLib::Library {
|
||||||
uint8_t _baseUsages;
|
uint8_t _baseUsages;
|
||||||
AttackTarget _target;
|
AttackTarget _target;
|
||||||
int8_t _priority;
|
int8_t _priority;
|
||||||
std::unordered_set<std::string> _flags;
|
std::unordered_set<Arbutils::CaseInsensitiveConstString> _flags;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AttackData(std::string name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy,
|
AttackData(std::string name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy,
|
||||||
uint8_t baseUsage, AttackTarget target, int8_t priority, std::unordered_set<std::string> flags);
|
uint8_t baseUsage, AttackTarget target, int8_t priority,
|
||||||
|
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags);
|
||||||
virtual ~AttackData() = default;
|
virtual ~AttackData() = default;
|
||||||
|
|
||||||
inline const std::string& GetName() const { return _name; }
|
inline const std::string& GetName() const { return _name; }
|
||||||
|
@ -33,7 +35,7 @@ namespace CreatureLib::Library {
|
||||||
inline AttackTarget GetTarget() const { return _target; }
|
inline AttackTarget GetTarget() const { return _target; }
|
||||||
inline int8_t GetPriority() const { return _priority; }
|
inline int8_t GetPriority() const { return _priority; }
|
||||||
|
|
||||||
bool HasFlag(const std::string& key) const;
|
bool HasFlag(const Arbutils::CaseInsensitiveConstString& key) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
#ifndef CREATURELIB_BASELIBRARY_HPP
|
#ifndef CREATURELIB_BASELIBRARY_HPP
|
||||||
#define CREATURELIB_BASELIBRARY_HPP
|
#define CREATURELIB_BASELIBRARY_HPP
|
||||||
|
|
||||||
|
#include <Arbutils/ConstString.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
template <class T> class BaseLibrary {
|
template <class T> class BaseLibrary {
|
||||||
inline static constexpr char charToLower(const char c) { return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; }
|
|
||||||
inline static uint32_t constexpr Hash(char const* input) {
|
|
||||||
return charToLower(*input) ? static_cast<uint32_t>(charToLower(*input)) + 33 * Hash(input + 1) : 5381;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unordered_map<uint32_t, const T*> _values;
|
std::unordered_map<uint32_t, const T*> _values;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -23,14 +20,13 @@ namespace CreatureLib::Library {
|
||||||
_values.clear();
|
_values.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Insert(const char* key, const T* value) { _values.insert({Hash(key), value}); }
|
inline void Insert(const Arbutils::CaseInsensitiveConstString& key, const T* value) {
|
||||||
inline void Insert(const std::string& key, const T* value) { Insert(key.c_str(), value); }
|
_values.insert({key.GetHash(), value});
|
||||||
|
}
|
||||||
|
inline void Delete(const Arbutils::CaseInsensitiveConstString& key) { _values.erase(key.GetHash()); }
|
||||||
|
|
||||||
inline void Delete(const char* key) { _values.erase(Hash(key)); }
|
bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const T*& out) const {
|
||||||
inline void Delete(const std::string& key) { Delete(key.c_str()); }
|
auto find = this->_values.find(name.GetHash());
|
||||||
|
|
||||||
bool TryGet(const char* name, const T*& out) const {
|
|
||||||
auto find = this->_values.find(Hash(name));
|
|
||||||
if (find == this->_values.end()) {
|
if (find == this->_values.end()) {
|
||||||
out = nullptr;
|
out = nullptr;
|
||||||
return false;
|
return false;
|
||||||
|
@ -38,16 +34,10 @@ namespace CreatureLib::Library {
|
||||||
out = find->second;
|
out = find->second;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool TryGet(const std::string& name, const T*& out) const {
|
inline const T* Get(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||||
return TryGet(name.c_str(), out);
|
return _values.at(name.GetHash());
|
||||||
}
|
}
|
||||||
|
inline const T* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); }
|
||||||
inline const T* Get(const char* name) const { return _values.at(Hash(name)); }
|
|
||||||
inline const T* Get(const std::string& name) const { return Get(name.c_str()); }
|
|
||||||
|
|
||||||
inline const T* operator[](const char* name) const { return Get(name); }
|
|
||||||
inline const T* operator[](const std::string& name) const { return Get(name.c_str()); }
|
|
||||||
|
|
||||||
inline const std::unordered_map<uint32_t, const T*>& GetIterator() const { return _values; }
|
inline const std::unordered_map<uint32_t, const T*>& GetIterator() const { return _values; }
|
||||||
|
|
||||||
size_t GetCount() const { return _values.size(); }
|
size_t GetCount() const { return _values.size(); }
|
||||||
|
|
|
@ -2,21 +2,19 @@
|
||||||
|
|
||||||
using namespace CreatureLib::Library;
|
using namespace CreatureLib::Library;
|
||||||
|
|
||||||
CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio,
|
CreatureSpecies::CreatureSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name,
|
||||||
std::string growthRate, uint8_t captureRate)
|
const SpeciesVariant* defaultVariant, float genderRatio,
|
||||||
: _id(id), _genderRate(genderRatio), _growthRate(std::move(growthRate)), _captureRate(captureRate),
|
const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate)
|
||||||
_variants({{"default", defaultVariant}}), _name(std::move(name)) {}
|
: _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
|
||||||
|
_variants({{"default"_cnc, defaultVariant}}), _name(name) {}
|
||||||
|
|
||||||
bool CreatureSpecies::HasVariant(const std::string& name) const {
|
bool CreatureSpecies::HasVariant(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||||
auto key = name;
|
return _variants.find(name) != _variants.end();
|
||||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
|
||||||
return _variants.find(key) != _variants.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVariant*& out) const {
|
bool CreatureSpecies::TryGetVariant(const Arbutils::CaseInsensitiveConstString& name,
|
||||||
auto key = name;
|
const SpeciesVariant*& out) const {
|
||||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
auto find = _variants.find(name);
|
||||||
auto find = _variants.find(key);
|
|
||||||
if (find != _variants.end()) {
|
if (find != _variants.end()) {
|
||||||
out = find->second;
|
out = find->second;
|
||||||
return true;
|
return true;
|
||||||
|
@ -24,20 +22,17 @@ bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVarian
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SpeciesVariant* CreatureSpecies::GetVariant(const std::string& name) const {
|
const SpeciesVariant* CreatureSpecies::GetVariant(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||||
auto key = name;
|
auto key = name;
|
||||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
|
||||||
return _variants.at(key);
|
return _variants.at(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureSpecies::SetVariant(const std::string& name, const SpeciesVariant* variant) {
|
void CreatureSpecies::SetVariant(const Arbutils::CaseInsensitiveConstString& name, const SpeciesVariant* variant) {
|
||||||
auto key = name;
|
auto find = _variants.find(name);
|
||||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
|
||||||
auto find = _variants.find(key);
|
|
||||||
if (find != _variants.end()) {
|
if (find != _variants.end()) {
|
||||||
delete find->second;
|
delete find->second;
|
||||||
}
|
}
|
||||||
_variants[key] = variant;
|
_variants[name] = variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const {
|
Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const {
|
||||||
|
@ -47,5 +42,3 @@ Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const {
|
||||||
return Gender ::Female;
|
return Gender ::Female;
|
||||||
return Gender ::Male;
|
return Gender ::Male;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& CreatureSpecies::GetName() const { return _name; }
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef CREATURELIB_CREATURESPECIES_HPP
|
#ifndef CREATURELIB_CREATURESPECIES_HPP
|
||||||
#define CREATURELIB_CREATURESPECIES_HPP
|
#define CREATURELIB_CREATURESPECIES_HPP
|
||||||
|
|
||||||
|
#include <Arbutils/ConstString.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "../Gender.hpp"
|
#include "../Gender.hpp"
|
||||||
|
@ -14,16 +15,17 @@ namespace CreatureLib::Library {
|
||||||
class CreatureSpecies {
|
class CreatureSpecies {
|
||||||
uint16_t _id;
|
uint16_t _id;
|
||||||
float _genderRate;
|
float _genderRate;
|
||||||
std::string _growthRate;
|
const Arbutils::CaseInsensitiveConstString _growthRate;
|
||||||
uint8_t _captureRate;
|
uint8_t _captureRate;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, const SpeciesVariant*> _variants;
|
std::unordered_map<Arbutils::CaseInsensitiveConstString, const SpeciesVariant*> _variants;
|
||||||
std::string _name;
|
Arbutils::CaseInsensitiveConstString _name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio,
|
CreatureSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name,
|
||||||
std::string growthRate, uint8_t captureRate);
|
const SpeciesVariant* defaultVariant, float genderRatio,
|
||||||
|
const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate);
|
||||||
|
|
||||||
virtual ~CreatureSpecies() {
|
virtual ~CreatureSpecies() {
|
||||||
for (auto v : _variants)
|
for (auto v : _variants)
|
||||||
|
@ -33,18 +35,22 @@ namespace CreatureLib::Library {
|
||||||
|
|
||||||
inline uint16_t GetId() const { return _id; }
|
inline uint16_t GetId() const { return _id; }
|
||||||
inline float GetGenderRate() const { return _genderRate; }
|
inline float GetGenderRate() const { return _genderRate; }
|
||||||
inline const std::string& GetGrowthRate() const { return _growthRate; }
|
inline const Arbutils::CaseInsensitiveConstString& GetGrowthRate() const { return _growthRate; }
|
||||||
inline uint8_t GetCaptureRate() const { return _captureRate; }
|
inline uint8_t GetCaptureRate() const { return _captureRate; }
|
||||||
|
|
||||||
[[nodiscard]] bool HasVariant(const std::string& key) const;
|
[[nodiscard]] bool HasVariant(const Arbutils::CaseInsensitiveConstString& key) const;
|
||||||
[[nodiscard]] bool TryGetVariant(const std::string& name, const SpeciesVariant*& out) const;
|
[[nodiscard]] bool TryGetVariant(const Arbutils::CaseInsensitiveConstString& name,
|
||||||
[[nodiscard]] const SpeciesVariant* GetVariant(const std::string& key) const;
|
const SpeciesVariant*& out) const;
|
||||||
|
[[nodiscard]] const SpeciesVariant* GetVariant(const Arbutils::CaseInsensitiveConstString& key) const;
|
||||||
[[nodiscard]] Gender GetRandomGender(Arbutils::Random& rand) const;
|
[[nodiscard]] Gender GetRandomGender(Arbutils::Random& rand) const;
|
||||||
[[nodiscard]] const std::string& GetName() const;
|
[[nodiscard]] const Arbutils::CaseInsensitiveConstString& GetName() const { return _name; }
|
||||||
|
|
||||||
void SetVariant(const std::string& name, const SpeciesVariant* variant);
|
void SetVariant(const Arbutils::CaseInsensitiveConstString& name, const SpeciesVariant* variant);
|
||||||
|
|
||||||
const std::unordered_map<std::string, const SpeciesVariant*>& GetVariantsIterator() const { return _variants; }
|
const std::unordered_map<Arbutils::CaseInsensitiveConstString, const SpeciesVariant*>&
|
||||||
|
GetVariantsIterator() const {
|
||||||
|
return _variants;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,30 +2,25 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "../../Core/Exceptions/CreatureException.hpp"
|
#include "../../Core/Exceptions/CreatureException.hpp"
|
||||||
|
|
||||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const std::string& growthRate,
|
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const Arbutils::CaseInsensitiveConstString& growthRate,
|
||||||
uint32_t experience) const {
|
uint32_t experience) const {
|
||||||
auto g = growthRate;
|
auto find = _growthRates.find(growthRate);
|
||||||
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
|
|
||||||
auto find = _growthRates.find(g);
|
|
||||||
if (find == _growthRates.end()) {
|
if (find == _growthRates.end()) {
|
||||||
throw CreatureException("Invalid growth rate was requested.");
|
throw CreatureException("Invalid growth rate was requested.");
|
||||||
}
|
}
|
||||||
return find->second->CalculateLevel(experience);
|
return find->second->CalculateLevel(experience);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const std::string& growthRate,
|
uint32_t
|
||||||
uint8_t level) const {
|
CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const Arbutils::CaseInsensitiveConstString& growthRate,
|
||||||
auto g = growthRate;
|
uint8_t level) const {
|
||||||
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
|
auto find = _growthRates.find(growthRate);
|
||||||
auto find = _growthRates.find(g);
|
|
||||||
if (find == _growthRates.end()) {
|
if (find == _growthRates.end()) {
|
||||||
throw CreatureException("Invalid growth rate was requested.");
|
throw CreatureException("Invalid growth rate was requested.");
|
||||||
}
|
}
|
||||||
return find->second->CalculateExperience(level);
|
return find->second->CalculateExperience(level);
|
||||||
}
|
}
|
||||||
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const std::string& name,
|
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const Arbutils::CaseInsensitiveConstString& name,
|
||||||
CreatureLib::Library::GrowthRate* rate) {
|
CreatureLib::Library::GrowthRate* rate) {
|
||||||
auto g = name;
|
_growthRates.insert({name, rate});
|
||||||
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
|
|
||||||
_growthRates.insert({g, rate});
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef CREATURELIB_GROWTHRATELIBRARY_HPP
|
#ifndef CREATURELIB_GROWTHRATELIBRARY_HPP
|
||||||
#define CREATURELIB_GROWTHRATELIBRARY_HPP
|
#define CREATURELIB_GROWTHRATELIBRARY_HPP
|
||||||
|
|
||||||
|
#include <Arbutils/ConstString.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
@ -9,11 +10,11 @@
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
class GrowthRateLibrary {
|
class GrowthRateLibrary {
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, GrowthRate*> _growthRates;
|
std::unordered_map<Arbutils::CaseInsensitiveConstString, GrowthRate*> _growthRates;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GrowthRateLibrary(size_t initialCapacity = 10)
|
GrowthRateLibrary(size_t initialCapacity = 10)
|
||||||
: _growthRates(std::unordered_map<std::string, GrowthRate*>(initialCapacity)) {}
|
: _growthRates(std::unordered_map<Arbutils::CaseInsensitiveConstString, GrowthRate*>(initialCapacity)) {}
|
||||||
|
|
||||||
virtual ~GrowthRateLibrary() {
|
virtual ~GrowthRateLibrary() {
|
||||||
for (auto gr : _growthRates) {
|
for (auto gr : _growthRates) {
|
||||||
|
@ -21,10 +22,12 @@ namespace CreatureLib::Library {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] uint8_t CalculateLevel(const std::string& growthRate, uint32_t experience) const;
|
[[nodiscard]] uint8_t CalculateLevel(const Arbutils::CaseInsensitiveConstString& growthRate,
|
||||||
[[nodiscard]] uint32_t CalculateExperience(const std::string& growthRate, uint8_t level) const;
|
uint32_t experience) const;
|
||||||
|
[[nodiscard]] uint32_t CalculateExperience(const Arbutils::CaseInsensitiveConstString& growthRate,
|
||||||
|
uint8_t level) const;
|
||||||
|
|
||||||
void AddGrowthRate(const std::string& name, GrowthRate* rate);
|
void AddGrowthRate(const Arbutils::CaseInsensitiveConstString& name, GrowthRate* rate);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "Item.hpp"
|
#include "Item.hpp"
|
||||||
|
|
||||||
bool CreatureLib::Library::Item::HasFlag(const std::string& flag) const {
|
bool CreatureLib::Library::Item::HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const {
|
||||||
return this->_flags.find(flag) != this->_flags.end();
|
return this->_flags.find(flag) != this->_flags.end();
|
||||||
}
|
}
|
||||||
CreatureLib::Library::Item::Item(std::string name, CreatureLib::Library::ItemCategory category,
|
CreatureLib::Library::Item::Item(std::string name, CreatureLib::Library::ItemCategory category,
|
||||||
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
|
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
|
||||||
std::unordered_set<std::string> flags)
|
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags)
|
||||||
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}
|
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef CREATURELIB_ITEM_HPP
|
#ifndef CREATURELIB_ITEM_HPP
|
||||||
#define CREATURELIB_ITEM_HPP
|
#define CREATURELIB_ITEM_HPP
|
||||||
|
|
||||||
|
#include <Arbutils/ConstString.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include "BattleItemCategory.hpp"
|
#include "BattleItemCategory.hpp"
|
||||||
|
@ -13,18 +14,18 @@ namespace CreatureLib::Library {
|
||||||
ItemCategory _category;
|
ItemCategory _category;
|
||||||
BattleItemCategory _battleCategory;
|
BattleItemCategory _battleCategory;
|
||||||
int32_t _price;
|
int32_t _price;
|
||||||
std::unordered_set<std::string> _flags;
|
std::unordered_set<Arbutils::CaseInsensitiveConstString> _flags;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Item(std::string name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
|
Item(std::string name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
|
||||||
std::unordered_set<std::string> flags);
|
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags);
|
||||||
|
|
||||||
inline const std::string& GetName() const { return _name; }
|
inline const std::string& GetName() const { return _name; }
|
||||||
inline ItemCategory GetCategory() const { return _category; }
|
inline ItemCategory GetCategory() const { return _category; }
|
||||||
inline BattleItemCategory GetBattleCategory() const { return _battleCategory; }
|
inline BattleItemCategory GetBattleCategory() const { return _battleCategory; }
|
||||||
inline const int32_t GetPrice() const { return _price; }
|
inline const int32_t GetPrice() const { return _price; }
|
||||||
|
|
||||||
bool HasFlag(const std::string& flag) const;
|
bool HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
|
||||||
|
|
||||||
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
|
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
|
||||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
auto l = TestLibrary::Get()->GetAttackLibrary();
|
||||||
auto a1 = new LearnedAttack(l->Get("standard"), AttackLearnMethod::Unknown);
|
auto a1 = new LearnedAttack(l->Get("standard"_cnc), AttackLearnMethod::Unknown);
|
||||||
auto a2 = new LearnedAttack(l->Get("highPriority"), AttackLearnMethod::Unknown);
|
auto a2 = new LearnedAttack(l->Get("highPriority"_cnc), AttackLearnMethod::Unknown);
|
||||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||||
|
@ -50,8 +50,8 @@ TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]")
|
||||||
|
|
||||||
TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") {
|
TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") {
|
||||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
auto l = TestLibrary::Get()->GetAttackLibrary();
|
||||||
auto a1 = new LearnedAttack(l->Get("highPriority"), AttackLearnMethod::Unknown);
|
auto a1 = new LearnedAttack(l->Get("highPriority"_cnc), AttackLearnMethod::Unknown);
|
||||||
auto a2 = new LearnedAttack(l->Get("higherPriority"), AttackLearnMethod::Unknown);
|
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc), AttackLearnMethod::Unknown);
|
||||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||||
|
@ -72,8 +72,8 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling
|
||||||
|
|
||||||
TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") {
|
TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") {
|
||||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
auto l = TestLibrary::Get()->GetAttackLibrary();
|
||||||
auto a1 = new LearnedAttack(l->Get("lowPriority"), AttackLearnMethod::Unknown);
|
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc), AttackLearnMethod::Unknown);
|
||||||
auto a2 = new LearnedAttack(l->Get("higherPriority"), AttackLearnMethod::Unknown);
|
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc), AttackLearnMethod::Unknown);
|
||||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||||
|
@ -94,8 +94,8 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]")
|
||||||
|
|
||||||
TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
|
TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
|
||||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
auto l = TestLibrary::Get()->GetAttackLibrary();
|
||||||
auto a1 = new LearnedAttack(l->Get("lowPriority"), AttackLearnMethod::Unknown);
|
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc), AttackLearnMethod::Unknown);
|
||||||
auto a2 = new LearnedAttack(l->Get("standard"), AttackLearnMethod::Unknown);
|
auto a2 = new LearnedAttack(l->Get("standard"_cnc), AttackLearnMethod::Unknown);
|
||||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||||
|
|
|
@ -13,7 +13,8 @@ using namespace Battling;
|
||||||
|
|
||||||
TEST_CASE("Create Party", "[Integrations]") {
|
TEST_CASE("Create Party", "[Integrations]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c1 =
|
||||||
|
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party1{c1};
|
CreatureParty party1{c1};
|
||||||
auto battleParty = BattleParty(&party1, {CreatureIndex(0, 0)});
|
auto battleParty = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
REQUIRE(battleParty.GetParty()->GetAtIndex(0) == c1);
|
REQUIRE(battleParty.GetParty()->GetAtIndex(0) == c1);
|
||||||
|
@ -21,10 +22,12 @@ TEST_CASE("Create Party", "[Integrations]") {
|
||||||
|
|
||||||
TEST_CASE("Create Battle", "[Integrations]") {
|
TEST_CASE("Create Battle", "[Integrations]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c1 =
|
||||||
|
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party1{c1};
|
CreatureParty party1{c1};
|
||||||
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
auto c2 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c2 =
|
||||||
|
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party2{c2};
|
CreatureParty party2{c2};
|
||||||
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
||||||
|
|
||||||
|
@ -33,10 +36,12 @@ TEST_CASE("Create Battle", "[Integrations]") {
|
||||||
|
|
||||||
TEST_CASE("Use damaging move", "[Integrations]") {
|
TEST_CASE("Use damaging move", "[Integrations]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c1 =
|
||||||
|
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party1{c1};
|
CreatureParty party1{c1};
|
||||||
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
auto c2 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c2 =
|
||||||
|
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party2{c2};
|
CreatureParty party2{c2};
|
||||||
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
||||||
|
|
||||||
|
@ -53,10 +58,12 @@ TEST_CASE("Use damaging move", "[Integrations]") {
|
||||||
|
|
||||||
TEST_CASE("Finish battle when all battle of one side have fainted", "[Integrations]") {
|
TEST_CASE("Finish battle when all battle of one side have fainted", "[Integrations]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c1 =
|
||||||
|
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party1{c1};
|
CreatureParty party1{c1};
|
||||||
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
auto c2 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c2 =
|
||||||
|
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party2{c2};
|
CreatureParty party2{c2};
|
||||||
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
||||||
|
|
||||||
|
@ -86,10 +93,12 @@ TEST_CASE("Finish battle when all battle of one side have fainted", "[Integratio
|
||||||
|
|
||||||
TEST_CASE("When creature is dealt enough damage, faint it and mark battle as ended", "[Integrations]") {
|
TEST_CASE("When creature is dealt enough damage, faint it and mark battle as ended", "[Integrations]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c1 =
|
||||||
|
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party1{c1};
|
CreatureParty party1{c1};
|
||||||
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c2 =
|
||||||
|
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party2{c2};
|
CreatureParty party2{c2};
|
||||||
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
||||||
|
|
||||||
|
@ -113,11 +122,14 @@ TEST_CASE("When creature is dealt enough damage, faint it and mark battle as end
|
||||||
|
|
||||||
TEST_CASE("When another creature is available on faint, make sure the battle hasn't ended", "[Integrations]") {
|
TEST_CASE("When another creature is available on faint, make sure the battle hasn't ended", "[Integrations]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c1 =
|
||||||
|
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party1{c1};
|
CreatureParty party1{c1};
|
||||||
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c2 =
|
||||||
auto c3 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
|
auto c3 =
|
||||||
|
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party2{c2, c3};
|
CreatureParty party2{c2, c3};
|
||||||
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
||||||
|
|
||||||
|
@ -148,11 +160,14 @@ TEST_CASE("When another creature is available on faint, make sure the battle has
|
||||||
|
|
||||||
TEST_CASE("Switch Creature in", "[Integrations]") {
|
TEST_CASE("Switch Creature in", "[Integrations]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c1 =
|
||||||
auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
|
auto c2 =
|
||||||
|
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party1{c1, c2};
|
CreatureParty party1{c1, c2};
|
||||||
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
auto c3 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c3 =
|
||||||
|
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party2{c3};
|
CreatureParty party2{c3};
|
||||||
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
||||||
|
|
||||||
|
@ -171,11 +186,14 @@ TEST_CASE("Switch Creature in", "[Integrations]") {
|
||||||
|
|
||||||
TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit new creature", "[Integrations]") {
|
TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit new creature", "[Integrations]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c1 =
|
||||||
auto c2 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
|
auto c2 =
|
||||||
|
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party1{c1, c2};
|
CreatureParty party1{c1, c2};
|
||||||
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
auto c3 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c3 =
|
||||||
|
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party2{c3};
|
CreatureParty party2{c3};
|
||||||
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
||||||
|
|
||||||
|
@ -193,11 +211,14 @@ TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit ne
|
||||||
|
|
||||||
TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integrations]") {
|
TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integrations]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c1 =
|
||||||
auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
|
auto c2 =
|
||||||
|
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party1{c1, c2};
|
CreatureParty party1{c1, c2};
|
||||||
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
auto c3 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c3 =
|
||||||
|
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party2{c3};
|
CreatureParty party2{c3};
|
||||||
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
||||||
|
|
||||||
|
@ -229,10 +250,12 @@ TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integratio
|
||||||
|
|
||||||
TEST_CASE("Flee Battle", "[Integrations]") {
|
TEST_CASE("Flee Battle", "[Integrations]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c1 =
|
||||||
|
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party1{c1};
|
CreatureParty party1{c1};
|
||||||
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
auto c2 =
|
||||||
|
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
|
||||||
CreatureParty party2{c2};
|
CreatureParty party2{c2};
|
||||||
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ TEST_CASE("Create basic creature", "[Library]") {
|
||||||
TEST_CASE("Get creature species", "[Library]") {
|
TEST_CASE("Get creature species", "[Library]") {
|
||||||
auto library = TestLibrary::Get();
|
auto library = TestLibrary::Get();
|
||||||
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
|
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
|
||||||
REQUIRE(creature->GetSpecies()->GetName() == "testSpecies1");
|
REQUIRE(creature->GetSpecies()->GetName() == "testSpecies1"_cnc);
|
||||||
delete creature;
|
delete creature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,25 +22,25 @@ BattleLibrary* TestLibrary::Get() {
|
||||||
|
|
||||||
SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
|
SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
|
||||||
auto l = new SpeciesLibrary();
|
auto l = new SpeciesLibrary();
|
||||||
l->Insert("testSpecies1",
|
l->Insert("testSpecies1"_cnc,
|
||||||
new CreatureSpecies(0, "testSpecies1",
|
new CreatureSpecies(0, "testSpecies1"_cnc,
|
||||||
new SpeciesVariant("default", 1, 1, 10, {0, 1},
|
new SpeciesVariant("default", 1, 1, 10, {0, 1},
|
||||||
StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10), {"testTalent"},
|
StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10), {"testTalent"},
|
||||||
{"testSecretTalent"}, new LearnableAttacks(100)),
|
{"testSecretTalent"}, new LearnableAttacks(100)),
|
||||||
0.5f, "testGrowthRate", 5));
|
0.5f, "testGrowthRate"_cnc, 5));
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
AttackLibrary* TestLibrary::BuildAttackLibrary() {
|
AttackLibrary* TestLibrary::BuildAttackLibrary() {
|
||||||
auto l = new AttackLibrary();
|
auto l = new AttackLibrary();
|
||||||
l->Insert("standard", new AttackData("standard", 0, AttackCategory::Physical, 20, 100, 30,
|
l->Insert("standard"_cnc, new AttackData("standard", 0, AttackCategory::Physical, 20, 100, 30,
|
||||||
AttackTarget::AdjacentOpponent, 0, {}));
|
AttackTarget::AdjacentOpponent, 0, {}));
|
||||||
l->Insert("highPriority", new AttackData("highPriority", 0, AttackCategory::Physical, 20, 100, 30,
|
l->Insert("highPriority"_cnc, new AttackData("highPriority", 0, AttackCategory::Physical, 20, 100, 30,
|
||||||
AttackTarget::AdjacentOpponent, 1, {}));
|
AttackTarget::AdjacentOpponent, 1, {}));
|
||||||
l->Insert("higherPriority", new AttackData("higherPriority", 0, AttackCategory::Physical, 20, 100, 30,
|
l->Insert("higherPriority"_cnc, new AttackData("higherPriority", 0, AttackCategory::Physical, 20, 100, 30,
|
||||||
AttackTarget::AdjacentOpponent, 2, {}));
|
AttackTarget::AdjacentOpponent, 2, {}));
|
||||||
l->Insert("lowPriority", new AttackData("lowPriority", 0, AttackCategory::Physical, 20, 100, 30,
|
l->Insert("lowPriority"_cnc, new AttackData("lowPriority", 0, AttackCategory::Physical, 20, 100, 30,
|
||||||
AttackTarget::AdjacentOpponent, -1, {}));
|
AttackTarget::AdjacentOpponent, -1, {}));
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ ItemLibrary* TestLibrary::BuildItemLibrary() {
|
||||||
|
|
||||||
GrowthRateLibrary* TestLibrary::BuildGrowthRateLibrary() {
|
GrowthRateLibrary* TestLibrary::BuildGrowthRateLibrary() {
|
||||||
auto l = new GrowthRateLibrary();
|
auto l = new GrowthRateLibrary();
|
||||||
l->AddGrowthRate("testGrowthRate", new LookupGrowthRate());
|
l->AddGrowthRate("testGrowthRate"_cnc, new LookupGrowthRate());
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue