diff options
-rw-r--r-- | src/ability_type.hpp | 8 | ||||
-rw-r--r-- | src/help.cc | 4 | ||||
-rw-r--r-- | src/help.hpp | 2 | ||||
-rw-r--r-- | src/include/tome/squelch/tree_printer.hpp | 4 | ||||
-rw-r--r-- | src/init1.cc | 24 | ||||
-rw-r--r-- | src/skills.cc | 30 | ||||
-rw-r--r-- | src/squelch/condition.cc | 4 | ||||
-rw-r--r-- | src/squelch/tree_printer.cc | 5 |
8 files changed, 44 insertions, 37 deletions
diff --git a/src/ability_type.hpp b/src/ability_type.hpp index 3a2a51ee..0291e4de 100644 --- a/src/ability_type.hpp +++ b/src/ability_type.hpp @@ -1,5 +1,7 @@ #pragma once +#include <string> + #include "h-basic.h" /** @@ -7,10 +9,10 @@ */ struct ability_type { - const char *name; /* Name */ - char *desc; /* Description */ + std::string name; /* Name */ + std::string desc; /* Description */ - const char *action_desc; /* Action Description */ + std::string action_desc; /* Action Description */ s16b action_mkey; /* Action do to */ diff --git a/src/help.cc b/src/help.cc index 1997717e..b74e6584 100644 --- a/src/help.cc +++ b/src/help.cc @@ -734,7 +734,7 @@ void help_skill(cptr skill) show_context_help(find_context_help(skill_table, skill)); } -void help_ability(cptr ability) +void help_ability(std::string const &ability) { - show_context_help(find_context_help(ability_table, ability)); + show_context_help(find_context_help(ability_table, ability.c_str())); } diff --git a/src/help.hpp b/src/help.hpp index 5de6e6c6..eb8c3c98 100644 --- a/src/help.hpp +++ b/src/help.hpp @@ -10,4 +10,4 @@ extern void help_subrace(std::string const &subrace); extern void help_class(std::string const &klass); extern void help_god(cptr god); extern void help_skill(cptr skill); -extern void help_ability(cptr ability); +extern void help_ability(std::string const &ability); diff --git a/src/include/tome/squelch/tree_printer.hpp b/src/include/tome/squelch/tree_printer.hpp index e8ee1e56..c9e79af2 100644 --- a/src/include/tome/squelch/tree_printer.hpp +++ b/src/include/tome/squelch/tree_printer.hpp @@ -3,6 +3,7 @@ #include <boost/noncopyable.hpp> #include <cstdint> +#include <string> namespace squelch { @@ -30,7 +31,8 @@ public: void scroll_right(); - void write(uint8_t color, const char *line); + void write(uint8_t color, const char *); + void write(uint8_t color, std::string const &); private: int m_indent; diff --git a/src/init1.cc b/src/init1.cc index 977bad9a..f9df3c1b 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3329,10 +3329,10 @@ errr init_ab_info_txt(FILE *fp) /* Point at the "info" */ ab_ptr = &expand_to_fit_index(ab_info, i); + assert(ab_ptr->name.empty()); /* Copy name */ - assert(!ab_ptr->name); - ab_ptr->name = my_strdup(s); + ab_ptr->name = s; /* Init */ ab_ptr->action_mkey = 0; @@ -3357,19 +3357,15 @@ errr init_ab_info_txt(FILE *fp) /* Process 'D' for "Description" */ if (buf[0] == 'D') { - /* Acquire the text */ - char const *s = buf + 2; - - /* Append description */ - if (!ab_ptr->desc) - { - ab_ptr->desc = my_strdup(s); - } - else + /* Need newline? */ + if (!ab_ptr->desc.empty()) { - strappend(&ab_ptr->desc, format("\n%s", s)); + ab_ptr->desc += '\n'; } + /* Append */ + ab_ptr->desc += (buf + 2); + /* Next... */ continue; } @@ -3387,8 +3383,8 @@ errr init_ab_info_txt(FILE *fp) txt++; /* Copy name */ - assert(!ab_ptr->action_desc); - ab_ptr->action_desc = my_strdup(txt); + assert(ab_ptr->action_desc.empty()); + ab_ptr->action_desc = txt; /* Set mkey */ ab_ptr->action_mkey = atoi(s); diff --git a/src/skills.cc b/src/skills.cc index cbd07540..d923af65 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -784,7 +784,7 @@ void select_default_melee() /* * Print a batch of skills. */ -static void print_skill_batch(const std::vector<std::tuple<cptr, int>> &p, int start) +static void print_skill_batch(const std::vector<std::tuple<std::string const &, int>> &p, int start) { char buff[80]; int j = 0; @@ -800,7 +800,7 @@ static void print_skill_batch(const std::vector<std::tuple<cptr, int>> &p, int s sprintf(buff, " %c - %d) %-30s", I2A(j), std::get<1>(p[i]), - std::get<0>(p[i])); + std::get<0>(p[i]).c_str()); prt(buff, 2 + j, 20); j++; @@ -817,7 +817,7 @@ static int do_cmd_activate_skill_aux() int start = 0; int ret; - std::vector<std::tuple<cptr,int>> p; + std::vector<std::tuple<std::string const &,int>> p; /* More than 1 melee skill ? */ if (get_melee_skills() > 1) @@ -920,8 +920,10 @@ static int do_cmd_activate_skill_aux() size_t i = 0; for (; i < p.size(); i++) { - if (!strcmp(buf, std::get<0>(p[i]))) + if (std::get<0>(p[i]) == buf) + { break; + } } if (i < p.size()) @@ -1448,7 +1450,9 @@ s16b find_ability(cptr name) for (std::size_t i = 0; i < ab_info.size(); i++) { - if (ab_info[i].name && streq(ab_info[i].name, name)) + auto const &ab_name = ab_info[i].name; + + if ((!ab_name.empty()) && (ab_name == name)) { return (i); } @@ -1544,7 +1548,7 @@ 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; + return ab_info[ab_idx1].name < ab_info[ab_idx2].name; } /* @@ -1558,7 +1562,7 @@ void dump_abilities(FILE *fff) std::vector<std::size_t> table; for (std::size_t i = 0; i < ab_info.size(); i++) { - if (ab_info[i].name && p_ptr->has_ability(i)) + if ((!ab_info[i].name.empty()) && p_ptr->has_ability(i)) { table.push_back(i); } @@ -1576,7 +1580,7 @@ void dump_abilities(FILE *fff) for (int i : table) { - fprintf(fff, "\n * %s", ab_info[i].name); + fprintf(fff, "\n * %s", ab_info[i].name.c_str()); } fprintf(fff, "\n"); @@ -1603,7 +1607,7 @@ static void print_abilities(const std::vector<std::size_t> &table, int sel, int c_prt((p_ptr->skill_points) ? TERM_L_BLUE : TERM_L_RED, format("Skill points left: %d", p_ptr->skill_points), 2, 0); - print_desc_aux(ab_info[table[sel]].desc, 3, 0); + print_desc_aux(ab_info[table[sel]].desc.c_str(), 3, 0); for (j = start; j < start + (hgt - 7); j++) { @@ -1639,7 +1643,7 @@ static void print_abilities(const std::vector<std::size_t> &table, int sel, int end = ']'; } - c_prt(color, format("%c.%c%s", deb, end, ab_info[i].name), + c_prt(color, format("%c.%c%s", deb, end, ab_info[i].name.c_str()), j + 7 - start, 0); if (!p_ptr->has_ability(i)) @@ -1654,7 +1658,7 @@ static void print_abilities(const std::vector<std::size_t> &table, int sel, int } /* - * Interreact with abilitiess + * Interreact with abilities */ void do_cmd_ability() { @@ -1674,7 +1678,7 @@ void do_cmd_ability() std::vector<std::size_t> table; for (std::size_t i = 0; i < ab_info.size(); i++) { - if (ab_info[i].name) + if (!ab_info[i].name.empty()) { table.push_back(i); } @@ -1798,7 +1802,7 @@ void apply_level_abilities(int level) { if ((level > 1) && (!p_ptr->has_ability(a.ability))) { - cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_info[a.ability].name); + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_info[a.ability].name.c_str()); } p_ptr->gain_ability(a.ability); diff --git a/src/squelch/condition.cc b/src/squelch/condition.cc index 7c01c4cd..09535c53 100644 --- a/src/squelch/condition.cc +++ b/src/squelch/condition.cc @@ -942,10 +942,8 @@ void AbilityCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_ { auto const &ab_info = game->edit_data.ab_info; - cptr ability_s = ab_info[m_ability_idx].name; - p->write(ecol, "You have the "); - p->write(bcol, ability_s); + p->write(bcol, ab_info[m_ability_idx].name); p->write(ecol, " ability"); p->write(TERM_WHITE, "\n"); } diff --git a/src/squelch/tree_printer.cc b/src/squelch/tree_printer.cc index 2be098dc..0dbceec9 100644 --- a/src/squelch/tree_printer.cc +++ b/src/squelch/tree_printer.cc @@ -86,4 +86,9 @@ void TreePrinter::write(uint8_t color, cptr line) } } +void TreePrinter::write(uint8_t color, std::string const &line) +{ + write(color, line.c_str()); +} + } // namespace |