From c25b265c056a4512b0fb0e1789927e6c4b7b32cf Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move t_info into GameEditData --- lib/edit/misc.txt | 3 --- lib/mods/theme/edit/misc.txt | 3 --- src/birth.cc | 9 ++++++--- src/cave.cc | 2 ++ src/cmd1.cc | 2 ++ src/cmd2.cc | 7 ++++++- src/cmd4.cc | 6 ++++-- src/files.cc | 19 ++++++++++++++----- src/game_edit_data.hpp | 6 ++++++ src/init1.cc | 13 +++---------- src/init2.cc | 2 +- src/loadsave.cc | 6 ++++-- src/object1.cc | 12 +++++------- src/spells1.cc | 1 + src/trap_type_fwd.hpp | 3 --- src/traps.cc | 20 +++++++++++--------- src/variable.cc | 10 ---------- src/variable.hpp | 3 --- src/xtra2.cc | 1 + 19 files changed, 66 insertions(+), 62 deletions(-) delete mode 100644 src/trap_type_fwd.hpp diff --git a/lib/edit/misc.txt b/lib/edit/misc.txt index 8d4b16e1..06a9fcce 100644 --- a/lib/edit/misc.txt +++ b/lib/edit/misc.txt @@ -12,9 +12,6 @@ M:X:101 # Maximum y size of the wilderness M:Y:66 -# Maximum number of trap types in tr_info.txt -M:U:176 - # Maximum size for "o_list[]" M:O:1024 diff --git a/lib/mods/theme/edit/misc.txt b/lib/mods/theme/edit/misc.txt index c90546ef..07261ba3 100644 --- a/lib/mods/theme/edit/misc.txt +++ b/lib/mods/theme/edit/misc.txt @@ -12,9 +12,6 @@ M:X:101 # Maximum y size of the wilderness M:Y:66 -# Maximum number of trap types in tr_info.txt -M:U:176 - # Maximum size for "o_list[]" M:O:1024 diff --git a/src/birth.cc b/src/birth.cc index 63560757..b18a4b9a 100644 --- a/src/birth.cc +++ b/src/birth.cc @@ -723,6 +723,7 @@ static void player_wipe(void) auto &r_info = game->edit_data.r_info; auto &k_info = game->edit_data.k_info; auto &a_info = game->edit_data.a_info; + auto &t_info = game->edit_data.t_info; /* Wipe special levels */ wipe_saved(); @@ -882,10 +883,10 @@ static void player_wipe(void) } /* Wipe the known traps list */ - for (std::size_t i = 0; i < max_t_idx; i++) + for (auto &t_ref: t_info) { - t_info[i].known = 0; - t_info[i].ident = FALSE; + t_ref.known = 0; + t_ref.ident = FALSE; } /* Reset wild_mode to FALSE */ @@ -985,6 +986,8 @@ static void player_outfit_spellbook(cptr spell_name) */ static void player_outfit(void) { + auto &t_info = game->edit_data.t_info; + // Shorthand names for convenience cptr class_name = spp_ptr->title; auto const &subrace_name = rmp_ptr->title; diff --git a/src/cave.cc b/src/cave.cc index bb15055b..14046eb2 100644 --- a/src/cave.cc +++ b/src/cave.cc @@ -854,6 +854,7 @@ static void map_info(int y, int x, byte *ap, char *cp) 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; + auto const &t_info = game->edit_data.t_info; byte a; @@ -1285,6 +1286,7 @@ void map_info_default(int y, int x, byte *ap, char *cp) 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; + auto const &t_info = game->edit_data.t_info; byte a; diff --git a/src/cmd1.cc b/src/cmd1.cc index 726916c4..6f8a26e3 100644 --- a/src/cmd1.cc +++ b/src/cmd1.cc @@ -539,6 +539,8 @@ void carry(int pickup) */ static void hit_trap(void) { + auto &t_info = game->edit_data.t_info; + bool_ ident = FALSE; cave_type *c_ptr; diff --git a/src/cmd2.cc b/src/cmd2.cc index 3bd10c7b..e4378699 100644 --- a/src/cmd2.cc +++ b/src/cmd2.cc @@ -733,6 +733,8 @@ static void chest_death(int y, int x, s16b o_idx) */ static void chest_trap(int y, int x, s16b o_idx) { + auto &t_info = game->edit_data.t_info; + int trap; object_type *o_ptr = &o_list[o_idx]; @@ -1846,13 +1848,15 @@ void do_cmd_tunnel(void) */ static bool_ do_cmd_disarm_chest(int y, int x, s16b o_idx) { + auto const &t_info = game->edit_data.t_info; + int i, j; bool_ more = FALSE; object_type *o_ptr = &o_list[o_idx]; - trap_type *t_ptr = &t_info[o_ptr->pval]; + auto t_ptr = &t_info[o_ptr->pval]; /* Take a turn */ @@ -1924,6 +1928,7 @@ static bool_ do_cmd_disarm_chest(int y, int x, s16b o_idx) static bool_ do_cmd_disarm_aux(int y, int x, int dir, int do_pickup) { auto const &f_info = game->edit_data.f_info; + auto const &t_info = game->edit_data.t_info; int i, j, power; diff --git a/src/cmd4.cc b/src/cmd4.cc index 26794840..8d1b0079 100644 --- a/src/cmd4.cc +++ b/src/cmd4.cc @@ -3242,12 +3242,14 @@ void do_cmd_knowledge_artifacts(void) */ void do_cmd_knowledge_traps(void) { + auto const &t_info = game->edit_data.t_info; + fmt::MemoryWriter w; /* Scan the traps */ - for (int k = 0; k < max_t_idx; k++) + for (auto const &t_ref: t_info) { /* Get the trap */ - trap_type *t_ptr = &t_info[k]; + auto t_ptr = &t_ref; /* Skip "empty" traps */ if (!t_ptr->name) continue; diff --git a/src/files.cc b/src/files.cc index 7ccb0508..91ead001 100644 --- a/src/files.cc +++ b/src/files.cc @@ -222,6 +222,7 @@ errr process_pref_file_aux(char *buf) auto &r_info = game->edit_data.r_info; auto &f_info = game->edit_data.f_info; auto &k_info = game->edit_data.k_info; + auto &t_info = game->edit_data.t_info; int i, j, n1, n2; @@ -336,13 +337,21 @@ errr process_pref_file_aux(char *buf) { if (tokenize(buf + 4, 3, zz, ':', '/') == 3) { - trap_type *t_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_t_idx) return (1); - t_ptr = &t_info[i]; - if (n1) t_ptr->g_attr = n1; + + if (i >= t_info.size()) + { + return 1; + } + + auto t_ptr = &t_info[i]; + + if (n1) + { + t_ptr->g_attr = n1; + } if (n2) { t_ptr->g_char = n2; diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp index cc3af2dc..cd0a0b6b 100644 --- a/src/game_edit_data.hpp +++ b/src/game_edit_data.hpp @@ -19,6 +19,7 @@ #include "skill_descriptor.hpp" #include "store_action_type.hpp" #include "store_info_type.hpp" +#include "trap_type.hpp" #include "vault_type.hpp" #include "wilderness_type_info.hpp" @@ -141,4 +142,9 @@ struct GameEditData { */ std::vector ab_info; + /** + * Traps + */ + std::vector t_info; + }; diff --git a/src/init1.cc b/src/init1.cc index 185548ea..105aadda 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4836,6 +4836,8 @@ static errr grab_one_trap_type_flag(trap_type *t_ptr, cptr what) */ errr init_t_info_txt(FILE *fp) { + auto &t_info = game->edit_data.t_info; + int i; char buf[1024]; char *s, *t; @@ -4882,14 +4884,11 @@ errr init_t_info_txt(FILE *fp) /* Verify information */ if (i <= error_idx) return (4); - /* Verify information */ - if (i >= max_t_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - t_ptr = &t_info[i]; + t_ptr = &expand_to_fit_index(t_info, i); /* Copy name */ t_ptr->name = my_strdup(s); @@ -6786,12 +6785,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_m_idx = atoi(zz[1]); } - /* Maximum tr_idx */ - else if (zz[0][0] == 'U') - { - max_t_idx = atoi(zz[1]); - } - /* Maximum wilderness x size */ else if (zz[0][0] == 'X') { diff --git a/src/init2.cc b/src/init2.cc index ad2bed62..9590633e 100644 --- a/src/init2.cc +++ b/src/init2.cc @@ -517,7 +517,7 @@ namespace { static void allocate() { - t_info = make_array(max_t_idx); + // Nothing to do } static errr parse(FILE *fp) diff --git a/src/loadsave.cc b/src/loadsave.cc index d9dfe452..f412cc52 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -2382,11 +2382,13 @@ static bool do_fates(ls_flag_t flag) static bool do_traps(ls_flag_t flag) { - u16b n_traps = max_t_idx; + auto &t_info = game->edit_data.t_info; + + u16b n_traps = t_info.size(); do_u16b(&n_traps, flag); - if ((flag == ls_flag_t::LOAD) && (n_traps > max_t_idx)) + if ((flag == ls_flag_t::LOAD) && (n_traps > t_info.size())) { note("Too many traps!"); return false; diff --git a/src/object1.cc b/src/object1.cc index 3c7da36e..d04c7ab2 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -636,8 +636,7 @@ void reset_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; + auto &t_info = game->edit_data.t_info; /* Extract some info about terrain features */ for (auto &f_ref: f_info) @@ -687,13 +686,11 @@ void reset_visuals(void) } /* Reset attr/char code for trap overlay graphics */ - for (i = 0; i < max_t_idx; i++) + for (auto &t_ref: t_info) { - trap_type *t_ptr = &t_info[i]; - /* Default attr/char */ - t_ptr->g_attr = 0; - t_ptr->g_char = 0; + t_ref.g_attr = 0; + t_ref.g_char = 0; } @@ -1036,6 +1033,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; auto const &e_info = game->edit_data.e_info; + auto const &t_info = game->edit_data.t_info; static auto const TR_PVAL_MASK = compute_pval_mask(); bool_ hack_name = FALSE; diff --git a/src/spells1.cc b/src/spells1.cc index 3eaf0303..e2a66184 100644 --- a/src/spells1.cc +++ b/src/spells1.cc @@ -6918,6 +6918,7 @@ static bool_ project_p(int who, int r, int y, int x, int dam, int typ, int a_rad auto const &d_info = game->edit_data.d_info; auto const &r_info = game->edit_data.r_info; auto const &f_info = game->edit_data.f_info; + auto const &t_info = game->edit_data.t_info; int k = 0, do_move = 0, a = 0, b = 0, x1 = 0, y1 = 0; diff --git a/src/trap_type_fwd.hpp b/src/trap_type_fwd.hpp deleted file mode 100644 index 480edfef..00000000 --- a/src/trap_type_fwd.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -struct trap_type; diff --git a/src/traps.cc b/src/traps.cc index ccc84aea..a646d221 100644 --- a/src/traps.cc +++ b/src/traps.cc @@ -449,7 +449,9 @@ static bool_ player_handle_missile_trap(s16b num, s16b tval, s16b sval, s16b dd, */ static bool_ player_handle_breath_trap(s16b rad, s16b type, u16b trap) { - trap_type *t_ptr = &t_info[trap]; + auto const &t_info = game->edit_data.t_info; + + auto t_ptr = &t_info[trap]; bool_ ident; s16b my_dd, my_ds, dam; @@ -1906,6 +1908,7 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item) void player_activate_door_trap(s16b y, s16b x) { auto const &f_info = game->edit_data.f_info; + auto &t_info = game->edit_data.t_info; cave_type *c_ptr; bool_ ident = FALSE; @@ -1945,9 +1948,8 @@ void place_trap(int y, int x) { auto const &d_info = game->edit_data.d_info; auto const &f_info = game->edit_data.f_info; + auto const &t_info = game->edit_data.t_info; - s16b trap; - trap_type *t_ptr; int cnt; u32b flags; cave_type *c_ptr = &cave[y][x]; @@ -1975,8 +1977,8 @@ void place_trap(int y, int x) cnt = 100; while (cnt--) { - trap = randint(max_t_idx - 1); - t_ptr = &t_info[trap]; + std::size_t trap = rand_int(t_info.size()); + auto t_ptr = &t_info[trap]; /* No traps below their minlevel */ if (t_ptr->minlevel > dun_level) continue; @@ -2025,8 +2027,8 @@ void place_trap_leveled(int y, int x, int lev) */ void place_trap_object(object_type *o_ptr) { - s16b trap; - trap_type *t_ptr; + auto const &t_info = game->edit_data.t_info; + int cnt; /* No traps in town or on first level */ @@ -2041,8 +2043,8 @@ void place_trap_object(object_type *o_ptr) cnt = 100; while (cnt--) { - trap = randint(max_t_idx - 1); - t_ptr = &t_info[trap]; + std::size_t trap = rand_int(t_info.size()); + auto t_ptr = &t_info[trap]; /* no traps below their minlevel */ if (t_ptr->minlevel > dun_level) continue; diff --git a/src/variable.cc b/src/variable.cc index cfb1f7bf..f1d007ff 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -427,11 +427,6 @@ player_race_mod const *rmp_ptr; player_class const *cp_ptr; player_spec const *spp_ptr; - -/* jk */ -/* the trap-arrays */ -trap_type *t_info; - /* * The wilderness features arrays */ @@ -563,11 +558,6 @@ u16b max_o_idx; */ u16b max_m_idx; -/* - * Maximum number of traps in tr_info.txt - */ -u16b max_t_idx; - /* * Flags for initialization */ diff --git a/src/variable.hpp b/src/variable.hpp index 5b40a693..0fba970d 100644 --- a/src/variable.hpp +++ b/src/variable.hpp @@ -24,7 +24,6 @@ #include "skills_defs.hpp" #include "timer_type_fwd.hpp" #include "town_type_fwd.hpp" -#include "trap_type_fwd.hpp" #include "seed.hpp" extern int max_macrotrigger; @@ -148,7 +147,6 @@ extern player_class const *cp_ptr; extern player_spec const *spp_ptr; extern char player_name[32]; extern char player_base[32]; -extern trap_type *t_info; extern int wildc2i[256]; extern cptr DEFAULT_FEAT_TEXT; extern cptr DEFAULT_FEAT_TUNNEL; @@ -162,7 +160,6 @@ extern bool_ (*get_mon_num2_hook)(int r_idx); extern bool_ (*get_obj_num_hook)(int k_idx); extern u16b max_o_idx; extern u16b max_m_idx; -extern u16b max_t_idx; extern int init_flags; extern bool_ ambush_flag; extern bool_ fate_flag; diff --git a/src/xtra2.cc b/src/xtra2.cc index bf39e8ce..890ce975 100644 --- a/src/xtra2.cc +++ b/src/xtra2.cc @@ -3902,6 +3902,7 @@ static int target_set_aux(int y, int x, int mode, cptr 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; + auto const &t_info = game->edit_data.t_info; cave_type *c_ptr = &cave[y][x]; -- cgit v1.2.3