summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormekolat <mekolat@users.noreply.github.com>2015-09-17 20:21:57 -0400
committermekolat <mekolat@users.noreply.github.com>2015-09-27 19:36:15 +0000
commit3d1770b8cc9e596ac33757ace64462ad3d90a15c (patch)
treeba5723306f5c9e7cb55f9b8ad0da36e0d9e1e717
parent69f5372502cb99fb9fe7f53ecd59ff2377237a5b (diff)
downloadtmwa-3d1770b8cc9e596ac33757ace64462ad3d90a15c.tar.gz
tmwa-3d1770b8cc9e596ac33757ace64462ad3d90a15c.tar.bz2
tmwa-3d1770b8cc9e596ac33757ace64462ad3d90a15c.tar.xz
tmwa-3d1770b8cc9e596ac33757ace64462ad3d90a15c.zip
add array_search
-rw-r--r--src/map/script-fun.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp
index 2407b37..a06eb1b 100644
--- a/src/map/script-fun.cpp
+++ b/src/map/script-fun.cpp
@@ -821,6 +821,54 @@ void builtin_getelementofarray(ScriptState *st)
}
static
+void builtin_array_search(ScriptState *st)
+{
+ ZString needle_str = ZString(conv_str(st, &AARG(0)));
+ int needle_int = conv_num(st, &AARG(0));
+ SIR reg = AARG(1).get_if<ScriptDataVariable>()->reg; // haystack
+ ZString name = variable_names.outtern(reg.base());
+ char prefix = name.front();
+ int i, c;
+
+ if (prefix != '$' && prefix != '@' && prefix != '.')
+ {
+ PRINTF("builtin_array_search: illegal scope!\n"_fmt);
+ return;
+ }
+
+ i = reg.index(); c = -1;
+ for (; i < 256; i++)
+ {
+ struct script_data vd = get_val2(st, reg.iplus(i));
+ MATCH_BEGIN (vd)
+ {
+ MATCH_CASE (const ScriptDataStr&, u)
+ {
+ if (u.str == needle_str)
+ {
+ c = i;
+ goto Out;
+ }
+ continue;
+ }
+ MATCH_CASE (const ScriptDataInt&, u)
+ {
+ if (u.numi == needle_int)
+ {
+ c = i;
+ goto Out;
+ }
+ continue;
+ }
+ }
+ MATCH_END ();
+ abort();
+ }
+ Out:
+ push_int<ScriptDataInt>(st->stack, c);
+}
+
+static
void builtin_wgm(ScriptState *st)
{
ZString message = ZString(conv_str(st, &AARG(0)));
@@ -3354,6 +3402,7 @@ BuiltinFunction builtin_functions[] =
BUILTIN(cleararray, "Nei"_s, '\0'),
BUILTIN(getarraysize, "N"_s, 'i'),
BUILTIN(getelementofarray, "Ni"_s, '.'),
+ BUILTIN(array_search, "eN"_s, 'i'),
BUILTIN(setlook, "ii"_s, '\0'),
BUILTIN(countitem, "I"_s, 'i'),
BUILTIN(checkweight, "Ii"_s, 'i'),