summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-10-05 18:45:08 +0200
committerBardur Arantsson <bardur@scientician.net>2016-10-05 18:49:37 +0200
commit765e1a3dc7abce3a849b8d1f124ada7a6984154a (patch)
tree0a4530d2091f05b70638f2eb833ae9b7238e4927
parent5869c5622e4345ffd50e0713d188f2d283b61caa (diff)
Move s_{info,descriptors} to Game/GameEdtiData
-rw-r--r--lib/edit/misc.txt3
-rw-r--r--lib/mods/theme/edit/misc.txt3
-rw-r--r--src/birth.cc32
-rw-r--r--src/game.hpp6
-rw-r--r--src/game_edit_data.hpp6
-rw-r--r--src/gods.cc3
-rw-r--r--src/help.cc4
-rw-r--r--src/help.hpp2
-rw-r--r--src/init1.cc61
-rw-r--r--src/init2.cc3
-rw-r--r--src/loadsave.cc10
-rw-r--r--src/lua_bind.cc3
-rw-r--r--src/mimic.cc3
-rw-r--r--src/q_bounty.cc3
-rw-r--r--src/q_god.cc2
-rw-r--r--src/q_thief.cc3
-rw-r--r--src/skill_descriptor.hpp21
-rw-r--r--src/skill_descriptor_fwd.hpp3
-rw-r--r--src/skill_modifiers.hpp10
-rw-r--r--src/skill_type_fwd.hpp3
-rw-r--r--src/skills.cc457
-rw-r--r--src/skills.hpp4
-rw-r--r--src/skills_defs.hpp1
-rw-r--r--src/spells6.cc5
-rw-r--r--src/squelch/condition.cc4
-rw-r--r--src/variable.cc15
-rw-r--r--src/variable.hpp5
-rw-r--r--src/xtra1.cc7
-rw-r--r--src/xtra2.cc2
29 files changed, 417 insertions, 267 deletions
diff --git a/lib/edit/misc.txt b/lib/edit/misc.txt
index 5f5a4b1d..0513f242 100644
--- a/lib/edit/misc.txt
+++ b/lib/edit/misc.txt
@@ -44,6 +44,3 @@ M:O:1024
# Maximum size for "m_list[]"
M:M:768
-
-# Maximum number of skills in s_info.txt
-M:k:60
diff --git a/lib/mods/theme/edit/misc.txt b/lib/mods/theme/edit/misc.txt
index 8cbac0ce..d158a6a9 100644
--- a/lib/mods/theme/edit/misc.txt
+++ b/lib/mods/theme/edit/misc.txt
@@ -44,6 +44,3 @@ M:O:1024
# Maximum size for "m_list[]"
M:M:768
-
-# Maximum number of skills in s_info.txt
-M:k:60
diff --git a/src/birth.cc b/src/birth.cc
index 0ea545b5..fe814978 100644
--- a/src/birth.cc
+++ b/src/birth.cc
@@ -2769,9 +2769,10 @@ static bool_ player_birth_aux_auto()
*/
static bool_ player_birth_aux()
{
- char c;
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto &s_info = game->s_info;
- int i, j;
+ char c;
int y = 0, x = 0;
@@ -2780,12 +2781,12 @@ static bool_ player_birth_aux()
/* Ask */
if (!player_birth_aux_ask()) return (FALSE);
- for (i = 1; i < max_s_idx; i++)
+ for (std::size_t i = 1; i < s_descriptors.size(); i++)
{
s_info[i].dev = false;
}
- for (i = 1; i < max_s_idx; i++)
+ for (std::size_t i = 1; i < s_descriptors.size(); i++)
{
s32b value = 0, mod = 0;
@@ -2845,22 +2846,31 @@ static bool_ player_birth_aux()
}
/* Edit character background */
- for (i = 0; i < 4; i++)
+ for (std::size_t i = 0; i < 4; i++)
{
strnfmt(old_history[i], 60, "%s", history[i]);
}
- /* Turn 0 to space */
- for (i = 0; i < 4; i++)
+
+ /* Turn NUL to space */
+ for (std::size_t i = 0; i < 4; i++)
{
- for (j = 0; history[i][j]; j++) /* loop */;
+ std::size_t j = 0;
- for (; j < 59; j++) history[i][j] = ' ';
+ // Search for the NUL
+ while (history[i][j++])
+ ;;
+
+ // Turn into spaces
+ for (; j < 59; j++)
+ {
+ history[i][j] = ' ';
+ }
}
display_player(1);
c_put_str(TERM_L_GREEN, "(Character Background - Edit Mode)", 15, 20);
while (TRUE)
{
- for (i = 0; i < 4; i++)
+ for (std::size_t i = 0; i < 4; i++)
{
put_str(history[i], i + 16, 10);
}
@@ -2897,7 +2907,7 @@ static bool_ player_birth_aux()
}
else if (c == ESCAPE)
{
- for (i = 0; i < 4; i++)
+ for (std::size_t i = 0; i < 4; i++)
{
strnfmt(history[i], 60, "%s", old_history[i]);
put_str(history[i], i + 16, 10);
diff --git a/src/game.hpp b/src/game.hpp
index 5da479c9..845824b7 100644
--- a/src/game.hpp
+++ b/src/game.hpp
@@ -6,6 +6,7 @@
#include "grid.hpp"
#include "h-basic.h"
#include "player_defs.hpp"
+#include "skill_type.hpp"
#include "wilderness_map.hpp"
/**
@@ -30,4 +31,9 @@ struct Game {
*/
GameEditData edit_data;
+ /**
+ * Current skill values.
+ */
+ std::vector<skill_type> s_info;
+
};
diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp
index b8463158..bb480f53 100644
--- a/src/game_edit_data.hpp
+++ b/src/game_edit_data.hpp
@@ -10,6 +10,7 @@
#include "randart_gen_type.hpp"
#include "randart_part_type.hpp"
#include "set_type.hpp"
+#include "skill_descriptor.hpp"
#include "store_action_type.hpp"
#include "store_info_type.hpp"
#include "vault_type.hpp"
@@ -84,6 +85,11 @@ struct GameEditData {
std::vector<hist_type> bg;
/**
+ * Player skills
+ */
+ std::vector<skill_descriptor> s_descriptors;
+
+ /**
* Base skills for all characters.
*/
skill_modifiers gen_skill;
diff --git a/src/gods.cc b/src/gods.cc
index 7da62d7a..82d8d300 100644
--- a/src/gods.cc
+++ b/src/gods.cc
@@ -7,6 +7,7 @@
*/
#include "gods.hpp"
+#include "game.hpp"
#include "player_type.hpp"
#include "skills.hpp"
#include "skill_type.hpp"
@@ -79,6 +80,8 @@ static bool_ may_follow_god(int god)
*/
void follow_god(int god, bool_ silent)
{
+ auto &s_info = game->s_info;
+
/* Poor unbelievers, i'm so mean ... BOUHAHAHA */
if (get_skill(SKILL_ANTIMAGIC))
{
diff --git a/src/help.cc b/src/help.cc
index b74e6584..e5014b45 100644
--- a/src/help.cc
+++ b/src/help.cc
@@ -729,9 +729,9 @@ void help_god(cptr god)
}
}
-void help_skill(cptr skill)
+void help_skill(const std::__cxx11::string &skill)
{
- show_context_help(find_context_help(skill_table, skill));
+ show_context_help(find_context_help(skill_table, skill.c_str()));
}
void help_ability(std::string const &ability)
diff --git a/src/help.hpp b/src/help.hpp
index eb8c3c98..5adf1381 100644
--- a/src/help.hpp
+++ b/src/help.hpp
@@ -9,5 +9,5 @@ extern void help_race(std::string const &race);
extern void help_subrace(std::string const &subrace);
extern void help_class(std::string const &klass);
extern void help_god(cptr god);
-extern void help_skill(cptr skill);
+extern void help_skill(std::string const &skill);
extern void help_ability(std::string const &ability);
diff --git a/src/init1.cc b/src/init1.cc
index 29f63ac7..9431ec46 100644
--- a/src/init1.cc
+++ b/src/init1.cc
@@ -833,7 +833,7 @@ static int read_skill_modifiers(skill_modifiers *skill_modifiers, cptr buf)
return 1;
}
- auto s = &skill_modifiers->modifiers[i];
+ auto s = &expand_to_fit_index(skill_modifiers->modifiers, i);
s->basem = monster_ego_modify(v);
s->base = val;
@@ -3011,9 +3011,11 @@ errr init_set_info_txt(FILE *fp)
*/
errr init_s_info_txt(FILE *fp)
{
- int i, order = 1;
+ auto &s_descriptors = game->edit_data.s_descriptors;
+ auto &s_info = game->s_info;
+
+ int order = 1;
char buf[1024];
- char *s;
/* Current entry */
skill_descriptor *s_ptr = NULL;
@@ -3083,8 +3085,11 @@ errr init_s_info_txt(FILE *fp)
s2 = find_skill(sec);
if ((s1 == -1) || (s2 == -1)) return (1);
- s_descriptors[s1].action[s2] = SKILL_EXCLUSIVE;
- s_descriptors[s2].action[s1] = SKILL_EXCLUSIVE;
+ // The "exclusive" relation is symmetric, so
+ // add summetrically so we don't have to specify
+ // twice in data files.
+ s_descriptors[s1].excludes.push_back(s2);
+ s_descriptors[s2].excludes.push_back(s1);
/* Next... */
continue;
@@ -3117,7 +3122,8 @@ errr init_s_info_txt(FILE *fp)
s2 = find_skill(sec);
if ((s1 == -1) || (s2 == -1)) return (1);
- s_descriptors[s1].action[s2] = atoi(cval);
+ s_descriptors[s1].increases.emplace_back(
+ std::make_tuple(s2, atoi(cval)));
/* Next... */
continue;
@@ -3127,7 +3133,7 @@ errr init_s_info_txt(FILE *fp)
if (buf[0] == 'N')
{
/* Find the colon before the name */
- s = strchr(buf + 2, ':');
+ char *s = strchr(buf + 2, ':');
/* Verify that colon */
if (!s) return (1);
@@ -3139,19 +3145,19 @@ errr init_s_info_txt(FILE *fp)
if (!*s) return (1);
/* Get the index */
- i = atoi(buf + 2);
-
- /* Verify information */
- if (i >= max_s_idx) return (2);
+ int i = atoi(buf + 2);
/* Save the index */
error_idx = i;
/* Point at the "info" */
- s_ptr = &s_descriptors[i];
+ s_ptr = &expand_to_fit_index(s_descriptors, i);
+ assert(s_ptr->name.empty());
+
+ /* Make sure s_info also expands appropriately */
+ expand_to_fit_index(s_info, i);
/* Copy name */
- assert(!s_ptr->name);
s_ptr->name = my_strdup(s);
/* Next... */
@@ -3164,19 +3170,15 @@ errr init_s_info_txt(FILE *fp)
/* Process 'D' for "Description" */
if (buf[0] == 'D')
{
- /* Acquire the text */
- s = buf + 2;
-
- /* Description */
- if (!s_ptr->desc)
- {
- s_ptr->desc = my_strdup(s);
- }
- else
+ /* Need newline? */
+ if (!s_ptr->desc.empty())
{
- strappend(&s_ptr->desc, format("\n%s", s));
+ s_ptr->desc += '\n';
}
+ /* Append */
+ s_ptr->desc += (buf + 2);
+
/* Next... */
continue;
}
@@ -3187,15 +3189,15 @@ errr init_s_info_txt(FILE *fp)
char *txt;
/* Acquire the text */
- s = buf + 2;
+ char const *s = buf + 2;
if (NULL == (txt = strchr(s, ':'))) return (1);
*txt = '\0';
txt++;
/* Copy action description */
- assert(!s_ptr->action_desc);
- s_ptr->action_desc = my_strdup(txt);
+ assert(s_ptr->action_desc.empty());
+ s_ptr->action_desc = txt;
/* Copy mkey index */
s_ptr->action_mkey = atoi(s);
@@ -6793,13 +6795,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst
max_re_idx = atoi(zz[1]);
}
- /* Maximum s_idx */
- else if (zz[0][0] == 'k')
- {
- max_s_idx = atoi(zz[1]);
- if (max_s_idx > MAX_SKILLS) return (1);
- }
-
/* Maximum k_idx */
else if (zz[0][0] == 'K')
{
diff --git a/src/init2.cc b/src/init2.cc
index cf68f4be..4ca60938 100644
--- a/src/init2.cc
+++ b/src/init2.cc
@@ -341,8 +341,7 @@ namespace {
static void allocate()
{
- s_info = new skill_type[max_s_idx];
- s_descriptors = new skill_descriptor[max_s_idx];
+ // Nothing to do
}
static errr parse(FILE *fp)
diff --git a/src/loadsave.cc b/src/loadsave.cc
index 64b4f6d6..41bd86d1 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -421,10 +421,7 @@ static void do_skill_modifier(skill_modifier *s, ls_flag_t flag)
static void do_skill_modifiers(skill_modifiers *skill_modifiers, ls_flag_t flag)
{
- for (std::size_t i = 0; i < MAX_SKILLS; i++)
- {
- do_skill_modifier(&skill_modifiers->modifiers[i], flag);
- }
+ do_vector(flag, skill_modifiers->modifiers, do_skill_modifier);
}
static void do_player_level_flag(player_level_flag *lflag, ls_flag_t flag)
@@ -533,6 +530,7 @@ static char loaded_game_module[80];
static bool_ do_extra(ls_flag_t flag)
{
auto const &d_info = game->edit_data.d_info;
+ auto &s_info = game->s_info;
do_string(player_name, 32, flag);
@@ -611,11 +609,11 @@ static bool_ do_extra(ls_flag_t flag)
do_s16b(&p_ptr->melee_style, flag);
do_s16b(&p_ptr->use_piercing_shots, flag);
- u16b tmp16u = MAX_SKILLS;
+ u16b tmp16u = s_info.size();
do_u16b(&tmp16u, flag);
- if ((flag == ls_flag_t::LOAD) && (tmp16u != MAX_SKILLS))
+ if ((flag == ls_flag_t::LOAD) && (tmp16u != s_info.size()))
{
quit("Too few/many skills");
}
diff --git a/src/lua_bind.cc b/src/lua_bind.cc
index 1612fb29..bb305aa3 100644
--- a/src/lua_bind.cc
+++ b/src/lua_bind.cc
@@ -10,6 +10,7 @@
#include "cmd7.hpp"
#include "corrupt.hpp"
+#include "game.hpp"
#include "init1.hpp"
#include "monster2.hpp"
#include "player_type.hpp"
@@ -85,6 +86,8 @@ s32b lua_get_level(spell_type *spell, s32b lvl, s32b max, s32b min, s32b bonus)
static s32b get_level_device_1(spell_type *spell, s32b max, s32b min)
{
+ auto const &s_info = game->s_info;
+
// Must be in "device" mode.
assert(get_level_use_stick > -1);
// Delegate
diff --git a/src/mimic.cc b/src/mimic.cc
index 463c389d..6ce7b180 100644
--- a/src/mimic.cc
+++ b/src/mimic.cc
@@ -1,5 +1,6 @@
#include "mimic.hpp"
+#include "game.hpp"
#include "object_flag.hpp"
#include "player_type.hpp"
#include "skill_type.hpp"
@@ -303,6 +304,8 @@ static s32b mumak_calc()
static s32b bear_calc()
{
+ auto &s_info = game->s_info;
+
p_ptr->pspeed = p_ptr->pspeed - 5 + (p_ptr->mimic_level / 5);
p_ptr->to_a = p_ptr->to_a + 5 + ((p_ptr->mimic_level * 2) / 3);
diff --git a/src/q_bounty.cc b/src/q_bounty.cc
index 56f2669a..e0a7ae2a 100644
--- a/src/q_bounty.cc
+++ b/src/q_bounty.cc
@@ -1,5 +1,6 @@
#include "q_bounty.hpp"
+#include "game.hpp"
#include "monster2.hpp"
#include "monster_race.hpp"
#include "monster_race_flag.hpp"
@@ -108,6 +109,8 @@ bool_ quest_bounty_drop_item()
bool_ quest_bounty_get_item()
{
+ auto &s_info = game->s_info;
+
if (cquest.status != QUEST_STATUS_TAKEN)
{
msg_print("You do not have any bounty quest yet.");
diff --git a/src/q_god.cc b/src/q_god.cc
index cfd5b257..1cb4c0f5 100644
--- a/src/q_god.cc
+++ b/src/q_god.cc
@@ -1020,6 +1020,8 @@ static bool_ quest_god_player_level_hook(void *, void *in_, void *)
static bool_ quest_god_get_hook(void *, void *in_, void *)
{
+ auto &s_info = game->s_info;
+
hook_get_in *in = static_cast<hook_get_in *>(in_);
s32b item = -in->o_idx; /* Note the negation */
diff --git a/src/q_thief.cc b/src/q_thief.cc
index a1ec76c6..e471aeab 100644
--- a/src/q_thief.cc
+++ b/src/q_thief.cc
@@ -3,6 +3,7 @@
#include "cave.hpp"
#include "cave_type.hpp"
#include "dungeon_flag.hpp"
+#include "game.hpp"
#include "hook_quest_finish_in.hpp"
#include "hooks.hpp"
#include "init1.hpp"
@@ -138,6 +139,8 @@ static bool_ quest_thieves_hook(void *, void *, void *)
static bool_ quest_thieves_finish_hook(void *, void *in_, void *)
{
+ auto const &s_info = game->s_info;
+
struct hook_quest_finish_in *in = static_cast<struct hook_quest_finish_in *>(in_);
s32b q_idx = in->q_idx;
diff --git a/src/skill_descriptor.hpp b/src/skill_descriptor.hpp
index 687597da..8d9de004 100644
--- a/src/skill_descriptor.hpp
+++ b/src/skill_descriptor.hpp
@@ -1,24 +1,31 @@
#pragma once
-#include "skill_descriptor_fwd.hpp"
-
#include "h-basic.h"
#include "skill_flag_set.hpp"
#include "skills_defs.hpp"
+#include <vector>
+#include <tuple>
+
/**
* Skill descriptor.
*/
struct skill_descriptor {
- const char *name = nullptr; /* Name */
- char *desc = nullptr; /* Description */
-
- const char *action_desc = nullptr; /* Action Description */
+ std::string name; /* Name */
+ std::string desc; /* Description */
+ std::string action_desc; /* Action Description */
s16b action_mkey = 0; /* Action do to */
- s16b action[MAX_SKILLS] = { 0 }; /* List of actions against other skills */
+ std::vector<std::size_t> excludes; /* List of skills that this skill excludes;
+ any skill points assigned completely nullify
+ the listed skills */
+
+ std::vector<std::tuple<std::size_t, int>> increases;
+ /* List of skills the this skill increases,
+ along with the modifier that gets applied.
+ The first tuple element is the skill index. */
s16b father = 0; /* Father in the skill tree */
s16b order = 0; /* Order in the tree */
diff --git a/src/skill_descriptor_fwd.hpp b/src/skill_descriptor_fwd.hpp
deleted file mode 100644
index 136f337b..00000000
--- a/src/skill_descriptor_fwd.hpp
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-struct skill_descriptor;
diff --git a/src/skill_modifiers.hpp b/src/skill_modifiers.hpp
index fe9d9a1b..5e90b000 100644
--- a/src/skill_modifiers.hpp
+++ b/src/skill_modifiers.hpp
@@ -3,9 +3,15 @@
#include "h-basic.h"
#include "skills_defs.hpp"
#include "skill_modifier.hpp"
-#include <array>
+
+#include <vector>
struct skill_modifiers
{
- std::array<skill_modifier, MAX_SKILLS> modifiers;
+ /**
+ * Skill modifiers indexed by skill. Note that this vector
+ * may be shorter than the s_descriptors vector.
+ */
+ std::vector<skill_modifier> modifiers;
+
};
diff --git a/src/skill_type_fwd.hpp b/src/skill_type_fwd.hpp
deleted file mode 100644
index 0a06dadb..00000000
--- a/src/skill_type_fwd.hpp
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-struct skill_type;
diff --git a/src/skills.cc b/src/skills.cc
index dc543ed8..96d34e06 100644
--- a/src/skills.cc
+++ b/src/skills.cc
@@ -57,6 +57,8 @@ using boost::algorithm::iequals;
*/
static void increase_skill(int i, s16b *invest)
{
+ auto &s_info = game->s_info;
+
s32b max_skill_overage;
/* No skill points to be allocated */
@@ -99,6 +101,8 @@ static void increase_skill(int i, s16b *invest)
*/
static void decrease_skill(int i, s16b *invest)
{
+ auto &s_info = game->s_info;
+
/* Cannot decrease more */
if (!invest[i]) return;
@@ -121,14 +125,17 @@ 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 name)
+s16b find_skill(cptr needle)
{
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+
/* Scan skill list */
- for (int i = 1; i < max_s_idx; i++)
+ for (std::size_t i = 1; i < s_descriptors.size(); i++)
{
- if (s_descriptors[i].name && streq(s_descriptors[i].name, name))
+ auto const &name = s_descriptors[i].name;
+ if (!name.empty() && (name == needle))
{
- return (i);
+ return i;
}
}
@@ -136,15 +143,15 @@ s16b find_skill(cptr name)
return -1;
}
-s16b find_skill_i(cptr name)
+s16b find_skill_i(cptr needle)
{
- u16b i;
+ auto const &s_descriptors = game->edit_data.s_descriptors;
/* Scan skill list */
- for (i = 1; i < max_s_idx; i++)
+ for (std::size_t i = 1; i < s_descriptors.size(); i++)
{
- /* The name matches */
- if (s_descriptors[i].name && iequals(s_descriptors[i].name, name))
+ auto const &name = s_descriptors[i].name;
+ if (!name.empty() && iequals(name, needle))
{
return (i);
}
@@ -160,6 +167,8 @@ s16b find_skill_i(cptr name)
*/
s16b get_skill(int skill)
{
+ auto const &s_info = game->s_info;
+
return (s_info[skill].value / SKILL_STEP);
}
@@ -170,7 +179,7 @@ s16b get_skill(int skill)
*/
s16b get_skill_scale(int skill, u32b scale)
{
- s32b temp;
+ auto const &s_info = game->s_info;
/*
* SKILL_STEP shouldn't matter here because the second parameter is
@@ -182,29 +191,35 @@ s16b get_skill_scale(int skill, u32b scale)
* formula given above, I verified this works the same by using a tiny
* scheme program... -- pelpel
*/
- temp = scale * s_info[skill].value;
+ s32b temp = scale * s_info[skill].value;
return (temp / SKILL_MAX);
}
-static int get_idx(int i)
+static std::size_t get_idx(int i)
{
- for (int j = 1; j < max_s_idx; j++)
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+
+ for (std::size_t j = 1; j < s_descriptors.size(); j++)
{
if (s_descriptors[j].order == i)
- return (j);
+ {
+ return j;
+ }
}
- return (0);
+
+ return 0;
}
static bool_ is_known(int s_idx)
{
- int i;
+ 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;
- for (i = 0; i < max_s_idx; i++)
+ for (std::size_t i = 0; i < s_descriptors.size(); i++)
{
/* It is our child, if we don't know it we continue to search, if we know it it is enough*/
if (s_descriptors[i].father == s_idx)
@@ -218,35 +233,51 @@ static bool_ is_known(int s_idx)
return FALSE;
}
-static void init_table_aux(int table[MAX_SKILLS][2], int *idx, int father, int lev, bool_ full)
+namespace { // anonymous
+
+struct skill_entry {
+ std::size_t skill_idx;
+ int indent_level;
+};
+
+}
+
+static void init_table_aux(std::vector<skill_entry> *table, int father, int lev, bool_ full)
{
- for (int j = 1; j < max_s_idx; j++)
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto const &s_info = game->s_info;
+
+ for (std::size_t j = 1; j < s_descriptors.size(); j++)
{
- int i = get_idx(j);
+ std::size_t i = get_idx(j);
+
if (s_descriptors[i].father != father) continue;
if (s_info[i].hidden) continue;
if (!is_known(i)) continue;
- table[*idx][0] = i;
- table[*idx][1] = lev;
- (*idx)++;
+ skill_entry entry;
+ entry.skill_idx = i;
+ entry.indent_level = lev;
+ table->emplace_back(entry);
if (s_info[i].dev || full)
{
- init_table_aux(table, idx, i, lev + 1, full);
+ init_table_aux(table, i, lev + 1, full);
}
}
}
-static void init_table(int table[MAX_SKILLS][2], int *max, bool_ full)
+static void init_table(std::vector<skill_entry> *table, bool_ full)
{
- *max = 0;
- init_table_aux(table, max, -1, 0, full);
+ table->clear();
+ init_table_aux(table, -1, 0, full);
}
static bool has_child(int sel)
{
- for (int i = 1; i < max_s_idx; i++)
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+
+ for (std::size_t i = 1; i < s_descriptors.size(); i++)
{
if ((s_descriptors[i].father == sel) && is_known(i))
{
@@ -263,42 +294,51 @@ static bool has_child(int sel)
*/
void dump_skills(FILE *fff)
{
- int i, j, max = 0;
- int table[MAX_SKILLS][2];
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto const &s_info = game->s_info;
+
char buf[80];
- init_table(table, &max, TRUE);
+ std::vector<skill_entry> table;
+ table.reserve(s_descriptors.size());
+ init_table(&table, TRUE);
fprintf(fff, "\nSkills (points left: %d)", p_ptr->skill_points);
- for (j = 0; j < max; j++)
+ for (auto const &entry: table)
{
- int z;
-
- i = table[j][0];
+ std::size_t i = entry.skill_idx;
+ auto const &skill = s_info[i];
+ auto const &skill_name = s_descriptors[i].name;
- if ((s_info[i].value == 0) && (i != SKILL_MISC))
+ if ((skill.value == 0) && (i != SKILL_MISC))
{
- if (s_info[i].mod == 0) continue;
+ if (skill.mod == 0)
+ {
+ continue;
+ }
}
sprintf(buf, "\n");
- for (z = 0; z < table[j][1]; z++) strcat(buf, " ");
+ for (int z = 0; z < entry.indent_level; z++)
+ {
+ strcat(buf, " ");
+ }
if (!has_child(i))
{
- strcat(buf, format(" . %s", s_descriptors[i].name));
+ strcat(buf, format(" . %s", skill_name.c_str()));
}
else
{
- strcat(buf, format(" - %s", s_descriptors[i].name));
+ strcat(buf, format(" - %s", skill_name.c_str()));
}
fprintf(fff, "%-49s%s%06.3f [%05.3f]",
- buf, s_info[i].value < 0 ? "-" : " ",
- static_cast<double>(ABS(s_info[i].value)) / SKILL_STEP,
- static_cast<double>(s_info[i].mod) / 1000);
+ buf, skill.value < 0 ? "-" : " ",
+ static_cast<double>(ABS(skill.value)) / SKILL_STEP,
+ static_cast<double>(skill.mod) / 1000);
}
fprintf(fff, "\n");
@@ -308,9 +348,12 @@ void dump_skills(FILE *fff)
/*
* Draw the skill tree
*/
-void print_skills(int table[MAX_SKILLS][2], int max, int sel, int start)
+static void print_skills(std::vector<skill_entry> const &table, int sel, int start)
{
- int i, j;
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto const &s_info = game->s_info;
+
+ int j;
int wid, hgt;
cptr keys;
@@ -322,52 +365,73 @@ 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_descriptors[table[sel][0]].desc, 3, 0);
+ print_desc_aux(s_descriptors[table[sel].skill_idx].desc.c_str(), 3, 0);
for (j = start; j < start + (hgt - 7); j++)
{
byte color = TERM_WHITE;
char deb = ' ', end = ' ';
- if (j >= max) break;
+ if (j >= static_cast<int>(table.size()))
+ {
+ break;
+ }
+
+ std::size_t i = table[j].skill_idx;
+ auto const &name = s_descriptors[i].name;
+ auto const &skill = s_info[i];
- i = table[j][0];
+ if ((skill.value == 0) && (i != SKILL_MISC))
+ {
+ if (skill.mod == 0)
+ {
+ color = TERM_L_DARK;
+ }
+ else
+ {
+ color = TERM_ORANGE;
+ }
+ }
+ else if (skill.value == SKILL_MAX)
+ {
+ color = TERM_L_BLUE;
+ }
- if ((s_info[i].value == 0) && (i != SKILL_MISC))
+ if (skill.hidden)
{
- if (s_info[i].mod == 0) color = TERM_L_DARK;
- else color = TERM_ORANGE;
+ color = TERM_L_RED;
}
- 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_descriptors[i].name),
- j + 7 - start, table[j][1] * 4);
+ c_prt(color, format("%c.%c%s", deb, end, name.c_str()),
+ j + 7 - start, table[j].indent_level * 4);
}
- else if (s_info[i].dev)
+ else if (skill.dev)
{
- c_prt(color, format("%c-%c%s", deb, end, s_descriptors[i].name),
- j + 7 - start, table[j][1] * 4);
+ c_prt(color, format("%c-%c%s", deb, end, name.c_str()),
+ j + 7 - start, table[j].indent_level * 4);
}
else
{
- c_prt(color, format("%c+%c%s", deb, end, s_descriptors[i].name),
- j + 7 - start, table[j][1] * 4);
+ c_prt(color, format("%c+%c%s", deb, end, name.c_str()),
+ j + 7 - start, table[j].indent_level * 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),
+ skill.value < 0 ? "-" : " ",
+ ABS(skill.value) / SKILL_STEP,
+ ABS(skill.value) % SKILL_STEP,
+ ABS(skill.mod) / 1000,
+ ABS(skill.mod) % 1000),
j + 7 - start, 60);
}
}
@@ -377,6 +441,8 @@ void print_skills(int table[MAX_SKILLS][2], int max, int sel, int start)
*/
void recalc_skills(bool_ init)
{
+ auto const &s_info = game->s_info;
+
static int thaum_level = 0;
/* TODO: This should be a hook in ToME's lua */
@@ -429,49 +495,64 @@ void recalc_skills(bool_ init)
/*
* Recalc the skill value
*/
-static void recalc_skills_theory(s16b *invest, s32b *base_val, s32b *base_mod, s32b *bonus)
+static void recalc_skills_theory(
+ std::vector<s16b> &invest,
+ std::vector<s32b> const &base_val,
+ std::vector<s32b> const &base_mod,
+ std::vector<s32b> const &bonus)
{
- int i, j;
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto &s_info = game->s_info;
/* First we assign the normal points */
- for (i = 0; i < max_s_idx; i++)
+ for (std::size_t i = 0; i < s_descriptors.size(); 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;
+ 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 (std::size_t i = 0; i < s_descriptors.size(); i++)
{
- for (j = 1; j < max_s_idx; j++)
- {
- /* Ignore self */
- if (j == i) continue;
+ auto const &s_descriptor = s_descriptors[i];
- /* Exclusive skills */
- if ((s_descriptors[i].action[j] == SKILL_EXCLUSIVE) && invest[i])
+ // Process all exlusions
+ if (invest[i])
+ {
+ for (auto exclude_si: s_descriptor.excludes)
{
- /* Turn it off */
- p_ptr->skill_points += invest[j];
- invest[j] = 0;
- s_info[j].value = 0;
+ // Give back skill points invested during this "session"
+ p_ptr->skill_points += invest[exclude_si];
+ invest[exclude_si] = 0;
+
+ // Turn it off
+ s_info[exclude_si].value = 0;
}
+ }
- /* Non-exclusive skills */
- else if (s_descriptors[i].action[j])
- {
- /* Increase / decrease with a % */
- s32b val = s_info[j].value + (invest[i] * s_info[j].mod * s_descriptors[i].action[j] / 100);
+ // Add any bonuses
+ for (auto const &increase: s_descriptor.increases)
+ {
+ auto increase_si = std::get<0>(increase);
+ auto increase_pct = std::get<1>(increase);
- /* It cannot exceed SKILL_MAX */
- if (val > SKILL_MAX) val = SKILL_MAX;
+ /* Increase/decrease by percentage */
+ s32b val = s_info[increase_si].value + (invest[i] * s_info[increase_si].mod * increase_pct / 100);
- /* Save the modified value */
- s_info[j].value = val;
+ /* It cannot exceed SKILL_MAX */
+ if (val > SKILL_MAX)
+ {
+ val = SKILL_MAX;
}
+
+ /* Save the modified value */
+ s_info[increase_si].value = val;
}
}
}
@@ -481,10 +562,11 @@ static void recalc_skills_theory(s16b *invest, s32b *base_val, s32b *base_mod, s
*/
void do_cmd_skill()
{
- int sel = 0, start = 0, max;
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto &s_info = game->s_info;
+
+ int sel = 0, start = 0;
char c;
- int table[MAX_SKILLS][2];
- int i;
int wid, hgt;
s16b skill_points_save;
@@ -493,39 +575,38 @@ void do_cmd_skill()
/* Save the screen */
screen_save();
- /* Allocate arrays to save skill values */
- std::unique_ptr<s32b[]> skill_values_save(new s32b[MAX_SKILLS]);
- std::unique_ptr<s32b[]> skill_mods_save(new s32b[MAX_SKILLS]);
- std::unique_ptr<s16b[]> skill_invest(new s16b[MAX_SKILLS]);
- std::unique_ptr<s32b[]> skill_bonus(new s32b[MAX_SKILLS]);
+ /* Allocate arrays to save skill values and track assigned points */
+ std::vector<s32b> skill_values_save; skill_values_save.resize(s_descriptors.size(), 0);
+ std::vector<s32b> skill_mods_save; skill_mods_save.resize(s_descriptors.size(), 0);
+ std::vector<s16b> skill_invest; skill_invest.resize(s_descriptors.size(), 0);
+ std::vector<s32b> skill_bonus; skill_bonus.resize(s_descriptors.size(), 0);
/* Save skill points */
skill_points_save = p_ptr->skill_points;
/* Save skill values */
- for (i = 0; i < max_s_idx; i++)
+ for (std::size_t i = 0; i < s_descriptors.size(); i++)
{
- skill_type *s_ptr = &s_info[i];
-
+ auto s_ptr = &s_info[i];
skill_values_save[i] = s_ptr->value;
skill_mods_save[i] = s_ptr->mod;
- skill_invest[i] = 0;
- skill_bonus[i] = 0;
}
/* Clear the screen */
Term_clear();
/* Initialise the skill list */
- init_table(table, &max, FALSE);
+ std::vector<skill_entry> table;
+ table.reserve(s_descriptors.size());
+ init_table(&table, 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);
+ recalc_skills_theory(skill_invest, skill_values_save, skill_mods_save, skill_bonus);
+ print_skills(table, sel, start);
/* Wait for user input */
c = inkey();
@@ -536,16 +617,21 @@ void do_cmd_skill()
/* Expand / collapse list of skills */
else if (c == '\r')
{
- s_info[table[sel][0]].dev = !s_info[table[sel][0]].dev;
-
- init_table(table, &max, FALSE);
+ // 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);
}
/* Next page */
else if (c == 'n')
{
sel += (hgt - 7);
- if (sel >= max) sel = max - 1;
+
+ if (sel >= static_cast<int>(table.size()))
+ {
+ sel = table.size() - 1;
+ }
}
/* Previous page */
@@ -570,31 +656,31 @@ void do_cmd_skill()
if (dir == 8) sel--;
/* Miscellaneous skills cannot be increased/decreased as a group */
- if ((sel >= 0) && (sel < max) && table[sel][0] == SKILL_MISC) continue;
+ if ((sel >= 0) && (sel < static_cast<int>(table.size())) && table[sel].skill_idx == SKILL_MISC) continue;
/* Increase the current skill */
- if (dir == 6) increase_skill(table[sel][0], skill_invest.get());
+ if (dir == 6) increase_skill(table[sel].skill_idx, skill_invest.data());
/* Decrease the current skill */
- if (dir == 4) decrease_skill(table[sel][0], skill_invest.get());
+ if (dir == 4) decrease_skill(table[sel].skill_idx, skill_invest.data());
/* XXX XXX XXX Wizard mode commands outside of wizard2.c */
/* Increase the skill */
- if (wizard && (c == '+')) skill_bonus[table[sel][0]] += SKILL_STEP;
+ if (wizard && (c == '+')) skill_bonus[table[sel].skill_idx] += SKILL_STEP;
/* Decrease the skill */
- if (wizard && (c == '-')) skill_bonus[table[sel][0]] -= SKILL_STEP;
+ if (wizard && (c == '-')) skill_bonus[table[sel].skill_idx] -= SKILL_STEP;
/* Contextual help */
if (c == '?')
{
- help_skill(s_descriptors[table[sel][0]].name);
+ help_skill(s_descriptors[table[sel].skill_idx].name);
}
/* Handle boundaries and scrolling */
- if (sel < 0) sel = max - 1;
- if (sel >= max) sel = 0;
+ if (sel < 0) sel = table.size() - 1;
+ if (sel >= static_cast<int>(table.size())) sel = 0;
if (sel < start) start = sel;
if (sel >= start + (hgt - 7)) start = sel - (hgt - 7) + 1;
}
@@ -616,10 +702,9 @@ void do_cmd_skill()
p_ptr->skill_points = skill_points_save;
/* Restore skill values */
- for (i = 0; i < max_s_idx; i++)
+ for (std::size_t i = 0; i < s_descriptors.size(); i++)
{
- skill_type *s_ptr = &s_info[i];
-
+ auto s_ptr = &s_info[i];
s_ptr->value = skill_values_save[i];
s_ptr->mod = skill_mods_save[i];
}
@@ -671,9 +756,11 @@ cptr get_melee_name()
s16b get_melee_skills()
{
- int i, j = 0;
+ auto const &s_info = game->s_info;
- for (i = 0; i < MAX_MELEE; i++)
+ int j = 0;
+
+ for (std::size_t i = 0; i < MAX_MELEE; i++)
{
if ((s_info[melee_skills[i]].value > 0) && (!s_info[melee_skills[i]].hidden))
{
@@ -784,7 +871,7 @@ void select_default_melee()
/*
* Print a batch of skills.
*/
-static void print_skill_batch(const std::vector<std::tuple<std::string const &, int>> &p, int start)
+static void print_skill_batch(const std::vector<std::tuple<std::string, int>> &p, int start)
{
char buff[80];
int j = 0;
@@ -812,12 +899,14 @@ static void print_skill_batch(const std::vector<std::tuple<std::string const &,
static int do_cmd_activate_skill_aux()
{
auto const &ab_info = game->edit_data.ab_info;
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto const &s_info = game->s_info;
char which;
int start = 0;
int ret;
- std::vector<std::tuple<std::string const &,int>> p;
+ std::vector<std::tuple<std::string,int>> p;
/* More than 1 melee skill ? */
if (get_melee_skills() > 1)
@@ -825,7 +914,7 @@ static int do_cmd_activate_skill_aux()
p.push_back(std::make_tuple("Change melee mode", 0));
}
- for (size_t i = 1; i < max_s_idx; i++)
+ for (size_t i = 1; i < s_descriptors.size(); i++)
{
if (s_descriptors[i].action_mkey && s_info[i].value && ((!s_info[i].hidden) || (i == SKILL_LEARN)))
{
@@ -960,6 +1049,8 @@ static int do_cmd_activate_skill_aux()
void do_cmd_activate_skill()
{
auto const &ab_info = game->edit_data.ab_info;
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto const &s_info = game->s_info;
int x_idx;
bool_ push = TRUE;
@@ -978,8 +1069,8 @@ void do_cmd_activate_skill()
x_idx = command_arg;
/* Check validity */
- int i;
- for (i = 1; i < max_s_idx; i++)
+ std::size_t i;
+ for (i = 1; i < s_descriptors.size(); i++)
{
if (s_info[i].value && (s_descriptors[i].action_mkey == x_idx))
{
@@ -996,7 +1087,7 @@ void do_cmd_activate_skill()
}
}
- if ((j == ab_info.size()) && (i == max_s_idx))
+ if ((j == ab_info.size()) && (i == s_descriptors.size()))
{
msg_print("Uh?");
return;
@@ -1201,32 +1292,39 @@ bool_ forbid_non_blessed()
/*
* Augment skill value/modifier with the given skill_modifiers
*/
-static void augment_skills(s32b *v, s32b *m, skill_modifier const &s)
+static void augment_skills(s32b *v, s32b *m, std::vector<skill_modifier> const &modifiers, std::size_t i)
{
- *v = modify_aux(*v, s.base, s.basem);
- *m = modify_aux(*m, s.mod, s.modm);
+ if (i < modifiers.size()) // Ignore if the skill has no modifiers.
+ {
+ auto const &s = modifiers[i];
+ *v = modify_aux(*v, s.base, s.basem);
+ *m = modify_aux(*m, s.mod, s.modm);
+ }
}
/*
* Gets the base value of a skill, given a race/class/...
*/
-void compute_skills(s32b *v, s32b *m, int i)
+void compute_skills(s32b *v, s32b *m, std::size_t i)
{
auto const &gen_skill = game->edit_data.gen_skill;
- augment_skills(v, m, gen_skill.modifiers[i]);
- augment_skills(v, m, rp_ptr->skill_modifiers.modifiers[i]);
- augment_skills(v, m, rmp_ptr->skill_modifiers.modifiers[i]);
- augment_skills(v, m, cp_ptr->skill_modifiers.modifiers[i]);
- augment_skills(v, m, spp_ptr->skill_modifiers.modifiers[i]);
+ augment_skills(v, m, gen_skill.modifiers, i);
+ augment_skills(v, m, rp_ptr->skill_modifiers.modifiers, i);
+ augment_skills(v, m, rmp_ptr->skill_modifiers.modifiers, i);
+ augment_skills(v, m, cp_ptr->skill_modifiers.modifiers, i);
+ augment_skills(v, m, spp_ptr->skill_modifiers.modifiers, i);
}
/*
* Initialize a skill with given values
*/
-void init_skill(s32b value, s32b mod, int i)
+void init_skill(s32b value, s32b mod, std::size_t i)
{
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto &s_info = game->s_info;
+
s_info[i].value = value;
s_info[i].mod = mod;
s_info[i].hidden = (s_descriptors[i].flags & SKF_HIDDEN)
@@ -1294,29 +1392,27 @@ static std::vector<size_t> wrs(const std::vector<s32b> &unscaled_weights)
void do_get_new_skill()
{
- std::vector<std::string> 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;
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto &s_info = game->s_info;
/* 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++)
+ std::vector<size_t> available_skills;
+ available_skills.reserve(s_descriptors.size());
+ for (std::size_t i = 0; i < s_descriptors.size(); i++)
{
if (s_descriptors[i].flags & SKF_RANDOM_GAIN)
{
- available_skills[max_a] = i;
- max_a++;
+ available_skills.push_back(i);
}
}
/* Perform the selection */
std::vector<s32b> weights;
- for (i = 0; i < max_a; i++) {
+ for (std::size_t i = 0; i < available_skills.size(); i++)
+ {
weights.push_back(s_descriptors[available_skills[i]].random_gain_chance);
}
@@ -1324,10 +1420,14 @@ void do_get_new_skill()
assert(indexes.size() >= LOST_SWORD_NSKILLS);
/* Extract the information needed from the skills */
- for (i = 0; i < LOST_SWORD_NSKILLS; i++)
+ int skl[LOST_SWORD_NSKILLS];
+ s32b val[LOST_SWORD_NSKILLS];
+ s32b mod[LOST_SWORD_NSKILLS];
+ std::vector<std::string> items;
+ for (std::size_t i = 0; i < LOST_SWORD_NSKILLS; i++)
{
s32b s_idx = available_skills[indexes[i]];
- skill_type *s_ptr = &s_info[s_idx];
+ auto s_ptr = &s_info[s_idx];
if (s_ptr->mod)
{
@@ -1341,7 +1441,9 @@ void do_get_new_skill()
val[i] = s_ptr->mod * 1;
mod[i] = 100;
if (mod[i] + s_ptr->mod > 500)
+ {
mod[i] = 500 - s_ptr->mod;
+ }
}
else
{
@@ -1355,41 +1457,56 @@ void do_get_new_skill()
val[i] = 1000;
}
- if (s_ptr->value + val[i] > SKILL_MAX) {
+ 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_descriptors[s_idx].name,
+ s_descriptors[s_idx].name.c_str(),
val[i] / SKILL_STEP,
val[i] % SKILL_STEP,
mod[i] / SKILL_STEP,
mod[i] % SKILL_STEP));
}
+ // Ask for a skill
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);
+ int res = ask_menu(buf, items);
/* Ok ? lets learn ! */
if (res > -1)
{
+ std::size_t chosen_skill = skl[res];
+
bool_ oppose = FALSE;
int oppose_skill = -1;
- /* Check we don't oppose an existing skill */
- for (i = 0; i < max_s_idx; i++)
+ /* Check we don't oppose a skill the player already has */
+ for (std::size_t i = 0; i < s_descriptors.size(); i++)
{
- if ((s_descriptors[i].action[skl[res]] == SKILL_EXCLUSIVE) &&
- (s_info[i].value != 0))
+ auto const &s_descriptor = s_descriptors[i];
+
+ // Only bother if player has skill
+ if (s_info[i].value)
{
- oppose = TRUE;
- oppose_skill = i;
- break;
+ // Check if i'th skill opposes the chosen one.
+ auto found = std::find(
+ s_descriptor.excludes.begin(),
+ s_descriptor.excludes.end(),
+ chosen_skill);
+
+ if (found != s_descriptor.excludes.end())
+ {
+ oppose = TRUE;
+ oppose_skill = i;
+ break;
+ }
}
}
@@ -1407,26 +1524,32 @@ void do_get_new_skill()
/* Prepare prompt */
msg = format("This skill is mutually exclusive with "
"at least %s, continue?",
- s_descriptors[oppose_skill].name);
+ s_descriptors[oppose_skill].name.c_str());
- /* The player rejected the choice */
- if (!get_check(msg)) continue;
+ /* The player rejected the choice; go back to prompt */
+ if (!get_check(msg))
+ {
+ continue;
+ }
}
- auto const s_desc = &s_descriptors[skl[res]];
- auto const s_ptr = &s_info[skl[res]];
+ auto const s_desc = &s_descriptors[chosen_skill];
+ auto const s_ptr = &s_info[chosen_skill];
+
s_ptr->value += val[res];
s_ptr->mod += mod[res];
+
if (mod[res])
{
msg_format("You can now learn the %s skill.",
- s_desc->name);
+ s_desc->name.c_str());
}
else
{
msg_format("Your knowledge of the %s skill increases.",
- s_desc->name);
+ s_desc->name.c_str());
}
+
break;
}
}
diff --git a/src/skills.hpp b/src/skills.hpp
index 4cd63358..694b29e9 100644
--- a/src/skills.hpp
+++ b/src/skills.hpp
@@ -15,10 +15,10 @@ extern s16b get_melee_skills(void);
extern s16b get_melee_skill(void);
extern bool_ forbid_gloves(void);
extern bool_ forbid_non_blessed(void);
-extern void compute_skills(s32b *v, s32b *m, int i);
+extern void compute_skills(s32b *v, s32b *m, std::size_t i);
extern void select_default_melee(void);
extern void do_get_new_skill(void);
-extern void init_skill(s32b value, s32b mod, int i);
+extern void init_skill(s32b value, s32b mod, std::size_t i);
extern s16b find_ability(cptr name);
extern void dump_abilities(FILE *fff);
extern void do_cmd_ability(void);
diff --git a/src/skills_defs.hpp b/src/skills_defs.hpp
index 1dbdee9f..a39fd027 100644
--- a/src/skills_defs.hpp
+++ b/src/skills_defs.hpp
@@ -60,4 +60,3 @@
#define SKILL_STUN 57
#define SKILL_BOULDER 58
#define SKILL_GEOMANCY 59
-#define MAX_SKILLS 200
diff --git a/src/spells6.cc b/src/spells6.cc
index a4564ae3..555f252f 100644
--- a/src/spells6.cc
+++ b/src/spells6.cc
@@ -1,5 +1,6 @@
#include "spells6.hpp"
+#include "game.hpp"
#include "gods.hpp"
#include "lua_bind.hpp"
#include "object2.hpp"
@@ -151,6 +152,8 @@ static bool_ geomancy_depends_satisfied()
long get_provided_levels(school_type *school)
{
+ auto const &s_info = game->s_info;
+
for (auto school_provider: school->providers->v)
{
if (school_provider.deity_idx == p_ptr->pgod)
@@ -171,6 +174,8 @@ struct get_level_school_callback_data {
static bool get_level_school_callback(struct get_level_school_callback_data *data, int school_idx)
{
+ auto const &s_info = game->s_info;
+
school_type *school = school_at(school_idx);
long r = 0, s = 0, p = 0, ok = 0;
diff --git a/src/squelch/condition.cc b/src/squelch/condition.cc
index 09535c53..8715b364 100644
--- a/src/squelch/condition.cc
+++ b/src/squelch/condition.cc
@@ -806,6 +806,8 @@ std::shared_ptr<Condition> SkillCondition::from_json(jsoncons::json const &j)
void SkillCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t bcol) const
{
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+
p->write(ecol, "Your skill in ");
p->write(bcol, s_descriptors[m_skill_idx].name);
p->write(ecol, " is from ");
@@ -817,6 +819,8 @@ void SkillCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t
void SkillCondition::to_json(jsoncons::json &j) const
{
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+
j["name"] = s_descriptors[m_skill_idx].name;
j["min"] = m_min;
j["max"] = m_max;
diff --git a/src/variable.cc b/src/variable.cc
index a13ee3aa..0e892bf3 100644
--- a/src/variable.cc
+++ b/src/variable.cc
@@ -463,16 +463,6 @@ monster_race *r_info;
monster_ego *re_info;
/*
- * Player skills arrays
- */
-skill_type *s_info;
-
-/**
- * Skill descriptors.
- */
-skill_descriptor *s_descriptors;
-
-/*
* The wilderness features arrays
*/
wilderness_type_info *wf_info;
@@ -595,11 +585,6 @@ s32b get_level_max_stick = -1;
s32b get_level_use_stick = -1;
/*
- * Maximum number of skills in s_info.txt
- */
-u16b max_s_idx;
-
-/*
* Maximum number of monsters in r_info.txt
*/
u16b max_r_idx;
diff --git a/src/variable.hpp b/src/variable.hpp
index 2192d2b2..35d482dc 100644
--- a/src/variable.hpp
+++ b/src/variable.hpp
@@ -26,9 +26,7 @@
#include "random_artifact.hpp"
#include "random_quest.hpp"
#include "school_type.hpp"
-#include "skill_descriptor_fwd.hpp"
#include "skill_modifiers_fwd.hpp"
-#include "skill_type_fwd.hpp"
#include "skills_defs.hpp"
#include "timer_type_fwd.hpp"
#include "town_type_fwd.hpp"
@@ -157,8 +155,6 @@ extern player_class const *cp_ptr;
extern player_spec const *spp_ptr;
extern char player_name[32];
extern char player_base[32];
-extern skill_type *s_info;
-extern skill_descriptor *s_descriptors;
extern feature_type *f_info;
extern object_kind *k_info;
extern artifact_type *a_info;
@@ -178,7 +174,6 @@ extern char *ANGBAND_DIR_DNGN;
extern bool_ (*get_mon_num_hook)(int r_idx);
extern bool_ (*get_mon_num2_hook)(int r_idx);
extern bool_ (*get_obj_num_hook)(int k_idx);
-extern u16b max_s_idx;
extern u16b max_r_idx;
extern u16b max_re_idx;
extern u16b max_k_idx;
diff --git a/src/xtra1.cc b/src/xtra1.cc
index 6c9d0a29..65767d76 100644
--- a/src/xtra1.cc
+++ b/src/xtra1.cc
@@ -2508,6 +2508,8 @@ static void calc_schools()
/* Apply corruptions */
static void calc_corruptions()
{
+ auto &s_info = game->s_info;
+
if (player_has_corruption(CORRUPT_BALROG_AURA))
{
p_ptr->xtra_flags |= TR_SH_FIRE;
@@ -2802,6 +2804,9 @@ static bool_ monk_empty_hands(void)
*/
void calc_bonuses(bool_ silent)
{
+ auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto &s_info = game->s_info;
+
static bool_ monk_notify_aux = FALSE;
int i, j, hold;
int old_speed;
@@ -2976,7 +2981,7 @@ void calc_bonuses(bool_ silent)
p_ptr->xtra_flags = object_flag_set();
/* Hide the skills that should auto hide */
- for (i = 0; i < max_s_idx; i++)
+ for (std::size_t i = 0; i < s_descriptors.size(); i++)
{
if (s_descriptors[i].flags & SKF_AUTO_HIDE)
{
diff --git a/src/xtra2.cc b/src/xtra2.cc
index d9de48cd..abb9957e 100644
--- a/src/xtra2.cc
+++ b/src/xtra2.cc
@@ -420,6 +420,8 @@ bool_ set_oppose_cc(int v)
*/
bool_ set_mimic(int v, int p, int level)
{
+ auto &s_info = game->s_info;
+
bool_ notice = FALSE;
/* Hack -- Force good values */