diff options
Diffstat (limited to 'src/skills.cc')
-rw-r--r-- | src/skills.cc | 185 |
1 files changed, 94 insertions, 91 deletions
diff --git a/src/skills.cc b/src/skills.cc index af5e46c7..ae53d6e6 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -34,10 +34,9 @@ #include "spells4.hpp" #include "tables.hpp" #include "util.hpp" -#include "util.h" -#include "variable.h" #include "variable.hpp" #include "xtra2.hpp" +#include "z-form.hpp" #include "z-rand.hpp" #include <algorithm> @@ -121,7 +120,7 @@ static void decrease_skill(int i, s16b *invest) * Given the name of a skill, returns skill index or -1 if no * such skill is found */ -s16b find_skill(cptr needle) +s16b find_skill(const char *needle) { auto const &s_descriptors = game->edit_data.s_descriptors; @@ -139,7 +138,12 @@ s16b find_skill(cptr needle) return -1; } -s16b find_skill_i(cptr needle) +s16b find_skill_i(std::string const &needle) +{ + return find_skill_i(needle.c_str()); +} + +s16b find_skill_i(const char *needle) { auto const &s_descriptors = game->edit_data.s_descriptors; @@ -207,13 +211,13 @@ static std::size_t get_idx(int i) return 0; } -static bool_ is_known(int s_idx) +static bool is_known(int s_idx) { auto const &s_descriptors = game->edit_data.s_descriptors; auto const &s_info = game->s_info; - if (wizard) return TRUE; - if (s_info[s_idx].value || s_info[s_idx].mod) return TRUE; + if (wizard) return true; + if (s_info[s_idx].value || s_info[s_idx].mod) return true; for (std::size_t i = 0; i < s_descriptors.size(); i++) { @@ -221,12 +225,12 @@ static bool_ is_known(int s_idx) if (s_descriptors[i].father == s_idx) { if (is_known(i)) - return TRUE; + return true; } } /* Ok know none */ - return FALSE; + return false; } namespace { // anonymous @@ -238,7 +242,7 @@ struct skill_entry { } -static void init_table_aux(std::vector<skill_entry> *table, int father, int lev, bool_ full) +static void init_table_aux(std::vector<skill_entry> *table, int father, int lev, bool full) { auto const &s_descriptors = game->edit_data.s_descriptors; auto const &s_info = game->s_info; @@ -263,7 +267,7 @@ static void init_table_aux(std::vector<skill_entry> *table, int father, int lev, } } -static void init_table(std::vector<skill_entry> *table, bool_ full) +static void init_table(std::vector<skill_entry> *table, bool full) { table->clear(); init_table_aux(table, -1, 0, full); @@ -297,7 +301,7 @@ void dump_skills(FILE *fff) std::vector<skill_entry> table; table.reserve(s_descriptors.size()); - init_table(&table, TRUE); + init_table(&table, true); fprintf(fff, "\nSkills (points left: %d)", p_ptr->skill_points); @@ -324,11 +328,11 @@ void dump_skills(FILE *fff) if (!has_child(i)) { - strcat(buf, format(" . %s", skill_name.c_str())); + strcat(buf, fmt::format(" . {}", skill_name).c_str()); } else { - strcat(buf, format(" - %s", skill_name.c_str())); + strcat(buf, fmt::format(" - %s", skill_name).c_str()); } fprintf(fff, "%-49s%s%06.3f [%05.3f]", @@ -351,16 +355,16 @@ static void print_skills(std::vector<skill_entry> const &table, int sel, int sta int j; int wid, hgt; - cptr keys; + const char *keys; Term_clear(); Term_get_size(&wid, &hgt); - c_prt(TERM_WHITE, format("%s Skills Screen", game_module), 0, 28); + c_prt(TERM_WHITE, fmt::format("{} Skills Screen", game_module), 0, 28); keys = format("#BEnter#W to develop a branch, #Bup#W/#Bdown#W to move, #Bright#W/#Bleft#W to modify, #B?#W for help"); display_message(0, 1, strlen(keys), TERM_WHITE, keys); c_prt((p_ptr->skill_points) ? TERM_L_BLUE : TERM_L_RED, - format("Skill points left: %d", p_ptr->skill_points), 2, 0); + fmt::format("Skill points left: {}", p_ptr->skill_points), 2, 0); print_desc_aux(s_descriptors[table[sel].skill_idx].desc.c_str(), 3, 0); for (j = start; j < start + (hgt - 7); j++) @@ -407,17 +411,17 @@ static void print_skills(std::vector<skill_entry> const &table, int sel, int sta if (!has_child(i)) { - c_prt(color, format("%c.%c%s", deb, end, name.c_str()), + c_prt(color, fmt::format("{}.{}{}", deb, end, name), j + 7 - start, table[j].indent_level * 4); } else if (skill.dev) { - c_prt(color, format("%c-%c%s", deb, end, name.c_str()), + c_prt(color, fmt::format("{}-{}{}", deb, end, name), j + 7 - start, table[j].indent_level * 4); } else { - c_prt(color, format("%c+%c%s", deb, end, name.c_str()), + c_prt(color, fmt::format("{}+{}{}", deb, end, name), j + 7 - start, table[j].indent_level * 4); } @@ -435,7 +439,7 @@ static void print_skills(std::vector<skill_entry> const &table, int sel, int sta /* * Checks various stuff to do when skills change, like new spells, ... */ -void recalc_skills(bool_ init) +void recalc_skills(bool init) { auto const &s_info = game->s_info; @@ -566,7 +570,7 @@ void do_cmd_skill() int wid, hgt; s16b skill_points_save; - recalc_skills(TRUE); + recalc_skills(true); /* Save the screen */ screen_save(); @@ -594,9 +598,9 @@ void do_cmd_skill() /* Initialise the skill list */ std::vector<skill_entry> table; table.reserve(s_descriptors.size()); - init_table(&table, FALSE); + init_table(&table, false); - while (TRUE) + while (true) { Term_get_size(&wid, &hgt); @@ -616,7 +620,7 @@ void do_cmd_skill() // Toggle the selected skill s_info[table[sel].skill_idx].dev = !s_info[table[sel].skill_idx].dev; // Re-populate table - init_table(&table, FALSE); + init_table(&table, false); } /* Next page */ @@ -710,7 +714,7 @@ void do_cmd_skill() /* Load the screen */ screen_load(); - recalc_skills(FALSE); + recalc_skills(false); } @@ -730,7 +734,7 @@ static const char *melee_names[MAX_MELEE] = "Barehanded combat", "Bearform combat", }; -static bool_ melee_bool[MAX_MELEE]; +static bool melee_bool[MAX_MELEE]; static int melee_num[MAX_MELEE]; s16b get_melee_skill() @@ -745,7 +749,7 @@ s16b get_melee_skill() return (0); } -cptr get_melee_name() +const char *get_melee_name() { return melee_names[get_melee_skill()]; } @@ -760,11 +764,11 @@ s16b get_melee_skills() { if ((s_info[melee_skills[i]].value > 0) && (!s_info[melee_skills[i]].hidden)) { - melee_bool[i] = TRUE; + melee_bool[i] = true; j++; } else - melee_bool[i] = FALSE; + melee_bool[i] = false; } return (j); @@ -773,10 +777,10 @@ s16b get_melee_skills() static void choose_melee() { int i, j, z = 0; - int force_drop = FALSE, style_unchanged = FALSE; + int force_drop = false, style_unchanged = false; + + screen_save_no_flush(); - character_icky = TRUE; - Term_save(); Term_clear(); j = get_melee_skills(); @@ -785,13 +789,13 @@ static void choose_melee() { if (melee_bool[i]) { - prt(format("%c) %s", I2A(z), melee_names[i]), z + 1, 0); + prt(fmt::format("{}) {}", I2A(z), melee_names[i]), z + 1, 0); melee_num[z] = i; z++; } } - while (TRUE) + while (true) { char c = inkey(); @@ -804,13 +808,13 @@ static void choose_melee() if (p_ptr->melee_style == melee_skills[melee_num[z]]) { - style_unchanged = TRUE; + style_unchanged = true; break; } for (i = INVEN_WIELD; p_ptr->body_parts[i - INVEN_WIELD] == INVEN_WIELD; i++) { - if (p_ptr->inventory[i].k_idx) + if (p_ptr->inventory[i].k_ptr) { if (cursed_p(&p_ptr->inventory[i])) { @@ -821,7 +825,7 @@ static void choose_melee() } else if (INVEN_PACK == inven_takeoff(i, 255, force_drop)) { - force_drop = TRUE; + force_drop = true; } } } @@ -839,8 +843,7 @@ static void choose_melee() /* Redraw monster hitpoint */ p_ptr->redraw |= (PR_FRAME); - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); if (style_unchanged) { @@ -889,7 +892,7 @@ static void print_skill_batch(const std::vector<std::tuple<std::string, int>> &p j++; } prt("", 2 + j, 20); - prt(format("Select a skill (a-%c), @ to select by name, +/- to scroll:", I2A(j - 1)), 0, 0); + prt(fmt::format("Select a skill (a-{}), @ to select by name, +/- to scroll:", I2A(j - 1)), 0, 0); } static int do_cmd_activate_skill_aux() @@ -914,14 +917,14 @@ static int do_cmd_activate_skill_aux() { if (s_descriptors[i].action_mkey && s_info[i].value && ((!s_info[i].hidden) || (i == SKILL_LEARN))) { - bool_ next = FALSE; + bool next = false; /* Already got it ? */ for (size_t j = 0; j < p.size(); j++) { if (s_descriptors[i].action_mkey == std::get<1>(p[j])) { - next = TRUE; + next = true; break; } } @@ -936,14 +939,14 @@ static int do_cmd_activate_skill_aux() { if (ab_info[i].action_mkey && p_ptr->has_ability(i)) { - bool_ next = FALSE; + bool next = false; /* Already got it ? */ for (size_t j = 0; j < p.size(); j++) { if (ab_info[i].action_mkey == std::get<1>(p[j])) { - next = TRUE; + next = true; break; } } @@ -960,10 +963,9 @@ static int do_cmd_activate_skill_aux() return -1; } - character_icky = TRUE; - Term_save(); + screen_save_no_flush(); - while (1) + while (true) { print_skill_batch(p, start); which = inkey(); @@ -980,8 +982,7 @@ static int do_cmd_activate_skill_aux() { start -= 20; } - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } else if (which == '-') { @@ -990,8 +991,7 @@ static int do_cmd_activate_skill_aux() { start += 20; } - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); } else if (which == '@') { @@ -999,7 +999,7 @@ static int do_cmd_activate_skill_aux() strcpy(buf, "Cast a spell"); if (!get_string("Skill action? ", buf, 79)) - return FALSE; + return false; /* Find the skill it is related to */ size_t i = 0; @@ -1035,8 +1035,7 @@ static int do_cmd_activate_skill_aux() break; } } - Term_load(); - character_icky = FALSE; + screen_load_no_flush(); return ret; } @@ -1049,12 +1048,12 @@ void do_cmd_activate_skill() auto const &s_info = game->s_info; int x_idx; - bool_ push = TRUE; + bool push = true; /* Get the skill, if available */ if (repeat_pull(&x_idx)) { - push = FALSE; + push = false; } else if (!command_arg) { @@ -1194,7 +1193,7 @@ void do_cmd_activate_skill() } o_ptr = get_object(INVEN_WIELD); - if ((o_ptr->k_idx <= 0) || + if ((!o_ptr->k_ptr) || (o_ptr->tval != TV_MSTAFF)) { msg_print("You must wield a magestaff to use Geomancy."); @@ -1204,7 +1203,7 @@ void do_cmd_activate_skill() s = get_school_spell("cast", BOOK_GEOMANCY); if (s >= 0) { - lua_cast_school_spell(s, FALSE); + lua_cast_school_spell(s, false); } break; @@ -1259,23 +1258,23 @@ void do_cmd_activate_skill() /* Which magic forbids non FA gloves */ -bool_ forbid_gloves() +bool forbid_gloves() { - if (get_skill(SKILL_SORCERY)) return (TRUE); - if (get_skill(SKILL_MANA)) return (TRUE); - if (get_skill(SKILL_FIRE)) return (TRUE); - if (get_skill(SKILL_AIR)) return (TRUE); - if (get_skill(SKILL_WATER)) return (TRUE); - if (get_skill(SKILL_EARTH)) return (TRUE); - if (get_skill(SKILL_THAUMATURGY)) return (TRUE); - return (FALSE); + if (get_skill(SKILL_SORCERY)) return true; + if (get_skill(SKILL_MANA)) return true; + if (get_skill(SKILL_FIRE)) return true; + if (get_skill(SKILL_AIR)) return true; + if (get_skill(SKILL_WATER)) return true; + if (get_skill(SKILL_EARTH)) return true; + if (get_skill(SKILL_THAUMATURGY)) return true; + return false; } /* Which gods forbid edged weapons */ -bool_ forbid_non_blessed() +bool forbid_non_blessed() { - if (p_ptr->pgod == GOD_ERU) return (TRUE); - return (FALSE); + if (p_ptr->pgod == GOD_ERU) return true; + return false; } @@ -1386,7 +1385,7 @@ void do_get_new_skill() auto &s_info = game->s_info; /* Check if some skills didn't influence other stuff */ - recalc_skills(TRUE); + recalc_skills(true); /* Grab the ones we can gain */ std::vector<size_t> available_skills; @@ -1462,7 +1461,7 @@ void do_get_new_skill() } // Ask for a skill - while (TRUE) + while (true) { char last = 'a' + (LOST_SWORD_NSKILLS-1); char buf[80]; @@ -1474,7 +1473,7 @@ void do_get_new_skill() { std::size_t chosen_skill = skl[res]; - bool_ oppose = FALSE; + bool oppose = false; int oppose_skill = -1; /* Check we don't oppose a skill the player already has */ @@ -1493,7 +1492,7 @@ void do_get_new_skill() if (found != s_descriptor.excludes.end()) { - oppose = TRUE; + oppose = true; oppose_skill = i; break; } @@ -1503,8 +1502,6 @@ void do_get_new_skill() /* Ok we oppose, so be sure */ if (oppose) { - cptr msg; - /* * Because this is SO critical a question, we must flush * input to prevent killing character off -- pelpel @@ -1512,9 +1509,10 @@ void do_get_new_skill() flush(); /* Prepare prompt */ - msg = format("This skill is mutually exclusive with " - "at least %s, continue?", - s_descriptors[oppose_skill].name.c_str()); + auto msg = fmt::format( + "This skill is mutually exclusive with " + "at least {}, continue?", + s_descriptors[oppose_skill].name); /* The player rejected the choice; go back to prompt */ if (!get_check(msg)) @@ -1545,7 +1543,7 @@ void do_get_new_skill() } /* Check if some skills didn't influence other stuff */ - recalc_skills(FALSE); + recalc_skills(false); } @@ -1553,11 +1551,16 @@ void do_get_new_skill() /**************************************** ABILITIES *****************************************/ +s16b find_ability(std::string const &name) +{ + return find_ability(name.c_str()); +} + /* * Given the name of an ability, returns ability index or -1 if no * such ability is found */ -s16b find_ability(cptr name) +s16b find_ability(const char *name) { auto const &ab_info = game->edit_data.ab_info; @@ -1584,19 +1587,19 @@ static bool can_learn_ability(int ab) if (p_ptr->has_ability(ab)) { - return FALSE; + return false; } if (p_ptr->skill_points < ab_info[ab].cost) { - return FALSE; + return false; } for (auto const &need_skill: ab_ptr->need_skills) { if (get_skill(need_skill.skill_idx) < need_skill.level) { - return FALSE; + return false; } } @@ -1604,7 +1607,7 @@ static bool can_learn_ability(int ab) { if (!p_ptr->has_ability(need_ability)) { - return FALSE; + return false; } } @@ -1614,11 +1617,11 @@ static bool can_learn_ability(int ab) if (ab_ptr->stat[i] > -1) { if (p_ptr->stat_ind[i] < ab_ptr->stat[i] - 3) - return FALSE; + return false; } } - return TRUE; + return true; } /* Learn an ability */ @@ -1697,7 +1700,7 @@ static void print_abilities(const std::vector<std::size_t> &table, int sel, int int i, j; int wid, hgt; - cptr keys; + const char *keys; Term_clear(); Term_get_size(&wid, &hgt); @@ -1706,7 +1709,7 @@ static void print_abilities(const std::vector<std::size_t> &table, int sel, int keys = format("#Bup#W/#Bdown#W to move, #Bright#W to buy, #B?#W for help"); display_message(0, 1, strlen(keys), TERM_WHITE, keys); c_prt((p_ptr->skill_points) ? TERM_L_BLUE : TERM_L_RED, - format("Skill points left: %d", p_ptr->skill_points), 2, 0); + fmt::format("Skill points left: {}", p_ptr->skill_points), 2, 0); print_desc_aux(ab_info[table[sel]].desc.c_str(), 3, 0); @@ -1789,7 +1792,7 @@ void do_cmd_ability() std::end(table), compare_abilities); - while (TRUE) + while (true) { Term_get_size(&wid, &hgt); |