From 8c2b0f2729f29f3906a75e2fba72d2dad4a80ee2 Mon Sep 17 00:00:00 2001 From: Fate Date: Mon, 24 Nov 2008 12:41:04 -0700 Subject: Added spell_index and is_equipped operations, permitted coercions from invocations to strings --- src/map/magic-expr.c | 23 +++++++++++++++++++++++ src/map/magic-interpreter-parser.c | 3 +++ src/map/magic-interpreter-parser.y | 3 +++ src/map/magic-interpreter.h | 1 + src/map/magic-stmt.c | 4 ++++ 5 files changed, 34 insertions(+) (limited to 'src') 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 /** -- cgit v1.2.3-60-g2f50