summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authormekolat <mekolat@users.noreply.github.com>2017-10-20 15:32:50 -0400
committerGitHub <noreply@github.com>2017-10-20 15:32:50 -0400
commit04f10f3b61044a78e9b3741cecbbdb8cf3a21236 (patch)
treef168dcd28250b6e4823bf833637057932661b07a /src/map
parent018f1ffc77c8f690a6a5643365f64794451c9aa9 (diff)
parent81bcd28716c28b326c4e41dca7228413f9afb472 (diff)
downloadhercules-04f10f3b61044a78e9b3741cecbbdb8cf3a21236.tar.gz
hercules-04f10f3b61044a78e9b3741cecbbdb8cf3a21236.tar.bz2
hercules-04f10f3b61044a78e9b3741cecbbdb8cf3a21236.tar.xz
hercules-04f10f3b61044a78e9b3741cecbbdb8cf3a21236.zip
Merge pull request #1852 from mekolat/getmapinfo2
Diffstat (limited to 'src/map')
-rw-r--r--src/map/script.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/map/script.c b/src/map/script.c
index da079c082..e2f53088c 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;
@@ -24012,6 +24082,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"),
@@ -24670,6 +24741,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);