From dd76070a7d8676a5f13dcc91fc7ed2eb2639d9df Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move ab_info into GameEditData --- lib/edit/misc.txt | 3 -- lib/mods/theme/edit/misc.txt | 3 -- src/ability_type_fwd.hpp | 3 -- src/game_edit_data.hpp | 6 ++++ src/init1.cc | 69 ++++++++++++++++++++++++-------------------- src/init2.cc | 2 +- src/skills.cc | 58 +++++++++++++++++++++++++------------ src/squelch/condition.cc | 5 ++++ src/variable.cc | 10 ------- src/variable.hpp | 3 -- 10 files changed, 89 insertions(+), 73 deletions(-) delete mode 100644 src/ability_type_fwd.hpp diff --git a/lib/edit/misc.txt b/lib/edit/misc.txt index 8bf64864..5f5a4b1d 100644 --- a/lib/edit/misc.txt +++ b/lib/edit/misc.txt @@ -47,6 +47,3 @@ M:M:768 # Maximum number of skills in s_info.txt M:k:60 - -# Maximum number of traits in ab_info.txt -M:b:50 diff --git a/lib/mods/theme/edit/misc.txt b/lib/mods/theme/edit/misc.txt index b4f43f5e..8cbac0ce 100644 --- a/lib/mods/theme/edit/misc.txt +++ b/lib/mods/theme/edit/misc.txt @@ -47,6 +47,3 @@ M:M:768 # Maximum number of skills in s_info.txt M:k:60 - -# Maximum number of traits in ab_info.txt -M:b:50 diff --git a/src/ability_type_fwd.hpp b/src/ability_type_fwd.hpp deleted file mode 100644 index bade8638..00000000 --- a/src/ability_type_fwd.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -struct ability_type; diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp index 7b69ecac..b8463158 100644 --- a/src/game_edit_data.hpp +++ b/src/game_edit_data.hpp @@ -1,5 +1,6 @@ #pragma once +#include "ability_type.hpp" #include "dungeon_info_type.hpp" #include "hist_type.hpp" #include "owner_type.hpp" @@ -87,4 +88,9 @@ struct GameEditData { */ skill_modifiers gen_skill; + /** + * Player abilities. + */ + std::vector ab_info; + }; diff --git a/src/init1.cc b/src/init1.cc index 658cf8e2..977bad9a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3279,9 +3279,9 @@ errr init_s_info_txt(FILE *fp) */ errr init_ab_info_txt(FILE *fp) { - int i, z; + auto &ab_info = game->edit_data.ab_info; + char buf[1024]; - char *s; /* Current entry */ ability_type *ab_ptr = NULL; @@ -3310,7 +3310,7 @@ errr init_ab_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); @@ -3322,16 +3322,13 @@ errr init_ab_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); - - /* Verify information */ - if (i >= max_ab_idx) return (2); + int i = atoi(buf + 2); /* Save the index */ error_idx = i; /* Point at the "info" */ - ab_ptr = &ab_info[i]; + ab_ptr = &expand_to_fit_index(ab_info, i); /* Copy name */ assert(!ab_ptr->name); @@ -3339,13 +3336,13 @@ errr init_ab_info_txt(FILE *fp) /* Init */ ab_ptr->action_mkey = 0; - for (z = 0; z < 10; z++) + for (std::size_t z = 0; z < 10; z++) { ab_ptr->skills[z] = -1; ab_ptr->need_abilities[z] = -1; ab_ptr->forbid_abilities[z] = -1; } - for (z = 0; z < 6; z++) + for (std::size_t z = 0; z < 6; z++) { ab_ptr->stat[z] = -1; } @@ -3361,7 +3358,7 @@ errr init_ab_info_txt(FILE *fp) if (buf[0] == 'D') { /* Acquire the text */ - s = buf + 2; + char const *s = buf + 2; /* Append description */ if (!ab_ptr->desc) @@ -3383,7 +3380,7 @@ errr init_ab_info_txt(FILE *fp) char *txt; /* Acquire the text */ - s = buf + 2; + char *s = buf + 2; if (NULL == (txt = strchr(s, ':'))) return (1); *txt = '\0'; @@ -3438,8 +3435,14 @@ errr init_ab_info_txt(FILE *fp) if (skill == -1) return (1); + std::size_t z; for (z = 0; z < 10; z++) - if (ab_ptr->skills[z] == -1) break; + { + if (ab_ptr->skills[z] == -1) + { + break; + } + } if (z < 10) { @@ -3454,20 +3457,14 @@ errr init_ab_info_txt(FILE *fp) /* Process 'a' for "needed ability" */ if (buf[0] == 'a') { - s16b ab; - - ab = find_ability(buf + 2); - - if (ab == -1) return (1); - - for (z = 0; z < 10; z++) - if (ab_ptr->need_abilities[z] == -1) break; - - if (z < 10) + s16b ab = find_ability(buf + 2); + if (ab == -1) { - ab_ptr->need_abilities[z] = ab; + return (1); } + ab_ptr->need_abilities.push_back(ab); + /* Next... */ continue; } @@ -3521,15 +3518,29 @@ errr init_ab_info_txt(FILE *fp) if ((ab1 == -1) || (ab2 == -1)) return (1); + std::size_t z; + for (z = 0; z < 10; z++) - if (ab_info[ab1].forbid_abilities[z] == -1) break; + { + if (ab_info[ab1].forbid_abilities[z] == -1) + { + break; + } + } + if (z < 10) { ab_info[ab1].forbid_abilities[z] = ab2; } for (z = 0; z < 10; z++) - if (ab_info[ab2].forbid_abilities[z] == -1) break; + { + if (ab_info[ab2].forbid_abilities[z] == -1) + { + break; + } + } + if (z < 10) { ab_info[ab2].forbid_abilities[z] = ab1; @@ -6901,12 +6912,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst if (max_s_idx > MAX_SKILLS) return (1); } - /* Maximum ab_idx */ - else if (zz[0][0] == 'b') - { - max_ab_idx = atoi(zz[1]); - } - /* Maximum k_idx */ else if (zz[0][0] == 'K') { diff --git a/src/init2.cc b/src/init2.cc index 242fd4bb..cf68f4be 100644 --- a/src/init2.cc +++ b/src/init2.cc @@ -358,7 +358,7 @@ namespace { static void allocate() { - ab_info = make_array(max_ab_idx); + // Nothing to do } static errr parse(FILE *fp) diff --git a/src/skills.cc b/src/skills.cc index a1f9f793..cbd07540 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -811,6 +811,8 @@ static void print_skill_batch(const std::vector> &p, int s static int do_cmd_activate_skill_aux() { + auto const &ab_info = game->edit_data.ab_info; + char which; int start = 0; int ret; @@ -845,7 +847,7 @@ static int do_cmd_activate_skill_aux() } } - for (size_t i = 0; i < max_ab_idx; i++) + for (size_t i = 0; i < ab_info.size(); i++) { if (ab_info[i].action_mkey && p_ptr->has_ability(i)) { @@ -955,6 +957,8 @@ static int do_cmd_activate_skill_aux() /* Ask & execute a skill */ void do_cmd_activate_skill() { + auto const &ab_info = game->edit_data.ab_info; + int x_idx; bool_ push = TRUE; @@ -963,26 +967,34 @@ void do_cmd_activate_skill() { push = FALSE; } - else if (!command_arg) x_idx = do_cmd_activate_skill_aux(); + else if (!command_arg) + { + x_idx = do_cmd_activate_skill_aux(); + } else { - int i, j; - x_idx = command_arg; /* Check validity */ + int i; for (i = 1; i < max_s_idx; i++) { if (s_info[i].value && (s_descriptors[i].action_mkey == x_idx)) + { break; + } } - for (j = 0; j < max_ab_idx; j++) + + std::size_t j; + for (j = 0; j < ab_info.size(); j++) { if (p_ptr->has_ability(j) && (ab_info[j].action_mkey == x_idx)) + { break; + } } - if ((j == max_ab_idx) && (i == max_s_idx)) + if ((j == ab_info.size()) && (i == max_s_idx)) { msg_print("Uh?"); return; @@ -1432,10 +1444,9 @@ void do_get_new_skill() */ s16b find_ability(cptr name) { - u16b i; + auto const &ab_info = game->edit_data.ab_info; - /* Scan ability list */ - for (i = 0; i < max_ab_idx; i++) + for (std::size_t i = 0; i < ab_info.size(); i++) { if (ab_info[i].name && streq(ab_info[i].name, name)) { @@ -1450,7 +1461,9 @@ s16b find_ability(cptr name) /* Do we meet the requirements */ static bool_ can_learn_ability(int ab) { - ability_type *ab_ptr = &ab_info[ab]; + auto const &ab_info = game->edit_data.ab_info; + + auto ab_ptr = &ab_info[ab]; int i; if (p_ptr->has_ability(ab)) @@ -1503,6 +1516,8 @@ static bool_ can_learn_ability(int ab) /* Learn an ability */ static void gain_ability(int ab) { + auto const &ab_info = game->edit_data.ab_info; + int wid, hgt; Term_get_size(&wid, &hgt); @@ -1525,8 +1540,10 @@ static void gain_ability(int ab) p_ptr->skill_points -= ab_info[ab].cost; } -static bool compare_abilities(const int ab_idx1, const int ab_idx2) +static bool compare_abilities(std::size_t ab_idx1, std::size_t ab_idx2) { + auto const &ab_info = game->edit_data.ab_info; + return strcmp(ab_info[ab_idx1].name, ab_info[ab_idx2].name) < 0; } @@ -1535,11 +1552,11 @@ static bool compare_abilities(const int ab_idx1, const int ab_idx2) */ void dump_abilities(FILE *fff) { - int i; + auto const &ab_info = game->edit_data.ab_info; // Find all abilities that the player has. - std::vector table; - for (i = 0; i < max_ab_idx; i++) + std::vector table; + for (std::size_t i = 0; i < ab_info.size(); i++) { if (ab_info[i].name && p_ptr->has_ability(i)) { @@ -1569,8 +1586,10 @@ void dump_abilities(FILE *fff) /* * Draw the abilities list */ -static void print_abilities(const std::vector &table, int sel, int start) +static void print_abilities(const std::vector &table, int sel, int start) { + auto const &ab_info = game->edit_data.ab_info; + int i, j; int wid, hgt; cptr keys; @@ -1639,9 +1658,10 @@ static void print_abilities(const std::vector &table, int sel, int start) */ void do_cmd_ability() { + auto const &ab_info = game->edit_data.ab_info; + int sel = 0, start = 0; char c; - int i; int wid, hgt; /* Save the screen */ @@ -1651,8 +1671,8 @@ void do_cmd_ability() Term_clear(); /* Initialise the abilities list */ - std::vector table; - for (i = 0; i < max_ab_idx; i++) + std::vector table; + for (std::size_t i = 0; i < ab_info.size(); i++) { if (ab_info[i].name) { @@ -1770,6 +1790,8 @@ void apply_level_abilities(int level) { auto apply = [level](std::vector const &abilities) -> void { + auto const &ab_info = game->edit_data.ab_info; + for (auto const &a: abilities) { if (a.level == level) diff --git a/src/squelch/condition.cc b/src/squelch/condition.cc index e7429cab..7c01c4cd 100644 --- a/src/squelch/condition.cc +++ b/src/squelch/condition.cc @@ -6,6 +6,7 @@ #include "tome/squelch/cursor.hpp" #include "tome/squelch/tree_printer.hpp" #include "../ability_type.hpp" +#include "../game.hpp" #include "../object1.hpp" #include "../object2.hpp" #include "../object_kind.hpp" @@ -939,6 +940,8 @@ std::shared_ptr AbilityCondition::from_json(jsoncons::json const &j) void AbilityCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t bcol) const { + auto const &ab_info = game->edit_data.ab_info; + cptr ability_s = ab_info[m_ability_idx].name; p->write(ecol, "You have the "); @@ -949,6 +952,8 @@ void AbilityCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_ void AbilityCondition::to_json(jsoncons::json &j) const { + auto const &ab_info = game->edit_data.ab_info; + j["ability"] = ab_info[m_ability_idx].name; } diff --git a/src/variable.cc b/src/variable.cc index 89e0bd5b..a13ee3aa 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -462,11 +462,6 @@ monster_race *r_info; */ monster_ego *re_info; -/* - * Player abilities arrays - */ -ability_type *ab_info; - /* * Player skills arrays */ @@ -604,11 +599,6 @@ s32b get_level_use_stick = -1; */ u16b max_s_idx; -/* - * Maximum number of abilities in ab_info.txt - */ -u16b max_ab_idx; - /* * Maximum number of monsters in r_info.txt */ diff --git a/src/variable.hpp b/src/variable.hpp index 415b0676..2192d2b2 100644 --- a/src/variable.hpp +++ b/src/variable.hpp @@ -1,7 +1,6 @@ #pragma once #include "angband.h" -#include "ability_type_fwd.hpp" #include "alloc_entry_fwd.hpp" #include "artifact_type_fwd.hpp" #include "birther.hpp" @@ -158,7 +157,6 @@ extern player_class const *cp_ptr; extern player_spec const *spp_ptr; extern char player_name[32]; extern char player_base[32]; -extern ability_type *ab_info; extern skill_type *s_info; extern skill_descriptor *s_descriptors; extern feature_type *f_info; @@ -180,7 +178,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_ab_idx; extern u16b max_s_idx; extern u16b max_r_idx; extern u16b max_re_idx; -- cgit v1.2.3