summaryrefslogtreecommitdiff
path: root/src/melee2.cc
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2015-06-12 06:27:05 +0200
committerBardur Arantsson <bardur@scientician.net>2015-08-01 17:26:10 +0200
commitc6196b25d119a10e79deedef26a73e0d5a021b0e (patch)
tree199f5bff5cf363787eb610caa495fd3682a463ed /src/melee2.cc
parent000f6272f8ab1d43ec6300fb5972f7813ada1c88 (diff)
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.
Diffstat (limited to 'src/melee2.cc')
-rw-r--r--src/melee2.cc19
1 files changed, 6 insertions, 13 deletions
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);
}
}