summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFate <fate-tmw@googlemail.com>2008-11-24 12:41:04 -0700
committerFate <fate-tmw@googlemail.com>2008-11-24 12:41:04 -0700
commit8c2b0f2729f29f3906a75e2fba72d2dad4a80ee2 (patch)
tree49ec1cec95b6e6a4cfdaeda49b42afb140ac825d
parent5bb68970dece3052f5bf82d53bec8c6eeac60e15 (diff)
downloadtmwa-8c2b0f2729f29f3906a75e2fba72d2dad4a80ee2.tar.gz
tmwa-8c2b0f2729f29f3906a75e2fba72d2dad4a80ee2.tar.bz2
tmwa-8c2b0f2729f29f3906a75e2fba72d2dad4a80ee2.tar.xz
tmwa-8c2b0f2729f29f3906a75e2fba72d2dad4a80ee2.zip
Added spell_index and is_equipped operations, permitted coercions from invocations to strings
-rw-r--r--doc/spell-language9
-rw-r--r--src/map/magic-expr.c23
-rw-r--r--src/map/magic-interpreter-parser.c3
-rw-r--r--src/map/magic-interpreter-parser.y3
-rw-r--r--src/map/magic-interpreter.h1
-rw-r--r--src/map/magic-stmt.c4
6 files changed, 43 insertions, 0 deletions
diff --git a/doc/spell-language b/doc/spell-language
index de34152..270f2f0 100644
--- a/doc/spell-language
+++ b/doc/spell-language
@@ -500,6 +500,15 @@ The following functions are available:
Determines what element level the entity has
+ has_shroud : entity -> int
+ Determines whether the player is presently shrouded (i.e., whether
+ the player's name is being obscured.)
+
+ + is_equipped : entity * int -> int
+ : entity * string -> int
+ Determines whether the player has equipped the specified item
+
+ + spell_index : spell -> int
+ Determines a unique index assigned to each spell
Operations:
diff --git a/src/map/magic-expr.c b/src/map/magic-expr.c
index efdbb72..7cb1d3a 100644
--- a/src/map/magic-expr.c
+++ b/src/map/magic-expr.c
@@ -214,6 +214,20 @@ make_location(val_t *v)
}
}
+static void
+make_spell(val_t *v)
+{
+ if (v->ty == TY_INVOCATION) {
+ invocation_t *invoc = v->v.v_invocation; //(invocation_t *) map_id2bl(v->v.v_int);
+ if (!invoc)
+ v->ty = TY_FAIL;
+ else {
+ v->ty = TY_SPELL;
+ v->v.v_spell = invoc->spell;
+ }
+ }
+}
+
static int
fun_add(env_t *env, int args_nr, val_t *result, val_t *args)
{
@@ -923,6 +937,13 @@ fun_element_level(env_t *env, int args_nr, val_t *result, val_t *args)
return 0;
}
+static int
+fun_index(env_t *env, int args_nr, val_t *result, val_t *args)
+{
+ RESULTINT = ARGSPELL(0)->index;
+ return 0;
+}
+
#define BATTLE_RECORD2(sname, name) { sname, "e", 'i', fun_get_##name }
#define BATTLE_RECORD(name) BATTLE_RECORD2(#name, name)
static fun_t functions[] = {
@@ -983,6 +1004,7 @@ static fun_t functions[] = {
{ "element_level", "e", 'i', fun_element_level },
{ "has_shroud", "e", 'i', fun_has_shroud },
{ "equipped", "e.", 'i', fun_equipped },
+ { "spell_index", "S", 'i', fun_index },
{ NULL, NULL, '.', NULL }
};
@@ -1206,6 +1228,7 @@ magic_signature_check(char *opname, char *funname, char *signature, int args_nr,
case TY_STRING: stringify(arg, 1); break; /* 100% success rate */
case TY_AREA: make_area(arg); break; /* Only works for locations */
case TY_LOCATION: make_location(arg); break; /* Only works for some areas */
+ case TY_SPELL: make_spell(arg); break; /* Only works for still-active invocatoins */
default: break; /* We'll fail right below */
}
diff --git a/src/map/magic-interpreter-parser.c b/src/map/magic-interpreter-parser.c
index cab0426..66fb120 100644
--- a/src/map/magic-interpreter-parser.c
+++ b/src/map/magic-interpreter-parser.c
@@ -2994,7 +2994,10 @@ fun_expr(char *name, int args_nr, expr_t **args, int line, int column)
static spell_t *
new_spell(spellguard_t *guard)
{
+ static int spell_counter = 0;
+
spell_t *retval = calloc(1, sizeof(spell_t));
+ retval->index = ++spell_counter;
retval->spellguard = guard;
return retval;
}
diff --git a/src/map/magic-interpreter-parser.y b/src/map/magic-interpreter-parser.y
index a8f7168..deb686d 100644
--- a/src/map/magic-interpreter-parser.y
+++ b/src/map/magic-interpreter-parser.y
@@ -821,7 +821,10 @@ fun_expr(char *name, int args_nr, expr_t **args, int line, int column)
static spell_t *
new_spell(spellguard_t *guard)
{
+ static int spell_counter = 0;
+
spell_t *retval = calloc(1, sizeof(spell_t));
+ retval->index = ++spell_counter;
retval->spellguard = guard;
return retval;
}
diff --git a/src/map/magic-interpreter.h b/src/map/magic-interpreter.h
index 1998eda..1f4f896 100644
--- a/src/map/magic-interpreter.h
+++ b/src/map/magic-interpreter.h
@@ -246,6 +246,7 @@ typedef struct letdef {
typedef struct spell {
char *name;
char *invocation;
+ int index; // Relative location in the definitions file
int flags;
int arg;
int spellarg_ty;
diff --git a/src/map/magic-stmt.c b/src/map/magic-stmt.c
index 3d28b3f..1812773 100644
--- a/src/map/magic-stmt.c
+++ b/src/map/magic-stmt.c
@@ -10,6 +10,7 @@ clif_spawn_fake_npc_for_player(struct map_session_data *sd, int fake_npc_id);
//#define DEBUG
+#ifdef DEBUG
static void
print_val(val_t *v)
{
@@ -37,6 +38,7 @@ dump_env(env_t *env)
fprintf(stderr, ")\n");
}
}
+#endif
static void
clear_activation_record(cont_activation_record_t *ar)
@@ -1098,6 +1100,7 @@ run_call(invocation_t *invocation, effect_t *return_location)
return current->e.e_call.body;
}
+#ifdef DEBUG
static void
print_cfg(int i, effect_t *e)
{
@@ -1151,6 +1154,7 @@ print_cfg(int i, effect_t *e)
}
print_cfg(i, e->next);
}
+#endif
/**