Replace most collections with Arbutils collections for more safety.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f190121e74
commit
27288563cd
|
@ -5,7 +5,7 @@ using namespace CreatureLib::Battling;
|
|||
export Battle* CreatureLib_Battle_Construct(const BattleLibrary* library, BattleParty* partyArr[],
|
||||
size_t numberOfParties, bool canFlee, uint8_t numberOfSides,
|
||||
uint8_t creaturesPerSide) {
|
||||
std::vector<BattleParty*> parties(partyArr, partyArr + numberOfParties);
|
||||
List<BattleParty*> parties(partyArr, partyArr + numberOfParties);
|
||||
return new Battle(library, parties, canFlee, numberOfSides, creaturesPerSide);
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,8 @@ export bool CreatureLib_Battle_HasEnded(const Battle* p) { return p->HasEnded();
|
|||
export bool CreatureLib_Battle_HasConclusiveResult(const Battle* p) { return p->GetResult().IsConclusiveResult(); }
|
||||
export bool CreatureLib_Battle_GetWinningSide(const Battle* p) { return p->GetResult().GetWinningSide(); }
|
||||
|
||||
export size_t CreatureLib_Battle_GetSidesCount(const Battle* p) { return p->GetSides().size(); }
|
||||
export BattleSide* const* CreatureLib_Battle_GetSides(const Battle* p) { return p->GetSides().data(); }
|
||||
export size_t CreatureLib_Battle_GetSidesCount(const Battle* p) { return p->GetSides().Count(); }
|
||||
export BattleSide* const* CreatureLib_Battle_GetSides(const Battle* p) { return p->GetSides().RawData(); }
|
||||
|
||||
export Script* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) {
|
||||
return p->GetVolatileScript(ConstString::GetHash(key));
|
||||
|
|
|
@ -6,7 +6,7 @@ using namespace CreatureLib::Battling;
|
|||
// side, one after the other.
|
||||
export BattleParty* CreatureLib_BattleParty_Construct(CreatureParty* p, uint8_t creatureIndices[],
|
||||
size_t numberOfIndices) {
|
||||
std::vector<CreatureIndex> indices(numberOfIndices);
|
||||
Arbutils::Collections::List<CreatureIndex> indices(numberOfIndices);
|
||||
for (size_t i = 0; i < numberOfIndices; i++) {
|
||||
indices[i] = CreatureIndex(creatureIndices[i * 2], creatureIndices[i * 2 + 1]);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ export Creature* CreatureLib_Creature_Construct(const BattleLibrary* library,
|
|||
uint8_t coloring, const CreatureLib::Library::Item* heldItem,
|
||||
std::string nickname, bool secretTalent, const uint8_t talent,
|
||||
LearnedAttack* attacks[], size_t attacksNum) {
|
||||
auto attacksVec = std::vector<LearnedAttack*>(attacks, attacks + attacksNum);
|
||||
auto attacksVec = List<LearnedAttack*>(attacks, attacks + attacksNum);
|
||||
return new Creature(library, species, variant, level, experience, uid, gender, coloring, heldItem, nickname,
|
||||
CreatureLib::Library::TalentIndex(secretTalent, talent), attacksVec);
|
||||
};
|
||||
|
@ -44,8 +44,8 @@ SIMPLE_GET_FUNC(Creature, GetBattle, Battle*);
|
|||
SIMPLE_GET_FUNC(Creature, GetBattleSide, BattleSide*);
|
||||
SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool);
|
||||
export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().c_str(); }
|
||||
export size_t CreatureLib_Creature_GetTypesCount(Creature* p) { return p->GetTypes().size(); }
|
||||
export const uint8_t* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().data(); }
|
||||
export size_t CreatureLib_Creature_GetTypesCount(Creature* p) { return p->GetTypes().Count(); }
|
||||
export const uint8_t* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().RawData(); }
|
||||
export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); }
|
||||
SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t);
|
||||
export void CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { return p->ChangeLevelBy(level); }
|
||||
|
@ -64,8 +64,7 @@ export void CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char
|
|||
return p->AddVolatileScript(ConstString(scriptName));
|
||||
}
|
||||
export void CreatureLib_Creature_AddVolatileScript(Creature* p, Script* script) {
|
||||
return p->AddVolatileScript(script);
|
||||
}
|
||||
return p->AddVolatileScript(script); }
|
||||
export void CreatureLib_Creature_RemoveVolatileScriptByName(Creature* p, const char* scriptName) {
|
||||
return p->RemoveVolatileScript(ConstString(scriptName));
|
||||
}
|
||||
|
@ -75,8 +74,8 @@ export void CreatureLib_Creature_RemoveVolatileScript(Creature* p, Script* scrip
|
|||
export bool CreatureLib_Creature_HasVolatileScript(Creature* p, const char* scriptName) {
|
||||
return p->HasVolatileScript(ConstString(scriptName));
|
||||
}
|
||||
export size_t CreatureLib_Creature_GetAttacksCount(Creature* p) { return p->GetAttacks().size(); }
|
||||
export LearnedAttack** CreatureLib_Creature_GetAttacks(Creature* p) { return p->GetAttacks().data(); }
|
||||
export size_t CreatureLib_Creature_GetAttacksCount(Creature* p) { return p->GetAttacks().Count(); }
|
||||
export LearnedAttack* const* CreatureLib_Creature_GetAttacks(Creature* p) { return p->GetAttacks().RawData(); }
|
||||
SIMPLE_GET_FUNC(Creature, GetDisplaySpecies, const CreatureLib::Library::CreatureSpecies*);
|
||||
SIMPLE_GET_FUNC(Creature, GetDisplayVariant, const CreatureLib::Library::SpeciesVariant*);
|
||||
export void CreatureLib_Creature_SetDisplaySpecies(Creature* p, const CreatureLib::Library::CreatureSpecies* species) {
|
||||
|
|
|
@ -4,7 +4,7 @@ using namespace CreatureLib::Battling;
|
|||
|
||||
export CreatureParty* CreatureLib_CreatureParty_ConstructWithSize(size_t size) { return new CreatureParty(size); }
|
||||
export CreatureParty* CreatureLib_CreatureParty_ConstructFromArray(Creature* creatures[], size_t size) {
|
||||
return new CreatureParty(std::vector<Creature*>(creatures, creatures + size));
|
||||
return new CreatureParty(Arbutils::Collections::List<Creature*>(creatures, creatures + size));
|
||||
}
|
||||
|
||||
export void CreatureLib_CreatureParty_Destruct(const CreatureParty* p) { delete p; }
|
||||
|
@ -21,4 +21,4 @@ export bool CreatureLib_CreatureParty_HasAvailableCreatures(const CreatureParty*
|
|||
|
||||
export size_t CreatureLib_CreatureParty_GetLength(const CreatureParty* p) { return p->GetLength(); }
|
||||
|
||||
export Creature** CreatureLib_CreatureParty_GetParty(CreatureParty* p) { return p->GetParty().data(); }
|
||||
export Creature* const* CreatureLib_CreatureParty_GetParty(CreatureParty* p) { return p->GetParty().RawData(); }
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
using namespace CreatureLib::Library;
|
||||
|
||||
export GrowthRate* CreatureLib_LookupGrowthRate_Construct(uint32_t experiencePerLevel[], size_t count) {
|
||||
std::vector<uint32_t> exp(experiencePerLevel, experiencePerLevel + count);
|
||||
Arbutils::Collections::List<uint32_t> exp(experiencePerLevel, experiencePerLevel + count);
|
||||
return new LookupGrowthRate(exp);
|
||||
};
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ export void CreatureLib_LearnableAttacks_AddLevelMove(LearnableAttacks* p, uint8
|
|||
}
|
||||
|
||||
export const AttackData* const* CreatureLib_LearnableAttacks_GetAttacksForLevel(LearnableAttacks* p, uint8_t level) {
|
||||
return p->GetAttacksForLevel(level).data();
|
||||
return p->GetAttacksForLevel(level).RawData();
|
||||
}
|
||||
export size_t CreatureLib_LearnableAttacks_GetAttacksForLevelCount(LearnableAttacks* p, uint8_t level) {
|
||||
return p->GetAttacksForLevel(level).size();
|
||||
return p->GetAttacksForLevel(level).Count();
|
||||
}
|
|
@ -10,17 +10,17 @@ export SpeciesVariant* CreatureLib_SpeciesVariant_Construct(
|
|||
uint16_t baseMagicalDefense, uint8_t baseSpeed, const char* talents[], size_t talentsLength,
|
||||
const char* secretTalents[], size_t secretTalentsLength, const LearnableAttacks* attacks) {
|
||||
|
||||
auto talentsWrapped = std::vector<ConstString>(talentsLength);
|
||||
auto talentsWrapped = Arbutils::Collections::List<ConstString>(talentsLength);
|
||||
for (size_t i = 0; i < talentsLength; i++) {
|
||||
talentsWrapped[i] = ConstString(talents[i]);
|
||||
}
|
||||
auto secretTalentsWrapped = std::vector<ConstString>(secretTalentsLength);
|
||||
auto secretTalentsWrapped = Arbutils::Collections::List<ConstString>(secretTalentsLength);
|
||||
for (size_t i = 0; i < secretTalentsLength; i++) {
|
||||
secretTalentsWrapped[i] = ConstString(secretTalents[i]);
|
||||
}
|
||||
|
||||
return new SpeciesVariant(Arbutils::CaseInsensitiveConstString(name), height, weight, baseExperience,
|
||||
std::vector<uint8_t>(types, types + typeLength),
|
||||
Arbutils::Collections::List<uint8_t>(types, types + typeLength),
|
||||
CreatureLib::Library::StatisticSet<uint16_t>(baseHealth, baseAttack, baseDefense,
|
||||
baseMagicalAttack, baseMagicalDefense,
|
||||
baseSpeed),
|
||||
|
|
|
@ -33,5 +33,5 @@ export float CreatureLib_TypeLibrary_GetSingleEffectiveness(TypeLibrary* p, uint
|
|||
|
||||
export float CreatureLib_TypeLibrary_GetEffectiveness(TypeLibrary* p, uint8_t attacking, uint8_t defensive[],
|
||||
size_t defensiveCount) {
|
||||
return p->GetEffectiveness(attacking, std::vector<uint8_t>(defensive, defensive + defensiveCount));
|
||||
return p->GetEffectiveness(attacking, List<uint8_t>(defensive, defensive + defensiveCount));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
TEST_CASE("Script Aggregator properly iterates containing script.", "[Battling, Scripting]") {
|
||||
Script* script = new TestScript("test");
|
||||
auto ran = 0;
|
||||
auto vec = std::vector<ScriptWrapper>{&script};
|
||||
auto vec = Arbutils::Collections::List<ScriptWrapper>{&script};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNext();
|
||||
|
@ -37,7 +37,7 @@ TEST_CASE("Script Aggregator properly iterates multiple scripts.", "[Battling, S
|
|||
Script* script2 = new TestScript("test2");
|
||||
Script* script3 = new TestScript("test3");
|
||||
auto ran = 0;
|
||||
auto vec = std::vector<ScriptWrapper>{&script, &script2, &script3};
|
||||
auto vec = Arbutils::Collections::List<ScriptWrapper>{&script, &script2, &script3};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNext();
|
||||
|
@ -59,7 +59,7 @@ TEST_CASE("Script Aggregator properly iterates Script Set.", "[Battling, Scripti
|
|||
set.Add(script);
|
||||
set.Add(script2);
|
||||
set.Add(script3);
|
||||
auto vec = std::vector<ScriptWrapper>{&set};
|
||||
auto vec = Arbutils::Collections::List<ScriptWrapper>{&set};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNext();
|
||||
|
@ -77,7 +77,7 @@ TEST_CASE("Script Aggregator properly iterates data of Script Set and Script.",
|
|||
auto set = ScriptSet();
|
||||
set.Add(script2);
|
||||
set.Add(script3);
|
||||
auto vec = std::vector<ScriptWrapper>{&set, &script};
|
||||
auto vec = Arbutils::Collections::List<ScriptWrapper>{&set, &script};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNext();
|
||||
|
@ -96,7 +96,7 @@ TEST_CASE("Script Aggregator properly iterates data of Script and Script Set.",
|
|||
auto set = ScriptSet();
|
||||
set.Add(script2);
|
||||
set.Add(script3);
|
||||
auto vec = std::vector<ScriptWrapper>{&script, &set};
|
||||
auto vec = Arbutils::Collections::List<ScriptWrapper>{&script, &set};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNext();
|
||||
|
@ -116,7 +116,7 @@ TEST_CASE("Script Aggregator properly iterates data of Script, Script Set and Sc
|
|||
auto set = ScriptSet();
|
||||
set.Add(script2);
|
||||
set.Add(script3);
|
||||
auto vec = std::vector<ScriptWrapper>{&script, &set, &script4};
|
||||
auto vec = Arbutils::Collections::List<ScriptWrapper>{&script, &set, &script4};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNext();
|
||||
|
@ -130,7 +130,7 @@ TEST_CASE("Script Aggregator properly iterates data of Script, Script Set and Sc
|
|||
|
||||
TEST_CASE("Script Aggregator properly iterates when empty.", "[Battling, Scripting]") {
|
||||
auto ran = 0;
|
||||
auto vec = std::vector<ScriptWrapper>{};
|
||||
auto vec = Arbutils::Collections::List<ScriptWrapper>{};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
throw CreatureException("Aggregator returned a script, but should have been empty.");
|
||||
|
@ -141,7 +141,7 @@ TEST_CASE("Script Aggregator properly iterates when empty.", "[Battling, Scripti
|
|||
TEST_CASE("Script Aggregator properly iterates empty Script Set.", "[Battling, Scripting]") {
|
||||
auto ran = 0;
|
||||
auto set = ScriptSet();
|
||||
auto vec = std::vector<ScriptWrapper>{&set};
|
||||
auto vec = Arbutils::Collections::List<ScriptWrapper>{&set};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNext();
|
||||
|
|
|
@ -33,7 +33,7 @@ TEST_CASE("Add script to script set, then retrieve it", "[Battling, Scripting]")
|
|||
auto s = new TestScript("foobar");
|
||||
set.Add(s);
|
||||
REQUIRE(set.Count() == 1);
|
||||
auto get = set.GetIterator()->at(0);
|
||||
auto get = set.GetIterator()->At(0);
|
||||
REQUIRE(get->GetName() == "foobar");
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,8 @@ TEST_CASE("Add two scripts to script set, then retrieve them", "[Battling, Scrip
|
|||
set.Add(s);
|
||||
set.Add(s2);
|
||||
REQUIRE(set.Count() == 2);
|
||||
auto get1 = set.GetIterator()->at(0);
|
||||
auto get2 = set.GetIterator()->at(1);
|
||||
auto get1 = set.GetIterator()->At(0);
|
||||
auto get2 = set.GetIterator()->At(1);
|
||||
REQUIRE(get1->GetName() == "foobar");
|
||||
REQUIRE(get2->GetName() == "foobar2");
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ TEST_CASE("Add script to script set, then remove it", "[Battling, Scripting]") {
|
|||
set.Remove("foobar"_cnc);
|
||||
REQUIRE(set.Count() == 0);
|
||||
auto it = set.GetIterator();
|
||||
REQUIRE(it->empty());
|
||||
REQUIRE(it->Count() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Add two scripts to script set, then remove them", "[Battling, Scripting]") {
|
||||
|
@ -80,7 +80,7 @@ TEST_CASE("Add two scripts to script set, then remove them", "[Battling, Scripti
|
|||
set.Remove("foobar"_cnc);
|
||||
REQUIRE(set.Count() == 1);
|
||||
auto it = set.GetIterator();
|
||||
REQUIRE(it->at(0)->GetName() == "foobar2");
|
||||
REQUIRE(it->At(0)->GetName() == "foobar2");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
Script* ScriptPtr = nullptr;
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override { scripts.emplace_back(&ScriptPtr); }
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override { scripts.Append(&ScriptPtr); }
|
||||
};
|
||||
|
||||
class ScriptSourceWithScriptSet : public ScriptSource {
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
ScriptSet Set;
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override { scripts.emplace_back(&Set); }
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override { scripts.Append(&Set); }
|
||||
};
|
||||
|
||||
TEST_CASE("Script source with unset script ptr.", "[Battling, Scripting]") {
|
||||
|
|
Loading…
Reference in New Issue