summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/itemdb.cpp37
-rw-r--r--src/map/itemdb.hpp2
-rw-r--r--src/map/map.cpp124
-rw-r--r--src/map/map.hpp6
-rw-r--r--src/map/mob.cpp14
-rw-r--r--src/map/npc.cpp124
-rw-r--r--src/map/party.cpp33
-rw-r--r--src/map/script.cpp115
-rw-r--r--src/map/script.hpp10
-rw-r--r--src/map/storage.cpp47
-rw-r--r--src/map/storage.hpp2
11 files changed, 184 insertions, 330 deletions
diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp
index 9c6d4e6..115893b 100644
--- a/src/map/itemdb.cpp
+++ b/src/map/itemdb.cpp
@@ -18,7 +18,7 @@ constexpr int MAX_RANDITEM = 2000;
//#define ITEMDB_OVERRIDE_NAME_VERBOSE 1
static
-struct dbt *item_db;
+Map<int, struct item_data> item_db;
// Function declarations
@@ -37,9 +37,8 @@ int itemdb_read_noequip(void);
*/
// name = item alias, so we should find items aliases first. if not found then look for "jname" (full name)
static
-void itemdb_searchname_sub(db_key_t, db_val_t data, const char *str, struct item_data **dst)
+void itemdb_searchname_sub(struct item_data *item, const char *str, struct item_data **dst)
{
- struct item_data *item = (struct item_data *) data;
if (strcasecmp(item->name, str) == 0) //by lupus
*dst = item;
}
@@ -51,7 +50,8 @@ void itemdb_searchname_sub(db_key_t, db_val_t data, const char *str, struct item
struct item_data *itemdb_searchname(const char *str)
{
struct item_data *item = NULL;
- numdb_foreach(item_db, std::bind(itemdb_searchname_sub, ph::_1, ph::_2, str, &item));
+ for (auto& pair : item_db)
+ itemdb_searchname_sub(&pair.second, str, &item);
return item;
}
@@ -61,7 +61,7 @@ struct item_data *itemdb_searchname(const char *str)
*/
struct item_data *itemdb_exists(int nameid)
{
- return (struct item_data *)numdb_search(item_db, nameid);
+ return item_db.search(nameid);
}
/*==========================================
@@ -70,12 +70,11 @@ struct item_data *itemdb_exists(int nameid)
*/
struct item_data *itemdb_search(int nameid)
{
- struct item_data *id = (struct item_data *)numdb_search(item_db, nameid);
+ struct item_data *id = item_db.search(nameid);
if (id)
return id;
- id = (struct item_data *) calloc(1, sizeof(struct item_data));
- numdb_insert(item_db, nameid, id);
+ id = item_db.init(nameid);
id->nameid = nameid;
id->value_buy = 10;
@@ -366,18 +365,12 @@ int itemdb_read_noequip(void)
*------------------------------------------
*/
static
-void itemdb_final(db_key_t, db_val_t data)
+void itemdb_final(struct item_data *id)
{
- struct item_data *id;
-
- id = (struct item_data *)data;
- nullpo_retv(id);
-
if (id->use_script)
free(const_cast<ScriptCode *>(id->use_script));
if (id->equip_script)
free(const_cast<ScriptCode *>(id->equip_script));
- free(id);
}
void itemdb_reload(void)
@@ -398,11 +391,9 @@ void itemdb_reload(void)
*/
void do_final_itemdb(void)
{
- if (item_db)
- {
- numdb_final(item_db, itemdb_final);
- item_db = NULL;
- }
+ for (auto& pair : item_db)
+ itemdb_final(&pair.second);
+ item_db.clear();
}
/*
@@ -438,11 +429,7 @@ void itemdb_read(void)
*
*------------------------------------------
*/
-int do_init_itemdb(void)
+void do_init_itemdb(void)
{
- item_db = numdb_init();
-
itemdb_read();
-
- return 0;
}
diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp
index 3b808a8..056213e 100644
--- a/src/map/itemdb.hpp
+++ b/src/map/itemdb.hpp
@@ -110,6 +110,6 @@ int itemdb_isequip3(int);
void itemdb_reload(void);
void do_final_itemdb(void);
-int do_init_itemdb(void);
+void do_init_itemdb(void);
#endif // ITEMDB_HPP
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 65fdc38..4fa56c2 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -39,15 +39,22 @@
#include "../poison.hpp"
-// 極力 staticでローカルに収める
-static
-struct dbt *id_db = NULL;
+DMap<int, struct block_list *> id_db;
+
static
-struct dbt *map_db = NULL;
+DMap<std::string, struct map_data *> map_db;
+
static
-struct dbt *nick_db = NULL;
+DMap<std::string, struct map_session_data *> nick_db;
+
+struct charid2nick
+{
+ char nick[24];
+ int req_id;
+};
+
static
-struct dbt *charid_db = NULL;
+Map<int, struct charid2nick> charid_db;
static
int users = 0;
@@ -77,12 +84,6 @@ int map_port = 0;
interval_t autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
int save_settings = 0xFFFF;
-struct charid2nick
-{
- char nick[24];
- int req_id;
-};
-
char motd_txt[256] = "conf/motd.txt";
char help_txt[256] = "conf/help.txt";
@@ -645,7 +646,7 @@ int map_addobject(struct block_list *bl)
if (last_object_id < i)
last_object_id = i;
object[i] = bl;
- numdb_insert(id_db, i, bl);
+ id_db.put(i, bl);
return i;
}
@@ -668,7 +669,7 @@ int map_delobjectnofree(int id, BL type)
}
map_delblock(object[id]);
- numdb_erase(id_db, id);
+ id_db.put(id, nullptr);
// map_freeblock(object[id]);
object[id] = NULL;
@@ -888,35 +889,12 @@ int map_addflooritem(struct item *item_data, int amount,
*/
void map_addchariddb(int charid, const char *name)
{
- struct charid2nick *p = (struct charid2nick *)numdb_search(charid_db, charid);
+ struct charid2nick *p = charid_db.search(charid);
if (p == NULL)
- { // データベースにない
- CREATE(p, struct charid2nick, 1);
- p->req_id = 0;
- }
- else
- numdb_erase(charid_db, charid);
+ p = charid_db.init(charid);
memcpy(p->nick, name, 24);
p->req_id = 0;
- numdb_insert(charid_db, charid, p);
-}
-
-/*==========================================
- * charid_dbへ追加(返信要求のみ)
- *------------------------------------------
- */
-int map_reqchariddb(struct map_session_data *sd, int charid)
-{
- nullpo_ret(sd);
-
- struct charid2nick *p = (struct charid2nick *)numdb_search(charid_db, charid);
- if (p != NULL) // データベースにすでにある
- return 0;
- CREATE(p, struct charid2nick, 1);
- p->req_id = sd->bl.id;
- numdb_insert(charid_db, charid, p);
- return 0;
}
/*==========================================
@@ -927,7 +905,7 @@ void map_addiddb(struct block_list *bl)
{
nullpo_retv(bl);
- numdb_insert(id_db, bl->id, bl);
+ id_db.put(bl->id, bl);
}
/*==========================================
@@ -938,7 +916,7 @@ void map_deliddb(struct block_list *bl)
{
nullpo_retv(bl);
- numdb_erase(id_db, bl->id);
+ id_db.put(bl->id, nullptr);
}
/*==========================================
@@ -949,7 +927,7 @@ void map_addnickdb(struct map_session_data *sd)
{
nullpo_retv(sd);
- strdb_insert(nick_db, sd->status.name, sd);
+ nick_db.put(sd->status.name, sd);
}
/*==========================================
@@ -958,9 +936,9 @@ void map_addnickdb(struct map_session_data *sd)
* quit処理の主体が違うような気もしてきた
*------------------------------------------
*/
-int map_quit(struct map_session_data *sd)
+void map_quit(struct map_session_data *sd)
{
- nullpo_ret(sd);
+ nullpo_retv(sd);
if (sd->chatID) // チャットから出る
chat_leavechat(sd);
@@ -1004,11 +982,9 @@ int map_quit(struct map_session_data *sd)
map_delblock(&sd->bl);
- numdb_erase(id_db, sd->bl.id);
- strdb_erase(nick_db, sd->status.name);
- numdb_erase(charid_db, sd->status.char_id);
-
- return 0;
+ id_db.put(sd->bl.id, nullptr);
+ nick_db.put(sd->status.name, nullptr);
+ charid_db.erase(sd->status.char_id);
}
/*==========================================
@@ -1047,7 +1023,7 @@ struct map_session_data *map_id2sd(int id)
*/
char *map_charid2nick(int id)
{
- struct charid2nick *p = (struct charid2nick *)numdb_search(charid_db, id);
+ struct charid2nick *p = charid_db.search(id);
if (p == NULL)
return NULL;
@@ -1172,21 +1148,12 @@ struct block_list *map_id2bl(int id)
if (id < sizeof(object) / sizeof(object[0]))
bl = object[id];
else
- bl = (struct block_list *)numdb_search(id_db, id);
+ bl = id_db.get(id);
return bl;
}
/*==========================================
- * id_db内の全てにfuncを実行
- *------------------------------------------
- */
-void map_foreachiddb(db_func_t func)
-{
- numdb_foreach(id_db, func);
-}
-
-/*==========================================
* map.npcへ追加 (warp等の領域持ちのみ)
*------------------------------------------
*/
@@ -1213,7 +1180,7 @@ int map_addnpc(int m, struct npc_data *nd)
map[m].npc[i] = nd;
nd->n = i;
- numdb_insert(id_db, nd->bl.id, nd);
+ id_db.put(nd->bl.id, (struct block_list *)nd);
return i;
}
@@ -1231,7 +1198,7 @@ void map_removenpc(void)
{
clif_clearchar(&map[m].npc[i]->bl, BeingRemoveWhy::QUIT);
map_delblock(&map[m].npc[i]->bl);
- numdb_erase(id_db, map[m].npc[i]->bl.id);
+ id_db.put(map[m].npc[i]->bl.id, nullptr);
if (map[m].npc[i]->bl.subtype == NpcSubtype::SCRIPT)
{
// free(map[m].npc[i]->u.scr.script);
@@ -1252,7 +1219,7 @@ void map_removenpc(void)
*/
int map_mapname2mapid(const char *name)
{
- struct map_data *md = (struct map_data *)strdb_search(map_db, name);
+ struct map_data *md = map_db.get(name);
if (md == NULL || md->gat == NULL)
return -1;
return md->m;
@@ -1264,7 +1231,7 @@ int map_mapname2mapid(const char *name)
*/
int map_mapname2ipport(const char *name, struct in_addr *ip, int *port)
{
- struct map_data_other_server *mdos = (struct map_data_other_server *)strdb_search(map_db, name);
+ struct map_data_other_server *mdos = (struct map_data_other_server *)map_db.get(name);
if (mdos == NULL || mdos->gat)
return -1;
*ip = mdos->ip;
@@ -1372,22 +1339,23 @@ void map_setcell(int m, int x, int y, MapCell t)
*/
int map_setipport(const char *name, struct in_addr ip, int port)
{
- struct map_data_other_server *mdos = NULL;
-
- struct map_data *md = (struct map_data *)strdb_search(map_db, name);
+ struct map_data *md = map_db.get(name);
if (md == NULL)
- { // not exist -> add new data
+ {
+ struct map_data_other_server *mdos = NULL;
+ // not exist -> add new data
CREATE(mdos, struct map_data_other_server, 1);
memcpy(mdos->name, name, 24);
mdos->gat = NULL;
mdos->ip = ip;
mdos->port = port;
- strdb_insert(map_db, mdos->name, mdos);
+ map_db.put(mdos->name, (struct map_data *)mdos);
}
else
{
if (md->gat)
- { // local -> check data
+ {
+ // local -> check data
if (ip.s_addr != clif_getip().s_addr || port != clif_getport())
{
PRINTF("from char server : %s -> %s:%d\n", name, ip2str(ip),
@@ -1396,7 +1364,9 @@ int map_setipport(const char *name, struct in_addr ip, int port)
}
}
else
- { // update
+ {
+ // update
+ struct map_data_other_server *mdos = NULL;
mdos = (struct map_data_other_server *) md;
mdos->ip = ip;
mdos->port = port;
@@ -1450,7 +1420,7 @@ bool map_readmap(int m, const_string fn)
CREATE(map[m].block_count, int, size);
CREATE(map[m].block_mob_count, int, size);
- strdb_insert(map_db, map[m].name, &map[m]);
+ map_db.put(map[m].name, &map[m]);
return true;
}
@@ -1783,11 +1753,6 @@ void term_func(void)
map_removenpc();
- numdb_final(id_db, NULL);
- strdb_final(map_db, NULL);
- strdb_final(nick_db, NULL);
- numdb_final(charid_db, NULL);
-
for (i = 0; i <= map_num; i++)
{
map[i].gat = nullptr;
@@ -1855,11 +1820,6 @@ int do_init(int argc, char *argv[])
atcommand_config_read(ATCOMMAND_CONF_FILENAME);
script_config_read();
- id_db = numdb_init();
- map_db = strdb_init(16);
- nick_db = strdb_init(24);
- charid_db = numdb_init();
-
map_readallmap();
do_init_chrif ();
diff --git a/src/map/map.hpp b/src/map/map.hpp
index 29680a6..7fb6026 100644
--- a/src/map/map.hpp
+++ b/src/map/map.hpp
@@ -533,7 +533,7 @@ int map_delobjectnofree(int id, BL type);
void map_foreachobject(std::function<void(struct block_list *)>,
BL);
//
-int map_quit(struct map_session_data *);
+void map_quit(struct map_session_data *);
// npc
int map_addnpc(int, struct npc_data *);
@@ -560,8 +560,9 @@ int map_addflooritem(struct item *, int, int, int, int,
struct map_session_data *);
// キャラid=>キャラ名 変換関連
+extern
+DMap<int, struct block_list *> id_db;
void map_addchariddb(int charid, const char *name);
-int map_reqchariddb(struct map_session_data *sd, int charid);
char *map_charid2nick(int);
struct map_session_data *map_id2sd(int);
@@ -571,7 +572,6 @@ int map_mapname2ipport(const char *, struct in_addr *, int *);
int map_setipport(const char *name, struct in_addr ip, int port);
void map_addiddb(struct block_list *);
void map_deliddb(struct block_list *bl);
-void map_foreachiddb(db_func_t);
void map_addnickdb(struct map_session_data *);
int map_scriptcont(struct map_session_data *sd, int id); /* Continues a script either on a spell or on an NPC */
struct map_session_data *map_nick2sd(const char *);
diff --git a/src/map/mob.cpp b/src/map/mob.cpp
index 79a21ea..709df2b 100644
--- a/src/map/mob.cpp
+++ b/src/map/mob.cpp
@@ -2094,17 +2094,14 @@ void mob_ai_hard(TimerData *, tick_t tick)
*------------------------------------------
*/
static
-void mob_ai_sub_lazy(db_key_t, db_val_t data, tick_t tick)
+void mob_ai_sub_lazy(struct block_list *bl, tick_t tick)
{
- struct mob_data *md = (struct mob_data *)data;
-
- nullpo_retv(md);
+ nullpo_retv(bl);
- if (md == NULL)
+ if (bl->type != BL::MOB)
return;
- if (md->bl.type == BL::NUL || md->bl.type != BL::MOB)
- return;
+ struct mob_data *md = (struct mob_data *)bl;
if (tick < md->last_thinktime + MIN_MOBTHINKTIME * 10)
return;
@@ -2161,7 +2158,8 @@ void mob_ai_sub_lazy(db_key_t, db_val_t data, tick_t tick)
static
void mob_ai_lazy(TimerData *, tick_t tick)
{
- map_foreachiddb(std::bind(mob_ai_sub_lazy, ph::_1, ph::_2, tick));
+ for (auto& pair : id_db)
+ mob_ai_sub_lazy(pair.second, tick);
}
/*==========================================
diff --git a/src/map/npc.cpp b/src/map/npc.cpp
index b65c263..f0cacb9 100644
--- a/src/map/npc.cpp
+++ b/src/map/npc.cpp
@@ -40,17 +40,17 @@ int npc_get_new_npc_id(void)
return npc_id++;
}
-static
-struct dbt *ev_db;
-static
-struct dbt *npcname_db;
-
struct event_data
{
struct npc_data *nd;
int pos;
};
static
+Map<std::string, struct event_data> ev_db;
+static
+DMap<std::string, struct npc_data *> npcname_db;
+
+static
struct tm ev_tm_b; // 時計イベント用
/*==========================================
@@ -84,7 +84,7 @@ void npc_enable_sub(struct block_list *bl, struct npc_data *nd)
int npc_enable(const char *name, bool flag)
{
- struct npc_data *nd = (struct npc_data *)strdb_search(npcname_db, name);
+ struct npc_data *nd = npcname_db.get(name);
if (nd == NULL)
return 0;
@@ -112,7 +112,7 @@ int npc_enable(const char *name, bool flag)
*/
struct npc_data *npc_name2id(const char *name)
{
- return (struct npc_data *)strdb_search(npcname_db, name);
+ return npcname_db.get(name);
}
/*==========================================
@@ -157,7 +157,7 @@ int npc_delete(struct npc_data *nd)
int npc_timer_event(const char *eventname) // Added by RoVeRT
{
- struct event_data *ev = (struct event_data *)strdb_search(ev_db, eventname);
+ struct event_data *ev = ev_db.search(eventname);
struct npc_data *nd;
// int xs,ys;
@@ -177,13 +177,11 @@ int npc_timer_event(const char *eventname) // Added by RoVeRT
*------------------------------------------
*/
static
-void npc_event_doall_sub(db_key_t key, db_val_t data,
+void npc_event_doall_sub(const std::string& key, struct event_data *ev,
int *c, const char *name, int rid, int argc, argrec_t *argv)
{
- const char *p = key.s;
- struct event_data *ev;
+ const char *p = key.c_str();
- ev = (struct event_data *) data;
nullpo_retv(ev);
if ((p = strchr(p, ':')) && p && strcasecmp(name, p) == 0)
@@ -201,18 +199,17 @@ int npc_event_doall_l(const char *name, int rid, int argc, argrec_t *args)
strncpy(buf + 2, name, sizeof(buf)-3);
buf[sizeof(buf)-1] = '\0';
- strdb_foreach(ev_db, std::bind(npc_event_doall_sub, ph::_1, ph::_2, &c, buf, rid, argc, args));
+ for (auto& pair : ev_db)
+ npc_event_doall_sub(pair.first, &pair.second, &c, buf, rid, argc, args);
return c;
}
static
-void npc_event_do_sub(db_key_t key, db_val_t data,
+void npc_event_do_sub(const std::string& key, struct event_data *ev,
int *c, const char *name, int rid, int argc, argrec_t *argv)
{
- const char *p = key.s;
- struct event_data *ev;
+ const char *p = key.c_str();
- ev = (struct event_data *) data;
nullpo_retv(ev);
if (p && strcasecmp(name, p) == 0)
@@ -232,7 +229,8 @@ int npc_event_do_l(const char *name, int rid, int argc, argrec_t *args)
return npc_event_doall_l(name + 2, rid, argc, args);
}
- strdb_foreach(ev_db, std::bind(npc_event_do_sub, ph::_1, ph::_2, &c, name, rid, argc, args));
+ for (auto& pair : ev_db)
+ npc_event_do_sub(pair.first, &pair.second, &c, name, rid, argc, args);
return c;
}
@@ -408,7 +406,7 @@ int npc_settimerevent_tick(struct npc_data *nd, interval_t newtimer)
int npc_event(struct map_session_data *sd, const char *eventname,
int mob_kill)
{
- struct event_data *ev = (struct event_data *)strdb_search(ev_db, eventname);
+ struct event_data *ev = ev_db.search(eventname);
struct npc_data *nd;
int xs, ys;
char mobevent[100];
@@ -428,7 +426,7 @@ int npc_event(struct map_session_data *sd, const char *eventname,
{
strcpy(mobevent, eventname);
strcat(mobevent, "::OnMyMobDead");
- ev = (struct event_data *)strdb_search(ev_db, mobevent);
+ ev = ev_db.search(mobevent);
if (ev == NULL || (nd = ev->nd) == NULL)
{
if (strncasecmp(eventname, "GM_MONSTER", 10) != 0)
@@ -493,10 +491,9 @@ int npc_event(struct map_session_data *sd, const char *eventname,
}
static
-void npc_command_sub(db_key_t key, db_val_t data, const char *npcname, const char *command)
+void npc_command_sub(const std::string& key, struct event_data *ev, const char *npcname, const char *command)
{
- const char *p = key.s;
- struct event_data *ev = (struct event_data *) data;
+ const char *p = key.c_str();
char temp[100];
if (strcmp(ev->nd->name, npcname) == 0 && (p = strchr(p, ':')) && p
@@ -511,7 +508,8 @@ void npc_command_sub(db_key_t key, db_val_t data, const char *npcname, const cha
int npc_command(struct map_session_data *, const char *npcname, const char *command)
{
- strdb_foreach(ev_db, std::bind(npc_command_sub, ph::_1, ph::_2, npcname, command));
+ for (auto& pair : ev_db)
+ npc_command_sub(pair.first, &pair.second, npcname, command);
return 0;
}
@@ -1031,7 +1029,7 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4)
nd->bl.subtype = NpcSubtype::WARP;
map_addblock(&nd->bl);
clif_spawnnpc(nd);
- strdb_insert(npcname_db, nd->name, nd);
+ npcname_db.put(nd->name, nd);
return 0;
}
@@ -1136,7 +1134,7 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4)
nd->n = map_addnpc(m, nd);
map_addblock(&nd->bl);
clif_spawnnpc(nd);
- strdb_insert(npcname_db, nd->name, nd);
+ npcname_db.put(nd->name, nd);
return 0;
}
@@ -1146,14 +1144,10 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4)
*------------------------------------------
*/
static
-void npc_convertlabel_db(db_key_t key, db_val_t data, struct npc_data *nd)
+void npc_convertlabel_db(const std::string& lname, int pos, struct npc_data *nd)
{
- const char *lname = key.s;
- int pos = (int) data;
struct npc_label_list *lst;
int num;
- // this exists for evil purposes
- char *p = const_cast<char *>(strchr(lname, ':'));
nullpo_retv(nd);
@@ -1169,11 +1163,7 @@ void npc_convertlabel_db(db_key_t key, db_val_t data, struct npc_data *nd)
lst = (struct npc_label_list *)
realloc(lst, sizeof(struct npc_label_list) * (num + 1));
- *p = '\0';
- // temporarily NUL-terminate lname
- strncpy(lst[num].name, lname, sizeof(lst[num].name)-1);
- lst[num].name[sizeof(lst[num].name)-1] = '\0';
- *p = ':';
+ strzcpy(lst[num].name, lname.c_str(), sizeof(lst[num].name));
lst[num].pos = pos;
nd->u.scr.label_list = lst;
nd->u.scr.label_list_num = num + 1;
@@ -1198,7 +1188,6 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
char line[1024];
struct npc_data *nd;
int evflag = 0;
- struct dbt *label_db;
char *p;
struct npc_label_list *label_dup = NULL;
int label_dupnum = 0;
@@ -1392,16 +1381,15 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
if (evflag)
{ // イベント型
- struct event_data *ev =
- (struct event_data *) calloc(1, sizeof(struct event_data));
- ev->nd = nd;
- ev->pos = 0;
- strdb_insert(ev_db, nd->exname, ev);
+ struct event_data ev {};
+ ev.nd = nd;
+ ev.pos = 0;
+ ev_db.insert(nd->exname, ev);
}
else
clif_spawnnpc(nd);
}
- strdb_insert(npcname_db, nd->exname, nd);
+ npcname_db.put(nd->exname, nd);
//-----------------------------------------
// ラベルデータの準備
@@ -1410,8 +1398,8 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
// script本体がある場合の処理
// ラベルデータのコンバート
- label_db = script_get_label_db();
- strdb_foreach(label_db, std::bind(npc_convertlabel_db, ph::_1, ph::_2, nd));
+ for (auto& pair : scriptlabel_db)
+ npc_convertlabel_db(pair.first, pair.second, nd);
// もう使わないのでバッファ解放
free(srcbuf);
@@ -1438,24 +1426,16 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
if ((lname[0] == 'O' || lname[0] == 'o')
&& (lname[1] == 'N' || lname[1] == 'n'))
{
- struct event_data *ev;
- char *buf;
- // エクスポートされる
- ev = (struct event_data *) calloc(1,
- sizeof(struct event_data));
- buf = (char *) calloc(50, sizeof(char));
if (strlen(lname) > 24)
{
PRINTF("npc_parse_script: label name error !\n");
exit(1);
}
- else
- {
- ev->nd = nd;
- ev->pos = pos;
- sprintf(buf, "%s::%s", nd->exname, lname);
- strdb_insert(ev_db, buf, ev);
- }
+ struct event_data ev {};
+ ev.nd = nd;
+ ev.pos = pos;
+ std::string buf = STRPRINTF("%s::%s", nd->exname, lname);
+ ev_db.insert(buf, ev);
}
}
@@ -1516,8 +1496,6 @@ int npc_parse_function(char *, char *, char *w3, char *,
int startline = 0;
char line[1024];
int i;
-// struct dbt *label_db;
- char *p;
// スクリプトの解析
srcbuf = (char *) calloc(srcsize, sizeof(char));
@@ -1563,20 +1541,12 @@ int npc_parse_function(char *, char *, char *w3, char *,
return 1;
}
- p = (char *) calloc(50, sizeof(char));
-
- strncpy(p, w3, 49);
- // db_val_t takes a void *, we do restore safely ...
- ScriptCode *script_ = const_cast<ScriptCode *>(script);
- strdb_insert(script_get_userfunc_db(), p, script_);
-
-// label_db=script_get_label_db();
+ std::string p = w3;
+ userfunc_db.put(p, script);
// もう使わないのでバッファ解放
free(srcbuf);
-// PRINTF("function %s => %p\n",p,script);
-
return 0;
}
@@ -1825,7 +1795,7 @@ struct npc_data *npc_spawn_text(int m, int x, int y,
map_addblock(&retval->bl);
map_addiddb(&retval->bl);
if (retval->name && retval->name[0])
- strdb_insert(npcname_db, retval->name, retval);
+ npcname_db.put(retval->name, retval);
return retval;
}
@@ -1882,13 +1852,6 @@ void npc_free(struct npc_data *nd)
npc_free_internal(nd);
}
-static
-void ev_release(db_key_t key, db_val_t val)
-{
- free(key.ms);
- free(val);
-}
-
/*==========================================
* npc初期化
*------------------------------------------
@@ -1900,11 +1863,6 @@ int do_init_npc(void)
char line[1024];
int m, lines;
- ev_db = strdb_init(24);
- npcname_db = strdb_init(24);
-
- ev_db->release = ev_release;
-
memset(&ev_tm_b, -1, sizeof(ev_tm_b));
for (nsl = npc_src_first; nsl; nsl = nsl->next)
diff --git a/src/map/party.cpp b/src/map/party.cpp
index f6cb84b..277d0c8 100644
--- a/src/map/party.cpp
+++ b/src/map/party.cpp
@@ -21,7 +21,7 @@
constexpr interval_t PARTY_SEND_XYHP_INVERVAL = std::chrono::seconds(1);
static
-struct dbt *party_db;
+Map<int, struct party> party_db;
static
int party_check_conflict(struct map_session_data *sd);
@@ -31,7 +31,6 @@ void party_send_xyhp_timer(TimerData *tid, tick_t tick);
// 初期化
void do_init_party(void)
{
- party_db = numdb_init();
add_timer_interval(gettick() + PARTY_SEND_XYHP_INVERVAL,
party_send_xyhp_timer,
PARTY_SEND_XYHP_INVERVAL);
@@ -40,13 +39,12 @@ void do_init_party(void)
// 検索
struct party *party_search(int party_id)
{
- return (struct party *)numdb_search(party_db, party_id);
+ return party_db.search(party_id);
}
static
-void party_searchname_sub(db_key_t, db_val_t data, const char *str, struct party **dst)
+void party_searchname_sub(struct party *p, const char *str, struct party **dst)
{
- struct party *p = (struct party *) data;
if (strcasecmp(p->name, str) == 0)
*dst = p;
}
@@ -55,7 +53,8 @@ void party_searchname_sub(db_key_t, db_val_t data, const char *str, struct party
struct party *party_searchname(const char *str)
{
struct party *p = NULL;
- numdb_foreach(party_db, std::bind(party_searchname_sub, ph::_1, ph::_2, str, &p));
+ for (auto& pair : party_db)
+ party_searchname_sub(&pair.second, str, &p);
return p;
}
@@ -93,19 +92,18 @@ int party_created(int account_id, int fail, int party_id, const char *name)
/* The party name is valid and not already taken. */
if (!fail)
{
- struct party *p;
sd->status.party_id = party_id;
- if ((p = (struct party *)numdb_search(party_db, party_id)) != NULL)
+ struct party *p = party_db.search(party_id);
+ if (p != NULL)
{
PRINTF("party_created(): ID already exists!\n");
exit(1);
}
- CREATE(p, struct party, 1);
+ p = party_db.init(party_id);
p->party_id = party_id;
memcpy(p->name, name, 24);
- numdb_insert(party_db, party_id, p);
/* The party was created successfully. */
clif_party_created(sd, 0);
@@ -184,15 +182,14 @@ int party_recv_noinfo(int party_id)
// 情報所得
int party_recv_info(const struct party *sp)
{
- struct party *p;
int i;
nullpo_ret(sp);
- if ((p = (struct party *)numdb_search(party_db, sp->party_id)) == NULL)
+ struct party *p = party_db.search(sp->party_id);
+ if (p == NULL)
{
- CREATE(p, struct party, 1);
- numdb_insert(party_db, sp->party_id, p);
+ p = party_db.init(sp->party_id);
// 最初のロードなのでユーザーのチェックを行う
*p = *sp;
@@ -466,7 +463,7 @@ int party_broken(int party_id)
p->member[i].sd->party_sended = 0;
}
}
- numdb_erase(party_db, party_id);
+ party_db.erase(party_id);
return 0;
}
@@ -633,9 +630,8 @@ int party_check_conflict(struct map_session_data *sd)
// 位置やHP通知用
static
-void party_send_xyhp_timer_sub(db_key_t, db_val_t data)
+void party_send_xyhp_timer_sub(struct party *p)
{
- struct party *p = (struct party *) data;
int i;
nullpo_retv(p);
@@ -666,7 +662,8 @@ void party_send_xyhp_timer_sub(db_key_t, db_val_t data)
// 位置やHP通知
void party_send_xyhp_timer(TimerData *, tick_t)
{
- numdb_foreach(party_db, party_send_xyhp_timer_sub);
+ for (auto& pair : party_db)
+ party_send_xyhp_timer_sub(&pair.second);
}
// 位置通知クリア
diff --git a/src/map/script.cpp b/src/map/script.cpp
index e7f957d..a39186e 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -67,30 +67,16 @@ static
int str_hash[16];
static
-struct dbt *mapreg_db = NULL;
+DMap<int, int> mapreg_db;
static
-struct dbt *mapregstr_db = NULL;
+DMap<int, char *> mapregstr_db;
static
int mapreg_dirty = -1;
char mapreg_txt[256] = "save/mapreg.txt";
constexpr std::chrono::milliseconds MAPREG_AUTOSAVE_INTERVAL = std::chrono::seconds(10);
-static
-struct dbt *scriptlabel_db = NULL;
-static
-struct dbt *userfunc_db = NULL;
-
-struct dbt *script_get_label_db(void)
-{
- return scriptlabel_db;
-}
-
-struct dbt *script_get_userfunc_db(void)
-{
- if (!userfunc_db)
- userfunc_db = strdb_init(50);
- return userfunc_db;
-}
+Map<std::string, int> scriptlabel_db;
+DMap<std::string, const ScriptCode *> userfunc_db;
static
const char *pos[11] =
@@ -910,9 +896,7 @@ const ScriptCode *parse_script(const char *src, int line)
}
// 外部用label dbの初期化
- if (scriptlabel_db != NULL)
- strdb_final(scriptlabel_db, NULL);
- scriptlabel_db = strdb_init(50);
+ scriptlabel_db.clear();
// for error message
startptr = src;
@@ -942,7 +926,8 @@ const ScriptCode *parse_script(const char *src, int line)
exit(1);
}
set_label(l, script_pos);
- strdb_insert(scriptlabel_db, p, script_pos); // 外部用label db登録
+ std::string str(p, skip_word(p));
+ scriptlabel_db.insert(str, script_pos);
*tmpp = c;
p = tmpp + 1;
continue;
@@ -1049,8 +1034,7 @@ void get_val(ScriptState *st, struct script_data *data)
}
else if (prefix == '$')
{
- data->u.str =
- (char *) numdb_search(mapregstr_db, data->u.num);
+ data->u.str = mapregstr_db.get(data->u.num);
}
else
{
@@ -1084,7 +1068,7 @@ void get_val(ScriptState *st, struct script_data *data)
}
else if (prefix == '$')
{
- data->u.num = (int) numdb_search(mapreg_db, data->u.num);
+ data->u.num = mapreg_db.get(data->u.num);
}
else if (prefix == '#')
{
@@ -1374,8 +1358,7 @@ void builtin_callfunc(ScriptState *st)
const ScriptCode *scr;
const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
- // note: strdb_search returns a void *; but ScriptCode is really const
- if ((scr = static_cast<const ScriptCode *>(strdb_search(script_get_userfunc_db(), str))))
+ if ((scr = userfunc_db.get(str)))
{
int j = 0;
#if 0
@@ -4889,10 +4872,7 @@ int run_script_l(const ScriptCode *script, int pos_, int rid, int oid,
*/
void mapreg_setreg(int num, int val)
{
- if (val != 0)
- numdb_insert(mapreg_db, num, val);
- else
- numdb_erase(mapreg_db, num);
+ mapreg_db.put(num, val);
mapreg_dirty = 1;
}
@@ -4903,20 +4883,16 @@ void mapreg_setreg(int num, int val)
*/
void mapreg_setregstr(int num, const char *str)
{
- char *p;
-
- if ((p = (char *)numdb_search(mapregstr_db, num)) != NULL)
+ char *p = mapregstr_db.get(num);
+ if (p)
free(p);
- if (str == NULL || *str == 0)
- {
- numdb_erase(mapregstr_db, num);
- mapreg_dirty = 1;
- return;
- }
- p = (char *) calloc(strlen(str) + 1, 1);
- strcpy(p, str);
- numdb_insert(mapregstr_db, num, p);
+ if (!str || !*str)
+ p = NULL;
+ else
+ p = strdup(str);
+
+ mapregstr_db.put(num, p);
mapreg_dirty = 1;
}
@@ -4951,14 +4927,14 @@ void script_load_mapreg(void)
if (buf1.back() == '$')
{
char *p = strdup(buf2.c_str());
- numdb_insert(mapregstr_db, key, p);
+ mapregstr_db.put(key, p);
}
else
{
int v;
if (!extract(buf2, &v))
goto borken;
- numdb_insert(mapreg_db, key, v);
+ mapreg_db.put(key, v);
}
}
else
@@ -4976,30 +4952,30 @@ void script_load_mapreg(void)
*------------------------------------------
*/
static
-void script_save_mapreg_intsub(db_key_t key, db_val_t data, FILE *fp)
+void script_save_mapreg_intsub(int key, int data, FILE *fp)
{
- int num = key.i & 0x00ffffff, i = key.i >> 24;
+ int num = key & 0x00ffffff, i = key >> 24;
char *name = str_buf + str_data[num].str;
if (name[1] != '@')
{
if (i == 0)
- FPRINTF(fp, "%s\t%d\n", name, (int) data);
+ FPRINTF(fp, "%s\t%d\n", name, data);
else
- FPRINTF(fp, "%s,%d\t%d\n", name, i, (int) data);
+ FPRINTF(fp, "%s,%d\t%d\n", name, i, data);
}
}
static
-void script_save_mapreg_strsub(db_key_t key, db_val_t data, FILE *fp)
+void script_save_mapreg_strsub(int key, char *data, FILE *fp)
{
- int num = key.i & 0x00ffffff, i = key.i >> 24;
+ int num = key & 0x00ffffff, i = key >> 24;
char *name = str_buf + str_data[num].str;
if (name[1] != '@')
{
if (i == 0)
- FPRINTF(fp, "%s\t%s\n", name, (char *) data);
+ FPRINTF(fp, "%s\t%s\n", name, data);
else
- FPRINTF(fp, "%s,%d\t%s\n", name, i, (char *) data);
+ FPRINTF(fp, "%s,%d\t%s\n", name, i, data);
}
}
@@ -5011,8 +4987,10 @@ void script_save_mapreg(void)
if ((fp = lock_fopen(mapreg_txt, &lock)) == NULL)
return;
- numdb_foreach(mapreg_db, std::bind(script_save_mapreg_intsub, ph::_1, ph::_2, fp));
- numdb_foreach(mapregstr_db, std::bind(script_save_mapreg_strsub, ph::_1, ph::_2, fp));
+ for (auto& pair : mapreg_db)
+ script_save_mapreg_intsub(pair.first, pair.second, fp);
+ for (auto& pair : mapregstr_db)
+ script_save_mapreg_strsub(pair.first, pair.second, fp);
lock_fclose(fp, mapreg_txt, &lock);
mapreg_dirty = 0;
}
@@ -5040,16 +5018,15 @@ void script_config_read()
*/
static
-void mapregstr_db_final(db_key_t, db_val_t data)
+void mapregstr_db_final(char *data)
{
free(data);
}
static
-void userfunc_db_final(db_key_t key, db_val_t data)
+void userfunc_db_final(const ScriptCode *data)
{
- free(key.ms);
- free(data);
+ free(const_cast<ScriptCode *>(data));
}
void do_final_script(void)
@@ -5065,14 +5042,14 @@ void do_final_script(void)
free(script_buf);
#endif
- if (mapreg_db)
- numdb_final(mapreg_db, NULL);
- if (mapregstr_db)
- strdb_final(mapregstr_db, mapregstr_db_final);
- if (scriptlabel_db)
- strdb_final(scriptlabel_db, NULL);
- if (userfunc_db)
- strdb_final(userfunc_db, userfunc_db_final);
+ mapreg_db.clear();
+ for (auto& pair : mapregstr_db)
+ mapregstr_db_final(pair.second);
+ mapregstr_db.clear();
+ scriptlabel_db.clear();
+ for (auto& pair : userfunc_db)
+ userfunc_db_final(pair.second);
+ userfunc_db.clear();
if (str_data)
free(str_data);
@@ -5086,15 +5063,11 @@ void do_final_script(void)
*/
void do_init_script(void)
{
- mapreg_db = numdb_init();
- mapregstr_db = numdb_init();
script_load_mapreg();
add_timer_interval(gettick() + MAPREG_AUTOSAVE_INTERVAL,
script_autosave_mapreg,
MAPREG_AUTOSAVE_INTERVAL);
-
- scriptlabel_db = strdb_init(50);
}
#define BUILTIN(func, args) \
diff --git a/src/map/script.hpp b/src/map/script.hpp
index e09baf8..352164b 100644
--- a/src/map/script.hpp
+++ b/src/map/script.hpp
@@ -3,6 +3,10 @@
#include <cstdint>
+#include <string>
+
+#include "../common/db.hpp"
+
enum class ScriptCode : uint8_t;
struct script_data
@@ -50,8 +54,10 @@ typedef struct argrec
int run_script_l(const ScriptCode *, int, int, int, int, argrec_t *args);
int run_script(const ScriptCode *, int, int, int);
-struct dbt *script_get_label_db(void);
-struct dbt *script_get_userfunc_db(void);
+extern
+Map<std::string, int> scriptlabel_db;
+extern
+DMap<std::string, const ScriptCode *> userfunc_db;
void script_config_read();
void do_init_script(void);
diff --git a/src/map/storage.cpp b/src/map/storage.cpp
index bcdf8bc..dcd0dd7 100644
--- a/src/map/storage.cpp
+++ b/src/map/storage.cpp
@@ -19,7 +19,7 @@
#include "../poison.hpp"
static
-struct dbt *storage_db;
+Map<int, struct storage> storage_db;
/*==========================================
* 倉庫内アイテムソート
@@ -41,13 +41,6 @@ int storage_comp_item(const void *_i1, const void *_i2)
}
static
-void storage_db_final(db_key_t, db_val_t data)
-{
- struct storage *stor = (struct storage *) data;
- free(stor);
-}
-
-static
void sortage_sortitem(struct storage *stor)
{
nullpo_retv(stor);
@@ -55,31 +48,22 @@ void sortage_sortitem(struct storage *stor)
storage_comp_item);
}
-/*==========================================
- * 初期化とか
- *------------------------------------------
- */
-int do_init_storage(void) // map.c::do_init()から呼ばれる
+void do_init_storage(void)
{
- storage_db = numdb_init();
- return 1;
}
-void do_final_storage(void) // by [MC Cameri]
+void do_final_storage(void)
{
- if (storage_db)
- numdb_final(storage_db, storage_db_final);
+ storage_db.clear();
}
struct storage *account2storage(int account_id)
{
- struct storage *stor =
- (struct storage *) numdb_search(storage_db, account_id);
+ struct storage *stor = storage_db.search(account_id);
if (stor == NULL)
{
- CREATE(stor, struct storage, 1);
+ stor = storage_db.init(account_id);
stor->account_id = account_id;
- numdb_insert(storage_db, stor->account_id, stor);
}
return stor;
}
@@ -87,20 +71,13 @@ struct storage *account2storage(int account_id)
// Just to ask storage, without creation
struct storage *account2storage2(int account_id)
{
- return (struct storage *) numdb_search(storage_db, account_id);
+ return storage_db.search(account_id);
}
static
-int storage_delete(int account_id)
+void storage_delete(int account_id)
{
- struct storage *stor =
- (struct storage *) numdb_search(storage_db, account_id);
- if (stor)
- {
- numdb_erase(storage_db, account_id);
- free(stor);
- }
- return 0;
+ storage_db.erase(account_id);
}
/*==========================================
@@ -109,15 +86,13 @@ int storage_delete(int account_id)
*/
int storage_storageopen(struct map_session_data *sd)
{
- struct storage *stor;
nullpo_ret(sd);
if (sd->state.storage_open)
return 1; //Already open?
- if ((stor =
- (struct storage *) numdb_search(storage_db,
- sd->status.account_id)) == NULL)
+ struct storage *stor = storage_db.search(sd->status.account_id);
+ if (stor == NULL)
{ //Request storage.
intif_request_storage(sd->status.account_id);
return 1;
diff --git a/src/map/storage.hpp b/src/map/storage.hpp
index 9daa446..1974efb 100644
--- a/src/map/storage.hpp
+++ b/src/map/storage.hpp
@@ -8,7 +8,7 @@ int storage_storageopen(struct map_session_data *sd);
int storage_storageadd(struct map_session_data *sd, int index, int amount);
int storage_storageget(struct map_session_data *sd, int index, int amount);
int storage_storageclose(struct map_session_data *sd);
-int do_init_storage(void);
+void do_init_storage(void);
void do_final_storage(void);
struct storage *account2storage(int account_id);
struct storage *account2storage2(int account_id);