From 174ade9a45988abf053cf45f30775fc6a76e706e Mon Sep 17 00:00:00 2001 From: zephyrus Date: Fri, 14 Aug 2009 14:03:53 +0000 Subject: - Fixes and optimization to instancing. Thanks to Saithis git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14006 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/mapindex.c | 2 +- src/map/instance.c | 29 ++++++++++------------------- src/map/instance.h | 4 ++-- src/map/npc.c | 3 +++ src/map/pc.c | 2 +- src/map/script.c | 48 +++++++++++++++++++++++++++++------------------- 6 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/common/mapindex.c b/src/common/mapindex.c index 01843c936..ca2ff4751 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -58,7 +58,7 @@ const char* mapindex_getmapname_ext(const char* string, char* output) len = safestrnlen(buf, MAP_NAME_LENGTH); if (len == MAP_NAME_LENGTH) { - ShowWarning("(mapindex_normalize_name) Map name '%*s' is too long!", 2*MAP_NAME_LENGTH, buf); + ShowWarning("(mapindex_normalize_name) Map name '%*s' is too long!\n", 2*MAP_NAME_LENGTH, buf); len--; } strncpy(dest, buf, len+1); diff --git a/src/map/instance.c b/src/map/instance.c index 45e610b8d..c617e60c4 100644 --- a/src/map/instance.c +++ b/src/map/instance.c @@ -75,7 +75,7 @@ int instance_create(int party_id, const char *name) /*-------------------------------------- * Add a map to the instance using src map "name" *--------------------------------------*/ -int instance_add_map(const char *name, int instance_id) +int instance_add_map(const char *name, int instance_id, bool usebasename) { int m = map_mapname2mapid(name), i, im = -1; size_t num_cell, size; @@ -109,7 +109,7 @@ int instance_add_map(const char *name, int instance_id) else im = map_num++; // Using next map index memcpy( &map[im], &map[m], sizeof(struct map_data) ); // Copy source map - snprintf(map[im].name, MAP_NAME_LENGTH, "%.3d%s", instance_id, name); // Generate Name for Instance Map + snprintf(map[im].name, MAP_NAME_LENGTH, (usebasename ? "%.3d#%s" : "%.3d%s"), instance_id, name); // Generate Name for Instance Map map[im].index = mapindex_addmap(-1, map[im].name); // Add map index if( !map[im].index ) @@ -150,24 +150,15 @@ int instance_add_map(const char *name, int instance_id) * party_id : source party of this instance * type : result (0 = map id | 1 = instance id) *--------------------------------------*/ -int instance_map2imap(int m, int party_id, int type) +int instance_map2imap(int m, int instance_id) { - int i; - struct party_data *p; - if( (p = party_search(party_id)) == NULL || !p->instance_id ) - return -1; - - for( i = 0; i < instance[p->instance_id].num_map; i++ ) - { - if( instance[p->instance_id].map[i] && map[instance[p->instance_id].map[i]].instance_src_map == m ) - { - if( type == 0 ) - return instance[p->instance_id].map[i]; - else - return p->instance_id; - } - } - return -1; + int i; + for( i = 0; i < instance[instance_id].num_map; i++ ) + { + if( instance[instance_id].map[i] && map[instance[instance_id].map[i]].instance_src_map == m ) + return instance[instance_id].map[i]; + } + return -1; } /*-------------------------------------- diff --git a/src/map/instance.h b/src/map/instance.h index a98117c57..f9fa87dc3 100644 --- a/src/map/instance.h +++ b/src/map/instance.h @@ -32,9 +32,9 @@ extern int instance_start; extern struct s_instance instance[MAX_INSTANCE]; int instance_create(int party_id, const char *name); -int instance_add_map(const char *name, int instance_id); +int instance_add_map(const char *name, int instance_id, bool usebasename); void instance_del_map(int m); -int instance_map2imap(int m, int party_id, int type); +int instance_map2imap(int m, int instance_id); int instance_mapid2imapid(int m, int instance_id); void instance_destroy(int instance_id); void instance_init(int instance_id); diff --git a/src/map/npc.c b/src/map/npc.c index 3614968c0..3380f2ace 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -3259,6 +3259,9 @@ int npc_reload(void) "\t-'"CL_WHITE"%d"CL_RESET"' Mobs Not Cached\n", npc_id - npc_new_min, npc_warp, npc_shop, npc_script, npc_mob, npc_cache_mob, npc_delay_mob); + for( i = 0; i < ARRAYLENGTH(instance); ++i ) + if( instance[i].instance_id ) instance_init(instance[i].instance_id); + //Re-read the NPC Script Events cache. npc_read_event_script(); diff --git a/src/map/pc.c b/src/map/pc.c index 2ded5e38b..17a8917cd 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -3890,7 +3890,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y if( map[m].flag.src4instance && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) { // Request the mapid of this src map into the instance of the party - int im = instance_map2imap(m, sd->status.party_id, 0); + int im = instance_map2imap(m, p->instance_id); if( im < 0 ) ; // Player will enter the src map for instances else diff --git a/src/map/script.c b/src/map/script.c index ac4c34860..ba2c9dc51 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -13780,10 +13780,14 @@ BUILDIN_FUNC(instance_attachmap) const char *name; int m; int instance_id; + bool usebasename = false; - name = script_getstr(st, 2); - instance_id = script_getnum(st, 3); - if( (m = instance_add_map(name, instance_id)) < 0 ) + name = script_getstr(st,2); + instance_id = script_getnum(st,3); + if( script_hasdata(st,4) && script_getnum(st,4) > 0) + usebasename = true; + + if( (m = instance_add_map(name, instance_id, usebasename)) < 0 ) // [Saithis] { ShowError("buildin_instance_attachmap: instance creation failed (%s): %d\n", name, m); script_pushconststr(st, ""); @@ -13810,7 +13814,7 @@ BUILDIN_FUNC(instance_detachmap) instance_id = p->instance_id; else return 0; - if( (m = map_mapname2mapid(str)) < 0 || (m = instance_map2imap(m,instance_id,0)) < 0 ) + if( (m = map_mapname2mapid(str)) < 0 || (m = instance_map2imap(m,instance_id)) < 0 ) { ShowError("buildin_instance_detachmap: Trying to detach invalid map %s\n", str); return 0; @@ -13920,7 +13924,7 @@ BUILDIN_FUNC(instance_announce) BUILDIN_FUNC(instance_npcname) { const char *str; - int instance_id; + int instance_id = 0; struct map_session_data *sd; struct party_data *p; @@ -13933,13 +13937,12 @@ BUILDIN_FUNC(instance_npcname) instance_id = st->instance_id; else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) instance_id = p->instance_id; - else return 0; - if( (nd = npc_name2id(str)) != NULL ) - { - char npcname[NAME_LENGTH]; - snprintf(npcname, ARRAYLENGTH(npcname), "dup_%d_%d", instance_id, nd->bl.id); - script_pushconststr(st,npcname); + if( instance_id && (nd = npc_name2id(str)) != NULL ) + { + static char npcname[NAME_LENGTH+1]; + snprintf(npcname, sizeof(npcname), "dup_%d_%d", instance_id, nd->bl.id); + script_pushconststr(st,npcname); } else script_pushconststr(st,""); @@ -13949,13 +13952,20 @@ BUILDIN_FUNC(instance_npcname) BUILDIN_FUNC(has_instance) { - struct map_session_data *sd = script_rid2sd(st); - const char *str; - int m; + struct map_session_data *sd; + struct party_data *p; + const char *str; + int m, instance_id = 0; + + str = script_getstr(st, 2); + if( script_hasdata(st, 3) ) + instance_id = script_getnum(st, 3); + else if( st->instance_id ) + instance_id = st->instance_id; + else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) + instance_id = p->instance_id; - str = script_getstr(st, 2); - - if( !sd || (m = map_mapname2mapid(str)) < 0 || (m = instance_map2imap(m, sd->status.party_id, 0)) < 0 ) + if( !instance_id || (m = map_mapname2mapid(str)) < 0 || (m = instance_map2imap(m, instance_id)) < 0 ) { script_pushconststr(st, ""); return 0; @@ -14467,7 +14477,7 @@ struct script_function buildin_func[] = { // Instancing BUILDIN_DEF(instance_create,"si"), BUILDIN_DEF(instance_destroy,"?"), - BUILDIN_DEF(instance_attachmap,"si"), + BUILDIN_DEF(instance_attachmap,"si?"), BUILDIN_DEF(instance_detachmap,"s?"), BUILDIN_DEF(instance_attach,"i"), BUILDIN_DEF(instance_id,"?"), @@ -14475,7 +14485,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(instance_init,"i"), BUILDIN_DEF(instance_announce,"isi*"), BUILDIN_DEF(instance_npcname,"s?"), - BUILDIN_DEF(has_instance,"s"), + BUILDIN_DEF(has_instance,"s?"), BUILDIN_DEF(instance_warpall,"sii?"), //Quest Log System [Inkfish] -- cgit v1.2.3-60-g2f50