diff options
author | Bardur Arantsson <bardur@scientician.net> | 2015-06-12 06:27:05 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2015-08-01 17:26:10 +0200 |
commit | c6196b25d119a10e79deedef26a73e0d5a021b0e (patch) | |
tree | 199f5bff5cf363787eb610caa495fd3682a463ed /src/monster3.cc | |
parent | 000f6272f8ab1d43ec6300fb5972f7813ada1c88 (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/monster3.cc')
-rw-r--r-- | src/monster3.cc | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/monster3.cc b/src/monster3.cc index 6201f198..e7e8e6da 100644 --- a/src/monster3.cc +++ b/src/monster3.cc @@ -345,12 +345,10 @@ bool_ do_control_walk(void) bool_ do_control_inven(void) { - int monst_list[23]; - if (!p_ptr->control) return FALSE; screen_save(); prt("Carried items", 0, 0); - show_monster_inven(p_ptr->control, monst_list); + (void) show_monster_inven(p_ptr->control); inkey(); screen_load(); return TRUE; @@ -358,24 +356,23 @@ bool_ do_control_inven(void) bool_ do_control_pickup(void) { - int this_o_idx, next_o_idx = 0; + if (!p_ptr->control) return FALSE; + monster_type *m_ptr = &m_list[p_ptr->control]; - cave_type *c_ptr; - bool_ done = FALSE; - if (!p_ptr->control) return FALSE; + cave_type *c_ptr = &cave[m_ptr->fy][m_ptr->fx]; + + /* Copy list of all objects in the grid; we need a + * copy since we're going to be excising objects + * from lists. */ + auto const object_idxs(c_ptr->o_idxs); /* Scan all objects in the grid */ - c_ptr = &cave[m_ptr->fy][m_ptr->fx]; - for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) + bool done = false; + 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; @@ -392,14 +389,19 @@ bool_ do_control_pickup(void) /* Memorize monster */ o_ptr->held_m_idx = p_ptr->control; - /* Build a stack */ - o_ptr->next_o_idx = m_ptr->hold_o_idx; - /* Carry object */ - m_ptr->hold_o_idx = this_o_idx; - done = TRUE; + m_ptr->hold_o_idxs.push_back(this_o_idx); + + /* Picked up at least one object */ + done = true; + } + + /* Feedback */ + if (done) + { + msg_print("You pick up all objects on the floor."); } - if (done) msg_print("You pick up all objects on the floor."); + return TRUE; } |