summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFate <fate-tmw@googlemail.com>2008-11-24 14:10:02 -0700
committerFate <fate-tmw@googlemail.com>2008-11-24 14:10:02 -0700
commitf9d990b2a553706334c3b85e211c0b10f6c7028f (patch)
treeb766c43077b4f6eb2b065b1a2f228359493d94cc /src
parentb218ad7f381cb7e460bd7f464f4c8b6fab18a27e (diff)
downloadtmwa-f9d990b2a553706334c3b85e211c0b10f6c7028f.tar.gz
tmwa-f9d990b2a553706334c3b85e211c0b10f6c7028f.tar.bz2
tmwa-f9d990b2a553706334c3b85e211c0b10f6c7028f.tar.xz
tmwa-f9d990b2a553706334c3b85e211c0b10f6c7028f.zip
Better handling of an invocation vanishing during a magic statement (should now be safe)
Diffstat (limited to 'src')
-rw-r--r--src/map/magic-stmt.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/map/magic-stmt.c b/src/map/magic-stmt.c
index cff90d7..c9984af 100644
--- a/src/map/magic-stmt.c
+++ b/src/map/magic-stmt.c
@@ -1195,6 +1195,9 @@ print_cfg(int i, effect_t *e)
static int
spell_run(invocation_t *invocation, int allow_delete)
{
+ const int invocation_id = invocation->bl.id;
+#define REFRESH_INVOCATION invocation = (invocation_t *) map_id2bl(invocation_id); if (!invocation) return 0;
+
#ifdef DEBUG
fprintf(stderr, "Resuming execution: invocation of `%s'\n", invocation->spell->name);
print_cfg(1, invocation->current_effect);
@@ -1285,6 +1288,7 @@ spell_run(invocation_t *invocation, int allow_delete)
invocation->script_pos = 0;
clif_clearchar_id(invocation->bl.id, 1, caster->fd);
}
+ REFRESH_INVOCATION; // Script may have killed the caster
break;
}
@@ -1306,6 +1310,8 @@ spell_run(invocation_t *invocation, int allow_delete)
for (i = 0; i < e->e.e_op.args_nr; i++)
magic_clear_var(&args[i]);
+
+ REFRESH_INVOCATION; // Effect may have killed the caster
break;
}
@@ -1327,6 +1333,7 @@ spell_run(invocation_t *invocation, int allow_delete)
if (allow_delete)
try_to_finish_invocation(invocation);
return 0;
+#undef REFRESH_INVOCATION
}
@@ -1371,7 +1378,11 @@ spell_attack(int caster_id, int target_id)
invocation->flags &= ~INVOCATION_FLAG_ABORTED;
spell_execute_d(invocation, 0 /* don't delete the invocation if done */);
- if (!(invocation->flags & INVOCATION_FLAG_ABORTED)) // If we didn't abort:
+ // If the caster died, we need to refresh here:
+ invocation = (invocation_t *)map_id2bl(caster->attack_spell_override);
+
+ if (invocation
+ && !(invocation->flags & INVOCATION_FLAG_ABORTED)) // If we didn't abort:
caster->attack_spell_charges--;
}