From c6196b25d119a10e79deedef26a73e0d5a021b0e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 12 Jun 2015 06:27:05 +0200 Subject: Refactor cave_type and monster_type to use non-intrusive lists We use vectors of object indexes instead of embedding the list within object_type itself. --- src/melee2.cc | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index da37f760..8e5f09cd 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -6934,8 +6934,6 @@ static void process_monster(int m_idx, bool_ is_frien) /* Creature has been allowed move */ if (do_move) { - s16b this_o_idx, next_o_idx = 0; - /* Take a turn */ do_turn = TRUE; @@ -7005,16 +7003,14 @@ static void process_monster(int m_idx, bool_ is_frien) } else { + /* Copy list of objects; we need a copy because we're mutating the list. */ + auto const object_idxs(c_ptr->o_idxs); + /* Scan all objects in the grid */ - for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) + for (auto const this_o_idx: object_idxs) { - object_type * o_ptr; - /* Acquire object */ - o_ptr = &o_list[this_o_idx]; - - /* Acquire next object */ - next_o_idx = o_ptr->next_o_idx; + object_type * o_ptr = &o_list[this_o_idx]; /* Skip gold */ if (o_ptr->tval == TV_GOLD) continue; @@ -7108,11 +7104,8 @@ static void process_monster(int m_idx, bool_ is_frien) /* Memorize monster */ o_ptr->held_m_idx = m_idx; - /* Build a stack */ - o_ptr->next_o_idx = m_ptr->hold_o_idx; - /* Carry object */ - m_ptr->hold_o_idx = this_o_idx; + m_ptr->hold_o_idxs.push_back(this_o_idx); } } -- cgit v1.2.3