From 3f214c06c13dfc4c4eb42a3f24553d7a1d30b26d Mon Sep 17 00:00:00 2001
From: HoraK-FDF <horak-fdf@web.de>
Date: Thu, 18 Apr 2024 00:46:16 +0200
Subject: getmapmaxx getmapmaxy

---
 src/map/script-fun.cpp | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp
index 8dc1989..2be0333 100644
--- a/src/map/script-fun.cpp
+++ b/src/map/script-fun.cpp
@@ -5471,6 +5471,30 @@ void builtin_getmap(ScriptState *st)
     push_str<ScriptDataStr>(st->stack, sd->bl_m->name_);
 }
 
+/*==========================================
+ * Get the maximum x coordinate of a map
+ *------------------------------------------
+ */
+static
+void builtin_getmapmaxx(ScriptState *st)
+{
+    MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARG(0))));
+    P<map_local> m = TRY_UNWRAP(map_mapname2mapid(mapname), return);
+    push_int<ScriptDataInt>(st->stack, m->xs-1);
+}
+
+/*==========================================
+ * Get the maximum y coordinate of a map
+ *------------------------------------------
+ */
+static
+void builtin_getmapmaxy(ScriptState *st)
+{
+    MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARG(0))));
+    P<map_local> m = TRY_UNWRAP(map_mapname2mapid(mapname), return);
+    push_int<ScriptDataInt>(st->stack, m->ys-1);
+}
+
 /*==========================================
  * Get the NPC's info
  *------------------------------------------
@@ -5732,6 +5756,8 @@ BuiltinFunction builtin_functions[] =
     BUILTIN(getnpcy, "?"_s, 'i'),
     BUILTIN(strnpcinfo, "i?"_s, 's'),
     BUILTIN(getmap, "?"_s, 's'),
+    BUILTIN(getmapmaxx, "M"_s, 'i'),
+    BUILTIN(getmapmaxy, "M"_s, 'i'),
     BUILTIN(mapexit, ""_s, '\0'),
     BUILTIN(freeloop, "i"_s, '\0'),
     BUILTIN(if_then_else, "iii"_s, 'v'),
-- 
cgit v1.2.3-70-g09d2