From 2568b4b6959a90f01e02918971eeb12d94e4a2fe Mon Sep 17 00:00:00 2001 From: gumi Date: Thu, 5 Oct 2017 14:23:04 -0400 Subject: add buildin_getmapinfo --- src/map/script.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/map/script.c b/src/map/script.c index 367c9927d..e02e57b56 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -12779,6 +12779,76 @@ BUILDIN(setmapflagnosave) { return true; } +enum mapinfo_info { + MAPINFO_NAME, + MAPINFO_ID, + MAPINFO_SIZE_X, + MAPINFO_SIZE_Y, + MAPINFO_ZONE +}; + +BUILDIN(getmapinfo) +{ + enum mapinfo_info mode = script_getnum(st, 2); + int16 m; + + if (script_hasdata(st, 3)) { + if (script_isstringtype(st, 3)) { + const char *str = script_getstr(st, 3); + m = map->mapname2mapid(str); + } else { + m = script_getnum(st, 3); + } + } else { + struct block_list *bl = NULL; + + if (st->oid) { + bl = map->id2bl(st->oid); + } else if (st->rid) { + bl = map->id2bl(st->rid); + } + + if (bl == NULL) { + ShowError("script:getmapinfo: map not supplied and NPC/PC not attached!\n"); + script_pushint(st, -3); + return false; + } + + m = bl->m; + } + + if (m < 0) { + // here we don't throw an error, so the command can be used + // to detect whether or not a map exists + script_pushint(st, -1); + return true; + } + + switch (mode) { + case MAPINFO_NAME: + script_pushconststr(st, map->list[m].name); + break; + case MAPINFO_ID: + script_pushint(st, m); + break; + case MAPINFO_SIZE_X: + script_pushint(st, map->list[m].xs); + break; + case MAPINFO_SIZE_Y: + script_pushint(st, map->list[m].ys); + break; + case MAPINFO_ZONE: + script_pushstrcopy(st, map->list[m].zone->name); + break; + default: + ShowError("script:getmapinfo: unknown option in second argument (%u).\n", mode); + script_pushint(st, -2); + return false; + } + + return true; +} + BUILDIN(getmapflag) { int16 m,i; @@ -23994,6 +24064,7 @@ void script_parse_builtin(void) { BUILDIN_DEF(isloggedin,"i?"), BUILDIN_DEF(setmapflagnosave,"ssii"), BUILDIN_DEF(getmapflag,"si"), + BUILDIN_DEF(getmapinfo,"i?"), BUILDIN_DEF(setmapflag,"si?"), BUILDIN_DEF(removemapflag,"si"), BUILDIN_DEF(pvpon,"s"), @@ -24648,6 +24719,13 @@ void script_hardcoded_constants(void) script->set_constant("DRESSROOM_OPEN", DRESSROOM_OPEN, false, false); script->set_constant("DRESSROOM_CLOSE", DRESSROOM_CLOSE, false, false); + script->constdb_comment("getmapinfo options"); + script->set_constant("MAPINFO_NAME", MAPINFO_NAME, false, false); + script->set_constant("MAPINFO_ID", MAPINFO_ID, false, false); + script->set_constant("MAPINFO_SIZE_X", MAPINFO_SIZE_X, false, false); + script->set_constant("MAPINFO_SIZE_Y", MAPINFO_SIZE_Y, false, false); + script->set_constant("MAPINFO_ZONE", MAPINFO_ZONE, false, false); + script->constdb_comment("Renewal"); #ifdef RENEWAL script->set_constant("RENEWAL", 1, false, false); -- cgit v1.2.3-70-g09d2 From 81bcd28716c28b326c4e41dca7228413f9afb472 Mon Sep 17 00:00:00 2001 From: gumi Date: Thu, 5 Oct 2017 14:34:43 -0400 Subject: add documentation for buildin_getmapinfo --- doc/script_commands.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 331bed1c7..8a7c9853c 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -3305,6 +3305,27 @@ Notice that NPC objects disabled with disablenpc() will still be located. --------------------------------------- +*getmapinfo({, ""}) +*getmapinfo({, }) + +This command returns various information about a specific map. If the second +argument is omitted, it will try to use the map of the attached NPC, or the +map of the attached player if the NPC can't be found. + +Valid are: + MAPINFO_NAME name of the map + MAPINFO_ID numeric ID of the map + MAPINFO_ZONE name of the zone used by the map + MAPINFO_SIZE_X width of the map (cells on the x axis) + MAPINFO_SIZE_Y height of the map (cells on the y axis) + +Examples: + getmapinfo(MAPINFO_ID, "map name"); // ID from name + getmapinfo(MAPINFO_NAME, 3); // name from ID + getmapinfo(MAPINFO_ZONE); // zone, ie Normal, PvP, Jail, ... + +--------------------------------------- + *getunits(, , , ""{, , , , }) This function searches a whole map or area for units and adds their GID to -- cgit v1.2.3-70-g09d2