From 35b0508a652811a3872f13a6a161a01fee6f5d1d Mon Sep 17 00:00:00 2001 From: gumi Date: Sun, 12 Nov 2017 22:14:18 -0500 Subject: re-fix the puppet despawn bug --- src/map/atcommand.cpp | 2 ++ src/map/map.cpp | 8 ++++++-- src/map/npc.cpp | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index a138b72..0b783a0 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -3610,6 +3610,8 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr sd, for (int i = 0; i < m_id->npc_num;) { nd = m_id->npc[i]; + if (nd == nullptr) continue; + switch (nd->dir) { case DIR::S: diff --git a/src/map/map.cpp b/src/map/map.cpp index e7b0da8..3538a59 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -1009,9 +1009,12 @@ dumb_ptr map_id2bl(BlockId id) int map_addnpc(Borrowed m, dumb_ptr nd) { int i; - for (i = 0; i < m->npc_num && i < MAX_NPC_PER_MAP; i++) - if (m->npc[i] == nullptr) + for (i = 0; i < m->npc_num && i < MAX_NPC_PER_MAP; i++) { + if (m->npc[i] == nullptr) { + PRINTF(">>>>>> reusing npc %i\n"_fmt, i); break; + } + } if (i == MAX_NPC_PER_MAP) { if (battle_config.error_log) @@ -1020,6 +1023,7 @@ int map_addnpc(Borrowed m, dumb_ptr nd) } if (i == m->npc_num) { + PRINTF(">>>>>> using new npc %i\n"_fmt, i); m->npc_num++; } diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 2600117..32a5a54 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -675,6 +675,9 @@ int npc_touch_areanpc(dumb_ptr sd, Borrowed m, int for (i = 0; i < m->npc_num; i++) { + if (m->npc[i] == nullptr) + continue; + if (m->npc[i]->flag & 1) continue; @@ -1046,6 +1049,11 @@ void npc_free_internal(dumb_ptr nd_) } if (nd_->name) npcs_by_name.put(nd_->name, nullptr); + + if (nd_->bl_m != borrow(undefined_gat)) { + nd_->bl_m->npc[nd_->n] = nullptr; + } + nd_.delete_(); } -- cgit v1.2.3-60-g2f50