From e6565c0be2bc726a30268c76d8732eb542d723da Mon Sep 17 00:00:00 2001 From: Akinari1087 Date: Tue, 6 Aug 2013 01:20:41 -0400 Subject: [PATCH] Add cell copying across instances - Fixes bugreport:7875 --- src/map/map.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/map/map.c b/src/map/map.c index b6b35dd325..66b491a2cc 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2182,7 +2182,7 @@ int map_addinstancemap(const char *name, int id) int src_m = map_mapname2mapid(name); int dst_m = -1, i; char iname[MAP_NAME_LENGTH]; - size_t size; + size_t num_cell, size; if(src_m < 0) return -1; @@ -2229,6 +2229,11 @@ int map_addinstancemap(const char *name, int id) memset(map[dst_m].npc, 0, sizeof(map[dst_m].npc)); map[dst_m].npc_num = 0; + // Reallocate cells + num_cell = map[dst_m].xs * map[dst_m].ys; + CREATE( map[dst_m].cell, struct mapcell, num_cell ); + memcpy( map[dst_m].cell, map[src_m].cell, num_cell * sizeof(struct mapcell) ); + size = map[dst_m].bxs * map[dst_m].bys * sizeof(struct block_list*); map[dst_m].block = (struct block_list **)aCalloc(1,size); map[dst_m].block_mob = (struct block_list **)aCalloc(1,size); @@ -2291,9 +2296,7 @@ static int map_instancemap_clean(struct block_list *bl, va_list ap) *------------------------------------------*/ int map_delinstancemap(int m) { - if(m < 0) - return 0; - if(map[m].instance_id == 0) + if(m < 0 || !map[m].instance_id) return 0; // Kick everyone out @@ -2308,6 +2311,7 @@ int map_delinstancemap(int m) mapindex_removemap( map[m].index ); // Free memory + aFree(map[m].cell); aFree(map[m].block); aFree(map[m].block_mob);