Updated to latest Arbutils.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-04-25 10:41:15 +02:00
parent df37558ec0
commit 1eb751538d
7 changed files with 66 additions and 77 deletions

View File

@@ -38,12 +38,12 @@ namespace CreatureLib::Battling {
uint8_t creaturesPerSide = 1)
: _library(library), _parties(std::move(parties)), _canFlee(canFlee), _numberOfSides(numberOfSides),
_creaturesPerSide(creaturesPerSide) {
AssertNotNull(_library)
AssertAllNotNull(parties)
AssertNotNull(_library);
AssertAllNotNull(parties);
_sides = List<BattleSide*>(numberOfSides);
_sides = List<BattleSide*>(numberOfSides);
for (size_t i = 0; i < numberOfSides; i++) {
_sides[i] = new BattleSide(i, this, creaturesPerSide);
_sides.Append(new BattleSide(i, this, creaturesPerSide));
}
}

View File

@@ -26,9 +26,9 @@ namespace CreatureLib::Battling {
: _index(index), _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide),
_choices(creaturesPerSide), _fillableSlots(creaturesPerSide), _battle(battle) {
for (size_t i = 0; i < creaturesPerSide; i++) {
_creatures[i] = nullptr;
_choices[i] = nullptr;
_fillableSlots[i] = true;
_creatures.Append(nullptr);
_choices.Append(nullptr);
_fillableSlots.Append(true);
}
ResetChoices();
}

View File

@@ -5,29 +5,29 @@
using namespace CreatureLib::Battling;
CreateCreature* CreateCreature::WithVariant(const Arbutils::CaseInsensitiveConstString& variant) {
CreateCreature CreateCreature::WithVariant(const Arbutils::CaseInsensitiveConstString& variant) {
this->_variant = variant;
return this;
return *this;
}
CreateCreature* CreateCreature::WithNickname(std::string nickname) {
CreateCreature CreateCreature::WithNickname(std::string nickname) {
this->_nickname = std::move(nickname);
return this;
return *this;
}
CreateCreature* CreateCreature::WithGender(Library::Gender gender) {
CreateCreature CreateCreature::WithGender(Library::Gender gender) {
this->_gender = gender;
return this;
return *this;
}
CreateCreature* CreateCreature::WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
AttackLearnMethod learnMethod) {
CreateCreature CreateCreature::WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
AttackLearnMethod learnMethod) {
if (_attacks.Count() >= _library->GetSettings()->GetMaximalMoves())
throw CreatureException("You have already set the maximum amount of allowed moves.");
auto attackData = _library->GetAttackLibrary()->Get(attackName);
_attacks.Append(std::tuple(attackData, learnMethod));
return this;
return *this;
}
Creature* CreateCreature::Create() {
@@ -57,9 +57,9 @@ Creature* CreateCreature::Create() {
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
auto attacks = List<LearnedAttack*>(_attacks.Count());
for (size_t i = 0; i < attacks.Count(); i++) {
for (size_t i = 0; i < _attacks.Count(); i++) {
auto kv = _attacks[i];
attacks[i] = new LearnedAttack(std::get<0>(kv), std::get<1>(kv));
attacks.Append(new LearnedAttack(std::get<0>(kv), std::get<1>(kv)));
}
auto c = new Creature(_library, species, variant, _level, experience, identifier, gender, _coloring, heldItem,
_nickname, talent, attacks);

View File

@@ -3,6 +3,7 @@
#include <Arbutils/Collections/List.hpp>
#include "../../Library/DataLibrary.hpp"
#include "../Library/BattleLibrary.hpp"
#include "Creature.hpp"
using namespace Arbutils::Collections;
@@ -20,17 +21,18 @@ namespace CreatureLib::Battling {
uint8_t _coloring = 0;
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc;
uint32_t _identifier = 0;
List<std::tuple<const Library::AttackData*, AttackLearnMethod>> _attacks = {};
List<std::tuple<const Library::AttackData*, AttackLearnMethod>> _attacks;
public:
CreateCreature(const BattleLibrary* library, const Arbutils::CaseInsensitiveConstString& species, uint8_t level)
: _library(library), _species(species), _level(level) {}
: _library(library), _species(species), _level(level), _attacks(library->GetSettings()->GetMaximalMoves()) {
}
CreateCreature* WithVariant(const Arbutils::CaseInsensitiveConstString& variant);
CreateCreature* WithNickname(std::string nickname);
CreateCreature* WithGender(Library::Gender gender);
CreateCreature* WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
AttackLearnMethod learnMethod);
CreateCreature WithVariant(const Arbutils::CaseInsensitiveConstString& variant);
CreateCreature WithNickname(std::string nickname);
CreateCreature WithGender(Library::Gender gender);
CreateCreature WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
AttackLearnMethod learnMethod);
Creature* Create();
};

View File

@@ -42,11 +42,7 @@ namespace CreatureLib::Battling {
List<HitData> _hits;
public:
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) {
for (uint8_t i = 0; i < numberOfHits; i++) {
_hits[i] = HitData();
}
}
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) { _hits.Resize(numberOfHits, HitData()); }
TargetData() = default;
HitData* GetHit(uint8_t index) { return &_hits[index]; }

View File

@@ -16,7 +16,9 @@ namespace CreatureLib::Library {
size_t _index;
public:
BaseLibrary(size_t initialCapacity = 32) : _values(initialCapacity), _listValues(initialCapacity) {}
BaseLibrary(size_t initialCapacity = 32) : _values(initialCapacity), _listValues(0) {
_listValues.Resize(initialCapacity);
}
virtual ~BaseLibrary() {
for (const auto& v : _values) {
@@ -28,12 +30,12 @@ namespace CreatureLib::Library {
inline void Insert(const Arbutils::CaseInsensitiveConstString& key, const T* value) {
AssertNotNull(value)
_values.Insert(key.GetHash(), value);
_listValues[_index++] = key;
_listValues.Append(key);
}
inline void Insert(uint32_t hashedKey, const T* value) {
AssertNotNull(value)
_values.Insert(hashedKey, value);
_listValues[_index++] = hashedKey;
_listValues.Append(hashedKey);
}
inline void Delete(const Arbutils::CaseInsensitiveConstString& key) {