summaryrefslogtreecommitdiff
path: root/src/loadsave.cc
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:15 +0200
committerBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:15 +0200
commit68c4fe1d6494fb6c92d117db170ea39831c16b00 (patch)
treea1e3076da36a3ba4139ced5d20396f2a7803b6eb /src/loadsave.cc
parent0a48c0f1af4b35338d2360f6efa4c467ec60b60d (diff)
Clean up do_stores() in loadsave.cc a little
Diffstat (limited to 'src/loadsave.cc')
-rw-r--r--src/loadsave.cc28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/loadsave.cc b/src/loadsave.cc
index ce7dfdf8..9b963cfd 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -2041,35 +2041,33 @@ static void do_timers(ls_flag_t flag)
*/
static void do_stores(ls_flag_t flag)
{
- u16b real_max = 0;
+ // Indexes for "real" towns.
+ std::vector<byte> reals;
+ reals.reserve(max_towns);
- /* Note that this forbids max_towns from shrinking, but that is fine */
- std::unique_ptr<byte[]> reals(new byte[max_towns]);
-
- /* Find the real towns */
+ // Fill in the "real" towns if necessary.
if (flag == ls_flag_t::SAVE)
{
for (int i = 1; i < max_towns; i++)
{
- if (!(town_info[i].flags & (TOWN_REAL))) continue;
- reals[real_max++] = i;
+ if (!(town_info[i].flags & TOWN_REAL))
+ {
+ continue;
+ }
+ reals.emplace_back(i);
}
}
- do_u16b(&real_max, flag);
- for (int i = 0; i < real_max; i++)
- {
- do_byte(&reals[i], flag);
- }
+
+ // Load/save
+ do_vector(flag, reals, do_byte);
/* Read the stores */
u16b n_stores = max_st_idx;
do_u16b(&n_stores, flag);
assert(n_stores <= max_st_idx);
- for (int i = 0; i < real_max; i++)
+ for (auto const z: reals)
{
- int z = reals[i];
-
if (!town_info[z].stocked)
{
create_stores_stock(z);