Make all individual scripts smart pointers.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -41,24 +41,25 @@ namespace CreatureLib::Battling {
|
||||
HitData* _hits;
|
||||
Creature* _user;
|
||||
ArbUt::BorrowedPtr<LearnedAttack> _attack;
|
||||
Script* _script;
|
||||
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, Script* script)
|
||||
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), _script(script) {
|
||||
_user(user), _attack(attack) {
|
||||
AssertNotNull(user)
|
||||
AssertNotNull(attack)
|
||||
for (auto target : targets) {
|
||||
_targets.Append(target);
|
||||
}
|
||||
// Take ownership of the script of the attack choice, and give attack choice our initial nullptr.
|
||||
_script.swap(const_cast<std::unique_ptr<Script>&>(script));
|
||||
}
|
||||
ExecutingAttack(const ExecutingAttack&) = delete;
|
||||
ExecutingAttack& operator=(const ExecutingAttack&) = delete;
|
||||
|
||||
virtual ~ExecutingAttack() noexcept {
|
||||
delete _script;
|
||||
delete[] _hits;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user