summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/birth.cc11
-rw-r--r--src/cave.cc6
-rw-r--r--src/cmd2.cc4
-rw-r--r--src/cmd3.cc2
-rw-r--r--src/cmd4.cc36
-rw-r--r--src/cmd6.cc22
-rw-r--r--src/cmd7.cc4
-rw-r--r--src/dungeon.cc11
-rw-r--r--src/files.cc44
-rw-r--r--src/game_edit_data.hpp6
-rw-r--r--src/generate.cc20
-rw-r--r--src/init1.cc13
-rw-r--r--src/init2.cc31
-rw-r--r--src/loadsave.cc8
-rw-r--r--src/monster2.cc8
-rw-r--r--src/object1.cc70
-rw-r--r--src/object2.cc83
-rw-r--r--src/object_kind_fwd.hpp3
-rw-r--r--src/powers.cc1
-rw-r--r--src/q_rand.cc2
-rw-r--r--src/spells1.cc5
-rw-r--r--src/spells2.cc2
-rw-r--r--src/spells3.cc4
-rw-r--r--src/squelch/condition.cc5
-rw-r--r--src/squeltch.cc3
-rw-r--r--src/store.cc5
-rw-r--r--src/traps.cc3
-rw-r--r--src/util.cc18
-rw-r--r--src/variable.cc10
-rw-r--r--src/variable.hpp3
-rw-r--r--src/wizard2.cc59
-rw-r--r--src/xtra1.cc5
-rw-r--r--src/xtra2.cc7
33 files changed, 323 insertions, 191 deletions
diff --git a/src/birth.cc b/src/birth.cc
index 083fe06c..65f6389e 100644
--- a/src/birth.cc
+++ b/src/birth.cc
@@ -721,6 +721,7 @@ static void player_wipe(void)
{
auto const &d_info = game->edit_data.d_info;
auto &r_info = game->edit_data.r_info;
+ auto &k_info = game->edit_data.k_info;
/* Wipe special levels */
wipe_saved();
@@ -790,18 +791,16 @@ static void player_wipe(void)
}
/* Reset the "objects" */
- for (std::size_t i = 1; i < max_k_idx; i++)
+ for (auto &k_ref: k_info)
{
- object_kind *k_ptr = &k_info[i];
-
/* Reset "tried" */
- k_ptr->tried = FALSE;
+ k_ref.tried = FALSE;
/* Reset "aware" */
- k_ptr->aware = FALSE;
+ k_ref.aware = FALSE;
/* Reset "artifact" */
- k_ptr->artifact = 0;
+ k_ref.artifact = 0;
}
diff --git a/src/cave.cc b/src/cave.cc
index 515a66d3..bb15055b 100644
--- a/src/cave.cc
+++ b/src/cave.cc
@@ -437,6 +437,8 @@ static void image_monster(byte *ap, char *cp)
*/
static void image_object(byte *ap, char *cp)
{
+ auto const &k_info = game->edit_data.k_info;
+
// Cached state which keeps a list of the "live" object_kind entries.
static std::vector<size_t> *instance = nullptr;
@@ -446,7 +448,7 @@ static void image_object(byte *ap, char *cp)
// Create the list of "live" indexes
instance = new std::vector<size_t>();
// Filter all the "live" entries
- for (size_t i = 0; i < max_k_idx; i++)
+ for (size_t i = 0; i < k_info.size(); i++)
{
if (k_info[i].name)
{
@@ -851,6 +853,7 @@ static void map_info(int y, int x, byte *ap, char *cp)
auto const &st_info = game->edit_data.st_info;
auto const &r_info = game->edit_data.r_info;
auto const &f_info = game->edit_data.f_info;
+ auto const &k_info = game->edit_data.k_info;
byte a;
@@ -1281,6 +1284,7 @@ void map_info_default(int y, int x, byte *ap, char *cp)
auto const &st_info = game->edit_data.st_info;
auto const &r_info = game->edit_data.r_info;
auto const &f_info = game->edit_data.f_info;
+ auto const &k_info = game->edit_data.k_info;
byte a;
diff --git a/src/cmd2.cc b/src/cmd2.cc
index 8b409f6b..3bd10c7b 100644
--- a/src/cmd2.cc
+++ b/src/cmd2.cc
@@ -3558,6 +3558,8 @@ void do_cmd_fire(void)
*/
void do_cmd_throw(void)
{
+ auto const &k_info = game->edit_data.k_info;
+
int dir;
s32b special = 0;
@@ -3932,6 +3934,8 @@ void do_cmd_throw(void)
*/
void do_cmd_boomerang(void)
{
+ auto const &k_info = game->edit_data.k_info;
+
int dir;
int j, y, x, ny, nx, ty, tx;
diff --git a/src/cmd3.cc b/src/cmd3.cc
index d65087f8..0010a6ea 100644
--- a/src/cmd3.cc
+++ b/src/cmd3.cc
@@ -557,6 +557,8 @@ void do_cmd_drop(void)
*/
void do_cmd_destroy(void)
{
+ auto const &k_info = game->edit_data.k_info;
+
int old_number;
bool_ force = FALSE;
diff --git a/src/cmd4.cc b/src/cmd4.cc
index e030d452..4ebb73d0 100644
--- a/src/cmd4.cc
+++ b/src/cmd4.cc
@@ -2016,6 +2016,7 @@ void do_cmd_visuals(void)
{
auto &r_info = game->edit_data.r_info;
auto &f_info = game->edit_data.f_info;
+ auto &k_info = game->edit_data.k_info;
int i;
@@ -2166,9 +2167,9 @@ void do_cmd_visuals(void)
fprintf(fff, "# Object attr/char definitions\n\n");
/* Dump objects */
- for (i = 0; i < max_k_idx; i++)
+ for (std::size_t k = 0; k < k_info.size(); k++)
{
- object_kind *k_ptr = &k_info[i];
+ object_kind *k_ptr = &k_info[k];
/* Skip non-entries */
if (!k_ptr->name) continue;
@@ -2177,7 +2178,7 @@ void do_cmd_visuals(void)
fprintf(fff, "# %s\n", k_ptr->name);
/* Dump the object attr/char info */
- fprintf(fff, "K:%d:0x%02X:0x%02X\n\n", i,
+ fprintf(fff, "K:%zu:0x%02X:0x%02X\n\n", k,
(byte)(k_ptr->x_attr), (byte)(k_ptr->x_char));
}
@@ -2346,8 +2347,8 @@ void do_cmd_visuals(void)
if (i == ESCAPE) break;
/* Analyze */
- if (i == 'n') k = (k + max_k_idx + 1) % max_k_idx;
- if (i == 'N') k = (k + max_k_idx - 1) % max_k_idx;
+ if (i == 'n') k = (k + k_info.size() + 1) % k_info.size();
+ if (i == 'N') k = (k + k_info.size() - 1) % k_info.size();
if (i == 'a') k_info[k].x_attr = (ca + 1);
if (i == 'A') k_info[k].x_attr = (ca - 1);
if (i == 'c') k_info[k].x_char = (cc + 1);
@@ -3023,13 +3024,15 @@ void do_cmd_save_screen(void)
*/
void do_cmd_knowledge_artifacts(void)
{
- int i, k, z, x, y;
+ auto const &k_info = game->edit_data.k_info;
+
+ int i, z, x, y;
char base_name[80];
/* Scan the artifacts */
std::unique_ptr<bool_[]> okay(new bool_[max_a_idx]);
- for (k = 0; k < max_a_idx; k++)
+ for (std::size_t k = 0; k < max_a_idx; k++)
{
artifact_type *a_ptr = &a_info[k];
@@ -3046,13 +3049,10 @@ void do_cmd_knowledge_artifacts(void)
okay[k] = TRUE;
}
- std::unique_ptr<bool_[]> okayk(new bool_[max_k_idx]);
- for (k = 0; k < max_k_idx; k++)
+ std::vector<bool_> okayk(k_info.size(), FALSE);
+ for (std::size_t k = 0; k < k_info.size(); k++)
{
- object_kind *k_ptr = &k_info[k];
-
- /* Default */
- okayk[k] = FALSE;
+ auto k_ptr = &k_info[k];
/* Skip "empty" artifacts */
if (!(k_ptr->flags & TR_NORM_ART)) continue;
@@ -3163,7 +3163,7 @@ void do_cmd_knowledge_artifacts(void)
fmt::MemoryWriter w;
/* Scan the artifacts */
- for (k = 0; k < max_a_idx; k++)
+ for (std::size_t k = 0; k < max_a_idx; k++)
{
artifact_type *a_ptr = &a_info[k];
@@ -3206,7 +3206,7 @@ void do_cmd_knowledge_artifacts(void)
w.write(" The {}\n", base_name);
}
- for (k = 0; k < max_k_idx; k++)
+ for (std::size_t k = 0; k < k_info.size(); k++)
{
/* List "dead" ones */
if (!okayk[k]) continue;
@@ -3598,12 +3598,14 @@ static void do_cmd_knowledge_kill_count(void)
*/
static void do_cmd_knowledge_objects(void)
{
+ auto const &k_info = game->edit_data.k_info;
+
fmt::MemoryWriter w;
/* Scan the object kinds */
- for (int k = 1; k < max_k_idx; k++)
+ for (std::size_t k = 1; k < k_info.size(); k++)
{
- object_kind *k_ptr = &k_info[k];
+ auto k_ptr = &k_info[k];
/* Hack -- skip artifacts */
if (k_ptr->flags & (TR_INSTA_ART)) continue;
diff --git a/src/cmd6.cc b/src/cmd6.cc
index 630f1e0e..56dd5cab 100644
--- a/src/cmd6.cc
+++ b/src/cmd6.cc
@@ -983,6 +983,7 @@ static object_filter_t const &item_tester_hook_eatable()
void do_cmd_eat_food(void)
{
auto const &r_info = game->edit_data.r_info;
+ auto const &k_info = game->edit_data.k_info;
int ident, lev, fval = 0;
@@ -2497,6 +2498,8 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2)
*/
void do_cmd_quaff_potion(void)
{
+ auto const &k_info = game->edit_data.k_info;
+
int ident, lev;
/* Get an item */
@@ -2653,14 +2656,14 @@ static void do_cmd_fill_bottle(void)
*/
void do_cmd_drink_fountain(void)
{
+ auto const &k_info = game->edit_data.k_info;
+
cave_type *c_ptr = &cave[p_ptr->py][p_ptr->px];
bool_ ident;
int tval, sval, pval = 0;
- int i;
-
char ch;
@@ -2697,9 +2700,9 @@ void do_cmd_drink_fountain(void)
sval = c_ptr->special - SV_POTION_LAST;
}
- for (i = 0; i < max_k_idx; i++)
+ for (auto const &k_ref: k_info)
{
- object_kind *k_ptr = &k_info[i];
+ auto k_ptr = &k_ref;
if (k_ptr->tval != tval) continue;
if (k_ptr->sval != sval) continue;
@@ -2873,6 +2876,7 @@ static object_filter_t const &item_tester_hook_readable()
void do_cmd_read_scroll(void)
{
auto const &d_info = game->edit_data.d_info;
+ auto const &k_info = game->edit_data.k_info;
auto &r_info = game->edit_data.r_info;
/* Check some conditions */
@@ -4077,14 +4081,14 @@ void zap_combine_rod_tip(object_type *q_ptr, int tip_item)
*/
void do_cmd_zap_rod(void)
{
+ auto const &k_info = game->edit_data.k_info;
+
int item, ident, chance, dir, lev;
int cost;
bool_ require_dir;
- object_kind *tip_ptr;
-
/* Hack -- let perception get aborted */
bool_ use_charge = TRUE;
@@ -4176,7 +4180,7 @@ void do_cmd_zap_rod(void)
ident = FALSE;
/* Extract the item level */
- tip_ptr = &k_info[lookup_kind(TV_ROD, o_ptr->pval)];
+ auto tip_ptr = &k_info[lookup_kind(TV_ROD, o_ptr->pval)];
lev = k_info[lookup_kind(TV_ROD, o_ptr->pval)].level;
/* Base chance of success */
@@ -4846,6 +4850,8 @@ static void activate_valaroma()
*/
void do_cmd_activate(void)
{
+ auto const &k_info = game->edit_data.k_info;
+
int item, lev, chance;
char ch, spell_choice;
@@ -5068,6 +5074,8 @@ void do_cmd_activate(void)
const char *activation_aux(object_type * o_ptr, bool_ doit, int item)
{
+ auto const &k_info = game->edit_data.k_info;
+
int plev = get_skill(SKILL_DEVICE);
int i = 0, ii = 0, ij = 0, k, dir, dummy = 0;
diff --git a/src/cmd7.cc b/src/cmd7.cc
index db496995..85da374c 100644
--- a/src/cmd7.cc
+++ b/src/cmd7.cc
@@ -110,6 +110,8 @@ void mindcraft_info(char *p, int power)
*/
void mimic_info(char *p, int power)
{
+ auto const &k_info = game->edit_data.k_info;
+
int plev = get_skill(SKILL_MIMICRY);
object_type *o_ptr = &p_ptr->inventory[INVEN_OUTER];
@@ -761,6 +763,8 @@ static int get_mimic_chance(int mimic)
void do_cmd_mimic_lore()
{
+ auto const &k_info = game->edit_data.k_info;
+
int fail;
object_type *o_ptr;
diff --git a/src/dungeon.cc b/src/dungeon.cc
index 96ac89cb..1f3f6253 100644
--- a/src/dungeon.cc
+++ b/src/dungeon.cc
@@ -134,7 +134,9 @@ static byte value_check_aux1(object_type const *o_ptr)
static byte value_check_aux1_magic(object_type const *o_ptr)
{
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto const &k_info = game->edit_data.k_info;
+
+ auto k_ptr = &k_info[o_ptr->k_idx];
switch (o_ptr->tval)
@@ -223,7 +225,9 @@ static byte value_check_aux2(object_type const *o_ptr)
static byte value_check_aux2_magic(object_type const *o_ptr)
{
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto const &k_info = game->edit_data.k_info;
+
+ auto k_ptr = &k_info[o_ptr->k_idx];
switch (o_ptr->tval)
@@ -4190,6 +4194,7 @@ static void process_command(void)
static void process_player(void)
{
auto const &f_info = game->edit_data.f_info;
+ auto const &k_info = game->edit_data.k_info;
int i, j;
@@ -4501,7 +4506,7 @@ static void process_player(void)
{
/* Acquire object -- for speed only base items are allowed to shimmer */
object_type *o_ptr = &o_list[i];
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto k_ptr = &k_info[o_ptr->k_idx];
/* Skip dead or carried objects */
if ((!o_ptr->k_idx) || (!o_ptr->ix)) continue;
diff --git a/src/files.cc b/src/files.cc
index 42d1bed3..7ccb0508 100644
--- a/src/files.cc
+++ b/src/files.cc
@@ -221,6 +221,7 @@ errr process_pref_file_aux(char *buf)
auto &re_info = game->edit_data.re_info;
auto &r_info = game->edit_data.r_info;
auto &f_info = game->edit_data.f_info;
+ auto &k_info = game->edit_data.k_info;
int i, j, n1, n2;
@@ -357,13 +358,21 @@ errr process_pref_file_aux(char *buf)
{
if (tokenize(buf + 2, 3, zz, ':', '/') == 3)
{
- object_kind *k_ptr;
- i = (huge)strtol(zz[0], NULL, 0);
+ std::size_t i = strtoul(zz[0], NULL, 0);
n1 = strtol(zz[1], NULL, 0);
n2 = strtol(zz[2], NULL, 0);
- if (i >= max_k_idx) return (1);
- k_ptr = &k_info[i];
- if (n1) k_ptr->x_attr = n1;
+
+ if (i >= k_info.size())
+ {
+ return (1);
+ }
+
+ auto k_ptr = &k_info[i];
+
+ if (n1)
+ {
+ k_ptr->x_attr = n1;
+ }
if (n2)
{
k_ptr->x_char = n2;
@@ -435,16 +444,23 @@ errr process_pref_file_aux(char *buf)
{
if (tokenize(buf + 2, 3, zz, ':', '/') == 3)
{
- j = (huge)strtol(zz[0], NULL, 0);
+ j = strtoul(zz[0], NULL, 0);
n1 = strtol(zz[1], NULL, 0);
n2 = strtol(zz[2], NULL, 0);
- for (i = 1; i < max_k_idx; i++)
+
+ for (auto &k_ref: k_info)
{
- object_kind *k_ptr = &k_info[i];
+ auto k_ptr = &k_ref;
if (k_ptr->tval == j)
{
- if (n1) k_ptr->d_attr = n1;
- if (n2) k_ptr->d_char = n2;
+ if (n1)
+ {
+ k_ref.d_attr = n1;
+ }
+ if (n2)
+ {
+ k_ref.d_char = n2;
+ }
}
}
return (0);
@@ -4058,6 +4074,7 @@ static long total_points(void)
{
auto const &d_info = game->edit_data.d_info;
auto const &r_info = game->edit_data.r_info;
+ auto const &k_info = game->edit_data.k_info;
s16b max_dl = 0;
long temp, Total = 0;
@@ -4106,11 +4123,10 @@ static long total_points(void)
/* Death of a companion is BAD */
temp /= comp_death;
- /* The know objects increase the score */
- /* Scan the object kinds */
- for (std::size_t k = 1; k < max_k_idx; k++)
+ /* The known objects increase the score */
+ for (std::size_t k = 1; k < k_info.size(); k++)
{
- object_kind *k_ptr = &k_info[k];
+ auto k_ptr = &k_info[k];
/* Hack -- skip artifacts */
if (k_ptr->flags & TR_INSTA_ART) continue;
diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp
index 6adb3804..59a74182 100644
--- a/src/game_edit_data.hpp
+++ b/src/game_edit_data.hpp
@@ -6,6 +6,7 @@
#include "hist_type.hpp"
#include "monster_ego.hpp"
#include "monster_race.hpp"
+#include "object_kind.hpp"
#include "owner_type.hpp"
#include "player_class.hpp"
#include "player_race.hpp"
@@ -54,6 +55,11 @@ struct GameEditData {
std::vector<set_type> set_info;
/**
+ * Object kinds
+ */
+ std::vector<object_kind> k_info;
+
+ /**
* Building actions.
*/
std::vector<store_action_type> ba_info;
diff --git a/src/generate.cc b/src/generate.cc
index 6612a888..fb59afe2 100644
--- a/src/generate.cc
+++ b/src/generate.cc
@@ -825,19 +825,28 @@ static void place_altar(int y, int x)
*/
static void place_fountain(int y, int x)
{
+ auto const &k_info = game->edit_data.k_info;
+
cave_type *c_ptr = &cave[y][x];
- int svals[SV_POTION_LAST + SV_POTION2_LAST + 1], maxsval = 0, k;
+ int svals[SV_POTION_LAST + SV_POTION2_LAST + 1];
+ int maxsval = 0;
/* List of usable svals */
- for (k = 1; k < max_k_idx; k++)
+ for (auto const &k_ref: k_info)
{
- object_kind *k_ptr = &k_info[k];
+ auto k_ptr = &k_ref;
if (((k_ptr->tval == TV_POTION) || (k_ptr->tval == TV_POTION2)) &&
(k_ptr->level <= dun_level) && (k_ptr->flags & TR_FOUNTAIN))
{
- if (k_ptr->tval == TV_POTION2) svals[maxsval] = k_ptr->sval + SV_POTION_LAST;
- else svals[maxsval] = k_ptr->sval;
+ if (k_ptr->tval == TV_POTION2)
+ {
+ svals[maxsval] = k_ptr->sval + SV_POTION_LAST;
+ }
+ else
+ {
+ svals[maxsval] = k_ptr->sval;
+ }
maxsval++;
}
}
@@ -7662,6 +7671,7 @@ static bool_ cave_gen(void)
{
auto const &d_info = game->edit_data.d_info;
auto const &r_info = game->edit_data.r_info;
+ auto &k_info = game->edit_data.k_info;
auto d_ptr = &d_info[dungeon_type];
diff --git a/src/init1.cc b/src/init1.cc
index d2fef6a9..89149c8f 100644
--- a/src/init1.cc
+++ b/src/init1.cc
@@ -2300,6 +2300,8 @@ errr init_f_info_txt(FILE *fp)
*/
errr init_k_info_txt(FILE *fp)
{
+ auto &k_info = game->edit_data.k_info;
+
int i;
char buf[1024];
char *s, *t;
@@ -2349,14 +2351,11 @@ errr init_k_info_txt(FILE *fp)
/* Verify information */
if (i <= error_idx) return (4);
- /* Verify information */
- if (i >= max_k_idx) return (2);
-
/* Save the index */
error_idx = i;
/* Point at the "info" */
- k_ptr = &k_info[i];
+ k_ptr = &expand_to_fit_index(k_info, i);
/* Advance and Save the name index */
assert(!k_ptr->name);
@@ -6777,12 +6776,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst
max_real_towns = atoi(zz[1]);
}
- /* Maximum k_idx */
- else if (zz[0][0] == 'K')
- {
- max_k_idx = atoi(zz[1]);
- }
-
/* Maximum a_idx */
else if (zz[0][0] == 'A')
{
diff --git a/src/init2.cc b/src/init2.cc
index 950badc3..73863842 100644
--- a/src/init2.cc
+++ b/src/init2.cc
@@ -293,7 +293,7 @@ namespace {
static void allocate()
{
- k_info = new object_kind[max_k_idx];
+ // Nothing to do
}
static errr parse(FILE *fp)
@@ -723,12 +723,13 @@ static errr init_other(void)
{
auto const &d_info = game->edit_data.d_info;
auto const &r_info = game->edit_data.r_info;
+ auto const &k_info = game->edit_data.k_info;
/*** Prepare the "dungeon" information ***/
/* Allocate and Wipe the special gene flags */
m_allow_special = make_array<bool_>(r_info.size());
- k_allow_special = make_array<bool_>(max_k_idx);
+ k_allow_special = make_array<bool_>(k_info.size());
a_allow_special = make_array<bool_>(max_a_idx);
@@ -804,10 +805,7 @@ static errr init_other(void)
static errr init_alloc(void)
{
auto const &r_info = game->edit_data.r_info;
-
- int i, j;
-
- object_kind *k_ptr;
+ auto const &k_info = game->edit_data.k_info;
alloc_entry *table;
@@ -827,12 +825,12 @@ static errr init_alloc(void)
alloc_kind_size = 0;
/* Scan the objects */
- for (i = 1; i < max_k_idx; i++)
+ for (auto const &k_ref: k_info)
{
- k_ptr = &k_info[i];
+ auto k_ptr = &k_ref;
/* Scan allocation pairs */
- for (j = 0; j < ALLOCATION_MAX; j++)
+ for (std::size_t j = 0; j < ALLOCATION_MAX; j++)
{
/* Count the "legal" entries */
if (k_ptr->chance[j])
@@ -847,7 +845,7 @@ static errr init_alloc(void)
}
/* Collect the level indexes */
- for (i = 1; i < MAX_DEPTH_MONSTER; i++)
+ for (std::size_t i = 1; i < MAX_DEPTH_MONSTER; i++)
{
/* Group by level */
num[i] += num[i - 1];
@@ -866,12 +864,12 @@ static errr init_alloc(void)
table = alloc_kind_table;
/* Scan the objects */
- for (i = 1; i < max_k_idx; i++)
+ for (std::size_t i = 1; i < k_info.size(); i++)
{
- k_ptr = &k_info[i];
+ auto k_ptr = &k_info[i];
/* Scan allocation pairs */
- for (j = 0; j < ALLOCATION_MAX; j++)
+ for (std::size_t j = 0; j < ALLOCATION_MAX; j++)
{
/* Count the "legal" entries */
if (k_ptr->chance[j])
@@ -933,7 +931,7 @@ static errr init_alloc(void)
}
/* Collect the level indexes */
- for (i = 1; i < MAX_DEPTH_MONSTER; i++)
+ for (std::size_t i = 1; i < MAX_DEPTH_MONSTER; i++)
{
/* Group by level */
num[i] += num[i - 1];
@@ -952,7 +950,7 @@ static errr init_alloc(void)
table = alloc_race_table;
/* Scan the monsters */
- for (i = 1; i < r_info.size(); i++)
+ for (std::size_t i = 1; i < r_info.size(); i++)
{
/* Get the i'th race */
auto r_ptr = &r_info[i];
@@ -1019,6 +1017,7 @@ static void init_guardians(void)
{
auto const &d_info = game->edit_data.d_info;
auto &r_info = game->edit_data.r_info;
+ auto &k_info = game->edit_data.k_info;
/* Scan dungeons */
for (std::size_t i = 0; i < d_info.size(); i++)
@@ -1042,7 +1041,7 @@ static void init_guardians(void)
/* Mark the final object */
if (d_ptr->final_object)
{
- object_kind *k_ptr = &k_info[d_ptr->final_object];
+ auto k_ptr = &k_info[d_ptr->final_object];
k_ptr->flags |= TR_SPECIAL_GENE;
}
diff --git a/src/loadsave.cc b/src/loadsave.cc
index 8d05cb43..1329827f 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -1056,6 +1056,8 @@ static bool_ wearable_p(object_type *o_ptr)
*/
static void do_item(object_type *o_ptr, ls_flag_t flag)
{
+ auto &k_info = game->edit_data.k_info;
+
byte old_dd;
byte old_ds;
@@ -2112,11 +2114,13 @@ static bool do_monster_lore(ls_flag_t flag)
*/
static bool do_object_lore(ls_flag_t flag)
{
- u16b n_kinds = max_k_idx;
+ auto &k_info = game->edit_data.k_info;
+
+ u16b n_kinds = k_info.size();
do_u16b(&n_kinds, flag);
- if ((flag == ls_flag_t::LOAD) && (n_kinds > max_k_idx))
+ if ((flag == ls_flag_t::LOAD) && (n_kinds > k_info.size()))
{
note("Too many object kinds!");
return false;
diff --git a/src/monster2.cc b/src/monster2.cc
index dccf47dc..17b5ab9a 100644
--- a/src/monster2.cc
+++ b/src/monster2.cc
@@ -430,6 +430,8 @@ static cptr funny_comments[MAX_COMMENT] =
*/
void delete_monster_idx(int i)
{
+ auto &k_info = game->edit_data.k_info;
+
/* Get location */
monster_type *m_ptr = &m_list[i];
int y = m_ptr->fy;
@@ -1887,6 +1889,8 @@ void update_monsters(bool_ full)
void monster_carry(monster_type *m_ptr, int m_idx, object_type *q_ptr)
{
+ auto &k_info = game->edit_data.k_info;
+
object_type *o_ptr;
/* Get new object */
@@ -1953,8 +1957,10 @@ static int possible_randart[] =
bool_ kind_is_randart(int k_idx)
{
+ auto const &k_info = game->edit_data.k_info;
+
int max;
- object_kind *k_ptr = &k_info[k_idx];
+ auto k_ptr = &k_info[k_idx];
if (!kind_is_legal(k_idx)) return (FALSE);
diff --git a/src/object1.cc b/src/object1.cc
index c10a52f9..42c3f9ff 100644
--- a/src/object1.cc
+++ b/src/object1.cc
@@ -331,14 +331,8 @@ static char scroll_adj[MAX_TITLES][16];
static byte scroll_col[MAX_TITLES];
-/*
- * Certain items have a flavor
- * This function is used only by "flavor_init()"
- */
-static byte object_flavor(int k_idx)
+static byte object_flavor(object_kind const *k_ptr)
{
- object_kind *k_ptr = &k_info[k_idx];
-
/* Analyze the item */
switch (k_ptr->tval)
{
@@ -390,7 +384,7 @@ static byte object_flavor(int k_idx)
}
/* No flavor */
- return (0);
+ return 0;
}
@@ -400,10 +394,8 @@ static byte object_flavor(int k_idx)
*
* XXX XXX XXX Add "EASY_KNOW" flag to "k_info.txt" file
*/
-static bool_ object_easy_know(int i)
+static bool_ object_easy_know(object_kind const *k_ptr)
{
- object_kind *k_ptr = &k_info[i];
-
/* Analyze the "tval" */
switch (k_ptr->tval)
{
@@ -507,6 +499,8 @@ static void shuffle_flavors(cptr adj[], byte col[])
*/
void flavor_init(void)
{
+ auto &k_info = game->edit_data.k_info;
+
/* Hack -- Induce consistant flavors */
set_quick_rng(seed_flavor());
@@ -599,21 +593,24 @@ void flavor_init(void)
set_complex_rng();
/* Analyze every object */
- for (std::size_t i = 1; i < max_k_idx; i++)
+ for (auto &k_ref: k_info)
{
- object_kind *k_ptr = &k_info[i];
+ auto k_ptr = &k_ref;
/* Skip "empty" objects */
if (!k_ptr->name) continue;
/* Extract "flavor" (if any) */
- k_ptr->flavor = object_flavor(i);
+ k_ptr->flavor = object_flavor(k_ptr);
/* No flavor yields aware */
- if ((!k_ptr->flavor) && (k_ptr->tval != TV_ROD_MAIN)) k_ptr->aware = TRUE;
+ if ((!k_ptr->flavor) && (k_ptr->tval != TV_ROD_MAIN))
+ {
+ k_ptr->aware = TRUE;
+ }
/* Check for "easily known" */
- k_ptr->easy_know = object_easy_know(i);
+ k_ptr->easy_know = object_easy_know(k_ptr);
}
}
@@ -638,6 +635,7 @@ void reset_visuals(void)
auto &re_info = game->edit_data.re_info;
auto &r_info = game->edit_data.r_info;
auto &f_info = game->edit_data.f_info;
+ auto &k_info = game->edit_data.k_info;
int i;
@@ -657,13 +655,11 @@ void reset_visuals(void)
}
/* Extract default attr/char code for objects */
- for (i = 0; i < max_k_idx; i++)
+ for (auto &k_ref: k_info)
{
- object_kind *k_ptr = &k_info[i];
-
/* Default attr/char */
- k_ptr->x_attr = k_ptr->d_attr;
- k_ptr->x_char = k_ptr->d_char;
+ k_ref.x_attr = k_ref.d_attr;
+ k_ref.x_char = k_ref.d_char;
}
/* Extract default attr/char code for monsters */
@@ -804,7 +800,9 @@ bool_ object_flags_no_set = FALSE;
*/
object_flag_set object_flags(object_type const *o_ptr)
{
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto const &k_info = game->edit_data.k_info;
+
+ auto k_ptr = &k_info[o_ptr->k_idx];
/* Base object */
auto f = k_ptr->flags;
@@ -834,7 +832,9 @@ object_flag_set object_flags(object_type const *o_ptr)
/* Return object granted power */
int object_power(object_type *o_ptr)
{
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto const &k_info = game->edit_data.k_info;
+
+ auto k_ptr = &k_info[o_ptr->k_idx];
int power = -1;
/* Base object */
@@ -873,7 +873,9 @@ int object_power(object_type *o_ptr)
*/
object_flag_set object_flags_known(object_type const *o_ptr)
{
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto const &k_info = game->edit_data.k_info;
+
+ auto k_ptr = &k_info[o_ptr->k_idx];
/* Must be identified */
if (!object_known_p(o_ptr))
@@ -1018,6 +1020,7 @@ static object_flag_set compute_pval_mask()
static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
{
auto const &r_info = game->edit_data.r_info;
+ auto const &k_info = game->edit_data.k_info;
static auto const TR_PVAL_MASK = compute_pval_mask();
bool_ hack_name = FALSE;
@@ -1027,7 +1030,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
bool_ show_weapon = FALSE;
bool_ show_armour = FALSE;
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto k_ptr = &k_info[o_ptr->k_idx];
/* Extract some flags */
auto const flags = object_flags(o_ptr);
@@ -2104,6 +2107,8 @@ void object_desc(char *buf, object_type const *o_ptr, int pref, int mode)
*/
void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode)
{
+ auto &k_info = game->edit_data.k_info;
+
/* Save the "aware" flag */
bool_ hack_aware = k_info[o_ptr->k_idx].aware;
@@ -2138,6 +2143,8 @@ void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode)
*/
cptr item_activation(object_type *o_ptr, byte num)
{
+ auto const &k_info = game->edit_data.k_info;
+
/* Needed hacks */
static char rspell[2][80];
@@ -2509,6 +2516,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait
{
auto const &set_info = game->edit_data.set_info;
auto const &st_info = game->edit_data.st_info;
+ auto const &k_info = game->edit_data.k_info;
cptr vp[64];
byte vc[64];
@@ -2553,7 +2561,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait
{
if (o_ptr->k_idx && (!trim_down))
{
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto k_ptr = &k_info[o_ptr->k_idx];
text_out_c(TERM_ORANGE, k_ptr->text);
text_out("\n");
@@ -6253,6 +6261,8 @@ static void apply_flags_set(s16b a_idx, s16b set_idx, object_flag_set *f)
byte object_attr(object_type const *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
if (o_ptr->tval == TV_RANDART)
{
return random_artifacts[o_ptr->sval].attr;
@@ -6269,6 +6279,8 @@ byte object_attr(object_type const *o_ptr)
byte object_attr_default(object_type *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
if (o_ptr->tval == TV_RANDART)
{
return random_artifacts[o_ptr->sval].attr;
@@ -6291,6 +6303,8 @@ byte object_attr_default(object_type *o_ptr)
char object_char(object_type const *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
if (k_info[o_ptr->k_idx].flavor)
{
return misc_to_char[k_info[o_ptr->k_idx].flavor];
@@ -6303,6 +6317,8 @@ char object_char(object_type const *o_ptr)
char object_char_default(object_type const *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
if (k_info[o_ptr->k_idx].flavor)
{
return misc_to_char[k_info[o_ptr->k_idx].flavor];
@@ -6318,6 +6334,8 @@ char object_char_default(object_type const *o_ptr)
*/
bool artifact_p(object_type const *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
return
(o_ptr->tval == TV_RANDART) ||
(o_ptr->name1 ? true : false) ||
diff --git a/src/object2.cc b/src/object2.cc
index 901bb854..e812340b 100644
--- a/src/object2.cc
+++ b/src/object2.cc
@@ -240,6 +240,8 @@ static void compact_objects_aux(int i1, int i2)
*/
void compact_objects(int size)
{
+ auto const &k_info = game->edit_data.k_info;
+
int i, y, x, num;
int cur_lev, cur_dis, chance;
@@ -269,7 +271,7 @@ void compact_objects(int size)
{
object_type *o_ptr = &o_list[i];
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto k_ptr = &k_info[o_ptr->k_idx];
/* Skip dead objects */
if (!o_ptr->k_idx) continue;
@@ -377,6 +379,8 @@ void compact_objects(int size)
*/
void wipe_o_list(void)
{
+ auto &k_info = game->edit_data.k_info;
+
int i;
/* Delete the existing objects */
@@ -554,10 +558,11 @@ errr get_obj_num_prep(void)
*/
s16b get_obj_num(int level)
{
+ auto const &k_info = game->edit_data.k_info;
+
int i, j, p;
int k_idx;
long value, total;
- object_kind *k_ptr;
alloc_entry *table = alloc_kind_table;
@@ -589,7 +594,7 @@ s16b get_obj_num(int level)
k_idx = table[i].index;
/* Access the actual kind */
- k_ptr = &k_info[k_idx];
+ auto k_ptr = &k_info[k_idx];
/* Hack -- prevent embedded chests */
if (opening_chest && (k_ptr->tval == TV_CHEST)) continue;
@@ -720,6 +725,8 @@ void object_known(object_type *o_ptr)
*/
bool object_known_p(object_type const *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
return ((o_ptr->ident & (IDENT_KNOWN)) ||
(k_info[o_ptr->k_idx].easy_know && k_info[o_ptr->k_idx].aware));
}
@@ -731,6 +738,8 @@ bool object_known_p(object_type const *o_ptr)
*/
void object_aware(object_type *o_ptr)
{
+ auto &k_info = game->edit_data.k_info;
+
/* Fully aware of the effects */
k_info[o_ptr->k_idx].aware = TRUE;
}
@@ -740,6 +749,8 @@ void object_aware(object_type *o_ptr)
*/
bool object_aware_p(object_type const *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
return k_info[o_ptr->k_idx].aware;
}
@@ -749,6 +760,8 @@ bool object_aware_p(object_type const *o_ptr)
*/
void object_tried(object_type *o_ptr)
{
+ auto &k_info = game->edit_data.k_info;
+
/* Mark it as tried (even if "aware") */
k_info[o_ptr->k_idx].tried = TRUE;
}
@@ -759,6 +772,8 @@ void object_tried(object_type *o_ptr)
*/
bool object_tried_p(object_type const *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
return k_info[o_ptr->k_idx].tried;
}
@@ -770,8 +785,9 @@ bool object_tried_p(object_type const *o_ptr)
static s32b object_value_base(object_type const *o_ptr)
{
auto const &r_info = game->edit_data.r_info;
+ auto const &k_info = game->edit_data.k_info;
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto k_ptr = &k_info[o_ptr->k_idx];
/* Aware item -- use template cost */
if ((object_aware_p(o_ptr)) && (o_ptr->tval != TV_EGG)) return (k_ptr->cost);
@@ -1073,10 +1089,11 @@ s32b flag_cost(object_type const *o_ptr, int plusses)
s32b object_value_real(object_type const *o_ptr)
{
auto const &r_info = game->edit_data.r_info;
+ auto const &k_info = game->edit_data.k_info;
s32b value;
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto k_ptr = &k_info[o_ptr->k_idx];
if (o_ptr->tval == TV_RANDART)
{
@@ -1801,22 +1818,22 @@ void object_absorb(object_type *o_ptr, object_type *j_ptr)
*/
s16b lookup_kind(int tval, int sval)
{
- int k;
+ auto const &k_info = game->edit_data.k_info;
- /* Look for it */
- for (k = 1; k < max_k_idx; k++)
+ for (std::size_t k = 1; k < k_info.size(); k++)
{
- object_kind *k_ptr = &k_info[k];
-
- /* Found a match */
- if ((k_ptr->tval == tval) && (k_ptr->sval == sval)) return (k);
+ auto k_ptr = &k_info[k];
+ if ((k_ptr->tval == tval) && (k_ptr->sval == sval))
+ {
+ return k;
+ }
}
/* Oops */
if (wizard) msg_format("No object (%d,%d)", tval, sval);
/* Oops */
- return (0);
+ return 0;
}
@@ -1856,7 +1873,9 @@ static void init_obj_exp(object_type *o_ptr, object_kind const *k_ptr)
*/
void object_prep(object_type *o_ptr, int k_idx)
{
- object_kind *k_ptr = &k_info[k_idx];
+ auto const &k_info = game->edit_data.k_info;
+
+ auto k_ptr = &k_info[k_idx];
/* Clear the record */
object_wipe(o_ptr);
@@ -2173,6 +2192,8 @@ void random_artifact_resistance(object_type * o_ptr)
*/
static bool_ make_artifact_special(object_type *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
/* No artifacts in the town */
if (!dun_level) return (FALSE);
@@ -2252,6 +2273,8 @@ static bool_ make_artifact_special(object_type *o_ptr)
*/
static bool_ make_artifact(object_type *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
/* No artifacts in the town */
if (!dun_level) return (FALSE);
@@ -2322,8 +2345,10 @@ static bool_ make_artifact(object_type *o_ptr)
*/
static bool_ make_ego_item(object_type *o_ptr, bool_ good)
{
+ auto const &k_info = game->edit_data.k_info;
+
bool_ ret = FALSE;
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto k_ptr = &k_info[o_ptr->k_idx];
if (artifact_p(o_ptr) || o_ptr->name2) return (FALSE);
@@ -3219,9 +3244,10 @@ static int get_stick_max_level(byte tval, int level, int spl)
static void a_m_aux_4(object_type *o_ptr, int level, int power)
{
auto const &r_info = game->edit_data.r_info;
+ auto const &k_info = game->edit_data.k_info;
s32b bonus_lvl, max_lvl;
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto k_ptr = &k_info[o_ptr->k_idx];
/* Very good */
if (power > 1)
@@ -3937,8 +3963,10 @@ void add_random_ego_flag(object_type *o_ptr, ego_flag_set const &fego, bool_ *li
*/
void apply_magic(object_type *o_ptr, int lev, bool_ okay, bool_ good, bool_ great, boost::optional<int> force_power)
{
+ auto &k_info = game->edit_data.k_info;
+
int i, rolls;
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto k_ptr = &k_info[o_ptr->k_idx];
/* Aply luck */
lev += luck( -7, 7);
@@ -4358,9 +4386,11 @@ bool init_match_theme(obj_theme const &theme)
*/
static bool kind_is_theme(obj_theme const *theme, int k_idx)
{
+ auto const &k_info = game->edit_data.k_info;
+
assert(theme != nullptr);
- object_kind *k_ptr = &k_info[k_idx];
+ auto k_ptr = &k_info[k_idx];
s32b prob = 0;
@@ -4551,7 +4581,9 @@ static bool kind_is_theme(obj_theme const *theme, int k_idx)
*/
bool_ kind_is_legal(int k_idx)
{
- object_kind *k_ptr = &k_info[k_idx];
+ auto const &k_info = game->edit_data.k_info;
+
+ auto k_ptr = &k_info[k_idx];
if (!kind_is_theme(match_theme, k_idx)) return FALSE;
@@ -4595,7 +4627,9 @@ bool_ kind_is_legal(int k_idx)
*/
static bool_ kind_is_good(int k_idx)
{
- object_kind *k_ptr = &k_info[k_idx];
+ auto const &k_info = game->edit_data.k_info;
+
+ auto k_ptr = &k_info[k_idx];
if (!kind_is_legal(k_idx)) return FALSE;
@@ -4692,8 +4726,9 @@ static bool_ kind_is_good(int k_idx)
bool_ kind_is_artifactable(int k_idx)
{
auto const &ra_info = game->edit_data.ra_info;
+ auto const &k_info = game->edit_data.k_info;
- object_kind *k_ptr = &k_info[k_idx];
+ auto k_ptr = &k_info[k_idx];
if (kind_is_good(k_idx))
{
// Consider the item artifactable if there is at least one
@@ -4731,6 +4766,8 @@ bool_ kind_is_artifactable(int k_idx)
*/
bool_ make_object(object_type *j_ptr, bool_ good, bool_ great, obj_theme const &theme)
{
+ auto const &k_info = game->edit_data.k_info;
+
int invprob, base;
@@ -4847,6 +4884,7 @@ bool_ make_object(object_type *j_ptr, bool_ good, bool_ great, obj_theme const &
void place_object(int y, int x, bool_ good, bool_ great, int where)
{
auto const &d_info = game->edit_data.d_info;
+ auto &k_info = game->edit_data.k_info;
s16b o_idx;
@@ -4955,6 +4993,8 @@ void place_object(int y, int x, bool_ good, bool_ great, int where)
*/
bool_ make_gold(object_type *j_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
int i;
s32b base;
@@ -5079,6 +5119,7 @@ void place_gold(int y, int x)
s16b drop_near(object_type *j_ptr, int chance, int y, int x)
{
auto const &f_info = game->edit_data.f_info;
+ auto &k_info = game->edit_data.k_info;
int i, k, d, s;
diff --git a/src/object_kind_fwd.hpp b/src/object_kind_fwd.hpp
deleted file mode 100644
index 6d26db9f..00000000
--- a/src/object_kind_fwd.hpp
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-struct object_kind;
diff --git a/src/powers.cc b/src/powers.cc
index 88292e21..b92d7731 100644
--- a/src/powers.cc
+++ b/src/powers.cc
@@ -131,6 +131,7 @@ static bool_ power_chance(power_type *x_ptr)
static void power_activate(int power)
{
auto const &f_info = game->edit_data.f_info;
+ auto const &k_info = game->edit_data.k_info;
s16b plev = p_ptr->lev;
char ch = 0;
diff --git a/src/q_rand.cc b/src/q_rand.cc
index 019f4b71..7a1faa87 100644
--- a/src/q_rand.cc
+++ b/src/q_rand.cc
@@ -218,6 +218,8 @@ bool_ is_randhero(int level)
static void do_get_new_obj(int y, int x)
{
+ auto &k_info = game->edit_data.k_info;
+
object_type *q_ptr[3], forge[3];
int res, i;
diff --git a/src/spells1.cc b/src/spells1.cc
index c11be30b..3eaf0303 100644
--- a/src/spells1.cc
+++ b/src/spells1.cc
@@ -1781,6 +1781,8 @@ typedef int (*inven_func)(object_type *);
*/
static int inven_damage(inven_func typ, int perc)
{
+ auto const &k_info = game->edit_data.k_info;
+
int i, j, k, amt;
object_type *o_ptr;
@@ -1827,7 +1829,7 @@ static int inven_damage(inven_func typ, int perc)
/* Potions smash open */
if (k_info[o_ptr->k_idx].tval == TV_POTION)
- {
+ {
(void)potion_smash_effect(0, p_ptr->py, p_ptr->px, o_ptr->sval);
}
@@ -3816,6 +3818,7 @@ static int raise_ego[MAX_RAISE] =
static bool_ project_o(int who, int r, int y, int x, int dam, int typ)
{
auto const &r_info = game->edit_data.r_info;
+ auto const &k_info = game->edit_data.k_info;
cave_type *c_ptr = &cave[y][x];
diff --git a/src/spells2.cc b/src/spells2.cc
index f918a970..5c1215d0 100644
--- a/src/spells2.cc
+++ b/src/spells2.cc
@@ -3483,6 +3483,8 @@ object_filter_t const &item_tester_hook_recharge()
*/
bool_ recharge(int power)
{
+ auto const &k_info = game->edit_data.k_info;
+
int recharge_strength, recharge_amount;
int lev;
bool_ fail = FALSE;
diff --git a/src/spells3.cc b/src/spells3.cc
index 276cfeec..f64a22bf 100644
--- a/src/spells3.cc
+++ b/src/spells3.cc
@@ -2975,6 +2975,8 @@ static object_filter_t const &udun_object_is_drainable()
casting_result udun_drain()
{
+ auto const &k_info = game->edit_data.k_info;
+
/* Ask for an item */
int item;
if (!get_item(&item,
@@ -2994,7 +2996,7 @@ casting_result udun_drain()
case TV_STAFF:
case TV_WAND:
{
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
+ auto k_ptr = &k_info[o_ptr->k_idx];
/* Generate mana */
increase_mana(o_ptr->pval * k_ptr->level * o_ptr->number);
diff --git a/src/squelch/condition.cc b/src/squelch/condition.cc
index 8715b364..cd7f879c 100644
--- a/src/squelch/condition.cc
+++ b/src/squelch/condition.cc
@@ -878,8 +878,9 @@ void StateCondition::to_json(jsoncons::json &j) const
bool SymbolCondition::is_match(object_type *o_ptr) const
{
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
- return k_ptr->d_char == m_symbol;
+ auto const &k_info = game->edit_data.k_info;
+
+ return k_info[o_ptr->k_idx].d_char == m_symbol;
}
std::shared_ptr<Condition> SymbolCondition::from_json(jsoncons::json const &j)
diff --git a/src/squeltch.cc b/src/squeltch.cc
index eed3bf1b..43f566ea 100644
--- a/src/squeltch.cc
+++ b/src/squeltch.cc
@@ -11,6 +11,7 @@
#include "cave_type.hpp"
#include "files.hpp"
+#include "game.hpp"
#include "loadsave.hpp"
#include "lua_bind.hpp"
#include "object1.hpp"
@@ -58,6 +59,8 @@ static squelch::Automatizer *automatizer = nullptr;
void squeltch_grid(void)
{
+ auto const &k_info = game->edit_data.k_info;
+
if (!automatizer_enabled)
{
return;
diff --git a/src/store.cc b/src/store.cc
index 47d5d943..cdf87d13 100644
--- a/src/store.cc
+++ b/src/store.cc
@@ -1170,7 +1170,9 @@ static int store_tval = 0, store_level = 0;
*/
static bool_ kind_is_storeok(int k_idx)
{
- object_kind *k_ptr = &k_info[k_idx];
+ auto const &k_info = game->edit_data.k_info;
+
+ auto k_ptr = &k_info[k_idx];
if (k_info[k_idx].flags & TR_NORM_ART)
return ( FALSE );
@@ -1199,6 +1201,7 @@ static bool_ kind_is_storeok(int k_idx)
static void store_create(void)
{
auto const &st_info = game->edit_data.st_info;
+ auto const &k_info = game->edit_data.k_info;
int i = 0, tries, level = 0;
diff --git a/src/traps.cc b/src/traps.cc
index f5abe202..0f80f8d6 100644
--- a/src/traps.cc
+++ b/src/traps.cc
@@ -2659,6 +2659,7 @@ bool_ mon_hit_trap_aux_potion(int m_idx, object_type *o_ptr)
bool_ mon_hit_trap(int m_idx)
{
auto const &r_info = game->edit_data.r_info;
+ auto const &k_info = game->edit_data.k_info;
monster_type *m_ptr = &m_list[m_idx];
auto r_ptr = &r_info[m_ptr->r_idx];
@@ -3028,7 +3029,7 @@ bool_ mon_hit_trap(int m_idx)
if (load_o_ptr->tval == TV_ROD_MAIN)
{
/* Extract mana cost of the rod tip */
- object_kind *tip_o_ptr = &k_info[lookup_kind(TV_ROD, load_o_ptr->pval)];
+ auto tip_o_ptr = &k_info[lookup_kind(TV_ROD, load_o_ptr->pval)];
auto const tflags = object_flags(load_o_ptr);
cost = (tflags & TR_CHEAPNESS) ? tip_o_ptr->pval / 2 : tip_o_ptr->pval;
if (cost <= 0) cost = 1;
diff --git a/src/util.cc b/src/util.cc
index 9351dce1..ccc61143 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -3363,18 +3363,20 @@ int test_mego_name(cptr needle)
* returned. Case doesn't matter. -DG-
*/
-int test_item_name(cptr name)
+int test_item_name(cptr needle)
{
- int i;
+ auto const &k_info = game->edit_data.k_info;
- /* Scan the items */
- for (i = 1; i < max_k_idx; i++)
+ for (std::size_t i = 0; i < k_info.size(); i++)
{
- object_kind *k_ptr = &k_info[i];
- /* If name matches, give us the number */
- if (k_ptr->name && iequals(name, k_ptr->name)) return (i);
+ auto const &name = k_info[i].name;
+ if (name && iequals(needle, name))
+ {
+ return i;
+ }
}
- return (0);
+
+ return 0;
}
/*
diff --git a/src/variable.cc b/src/variable.cc
index f8be6224..4275f21f 100644
--- a/src/variable.cc
+++ b/src/variable.cc
@@ -429,11 +429,6 @@ player_spec const *spp_ptr;
/*
- * The object kind arrays
- */
-object_kind *k_info;
-
-/*
* The artifact arrays
*/
artifact_type *a_info;
@@ -569,11 +564,6 @@ s32b get_level_max_stick = -1;
s32b get_level_use_stick = -1;
/*
- * Maximum number of items in k_info.txt
- */
-u16b max_k_idx;
-
-/*
* Maximum number of artifacts in a_info.txt
*/
u16b max_a_idx;
diff --git a/src/variable.hpp b/src/variable.hpp
index 9daaf3d9..430a1a46 100644
--- a/src/variable.hpp
+++ b/src/variable.hpp
@@ -11,7 +11,6 @@
#include "ego_item_type_fwd.hpp"
#include "fate.hpp"
#include "monster_type_fwd.hpp"
-#include "object_kind_fwd.hpp"
#include "object_type_fwd.hpp"
#include "options.hpp"
#include "player_class_fwd.hpp"
@@ -151,7 +150,6 @@ extern player_class const *cp_ptr;
extern player_spec const *spp_ptr;
extern char player_name[32];
extern char player_base[32];
-extern object_kind *k_info;
extern artifact_type *a_info;
extern ego_item_type *e_info;
extern trap_type *t_info;
@@ -166,7 +164,6 @@ extern char *ANGBAND_DIR_DNGN;
extern bool_ (*get_mon_num_hook)(int r_idx);
extern bool_ (*get_mon_num2_hook)(int r_idx);
extern bool_ (*get_obj_num_hook)(int k_idx);
-extern u16b max_k_idx;
extern u16b max_a_idx;
extern u16b max_e_idx;
extern u16b max_o_idx;
diff --git a/src/wizard2.cc b/src/wizard2.cc
index 575b6e72..6665102e 100644
--- a/src/wizard2.cc
+++ b/src/wizard2.cc
@@ -413,6 +413,8 @@ static void do_cmd_wiz_change(void)
*/
static void wiz_display_item(object_type *o_ptr)
{
+ auto const &k_info = game->edit_data.k_info;
+
int i, j = 13;
char buf[256];
@@ -472,12 +474,8 @@ static void wiz_display_item(object_type *o_ptr)
/*
* Strip an "object name" into a buffer
*/
-static void strip_name(char *buf, int k_idx)
+static void strip_name(char *buf, const object_kind *k_ptr)
{
- char *t;
-
- object_kind *k_ptr = &k_info[k_idx];
-
cptr str = k_ptr->name;
@@ -485,6 +483,7 @@ static void strip_name(char *buf, int k_idx)
while ((*str == ' ') || (*str == '&')) str++;
/* Copy useful chars */
+ char *t;
for (t = buf; *str; str++)
{
if (*str != '~') *t++ = *str;
@@ -534,14 +533,14 @@ static void wci_string(cptr string, int num)
*/
static int wiz_create_itemtype(void)
{
- int i, num, max_num;
+ auto const &k_info = game->edit_data.k_info;
+
+ int num, max_num;
int tval;
cptr tval_desc2;
char ch;
- int choice[60];
-
char buf[160];
@@ -580,9 +579,12 @@ static int wiz_create_itemtype(void)
Term_clear();
/* We have to search the whole itemlist. */
- for (num = 0, i = 1; (num < 60) && (i < max_k_idx); i++)
+ std::vector<std::size_t> choice;
+ choice.reserve(60);
+ std::size_t i;
+ for (num = 0, i = 1; (choice.size() < 60) && (i < k_info.size()); i++)
{
- object_kind *k_ptr = &k_info[i];
+ auto k_ptr = &k_info[i];
/* Analyze matching items */
if (k_ptr->tval == tval)
@@ -590,19 +592,19 @@ static int wiz_create_itemtype(void)
/* Hack -- Skip instant artifacts */
if (k_ptr->flags & TR_INSTA_ART) continue;
- /* Acquire the "name" of object "i" */
- strip_name(buf, i);
+ /* Acquire the "name" of object */
+ strip_name(buf, k_ptr);
/* Print it */
wci_string(buf, num);
/* Remember the object index */
- choice[num++] = i;
+ choice.push_back(i);
}
}
/* Me need to know the maximal possible remembered object_index */
- max_num = num;
+ max_num = choice.size();
/* Choose! */
if (!get_com(format("What Kind of %s? ", tval_desc2), &ch)) return (0);
@@ -1208,23 +1210,26 @@ static void wiz_create_item(void)
*/
static void wiz_create_item_2(void)
{
- object_type forge;
- object_type *q_ptr;
- int a_idx;
+ auto const &k_info = game->edit_data.k_info;
+
cptr p = "Number of the object :";
char out_val[80] = "";
if (!get_string(p, out_val, 4)) return;
- a_idx = atoi(out_val);
+ int k_idx = atoi(out_val);
/* Return if failed or out-of-bounds */
- if ((a_idx <= 0) || (a_idx >= max_k_idx)) return;
+ if ((k_idx <= 0) || (k_idx >= static_cast<int>(k_info.size())))
+ {
+ return;
+ }
/* Get local object */
- q_ptr = &forge;
+ object_type forge;
+ auto q_ptr = &forge;
/* Create the item */
- object_prep(q_ptr, a_idx);
+ object_prep(q_ptr, k_idx);
/* Apply magic (no messages, no artifacts) */
apply_magic(q_ptr, dun_level, FALSE, FALSE, FALSE);
@@ -1354,21 +1359,19 @@ static void do_cmd_wiz_jump(void)
*/
static void do_cmd_wiz_learn(void)
{
- int i;
-
- object_type forge;
- object_type *q_ptr;
+ auto const &k_info = game->edit_data.k_info;
/* Scan every object */
- for (i = 1; i < max_k_idx; i++)
+ for (std::size_t i = 0; i < k_info.size(); i++)
{
- object_kind *k_ptr = &k_info[i];
+ auto k_ptr = &k_info[i];
/* Induce awareness */
if (k_ptr->level <= command_arg)
{
/* Get local object */
- q_ptr = &forge;
+ object_type forge;
+ auto q_ptr = &forge;
/* Prepare object */
object_prep(q_ptr, i);
diff --git a/src/xtra1.cc b/src/xtra1.cc
index 80cbe09e..27bdce71 100644
--- a/src/xtra1.cc
+++ b/src/xtra1.cc
@@ -4415,6 +4415,8 @@ static int get_artifact_idx(int level)
/* Chose a fate */
void gain_fate(byte fate)
{
+ auto const &k_info = game->edit_data.k_info;
+
int i;
int level;
@@ -4485,7 +4487,6 @@ void gain_fate(byte fate)
{
while (TRUE)
{
- object_kind *k_ptr;
obj_theme theme;
/* No themes */
@@ -4506,7 +4507,7 @@ void gain_fate(byte fate)
/* Invalidate the cached allocation table */
alloc_kind_table_valid = FALSE;
- k_ptr = &k_info[fates[i].o_idx];
+ auto k_ptr = &k_info[fates[i].o_idx];
if (!(k_ptr->flags & TR_INSTA_ART) && !(k_ptr->flags & TR_NORM_ART)) break;
}
diff --git a/src/xtra2.cc b/src/xtra2.cc
index af25e906..bb757b4f 100644
--- a/src/xtra2.cc
+++ b/src/xtra2.cc
@@ -3900,6 +3900,7 @@ static int target_set_aux(int y, int x, int mode, cptr info)
auto const &st_info = game->edit_data.st_info;
auto const &wf_info = game->edit_data.wf_info;
auto const &f_info = game->edit_data.f_info;
+ auto const &k_info = game->edit_data.k_info;
cave_type *c_ptr = &cave[y][x];
@@ -5004,13 +5005,15 @@ void set_grace(s32b v)
static bool_ test_object_wish(char *name, object_type *o_ptr, object_type *forge, const char *what)
{
+ auto &k_info = game->edit_data.k_info;
+
int i, j, jb, save_aware;
char buf[200];
/* try all objects, this *IS* a very ugly and slow method :( */
- for (i = 0; i < max_k_idx; i++)
+ for (i = 0; i < k_info.size(); i++)
{
- object_kind *k_ptr = &k_info[i];
+ auto k_ptr = &k_info[i];
o_ptr = forge;