summaryrefslogtreecommitdiff
path: root/src/map/script-fun.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/script-fun.cpp')
-rw-r--r--src/map/script-fun.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp
index a291a11..f9334bc 100644
--- a/src/map/script-fun.cpp
+++ b/src/map/script-fun.cpp
@@ -2574,6 +2574,69 @@ void builtin_npcwarp(ScriptState *st)
}
/*==========================================
+ * npcareawarp [remoitnane] [wushin]
+ * Move NPC to a new area on the same map.
+ *------------------------------------------
+ */
+static
+void builtin_npcareawarp(ScriptState *st)
+{
+ int x0, y0, x1, y1, x, y, max, cb, lx = -1, ly = -1, j = 0;
+ dumb_ptr<npc_data> nd = nullptr;
+
+ NpcName npc = stringish<NpcName>(ZString(conv_str(st, &AARG(5))));
+ nd = npc_name2id(npc);
+
+ x0 = conv_num(st, &AARG(0));
+ y0 = conv_num(st, &AARG(1));
+ x1 = conv_num(st, &AARG(2));
+ y1 = conv_num(st, &AARG(3));
+ cb = conv_num(st, &AARG(4));
+
+ if (!nd)
+ {
+ PRINTF("builtin_npcareawarp: no such npc: %s\n"_fmt, npc);
+ return;
+ }
+
+ max = (y1 - y0 + 1) * (x1 - x0 + 1) * 3;
+ if (max > 1000)
+ max = 1000;
+
+ P<map_local> m = nd->bl_m;
+ if (cb) {
+ do
+ {
+ x = random_::in(x0, x1);
+ y = random_::in(y0, y1);
+ }
+ while (bool(map_getcell(m, x, y) & MapCell::UNWALKABLE)
+ && (++j) < max);
+ if (j >= max)
+ {
+ if (lx >= 0)
+ { // Since reference went wrong, the place which boiled before is used.
+ x = lx;
+ y = ly;
+ }
+ else
+ return; // Since reference of the place which boils first went wrong, it stops.
+ }
+ }
+ else
+ x = random_::in(x0, x1);
+ y = random_::in(y0, y1);
+
+ npc_enable(npc, 0);
+ map_delblock(nd); /* [Freeyorp] */
+ nd->bl_x = x;
+ nd->bl_y = y;
+ map_addblock(nd);
+ npc_enable(npc, 1);
+
+}
+
+/*==========================================
* message [MouseJstr]
*------------------------------------------
*/
@@ -2745,6 +2808,24 @@ void builtin_isin(ScriptState *st)
&& (str == sd->bl_m->name_));
}
+/*==========================================
+ * Check whether the coords are collision
+ *------------------------------------------
+ */
+static
+void builtin_iscollision(ScriptState *st)
+{
+ int x, y;
+ MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARG(0))));
+ P<map_local> m = TRY_UNWRAP(map_mapname2mapid(mapname), return);
+
+ x = conv_num(st, &AARG(1));
+ y = conv_num(st, &AARG(2));
+
+ push_int<ScriptDataInt>(st->stack,
+ bool(map_getcell(m, x, y) & MapCell::UNWALKABLE));
+}
+
// Trigger the shop on a (hopefully) nearby shop NPC
static
void builtin_shop(ScriptState *st)
@@ -2954,12 +3035,14 @@ BuiltinFunction builtin_functions[] =
BUILTIN(unequipbyid, "i"_s, '\0'),
BUILTIN(gmcommand, "s"_s, '\0'),
BUILTIN(npcwarp, "xys"_s, '\0'),
+ BUILTIN(npcareawarp, "xyxyis"_s, '\0'),
BUILTIN(message, "Ps"_s, '\0'),
BUILTIN(npctalk, "s"_s, '\0'),
BUILTIN(getlook, "i"_s, 'i'),
BUILTIN(getsavepoint, "i"_s, '.'),
BUILTIN(areatimer, "MxyxytE"_s, '\0'),
BUILTIN(isin, "Mxyxy"_s, 'i'),
+ BUILTIN(iscollision, "Mxy"_s, 'i'),
BUILTIN(shop, "s"_s, '\0'),
BUILTIN(isdead, ""_s, 'i'),
BUILTIN(fakenpcname, "ssi"_s, '\0'),