Make LearnedAttack of Creature a smart pointer.
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:
@@ -56,10 +56,10 @@ Creature* CreateCreature::Create() {
|
||||
}
|
||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
||||
|
||||
auto attacks = ArbUt::List<LearnedAttack*>(_attacks.Count());
|
||||
auto attacks = std::vector<LearnedAttack*>(_attacks.Count());
|
||||
for (size_t i = 0; i < _attacks.Count(); i++) {
|
||||
auto kv = _attacks[i];
|
||||
attacks.Append(new LearnedAttack(std::get<0>(kv), std::get<1>(kv)));
|
||||
attacks[i] = new LearnedAttack(std::get<0>(kv), std::get<1>(kv));
|
||||
}
|
||||
auto c = new Creature(_library, species, variant, _level, experience, identifier, gender, _coloring, heldItem,
|
||||
_nickname, talent, attacks);
|
||||
|
||||
@@ -11,7 +11,7 @@ Battling::Creature::Creature(const BattleLibrary* library,
|
||||
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level,
|
||||
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
|
||||
const ArbUt::BorrowedPtr<const Library::Item> heldItem, std::string nickname,
|
||||
const Library::TalentIndex& talent, const ArbUt::List<LearnedAttack*>& attacks,
|
||||
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
|
||||
bool allowedExperienceGain)
|
||||
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience),
|
||||
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _nickname(std::move(nickname)),
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include <Arbutils/Memory/UniquePtrList.hpp>
|
||||
#include "../../Library/ClampedStatisticSet.hpp"
|
||||
#include "../../Library/CreatureData/CreatureSpecies.hpp"
|
||||
#include "../../Library/Items/Item.hpp"
|
||||
@@ -52,7 +53,7 @@ namespace CreatureLib::Battling {
|
||||
ArbUt::CaseInsensitiveConstString _overridenTalentName = ""_cnc;
|
||||
std::unordered_set<Creature*> _seenOpponents = {};
|
||||
|
||||
ArbUt::List<LearnedAttack*> _attacks;
|
||||
ArbUt::UniquePtrList<LearnedAttack> _attacks;
|
||||
bool _allowedExperienceGain;
|
||||
|
||||
Script* _status = nullptr;
|
||||
@@ -66,13 +67,10 @@ namespace CreatureLib::Battling {
|
||||
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level, uint32_t experience,
|
||||
uint32_t uid, Library::Gender gender, uint8_t coloring,
|
||||
const ArbUt::BorrowedPtr<const Library::Item> heldItem, std::string nickname,
|
||||
const Library::TalentIndex& talent, const ArbUt::List<LearnedAttack*>& attacks,
|
||||
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
|
||||
bool allowedExperienceGain = true);
|
||||
|
||||
virtual ~Creature() {
|
||||
for (auto attack : _attacks) {
|
||||
delete attack;
|
||||
}
|
||||
delete _activeTalent;
|
||||
delete _status;
|
||||
};
|
||||
@@ -135,7 +133,7 @@ namespace CreatureLib::Battling {
|
||||
void RemoveVolatileScript(Script* script);
|
||||
bool HasVolatileScript(const ArbUt::CaseInsensitiveConstString& name) const;
|
||||
|
||||
const ArbUt::List<LearnedAttack*>& GetAttacks() noexcept { return _attacks; }
|
||||
const ArbUt::UniquePtrList<LearnedAttack>& GetAttacks() noexcept { return _attacks; }
|
||||
|
||||
ArbUt::BorrowedPtr<const Library::CreatureSpecies> GetDisplaySpecies() const noexcept;
|
||||
ArbUt::BorrowedPtr<const Library::SpeciesVariant> GetDisplayVariant() const noexcept;
|
||||
|
||||
@@ -40,12 +40,12 @@ namespace CreatureLib::Battling {
|
||||
uint8_t _numberHits;
|
||||
HitData* _hits;
|
||||
Creature* _user;
|
||||
LearnedAttack* _attack;
|
||||
ArbUt::BorrowedPtr<LearnedAttack> _attack;
|
||||
Script* _script;
|
||||
|
||||
public:
|
||||
ExecutingAttack(const ArbUt::List<Creature*>& targets, uint8_t numberHits, Creature* user,
|
||||
LearnedAttack* attack, Script* script)
|
||||
const ArbUt::BorrowedPtr<LearnedAttack>& attack, Script* script)
|
||||
: _targets(targets.Count()), _numberHits(numberHits), _hits(new HitData[targets.Count() * numberHits]),
|
||||
_user(user), _attack(attack), _script(script) {
|
||||
AssertNotNull(user)
|
||||
@@ -87,7 +87,7 @@ namespace CreatureLib::Battling {
|
||||
|
||||
Creature* GetUser() noexcept { return _user; }
|
||||
|
||||
LearnedAttack* GetAttack() noexcept { return _attack; }
|
||||
const ArbUt::BorrowedPtr<LearnedAttack>& GetAttack() noexcept { return _attack; }
|
||||
size_t ScriptCount() const override { return _user->ScriptCount() + 1; }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class AttackTurnChoice : public BaseTurnChoice {
|
||||
LearnedAttack* _attack;
|
||||
ArbUt::BorrowedPtr<LearnedAttack> _attack;
|
||||
CreatureIndex _target;
|
||||
Script* _attackScript = nullptr;
|
||||
bool _scriptIsTaken = false;
|
||||
@@ -34,12 +34,13 @@ namespace CreatureLib::Battling {
|
||||
}
|
||||
|
||||
public:
|
||||
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target)
|
||||
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target)
|
||||
: BaseTurnChoice(user), _attack(attack), _target(target) {
|
||||
AssertNotNull(attack)
|
||||
ResolveScript();
|
||||
}
|
||||
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target, Script* script) noexcept
|
||||
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target,
|
||||
Script* script) noexcept
|
||||
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {}
|
||||
|
||||
~AttackTurnChoice() {
|
||||
@@ -48,7 +49,7 @@ namespace CreatureLib::Battling {
|
||||
}
|
||||
}
|
||||
|
||||
inline LearnedAttack* GetAttack() const noexcept { return _attack; }
|
||||
inline const ArbUt::BorrowedPtr<LearnedAttack>& GetAttack() const noexcept { return _attack; }
|
||||
|
||||
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user