summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHoraK-FDF <horak-fdf@web.de>2025-05-21 14:41:58 +0000
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-05-21 14:41:58 +0000
commit283b6c1ba3ff330b9030d857c8f53e9da51fb09b (patch)
tree691121a6b4ea6ce60f3557b380c6efb2fd45030d /src
parentb5ab3d6d25c024fc120746514edfff33c55074d2 (diff)
downloadtmwa-283b6c1ba3ff330b9030d857c8f53e9da51fb09b.tar.gz
tmwa-283b6c1ba3ff330b9030d857c8f53e9da51fb09b.tar.bz2
tmwa-283b6c1ba3ff330b9030d857c8f53e9da51fb09b.tar.xz
tmwa-283b6c1ba3ff330b9030d857c8f53e9da51fb09b.zip
Add map helper functions
* function mapexists tells if a map exists or not. * function numberofmaps tells the current number of maps in maps_db. * function getmapnamebyindex tells map name of a specific index in maps_db. Reviewed-by: Thorbjørn Lindeijer <bjorn@lindeijer.nl>
Diffstat (limited to 'src')
-rw-r--r--src/map/script-fun.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp
index 27807b9..64ba542 100644
--- a/src/map/script-fun.cpp
+++ b/src/map/script-fun.cpp
@@ -5517,6 +5517,53 @@ void builtin_getmapnamefromhash(ScriptState *st)
}
/*==========================================
+ * Look if a map exists
+ * return value:
+ * 0 = map does not exist
+ * 1 = map exists
+ *------------------------------------------
+ */
+static
+void builtin_mapexists(ScriptState *st)
+{
+ MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARG(0))));
+ push_int<ScriptDataInt>(st->stack, map_mapname2mapid(mapname).is_some());
+}
+
+/*==========================================
+ * Returns number of available maps
+ *------------------------------------------
+ */
+static
+void builtin_numberofmaps(ScriptState *st)
+{
+ push_int<ScriptDataInt>(st->stack, maps_db.size());
+}
+
+/*==========================================
+ * Get the map name of a specific maps_db index
+ *------------------------------------------
+ */
+static
+void builtin_getmapnamebyindex(ScriptState *st)
+{
+ int index = conv_num(st, &AARG(0));
+ int count = 0;
+
+ for (auto& mit : maps_db)
+ {
+ if (count == index)
+ {
+ push_str<ScriptDataStr>(st->stack, mit.second->name_);
+ return;
+ }
+ ++count;
+ }
+
+ push_str<ScriptDataStr>(st->stack, ""_s);
+}
+
+/*==========================================
* Get the NPC's info
*------------------------------------------
*/
@@ -5782,6 +5829,9 @@ BuiltinFunction builtin_functions[] =
BUILTIN(getmapmaxy, "M"_s, 'i'),
BUILTIN(getmaphash, "M"_s, 'i'),
BUILTIN(getmapnamefromhash, "i"_s, 's'),
+ BUILTIN(mapexists, "M"_s, 'i'),
+ BUILTIN(numberofmaps, ""_s, 'i'),
+ BUILTIN(getmapnamebyindex, "i"_s, 's'),
BUILTIN(mapexit, ""_s, '\0'),
BUILTIN(freeloop, "i"_s, '\0'),
BUILTIN(if_then_else, "iii"_s, 'v'),