summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/map.c108
-rw-r--r--src/map/npc.c92
-rw-r--r--src/map/pc.c5
-rw-r--r--src/map/pc.h1
4 files changed, 118 insertions, 88 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 60d41b84e..9dcf541c1 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1697,24 +1697,24 @@ int map_addnpc(int m,struct npc_data *nd) {
}
void map_removenpc(void) {
- int i,m,n=0;
-
- for(m=0;m<map_num;m++) {
- for(i=0;i<map[m].npc_num && i<MAX_NPC_PER_MAP;i++) {
- if(map[m].npc[i]!=NULL) {
- clif_clearchar_area(&map[m].npc[i]->bl,2);
- map_delblock(&map[m].npc[i]->bl);
- numdb_erase(id_db,map[m].npc[i]->bl.id);
- if(map[m].npc[i]->bl.subtype==SCRIPT) {
-// aFree(map[m].npc[i]->u.scr.script);
-// aFree(map[m].npc[i]->u.scr.label_list);
- }
- aFree(map[m].npc[i]);
- map[m].npc[i] = NULL;
- n++;
- }
- }
- }
+ int i,m,n=0;
+
+ for(m=0;m<map_num;m++) {
+ for(i=0;i<map[m].npc_num && i<MAX_NPC_PER_MAP;i++) {
+ if(map[m].npc[i]!=NULL) {
+ clif_clearchar_area(&map[m].npc[i]->bl,2);
+ map_delblock(&map[m].npc[i]->bl);
+ numdb_erase(id_db,map[m].npc[i]->bl.id);
+ if(map[m].npc[i]->bl.subtype==SCRIPT) {
+ aFree(map[m].npc[i]->u.scr.script);
+ aFree(map[m].npc[i]->u.scr.label_list);
+ }
+ aFree(map[m].npc[i]);
+ map[m].npc[i] = NULL;
+ n++;
+ }
+ }
+ }
sprintf(tmp_output,"Successfully removed and freed from memory '"CL_WHITE"%d"CL_RESET"' NPCs.\n",n);
ShowStatus(tmp_output);
@@ -3097,29 +3097,20 @@ int flush_timer(int tid, unsigned int tick, int id, int data){
return 0;
}
-int id_db_final(void *k,void *d,va_list ap)
+int id_db_final(void *k,void *d,va_list ap) { return 0; }
+int map_db_final(void *k,void *d,va_list ap) { return 0; }
+int nick_db_final(void *k,void *d,va_list ap)
{
- struct mob_data *id;
- nullpo_retr(0, id = (struct mob_data*)d);
- if(id->lootitem)
- aFree(id->lootitem);
- if(id)
- aFree(id);
+ char *p = d;
+ if (p) aFree(p);
return 0;
}
-
-int map_db_final(void *k,void *d,va_list ap)
+int charid_db_final(void *k,void *d,va_list ap)
{
- struct map_data *id;
- nullpo_retr(0, id = (struct map_data*)d);
- if(id->gat)
- aFree(id->gat);
- if(id)
- aFree(id);
+ struct charid2nick *p = d;
+ if (p) aFree(p);
return 0;
}
-int nick_db_final(void *k,void *d,va_list ap){ return 0; }
-int charid_db_final(void *k,void *d,va_list ap){ return 0; }
int cleanup_sub(struct block_list *bl, va_list ap) {
nullpo_retr(0, bl);
@@ -3152,12 +3143,12 @@ int cleanup_sub(struct block_list *bl, va_list ap) {
*------------------------------------------
*/
void do_final(void) {
- int map_id, i;
+ int i;
ShowStatus("Terminating...\n");
- for (map_id = 0; map_id < map_num;map_id++)
- if(map[map_id].m)
- map_foreachinarea(cleanup_sub, map_id, 0, 0, map[map_id].xs, map[map_id].ys, 0, 0);
+ for (i = 0; i < map_num; i++)
+ if(map[i].m)
+ map_foreachinarea(cleanup_sub, i, 0, 0, map[i].xs, map[i].ys, 0, 0);
#ifndef TXT_ONLY
chrif_char_reset_offline();
@@ -3165,38 +3156,35 @@ void do_final(void) {
chrif_flush_fifo();
- for (i = 0; i < fd_max; i++)
- delete_session(i);
-
-#if 0
- map_removenpc();
-
-// do_final_timer(); (we used timer_final() instead)
- timer_final();
-// numdb_final(id_db, id_db_final);
- strdb_final(map_db, map_db_final);
- strdb_final(nick_db, nick_db_final);
- numdb_final(charid_db, charid_db_final);
-
+//#if 0 // why is this here? >_>
do_final_chrif(); // この内部でキャラを全て切断する
+ do_final_npc();
+// map_removenpc();
do_final_script();
do_final_itemdb();
do_final_storage();
do_final_guild();
+ do_final_party();
+ do_final_pc();
do_final_pet();
-/*
- for(i=0;i<map_num;i++){
- if(map[i].gat) {
- aFree(map[i].gat);
- map[i].gat=NULL; //isn't it NULL already o_O?
- }
+
+ for (i=0; i<map_num; i++) {
+ if(map[i].gat) aFree(map[i].gat);
if(map[i].block) aFree(map[i].block);
if(map[i].block_mob) aFree(map[i].block_mob);
if(map[i].block_count) aFree(map[i].block_count);
if(map[i].block_mob_count) aFree(map[i].block_mob_count);
}
-*/
-#endif
+
+// do_final_timer(); (we used timer_final() instead)
+ timer_final();
+ numdb_final(id_db, id_db_final);
+ strdb_final(map_db, map_db_final);
+ strdb_final(nick_db, nick_db_final);
+ numdb_final(charid_db, charid_db_final);
+ exit_dbn();
+
+//#endif
#ifndef TXT_ONLY
map_sql_close();
diff --git a/src/map/npc.c b/src/map/npc.c
index eb3f33ac5..0e158bc77 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -2315,7 +2315,37 @@ static int npc_read_indoors(void)
return 0;
}
+static int npc_unload(struct npc_data *nd)
+{
+ struct chat_data *cd;
+
+ nullpo_retr (0, nd);
+ if (nd->chat_id && (cd=(struct chat_data*)map_id2bl(nd->chat_id))){
+ aFree (cd);
+ cd = NULL;
+ }
+ if (nd->bl.subtype == SCRIPT) {
+ if (nd->u.scr.timer_event)
+ aFree(nd->u.scr.timer_event);
+ if (nd->u.scr.src_id==0) {
+ if(nd->u.scr.script) {
+ aFree(nd->u.scr.script);
+ nd->u.scr.script=NULL;
+ }
+ if (nd->u.scr.label_list) {
+ aFree(nd->u.scr.label_list);
+ nd->u.scr.label_list = NULL;
+ }
+ }
+ }
+ clif_clearchar_area(&nd->bl, 2);
+ map_delblock(&nd->bl);
+ map_deliddb(&nd->bl);
+ aFree(nd);
+ nd = NULL;
+ return 0;
+}
static int ev_db_final(void *key,void *data,va_list ap)
{
aFree(data);
@@ -2328,6 +2358,30 @@ static int npcname_db_final(void *key,void *data,va_list ap)
return 0;
}
/*==========================================
+ *
+ *------------------------------------------
+ */
+int npc_reload(void)
+{
+ struct npc_data *nd;
+ struct block_list *bl;
+ int i;
+
+ if(ev_db)
+ strdb_final(ev_db,ev_db_final);
+ if(npcname_db)
+ strdb_final(npcname_db,npcname_db_final);
+
+ for (i = START_NPC_NUM; i < npc_id; i++) {
+ if((bl = map_id2bl(i)) && bl->type == BL_NPC && (nd = (struct npc_data *)bl))
+ npc_unload(nd);
+ }
+
+ return 0;
+
+
+}
+/*==========================================
* 終了
*------------------------------------------
*/
@@ -2337,7 +2391,6 @@ int do_final_npc(void)
struct block_list *bl;
struct npc_data *nd;
struct mob_data *md;
- struct chat_data *cd;
struct pet_data *pd;
if(ev_db)
@@ -2345,31 +2398,14 @@ int do_final_npc(void)
if(npcname_db)
strdb_final(npcname_db,npcname_db_final);
- for(i=START_NPC_NUM;i<npc_id;i++){
- if((bl=map_id2bl(i))){
+ npc_clearsrcfile();
+
+ for (i = START_NPC_NUM; i < npc_id; i++){
+ if((bl = map_id2bl(i))){
if(bl->type == BL_NPC && (nd = (struct npc_data *)bl)){
- if(nd->chat_id && (cd=(struct chat_data*)map_id2bl(nd->chat_id))){
- aFree(cd);
- cd = NULL;
- }
- if(nd->bl.subtype == SCRIPT){
- if(nd->u.scr.timer_event)
- aFree(nd->u.scr.timer_event);
- if(nd->u.scr.src_id==0){
- if(nd->u.scr.script){
- aFree(nd->u.scr.script);
- nd->u.scr.script=NULL;
- }
- if(nd->u.scr.label_list){
- aFree(nd->u.scr.label_list);
- nd->u.scr.label_list = NULL;
- }
- }
- }
- aFree(nd);
- nd = NULL;
- }else if(bl->type == BL_MOB && (md = (struct mob_data *)bl)){
- if(md->lootitem){
+ npc_unload(nd);
+ }else if (bl->type == BL_MOB && (md = (struct mob_data *)bl)){
+ if (md->lootitem){
aFree(md->lootitem);
md->lootitem = NULL;
}
@@ -2415,10 +2451,10 @@ int do_init_npc(void)
// comparing only the first 24 chars of labels that are 50 chars long isn't that nice
// will cause "duplicated" labels where actually no dup is...
//ev_db=strdb_init(24);
- ev_db=strdb_init(51);
- npcname_db=strdb_init(24);
+ ev_db = strdb_init(51);
+ npcname_db = strdb_init(24);
- ev_db->release = ev_release;
+ ev_db->release = ev_release;
memset(&ev_tm_b,-1,sizeof(ev_tm_b));
diff --git a/src/map/pc.c b/src/map/pc.c
index 07e712dbe..8c0857d4b 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -7234,6 +7234,11 @@ int pc_readdb(void)
* pc? 係初期化
*------------------------------------------
*/
+void do_final_pc(void) {
+ if (gm_account)
+ aFree(gm_account);
+ return;
+}
int do_init_pc(void) {
pc_readdb();
diff --git a/src/map/pc.h b/src/map/pc.h
index 242ae3147..8c4f96529 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -202,6 +202,7 @@ int pc_delspiritball(struct map_session_data *sd,int,int);
int pc_eventtimer(int tid,unsigned int tick,int id,int data); // for npc_dequeue
int do_init_pc(void);
+void do_final_pc(void);
enum {ADDITEM_EXIST,ADDITEM_NEW,ADDITEM_OVERAMOUNT};