summaryrefslogtreecommitdiff
path: root/src/map/magic-stmt.c
diff options
context:
space:
mode:
authorFate <fate-tmw@googlemail.com>2008-11-24 13:27:26 -0700
committerFate <fate-tmw@googlemail.com>2008-11-24 13:27:26 -0700
commitb218ad7f381cb7e460bd7f464f4c8b6fab18a27e (patch)
tree8b69f77c7e983df0589739edc32a7fbea3ffe11c /src/map/magic-stmt.c
parent0cf54b3627d8880bf9670b518740d96d8b80a8f4 (diff)
downloadtmwa-b218ad7f381cb7e460bd7f464f4c8b6fab18a27e.tar.gz
tmwa-b218ad7f381cb7e460bd7f464f4c8b6fab18a27e.tar.bz2
tmwa-b218ad7f381cb7e460bd7f464f4c8b6fab18a27e.tar.xz
tmwa-b218ad7f381cb7e460bd7f464f4c8b6fab18a27e.zip
Fixed looping over spells
Diffstat (limited to 'src/map/magic-stmt.c')
-rw-r--r--src/map/magic-stmt.c48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/map/magic-stmt.c b/src/map/magic-stmt.c
index 1812773..cff90d7 100644
--- a/src/map/magic-stmt.c
+++ b/src/map/magic-stmt.c
@@ -884,7 +884,7 @@ return_to_stack(invocation_t *invocation)
} while (!entity_id || !map_id2bl(entity_id));
magic_clear_var(var);
- var->ty = TY_ENTITY;
+ var->ty = ar->c.c_foreach.ty;
var->v.v_int = entity_id;
return ar->c.c_foreach.body;
@@ -934,6 +934,17 @@ find_entities_in_area_c(entity_t *target, va_list va)
int **entities_p = va_arg(va, int **);
int filter = va_arg(va, int);
+/* The following macro adds an entity to the result list: */
+#define ADD_ENTITY(e) \
+ if (*entities_nr_p == *entities_allocd_p) { \
+ /* Need more space */ \
+ (*entities_allocd_p) += 32; \
+ *entities_p = realloc(*entities_p, sizeof(int) * (*entities_allocd_p)); \
+ } \
+ (*entities_p)[(*entities_nr_p)++] = e;
+
+
+
switch (target->type) {
case BL_PC:
@@ -942,8 +953,16 @@ find_entities_in_area_c(entity_t *target, va_list va)
|| (filter == FOREACH_FILTER_TARGET
&& map[target->m].flag.pvp))
break;
- else
- return 0;
+ else if (filter == FOREACH_FILTER_SPELL) { /* Check all spells bound to the caster */
+ invocation_t *invoc = ((character_t *) target) -> active_spells;
+ /* Add all spells locked onto thie PC */
+
+ while (invoc) {
+ ADD_ENTITY(invoc->bl.id);
+ invoc = invoc->next_invocation;
+ }
+ }
+ return 0;
case BL_MOB:
if (filter == FOREACH_FILTER_MOB
@@ -953,18 +972,24 @@ find_entities_in_area_c(entity_t *target, va_list va)
else
return 0;
+ case BL_SPELL:
+ if (filter == FOREACH_FILTER_SPELL) {
+ invocation_t *invocation = (invocation_t *) target;
+
+ /* Check whether the spell is `bound'-- if so, we'll consider it iff we see the caster (case BL_PC). */
+ if (invocation->flags & INVOCATION_FLAG_BOUND)
+ return 0;
+ else
+ break; /* Add the spell */
+ } else
+ return 0;
+
default:
return 0;
}
- if (*entities_nr_p == *entities_allocd_p) {
- /* Need more space */
- (*entities_allocd_p) += 32;
- *entities_p = realloc(*entities_p, sizeof(int) * (*entities_allocd_p));
- }
-
- (*entities_p)[(*entities_nr_p)++] = target->id;
-
+ ADD_ENTITY(target->id);
+#undef ADD_ENTITY
return 0;
}
@@ -1037,6 +1062,7 @@ run_foreach(invocation_t *invocation, effect_t *foreach, effect_t *return_locati
ar->c.c_foreach.index = 0;
ar->c.c_foreach.entities_nr = entities_nr;
ar->c.c_foreach.entities = entities;
+ ar->c.c_foreach.ty = (filter == FOREACH_FILTER_SPELL) ? TY_INVOCATION : TY_ENTITY;
magic_clear_var(&area);