Make ExecutingAttack a local variable while being used, to ensure it's always cleaned up.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a9740cb1eb
commit
d51919c74f
|
@ -62,9 +62,9 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
||||||
auto target = choice->GetUser()->GetBattle()->GetCreature(choice->GetTarget());
|
auto target = choice->GetUser()->GetBattle()->GetCreature(choice->GetTarget());
|
||||||
ArbUt::List<Creature*> targets = {target};
|
ArbUt::List<Creature*> targets = {target};
|
||||||
|
|
||||||
auto attack = new ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
auto attack = ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
||||||
bool prevented = false;
|
bool prevented = false;
|
||||||
HOOK(PreventAttack, attack, attack, &prevented);
|
HOOK_LOCAL(PreventAttack, attack, &attack, &prevented);
|
||||||
if (prevented) {
|
if (prevented) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -77,25 +77,22 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
||||||
|
|
||||||
// HOOK: check if attack fails
|
// HOOK: check if attack fails
|
||||||
bool fail = false;
|
bool fail = false;
|
||||||
HOOK(FailAttack, attack, attack, &fail);
|
HOOK_LOCAL(FailAttack, attack, &attack, &fail);
|
||||||
if (fail) {
|
if (fail) {
|
||||||
// TODO: Fail handling.
|
// TODO: Fail handling.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool stopBeforeAttack = false;
|
bool stopBeforeAttack = false;
|
||||||
HOOK(StopBeforeAttack, attack, attack, &stopBeforeAttack);
|
HOOK_LOCAL(StopBeforeAttack, attack, &attack, &stopBeforeAttack);
|
||||||
if (stopBeforeAttack) {
|
if (stopBeforeAttack) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HOOK(OnBeforeAttack, attack, attack);
|
HOOK_LOCAL(OnBeforeAttack, attack, &attack);
|
||||||
|
|
||||||
for (auto& t : attack->GetTargets()) {
|
for (auto& t : attack.GetTargets()) {
|
||||||
HandleAttackForTarget(attack, t);
|
HandleAttackForTarget(&attack, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: We currently delete this, but we probably want to store this in a log, so scripts can look it up.
|
|
||||||
delete attack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target) {
|
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target) {
|
||||||
|
|
|
@ -9,3 +9,15 @@
|
||||||
next->hookName(__VA_ARGS__); \
|
next->hookName(__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define HOOK_LOCAL(hookName, source, ...) \
|
||||||
|
{ \
|
||||||
|
auto aggregator = source.GetScriptIterator(); \
|
||||||
|
aggregator.Reset(); \
|
||||||
|
while (aggregator.HasNext()) { \
|
||||||
|
auto next = aggregator.GetNext(); \
|
||||||
|
if (next == nullptr) \
|
||||||
|
continue; \
|
||||||
|
next->hookName(__VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue