Refactored Instances to utilize C++ features (#3163)
* Fixes #3087 and fixes #3095. * Converts database file to YAML. * Converts static array to unordered_map which frees up pre-allocated memory that may never be fully used. * Got rid of all DBMap/ERS features. * Removes MAX_INSTANCE_DATA in favor of INT_MAX. * Includes TXT converter. Thanks to @Lemongrass3110, @secretdataz, @Atemo, @lighta, @InusualZ, @Angelic234, @Normynator, @cydh, and @ecdarreola!
This commit is contained in:
@@ -2171,12 +2171,12 @@ int map_quit(struct map_session_data *sd) {
|
||||
|
||||
struct map_data *mapdata = map_getmapdata(sd->bl.m);
|
||||
|
||||
if( mapdata->instance_id )
|
||||
if( mapdata->instance_id > 0 )
|
||||
instance_delusers(mapdata->instance_id);
|
||||
|
||||
unit_remove_map_pc(sd,CLR_RESPAWN);
|
||||
|
||||
if( mapdata->instance_id ) { // Avoid map conflicts and warnings on next login
|
||||
if( mapdata->instance_id > 0 ) { // Avoid map conflicts and warnings on next login
|
||||
int16 m;
|
||||
struct point *pt;
|
||||
if( mapdata->save.map )
|
||||
@@ -2694,18 +2694,16 @@ bool map_addnpc(int16 m,struct npc_data *nd)
|
||||
/*==========================================
|
||||
* Add an instance map
|
||||
*------------------------------------------*/
|
||||
int map_addinstancemap(const char *name, unsigned short instance_id)
|
||||
int map_addinstancemap(int src_m, int instance_id)
|
||||
{
|
||||
int16 src_m = map_mapname2mapid(name);
|
||||
char iname[MAP_NAME_LENGTH];
|
||||
size_t num_cell, size;
|
||||
|
||||
if(src_m < 0)
|
||||
return -1;
|
||||
|
||||
const char *name = map_mapid2mapname(src_m);
|
||||
|
||||
if(strlen(name) > 20) {
|
||||
// against buffer overflow
|
||||
ShowError("map_addisntancemap: can't add long map name \"%s\"\n", name);
|
||||
ShowError("map_addinstancemap: can't add long map name \"%s\"\n", name);
|
||||
return -2;
|
||||
}
|
||||
|
||||
@@ -2727,18 +2725,19 @@ int map_addinstancemap(const char *name, unsigned short instance_id)
|
||||
|
||||
struct map_data *src_map = map_getmapdata(src_m);
|
||||
struct map_data *dst_map = map_getmapdata(dst_m);
|
||||
char iname[MAP_NAME_LENGTH];
|
||||
|
||||
strcpy(iname, name);
|
||||
|
||||
// Alter the name
|
||||
// Due to this being custom we only worry about preserving as many characters as necessary for accurate map distinguishing
|
||||
// This also allows us to maintain complete independence with main map functions
|
||||
if((strchr(iname,'@') == NULL) && strlen(iname) > 8) {
|
||||
memmove(iname, iname+(strlen(iname)-9), strlen(iname));
|
||||
snprintf(dst_map->name, sizeof(dst_map->name),"%hu#%s", instance_id, iname);
|
||||
if ((strchr(iname, '@') == NULL) && strlen(iname) > 8) {
|
||||
memmove(iname, iname + (strlen(iname) - 9), strlen(iname));
|
||||
snprintf(dst_map->name, sizeof(dst_map->name), "%d#%s", (instance_id % 1000), iname);
|
||||
} else
|
||||
snprintf(dst_map->name, sizeof(dst_map->name),"%.3hu%s", instance_id, iname);
|
||||
dst_map->name[MAP_NAME_LENGTH-1] = '\0';
|
||||
snprintf(dst_map->name, sizeof(dst_map->name), "%.3d%s", (instance_id % 1000), iname);
|
||||
dst_map->name[MAP_NAME_LENGTH - 1] = '\0';
|
||||
|
||||
dst_map->m = dst_m;
|
||||
dst_map->instance_id = instance_id;
|
||||
@@ -2756,11 +2755,13 @@ int map_addinstancemap(const char *name, unsigned short instance_id)
|
||||
dst_map->npc_num_warp = 0;
|
||||
|
||||
// Reallocate cells
|
||||
num_cell = dst_map->xs * dst_map->ys;
|
||||
size_t num_cell = dst_map->xs * dst_map->ys;
|
||||
|
||||
CREATE( dst_map->cell, struct mapcell, num_cell );
|
||||
memcpy( dst_map->cell, src_map->cell, num_cell * sizeof(struct mapcell) );
|
||||
|
||||
size = dst_map->bxs * dst_map->bys * sizeof(struct block_list*);
|
||||
size_t size = dst_map->bxs * dst_map->bys * sizeof(struct block_list*);
|
||||
|
||||
dst_map->block = (struct block_list **)aCalloc(1,size);
|
||||
dst_map->block_mob = (struct block_list **)aCalloc(1,size);
|
||||
|
||||
@@ -2829,7 +2830,7 @@ int map_delinstancemap(int m)
|
||||
{
|
||||
struct map_data *mapdata = map_getmapdata(m);
|
||||
|
||||
if(m < 0 || !mapdata->instance_id)
|
||||
if(m < 0 || mapdata->instance_id <= 0)
|
||||
return 0;
|
||||
|
||||
// Kick everyone out
|
||||
@@ -2972,7 +2973,7 @@ void map_removemobs(int16 m)
|
||||
return; //Mobs are already scheduled for removal
|
||||
|
||||
// Don't remove mobs on instance map
|
||||
if (mapdata->instance_id)
|
||||
if (mapdata->instance_id > 0)
|
||||
return;
|
||||
|
||||
mapdata->mob_delete_timer = add_timer(gettick()+battle_config.mob_remove_delay, map_removemobs_timer, m, 0);
|
||||
@@ -2991,17 +2992,15 @@ const char* map_mapid2mapname(int m)
|
||||
if (!mapdata)
|
||||
return "";
|
||||
|
||||
if (mapdata->instance_id) { // Instance map check
|
||||
struct instance_data *im = &instance_data[mapdata->instance_id];
|
||||
if (mapdata->instance_id > 0) { // Instance map check
|
||||
std::shared_ptr<s_instance_data> idata = util::umap_find(instances, map[m].instance_id);
|
||||
|
||||
if (!im) // This shouldn't happen but if it does give them the map we intended to give
|
||||
if (!idata) // This shouldn't happen but if it does give them the map we intended to give
|
||||
return mapdata->name;
|
||||
else {
|
||||
uint8 i;
|
||||
|
||||
for (i = 0; i < im->cnt_map; i++) { // Loop to find the src map we want
|
||||
if (im->map[i]->m == m)
|
||||
return map[im->map[i]->src_m].name;
|
||||
for (const auto &it : idata->map) { // Loop to find the src map we want
|
||||
if (it.m == m)
|
||||
return map_getmapdata(it.src_m)->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user