summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:14 +0200
committerBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:14 +0200
commit1e045ed09258e6c7fff63ef829759c6c8f06f441 (patch)
tree89a8737e5d33ccf2723a199efdf0aa8eb2d175e4
parent86fba667d4aaf01b0efc47e26b8e482f13349038 (diff)
Separate skill values from skill descriptions
-rw-r--r--src/birth.cc11
-rw-r--r--src/init1.cc27
-rw-r--r--src/init2.cc1
-rw-r--r--src/skill_descriptor.hpp30
-rw-r--r--src/skill_descriptor_fwd.hpp3
-rw-r--r--src/skill_type.hpp42
-rw-r--r--src/skills.cc83
-rw-r--r--src/squelch/condition.cc4
-rw-r--r--src/variable.cc5
-rw-r--r--src/variable.hpp2
-rw-r--r--src/xtra1.cc4
11 files changed, 127 insertions, 85 deletions
diff --git a/src/birth.cc b/src/birth.cc
index 086f932f..2ed3fc79 100644
--- a/src/birth.cc
+++ b/src/birth.cc
@@ -2782,7 +2782,10 @@ static bool_ player_birth_aux()
if (!player_birth_aux_ask()) return (FALSE);
for (i = 1; i < max_s_idx; i++)
+ {
s_info[i].dev = FALSE;
+ }
+
for (i = 1; i < max_s_idx; i++)
{
s32b value = 0, mod = 0;
@@ -2794,14 +2797,18 @@ static bool_ player_birth_aux()
/* Develop only revelant branches */
if (s_info[i].value || s_info[i].mod)
{
- int z = s_info[i].father;
+ int z = s_descriptors[i].father;
while (z != -1)
{
+ // Mark as developed
s_info[z].dev = TRUE;
- z = s_info[z].father;
+ // Next node up the tree
+ z = s_descriptors[z].father;
if (z == 0)
+ {
break;
+ }
}
}
}
diff --git a/src/init1.cc b/src/init1.cc
index 028e6b14..5395ed70 100644
--- a/src/init1.cc
+++ b/src/init1.cc
@@ -3085,12 +3085,12 @@ errr init_set_info_txt(FILE *fp)
*/
errr init_s_info_txt(FILE *fp)
{
- int i, z, order = 1;
+ int i, order = 1;
char buf[1024];
char *s;
/* Current entry */
- skill_type *s_ptr = NULL;
+ skill_descriptor *s_ptr = NULL;
/* Just before the first record */
@@ -3131,8 +3131,8 @@ errr init_s_info_txt(FILE *fp)
s2 = find_skill(sec);
if (s2 == -1) return (1);
- s_info[s2].father = s1;
- s_info[s2].order = order++;
+ s_descriptors[s2].father = s1;
+ s_descriptors[s2].order = order++;
/* Next... */
continue;
@@ -3157,8 +3157,8 @@ errr init_s_info_txt(FILE *fp)
s2 = find_skill(sec);
if ((s1 == -1) || (s2 == -1)) return (1);
- s_info[s1].action[s2] = SKILL_EXCLUSIVE;
- s_info[s2].action[s1] = SKILL_EXCLUSIVE;
+ s_descriptors[s1].action[s2] = SKILL_EXCLUSIVE;
+ s_descriptors[s2].action[s1] = SKILL_EXCLUSIVE;
/* Next... */
continue;
@@ -3191,7 +3191,7 @@ errr init_s_info_txt(FILE *fp)
s2 = find_skill(sec);
if ((s1 == -1) || (s2 == -1)) return (1);
- s_info[s1].action[s2] = -atoi(cval);
+ s_descriptors[s1].action[s2] = -atoi(cval);
/* Next... */
continue;
@@ -3223,7 +3223,7 @@ errr init_s_info_txt(FILE *fp)
s2 = find_skill(sec);
if ((s1 == -1) || (s2 == -1)) return (1);
- s_info[s1].action[s2] = atoi(cval);
+ s_descriptors[s1].action[s2] = atoi(cval);
/* Next... */
continue;
@@ -3254,21 +3254,12 @@ errr init_s_info_txt(FILE *fp)
error_idx = i;
/* Point at the "info" */
- s_ptr = &s_info[i];
+ s_ptr = &s_descriptors[i];
/* Copy name */
assert(!s_ptr->name);
s_ptr->name = my_strdup(s);
- /* Init */
- s_ptr->action_mkey = 0;
- s_ptr->dev = FALSE;
- s_ptr->random_gain_chance = 100;
- for (z = 0; z < max_s_idx; z++)
- {
- s_ptr->action[z] = 0;
- }
-
/* Next... */
continue;
}
diff --git a/src/init2.cc b/src/init2.cc
index 0fb1a5a8..ad96df86 100644
--- a/src/init2.cc
+++ b/src/init2.cc
@@ -344,6 +344,7 @@ namespace {
static void allocate()
{
s_info = new skill_type[max_s_idx];
+ s_descriptors = new skill_descriptor[max_s_idx];
}
static errr parse(FILE *fp)
diff --git a/src/skill_descriptor.hpp b/src/skill_descriptor.hpp
new file mode 100644
index 00000000..687597da
--- /dev/null
+++ b/src/skill_descriptor.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "skill_descriptor_fwd.hpp"
+
+#include "h-basic.h"
+#include "skill_flag_set.hpp"
+#include "skills_defs.hpp"
+
+/**
+ * Skill descriptor.
+ */
+struct skill_descriptor {
+
+ const char *name = nullptr; /* Name */
+ char *desc = nullptr; /* Description */
+
+ const char *action_desc = nullptr; /* Action Description */
+
+ s16b action_mkey = 0; /* Action do to */
+
+ s16b action[MAX_SKILLS] = { 0 }; /* List of actions against other skills */
+
+ s16b father = 0; /* Father in the skill tree */
+ s16b order = 0; /* Order in the tree */
+
+ byte random_gain_chance = 100; /* Chance to gain from Lost Sword quest; if applicable */
+
+ skill_flag_set flags; /* Skill flags */
+
+};
diff --git a/src/skill_descriptor_fwd.hpp b/src/skill_descriptor_fwd.hpp
new file mode 100644
index 00000000..136f337b
--- /dev/null
+++ b/src/skill_descriptor_fwd.hpp
@@ -0,0 +1,3 @@
+#pragma once
+
+struct skill_descriptor;
diff --git a/src/skill_type.hpp b/src/skill_type.hpp
index 644ba716..e93303e6 100644
--- a/src/skill_type.hpp
+++ b/src/skill_type.hpp
@@ -3,30 +3,30 @@
#include "h-basic.h"
#include "skill_flag_set.hpp"
#include "skills_defs.hpp"
+#include "skill_descriptor.hpp"
/**
- * Skill descriptors and runtime data.
+ * Skill runtime data.
*/
struct skill_type
{
- const char *name = nullptr; /* Name */
- char *desc = nullptr; /* Description */
-
- const char *action_desc = nullptr; /* Action Description */
-
- s16b action_mkey = 0; /* Action do to */
-
- s32b value = 0; /* Current value */
- s32b mod = 0; /* Modifier, i.e. how much value 1 skill point gives */
-
- s16b action[MAX_SKILLS] = { 0 }; /* List of actions against other skills */
-
- s16b father = 0; /* Father in the skill tree */
- bool_ dev = FALSE; /* Is the branch developped ? */
- s16b order = 0; /* Order in the tree */
- bool_ hidden = FALSE; /* Inactive */
-
- byte random_gain_chance = 0; /* Chance to gain from Lost Sword quest; if applicable */
-
- skill_flag_set flags; /* Skill flags */
+ /**
+ * Current value.
+ */
+ s32b value = 0;
+
+ /**
+ * Current modifier, i.e. how much value 1 skill point gives.
+ */
+ s32b mod = 0;
+
+ /**
+ * Is the branch developed?
+ */
+ bool_ dev = FALSE;
+
+ /**
+ * Is the skill hidden?
+ */
+ bool_ hidden = FALSE;
};
diff --git a/src/skills.cc b/src/skills.cc
index 155672f6..a46bf7ed 100644
--- a/src/skills.cc
+++ b/src/skills.cc
@@ -122,20 +122,19 @@ static void decrease_skill(int i, s16b *invest)
*/
s16b find_skill(cptr name)
{
- u16b i;
-
/* Scan skill list */
- for (i = 1; i < max_s_idx; i++)
+ for (int i = 1; i < max_s_idx; i++)
{
- if (s_info[i].name && streq(s_info[i].name, name))
+ if (s_descriptors[i].name && streq(s_descriptors[i].name, name))
{
return (i);
}
}
/* No match found */
- return ( -1);
+ return -1;
}
+
s16b find_skill_i(cptr name)
{
u16b i;
@@ -144,7 +143,7 @@ s16b find_skill_i(cptr name)
for (i = 1; i < max_s_idx; i++)
{
/* The name matches */
- if (s_info[i].name && iequals(s_info[i].name, name))
+ if (s_descriptors[i].name && iequals(s_descriptors[i].name, name))
{
return (i);
}
@@ -191,7 +190,7 @@ static int get_idx(int i)
{
for (int j = 1; j < max_s_idx; j++)
{
- if (s_info[j].order == i)
+ if (s_descriptors[j].order == i)
return (j);
}
return (0);
@@ -207,7 +206,7 @@ static bool_ is_known(int s_idx)
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 (s_descriptors[i].father == s_idx)
{
if (is_known(i))
return TRUE;
@@ -223,7 +222,7 @@ static void init_table_aux(int table[MAX_SKILLS][2], int *idx, int father, int l
for (int j = 1; j < max_s_idx; j++)
{
int i = get_idx(j);
- if (s_info[i].father != father) continue;
+ if (s_descriptors[i].father != father) continue;
if (s_info[i].hidden) continue;
if (!is_known(i)) continue;
@@ -240,16 +239,17 @@ static void init_table(int table[MAX_SKILLS][2], int *max, bool_ full)
init_table_aux(table, max, -1, 0, full);
}
-static bool_ has_child(int sel)
+static bool has_child(int sel)
{
- int i;
-
- for (i = 1; i < max_s_idx; i++)
+ for (int i = 1; i < max_s_idx; i++)
{
- if ((s_info[i].father == sel) && (is_known(i)))
- return (TRUE);
+ if ((s_descriptors[i].father == sel) && is_known(i))
+ {
+ return true;
+ }
}
- return (FALSE);
+
+ return false;
}
@@ -283,11 +283,11 @@ void dump_skills(FILE *fff)
if (!has_child(i))
{
- strcat(buf, format(" . %s", s_info[i].name));
+ strcat(buf, format(" . %s", s_descriptors[i].name));
}
else
{
- strcat(buf, format(" - %s", s_info[i].name));
+ strcat(buf, format(" - %s", s_descriptors[i].name));
}
fprintf(fff, "%-49s%s%06.3f [%05.3f]",
@@ -317,7 +317,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, 3, 0);
+ print_desc_aux(s_descriptors[table[sel][0]].desc, 3, 0);
for (j = start; j < start + (hgt - 7); j++)
{
@@ -343,17 +343,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),
+ c_prt(color, format("%c.%c%s", deb, end, s_descriptors[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),
+ c_prt(color, format("%c-%c%s", deb, end, s_descriptors[i].name),
j + 7 - start, table[j][1] * 4);
}
else
{
- c_prt(color, format("%c+%c%s", deb, end, s_info[i].name),
+ c_prt(color, format("%c+%c%s", deb, end, s_descriptors[i].name),
j + 7 - start, table[j][1] * 4);
}
c_prt(color,
@@ -444,7 +444,7 @@ static void recalc_skills_theory(s16b *invest, s32b *base_val, s32b *base_mod, s
if (j == i) continue;
/* Exclusive skills */
- if ((s_info[i].action[j] == SKILL_EXCLUSIVE) && invest[i])
+ if ((s_descriptors[i].action[j] == SKILL_EXCLUSIVE) && invest[i])
{
/* Turn it off */
p_ptr->skill_points += invest[j];
@@ -453,10 +453,10 @@ static void recalc_skills_theory(s16b *invest, s32b *base_val, s32b *base_mod, s
}
/* Non-exclusive skills */
- else if (s_info[i].action[j])
+ else if (s_descriptors[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);
+ s32b val = s_info[j].value + (invest[i] * s_info[j].mod * s_descriptors[i].action[j] / 100);
/* It cannot exceed SKILL_MAX */
if (val > SKILL_MAX) val = SKILL_MAX;
@@ -581,7 +581,7 @@ void do_cmd_skill()
/* Contextual help */
if (c == '?')
{
- help_skill(s_info[table[sel][0]].name);
+ help_skill(s_descriptors[table[sel][0]].name);
}
/* Handle boundaries and scrolling */
@@ -817,14 +817,14 @@ static int do_cmd_activate_skill_aux()
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)))
+ if (s_descriptors[i].action_mkey && s_info[i].value && ((!s_info[i].hidden) || (i == SKILL_LEARN)))
{
bool_ next = FALSE;
/* Already got it ? */
for (size_t j = 0; j < p.size(); j++)
{
- if (s_info[i].action_mkey == std::get<1>(p[j]))
+ if (s_descriptors[i].action_mkey == std::get<1>(p[j]))
{
next = TRUE;
break;
@@ -832,8 +832,8 @@ static int do_cmd_activate_skill_aux()
}
if (next) continue;
- p.push_back(std::make_tuple(s_info[i].action_desc,
- s_info[i].action_mkey));
+ p.push_back(std::make_tuple(s_descriptors[i].action_desc,
+ s_descriptors[i].action_mkey));
}
}
@@ -965,7 +965,7 @@ void do_cmd_activate_skill()
/* Check validity */
for (i = 1; i < max_s_idx; i++)
{
- if (s_info[i].value && (s_info[i].action_mkey == x_idx))
+ if (s_info[i].value && (s_descriptors[i].action_mkey == x_idx))
break;
}
for (j = 0; j < max_ab_idx; j++)
@@ -1205,7 +1205,7 @@ void init_skill(s32b value, s32b mod, int i)
{
s_info[i].value = value;
s_info[i].mod = mod;
- s_info[i].hidden = (s_info[i].flags & SKF_HIDDEN)
+ s_info[i].hidden = (s_descriptors[i].flags & SKF_HIDDEN)
? TRUE
: FALSE
;
@@ -1283,7 +1283,8 @@ void do_get_new_skill()
max_a = 0;
for (i = 0; i < max_s_idx; i++)
{
- if (s_info[i].flags & SKF_RANDOM_GAIN) {
+ if (s_descriptors[i].flags & SKF_RANDOM_GAIN)
+ {
available_skills[max_a] = i;
max_a++;
}
@@ -1292,7 +1293,7 @@ void do_get_new_skill()
/* Perform the selection */
std::vector<s32b> weights;
for (i = 0; i < max_a; i++) {
- weights.push_back(s_info[available_skills[i]].random_gain_chance);
+ weights.push_back(s_descriptors[available_skills[i]].random_gain_chance);
}
std::vector<size_t> indexes = wrs(weights);
@@ -1336,7 +1337,7 @@ void do_get_new_skill()
skl[i] = s_idx;
items.push_back(format("%-40s: +%02ld.%03ld value, +%01d.%03d modifier",
- s_ptr->name,
+ s_descriptors[s_idx].name,
val[i] / SKILL_STEP,
val[i] % SKILL_STEP,
mod[i] / SKILL_STEP,
@@ -1353,14 +1354,13 @@ void do_get_new_skill()
/* 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) &&
+ if ((s_descriptors[i].action[skl[res]] == SKILL_EXCLUSIVE) &&
(s_info[i].value != 0))
{
oppose = TRUE;
@@ -1383,24 +1383,25 @@ 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_descriptors[oppose_skill].name);
/* The player rejected the choice */
if (!get_check(msg)) continue;
}
- s_ptr = &s_info[skl[res]];
+ auto const s_desc = &s_descriptors[skl[res]];
+ auto const 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_desc->name);
}
else
{
msg_format("Your knowledge of the %s skill increases.",
- s_ptr->name);
+ s_desc->name);
}
break;
}
diff --git a/src/squelch/condition.cc b/src/squelch/condition.cc
index 41806feb..1b58b752 100644
--- a/src/squelch/condition.cc
+++ b/src/squelch/condition.cc
@@ -773,7 +773,7 @@ std::shared_ptr<Condition> SkillCondition::from_json(json_t *j)
void SkillCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t bcol) const
{
p->write(ecol, "Your skill in ");
- p->write(bcol, s_info[m_skill_idx].name);
+ p->write(bcol, s_descriptors[m_skill_idx].name);
p->write(ecol, " is from ");
p->write(TERM_WHITE, format("%d", (int) m_min));
p->write(ecol, " to ");
@@ -784,7 +784,7 @@ void SkillCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t
void SkillCondition::to_json(json_t *j) const
{
json_object_set_new(j, "name",
- json_string(s_info[m_skill_idx].name));
+ json_string(s_descriptors[m_skill_idx].name));
json_object_set_new(j, "min",
json_integer(m_min));
json_object_set_new(j, "max",
diff --git a/src/variable.cc b/src/variable.cc
index 00fd340d..827ee1af 100644
--- a/src/variable.cc
+++ b/src/variable.cc
@@ -510,6 +510,11 @@ ability_type *ab_info;
*/
skill_type *s_info;
+/**
+ * Skill descriptors.
+ */
+skill_descriptor *s_descriptors;
+
/*
* Player race arrays
*/
diff --git a/src/variable.hpp b/src/variable.hpp
index 9d737930..52dbc455 100644
--- a/src/variable.hpp
+++ b/src/variable.hpp
@@ -36,6 +36,7 @@
#include "rune_spell.hpp"
#include "school_type.hpp"
#include "set_type_fwd.hpp"
+#include "skill_descriptor_fwd.hpp"
#include "skill_modifiers_fwd.hpp"
#include "skill_type_fwd.hpp"
#include "skills_defs.hpp"
@@ -174,6 +175,7 @@ extern char player_name[32];
extern char player_base[32];
extern ability_type *ab_info;
extern skill_type *s_info;
+extern skill_descriptor *s_descriptors;
extern vault_type *v_info;
extern feature_type *f_info;
extern object_kind *k_info;
diff --git a/src/xtra1.cc b/src/xtra1.cc
index fbbd7922..c97d3663 100644
--- a/src/xtra1.cc
+++ b/src/xtra1.cc
@@ -2972,8 +2972,10 @@ void calc_bonuses(bool_ silent)
/* Hide the skills that should auto hide */
for (i = 0; i < max_s_idx; i++)
{
- if (s_info[i].flags & SKF_AUTO_HIDE)
+ if (s_descriptors[i].flags & SKF_AUTO_HIDE)
+ {
s_info[i].hidden = TRUE;
+ }
}
/* Base Luck */