Replace most collections with Arbutils collections for more safety.
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:
@@ -62,7 +62,7 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
||||
|
||||
// FIXME: Resolve all targets
|
||||
auto target = choice->GetUser()->GetBattle()->GetCreature(choice->GetTarget());
|
||||
std::vector<Creature*> targets = {target};
|
||||
Arbutils::Collections::List<Creature*> targets = {target};
|
||||
|
||||
auto attack = new ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
||||
bool prevented = false;
|
||||
|
||||
@@ -84,7 +84,7 @@ bool Battle::CreatureInField(const Creature* creature) const {
|
||||
|
||||
void Battle::ForceRecall(uint8_t side, uint8_t index) { _sides[side]->SetCreature(nullptr, index); }
|
||||
|
||||
void Battle::GetActiveScripts(std::vector<ScriptWrapper>& scripts) { scripts.emplace_back(&_volatile); }
|
||||
void Battle::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) { scripts.Append(&_volatile); }
|
||||
|
||||
void Battle::SwitchCreature(uint8_t sideIndex, uint8_t index, Creature* c) {
|
||||
AssertNotNull(c)
|
||||
@@ -105,7 +105,7 @@ bool Battle::CanSlotBeFilled(uint8_t side, uint8_t index) const {
|
||||
void Battle::ValidateBattleState() {
|
||||
bool survivingSideExists = false;
|
||||
uint8_t winningSide = 0;
|
||||
for (uint8_t i = 0; i < _sides.size(); i++) {
|
||||
for (uint8_t i = 0; i < _sides.Count(); i++) {
|
||||
auto side = _sides[i];
|
||||
if (side->HasFled()) {
|
||||
this->_battleResult = BattleResult::Inconclusive();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CREATURELIB_BATTLE_HPP
|
||||
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <vector>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include "../EventHooks/EventHook.hpp"
|
||||
#include "../Flow/ChoiceQueue.hpp"
|
||||
#include "../Library/BattleLibrary.hpp"
|
||||
@@ -13,14 +13,16 @@
|
||||
#include "BattleSide.hpp"
|
||||
#include "CreatureIndex.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class Battle : public ScriptSource {
|
||||
const BattleLibrary* _library;
|
||||
std::vector<BattleParty*> _parties;
|
||||
List<BattleParty*> _parties;
|
||||
bool _canFlee;
|
||||
uint8_t _numberOfSides;
|
||||
uint8_t _creaturesPerSide;
|
||||
std::vector<BattleSide*> _sides;
|
||||
List<BattleSide*> _sides;
|
||||
BattleRandom _random;
|
||||
ChoiceQueue* _currentTurnQueue = nullptr;
|
||||
bool _hasEnded = false;
|
||||
@@ -31,15 +33,15 @@ namespace CreatureLib::Battling {
|
||||
ScriptSet _volatile;
|
||||
|
||||
public:
|
||||
Battle(const BattleLibrary* library, std::vector<BattleParty*> parties, bool canFlee = true,
|
||||
uint8_t numberOfSides = 2, uint8_t creaturesPerSide = 1)
|
||||
Battle(const BattleLibrary* library, List<BattleParty*> parties, bool canFlee = true, uint8_t numberOfSides = 2,
|
||||
uint8_t creaturesPerSide = 1)
|
||||
: _library(library), _parties(std::move(parties)), _canFlee(canFlee), _numberOfSides(numberOfSides),
|
||||
_creaturesPerSide(creaturesPerSide) {
|
||||
AssertNotNull(_library)
|
||||
for (auto p : parties)
|
||||
AssertNotNull(p)
|
||||
|
||||
_sides = std::vector<BattleSide*>(numberOfSides);
|
||||
_sides = List<BattleSide*>(numberOfSides);
|
||||
for (size_t i = 0; i < numberOfSides; i++) {
|
||||
_sides[i] = new BattleSide(i, this, creaturesPerSide);
|
||||
}
|
||||
@@ -71,7 +73,6 @@ namespace CreatureLib::Battling {
|
||||
bool CreatureInField(const Creature* creature) const;
|
||||
|
||||
Creature* GetCreature(const CreatureIndex& target) const {
|
||||
Assert(target.GetSideIndex() < _sides.size())
|
||||
return _sides[target.GetSideIndex()]->GetCreature(target.GetCreatureIndex());
|
||||
}
|
||||
Creature* GetCreature(uint8_t side, uint8_t target) const { return _sides[side]->GetCreature(target); }
|
||||
@@ -80,13 +81,13 @@ namespace CreatureLib::Battling {
|
||||
void SwitchCreature(uint8_t side, uint8_t index, Creature* c);
|
||||
bool CanSlotBeFilled(uint8_t side, uint8_t index) const;
|
||||
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
||||
|
||||
void ValidateBattleState();
|
||||
inline bool HasEnded() const { return _hasEnded; }
|
||||
inline const BattleResult& GetResult() const { return _battleResult; }
|
||||
|
||||
const std::vector<BattleSide*>& GetSides() const { return _sides; }
|
||||
const List<BattleSide*>& GetSides() const { return _sides; }
|
||||
Script* GetVolatileScript(const ConstString& key) const { return _volatile.Get(key); }
|
||||
Script* GetVolatileScript(uint32_t keyHash) const { return _volatile.Get(keyHash); }
|
||||
void AddVolatileScript(const ConstString& key);
|
||||
|
||||
@@ -2,28 +2,28 @@
|
||||
#define CREATURELIB_BATTLEPARTY_HPP
|
||||
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include "CreatureIndex.hpp"
|
||||
#include "CreatureParty.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class BattleParty {
|
||||
CreatureParty* _party;
|
||||
std::vector<CreatureIndex> _responsibleIndices;
|
||||
List<CreatureIndex> _responsibleIndices;
|
||||
|
||||
public:
|
||||
BattleParty(CreatureParty* party, std::vector<CreatureIndex> responsibleIndices)
|
||||
BattleParty(CreatureParty* party, const List<CreatureIndex>& responsibleIndices)
|
||||
: _party(party), _responsibleIndices(responsibleIndices) {
|
||||
AssertNotNull(_party)
|
||||
}
|
||||
|
||||
inline CreatureParty* GetParty() const { return _party; }
|
||||
inline const std::vector<CreatureIndex>& GetResponsibleIndices() const { return _responsibleIndices; }
|
||||
inline const List<CreatureIndex>& GetResponsibleIndices() const { return _responsibleIndices; }
|
||||
|
||||
inline bool IsResponsibleForIndex(const CreatureIndex& index) const {
|
||||
for (const auto& i : _responsibleIndices) {
|
||||
if (i == index)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return _responsibleIndices.Contains(index);
|
||||
}
|
||||
|
||||
inline bool IsResponsibleForIndex(uint8_t side, uint8_t index) const {
|
||||
|
||||
@@ -9,7 +9,7 @@ bool BattleSide::AllChoicesSet() const { return _choicesSet == _creaturesPerSide
|
||||
|
||||
bool BattleSide::AllPossibleSlotsFilled() const {
|
||||
AssertNotNull(_battle)
|
||||
for (size_t i = 0; i < _creatures.size(); i++) {
|
||||
for (size_t i = 0; i < _creatures.Count(); i++) {
|
||||
auto c = _creatures[i];
|
||||
if (c == nullptr || c->IsFainted()) {
|
||||
if (_battle->CanSlotBeFilled(_index, i))
|
||||
@@ -26,7 +26,7 @@ void BattleSide::ResetChoices() {
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<BaseTurnChoice*>& BattleSide::GetChoices() const { return _choices; }
|
||||
const List<BaseTurnChoice*>& BattleSide::GetChoices() const { return _choices; }
|
||||
|
||||
void BattleSide::SetChoice(BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice)
|
||||
@@ -68,8 +68,8 @@ bool BattleSide::CreatureOnSide(const Creature* creature) const {
|
||||
|
||||
Creature* BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; }
|
||||
|
||||
void BattleSide::GetActiveScripts(std::vector<ScriptWrapper>& scripts) {
|
||||
scripts.emplace_back(&_volatile);
|
||||
void BattleSide::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) {
|
||||
scripts.Append(&_volatile);
|
||||
_battle->GetActiveScripts(scripts);
|
||||
}
|
||||
uint8_t BattleSide::GetRandomCreatureIndex() {
|
||||
|
||||
@@ -2,17 +2,20 @@
|
||||
#define CREATURELIB_BATTLESIDE_HPP
|
||||
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <vector>
|
||||
#include "../TurnChoices/BaseTurnChoice.hpp"
|
||||
#include "Creature.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class BattleSide : public ScriptSource {
|
||||
uint8_t _index;
|
||||
uint8_t _creaturesPerSide;
|
||||
std::vector<Creature*> _creatures;
|
||||
std::vector<BaseTurnChoice*> _choices;
|
||||
std::vector<bool> _fillableSlots;
|
||||
List<Creature*> _creatures;
|
||||
List<BaseTurnChoice*> _choices;
|
||||
List<bool> _fillableSlots;
|
||||
uint8_t _choicesSet = 0;
|
||||
ScriptSet _volatile;
|
||||
Battle* _battle;
|
||||
@@ -33,7 +36,7 @@ namespace CreatureLib::Battling {
|
||||
virtual ~BattleSide() = default;
|
||||
|
||||
[[nodiscard]] bool AllChoicesSet() const;
|
||||
[[nodiscard]] const std::vector<BaseTurnChoice*>& GetChoices() const;
|
||||
[[nodiscard]] const List<BaseTurnChoice*>& GetChoices() const;
|
||||
|
||||
[[nodiscard]] bool AllPossibleSlotsFilled() const;
|
||||
|
||||
@@ -45,13 +48,13 @@ namespace CreatureLib::Battling {
|
||||
Creature* GetCreature(uint8_t index) const;
|
||||
bool CreatureOnSide(const Creature* creature) const;
|
||||
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) final;
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) final;
|
||||
|
||||
const std::vector<Creature*>& GetCreatures() { return _creatures; }
|
||||
const List<Creature*>& GetCreatures() { return _creatures; }
|
||||
|
||||
uint8_t GetSideIndex() { return _index; }
|
||||
uint8_t GetCreatureIndex(Creature* c) {
|
||||
for (size_t i = 0; i < _creatures.size(); i++) {
|
||||
for (size_t i = 0; i < _creatures.Count(); i++) {
|
||||
if (c == _creatures[i])
|
||||
return i;
|
||||
}
|
||||
@@ -61,7 +64,7 @@ namespace CreatureLib::Battling {
|
||||
void MarkSlotAsUnfillable(Creature* creature) {
|
||||
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
|
||||
if (_creatures[i] == creature) {
|
||||
_fillableSlots[i] = false;
|
||||
_fillableSlots.At(i) = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ CreateCreature* CreateCreature::WithGender(Library::Gender gender) {
|
||||
|
||||
CreateCreature* CreateCreature::WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
|
||||
AttackLearnMethod learnMethod) {
|
||||
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves())
|
||||
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.emplace_back(attackData, learnMethod);
|
||||
_attacks.Append(std::tuple(attackData, learnMethod));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ Creature* CreateCreature::Create() {
|
||||
}
|
||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
||||
|
||||
auto attacks = std::vector<LearnedAttack*>(_attacks.size());
|
||||
for (size_t i = 0; i < attacks.size(); i++) {
|
||||
auto attacks = List<LearnedAttack*>(_attacks.Count());
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#ifndef CREATURELIB_CREATECREATURE_HPP
|
||||
#define CREATURELIB_CREATECREATURE_HPP
|
||||
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include "../../Library/DataLibrary.hpp"
|
||||
#include "Creature.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class CreateCreature {
|
||||
const BattleLibrary* _library;
|
||||
@@ -17,7 +20,7 @@ namespace CreatureLib::Battling {
|
||||
uint8_t _coloring = 0;
|
||||
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc;
|
||||
uint32_t _identifier = 0;
|
||||
std::vector<std::tuple<const Library::AttackData*, AttackLearnMethod>> _attacks = {};
|
||||
List<std::tuple<const Library::AttackData*, AttackLearnMethod>> _attacks = {};
|
||||
|
||||
public:
|
||||
CreateCreature(const BattleLibrary* library, std::string species, uint8_t level)
|
||||
|
||||
@@ -9,8 +9,7 @@ using namespace CreatureLib;
|
||||
Battling::Creature::Creature(const BattleLibrary* library, const Library::CreatureSpecies* species,
|
||||
const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, uint32_t uid,
|
||||
Library::Gender gender, uint8_t coloring, const Library::Item* heldItem,
|
||||
std::string nickname, const Library::TalentIndex& talent,
|
||||
std::vector<LearnedAttack*> attacks)
|
||||
std::string nickname, const Library::TalentIndex& talent, List<LearnedAttack*> attacks)
|
||||
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience),
|
||||
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _nickname(std::move(nickname)),
|
||||
_talentIndex(talent), _hasOverridenTalent(false), _attacks(std::move(attacks)) {
|
||||
@@ -143,7 +142,7 @@ void Battling::Creature::OverrideActiveTalent(const ConstString& talent) {
|
||||
_activeTalent = this->_library->LoadScript(ScriptCategory::Talent, talent);
|
||||
}
|
||||
|
||||
const std::vector<uint8_t>& Battling::Creature::GetTypes() const noexcept {
|
||||
const List<uint8_t>& Battling::Creature::GetTypes() const noexcept {
|
||||
// HOOK: override types.
|
||||
return this->_variant->GetTypes();
|
||||
}
|
||||
@@ -153,10 +152,10 @@ bool Battling::Creature::HasType(uint8_t type) const noexcept {
|
||||
return std::find(t.begin(), t.end(), type) != t.end();
|
||||
}
|
||||
|
||||
void Battling::Creature::GetActiveScripts(std::vector<ScriptWrapper>& scripts) {
|
||||
scripts.emplace_back(&_activeTalent);
|
||||
scripts.emplace_back(&_status);
|
||||
scripts.emplace_back(&_volatile);
|
||||
void Battling::Creature::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) {
|
||||
scripts.Append(&_activeTalent);
|
||||
scripts.Append(&_status);
|
||||
scripts.Append(&_volatile);
|
||||
if (_side != nullptr) {
|
||||
_side->GetActiveScripts(scripts);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef CREATURELIB_BATTLECREATURE_HPP
|
||||
#define CREATURELIB_BATTLECREATURE_HPP
|
||||
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include "../../Library/CreatureData/CreatureSpecies.hpp"
|
||||
#include "../../Library/Items/Item.hpp"
|
||||
#include "../ScriptHandling/ScriptAggregator.hpp"
|
||||
@@ -9,6 +10,8 @@
|
||||
#include "DamageSource.hpp"
|
||||
#include "LearnedAttack.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
// Forward declare battle class
|
||||
class Battle;
|
||||
@@ -49,7 +52,7 @@ namespace CreatureLib::Battling {
|
||||
ConstString _overridenTalentName = ""_cnc;
|
||||
std::unordered_set<Creature*> _seenOpponents = {};
|
||||
|
||||
std::vector<LearnedAttack*> _attacks;
|
||||
List<LearnedAttack*> _attacks;
|
||||
|
||||
Script* _status = nullptr;
|
||||
ScriptSet _volatile = {};
|
||||
@@ -61,7 +64,7 @@ namespace CreatureLib::Battling {
|
||||
Creature(const BattleLibrary* library, const Library::CreatureSpecies* species,
|
||||
const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, uint32_t uid,
|
||||
Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, std::string nickname,
|
||||
const Library::TalentIndex& talent, std::vector<LearnedAttack*> attacks);
|
||||
const Library::TalentIndex& talent, List<LearnedAttack*> attacks);
|
||||
|
||||
virtual ~Creature() {
|
||||
for (auto attack : _attacks) {
|
||||
@@ -105,7 +108,7 @@ namespace CreatureLib::Battling {
|
||||
const ConstString& GetActiveTalent() const;
|
||||
|
||||
[[nodiscard]] bool IsFainted() const noexcept;
|
||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const noexcept;
|
||||
[[nodiscard]] const List<uint8_t>& GetTypes() const noexcept;
|
||||
[[nodiscard]] bool HasType(uint8_t type) const noexcept;
|
||||
|
||||
uint32_t GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); }
|
||||
@@ -118,7 +121,7 @@ namespace CreatureLib::Battling {
|
||||
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
|
||||
const std::unordered_set<Creature*>& GetSeenOpponents() const { return _seenOpponents; }
|
||||
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
||||
void ClearVolatileScripts();
|
||||
void AddVolatileScript(const ConstString& name);
|
||||
void AddVolatileScript(Script* script);
|
||||
@@ -126,7 +129,7 @@ namespace CreatureLib::Battling {
|
||||
void RemoveVolatileScript(Script* script);
|
||||
bool HasVolatileScript(const ConstString& name) const;
|
||||
|
||||
std::vector<LearnedAttack*>& GetAttacks() { return _attacks; }
|
||||
List<LearnedAttack*>& GetAttacks() { return _attacks; }
|
||||
|
||||
const Library::CreatureSpecies* GetDisplaySpecies() const;
|
||||
const Library::SpeciesVariant* GetDisplayVariant() const;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#ifndef CREATURELIB_CREATUREPARTY_HPP
|
||||
#define CREATURELIB_CREATUREPARTY_HPP
|
||||
|
||||
#include <array>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include "Creature.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class CreatureParty {
|
||||
std::vector<Creature*> _party;
|
||||
Arbutils::Collections::List<Creature*> _party;
|
||||
|
||||
public:
|
||||
CreatureParty(size_t size) : _party(size) {}
|
||||
CreatureParty(std::vector<Creature*> party) : _party(party) {}
|
||||
CreatureParty(Arbutils::Collections::List<Creature*> party) : _party(party) {}
|
||||
CreatureParty(std::initializer_list<Creature*> party) : _party(party) {}
|
||||
|
||||
virtual ~CreatureParty() {
|
||||
@@ -38,10 +38,10 @@ namespace CreatureLib::Battling {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<Creature*>& GetParty() { return _party; }
|
||||
const std::vector<Creature*>& GetParty() const { return _party; }
|
||||
Arbutils::Collections::List<Creature*>& GetParty() { return _party; }
|
||||
const Arbutils::Collections::List<Creature*>& GetParty() const { return _party; }
|
||||
|
||||
size_t GetLength() const { return _party.size(); }
|
||||
size_t GetLength() const { return _party.Count(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
#define CREATURELIB_EXECUTINGATTACK_HPP
|
||||
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "Creature.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ExecutingAttack : public ScriptSource {
|
||||
public:
|
||||
@@ -35,7 +39,7 @@ namespace CreatureLib::Battling {
|
||||
|
||||
class TargetData {
|
||||
bool _isHit = true;
|
||||
std::vector<HitData> _hits;
|
||||
List<HitData> _hits;
|
||||
|
||||
public:
|
||||
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) {
|
||||
@@ -47,26 +51,25 @@ namespace CreatureLib::Battling {
|
||||
|
||||
HitData* GetHit(uint8_t index) { return &_hits[index]; }
|
||||
|
||||
uint8_t GetNumberOfHits() const { return _hits.size(); }
|
||||
uint8_t GetNumberOfHits() const { return _hits.Count(); }
|
||||
|
||||
bool IsHit() const { return _isHit; }
|
||||
};
|
||||
|
||||
private:
|
||||
std::unordered_map<Creature*, TargetData> _targets;
|
||||
Dictionary<Creature*, TargetData> _targets;
|
||||
Creature* _user;
|
||||
LearnedAttack* _attack;
|
||||
Script* _script;
|
||||
|
||||
public:
|
||||
ExecutingAttack(const std::vector<Creature*>& targets, uint8_t numberHits, Creature* user,
|
||||
LearnedAttack* attack, Script* script)
|
||||
: _user(user), _attack(attack), _script(script) {
|
||||
ExecutingAttack(const List<Creature*>& targets, uint8_t numberHits, Creature* user, LearnedAttack* attack,
|
||||
Script* script)
|
||||
: _targets(targets.Count()), _user(user), _attack(attack), _script(script) {
|
||||
AssertNotNull(user)
|
||||
AssertNotNull(attack)
|
||||
_targets.reserve(targets.size());
|
||||
for (auto target : targets) {
|
||||
_targets.insert({target, TargetData(numberHits)});
|
||||
_targets.Insert(target, TargetData(numberHits));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,17 +77,17 @@ namespace CreatureLib::Battling {
|
||||
|
||||
TargetData* GetAttackDataForTarget(Creature* creature) { return &_targets[creature]; }
|
||||
|
||||
bool IsCreatureTarget(Creature* creature) { return _targets.find(creature) != _targets.end(); }
|
||||
bool IsCreatureTarget(Creature* creature) { return _targets.Has(creature); }
|
||||
|
||||
std::unordered_map<Creature*, TargetData>& GetTargets() { return _targets; }
|
||||
Dictionary<Creature*, TargetData>& GetTargets() { return _targets; }
|
||||
|
||||
Creature* GetUser() { return _user; }
|
||||
|
||||
LearnedAttack* GetAttack() { return _attack; }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override {
|
||||
scripts.emplace_back(&_script);
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(&_script);
|
||||
_user->GetActiveScripts(scripts);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,41 +1,42 @@
|
||||
#ifndef CREATURELIB_SCRIPTAGGREGATOR_HPP
|
||||
#define CREATURELIB_SCRIPTAGGREGATOR_HPP
|
||||
|
||||
#include <any>
|
||||
#include <queue>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include "../../Library/Exceptions/NotReachableException.hpp"
|
||||
#include "Script.hpp"
|
||||
#include "ScriptSet.hpp"
|
||||
#include "ScriptWrapper.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptAggregator {
|
||||
std::vector<ScriptWrapper> _scripts;
|
||||
List<ScriptWrapper> _scripts;
|
||||
size_t _index = 0;
|
||||
bool _isSetSet = false;
|
||||
const std::vector<Script*>* _setScripts;
|
||||
const List<Script*>* _setScripts;
|
||||
size_t _setIndex;
|
||||
|
||||
public:
|
||||
ScriptAggregator(std::vector<ScriptWrapper> scripts) : _scripts(std::move(scripts)){};
|
||||
ScriptAggregator(List<ScriptWrapper> scripts) : _scripts(std::move(scripts)){};
|
||||
|
||||
bool HasNext() { return _index < _scripts.size() || (_isSetSet && _setIndex < _setScripts->size()); }
|
||||
bool HasNext() { return _index < _scripts.Count() || (_isSetSet && _setIndex < _setScripts->Count()); }
|
||||
|
||||
Script* GetNext() {
|
||||
// We can probably do this in a cleaner version once C++ 20 drops with Coroutine support.
|
||||
if (_isSetSet) {
|
||||
if (_setIndex >= _setScripts->size()) {
|
||||
if (_setIndex >= _setScripts->Count()) {
|
||||
_isSetSet = false;
|
||||
return GetNext();
|
||||
}
|
||||
auto s = _setScripts->at(_setIndex);
|
||||
auto s = _setScripts->At(_setIndex);
|
||||
_setIndex++;
|
||||
if (_setIndex >= _setScripts->size()) {
|
||||
if (_setIndex >= _setScripts->Count()) {
|
||||
_isSetSet = false;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
if (_index >= _scripts.size())
|
||||
if (_index >= _scripts.Count())
|
||||
return nullptr;
|
||||
auto next = _scripts[_index];
|
||||
_index++;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptSet {
|
||||
std::vector<Script*> _scripts;
|
||||
Arbutils::Collections::List<Script*> _scripts;
|
||||
std::unordered_map<uint32_t, size_t> _lookup;
|
||||
|
||||
public:
|
||||
@@ -24,8 +24,8 @@ namespace CreatureLib::Battling {
|
||||
delete script;
|
||||
return;
|
||||
}
|
||||
_scripts.push_back(script);
|
||||
_lookup.insert({script->GetName(), _scripts.size() - 1});
|
||||
_scripts.Append(script);
|
||||
_lookup.insert({script->GetName(), _scripts.Count() - 1});
|
||||
}
|
||||
|
||||
Script* Get(const ConstString& key) const { return Get(key.GetHash()); }
|
||||
@@ -46,7 +46,7 @@ namespace CreatureLib::Battling {
|
||||
auto script = _scripts[find->second];
|
||||
script->OnRemove();
|
||||
delete script;
|
||||
_scripts.erase(_scripts.begin() + find.operator*().second);
|
||||
_scripts.Remove(find.operator*().second);
|
||||
_lookup.erase(keyHash);
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace CreatureLib::Battling {
|
||||
for (auto s : _scripts) {
|
||||
delete s;
|
||||
}
|
||||
_scripts.clear();
|
||||
_scripts.Clear();
|
||||
_lookup.clear();
|
||||
}
|
||||
|
||||
@@ -63,9 +63,9 @@ namespace CreatureLib::Battling {
|
||||
|
||||
bool Has(uint32_t keyHash) const { return _lookup.find(keyHash) != _lookup.end(); }
|
||||
|
||||
size_t Count() const { return _scripts.size(); }
|
||||
size_t Count() const { return _scripts.Count(); }
|
||||
|
||||
const std::vector<Script*>* GetIterator() const { return &_scripts; }
|
||||
const Arbutils::Collections::List<Script*>* GetIterator() const { return &_scripts; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptSource {
|
||||
bool _areScriptsInitialized = false;
|
||||
std::vector<ScriptWrapper> _scripts;
|
||||
Arbutils::Collections::List<ScriptWrapper> _scripts;
|
||||
|
||||
protected:
|
||||
virtual void GetActiveScripts(std::vector<ScriptWrapper>& scripts) = 0;
|
||||
virtual void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) = 0;
|
||||
void ResetActiveScripts() {
|
||||
_areScriptsInitialized = false;
|
||||
_scripts.clear();
|
||||
_scripts.Clear();
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace CreatureLib::Battling {
|
||||
Script* GetAttackScript() const { return _attackScript; }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override {
|
||||
scripts.emplace_back(&_attackScript);
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(&_attackScript);
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,7 +12,9 @@ namespace CreatureLib::Battling {
|
||||
TurnChoiceKind GetKind() const override { return TurnChoiceKind ::Flee; }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override { GetUser()->GetActiveScripts(scripts); }
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ namespace CreatureLib::Battling {
|
||||
TurnChoiceKind GetKind() const override { return TurnChoiceKind ::Pass; }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override { GetUser()->GetActiveScripts(scripts); }
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,9 @@ namespace CreatureLib::Battling {
|
||||
inline Creature* GetNewCreature() const { return _newCreature; }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override { GetUser()->GetActiveScripts(scripts); }
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CREATURELIB_BASELIBRARY_HPP
|
||||
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
@@ -9,7 +10,7 @@
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
template <class T> class BaseLibrary {
|
||||
std::unordered_map<uint32_t, const T*> _values;
|
||||
Arbutils::Collections::Dictionary<uint32_t, const T*> _values;
|
||||
|
||||
public:
|
||||
BaseLibrary(size_t initialCapacity = 32) : _values(initialCapacity) {}
|
||||
@@ -18,46 +19,40 @@ namespace CreatureLib::Library {
|
||||
for (const auto& v : _values) {
|
||||
delete v.second;
|
||||
}
|
||||
_values.clear();
|
||||
_values.Clear();
|
||||
}
|
||||
|
||||
inline void Insert(const Arbutils::CaseInsensitiveConstString& key, const T* value) {
|
||||
AssertNotNull(value)
|
||||
_values.insert({key.GetHash(), value});
|
||||
_values.Insert(key.GetHash(), value);
|
||||
}
|
||||
inline void Insert(uint32_t hashedKey, const T* value) {
|
||||
AssertNotNull(value)
|
||||
_values.insert({hashedKey, value});
|
||||
_values.Insert(hashedKey, value);
|
||||
}
|
||||
|
||||
inline void Delete(const Arbutils::CaseInsensitiveConstString& key) { _values.erase(key.GetHash()); }
|
||||
inline void Delete(uint32_t hashedKey) { _values.erase({hashedKey}); }
|
||||
inline void Delete(uint32_t hashedKey) { _values.Remove(hashedKey); }
|
||||
|
||||
bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const T*& out) const {
|
||||
return TryGet(name.GetHash(), out);
|
||||
}
|
||||
bool TryGet(uint32_t hashedKey, const T*& out) const {
|
||||
auto find = this->_values.find(hashedKey);
|
||||
if (find == this->_values.end()) {
|
||||
out = nullptr;
|
||||
return false;
|
||||
}
|
||||
out = find->second;
|
||||
return true;
|
||||
}
|
||||
bool TryGet(uint32_t hashedKey, const T*& out) const { return _values.TryGet(hashedKey, out); }
|
||||
|
||||
[[nodiscard]] inline const T* Get(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return _values.at(name.GetHash());
|
||||
return _values.Get(name.GetHash());
|
||||
}
|
||||
[[nodiscard]] inline const T* Get(uint32_t hashedKey) const { return _values.at(hashedKey); }
|
||||
[[nodiscard]] inline const T* Get(uint32_t hashedKey) const { return _values.Get(hashedKey); }
|
||||
|
||||
[[nodiscard]] inline const T* operator[](const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return Get(name);
|
||||
}
|
||||
[[nodiscard]] inline const T* operator[](uint32_t hashedKey) const { return Get(hashedKey); }
|
||||
[[nodiscard]] inline const std::unordered_map<uint32_t, const T*>& GetIterator() const { return _values; }
|
||||
[[nodiscard]] inline const Arbutils::Collections::Dictionary<uint32_t, const T*>& GetIterator() const {
|
||||
return _values;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t GetCount() const { return _values.size(); }
|
||||
[[nodiscard]] size_t GetCount() const { return _values.Count(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,30 +10,21 @@ CreatureSpecies::CreatureSpecies(uint16_t id, const ConstString& name, const Spe
|
||||
AssertNotNull(defaultVariant)
|
||||
}
|
||||
|
||||
bool CreatureSpecies::HasVariant(const ConstString& name) const { return _variants.find(name) != _variants.end(); }
|
||||
bool CreatureSpecies::HasVariant(const ConstString& name) const { return _variants.Has(name); }
|
||||
|
||||
bool CreatureSpecies::TryGetVariant(const ConstString& name, const SpeciesVariant*& out) const {
|
||||
return TryGetVariant(name.GetHash(), out);
|
||||
}
|
||||
bool CreatureSpecies::TryGetVariant(uint32_t hash, const SpeciesVariant*& out) const {
|
||||
auto find = _variants.find(hash);
|
||||
if (find != _variants.end()) {
|
||||
out = find->second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return _variants.TryGet(hash, out);
|
||||
}
|
||||
|
||||
const SpeciesVariant* CreatureSpecies::GetVariant(const ConstString& name) const { return _variants.at(name); }
|
||||
const SpeciesVariant* CreatureSpecies::GetVariant(uint32_t key) const { return _variants.at(key); }
|
||||
bool CreatureSpecies::HasVariant(uint32_t hash) const { return _variants.at(hash); }
|
||||
const SpeciesVariant* CreatureSpecies::GetVariant(const ConstString& name) const { return _variants.Get(name); }
|
||||
const SpeciesVariant* CreatureSpecies::GetVariant(uint32_t key) const { return _variants.Get(key); }
|
||||
bool CreatureSpecies::HasVariant(uint32_t hash) const { return _variants.Has(hash); }
|
||||
|
||||
void CreatureSpecies::SetVariant(const ConstString& name, const SpeciesVariant* variant) {
|
||||
auto find = _variants.find(name);
|
||||
if (find != _variants.end()) {
|
||||
delete find->second;
|
||||
}
|
||||
_variants[name] = variant;
|
||||
_variants.Insert(name, variant);
|
||||
}
|
||||
|
||||
Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef CREATURELIB_CREATURESPECIES_HPP
|
||||
#define CREATURELIB_CREATURESPECIES_HPP
|
||||
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -20,7 +21,7 @@ namespace CreatureLib::Library {
|
||||
float _genderRate;
|
||||
const ConstString _growthRate;
|
||||
uint8_t _captureRate;
|
||||
std::unordered_map<uint32_t, const SpeciesVariant*> _variants;
|
||||
Arbutils::Collections::Dictionary<uint32_t, const SpeciesVariant*> _variants;
|
||||
|
||||
public:
|
||||
CreatureSpecies(uint16_t id, const ConstString& name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
@@ -29,7 +30,7 @@ namespace CreatureLib::Library {
|
||||
virtual ~CreatureSpecies() {
|
||||
for (auto v : _variants)
|
||||
delete v.second;
|
||||
_variants.clear();
|
||||
_variants.Clear();
|
||||
}
|
||||
|
||||
inline uint16_t GetId() const { return _id; }
|
||||
@@ -48,7 +49,9 @@ namespace CreatureLib::Library {
|
||||
|
||||
void SetVariant(const ConstString& name, const SpeciesVariant* variant);
|
||||
|
||||
const std::unordered_map<uint32_t, const SpeciesVariant*>& GetVariantsIterator() const { return _variants; }
|
||||
const Arbutils::Collections::Dictionary<uint32_t, const SpeciesVariant*>& GetVariantsIterator() const {
|
||||
return _variants;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
void LearnableAttacks::AddLevelMove(uint8_t level, const AttackData* attack) {
|
||||
auto find = _learnedByLevel.find(level);
|
||||
if (find != _learnedByLevel.end()) {
|
||||
find->second.push_back(attack);
|
||||
|
||||
List<const AttackData*> levelData;
|
||||
if (_learnedByLevel.TryGet(level, levelData)) {
|
||||
levelData.Append(attack);
|
||||
} else {
|
||||
_learnedByLevel.insert({level, {attack}});
|
||||
levelData = {attack};
|
||||
_learnedByLevel.Insert(level, levelData);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<const AttackData*>& LearnableAttacks::GetAttacksForLevel(uint8_t level) const {
|
||||
return _learnedByLevel.at(level);
|
||||
const List<const AttackData*>& LearnableAttacks::GetAttacksForLevel(uint8_t level) const {
|
||||
return _learnedByLevel.Get(level);
|
||||
}
|
||||
|
||||
@@ -2,17 +2,20 @@
|
||||
#define CREATURELIB_LEARNABLEATTACKS_HPP
|
||||
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "../Attacks/AttackData.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class LearnableAttacks {
|
||||
std::unordered_map<uint8_t, std::vector<const AttackData*>> _learnedByLevel;
|
||||
Dictionary<uint8_t, List<const AttackData*>> _learnedByLevel;
|
||||
|
||||
public:
|
||||
LearnableAttacks(size_t levelAttackCapacity)
|
||||
: _learnedByLevel(std::unordered_map<uint8_t, std::vector<const AttackData*>>(levelAttackCapacity)) {
|
||||
: _learnedByLevel(Dictionary<uint8_t, List<const AttackData*>>(levelAttackCapacity)) {
|
||||
for (auto kv : _learnedByLevel) {
|
||||
for (auto attack : kv.second)
|
||||
AssertNotNull(attack)
|
||||
@@ -21,7 +24,7 @@ namespace CreatureLib::Library {
|
||||
|
||||
void AddLevelMove(uint8_t level, const AttackData* attack);
|
||||
|
||||
const std::vector<const AttackData*>& GetAttacksForLevel(uint8_t level) const;
|
||||
const List<const AttackData*>& GetAttacksForLevel(uint8_t level) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
const std::vector<uint8_t>& CreatureLib::Library::SpeciesVariant::GetTypes() const { return _types; }
|
||||
const List<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.Count(); }
|
||||
|
||||
uint8_t CreatureLib::Library::SpeciesVariant::GetType(size_t index) const { return _types[index]; }
|
||||
|
||||
@@ -14,13 +14,13 @@ uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Library
|
||||
|
||||
const CreatureLib::Library::TalentIndex
|
||||
CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ConstString& talent) const {
|
||||
for (size_t i = 0; i < _talents.size(); i++) {
|
||||
if (_talents.at(i) == talent) {
|
||||
for (size_t i = 0; i < _talents.Count(); i++) {
|
||||
if (_talents.At(i) == talent) {
|
||||
return TalentIndex(false, i);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < _secretTalents.size(); i++) {
|
||||
if (_secretTalents.at(i) == talent) {
|
||||
for (size_t i = 0; i < _secretTalents.Count(); i++) {
|
||||
if (_secretTalents.At(i) == talent) {
|
||||
return TalentIndex(true, i);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ConstString& talent)
|
||||
}
|
||||
|
||||
CreatureLib::Library::TalentIndex CreatureLib::Library::SpeciesVariant::GetRandomTalent(Arbutils::Random* rand) const {
|
||||
return TalentIndex(false, rand->Get(_talents.size()));
|
||||
return TalentIndex(false, rand->Get(_talents.Count()));
|
||||
}
|
||||
|
||||
const CreatureLib::Library::LearnableAttacks* CreatureLib::Library::SpeciesVariant::GetLearnableAttacks() const {
|
||||
@@ -36,10 +36,9 @@ const CreatureLib::Library::LearnableAttacks* CreatureLib::Library::SpeciesVaria
|
||||
}
|
||||
|
||||
CreatureLib::Library::SpeciesVariant::SpeciesVariant(ConstString name, float height, float weight,
|
||||
uint32_t baseExperience, std::vector<uint8_t> types,
|
||||
uint32_t baseExperience, List<uint8_t> types,
|
||||
CreatureLib::Library::StatisticSet<uint16_t> baseStats,
|
||||
std::vector<ConstString> talents,
|
||||
std::vector<ConstString> secretTalents,
|
||||
List<ConstString> talents, List<ConstString> secretTalents,
|
||||
const LearnableAttacks* attacks)
|
||||
: _name(std::move(name)), _height(height), _weight(weight), _baseExperience(baseExperience),
|
||||
_types(std::move(types)), _baseStatistics(baseStats), _talents(std::move(talents)),
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#ifndef CREATURELIB_SPECIESVARIANT_HPP
|
||||
#define CREATURELIB_SPECIESVARIANT_HPP
|
||||
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/Random.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../StatisticSet.hpp"
|
||||
#include "CreatureMoves.hpp"
|
||||
#include "LearnableAttacks.hpp"
|
||||
#include "TalentIndex.hpp"
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
@@ -22,17 +23,16 @@ namespace CreatureLib::Library {
|
||||
uint32_t _baseExperience;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> _types;
|
||||
List<uint8_t> _types;
|
||||
Library::StatisticSet<uint16_t> _baseStatistics;
|
||||
std::vector<ConstString> _talents;
|
||||
std::vector<ConstString> _secretTalents;
|
||||
List<ConstString> _talents;
|
||||
List<ConstString> _secretTalents;
|
||||
const LearnableAttacks* _attacks;
|
||||
|
||||
public:
|
||||
SpeciesVariant(ConstString name, float height, float weight, uint32_t baseExperience,
|
||||
std::vector<uint8_t> types, Library::StatisticSet<uint16_t> baseStats,
|
||||
std::vector<ConstString> talents, std::vector<ConstString> secretTalents,
|
||||
const LearnableAttacks* attacks);
|
||||
SpeciesVariant(ConstString name, float height, float weight, uint32_t baseExperience, List<uint8_t> types,
|
||||
Library::StatisticSet<uint16_t> baseStats, List<ConstString> talents,
|
||||
List<ConstString> secretTalents, const LearnableAttacks* attacks);
|
||||
|
||||
virtual ~SpeciesVariant();
|
||||
|
||||
@@ -43,21 +43,21 @@ namespace CreatureLib::Library {
|
||||
|
||||
[[nodiscard]] size_t GetTypeCount() const;
|
||||
[[nodiscard]] uint8_t GetType(size_t index) const;
|
||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||
[[nodiscard]] const List<uint8_t>& GetTypes() const;
|
||||
[[nodiscard]] uint32_t GetStatistic(Library::Statistic stat) const;
|
||||
[[nodiscard]] const size_t GetTalentCount() const { return _talents.size(); }
|
||||
[[nodiscard]] const size_t GetSecretTalentCount() const { return _secretTalents.size(); }
|
||||
[[nodiscard]] const size_t GetTalentCount() const { return _talents.Count(); }
|
||||
[[nodiscard]] const size_t GetSecretTalentCount() const { return _secretTalents.Count(); }
|
||||
[[nodiscard]] const ConstString& GetTalent(const TalentIndex& index) const {
|
||||
if (index.IsSecret())
|
||||
return _secretTalents.at(index.GetIndex());
|
||||
return _talents.at(index.GetIndex());
|
||||
return _secretTalents.At(index.GetIndex());
|
||||
return _talents.At(index.GetIndex());
|
||||
}
|
||||
[[nodiscard]] const TalentIndex GetTalentIndex(const ConstString& talent) const;
|
||||
|
||||
[[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const;
|
||||
[[nodiscard]] TalentIndex GetRandomTalent(Arbutils::Random* rand) const;
|
||||
[[nodiscard]] inline const std::vector<ConstString>& GetTalents() const { return _talents; }
|
||||
[[nodiscard]] inline const std::vector<ConstString>& GetSecretTalents() const { return _secretTalents; }
|
||||
[[nodiscard]] inline const List<ConstString>& GetTalents() const { return _talents; }
|
||||
[[nodiscard]] inline const List<ConstString>& GetSecretTalents() const { return _secretTalents; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,27 @@
|
||||
#ifndef CREATURELIB_LOOKUPGROWTHRATE_HPP
|
||||
#define CREATURELIB_LOOKUPGROWTHRATE_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include "GrowthRate.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class LookupGrowthRate : public GrowthRate {
|
||||
protected:
|
||||
std::vector<uint32_t> _experience;
|
||||
Arbutils::Collections::List<uint32_t> _experience;
|
||||
|
||||
public:
|
||||
LookupGrowthRate(const std::vector<uint32_t>& experience) : _experience(experience) {}
|
||||
LookupGrowthRate(const Arbutils::Collections::List<uint32_t>& experience) : _experience(experience) {}
|
||||
|
||||
uint8_t CalculateLevel(uint32_t experience) const override {
|
||||
for (uint8_t i = 0; i < _experience.size(); i++) {
|
||||
for (uint8_t i = 0; i < _experience.Count(); i++) {
|
||||
if (_experience[i] > experience) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return _experience[_experience.size() - 1];
|
||||
return _experience[_experience.Count() - 1];
|
||||
}
|
||||
|
||||
uint32_t CalculateExperience(uint8_t level) const override {
|
||||
Assert(level <= _experience.size())
|
||||
return _experience[level - 1];
|
||||
}
|
||||
uint32_t CalculateExperience(uint8_t level) const override { return _experience[level - 1]; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
float TypeLibrary::GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const {
|
||||
float TypeLibrary::GetEffectiveness(uint8_t attacking, const List<uint8_t>& defensive) const {
|
||||
auto eff = 1;
|
||||
for (auto def : defensive) {
|
||||
eff *= GetSingleEffectiveness(attacking, def);
|
||||
@@ -12,33 +12,29 @@ float TypeLibrary::GetEffectiveness(uint8_t attacking, const std::vector<uint8_t
|
||||
}
|
||||
|
||||
float TypeLibrary::GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const {
|
||||
Assert(attacking < _effectiveness.size())
|
||||
Assert(defensive < _effectiveness.size())
|
||||
return _effectiveness[attacking][defensive];
|
||||
}
|
||||
|
||||
uint8_t TypeLibrary::GetTypeId(const ConstString& key) const { return _types.at(key); }
|
||||
uint8_t TypeLibrary::GetTypeId(uint32_t s) const { return _types.at(s); }
|
||||
uint8_t TypeLibrary::GetTypeId(const ConstString& key) const { return _types.Get(key); }
|
||||
uint8_t TypeLibrary::GetTypeId(uint32_t s) const { return _types.Get(s); }
|
||||
|
||||
uint8_t TypeLibrary::RegisterType(const ConstString& key) {
|
||||
_types.insert({key, _types.size()});
|
||||
_effectiveness.resize(_types.size());
|
||||
_types.Insert(key, _types.Count());
|
||||
_effectiveness.Resize(_types.Count());
|
||||
for (auto& eff : _effectiveness) {
|
||||
eff.resize(_types.size(), 1);
|
||||
eff.Resize(_types.Count(), 1);
|
||||
}
|
||||
return _types.size() - 1;
|
||||
return _types.Count() - 1;
|
||||
}
|
||||
uint8_t TypeLibrary::RegisterType(uint32_t key) {
|
||||
_types.insert({key, _types.size()});
|
||||
_effectiveness.resize(_types.size());
|
||||
_types.Insert(key, _types.Count());
|
||||
_effectiveness.Resize(_types.Count());
|
||||
for (auto& eff : _effectiveness) {
|
||||
eff.resize(_types.size(), 1);
|
||||
eff.Resize(_types.Count(), 1);
|
||||
}
|
||||
return _types.size() - 1;
|
||||
return _types.Count() - 1;
|
||||
}
|
||||
|
||||
void TypeLibrary::SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness) {
|
||||
Assert(attacking < _effectiveness.size())
|
||||
Assert(defensive < _effectiveness.size())
|
||||
_effectiveness[attacking][defensive] = effectiveness;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
#ifndef CREATURELIB_TYPELIBRARY_HPP
|
||||
#define CREATURELIB_TYPELIBRARY_HPP
|
||||
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class TypeLibrary {
|
||||
std::unordered_map<uint32_t, uint8_t> _types;
|
||||
std::vector<std::vector<float>> _effectiveness;
|
||||
Dictionary<uint32_t, uint8_t> _types;
|
||||
List<List<float>> _effectiveness;
|
||||
|
||||
public:
|
||||
TypeLibrary(size_t initialCapacity = 20) : _types(std::unordered_map<uint32_t, uint8_t>(initialCapacity)) {}
|
||||
TypeLibrary(size_t initialCapacity = 20) : _types(Dictionary<uint32_t, uint8_t>(initialCapacity)) {}
|
||||
|
||||
uint8_t GetTypeId(const ConstString& s) const;
|
||||
uint8_t GetTypeId(uint32_t s) const;
|
||||
[[nodiscard]] float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
|
||||
[[nodiscard]] float GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const;
|
||||
[[nodiscard]] float GetEffectiveness(uint8_t attacking, const List<uint8_t>& defensive) const;
|
||||
|
||||
uint8_t RegisterType(const ConstString& typeName);
|
||||
uint8_t RegisterType(uint32_t typeHash);
|
||||
|
||||
Reference in New Issue
Block a user