summaryrefslogtreecommitdiff
path: root/src/map/script-fun.cpp
diff options
context:
space:
mode:
authorHoraK-FDF <horak-fdf@web.de>2024-06-20 11:40:01 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-08-30 21:05:10 +0200
commit69e85064403904ba6bece8532b29cc4fc60e722d (patch)
treee72d4174caab76c5f4153e6f7112de87a0bd8f8a /src/map/script-fun.cpp
parent4f80aafa3940abf4050290e6c8b63c45716e0db0 (diff)
downloadtmwa-69e85064403904ba6bece8532b29cc4fc60e722d.tar.gz
tmwa-69e85064403904ba6bece8532b29cc4fc60e722d.tar.bz2
tmwa-69e85064403904ba6bece8532b29cc4fc60e722d.tar.xz
tmwa-69e85064403904ba6bece8532b29cc4fc60e722d.zip
map hash
as it was not possible to store a string variable with the current format of the athena.txt I though a hash could help to identify the maps since this one can be stored as a permanent char bound variable in athena.txt
Diffstat (limited to 'src/map/script-fun.cpp')
-rw-r--r--src/map/script-fun.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp
index 1efa006..74a70b3 100644
--- a/src/map/script-fun.cpp
+++ b/src/map/script-fun.cpp
@@ -5524,6 +5524,39 @@ void builtin_getmapmaxy(ScriptState *st)
}
/*==========================================
+ * Get the hash of a map
+ *------------------------------------------
+ */
+static
+void builtin_getmaphash(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->hash);
+}
+
+/*==========================================
+ * Get the map name from a hash
+ *------------------------------------------
+ */
+static
+void builtin_getmapnamefromhash(ScriptState *st)
+{
+ int hash = conv_num(st, &AARG(0));
+ MapName mapname;
+ for (auto& mit : maps_db)
+ {
+ map_local *ml = static_cast<map_local *>(mit.second.get());
+ if (ml->hash == hash)
+ {
+ mapname = ml->name_;
+ break;
+ }
+ }
+ push_str<ScriptDataStr>(st->stack, mapname);
+}
+
+/*==========================================
* Get the NPC's info
*------------------------------------------
*/
@@ -5787,6 +5820,8 @@ BuiltinFunction builtin_functions[] =
BUILTIN(getmap, "?"_s, 's'),
BUILTIN(getmapmaxx, "M"_s, 'i'),
BUILTIN(getmapmaxy, "M"_s, 'i'),
+ BUILTIN(getmaphash, "M"_s, 'i'),
+ BUILTIN(getmapnamefromhash, "i"_s, 's'),
BUILTIN(mapexit, ""_s, '\0'),
BUILTIN(freeloop, "i"_s, '\0'),
BUILTIN(if_then_else, "iii"_s, 'v'),