summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFate <fate-tmw@googlemail.com>2008-11-29 12:04:43 -0700
committerFate <fate-tmw@googlemail.com>2008-11-29 12:04:43 -0700
commit481c74df8cfd2b63376b29158cc8f3c5d11addef (patch)
tree916b8687484c6633a6e75e3953b4bf0ad23c9c79
parentee5ea021c66a6d8b011dd754ce620fd6b1cc60e1 (diff)
downloadtmwa-481c74df8cfd2b63376b29158cc8f3c5d11addef.tar.gz
tmwa-481c74df8cfd2b63376b29158cc8f3c5d11addef.tar.bz2
tmwa-481c74df8cfd2b63376b29158cc8f3c5d11addef.tar.xz
tmwa-481c74df8cfd2b63376b29158cc8f3c5d11addef.zip
Added SLang operations `is_exterior', `strstr', `substr', `contains_string', `strlen'
-rw-r--r--doc/spell-language19
-rw-r--r--save/account.txt2
-rw-r--r--src/map/magic-expr.c60
3 files changed, 80 insertions, 1 deletions
diff --git a/doc/spell-language b/doc/spell-language
index 270f2f0..d5a798a 100644
--- a/doc/spell-language
+++ b/doc/spell-language
@@ -510,6 +510,25 @@ The following functions are available:
+ spell_index : spell -> int
Determines a unique index assigned to each spell
+ + is_exterior : location -> bool
+ Determines whether the location is under an open sky
+
+ + contains_string : string * string -> bool
+ contains_string(a, b) determines whether the string `a' contains
+ the string `b' as a substring.
+
+ + strstr : string * string -> bool
+ strstr(a, b) returns the offset of the first instance of the
+ string `b' in the string `a', or fails if there is none. The
+ offset is reported with a base of zero, i.e., strstr("xyz", "x") = 0.
+
+ + strlen : string -> int
+ Compute the length of a string, in characters.
+
+ + substr : string * int * int -> string
+ substr(s, offset, len) extracts a substring of the length `len' at
+ offset `offset'. The substring is automatically clipped, i.e., the
+ function will never fail.
Operations:
-----------
diff --git a/save/account.txt b/save/account.txt
index b7a4603..7d6fe0e 100644
--- a/save/account.txt
+++ b/save/account.txt
@@ -10,6 +10,6 @@
// valitidy time : 0: unlimited account, <other value>: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)
// memo field : max 254 char
// ban time : 0: no ban, <other value>: banned until the date: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)
-0 s1 p1 2006-03-25 16:09:35.113 S 38706 0 a@a.com - 0 - - 0
+0 s1 p1 2008-11-24 15:54:26.750 S 38707 0 a@a.com - 0 127.0.0.1 - 0
1 s2 p2 2006-03-04 16:54:40.974 S 3 0 a@a.com - 0 - - 0
2000000 %newid%
diff --git a/src/map/magic-expr.c b/src/map/magic-expr.c
index 0034441..04e5e60 100644
--- a/src/map/magic-expr.c
+++ b/src/map/magic-expr.c
@@ -954,6 +954,61 @@ fun_index(env_t *env, int args_nr, val_t *result, val_t *args)
return 0;
}
+static int
+fun_is_exterior(env_t *env, int args_nr, val_t *result, val_t *args)
+{
+ RESULTINT = map[ARGLOCATION(0).m].name[4] == '1';
+ return 0;
+}
+
+static int
+fun_contains_string(env_t *env, int args_nr, val_t *result, val_t *args)
+{
+ RESULTINT = NULL != strstr(ARGSTR(0), ARGSTR(1));
+ return 0;
+}
+
+static int
+fun_strstr(env_t *env, int args_nr, val_t *result, val_t *args)
+{
+ char *offset = strstr(ARGSTR(0), ARGSTR(1));
+ RESULTINT = offset - ARGSTR(0);
+ return offset == NULL;
+}
+
+static int
+fun_strlen(env_t *env, int args_nr, val_t *result, val_t *args)
+{
+ RESULTINT = strlen(ARGSTR(0));
+ return 0;
+}
+
+static int
+fun_substr(env_t *env, int args_nr, val_t *result, val_t *args)
+{
+ const char *src = ARGSTR(0);
+ const int slen = strlen(src);
+ int offset = ARGINT(1);
+ int len = ARGINT(2);
+
+ if (len < 0)
+ len = 0;
+ if (offset < 0)
+ offset = 0;
+
+ if (offset > slen)
+ offset = slen;
+
+ if (offset + len > slen)
+ len = slen - offset;
+
+ RESULTSTR = (char *) calloc(1, 1 + len);
+ memcpy(RESULTSTR, src + offset, len);
+
+ 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[] = {
@@ -1015,6 +1070,11 @@ static fun_t functions[] = {
{ "has_shroud", "e", 'i', fun_has_shroud },
{ "is_equipped", "e.", 'i', fun_is_equipped },
{ "spell_index", "S", 'i', fun_index },
+ { "is_exterior", "l", 'i', fun_is_exterior },
+ { "contains_string", "ss", 'i', fun_contains_string },
+ { "strstr", "ss", 'i', fun_strstr },
+ { "strlen", "s", 'i', fun_strlen },
+ { "substr", "sii", 's', fun_substr },
{ NULL, NULL, '.', NULL }
};