summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorWushin <pasekei@gmail.com>2015-04-13 21:11:47 -0500
committerWushin <pasekei@gmail.com>2015-04-13 21:11:47 -0500
commit1ee72d7b3c9acd5221b43c7b86de869394a8ca89 (patch)
tree1c7deb05f4dcfaf969adeb6d8791b1136dacf670 /src/map
parent5b1612cf0187ebd04a22226027c211ea7030be04 (diff)
parentf59a33c4796c0e5106776d1c595d19b8feeac9cd (diff)
downloadtmwa-1ee72d7b3c9acd5221b43c7b86de869394a8ca89.tar.gz
tmwa-1ee72d7b3c9acd5221b43c7b86de869394a8ca89.tar.bz2
tmwa-1ee72d7b3c9acd5221b43c7b86de869394a8ca89.tar.xz
tmwa-1ee72d7b3c9acd5221b43c7b86de869394a8ca89.zip
Merge pull request #39 from mekolat/getnpclocation
add npc-related builtins
Diffstat (limited to 'src/map')
-rw-r--r--src/map/script-fun.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp
index 7e01aaa..fd618f8 100644
--- a/src/map/script-fun.cpp
+++ b/src/map/script-fun.cpp
@@ -3000,6 +3000,95 @@ void builtin_getmap(ScriptState *st)
push_str<ScriptDataStr>(st->stack, sd->bl_m->name_);
}
+/*
+ * Get the NPC's info
+ */
+static
+void builtin_strnpcinfo(ScriptState *st)
+{
+ int num = conv_num(st, &AARG(0));
+ RString name;
+ dumb_ptr<npc_data> nd;
+
+ if(HARG(1)){
+ NpcName npc = stringish<NpcName>(ZString(conv_str(st, &AARG(1))));
+ nd = npc_name2id(npc);
+ if (!nd)
+ {
+ PRINTF("builtin_strnpcinfo: no such npc: %s\n"_fmt, npc);
+ return;
+ }
+ } else {
+ nd = map_id_is_npc(st->oid);
+ }
+
+ switch(num)
+ {
+ case 0:
+ name = nd->name;
+ break;
+ case 1:
+ name = nd->name.xislice_h(std::find(nd->name.begin(), nd->name.end(), '#'));
+ break;
+ case 2:
+ name = nd->name.xislice_t(std::find(nd->name.begin(), nd->name.end(), '#'));
+ break;
+ case 3:
+ name = nd->bl_m->name_;
+ break;
+ }
+
+ push_str<ScriptDataStr>(st->stack, name);
+}
+
+/*============================
+ * Gets the NPC's x pos
+ *----------------------------
+ */
+static
+void builtin_getnpcx(ScriptState *st)
+{
+ dumb_ptr<npc_data> nd;
+
+ if(HARG(0)){
+ NpcName name = stringish<NpcName>(ZString(conv_str(st, &AARG(0))));
+ nd = npc_name2id(name);
+ if (!nd)
+ {
+ PRINTF("builtin_getnpcx: no such npc: %s\n"_fmt, name);
+ return;
+ }
+ } else {
+ nd = map_id_is_npc(st->oid);
+ }
+
+ push_int<ScriptDataInt>(st->stack, nd->bl_x);
+}
+
+/*============================
+ * Gets the NPC's y pos
+ *----------------------------
+ */
+static
+void builtin_getnpcy(ScriptState *st)
+{
+ dumb_ptr<npc_data> nd;
+
+ if(HARG(0)){
+ NpcName name = stringish<NpcName>(ZString(conv_str(st, &AARG(0))));
+ nd = npc_name2id(name);
+ if (!nd)
+ {
+ PRINTF("builtin_getnpcy: no such npc: %s\n"_fmt, name);
+ return;
+ }
+ } else {
+ nd = map_id_is_npc(st->oid);
+ }
+
+ push_int<ScriptDataInt>(st->stack, nd->bl_y);
+}
+
static
void builtin_mapexit(ScriptState *)
{
@@ -3128,6 +3217,9 @@ BuiltinFunction builtin_functions[] =
BUILTIN(fakenpcname, "ssi"_s, '\0'),
BUILTIN(getx, ""_s, 'i'),
BUILTIN(gety, ""_s, 'i'),
+ BUILTIN(getnpcx, "?"_s, 'i'),
+ BUILTIN(getnpcy, "?"_s, 'i'),
+ BUILTIN(strnpcinfo, "i?"_s, 's'),
BUILTIN(getmap, ""_s, 's'),
BUILTIN(mapexit, ""_s, '\0'),
BUILTIN(freeloop, "i"_s, '\0'),