From 161a4c01c9c8c31b1514d2a79fa1c6348f56cac2 Mon Sep 17 00:00:00 2001 From: aleos89 Date: Thu, 26 May 2016 09:06:49 -0400 Subject: [PATCH] Small adjustments for the instance system * Follow up to 32c829d. * Added a missing break on guild type instance creation. - Thanks to @Canoe! * Added instance name back to script command instance_enter. - This will present the proper error message when trying to enter another instance. --- doc/script_commands.txt | 2 +- npc/instances/EndlessTower.txt | 2 +- npc/instances/NydhoggsNest.txt | 2 +- npc/instances/OrcsMemory.txt | 2 +- npc/instances/SealedShrine.txt | 2 +- npc/re/instances/BakonawaLake.txt | 2 +- npc/re/instances/BangungotHospital.txt | 2 +- npc/re/instances/BuwayaCave.txt | 2 +- npc/re/instances/EclageInterior.txt | 2 +- npc/re/instances/HazyForest.txt | 2 +- npc/re/instances/MalangdoCulvert.txt | 2 +- npc/re/instances/OctopusCave.txt | 2 +- npc/re/instances/OldGlastHeim.txt | 2 +- npc/re/instances/WolfchevLaboratory.txt | 2 +- src/map/instance.c | 20 ++++++++++++-------- src/map/instance.h | 6 +++--- src/map/script.c | 13 +++++++------ 17 files changed, 36 insertions(+), 31 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index fc8bcc8327..523ff607ae 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -8151,7 +8151,7 @@ that fails, the script will come to a halt. --------------------------------------- -*instance_enter({,,}); +*instance_enter("",{,,}); Warps player to the specified instance after the script terminates. The map and coordinates are located in 'db/(pre-)re/instance_db.txt'. diff --git a/npc/instances/EndlessTower.txt b/npc/instances/EndlessTower.txt index e44bf3a0cf..756690c9dc 100644 --- a/npc/instances/EndlessTower.txt +++ b/npc/instances/EndlessTower.txt @@ -291,7 +291,7 @@ e_tower,81,105,0 script Tower Protection Stone 406,{ } L_Enter: - switch(instance_enter()) { + switch(instance_enter("Endless Tower")) { case 3: mes "An unknown error has occurred."; close; diff --git a/npc/instances/NydhoggsNest.txt b/npc/instances/NydhoggsNest.txt index f5a08096ab..ced58fceb1 100644 --- a/npc/instances/NydhoggsNest.txt +++ b/npc/instances/NydhoggsNest.txt @@ -192,7 +192,7 @@ nyd_dun02,100,201,3 script Yggdrasil Gatekeeper 111,8,8,{ close; L_Enter: - switch(instance_enter()) { + switch(instance_enter("Nidhoggur's Nest")) { case 3: mes "[Yggdrasil Gatekeeper]"; mes "An unknown error has occurred."; diff --git a/npc/instances/OrcsMemory.txt b/npc/instances/OrcsMemory.txt index 3d94be13a4..6965be8b1c 100644 --- a/npc/instances/OrcsMemory.txt +++ b/npc/instances/OrcsMemory.txt @@ -84,7 +84,7 @@ gef_fild10,242,202,0 script Dimensional Gorge Piece 406,{ mes "In order to generate a dungeon you must be the Party Leader and have at least 2 members in the party."; close; L_Enter: - switch(instance_enter()) { + switch(instance_enter("Orc's Memory")) { case 3: mes "An unknown error has occurred."; close; diff --git a/npc/instances/SealedShrine.txt b/npc/instances/SealedShrine.txt index ee68eec968..2734a5f228 100644 --- a/npc/instances/SealedShrine.txt +++ b/npc/instances/SealedShrine.txt @@ -214,7 +214,7 @@ monk_test,306,151,3 script Grave of Baphomet#edq 111,{ //set .@ins_bapho_check2,checkquest(3045,PLAYTIME); if (.@ins_bapho_check == -1) { - switch(instance_enter()) { + switch(instance_enter("Sealed Catacomb")) { case 3: case 2: mes "It's cold to the touch. It doesn't respond."; diff --git a/npc/re/instances/BakonawaLake.txt b/npc/re/instances/BakonawaLake.txt index 893a5d5f5f..39ec9f5dfb 100644 --- a/npc/re/instances/BakonawaLake.txt +++ b/npc/re/instances/BakonawaLake.txt @@ -74,7 +74,7 @@ ma_scene01,174,179,4 script Taho 541,{ mes "Now I'm weaving, so you can go down when I'm done."; close; case 2: - switch(instance_enter()) { + switch(instance_enter(.@md_name$)) { case 3: mes "[Taho]"; mes "An unknown error occurred."; diff --git a/npc/re/instances/BangungotHospital.txt b/npc/re/instances/BangungotHospital.txt index b671860f63..a9127bd417 100644 --- a/npc/re/instances/BangungotHospital.txt +++ b/npc/re/instances/BangungotHospital.txt @@ -282,7 +282,7 @@ L_Enter: cutin "",255; end; case 2: - switch(instance_enter()) { + switch(instance_enter(.@md_name$)) { case 3: mes "[Nurse Maenne]"; mes "A critical situation has happened."; diff --git a/npc/re/instances/BuwayaCave.txt b/npc/re/instances/BuwayaCave.txt index f30aa1743f..f6c3618ce4 100644 --- a/npc/re/instances/BuwayaCave.txt +++ b/npc/re/instances/BuwayaCave.txt @@ -126,7 +126,7 @@ OnTouch: } switch(select("Enter.:Turn back.")) { case 1: - switch(instance_enter()) { + switch(instance_enter("Buwaya Cave")) { case 3: mes "[Guard]"; mes "Oh, now is not a good time."; diff --git a/npc/re/instances/EclageInterior.txt b/npc/re/instances/EclageInterior.txt index b2e68f70ba..61dbc7debd 100644 --- a/npc/re/instances/EclageInterior.txt +++ b/npc/re/instances/EclageInterior.txt @@ -74,7 +74,7 @@ ecl_hub01,130,15,0 script It is closed shut. 844,{ mes "It is pretty difficult to guide an outsider like you."; close; } - switch (instance_enter()) { + switch (instance_enter(.@md_name$)) { case 3: mes "An unknown error has occurred."; close; diff --git a/npc/re/instances/HazyForest.txt b/npc/re/instances/HazyForest.txt index 80e86d9962..cdf6670e57 100644 --- a/npc/re/instances/HazyForest.txt +++ b/npc/re/instances/HazyForest.txt @@ -139,7 +139,7 @@ bif_fild01,161,355,0 script Log Tunnel 844,{ next; if(select("Enter the tunnel.:Give up.") == 2) close; - switch(instance_enter()) { + switch(instance_enter("Mistwood Maze")) { case 3: mes "[Laphine Soldier]"; mes "Something doesn't feel right. Looks like something dangerous is going on, so you'd better turn back today."; diff --git a/npc/re/instances/MalangdoCulvert.txt b/npc/re/instances/MalangdoCulvert.txt index 150d9b019e..264467a951 100644 --- a/npc/re/instances/MalangdoCulvert.txt +++ b/npc/re/instances/MalangdoCulvert.txt @@ -432,7 +432,7 @@ mal_in01,160,34,4 script Missing, the Cleaner 545,{ } end; L_Enter: - switch(instance_enter()) { + switch(instance_enter("Culvert")) { case 3: mes "An unknown error has occurred."; close; diff --git a/npc/re/instances/OctopusCave.txt b/npc/re/instances/OctopusCave.txt index 1c5c216c20..affbcf639c 100644 --- a/npc/re/instances/OctopusCave.txt +++ b/npc/re/instances/OctopusCave.txt @@ -119,7 +119,7 @@ mal_dun01,153,237,5 script Weird Entrance 844,{ switch(select("Go in.:Stop.")) { case 1: if (countitem(6442)) { - switch(instance_enter()) { + switch(instance_enter("Octopus Cave")) { case 3: mes "[Starfish]"; mes "Ah, now is not the time..."; diff --git a/npc/re/instances/OldGlastHeim.txt b/npc/re/instances/OldGlastHeim.txt index 8edaa630ac..434ef29760 100644 --- a/npc/re/instances/OldGlastHeim.txt +++ b/npc/re/instances/OldGlastHeim.txt @@ -51,7 +51,7 @@ glast_01,204,273,6 script Hugin#ghinstance 755,{ mes "The time gap was created. When you're ready, talk to me again."; close; case 2: - switch(instance_enter()) { + switch(instance_enter(.@md_name$)) { case 3: mes "An unknown error has occurred."; close; diff --git a/npc/re/instances/WolfchevLaboratory.txt b/npc/re/instances/WolfchevLaboratory.txt index 3a7096b945..a814f6146e 100644 --- a/npc/re/instances/WolfchevLaboratory.txt +++ b/npc/re/instances/WolfchevLaboratory.txt @@ -877,7 +877,7 @@ lhz_dun04,147,279,0 script Laboratory Entrance#memo CLEAR_NPC,{ mes "You have stopped entering to Wolfchev's laboratory."; close; } - if (instance_enter() != 0) { // probably missing failure cases + if (instance_enter("Wolfchev's Laboratory") != 0) { // probably missing failure cases mes "^FF0000Warning^000000"; mes ""+ strcharinfo(0) +". . ."; mes "^FF0000Unregistered personnel^000000"; diff --git a/src/map/instance.c b/src/map/instance.c index 480d3a9b7e..68f811b126 100644 --- a/src/map/instance.c +++ b/src/map/instance.c @@ -499,10 +499,10 @@ int instance_addmap(unsigned short instance_id) { * instance_id : where to search * result : mapid of map "name" in this instance *------------------------------------------*/ -int instance_mapname2mapid(const char *name, unsigned short instance_id) +int16 instance_mapname2mapid(const char *name, unsigned short instance_id) { struct instance_data *im; - int m = map_mapname2mapid(name); + int16 m = map_mapname2mapid(name); char iname[MAP_NAME_LENGTH]; int i; @@ -632,29 +632,31 @@ int instance_destroy(unsigned short instance_id) /*========================================== * Allows a user to enter an instance *------------------------------------------*/ -int instance_enter(struct map_session_data *sd, unsigned short instance_id) +int instance_enter(struct map_session_data *sd, unsigned short instance_id, const char *name) { - struct instance_db *db = instance_searchtype_db(instance_data[instance_id].type); + struct instance_db *db = instance_searchname_db(name); nullpo_retr(-1, sd); if (db == NULL) return 2; - return instance_enter_position(sd, instance_id, db->enter.x, db->enter.y); + return instance_enter_position(sd, instance_id, name, db->enter.x, db->enter.y); } /*========================================== * Warp a user into instance *------------------------------------------*/ -int instance_enter_position(struct map_session_data *sd, unsigned short instance_id, short x, short y) +int instance_enter_position(struct map_session_data *sd, unsigned short instance_id, const char *name, short x, short y) { struct instance_data *im = &instance_data[instance_id]; + struct instance_db *db = instance_searchname_db(name); struct party_data *p = NULL; struct guild *g = NULL; int16 m; nullpo_retr(-1, sd); + nullpo_retr(3, db); switch(instance_data[instance_id].mode) { case IM_NONE: @@ -689,9 +691,11 @@ int instance_enter_position(struct map_session_data *sd, unsigned short instance if (im->state != INSTANCE_BUSY) return 3; + if (im->type != db->id) + return 3; // Does the instance match? - if ((m = instance_mapname2mapid(map_mapid2mapname(im->map[0]->m), instance_id)) < 0) + if ((m = instance_mapname2mapid(StringBuf_Value(db->enter.mapname), instance_id)) < 0) return 3; if (pc_setpos(sd, map_id2index(m), x, y, CLR_OUTSIGHT)) @@ -941,7 +945,7 @@ void do_reload_instance(void) if (instance_data[map[sd->bl.m].instance_id].mode == IM_GUILD && (!(g = guild_search(sd->status.guild_id)) || g->instance_id != map[sd->bl.m].instance_id)) // Someone not in guild is on instance map continue; im = &instance_data[p->instance_id]; - if((db = instance_searchtype_db(im->type)) != NULL && !instance_enter(sd, i)) { // All good + if((db = instance_searchtype_db(im->type)) != NULL && !instance_enter(sd, i, StringBuf_Value(db->name))) { // All good clif_displaymessage(sd->fd, msg_txt(sd,515)); // Instance has been reloaded instance_reqinfo(sd,p->instance_id); } else // Something went wrong diff --git a/src/map/instance.h b/src/map/instance.h index 5879f4f883..e2b91060b0 100644 --- a/src/map/instance.h +++ b/src/map/instance.h @@ -68,12 +68,12 @@ void instance_getsd(unsigned short instance_id, struct map_session_data **sd, en int instance_create(int owner_id, const char *name, enum instance_mode mode); int instance_destroy(unsigned short instance_id); -int instance_enter(struct map_session_data *sd, unsigned short instance_id); -int instance_enter_position(struct map_session_data *sd, unsigned short instance_id, short x, short y); +int instance_enter(struct map_session_data *sd, unsigned short instance_id, const char *name); +int instance_enter_position(struct map_session_data *sd, unsigned short instance_id, const char *name, short x, short y); int instance_reqinfo(struct map_session_data *sd, unsigned short instance_id); int instance_addusers(unsigned short instance_id); int instance_delusers(unsigned short instance_id); -int instance_mapname2mapid(const char *name, unsigned short instance_id); +int16 instance_mapname2mapid(const char *name, unsigned short instance_id); int instance_addmap(unsigned short instance_id); void instance_addnpc(struct instance_data *im); diff --git a/src/map/script.c b/src/map/script.c index 8371cc694a..b9d43fe535 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -18892,6 +18892,7 @@ BUILDIN_FUNC(instance_create) case IM_GUILD: if (sd) owner_id = sd->status.guild_id; + break; default: ShowError("buildin_instance_create: Invalid instance mode (instance name: %s)\n", script_getstr(st, 2)); return SCRIPT_CMD_FAILURE; @@ -18937,16 +18938,16 @@ BUILDIN_FUNC(instance_destroy) BUILDIN_FUNC(instance_enter) { struct map_session_data *sd = NULL; - int x = script_hasdata(st,2) ? script_getnum(st, 2) : -1; - int y = script_hasdata(st,3) ? script_getnum(st, 3) : -1; + int x = script_hasdata(st,3) ? script_getnum(st, 3) : -1; + int y = script_hasdata(st,4) ? script_getnum(st, 4) : -1; - if (!script_charid2sd(4,sd)) + if (!script_charid2sd(5,sd)) return SCRIPT_CMD_FAILURE; if (x != -1 && y != -1) - script_pushint(st, instance_enter_position(sd, script_instancegetid(st), x, y)); + script_pushint(st, instance_enter_position(sd, script_instancegetid(st), script_getstr(st, 2), x, y)); else - script_pushint(st, instance_enter(sd, script_instancegetid(st))); + script_pushint(st, instance_enter(sd, script_instancegetid(st), script_getstr(st, 2))); return SCRIPT_CMD_SUCCESS; } @@ -21917,7 +21918,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(instance_create,"s??"), BUILDIN_DEF(instance_destroy,"?"), BUILDIN_DEF(instance_id,""), - BUILDIN_DEF(instance_enter,"???"), + BUILDIN_DEF(instance_enter,"s???"), BUILDIN_DEF(instance_npcname,"s?"), BUILDIN_DEF(instance_mapname,"s?"), BUILDIN_DEF(instance_warpall,"sii?"),