Make ExecutingAttack use smart pointers.
This commit is contained in:
parent
a5a613ba5c
commit
7262ae9e8b
|
@ -21,7 +21,7 @@ export bool CreatureLib_ExecutingAttack_IsCreatureTarget(ExecutingAttack* p, Cre
|
|||
return p->IsCreatureTarget(target);
|
||||
}
|
||||
|
||||
export Creature* CreatureLib_ExecutingAttack_GetUser(ExecutingAttack* p) { return p->GetUser(); }
|
||||
export Creature* CreatureLib_ExecutingAttack_GetUser(ExecutingAttack* p) { return p->GetUser().GetRaw(); }
|
||||
export LearnedAttack* CreatureLib_ExecutingAttack_GetAttack(ExecutingAttack* p) { return p->GetAttack().operator->(); }
|
||||
|
||||
#define HITDATA_GET_FUNC(name, returnType) \
|
||||
|
|
|
@ -30,7 +30,7 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
|
|||
const ExecutingAttack::HitData& hitData) const {
|
||||
AssertNotNull(attack)
|
||||
AssertNotNull(target)
|
||||
auto user = attack->GetUser();
|
||||
auto user = attack->GetUser().GetRaw();
|
||||
AssertNotNull(user)
|
||||
HOOK(ChangeDamageStatsUser, attack, attack, target, hitIndex, &user);
|
||||
Library::Statistic offensiveStat;
|
||||
|
|
|
@ -45,7 +45,7 @@ const ConstString& Battling::Creature::GetActiveTalent() const {
|
|||
return _variant->GetTalent(_talentIndex);
|
||||
}
|
||||
|
||||
void Battling::Creature::SetBattleData(ArbUt::BorrowedPtr<Battle> battle, BattleSide* side) {
|
||||
void Battling::Creature::SetBattleData(ArbUt::BorrowedPtr<Battle> battle, ArbUt::BorrowedPtr<BattleSide> side) {
|
||||
_battle = battle;
|
||||
_side = side;
|
||||
this->ResetActiveScripts();
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace CreatureLib::Battling {
|
|||
Library::Gender _gender;
|
||||
uint8_t _coloring;
|
||||
ArbUt::BorrowedPtr<const Library::Item> _heldItem;
|
||||
uint32_t _currentHealth;
|
||||
uint32_t _currentHealth = -1;
|
||||
|
||||
Library::ClampedStatisticSet<int8_t, -6, 6> _statBoost;
|
||||
Library::StatisticSet<uint32_t> _flatStats;
|
||||
|
@ -99,7 +99,7 @@ namespace CreatureLib::Battling {
|
|||
|
||||
inline uint32_t GetCurrentHealth() const noexcept { return _currentHealth; }
|
||||
|
||||
void SetBattleData(ArbUt::BorrowedPtr<Battle> battle, BattleSide* side);
|
||||
void SetBattleData(ArbUt::BorrowedPtr<Battle> battle, ArbUt::BorrowedPtr<BattleSide> side);
|
||||
const ArbUt::BorrowedPtr<Battle>& GetBattle() const;
|
||||
const ArbUt::BorrowedPtr<BattleSide>& GetBattleSide() const;
|
||||
void SetOnBattleField(bool value) { _onBattleField = value; }
|
||||
|
@ -139,7 +139,9 @@ namespace CreatureLib::Battling {
|
|||
void SetDisplaySpecies(const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species) noexcept {
|
||||
_displaySpecies = species;
|
||||
}
|
||||
void SetDisplayVariant(const Library::SpeciesVariant* variant) noexcept { _displayVariant = variant; };
|
||||
void SetDisplayVariant(ArbUt::BorrowedPtr<const Library::SpeciesVariant> variant) noexcept {
|
||||
_displayVariant = variant;
|
||||
};
|
||||
|
||||
inline bool AllowedExperienceGain() const noexcept { return _allowedExperienceGain; }
|
||||
inline void SetAllowedExperienceGain(bool allowed) noexcept { _allowedExperienceGain = allowed; }
|
||||
|
|
|
@ -38,16 +38,16 @@ namespace CreatureLib::Battling {
|
|||
private:
|
||||
ArbUt::List<ArbUt::BorrowedPtr<Creature>> _targets;
|
||||
uint8_t _numberHits;
|
||||
HitData* _hits;
|
||||
Creature* _user;
|
||||
std::unique_ptr<HitData[]> _hits;
|
||||
ArbUt::BorrowedPtr<Creature> _user;
|
||||
ArbUt::BorrowedPtr<LearnedAttack> _attack;
|
||||
std::unique_ptr<Script> _script = nullptr;
|
||||
|
||||
public:
|
||||
ExecutingAttack(const ArbUt::List<ArbUt::BorrowedPtr<Creature>>& targets, uint8_t numberHits, Creature* user,
|
||||
const ArbUt::BorrowedPtr<LearnedAttack>& attack, const std::unique_ptr<Script>& script)
|
||||
: _targets(targets.Count()), _numberHits(numberHits), _hits(new HitData[targets.Count() * numberHits]),
|
||||
_user(user), _attack(attack) {
|
||||
: _targets(targets.Count()), _numberHits(numberHits),
|
||||
_hits(std::make_unique<HitData[]>(targets.Count() * numberHits)), _user(user), _attack(attack) {
|
||||
AssertNotNull(user)
|
||||
AssertNotNull(attack)
|
||||
for (auto target : targets) {
|
||||
|
@ -59,7 +59,7 @@ namespace CreatureLib::Battling {
|
|||
ExecutingAttack(const ExecutingAttack&) = delete;
|
||||
ExecutingAttack& operator=(const ExecutingAttack&) = delete;
|
||||
|
||||
virtual ~ExecutingAttack() noexcept { delete[] _hits; };
|
||||
virtual ~ExecutingAttack() noexcept = default;
|
||||
|
||||
HitData& GetHitData(Creature* creature, uint8_t hit) {
|
||||
for (size_t i = 0; i < _targets.Count(); i++) {
|
||||
|
@ -73,8 +73,7 @@ namespace CreatureLib::Battling {
|
|||
HitData* GetTargetIteratorBegin(Creature* creature) {
|
||||
for (size_t i = 0; i < _targets.Count(); i++) {
|
||||
if (_targets[i] == creature) {
|
||||
auto v = _hits + (i * _numberHits * sizeof(HitData));
|
||||
return v;
|
||||
return &_hits[i * _numberHits * sizeof(HitData)];
|
||||
}
|
||||
}
|
||||
throw CreatureException("Invalid target requested.");
|
||||
|
@ -84,7 +83,7 @@ namespace CreatureLib::Battling {
|
|||
const ArbUt::List<ArbUt::BorrowedPtr<Creature>>& GetTargets() noexcept { return _targets; }
|
||||
uint8_t GetNumberOfHits() const noexcept { return _numberHits; }
|
||||
|
||||
Creature* GetUser() noexcept { return _user; }
|
||||
ArbUt::BorrowedPtr<Creature> GetUser() noexcept { return _user; }
|
||||
|
||||
const ArbUt::BorrowedPtr<LearnedAttack>& GetAttack() noexcept { return _attack; }
|
||||
size_t ScriptCount() const override { return _user->ScriptCount() + 1; }
|
||||
|
|
Loading…
Reference in New Issue