瀏覽代碼

- Fixes and optimization to instancing. Thanks to Saithis

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14006 54d463be-8e91-2dee-dedb-b68131a5f0ec
zephyrus 15 年之前
父節點
當前提交
515cd8685c
共有 6 個文件被更改,包括 46 次插入42 次删除
  1. 1 1
      src/common/mapindex.c
  2. 10 19
      src/map/instance.c
  3. 2 2
      src/map/instance.h
  4. 3 0
      src/map/npc.c
  5. 1 1
      src/map/pc.c
  6. 29 19
      src/map/script.c

+ 1 - 1
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);

+ 10 - 19
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;
 }
 
 /*--------------------------------------

+ 2 - 2
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);

+ 3 - 0
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();
 

+ 1 - 1
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

+ 29 - 19
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]