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:
Aleos
2020-04-08 12:52:45 -04:00
committed by GitHub
parent 7507065885
commit 06c159c405
22 changed files with 1367 additions and 891 deletions

View File

@@ -16,6 +16,7 @@
#include "../common/showmsg.hpp"
#include "../common/strlib.hpp"
#include "../common/timer.hpp"
#include "../common/utilities.hpp"
#include "../common/utils.hpp"
#include "battle.hpp"
@@ -33,6 +34,8 @@
#include "pet.hpp"
#include "script.hpp" // script_config
using namespace rathena;
struct npc_data* fake_nd;
// linked list of npc source files
@@ -3489,7 +3492,7 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) {
char newname[NPC_NAME_LENGTH+1];
struct map_data *mapdata = map_getmapdata(m);
if( mapdata->instance_id == 0 )
if( mapdata->instance_id <= 0 )
return 1;
snprintf(newname, ARRAYLENGTH(newname), "dup_%d_%d", mapdata->instance_id, snd->bl.id);
@@ -3500,15 +3503,17 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) {
if( snd->subtype == NPCTYPE_WARP ) { // Adjust destination, if instanced
struct npc_data *wnd = NULL; // New NPC
struct instance_data *im = &instance_data[mapdata->instance_id];
int dm = map_mapindex2mapid(snd->u.warp.mapindex), imap = 0, i;
std::shared_ptr<s_instance_data> idata = util::umap_find(instances, mapdata->instance_id);
int dm = map_mapindex2mapid(snd->u.warp.mapindex), imap = 0;
if( dm < 0 ) return 1;
for(i = 0; i < im->cnt_map; i++)
if(im->map[i]->m && map_mapname2mapid(map_getmapdata(im->map[i]->src_m)->name) == dm) {
imap = map_mapname2mapid(map_getmapdata(im->map[i]->m)->name);
for (const auto &it : idata->map) {
if (it.m && map_mapname2mapid(map_getmapdata(it.src_m)->name) == dm) {
imap = map_mapname2mapid(map_getmapdata(it.m)->name);
break; // Instance map matches destination, update to instance map
}
}
if(!imap)
imap = map_mapname2mapid(map_getmapdata(dm)->name);