summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game_edit_data.hpp9
-rw-r--r--src/generate.cc20
-rw-r--r--src/init1.cc42
-rw-r--r--src/init2.cc2
-rw-r--r--src/variable.cc10
-rw-r--r--src/variable.hpp3
-rw-r--r--src/vault_type_fwd.hpp3
7 files changed, 45 insertions, 44 deletions
diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp
index e05f6d60..7dea2610 100644
--- a/src/game_edit_data.hpp
+++ b/src/game_edit_data.hpp
@@ -1,9 +1,18 @@
#pragma once
+#include "vault_type.hpp"
+
+#include <vector>
+
/**
* Game edit data, i.e. the parsed contents of the edit .txt
* files.
*/
struct GameEditData {
+ /**
+ * Vaults
+ */
+ std::vector<vault_type> v_info;
+
};
diff --git a/src/generate.cc b/src/generate.cc
index 752b0f53..3f6d64c0 100644
--- a/src/generate.cc
+++ b/src/generate.cc
@@ -3744,8 +3744,10 @@ static void build_vault(int yval, int xval, int ymax, int xmax, std::string cons
*/
static void build_type7(int by0, int bx0)
{
- vault_type *v_ptr = NULL;
- int dummy = 0, xval, yval;
+ auto const &v_info = game->edit_data.v_info;
+
+ auto v_ptr(v_info.end());
+ int dummy = 0;
/* Pick a lesser vault */
while (dummy < SAFE_MAX_ATTEMPTS)
@@ -3753,13 +3755,15 @@ static void build_type7(int by0, int bx0)
dummy++;
/* Access a random vault record */
- v_ptr = &v_info[rand_int(max_v_idx)];
+ v_ptr = uniform_element(v_info);
/* Accept the first lesser vault */
if (v_ptr->typ == 7) break;
}
/* Try to allocate space for room. If fails, exit */
+ int xval;
+ int yval;
if (!room_alloc(v_ptr->wid, v_ptr->hgt, FALSE, by0, bx0, &xval, &yval))
{
if (options->cheat_room)
@@ -3806,8 +3810,10 @@ static void build_type7(int by0, int bx0)
*/
static void build_type8(int by0, int bx0)
{
- vault_type *v_ptr = NULL;
- int dummy = 0, xval, yval;
+ auto const &v_info = game->edit_data.v_info;
+
+ auto v_ptr(v_info.end());
+ int dummy = 0;
/* Pick a lesser vault */
while (dummy < SAFE_MAX_ATTEMPTS)
@@ -3815,13 +3821,15 @@ static void build_type8(int by0, int bx0)
dummy++;
/* Access a random vault record */
- v_ptr = &v_info[rand_int(max_v_idx)];
+ v_ptr = uniform_element(v_info);
/* Accept the first greater vault */
if (v_ptr->typ == 8) break;
}
/* Try to allocate space for room. If fails, exit */
+ int xval;
+ int yval;
if (!room_alloc(v_ptr->wid, v_ptr->hgt, FALSE, by0, bx0, &xval, &yval))
{
if (options->cheat_room)
diff --git a/src/init1.cc b/src/init1.cc
index 012537ce..08cc80a0 100644
--- a/src/init1.cc
+++ b/src/init1.cc
@@ -51,7 +51,6 @@
#include "util.h"
#include "variable.h"
#include "variable.hpp"
-#include "vault_type.hpp"
#include "wilderness_type_info.hpp"
#include "z-rand.hpp"
@@ -61,6 +60,20 @@ using boost::algorithm::iequals;
using boost::algorithm::ends_with;
+/**
+ * Expand vector such that it has room for an item at index i.
+ * If the vector is already large enough, nothing happens.
+ */
+template <class T> typename std::vector<T>::reference expand_to_fit_index(std::vector<T> &v, std::size_t i)
+{
+ if (v.size() < i + 1)
+ {
+ v.resize(i + 1);
+ }
+ return v[i];
+}
+
+
/*
* This file is used to initialize various variables and arrays for the
* Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
@@ -1950,12 +1963,12 @@ errr init_player_info_txt(FILE *fp)
*/
errr init_v_info_txt(FILE *fp)
{
- int i;
char buf[1024];
- char *s;
+
+ auto &v_info = game->edit_data.v_info;
/* Current entry */
- vault_type *v_ptr = NULL;
+ vault_type *v_ptr = nullptr;
/* Just before the first record */
error_idx = -1;
@@ -1980,7 +1993,7 @@ errr init_v_info_txt(FILE *fp)
if (buf[0] == 'N')
{
/* Find the colon before the name */
- s = strchr(buf + 2, ':');
+ char *s = strchr(buf + 2, ':');
/* Verify that colon */
if (!s) return (1);
@@ -1992,23 +2005,16 @@ errr init_v_info_txt(FILE *fp)
if (!*s) return (1);
/* Get the index */
- i = atoi(buf + 2);
+ int i = atoi(buf + 2);
/* Verify information */
if (i <= error_idx) return (4);
- /* Verify information */
- if (i >= max_v_idx) return (2);
-
/* Save the index */
error_idx = i;
/* Point at the "info" */
- v_ptr = &v_info[i];
-
- /* Initialize data -- we ignore the name, it's not
- * used for anything */
- v_ptr->data = my_strdup("");
+ v_ptr = &expand_to_fit_index(v_info, i);
/* Next... */
continue;
@@ -2021,7 +2027,7 @@ errr init_v_info_txt(FILE *fp)
if (buf[0] == 'D')
{
/* Acquire the text */
- s = buf + 2;
+ cptr s = buf + 2;
/* Append data */
v_ptr->data += s;
@@ -7001,12 +7007,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst
max_k_idx = atoi(zz[1]);
}
- /* Maximum v_idx */
- else if (zz[0][0] == 'V')
- {
- max_v_idx = atoi(zz[1]);
- }
-
/* Maximum f_idx */
else if (zz[0][0] == 'F')
{
diff --git a/src/init2.cc b/src/init2.cc
index 1438ed60..de810fc0 100644
--- a/src/init2.cc
+++ b/src/init2.cc
@@ -536,7 +536,7 @@ namespace {
static void allocate()
{
- v_info = new vault_type[max_v_idx];
+ // Nothing to do
}
static errr parse(FILE *fp)
diff --git a/src/variable.cc b/src/variable.cc
index 777c2b17..33f9694e 100644
--- a/src/variable.cc
+++ b/src/variable.cc
@@ -431,11 +431,6 @@ player_spec *spp_ptr;
/*
- * The vault generation arrays
- */
-vault_type *v_info;
-
-/*
* The terrain feature arrays
*/
feature_type *f_info;
@@ -679,11 +674,6 @@ u16b max_re_idx;
u16b max_k_idx;
/*
- * Maximum number of vaults in v_info.txt
- */
-u16b max_v_idx;
-
-/*
* Maximum number of terrain features in f_info.txt
*/
u16b max_f_idx;
diff --git a/src/variable.hpp b/src/variable.hpp
index b04f3140..f3b4c351 100644
--- a/src/variable.hpp
+++ b/src/variable.hpp
@@ -43,7 +43,6 @@
#include "timer_type_fwd.hpp"
#include "town_type_fwd.hpp"
#include "trap_type_fwd.hpp"
-#include "vault_type_fwd.hpp"
#include "wilderness_type_info_fwd.hpp"
#include "seed.hpp"
@@ -171,7 +170,6 @@ extern char player_base[32];
extern ability_type *ab_info;
extern skill_type *s_info;
extern skill_descriptor *s_descriptors;
-extern vault_type *v_info;
extern feature_type *f_info;
extern object_kind *k_info;
extern artifact_type *a_info;
@@ -207,7 +205,6 @@ extern u16b max_s_idx;
extern u16b max_r_idx;
extern u16b max_re_idx;
extern u16b max_k_idx;
-extern u16b max_v_idx;
extern u16b max_f_idx;
extern u16b max_a_idx;
extern u16b max_e_idx;
diff --git a/src/vault_type_fwd.hpp b/src/vault_type_fwd.hpp
deleted file mode 100644
index 25ffd8cc..00000000
--- a/src/vault_type_fwd.hpp
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-struct vault_type;