From cbef37bd5bfb938a2303ee3887520c08be85d8e8 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 26 Mar 2013 17:10:10 +0100 Subject: Switch almost everything over to C++ --- src/skills.cc | 1814 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1814 insertions(+) create mode 100644 src/skills.cc (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc new file mode 100644 index 00000000..221a5e27 --- /dev/null +++ b/src/skills.cc @@ -0,0 +1,1814 @@ +/* File: skills.c */ + +/* Purpose: player skills */ + +/* + * Copyright (c) 2001 DarkGod + * + * This software may be copied and distributed for educational, research, and + * not for profit purposes provided that this copyright and statement are + * included in all such copies. + */ + +#include "angband.h" + +#include +#include "hooks.h" +#include "util.hpp" + +#include +#include +#include +#include +#include + + +/* + * Advance the skill point of the skill specified by i and + * modify related skills + */ +static void increase_skill(int i, s16b *invest) +{ + s32b max_skill_overage; + + /* No skill points to be allocated */ + if (!p_ptr->skill_points) return; + + /* The skill cannot be increased */ + if (!s_info[i].mod) return; + + /* The skill is already maxed */ + if (s_info[i].value >= SKILL_MAX) return; + + /* Cannot allocate more than player level + max_skill_overage levels */ + max_skill_overage = modules[game_module_idx].skills.max_skill_overage; + if (((s_info[i].value + s_info[i].mod) / SKILL_STEP) >= (p_ptr->lev + max_skill_overage + 1)) + { + int hgt, wid; + char buf[256]; + + sprintf(buf, + "Cannot raise a skill value above " FMTs32b " + player level.", + max_skill_overage); + + Term_get_size(&wid, &hgt); + msg_box(buf, hgt / 2, wid / 2); + return; + } + + /* Spend an unallocated skill point */ + p_ptr->skill_points--; + + /* Increase the skill */ + s_info[i].value += s_info[i].mod; + invest[i]++; +} + + +/* + * Descrease the skill point of the skill specified by i and + * modify related skills + */ +void decrease_skill(int i, s16b *invest) +{ + /* Cannot decrease more */ + if (!invest[i]) return; + + /* The skill cannot be decreased */ + if (!s_info[i].mod) return; + + /* The skill already has minimal value */ + if (!s_info[i].value) return; + + /* Free a skill point */ + p_ptr->skill_points++; + + /* Decrease the skill */ + s_info[i].value -= s_info[i].mod; + invest[i]--; +} + + +/* + * Given the name of a skill, returns skill index or -1 if no + * such skill is found + */ +s16b find_skill(cptr name) +{ + u16b i; + + /* Scan skill list */ + for (i = 1; i < max_s_idx; i++) + { + /* The name matches */ + if (s_info[i].name > 0) + { + if (streq(s_info[i].name + s_name, name)) return (i); + } + } + + /* No match found */ + return ( -1); +} +s16b find_skill_i(cptr name) +{ + u16b i; + + /* Scan skill list */ + for (i = 1; i < max_s_idx; i++) + { + /* The name matches */ + if (s_info[i].name > 0) { + if (0 == stricmp(s_info[i].name + s_name, name)) return (i); + } + } + + /* No match found */ + return ( -1); +} + + +/* + * + */ +s16b get_skill(int skill) +{ + return (s_info[skill].value / SKILL_STEP); +} + + +/* + * Return "scale" (a misnomer -- this is max value) * (current skill value) + * / (max skill value) + */ +s16b get_skill_scale(int skill, u32b scale) +{ + s32b temp; + + /* + * SKILL_STEP shouldn't matter here because the second parameter is + * relatively small (the largest one being somewhere around 200), + * AND because we could have used much simpler 0--50 if the ability + * progression were only possible at step boundaries. + * + * Because I'm not at all certain about my interpretation of the mysterious + * formula given above, I verified this works the same by using a tiny + * scheme program... -- pelpel + */ + temp = scale * s_info[skill].value; + + return (temp / SKILL_MAX); +} + + +/* + * + */ +int get_idx(int i) +{ + int j; + + for (j = 1; j < max_s_idx; j++) + { + if (s_info[j].order == i) + return (j); + } + return (0); +} + +static bool_ is_known(int s_idx) +{ + int i; + + if (wizard) return TRUE; + if (s_info[s_idx].value || s_info[s_idx].mod) return TRUE; + + for (i = 0; i < max_s_idx; i++) + { + /* It is our child, if we don't know it we continue to search, if we know it it is enough*/ + if (s_info[i].father == s_idx) + { + if (is_known(i)) + return TRUE; + } + } + + /* Ok know none */ + return FALSE; +} + +/* + * + */ +void init_table_aux(int table[MAX_SKILLS][2], int *idx, int father, int lev, + bool_ full) +{ + int j, i; + + for (j = 1; j < max_s_idx; j++) + { + i = get_idx(j); + if (s_info[i].father != father) continue; + if (s_info[i].hidden) continue; + if (!is_known(i)) continue; + + table[*idx][0] = i; + table[*idx][1] = lev; + (*idx)++; + if (s_info[i].dev || full) init_table_aux(table, idx, i, lev + 1, full); + } +} + + +void init_table(int table[MAX_SKILLS][2], int *max, bool_ full) +{ + *max = 0; + init_table_aux(table, max, -1, 0, full); +} + + +bool_ has_child(int sel) +{ + int i; + + for (i = 1; i < max_s_idx; i++) + { + if ((s_info[i].father == sel) && (is_known(i))) + return (TRUE); + } + return (FALSE); +} + + +/* + * Dump the skill tree + */ +void dump_skills(FILE *fff) +{ + int i, j, max = 0; + int table[MAX_SKILLS][2]; + char buf[80]; + + init_table(table, &max, TRUE); + + fprintf(fff, "\nSkills (points left: %d)", p_ptr->skill_points); + + for (j = 0; j < max; j++) + { + int z; + + i = table[j][0]; + + if ((s_info[i].value == 0) && (i != SKILL_MISC)) + { + if (s_info[i].mod == 0) continue; + } + + sprintf(buf, "\n"); + + for (z = 0; z < table[j][1]; z++) strcat(buf, " "); + + if (!has_child(i)) + { + strcat(buf, format(" . %s", s_info[i].name + s_name)); + } + else + { + strcat(buf, format(" - %s", s_info[i].name + s_name)); + } + + fprintf(fff, "%-49s%s%06.3f [%05.3f]", + buf, s_info[i].value < 0 ? "-" : " ", + static_cast(ABS(s_info[i].value)) / SKILL_STEP, + static_cast(s_info[i].mod) / 1000); + } + + fprintf(fff, "\n"); +} + + +/* + * Draw the skill tree + */ +void print_skills(int table[MAX_SKILLS][2], int max, int sel, int start) +{ + int i, j; + int wid, hgt; + cptr keys; + + Term_clear(); + Term_get_size(&wid, &hgt); + + c_prt(TERM_WHITE, format("%s 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); + print_desc_aux(s_info[table[sel][0]].desc + s_text, 3, 0); + + for (j = start; j < start + (hgt - 7); j++) + { + byte color = TERM_WHITE; + char deb = ' ', end = ' '; + + if (j >= max) break; + + i = table[j][0]; + + if ((s_info[i].value == 0) && (i != SKILL_MISC)) + { + if (s_info[i].mod == 0) color = TERM_L_DARK; + else color = TERM_ORANGE; + } + else if (s_info[i].value == SKILL_MAX) color = TERM_L_BLUE; + if (s_info[i].hidden) color = TERM_L_RED; + if (j == sel) + { + color = TERM_L_GREEN; + deb = '['; + end = ']'; + } + if (!has_child(i)) + { + c_prt(color, format("%c.%c%s", deb, end, s_info[i].name + s_name), + j + 7 - start, table[j][1] * 4); + } + else if (s_info[i].dev) + { + c_prt(color, format("%c-%c%s", deb, end, s_info[i].name + s_name), + j + 7 - start, table[j][1] * 4); + } + else + { + c_prt(color, format("%c+%c%s", deb, end, s_info[i].name + s_name), + j + 7 - start, table[j][1] * 4); + } + c_prt(color, + format("%s%02ld.%03ld [%01d.%03d]", + s_info[i].value < 0 ? "-" : " ", + ABS(s_info[i].value) / SKILL_STEP, + ABS(s_info[i].value) % SKILL_STEP, + ABS(s_info[i].mod) / 1000, + ABS(s_info[i].mod) % 1000), + j + 7 - start, 60); + } +} + +/* + * Checks various stuff to do when skills change, like new spells, ... + */ +void recalc_skills(bool_ init) +{ + static int thaum_level = 0; + + /* TODO: This should be a hook in ToME's lua */ + if (init) + { + thaum_level = get_skill_scale(SKILL_THAUMATURGY, 100); + } + else + { + int thaum_gain = 0; + + /* Gain thaum spells */ + while (thaum_level < get_skill_scale(SKILL_THAUMATURGY, 100)) + { + if (spell_num == MAX_SPELLS) break; + thaum_level++; + generate_spell((thaum_level + 1) / 2); + thaum_gain++; + } + if (thaum_gain) + { + if (thaum_gain == 1) + msg_print("You have gained one new thaumaturgy spell."); + else + msg_format("You have gained %d new thaumaturgy spells.", thaum_gain); + } + + /* Antimagic means you don't believe in gods. */ + if ((p_ptr->pgod != GOD_NONE) && + (s_info[SKILL_ANTIMAGIC].value > 0)) + { + msg_print("You no longer believe."); + abandon_god(GOD_ALL); + } + + process_hooks(HOOK_RECALC_SKILLS, "()"); + process_hooks_new(HOOK_RECALC_SKILLS, NULL, NULL); + + /* Update stuffs */ + p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS | PU_POWERS | + PU_SANITY | PU_BODY); + + /* Redraw various info */ + p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP); + } +} + +/* + * Recalc the skill value + */ +static void recalc_skills_theory(s16b *invest, s32b *base_val, s32b *base_mod, s32b *bonus) +{ + int i, j; + + /* First we assign the normal points */ + for (i = 0; i < max_s_idx; i++) + { + /* Calc the base */ + s_info[i].value = base_val[i] + (base_mod[i] * invest[i]) + bonus[i]; + + /* It cannot exceed SKILL_MAX */ + if (s_info[i].value > SKILL_MAX) s_info[i].value = SKILL_MAX; + } + + /* Then we modify related skills */ + for (i = 0; i < max_s_idx; i++) + { + for (j = 1; j < max_s_idx; j++) + { + /* Ignore self */ + if (j == i) continue; + + /* Exclusive skills */ + if ((s_info[i].action[j] == SKILL_EXCLUSIVE) && invest[i]) + { + /* Turn it off */ + p_ptr->skill_points += invest[j]; + invest[j] = 0; + s_info[j].value = 0; + } + + /* Non-exclusive skills */ + else if (s_info[i].action[j]) + { + /* Increase / decrease with a % */ + s32b val = s_info[j].value + (invest[i] * s_info[j].mod * s_info[i].action[j] / 100); + + /* It cannot exceed SKILL_MAX */ + if (val > SKILL_MAX) val = SKILL_MAX; + + /* Save the modified value */ + s_info[j].value = val; + } + } + } +} + +/* + * Interreact with skills + */ +void do_cmd_skill() +{ + int sel = 0, start = 0, max; + char c; + int table[MAX_SKILLS][2]; + int i; + int wid, hgt; + s16b skill_points_save; + + recalc_skills(TRUE); + + /* Save the screen */ + screen_save(); + + /* Allocate arrays to save skill values */ + std::unique_ptr skill_values_save(new s32b[MAX_SKILLS]); + std::unique_ptr skill_mods_save(new s32b[MAX_SKILLS]); + std::unique_ptr skill_rates_save(new s16b[MAX_SKILLS]); + std::unique_ptr skill_invest(new s16b[MAX_SKILLS]); + std::unique_ptr skill_bonus(new s32b[MAX_SKILLS]); + + /* Save skill points */ + skill_points_save = p_ptr->skill_points; + + /* Save skill values */ + for (i = 0; i < max_s_idx; i++) + { + skill_type *s_ptr = &s_info[i]; + + skill_values_save[i] = s_ptr->value; + skill_mods_save[i] = s_ptr->mod; + skill_rates_save[i] = s_ptr->rate; + skill_invest[i] = 0; + skill_bonus[i] = 0; + } + + /* Clear the screen */ + Term_clear(); + + /* Initialise the skill list */ + init_table(table, &max, FALSE); + + while (TRUE) + { + Term_get_size(&wid, &hgt); + + /* Display list of skills */ + recalc_skills_theory(skill_invest.get(), skill_values_save.get(), skill_mods_save.get(), skill_bonus.get()); + print_skills(table, max, sel, start); + + /* Wait for user input */ + c = inkey(); + + /* Leave the skill screen */ + if (c == ESCAPE) break; + + /* Expand / collapse list of skills */ + else if (c == '\r') + { + if (s_info[table[sel][0]].dev) s_info[table[sel][0]].dev = FALSE; + else s_info[table[sel][0]].dev = TRUE; + init_table(table, &max, FALSE); + } + + /* Next page */ + else if (c == 'n') + { + sel += (hgt - 7); + if (sel >= max) sel = max - 1; + } + + /* Previous page */ + else if (c == 'p') + { + sel -= (hgt - 7); + if (sel < 0) sel = 0; + } + + /* Select / increase a skill */ + else + { + int dir; + + /* Allow use of numpad / arrow keys / roguelike keys */ + dir = get_keymap_dir(c); + + /* Move cursor down */ + if (dir == 2) sel++; + + /* Move cursor up */ + if (dir == 8) sel--; + + /* Miscellaneous skills cannot be increased/decreased as a group */ + if (table[sel][0] == SKILL_MISC) continue; + + /* Increase the current skill */ + if (dir == 6) increase_skill(table[sel][0], skill_invest.get()); + + /* Decrease the current skill */ + if (dir == 4) decrease_skill(table[sel][0], skill_invest.get()); + + /* XXX XXX XXX Wizard mode commands outside of wizard2.c */ + + /* Increase the skill */ + if (wizard && (c == '+')) skill_bonus[table[sel][0]] += SKILL_STEP; + + /* Decrease the skill */ + if (wizard && (c == '-')) skill_bonus[table[sel][0]] -= SKILL_STEP; + + /* Contextual help */ + if (c == '?') + { + help_skill(s_info[table[sel][0]].name + s_name); + } + + /* Handle boundaries and scrolling */ + if (sel < 0) sel = max - 1; + if (sel >= max) sel = 0; + if (sel < start) start = sel; + if (sel >= start + (hgt - 7)) start = sel - (hgt - 7) + 1; + } + } + + + /* Some skill points are spent */ + if (p_ptr->skill_points != skill_points_save) + { + /* Flush input as we ask an important and irreversible question */ + flush(); + + /* Ask we can commit the change */ + if (msg_box("Save and use these skill values? (y/n)", hgt / 2, wid / 2) != 'y') + { + /* User declines -- restore the skill values before exiting */ + + /* Restore skill points */ + p_ptr->skill_points = skill_points_save; + + /* Restore skill values */ + for (i = 0; i < max_s_idx; i++) + { + skill_type *s_ptr = &s_info[i]; + + s_ptr->value = skill_values_save[i]; + s_ptr->mod = skill_mods_save[i]; + s_ptr->rate = skill_rates_save[i]; + } + } + } + + /* Load the screen */ + screen_load(); + + recalc_skills(FALSE); +} + + + +/* + * List of melee skills + */ +s16b melee_skills[MAX_MELEE] = +{ + SKILL_MASTERY, + SKILL_HAND, + SKILL_BEAR, +}; +const char *melee_names[MAX_MELEE] = +{ + "Weapon combat", + "Barehanded combat", + "Bearform combat", +}; +static bool_ melee_bool[MAX_MELEE]; +static int melee_num[MAX_MELEE]; + +s16b get_melee_skill() +{ + int i; + + for (i = 0; i < MAX_MELEE; i++) + { + if (p_ptr->melee_style == melee_skills[i]) + return (i); + } + return (0); +} + +s16b get_melee_skills() +{ + int i, j = 0; + + for (i = 0; i < MAX_MELEE; i++) + { + if ((s_info[melee_skills[i]].value > 0) && (!s_info[melee_skills[i]].hidden)) + { + melee_bool[i] = TRUE; + j++; + } + else + melee_bool[i] = FALSE; + } + + return (j); +} + +static void choose_melee() +{ + int i, j, z = 0; + int force_drop = FALSE, style_unchanged = FALSE; + + character_icky = TRUE; + Term_save(); + Term_clear(); + + j = get_melee_skills(); + prt("Choose a melee style:", 0, 0); + for (i = 0; i < MAX_MELEE; i++) + { + if (melee_bool[i]) + { + prt(format("%c) %s", I2A(z), melee_names[i]), z + 1, 0); + melee_num[z] = i; + z++; + } + } + + while (TRUE) + { + char c = inkey(); + + if (c == ESCAPE) break; + if (A2I(c) < 0) continue; + if (A2I(c) >= j) continue; + + for (i = 0, z = 0; z < A2I(c); i++) + if (melee_bool[i]) z++; + + if (p_ptr->melee_style == melee_skills[melee_num[z]]) + { + 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 (cursed_p(&p_ptr->inventory[i])) + { + char name[80]; + object_desc(name, &p_ptr->inventory[i], 0, 0); + msg_format("Hmmm, your %s seems to be cursed.", name); + break; + } + else if (INVEN_PACK == inven_takeoff(i, 255, force_drop)) + { + force_drop = TRUE; + } + } + } + p_ptr->melee_style = melee_skills[melee_num[z]]; + energy_use = 100; + break; + } + + /* Recalculate bonuses */ + p_ptr->update |= (PU_BONUS); + + /* Recalculate hitpoint */ + p_ptr->update |= (PU_HP); + + /* Redraw monster hitpoint */ + p_ptr->redraw |= (PR_MH); + + Term_load(); + character_icky = FALSE; + + if (style_unchanged) + { + msg_format("You are already using %s.", melee_names[melee_num[z]]); + } +} + +void select_default_melee() +{ + int i; + + get_melee_skills(); + p_ptr->melee_style = SKILL_MASTERY; + for (i = 0; i < MAX_MELEE; i++) + { + if (melee_bool[i]) + { + p_ptr->melee_style = melee_skills[i]; + break; + } + } +} + +/* + * Print a batch of skills. + */ +static void print_skill_batch(const std::vector> &p, int start) +{ + char buff[80]; + int i = start, j = 0; + + prt(format(" %-31s", "Name"), 1, 20); + + for (i = start; i < (start + 20); i++) + { + if (i >= p.size()) + { + break; + } + + sprintf(buff, " %c - %d) %-30s", I2A(j), + std::get<1>(p[i]), + std::get<0>(p[i])); + + prt(buff, 2 + j, 20); + j++; + } + prt("", 2 + j, 20); + prt(format("Select a skill (a-%c), @ to select by name, +/- to scroll:", I2A(j - 1)), 0, 0); +} + +int do_cmd_activate_skill_aux() +{ + char which; + int i, start = 0; + int ret; + + std::vector> p; + + /* More than 1 melee skill ? */ + if (get_melee_skills() > 1) + { + p.push_back(std::make_tuple("Change melee mode", 0)); + } + + for (i = 1; i < max_s_idx; i++) + { + if (s_info[i].action_mkey && s_info[i].value && ((!s_info[i].hidden) || (i == SKILL_LEARN))) + { + int j; + bool_ next = FALSE; + + /* Already got it ? */ + for (j = 0; j < p.size(); j++) + { + if (s_info[i].action_mkey == std::get<1>(p[j])) + { + next = TRUE; + break; + } + } + if (next) continue; + + p.push_back(std::make_tuple(s_text + s_info[i].action_desc, + s_info[i].action_mkey)); + } + } + + for (i = 0; i < max_ab_idx; i++) + { + if (ab_info[i].action_mkey && ab_info[i].acquired) + { + int j; + bool_ next = FALSE; + + /* Already got it ? */ + for (j = 0; j < p.size(); j++) + { + if (ab_info[i].action_mkey == std::get<1>(p[j])) + { + next = TRUE; + break; + } + } + if (next) continue; + + p.push_back(std::make_tuple(ab_text + ab_info[i].action_desc, + ab_info[i].action_mkey)); + } + } + + if (p.empty()) + { + msg_print("You don't have any activable skills or abilities."); + return -1; + } + + character_icky = TRUE; + Term_save(); + + while (1) + { + print_skill_batch(p, start); + which = inkey(); + + if (which == ESCAPE) + { + ret = -1; + break; + } + else if (which == '+') + { + start += 20; + if (start >= p.size()) start -= 20; + Term_load(); + character_icky = FALSE; + } + else if (which == '-') + { + start -= 20; + if (start < 0) start += 20; + Term_load(); + character_icky = FALSE; + } + else if (which == '@') + { + char buf[80]; + + strcpy(buf, "Cast a spell"); + if (!get_string("Skill action? ", buf, 79)) + return FALSE; + + /* Find the skill it is related to */ + for (i = 0; i < p.size(); i++) + { + if (!strcmp(buf, std::get<0>(p[i]))) + break; + } + if ((i < p.size())) + { + ret = std::get<1>(p[i]); + break; + } + + } + else + { + which = tolower(which); + if (start + A2I(which) >= p.size()) + { + bell(); + continue; + } + if (start + A2I(which) < 0) + { + bell(); + continue; + } + + ret = std::get<1>(p[start + A2I(which)]); + break; + } + } + Term_load(); + character_icky = FALSE; + + return ret; +} + +/* Ask & execute a skill */ +void do_cmd_activate_skill() +{ + int x_idx; + bool_ push = TRUE; + + /* Get the skill, if available */ + if (repeat_pull(&x_idx)) + { + push = FALSE; + } + else if (!command_arg) x_idx = do_cmd_activate_skill_aux(); + else + { + int i, j; + + x_idx = command_arg; + + /* Check validity */ + for (i = 1; i < max_s_idx; i++) + { + if (s_info[i].value && (s_info[i].action_mkey == x_idx)) + break; + } + for (j = 0; j < max_ab_idx; j++) + { + if (ab_info[j].acquired && (ab_info[j].action_mkey == x_idx)) + break; + } + + if ((j == max_ab_idx) && (i == max_s_idx)) + { + msg_print("Uh?"); + return; + } + } + + if (x_idx == -1) return; + + if (push) repeat_push(x_idx); + + if (!x_idx) + { + choose_melee(); + return; + } + + /* Break goi/manashield */ + if (p_ptr->invuln) + { + set_invuln(0); + } + if (p_ptr->disrupt_shield) + { + set_disrupt_shield(0); + } + + switch (x_idx) + { + case MKEY_ANTIMAGIC: + do_cmd_unbeliever(); + break; + case MKEY_MINDCRAFT: + do_cmd_mindcraft(); + break; + case MKEY_ALCHEMY: + do_cmd_alchemist(); + break; + case MKEY_MIMIC: + do_cmd_mimic(); + break; + case MKEY_POWER_MAGE: + do_cmd_powermage(); + break; + case MKEY_RUNE: + do_cmd_runecrafter(); + break; + case MKEY_FORGING: + do_cmd_archer(); + break; + case MKEY_INCARNATION: + do_cmd_possessor(); + break; + case MKEY_TELEKINESIS: + do_cmd_portable_hole(); + break; + case MKEY_BLADE: + do_cmd_blade(); + break; + case MKEY_SUMMON: + do_cmd_summoner(); + break; + case MKEY_NECRO: + do_cmd_necromancer(); + break; + case MKEY_SYMBIOTIC: + do_cmd_symbiotic(); + break; + case MKEY_TRAP: + do_cmd_set_trap(); + break; + case MKEY_STEAL: + do_cmd_steal(); + break; + case MKEY_DODGE: + use_ability_blade(); + break; + case MKEY_SCHOOL: + cast_school_spell(); + break; + case MKEY_COPY: + do_cmd_copy_spell(); + break; + case MKEY_BOULDER: + do_cmd_create_boulder(); + break; + case MKEY_COMPANION: + if (get_skill(SKILL_LORE) >= 12) + do_cmd_companion(); + else + msg_print("You need a skill level of at least 12."); + break; + case MKEY_PIERCING: + do_cmd_set_piercing(); + break; + case MKEY_DEATH_TOUCH: + { + if (p_ptr->csp > 40) + { + increase_mana(-40); + set_project(randint(30) + 10, + GF_INSTA_DEATH, + 1, + 0, + PROJECT_STOP | PROJECT_KILL); + energy_use = 100; + } + else + { + msg_print("You need at least 40 mana."); + } + break; + } + case MKEY_GEOMANCY: + { + s32b s = -1; + object_type *o_ptr = NULL; + + /* No magic */ + if (p_ptr->antimagic > 0) + { + msg_print("Your anti-magic field disrupts any magic attempts."); + break; + } + + o_ptr = get_object(INVEN_WIELD); + if ((o_ptr->k_idx <= 0) || + (o_ptr->tval != TV_MSTAFF)) + { + msg_print("You must wield a magestaff to use Geomancy."); + break; + } + + s = get_school_spell("cast", BOOK_GEOMANCY); + if (s >= 0) + { + lua_cast_school_spell(s, FALSE); + } + + break; + } + case MKEY_REACH_ATTACK: + { + object_type *o_ptr = NULL; + int dir, dy, dx, targetx, targety, max_blows, flags; + + o_ptr = get_object(INVEN_WIELD); + if (o_ptr->tval == TV_POLEARM) + { + msg_print("You will need a long polearm for this!"); + return; + } + + if (!get_rep_dir(&dir)) + { + return; + } + + dy = ddy[dir]; + dx = ddx[dir]; + dy = dy * 2; + dx = dx * 2; + targety = p_ptr->py + dy; + targetx = p_ptr->px + dx; + + max_blows = get_skill_scale(SKILL_POLEARM, p_ptr->num_blow / 2); + if (max_blows == 0) + { + max_blows = 1; + } + + energy_use = energy_use + 200; + + flags = PROJECT_BEAM | PROJECT_KILL; + if (get_skill(SKILL_POLEARM) < 40) + { + flags |= PROJECT_STOP; + } + + project(0, 0, targety, targetx, + max_blows, GF_ATTACK, flags); + + break; + } + default: + break; + } +} + + +/* Which magic forbids non FA 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); +} + +/* Which gods forbid edged weapons */ +bool_ forbid_non_blessed() +{ + GOD(GOD_ERU) return (TRUE); + return (FALSE); +} + + +/* + * Gets the base value of a skill, given a race/class/... + */ +void compute_skills(s32b *v, s32b *m, int i) +{ + s32b value, mod; + + /***** general skills *****/ + + /* If the skill correspond to the magic school lets pump them a bit */ + value = gen_skill_base[i]; + mod = gen_skill_mod[i]; + + *v = modify_aux(*v, + value, gen_skill_basem[i]); + *m = modify_aux(*m, + mod, gen_skill_modm[i]); + + /***** race skills *****/ + + value = rp_ptr->skill_base[i]; + mod = rp_ptr->skill_mod[i]; + + *v = modify_aux(*v, + value, rp_ptr->skill_basem[i]); + *m = modify_aux(*m, + mod, rp_ptr->skill_modm[i]); + + /***** race mod skills *****/ + + value = rmp_ptr->skill_base[i]; + mod = rmp_ptr->skill_mod[i]; + + *v = modify_aux(*v, + value, rmp_ptr->skill_basem[i]); + *m = modify_aux(*m, + mod, rmp_ptr->skill_modm[i]); + + /***** class skills *****/ + + value = cp_ptr->skill_base[i]; + mod = cp_ptr->skill_mod[i]; + + *v = modify_aux(*v, + value, cp_ptr->skill_basem[i]); + *m = modify_aux(*m, + mod, cp_ptr->skill_modm[i]); + + /***** class spec skills *****/ + + value = spp_ptr->skill_base[i]; + mod = spp_ptr->skill_mod[i]; + + *v = modify_aux(*v, + value, spp_ptr->skill_basem[i]); + *m = modify_aux(*m, + mod, spp_ptr->skill_modm[i]); +} + +/* + * Initialize a skill with given values + */ +void init_skill(s32b value, s32b mod, int i) +{ + s_info[i].value = value; + s_info[i].mod = mod; + + if (s_info[i].flags1 & SKF1_HIDDEN) + s_info[i].hidden = TRUE; + else + s_info[i].hidden = FALSE; +} + +/* + * Perform weighted random selection without replacement according to + * the algorithm given in "Weighted Random Sampling" (2005, Eframidis, + * Spirakis) + * + * @param k is the total number of items to choose. This MUST be smaller than or equal to the number of weights. + * @param weights is the array of weights. + * @return an output vector of size k containing the chosen indices. + */ +static std::vector wrs_without_replacement(size_t k, const std::vector &unscaled_weights) +{ + size_t n = unscaled_weights.size(); + + assert(k <= n); + + /* Rescale weights into unit interval for numerical stability */ + std::vector weights(unscaled_weights.size()); + { + s32b scale = 0; + for (s32b weight: unscaled_weights) + { + scale += weight; + } + + for (size_t i = 0; i < n; i++) { + weights[i] = + ((double) unscaled_weights[i]) / + ((double) scale); + } + } + + /* Generate the keys to use for selection. This is where the + magic happens. */ + std::vector keys(unscaled_weights.size()); + for (size_t i = 0; i < n; i++) { + double u = ((double) rand_int(100000)) / ((double) 100000); + keys[i] = pow(u, 1/weights[i]); + } + + /* Generate the initial permutation */ + std::vector permutation(unscaled_weights.size()); + for (size_t i = 0; i < n; i++) { + permutation[i] = i; + } + + /* Select the k indexes with the largest keys */ + std::vector indexes; + for (size_t i = 0; i < k; i++) { + /* Find maximal value and its index */ + size_t max_idx = i; + double max_value = keys[max_idx]; + for (size_t j = i + 1; j < n; j++) { + if (keys[j] > max_value) { + max_idx = j; + max_value = keys[j]; + } + } + + /* Swap into k'th position */ + if (max_idx != i) { + /* Swap keys */ + std::swap(keys[i], keys[max_idx]); + /* Swap indexes in permutation */ + std::swap(permutation[i], permutation[max_idx]); + } + + /* Output the k'th choice. We can do this already + since we'll never revisit the i'th position in + permutation vector. */ + indexes.push_back(permutation[i]); + } + + return indexes; +} + +void do_get_new_skill() +{ + std::vector items; + int skl[LOST_SWORD_NSKILLS]; + s32b val[LOST_SWORD_NSKILLS], mod[LOST_SWORD_NSKILLS]; + int available_skills[MAX_SKILLS]; + int max_a = 0, res, i; + + /* Check if some skills didn't influence other stuff */ + recalc_skills(TRUE); + + /* Grab the ones we can gain */ + max_a = 0; + for (i = 0; i < max_s_idx; i++) + { + if (s_info[i].flags1 & SKF1_RANDOM_GAIN) { + available_skills[max_a] = i; + max_a++; + } + } + + /* Perform the selection */ + std::vector weights; + for (i = 0; i < max_a; i++) { + weights.push_back(s_info[available_skills[i]].random_gain_chance); + } + + std::vector indexes = + wrs_without_replacement(LOST_SWORD_NSKILLS, weights); + assert(indexes.size() == LOST_SWORD_NSKILLS); + + /* Extract the information needed from the skills */ + for (i = 0; i < LOST_SWORD_NSKILLS; i++) + { + s32b s_idx = available_skills[indexes[i]]; + skill_type *s_ptr = &s_info[s_idx]; + + if (s_ptr->mod) + { + if (s_ptr->mod < 300) + { + val[i] = 1000; + mod[i] = 300 - s_ptr->mod; + } + else if (s_ptr->mod < 500) + { + val[i] = s_ptr->mod * 1; + mod[i] = 100; + if (mod[i] + s_ptr->mod > 500) + mod[i] = 500 - s_ptr->mod; + } + else + { + val[i] = s_ptr->mod * 3; + mod[i] = 0; + } + } + else + { + mod[i] = 300; + val[i] = 1000; + } + + if (s_ptr->value + val[i] > SKILL_MAX) { + val[i] = SKILL_MAX - s_ptr->value; + } + + skl[i] = s_idx; + items.push_back(format("%-40s: +%02ld.%03ld value, +%01d.%03d modifier", s_ptr->name + s_name, val[i] / SKILL_STEP, val[i] % SKILL_STEP, mod[i] / SKILL_STEP, mod[i] % SKILL_STEP)); + } + + while (TRUE) + { + char last = 'a' + (LOST_SWORD_NSKILLS-1); + char buf[80]; + sprintf(buf, "Choose a skill to learn(a-%c to choose, ESC to cancel)?", last); + res = ask_menu(buf, items); + + /* Ok ? lets learn ! */ + if (res > -1) + { + skill_type *s_ptr; + bool_ oppose = FALSE; + int oppose_skill = -1; + + /* Check we don't oppose an existing skill */ + for (i = 0; i < max_s_idx; i++) + { + if ((s_info[i].action[skl[res]] == SKILL_EXCLUSIVE) && + (s_info[i].value != 0)) + { + oppose = TRUE; + oppose_skill = i; + break; + } + } + + /* 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 + */ + flush(); + + /* Prepare prompt */ + msg = format("This skill is mutually exclusive with " + "at least %s, continue?", + s_info[oppose_skill].name + s_name); + + /* The player rejected the choice */ + if (!get_check(msg)) continue; + } + + s_ptr = &s_info[skl[res]]; + s_ptr->value += val[res]; + s_ptr->mod += mod[res]; + if (mod[res]) + { + msg_format("You can now learn the %s skill.", + s_ptr->name + s_name); + } + else + { + msg_format("Your knowledge of the %s skill increases.", + s_ptr->name + s_name); + } + break; + } + } + + /* Check if some skills didn't influence other stuff */ + recalc_skills(FALSE); +} + + + + +/**************************************** ABILITIES *****************************************/ + +/* + * Given the name of an ability, returns ability index or -1 if no + * such ability is found + */ +s16b find_ability(cptr name) +{ + u16b i; + + /* Scan ability list */ + for (i = 0; i < max_ab_idx; i++) + { + /* The name matches */ + if (ab_info[i].name > 0) { + if (streq(ab_info[i].name + ab_name, name)) return (i); + } + } + + /* No match found */ + return ( -1); +} + +/* + * Do the player have the ability + */ +bool_ has_ability(int ab) +{ + return ab_info[ab].acquired; +} + +/* Do we meet the requirements */ +bool_ can_learn_ability(int ab) +{ + ability_type *ab_ptr = &ab_info[ab]; + int i; + + if (ab_ptr->acquired) + return FALSE; + + if (p_ptr->skill_points < ab_info[ab].cost) + return FALSE; + + for (i = 0; i < 10; i++) + { + /* Must have skill level */ + if (ab_ptr->skills[i] > -1) + { + 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 (!ab_info[ab_ptr->need_abilities[i]].acquired) + return FALSE; + } + + /* Must not have ability */ + if (ab_ptr->forbid_abilities[i] > -1) + { + if (ab_info[ab_ptr->forbid_abilities[i]].acquired) + return FALSE; + } + } + + for (i = 0; i < 6; i++) + { + /* Must have stat */ + if (ab_ptr->stat[i] > -1) + { + if (p_ptr->stat_ind[i] < ab_ptr->stat[i] - 3) + return FALSE; + } + } + + /* Do the script allow us? */ + if (process_hooks(HOOK_LEARN_ABILITY, "(d)", ab)) + return FALSE; + + return TRUE; +} + +/* Learn an ability */ +void gain_ability(int ab) +{ + int wid, hgt; + Term_get_size(&wid, &hgt); + + if (!can_learn_ability(ab)) + { + msg_box("You cannot learn this ability.", hgt / 2, wid / 2); + return; + } + + /* Flush input as we ask an important and irreversible question */ + flush(); + + /* Ask we can commit the change */ + if (msg_box("Learn this ability(this is permanent)? (y/n)", hgt / 2, wid / 2) != 'y') + { + return; + } + + ab_info[ab].acquired = TRUE; + p_ptr->skill_points -= ab_info[ab].cost; +} + +static bool compare_abilities(const int ab_idx1, const int ab_idx2) +{ + return strcmp(ab_name + ab_info[ab_idx1].name, + ab_name + ab_info[ab_idx2].name) < 0; +} + +/* + * Print the abilities list + */ +void dump_abilities(FILE *fff) +{ + int i; + + // Find all abilities that the player has. + std::vector table; + for (i = 0; i < max_ab_idx; i++) + { + if (ab_info[i].name && has_ability(i)) + { + table.push_back(i); + } + } + + // Sort + std::sort(std::begin(table), + std::end(table), + compare_abilities); + + // Show + if (!table.empty()) + { + fprintf(fff, "\nAbilities"); + + for (int i : table) + { + fprintf(fff, "\n * %s", ab_info[i].name + ab_name); + } + + fprintf(fff, "\n"); + } +} + +/* + * Draw the abilities list + */ +static void print_abilities(const std::vector &table, int sel, int start) +{ + int i, j; + int wid, hgt; + cptr keys; + + Term_clear(); + Term_get_size(&wid, &hgt); + + c_prt(TERM_WHITE, format("%s Abilities Screen", game_module), 0, 28); + 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); + + print_desc_aux(ab_info[table[sel]].desc + ab_text, 3, 0); + + for (j = start; j < start + (hgt - 7); j++) + { + byte color = TERM_WHITE; + char deb = ' ', end = ' '; + + if (j >= table.size()) + { + break; + } + + i = table[j]; + + if (ab_info[i].acquired) + color = TERM_L_BLUE; + else if (can_learn_ability(i)) + color = TERM_WHITE; + else + color = TERM_L_DARK; + + + if (j == sel) + { + color = TERM_L_GREEN; + deb = '['; + end = ']'; + } + + c_prt(color, format("%c.%c%s", deb, end, ab_info[i].name + ab_name), + j + 7 - start, 0); + + if (!ab_info[i].acquired) + { + c_prt(color, format("%d", ab_info[i].cost), j + 7 - start, 60); + } + else + { + c_prt(color, "Known", j + 7 - start, 60); + } + } +} + +/* + * Interreact with abilitiess + */ +void do_cmd_ability() +{ + int sel = 0, start = 0; + char c; + int i; + int wid, hgt; + + /* Save the screen */ + screen_save(); + + /* Clear the screen */ + Term_clear(); + + /* Initialise the abilities list */ + std::vector table; + for (i = 0; i < max_ab_idx; i++) + { + if (ab_info[i].name) + { + table.push_back(i); + } + } + + std::sort(std::begin(table), + std::end(table), + compare_abilities); + + while (TRUE) + { + Term_get_size(&wid, &hgt); + + /* Display list of skills */ + print_abilities(table, sel, start); + + /* Wait for user input */ + c = inkey(); + + /* Leave the skill screen */ + if (c == ESCAPE) + { + break; + } + + /* Next page */ + else if (c == 'n') + { + sel += (hgt - 7); + if (sel >= table.size()) + { + sel = table.size() - 1; + } + } + + /* Previous page */ + else if (c == 'p') + { + sel -= (hgt - 7); + if (sel < 0) sel = 0; + } + + /* Select / increase a skill */ + else + { + int dir; + + /* Allow use of numpad / arrow keys / roguelike keys */ + dir = get_keymap_dir(c); + + /* Move cursor down */ + if (dir == 2) sel++; + + /* Move cursor up */ + if (dir == 8) sel--; + + /* gain ability */ + if (dir == 6) gain_ability(table[sel]); + + /* XXX XXX XXX Wizard mode commands outside of wizard2.c */ + + if (wizard && (c == '+')) ab_info[table[sel]].acquired = TRUE; + if (wizard && (c == '-')) ab_info[table[sel]].acquired = FALSE; + + /* Contextual help */ + if (c == '?') + { + help_ability(ab_info[table[sel]].name + ab_name); + } + + /* Handle boundaries and scrolling */ + if (sel < 0) sel = table.size() - 1; + if (sel >= table.size()) sel = 0; + if (sel < start) start = sel; + if (sel >= start + (hgt - 7)) start = sel - (hgt - 7) + 1; + } + } + + /* Load the screen */ + screen_load(); + + /* Update stuffs */ + p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS | PU_POWERS | + PU_SANITY | PU_BODY); + + /* Redraw various info */ + p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP); +} + +/* + * Apply abilities to be granted this level + */ +void apply_level_abilities(int level) +{ + int i; + + for (i = 0; i < 10; i++) + { + if (cp_ptr->abilities[i].level == level) + { + if ((level > 1) && (!ab_info[cp_ptr->abilities[i].ability].acquired)) + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[cp_ptr->abilities[i].ability].name); + ab_info[cp_ptr->abilities[i].ability].acquired = TRUE; + } + if (spp_ptr->abilities[i].level == level) + { + if ((level > 1) && (!ab_info[spp_ptr->abilities[i].ability].acquired)) + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[spp_ptr->abilities[i].ability].name); + ab_info[spp_ptr->abilities[i].ability].acquired = TRUE; + } + if (rp_ptr->abilities[i].level == level) + { + if ((level > 1) && (!ab_info[rp_ptr->abilities[i].ability].acquired)) + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[rp_ptr->abilities[i].ability].name); + ab_info[rp_ptr->abilities[i].ability].acquired = TRUE; + } + if (rmp_ptr->abilities[i].level == level) + { + if ((level > 1) && (!ab_info[rmp_ptr->abilities[i].ability].acquired)) + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[rmp_ptr->abilities[i].ability].name); + ab_info[rmp_ptr->abilities[i].ability].acquired = TRUE; + } + } +} -- cgit v1.2.3 From a9c4798ddb2f5ed52c7bcdac6b83510f62996795 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 15 Jul 2013 22:17:36 +0200 Subject: Make Weighted Random Selection algorithm higher level --- src/skills.cc | 79 +++++++++++++++++++++++------------------------------------ 1 file changed, 30 insertions(+), 49 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 221a5e27..b5b90d77 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -12,12 +12,12 @@ #include "angband.h" -#include #include "hooks.h" #include "util.hpp" #include #include +#include #include #include #include @@ -1240,19 +1240,18 @@ void init_skill(s32b value, s32b mod, int i) } /* - * Perform weighted random selection without replacement according to - * the algorithm given in "Weighted Random Sampling" (2005, Eframidis, - * Spirakis) + * Perform weighted random shuffle according to the algorithm given in + * "Weighted Random Sampling" (2005, Eframidis, Spirakis). * - * @param k is the total number of items to choose. This MUST be smaller than or equal to the number of weights. - * @param weights is the array of weights. - * @return an output vector of size k containing the chosen indices. + * @param weights is the vector of weights. + * @return an output vector of the same size as the input weights vector containing, + * in order of selection, the indices to select. For example, if you + * need to choose two items, you would use v[0], v[1] as the indices + * to pick. */ -static std::vector wrs_without_replacement(size_t k, const std::vector &unscaled_weights) +static std::vector wrs(const std::vector &unscaled_weights) { - size_t n = unscaled_weights.size(); - - assert(k <= n); + const size_t n = unscaled_weights.size(); /* Rescale weights into unit interval for numerical stability */ std::vector weights(unscaled_weights.size()); @@ -1270,47 +1269,30 @@ static std::vector wrs_without_replacement(size_t k, const std::vector keys(unscaled_weights.size()); + /* Generate the keys and indexes to use for selection. This + is the only randomized portion of the algorithm. */ + std::vector> keys_and_indexes(unscaled_weights.size()); for (size_t i = 0; i < n; i++) { - double u = ((double) rand_int(100000)) / ((double) 100000); - keys[i] = pow(u, 1/weights[i]); + /* Randomized keys according to the algorithm. */ + double u = static_cast(rand_int(100000)) / 100000; + double k = std::pow(u, 1/weights[i]); + /* Set up the key and index. We negate the k value + here so that keys will be sorted in descending + order rather than ascending order. */ + keys_and_indexes[i] = std::make_tuple(-k, i); } - /* Generate the initial permutation */ - std::vector permutation(unscaled_weights.size()); - for (size_t i = 0; i < n; i++) { - permutation[i] = i; - } + /* Sort indexes according to keys. Since the keys have been + negated and we're using a lexicographical sort, we're + effectively sorting in descending order of key. */ + std::sort(std::begin(keys_and_indexes), + std::end(keys_and_indexes)); - /* Select the k indexes with the largest keys */ + /* Produce the output vector consisting of indexes only. */ std::vector indexes; - for (size_t i = 0; i < k; i++) { - /* Find maximal value and its index */ - size_t max_idx = i; - double max_value = keys[max_idx]; - for (size_t j = i + 1; j < n; j++) { - if (keys[j] > max_value) { - max_idx = j; - max_value = keys[j]; - } - } - - /* Swap into k'th position */ - if (max_idx != i) { - /* Swap keys */ - std::swap(keys[i], keys[max_idx]); - /* Swap indexes in permutation */ - std::swap(permutation[i], permutation[max_idx]); - } - - /* Output the k'th choice. We can do this already - since we'll never revisit the i'th position in - permutation vector. */ - indexes.push_back(permutation[i]); + for (auto const &key_and_index: keys_and_indexes) { + indexes.push_back(std::get<1>(key_and_index)); } - return indexes; } @@ -1341,9 +1323,8 @@ void do_get_new_skill() weights.push_back(s_info[available_skills[i]].random_gain_chance); } - std::vector indexes = - wrs_without_replacement(LOST_SWORD_NSKILLS, weights); - assert(indexes.size() == LOST_SWORD_NSKILLS); + std::vector indexes = wrs(weights); + assert(indexes.size() >= LOST_SWORD_NSKILLS); /* Extract the information needed from the skills */ for (i = 0; i < LOST_SWORD_NSKILLS; i++) -- cgit v1.2.3 From ca71ccff098e4eec97480d2a08773a06629cc66e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 26 Jun 2014 06:50:06 +0200 Subject: Simplify PR_* redraw code and remove direct references to Term members --- src/skills.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index b5b90d77..6fefd84f 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -402,7 +402,7 @@ void recalc_skills(bool_ init) PU_SANITY | PU_BODY); /* Redraw various info */ - p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP); + p_ptr->redraw |= (PR_WIPE | PR_FRAME | PR_MAP); } } @@ -732,7 +732,7 @@ static void choose_melee() p_ptr->update |= (PU_HP); /* Redraw monster hitpoint */ - p_ptr->redraw |= (PR_MH); + p_ptr->redraw |= (PR_FRAME); Term_load(); character_icky = FALSE; @@ -1755,7 +1755,7 @@ void do_cmd_ability() PU_SANITY | PU_BODY); /* Redraw various info */ - p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP); + p_ptr->redraw |= (PR_WIPE | PR_FRAME | PR_MAP); } /* -- cgit v1.2.3 From 27b26f3940a589d8df800254b66de87f75b28758 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 14 Dec 2013 10:31:53 +0100 Subject: Fix a typo in article author's name --- src/skills.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 6fefd84f..27741dc5 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -1241,7 +1241,7 @@ void init_skill(s32b value, s32b mod, int i) /* * Perform weighted random shuffle according to the algorithm given in - * "Weighted Random Sampling" (2005, Eframidis, Spirakis). + * "Weighted Random Sampling" (2005, Efraimidis, Spirakis). * * @param weights is the vector of weights. * @return an output vector of the same size as the input weights vector containing, -- cgit v1.2.3 From ff252acf7f2f38e33017e82881c95825b54c7cee Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 16 Dec 2014 18:28:59 +0100 Subject: Replace uses of stricmp with boost::algorithm::iequals --- src/skills.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 27741dc5..12c1fb3d 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -16,12 +16,14 @@ #include "util.hpp" #include +#include #include #include #include #include #include +using boost::algorithm::iequals; /* * Advance the skill point of the skill specified by i and @@ -119,7 +121,7 @@ s16b find_skill_i(cptr name) { /* The name matches */ if (s_info[i].name > 0) { - if (0 == stricmp(s_info[i].name + s_name, name)) return (i); + if (iequals(s_info[i].name + s_name, name)) return (i); } } -- cgit v1.2.3 From 07331bfbf3fc2096241194a491047a13af9f2cb4 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 21 Dec 2014 15:45:42 +0100 Subject: Remove unused HOOK_LEARN_ABILITY --- src/skills.cc | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 12c1fb3d..63c9ad72 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -1515,10 +1515,6 @@ bool_ can_learn_ability(int ab) } } - /* Do the script allow us? */ - if (process_hooks(HOOK_LEARN_ABILITY, "(d)", ab)) - return FALSE; - return TRUE; } -- cgit v1.2.3 From 9f93aa171a1a919203aeb579388ab14cec788f53 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 21 Dec 2014 15:49:26 +0100 Subject: Remove old-style HOOK_RECALC_SKILLS invocation --- src/skills.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 63c9ad72..3d96300d 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -396,7 +396,6 @@ void recalc_skills(bool_ init) abandon_god(GOD_ALL); } - process_hooks(HOOK_RECALC_SKILLS, "()"); process_hooks_new(HOOK_RECALC_SKILLS, NULL, NULL); /* Update stuffs */ -- cgit v1.2.3 From a2c6896585d13c420b9f6c8984054eae27e036a9 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 23 Dec 2014 17:37:12 +0100 Subject: Make a few functions in skills.cc static --- src/skills.cc | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 3d96300d..26e1537d 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -71,7 +71,7 @@ static void increase_skill(int i, s16b *invest) * Descrease the skill point of the skill specified by i and * modify related skills */ -void decrease_skill(int i, s16b *invest) +static void decrease_skill(int i, s16b *invest) { /* Cannot decrease more */ if (!invest[i]) return; @@ -162,15 +162,9 @@ s16b get_skill_scale(int skill, u32b scale) return (temp / SKILL_MAX); } - -/* - * - */ -int get_idx(int i) +static int get_idx(int i) { - int j; - - for (j = 1; j < max_s_idx; j++) + for (int j = 1; j < max_s_idx; j++) { if (s_info[j].order == i) return (j); @@ -199,17 +193,11 @@ static bool_ is_known(int s_idx) return FALSE; } -/* - * - */ -void init_table_aux(int table[MAX_SKILLS][2], int *idx, int father, int lev, - bool_ full) +static void init_table_aux(int table[MAX_SKILLS][2], int *idx, int father, int lev, bool_ full) { - int j, i; - - for (j = 1; j < max_s_idx; j++) + for (int j = 1; j < max_s_idx; j++) { - i = get_idx(j); + int i = get_idx(j); if (s_info[i].father != father) continue; if (s_info[i].hidden) continue; if (!is_known(i)) continue; @@ -221,15 +209,13 @@ void init_table_aux(int table[MAX_SKILLS][2], int *idx, int father, int lev, } } - -void init_table(int table[MAX_SKILLS][2], int *max, bool_ full) +static void init_table(int table[MAX_SKILLS][2], int *max, bool_ full) { *max = 0; init_table_aux(table, max, -1, 0, full); } - -bool_ has_child(int sel) +static bool_ has_child(int sel) { int i; @@ -788,7 +774,7 @@ static void print_skill_batch(const std::vector> &p, int s prt(format("Select a skill (a-%c), @ to select by name, +/- to scroll:", I2A(j - 1)), 0, 0); } -int do_cmd_activate_skill_aux() +static int do_cmd_activate_skill_aux() { char which; int i, start = 0; @@ -1469,7 +1455,7 @@ bool_ has_ability(int ab) } /* Do we meet the requirements */ -bool_ can_learn_ability(int ab) +static bool_ can_learn_ability(int ab) { ability_type *ab_ptr = &ab_info[ab]; int i; @@ -1518,7 +1504,7 @@ bool_ can_learn_ability(int ab) } /* Learn an ability */ -void gain_ability(int ab) +static void gain_ability(int ab) { int wid, hgt; Term_get_size(&wid, &hgt); -- cgit v1.2.3 From b1f5178bdabafde20eb65df6256b53dc5968b2e2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:56 +0100 Subject: Apply trivial warning cleanups --- src/skills.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 26e1537d..37e84c57 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -792,11 +792,10 @@ static int do_cmd_activate_skill_aux() { if (s_info[i].action_mkey && s_info[i].value && ((!s_info[i].hidden) || (i == SKILL_LEARN))) { - int j; bool_ next = FALSE; /* Already got it ? */ - for (j = 0; j < p.size(); j++) + for (size_t j = 0; j < p.size(); j++) { if (s_info[i].action_mkey == std::get<1>(p[j])) { @@ -815,11 +814,10 @@ static int do_cmd_activate_skill_aux() { if (ab_info[i].action_mkey && ab_info[i].acquired) { - int j; bool_ next = FALSE; /* Already got it ? */ - for (j = 0; j < p.size(); j++) + for (size_t j = 0; j < p.size(); j++) { if (ab_info[i].action_mkey == std::get<1>(p[j])) { -- cgit v1.2.3 From 61e8cfc1d553b2bc0cce6b0dd56b03f51f187423 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:56 +0100 Subject: Clean up warnings about signed/unsigned comparisons --- src/skills.cc | 57 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 18 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 37e84c57..e8291ce4 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -752,13 +752,13 @@ void select_default_melee() static void print_skill_batch(const std::vector> &p, int start) { char buff[80]; - int i = start, j = 0; + int j = 0; prt(format(" %-31s", "Name"), 1, 20); - for (i = start; i < (start + 20); i++) + for (int i = start; i < (start + 20); i++) { - if (i >= p.size()) + if (static_cast(i) >= p.size()) { break; } @@ -777,7 +777,7 @@ static void print_skill_batch(const std::vector> &p, int s static int do_cmd_activate_skill_aux() { char which; - int i, start = 0; + int start = 0; int ret; std::vector> p; @@ -788,7 +788,7 @@ static int do_cmd_activate_skill_aux() p.push_back(std::make_tuple("Change melee mode", 0)); } - for (i = 1; i < max_s_idx; i++) + for (size_t i = 1; i < max_s_idx; i++) { if (s_info[i].action_mkey && s_info[i].value && ((!s_info[i].hidden) || (i == SKILL_LEARN))) { @@ -810,7 +810,7 @@ static int do_cmd_activate_skill_aux() } } - for (i = 0; i < max_ab_idx; i++) + for (size_t i = 0; i < max_ab_idx; i++) { if (ab_info[i].action_mkey && ab_info[i].acquired) { @@ -854,14 +854,20 @@ static int do_cmd_activate_skill_aux() else if (which == '+') { start += 20; - if (start >= p.size()) start -= 20; + if (static_cast(start) >= p.size()) + { + start -= 20; + } Term_load(); character_icky = FALSE; } else if (which == '-') { start -= 20; - if (start < 0) start += 20; + if (start < 0) + { + start += 20; + } Term_load(); character_icky = FALSE; } @@ -874,22 +880,23 @@ static int do_cmd_activate_skill_aux() return FALSE; /* Find the skill it is related to */ - for (i = 0; i < p.size(); i++) + size_t i = 0; + for (; i < p.size(); i++) { if (!strcmp(buf, std::get<0>(p[i]))) break; } - if ((i < p.size())) + + if (i < p.size()) { ret = std::get<1>(p[i]); break; } - } else { which = tolower(which); - if (start + A2I(which) >= p.size()) + if (start + A2I(which) >= static_cast(p.size())) { bell(); continue; @@ -1593,7 +1600,8 @@ static void print_abilities(const std::vector &table, int sel, int start) byte color = TERM_WHITE; char deb = ' ', end = ' '; - if (j >= table.size()) + assert(j >= 0); + if (static_cast(j) >= table.size()) { break; } @@ -1679,7 +1687,8 @@ void do_cmd_ability() else if (c == 'n') { sel += (hgt - 7); - if (sel >= table.size()) + assert(sel >= 0); + if (static_cast(sel) >= table.size()) { sel = table.size() - 1; } @@ -1721,10 +1730,22 @@ void do_cmd_ability() } /* Handle boundaries and scrolling */ - if (sel < 0) sel = table.size() - 1; - if (sel >= table.size()) sel = 0; - if (sel < start) start = sel; - if (sel >= start + (hgt - 7)) start = sel - (hgt - 7) + 1; + if (sel < 0) + { + sel = table.size() - 1; + } + if (static_cast(sel) >= table.size()) + { + sel = 0; + } + if (sel < start) + { + start = sel; + } + if (sel >= start + (hgt - 7)) + { + start = sel - (hgt - 7) + 1; + } } } -- cgit v1.2.3 From 06365ca3274fc48b3c0b69418c1f8ee0d63a9a37 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: Remove a few unused fields in player_type --- src/skills.cc | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index e8291ce4..0d3c39a3 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -1003,9 +1003,6 @@ void do_cmd_activate_skill() case MKEY_TELEKINESIS: do_cmd_portable_hole(); break; - case MKEY_BLADE: - do_cmd_blade(); - break; case MKEY_SUMMON: do_cmd_summoner(); break; -- cgit v1.2.3 From 3f59d3d407cd743f4e4b27791c4fe13785f8669d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove ab_head, ab_name, ab_text --- src/skills.cc | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 0d3c39a3..3ed64d17 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -827,7 +827,7 @@ static int do_cmd_activate_skill_aux() } if (next) continue; - p.push_back(std::make_tuple(ab_text + ab_info[i].action_desc, + p.push_back(std::make_tuple(ab_info[i].action_desc, ab_info[i].action_mkey)); } } @@ -1438,9 +1438,9 @@ s16b find_ability(cptr name) /* Scan ability list */ for (i = 0; i < max_ab_idx; i++) { - /* The name matches */ - if (ab_info[i].name > 0) { - if (streq(ab_info[i].name + ab_name, name)) return (i); + if (ab_info[i].name && streq(ab_info[i].name, name)) + { + return (i); } } @@ -1532,8 +1532,7 @@ static void gain_ability(int ab) static bool compare_abilities(const int ab_idx1, const int ab_idx2) { - return strcmp(ab_name + ab_info[ab_idx1].name, - ab_name + ab_info[ab_idx2].name) < 0; + return strcmp(ab_info[ab_idx1].name, ab_info[ab_idx2].name) < 0; } /* @@ -1565,7 +1564,7 @@ void dump_abilities(FILE *fff) for (int i : table) { - fprintf(fff, "\n * %s", ab_info[i].name + ab_name); + fprintf(fff, "\n * %s", ab_info[i].name); } fprintf(fff, "\n"); @@ -1590,7 +1589,7 @@ static void print_abilities(const std::vector &table, int sel, int start) 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 + ab_text, 3, 0); + print_desc_aux(ab_info[table[sel]].desc, 3, 0); for (j = start; j < start + (hgt - 7); j++) { @@ -1620,7 +1619,7 @@ static void print_abilities(const std::vector &table, int sel, int start) end = ']'; } - c_prt(color, format("%c.%c%s", deb, end, ab_info[i].name + ab_name), + c_prt(color, format("%c.%c%s", deb, end, ab_info[i].name), j + 7 - start, 0); if (!ab_info[i].acquired) @@ -1723,7 +1722,7 @@ void do_cmd_ability() /* Contextual help */ if (c == '?') { - help_ability(ab_info[table[sel]].name + ab_name); + help_ability(ab_info[table[sel]].name); } /* Handle boundaries and scrolling */ @@ -1769,25 +1768,33 @@ void apply_level_abilities(int level) if (cp_ptr->abilities[i].level == level) { if ((level > 1) && (!ab_info[cp_ptr->abilities[i].ability].acquired)) - cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[cp_ptr->abilities[i].ability].name); + { + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_info[cp_ptr->abilities[i].ability].name); + } ab_info[cp_ptr->abilities[i].ability].acquired = TRUE; } if (spp_ptr->abilities[i].level == level) { if ((level > 1) && (!ab_info[spp_ptr->abilities[i].ability].acquired)) - cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[spp_ptr->abilities[i].ability].name); + { + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_info[spp_ptr->abilities[i].ability].name); + } ab_info[spp_ptr->abilities[i].ability].acquired = TRUE; } if (rp_ptr->abilities[i].level == level) { if ((level > 1) && (!ab_info[rp_ptr->abilities[i].ability].acquired)) - cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[rp_ptr->abilities[i].ability].name); + { + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_info[rp_ptr->abilities[i].ability].name); + } ab_info[rp_ptr->abilities[i].ability].acquired = TRUE; } if (rmp_ptr->abilities[i].level == level) { if ((level > 1) && (!ab_info[rmp_ptr->abilities[i].ability].acquired)) - cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[rmp_ptr->abilities[i].ability].name); + { + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_info[rmp_ptr->abilities[i].ability].name); + } ab_info[rmp_ptr->abilities[i].ability].acquired = TRUE; } } -- cgit v1.2.3 From 58e8024f17446bf3b1a36985d746f6de330874c0 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove s_head, s_name, s_text --- src/skills.cc | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 3ed64d17..a31b3fcd 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -102,10 +102,9 @@ s16b find_skill(cptr name) /* Scan skill list */ for (i = 1; i < max_s_idx; i++) { - /* The name matches */ - if (s_info[i].name > 0) + if (s_info[i].name && streq(s_info[i].name, name)) { - if (streq(s_info[i].name + s_name, name)) return (i); + return (i); } } @@ -120,8 +119,9 @@ s16b find_skill_i(cptr name) for (i = 1; i < max_s_idx; i++) { /* The name matches */ - if (s_info[i].name > 0) { - if (iequals(s_info[i].name + s_name, name)) return (i); + if (s_info[i].name && iequals(s_info[i].name, name)) + { + return (i); } } @@ -258,11 +258,11 @@ void dump_skills(FILE *fff) if (!has_child(i)) { - strcat(buf, format(" . %s", s_info[i].name + s_name)); + strcat(buf, format(" . %s", s_info[i].name)); } else { - strcat(buf, format(" - %s", s_info[i].name + s_name)); + strcat(buf, format(" - %s", s_info[i].name)); } fprintf(fff, "%-49s%s%06.3f [%05.3f]", @@ -292,7 +292,7 @@ void print_skills(int table[MAX_SKILLS][2], int max, int sel, int start) 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); - print_desc_aux(s_info[table[sel][0]].desc + s_text, 3, 0); + print_desc_aux(s_info[table[sel][0]].desc, 3, 0); for (j = start; j < start + (hgt - 7); j++) { @@ -318,17 +318,17 @@ void print_skills(int table[MAX_SKILLS][2], int max, int sel, int start) } if (!has_child(i)) { - c_prt(color, format("%c.%c%s", deb, end, s_info[i].name + s_name), + c_prt(color, format("%c.%c%s", deb, end, s_info[i].name), j + 7 - start, table[j][1] * 4); } else if (s_info[i].dev) { - c_prt(color, format("%c-%c%s", deb, end, s_info[i].name + s_name), + c_prt(color, format("%c-%c%s", deb, end, s_info[i].name), j + 7 - start, table[j][1] * 4); } else { - c_prt(color, format("%c+%c%s", deb, end, s_info[i].name + s_name), + c_prt(color, format("%c+%c%s", deb, end, s_info[i].name), j + 7 - start, table[j][1] * 4); } c_prt(color, @@ -558,7 +558,7 @@ void do_cmd_skill() /* Contextual help */ if (c == '?') { - help_skill(s_info[table[sel][0]].name + s_name); + help_skill(s_info[table[sel][0]].name); } /* Handle boundaries and scrolling */ @@ -805,7 +805,7 @@ static int do_cmd_activate_skill_aux() } if (next) continue; - p.push_back(std::make_tuple(s_text + s_info[i].action_desc, + p.push_back(std::make_tuple(s_info[i].action_desc, s_info[i].action_mkey)); } } @@ -1352,7 +1352,12 @@ void do_get_new_skill() } skl[i] = s_idx; - items.push_back(format("%-40s: +%02ld.%03ld value, +%01d.%03d modifier", s_ptr->name + s_name, val[i] / SKILL_STEP, val[i] % SKILL_STEP, mod[i] / SKILL_STEP, mod[i] % SKILL_STEP)); + items.push_back(format("%-40s: +%02ld.%03ld value, +%01d.%03d modifier", + s_ptr->name, + val[i] / SKILL_STEP, + val[i] % SKILL_STEP, + mod[i] / SKILL_STEP, + mod[i] % SKILL_STEP)); } while (TRUE) @@ -1395,7 +1400,7 @@ void do_get_new_skill() /* Prepare prompt */ msg = format("This skill is mutually exclusive with " "at least %s, continue?", - s_info[oppose_skill].name + s_name); + s_info[oppose_skill].name); /* The player rejected the choice */ if (!get_check(msg)) continue; @@ -1407,12 +1412,12 @@ void do_get_new_skill() if (mod[res]) { msg_format("You can now learn the %s skill.", - s_ptr->name + s_name); + s_ptr->name); } else { msg_format("Your knowledge of the %s skill increases.", - s_ptr->name + s_name); + s_ptr->name); } break; } -- cgit v1.2.3 From ee2595abc99b86f081acbf5479577f9548baff3b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Move gods.cc function declarations to separate header --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index a31b3fcd..31897a94 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -12,6 +12,7 @@ #include "angband.h" +#include "gods.hpp" #include "hooks.h" #include "util.hpp" -- cgit v1.2.3 From dc4b789acb2e6737dd6ed5721b3efbde1a2be14f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Move skills.cc function declarations to skills.hpp --- src/skills.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 31897a94..5df8af64 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -608,13 +608,13 @@ void do_cmd_skill() /* * List of melee skills */ -s16b melee_skills[MAX_MELEE] = +static s16b melee_skills[MAX_MELEE] = { SKILL_MASTERY, SKILL_HAND, SKILL_BEAR, }; -const char *melee_names[MAX_MELEE] = +static const char *melee_names[MAX_MELEE] = { "Weapon combat", "Barehanded combat", @@ -635,6 +635,11 @@ s16b get_melee_skill() return (0); } +cptr get_melee_name() +{ + return melee_names[get_melee_skill()]; +} + s16b get_melee_skills() { int i, j = 0; -- cgit v1.2.3 From 5ef53fee463b7f93b8b890ed8e6ff0db778bd596 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Move xtra2.cc functions to separate header Remove some functions and make others static while we're at it. --- src/skills.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 5df8af64..797bf131 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -1,7 +1,3 @@ -/* File: skills.c */ - -/* Purpose: player skills */ - /* * Copyright (c) 2001 DarkGod * @@ -15,6 +11,7 @@ #include "gods.hpp" #include "hooks.h" #include "util.hpp" +#include "xtra2.hpp" #include #include -- cgit v1.2.3 From 21bbf94c159d161058282696630e0e0431917e92 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move birth.cc function declarations to separate header We leave the no_begin_screen variable because it needs to be accessed by non-C++ code. --- src/skills.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 797bf131..591f184e 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -7,7 +7,7 @@ */ #include "angband.h" - +#include "birth.hpp" #include "gods.hpp" #include "hooks.h" #include "util.hpp" -- cgit v1.2.3 From 754e2465d65f64085d27eed6f4bc142bec7b3c24 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move help.cc function declarations to separate header --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 591f184e..2dbcb6ca 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -9,6 +9,7 @@ #include "angband.h" #include "birth.hpp" #include "gods.hpp" +#include "help.hpp" #include "hooks.h" #include "util.hpp" #include "xtra2.hpp" -- cgit v1.2.3 From f995c99cc4b7c0695b3642c8bbac06124874ffcb Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cmd2.cc function declarations to separate header --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 2dbcb6ca..700405b8 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -8,6 +8,7 @@ #include "angband.h" #include "birth.hpp" +#include "cmd2.hpp" #include "gods.hpp" #include "help.hpp" #include "hooks.h" -- cgit v1.2.3 From 3a6e755dd2efe4e7d72515d4c0041cc3042d0c5f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cmd3.cc function declarations to separate header --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 700405b8..9bbefd24 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -9,6 +9,7 @@ #include "angband.h" #include "birth.hpp" #include "cmd2.hpp" +#include "cmd3.hpp" #include "gods.hpp" #include "help.hpp" #include "hooks.h" -- cgit v1.2.3 From 6cffbd70646ee66c3b2a2a2fd7fd35c23d88b93e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cmd5.cc function declarations to separate header file Make a few of functions static, remove dead code and fix a few stray declarations while we're at it. --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 9bbefd24..4c8a3601 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -10,6 +10,7 @@ #include "birth.hpp" #include "cmd2.hpp" #include "cmd3.hpp" +#include "cmd5.hpp" #include "gods.hpp" #include "help.hpp" #include "hooks.h" -- cgit v1.2.3 From 91964ee9dd97c6c41a3551aba5af6fae67989e4f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cmd7.cc function declarations to separate header file Make a few of the functions static while we're at it. --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 4c8a3601..88549078 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -11,6 +11,7 @@ #include "cmd2.hpp" #include "cmd3.hpp" #include "cmd5.hpp" +#include "cmd7.hpp" #include "gods.hpp" #include "help.hpp" #include "hooks.h" -- cgit v1.2.3 From f19edf28cf16a0776f54753d953901b91f54e278 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split traps.cc function declarations to separate file --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 88549078..f1e121c7 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -15,6 +15,7 @@ #include "gods.hpp" #include "help.hpp" #include "hooks.h" +#include "traps.hpp" #include "util.hpp" #include "xtra2.hpp" -- cgit v1.2.3 From 901657b0c61ab16cceaef875d3ecd0b9f2bbbc5b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split spells1.cc declarations to separate header file Make a couple of the functions static while we're at it --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index f1e121c7..84715150 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -15,6 +15,7 @@ #include "gods.hpp" #include "help.hpp" #include "hooks.h" +#include "spells1.hpp" #include "traps.hpp" #include "util.hpp" #include "xtra2.hpp" -- cgit v1.2.3 From 0f610b77f2016ca80b18fdfb7a0bdd6eeb804743 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split spells4.cc declarations into separate header file --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 84715150..c3fb3835 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -16,6 +16,7 @@ #include "help.hpp" #include "hooks.h" #include "spells1.hpp" +#include "spells4.hpp" #include "traps.hpp" #include "util.hpp" #include "xtra2.hpp" -- cgit v1.2.3 From 37ac44add61e4547507770017dcb85b53c20acb5 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split util.cc function declarations into separate header files We need one .h file and one .hpp since some of the functions are being called from plain C code. --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index c3fb3835..1e73ed25 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -19,6 +19,7 @@ #include "spells4.hpp" #include "traps.hpp" #include "util.hpp" +#include "util.h" #include "xtra2.hpp" #include -- cgit v1.2.3 From d379c47aaec011921c1d09140ee1098a7053b5b6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split monster2.cc declarations into separate header --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 1e73ed25..3e11bfe4 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -15,6 +15,7 @@ #include "gods.hpp" #include "help.hpp" #include "hooks.h" +#include "monster2.hpp" #include "spells1.hpp" #include "spells4.hpp" #include "traps.hpp" -- cgit v1.2.3 From d2b23810e3349e7cb12d8c51d2a630c6a31d7cd0 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split monster3.cc declarations to separate header file --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 3e11bfe4..ec48d8f7 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -16,6 +16,7 @@ #include "help.hpp" #include "hooks.h" #include "monster2.hpp" +#include "monster3.hpp" #include "spells1.hpp" #include "spells4.hpp" #include "traps.hpp" -- cgit v1.2.3 From cfc0a04155eda35a4fe80ef72fd2b0f9eb10856b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:41 +0100 Subject: Split object*.cc declarations into separate header files --- src/skills.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index ec48d8f7..b7a94e17 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -17,6 +17,8 @@ #include "hooks.h" #include "monster2.hpp" #include "monster3.hpp" +#include "object1.hpp" +#include "object2.hpp" #include "spells1.hpp" #include "spells4.hpp" #include "traps.hpp" -- cgit v1.2.3 From 05f1835fd9ec10fa3dd3c9962605e889ec0fc698 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:41 +0100 Subject: Move lua_bind.cc declarations to separate header file --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index b7a94e17..0832f294 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -15,6 +15,7 @@ #include "gods.hpp" #include "help.hpp" #include "hooks.h" +#include "lua_bind.hpp" #include "monster2.hpp" #include "monster3.hpp" #include "object1.hpp" -- cgit v1.2.3 From f93c700dc8320da438ad46b59b2541e29d9b6d68 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:42 +0100 Subject: Split tables.cc declarations into separate header files --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 0832f294..b67c8cae 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -22,6 +22,7 @@ #include "object2.hpp" #include "spells1.hpp" #include "spells4.hpp" +#include "tables.hpp" #include "traps.hpp" #include "util.hpp" #include "util.h" -- cgit v1.2.3 From 6f612c6e6cf9b20c00fd2f515d3694d2b7f7f444 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:42 +0100 Subject: Split variables.cc declarations to separate header files - Can now remove externs.h. Yay! - Put a stray option variable into its rightful place in options.hpp --- src/skills.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index b67c8cae..c6d609c0 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -26,6 +26,8 @@ #include "traps.hpp" #include "util.hpp" #include "util.h" +#include "variable.h" +#include "variable.hpp" #include "xtra2.hpp" #include -- cgit v1.2.3 From b11197ae79d621c50d89f6a092a3f95f954712f0 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 22 Mar 2015 13:05:39 +0100 Subject: Inline various GOD macros --- src/skills.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index c6d609c0..5b93ce2e 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -1170,7 +1170,7 @@ bool_ forbid_gloves() /* Which gods forbid edged weapons */ bool_ forbid_non_blessed() { - GOD(GOD_ERU) return (TRUE); + if (p_ptr->pgod == GOD_ERU) return (TRUE); return (FALSE); } -- cgit v1.2.3 From c17c9486a22ce9f2160b2d2ad559d9a19e453f83 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 22 Mar 2015 15:22:02 +0100 Subject: Rename miscellaneous .h headers to .hpp --- src/skills.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 5b93ce2e..87aebd9c 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -14,7 +14,7 @@ #include "cmd7.hpp" #include "gods.hpp" #include "help.hpp" -#include "hooks.h" +#include "hooks.hpp" #include "lua_bind.hpp" #include "monster2.hpp" #include "monster3.hpp" -- cgit v1.2.3 From 92344ee3f306ecdfd1da4365ffc5cab6eaa29afd Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 22 Mar 2015 18:17:06 +0100 Subject: Fix a wrap-around in skills menu The previous implementation would result in undefined behavior when wrapping around 0. --- src/skills.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 87aebd9c..787cbfa5 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -554,7 +554,7 @@ void do_cmd_skill() if (dir == 8) sel--; /* Miscellaneous skills cannot be increased/decreased as a group */ - if (table[sel][0] == SKILL_MISC) continue; + if ((sel >= 0) && (sel < max) && table[sel][0] == SKILL_MISC) continue; /* Increase the current skill */ if (dir == 6) increase_skill(table[sel][0], skill_invest.get()); -- cgit v1.2.3 From 7d5abc9c35e080555d1841234497ad1b06528f3a Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 22 Mar 2015 19:32:29 +0100 Subject: Split struct ability_type into separate header file --- src/skills.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 787cbfa5..7936b68c 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -6,7 +6,10 @@ * included in all such copies. */ +#include "skills.hpp" + #include "angband.h" +#include "ability_type.hpp" #include "birth.hpp" #include "cmd2.hpp" #include "cmd3.hpp" -- cgit v1.2.3 From c8a270e51dc22f39ed048ab1cc609e6e456df58f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 7 Jun 2015 17:49:09 +0200 Subject: Split types.h into separate header for each type --- src/skills.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 7936b68c..a5808b37 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -8,7 +8,6 @@ #include "skills.hpp" -#include "angband.h" #include "ability_type.hpp" #include "birth.hpp" #include "cmd2.hpp" @@ -23,6 +22,12 @@ #include "monster3.hpp" #include "object1.hpp" #include "object2.hpp" +#include "player_class.hpp" +#include "player_race.hpp" +#include "player_race_mod.hpp" +#include "player_spec.hpp" +#include "player_type.hpp" +#include "skill_type.hpp" #include "spells1.hpp" #include "spells4.hpp" #include "tables.hpp" -- cgit v1.2.3 From 000f6272f8ab1d43ec6300fb5972f7813ada1c88 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 11 Jun 2015 07:20:42 +0200 Subject: Remove dead Portable Hole code --- src/skills.cc | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index a5808b37..330aa9ba 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -1028,9 +1028,6 @@ void do_cmd_activate_skill() case MKEY_INCARNATION: do_cmd_possessor(); break; - case MKEY_TELEKINESIS: - do_cmd_portable_hole(); - break; case MKEY_SUMMON: do_cmd_summoner(); break; -- cgit v1.2.3 From 33e7dc3baa6b375efb6d8989ffe3c50511291228 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Remove Alchemist class and associated skills/code Alchemy has always been ridiculously broken and there's been a huge amount of horrible code to support it. Sorry to any fans of Alchemy, but it's got to go. --- src/skills.cc | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 330aa9ba..997b3bc8 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -1010,9 +1010,6 @@ void do_cmd_activate_skill() case MKEY_MINDCRAFT: do_cmd_mindcraft(); break; - case MKEY_ALCHEMY: - do_cmd_alchemist(); - break; case MKEY_MIMIC: do_cmd_mimic(); break; -- cgit v1.2.3 From 97bcf1bc612d9920390c885b8dcea0b0cda6f246 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Migrate z-rand.c to C++ - Include explicitly instead of via angband.h - Change to regular functions instead of macros. --- src/skills.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/skills.cc') diff --git a/src/skills.cc b/src/skills.cc index 997b3bc8..3a14a6ce 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -37,6 +37,7 @@ #include "variable.h" #include "variable.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include #include -- cgit v1.2.3