diff options
author | Bardur Arantsson <bardur@scientician.net> | 2016-10-05 18:45:08 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2016-10-05 18:45:08 +0200 |
commit | 5f3ce3824f5174608a955703a14595c14d0a577d (patch) | |
tree | b915e818e74b3f84fd38966ccb4664185c3fd28f /src | |
parent | c84490dd6fb5d1e85482c2271e00cb768bae410e (diff) |
Clean up ability_type
Diffstat (limited to 'src')
-rw-r--r-- | src/ability_type.hpp | 42 | ||||
-rw-r--r-- | src/init1.cc | 88 | ||||
-rw-r--r-- | src/skills.cc | 39 |
3 files changed, 52 insertions, 117 deletions
diff --git a/src/ability_type.hpp b/src/ability_type.hpp index 0291e4de..0ec596ba 100644 --- a/src/ability_type.hpp +++ b/src/ability_type.hpp @@ -1,6 +1,7 @@ #pragma once #include <string> +#include <vector> #include "h-basic.h" @@ -9,19 +10,38 @@ */ struct ability_type { - std::string name; /* Name */ - std::string desc; /* Description */ +public: + struct skill_requirement { + s16b skill_idx = 0; + s16b level = 0; + }; - std::string action_desc; /* Action Description */ +public: + std::string name; /* Name */ + std::string desc; /* Description */ - s16b action_mkey; /* Action do to */ + std::string action_desc; /* Action Description */ - s16b cost; /* Skill points cost */ + s16b action_mkey = 0; /* Action do to */ + + s16b cost = 0; /* Skill points cost */ + + std::vector<skill_requirement> need_skills; /* List of prereq skills */ + + s16b stat[6] { }; /* List of prereq stats */ + + std::vector<s16b> need_abilities; /* List of prereq abilities */ + + /** + * Default constructor + */ + ability_type() + { + for (auto &stat_ref: stat) + { + // Requirement is always met unless otherwise specified. + stat_ref = -1; + } + } - /* Prereqs */ - s16b skills[10]; /* List of prereq skills(10 max) */ - s16b skill_levels[10]; /* List of prereq skills(10 max) */ - s16b stat[6]; /* List of prereq stats */ - s16b need_abilities[10]; /* List of prereq abilities(10 max) */ - s16b forbid_abilities[10]; /* List of forbidden abilities(10 max) */ }; diff --git a/src/init1.cc b/src/init1.cc index f9df3c1b..a6376090 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3334,19 +3334,6 @@ errr init_ab_info_txt(FILE *fp) /* Copy name */ ab_ptr->name = s; - /* Init */ - ab_ptr->action_mkey = 0; - 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 (std::size_t z = 0; z < 6; z++) - { - ab_ptr->stat[z] = -1; - } - /* Next... */ continue; } @@ -3415,7 +3402,6 @@ errr init_ab_info_txt(FILE *fp) if (buf[0] == 'k') { char *sec; - s16b level, skill; /* Scan for the values */ if (NULL == (sec = strchr(buf + 2, ':'))) @@ -3426,25 +3412,15 @@ errr init_ab_info_txt(FILE *fp) sec++; if (!*sec) return (1); - level = atoi(buf + 2); - skill = find_skill(sec); - + s16b level = atoi(buf + 2); + s16b skill = find_skill(sec); if (skill == -1) return (1); - std::size_t z; - for (z = 0; z < 10; z++) - { - if (ab_ptr->skills[z] == -1) - { - break; - } - } + ability_type::skill_requirement req; + req.skill_idx = skill; + req.level = level; - if (z < 10) - { - ab_ptr->skills[z] = skill; - ab_ptr->skill_levels[z] = level; - } + ab_ptr->need_skills.emplace_back(req); /* Next... */ continue; @@ -3494,58 +3470,6 @@ errr init_ab_info_txt(FILE *fp) continue; } - /* Process 'E' for "Excluding ability" */ - if (buf[0] == 'E') - { - char *sec; - s16b ab1, ab2; - - /* Scan for the values */ - if (NULL == (sec = strchr(buf + 2, ':'))) - { - return (1); - } - *sec = '\0'; - sec++; - if (!*sec) return (1); - - ab1 = find_ability(buf + 2); - ab2 = find_ability(sec); - - 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 (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 (z < 10) - { - ab_info[ab2].forbid_abilities[z] = ab1; - } - - /* Next... */ - continue; - } - /* Oops */ return (6); } diff --git a/src/skills.cc b/src/skills.cc index d923af65..dc543ed8 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -1462,49 +1462,40 @@ s16b find_ability(cptr name) return ( -1); } -/* Do we meet the requirements */ -static bool_ can_learn_ability(int ab) +/* Do we meet the requirements? */ +static bool can_learn_ability(int ab) { auto const &ab_info = game->edit_data.ab_info; auto ab_ptr = &ab_info[ab]; - int i; if (p_ptr->has_ability(ab)) + { return FALSE; + } if (p_ptr->skill_points < ab_info[ab].cost) + { return FALSE; + } - for (i = 0; i < 10; i++) + for (auto const &need_skill: ab_ptr->need_skills) { - /* Must have skill level */ - if (ab_ptr->skills[i] > -1) + if (get_skill(need_skill.skill_idx) < need_skill.level) { - if (get_skill(ab_ptr->skills[i]) < ab_ptr->skill_levels[i]) - return FALSE; - } - - /* Must have ability */ - if (ab_ptr->need_abilities[i] > -1) - { - if (!p_ptr->has_ability(ab_ptr->need_abilities[i])) - { - return FALSE; - } + return FALSE; } + } - /* Must not have ability */ - if (ab_ptr->forbid_abilities[i] > -1) + for (auto const &need_ability: ab_ptr->need_abilities) + { + if (!p_ptr->has_ability(need_ability)) { - if (p_ptr->has_ability(ab_ptr->forbid_abilities[i])) - { - return FALSE; - } + return FALSE; } } - for (i = 0; i < 6; i++) + for (std::size_t i = 0; i < 6; i++) { /* Must have stat */ if (ab_ptr->stat[i] > -1) |