summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:13 +0200
committerBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:13 +0200
commit50c916646b647030755673a9a1dc82e192e492d4 (patch)
treeeb9d7a2b5e27be18f7d1905bed262535a18d05e9 /src
parent8c538df0f6f481c4ac70bf15d9f49621d21aa821 (diff)
Change player_class::spec to a std::vector<>
Diffstat (limited to 'src')
-rw-r--r--src/birth.cc39
-rw-r--r--src/init1.cc19
-rw-r--r--src/player_class.hpp7
3 files changed, 25 insertions, 40 deletions
diff --git a/src/birth.cc b/src/birth.cc
index be8a8a33..8d14da00 100644
--- a/src/birth.cc
+++ b/src/birth.cc
@@ -1235,25 +1235,23 @@ static void dump_classes(std::vector<u16b> const &classes, int sel, u32b *restri
}
}
-static int dump_specs(int sel)
+static void dump_specs(int sel_)
{
- int n = 0;
-
- char buf[80];
+ assert(sel_ >= 0);
+ std::size_t sel = sel_;
- /* Clean up */
clear_from(12);
- for (n = 0; n < MAX_SPEC; n++)
- {
- char p2 = ')', p1 = ' ';
+ auto specs = &class_info[p_ptr->pclass].spec;
- /* Found the last one ? */
- if (!class_info[p_ptr->pclass].spec[n].title) break;
+ for (std::size_t n = 0; n < specs->size(); n++)
+ {
+ char p2 = ')';
+ char p1 = ' ';
/* Analyze */
p_ptr->pspec = n;
- spp_ptr = &class_info[p_ptr->pclass].spec[p_ptr->pspec];
+ spp_ptr = &(*specs)[p_ptr->pspec];
if (sel == n)
{
@@ -1262,6 +1260,7 @@ static int dump_specs(int sel)
}
/* Display */
+ char buf[80];
strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, spp_ptr->title);
/* Print some more info */
@@ -1278,20 +1277,26 @@ static int dump_specs(int sel)
print_desc(desc.c_str());
if (spp_ptr->flags & PR_EXPERIMENTAL)
+ {
c_put_str(TERM_BLUE, buf, 18 + (n / 4), 1 + 20 * (n % 4));
+ }
else
+ {
c_put_str(TERM_L_BLUE, buf, 18 + (n / 4), 1 + 20 * (n % 4));
+ }
}
else
{
if (spp_ptr->flags & PR_EXPERIMENTAL)
+ {
c_put_str(TERM_SLATE, buf, 18 + (n / 4), 1 + 20 * (n % 4));
+ }
else
+ {
put_str(buf, 18 + (n / 4), 1 + 20 * (n % 4));
+ }
}
}
-
- return (n);
}
static int dump_races(int sel)
@@ -1911,11 +1916,7 @@ static bool_ player_birth_aux_ask()
clear_from(15);
/* Count choices */
- for (n = 0; n < MAX_SPEC; n++)
- {
- /* Found the last one ? */
- if (!class_info[p_ptr->pclass].spec[n].title) break;
- }
+ n = class_info[p_ptr->pclass].spec.size();
/* Only one choice = auto choice */
if (n == 1)
@@ -1924,7 +1925,7 @@ static bool_ player_birth_aux_ask()
{
/* Dump classes spec */
sel = 0;
- n = dump_specs(sel);
+ dump_specs(sel);
/* Get a class */
while (1)
diff --git a/src/init1.cc b/src/init1.cc
index 1d04509b..0654155e 100644
--- a/src/init1.cc
+++ b/src/init1.cc
@@ -916,7 +916,6 @@ errr init_player_info_txt(FILE *fp)
int powers = 0;
int lev = 1;
int tit_idx = 0;
- int spec_idx = 0;
char buf[1024];
char *s, *t;
@@ -1475,8 +1474,6 @@ errr init_player_info_txt(FILE *fp)
/* Process 'N' for "New/Number/Name" */
if ((buf[0] == 'C') && (buf[2] == 'N'))
{
- int z;
-
/* Find the colon before the name */
s = strchr(buf + 4, ':');
@@ -1513,9 +1510,6 @@ errr init_player_info_txt(FILE *fp)
powers = 0;
lev = 1;
tit_idx = 0;
- spec_idx = -1;
- for (z = 0; z < MAX_SPEC; z++)
- c_ptr->spec[z].title = 0;
/* Next... */
continue;
@@ -1771,17 +1765,12 @@ errr init_player_info_txt(FILE *fp)
/* Paranoia -- require a name */
if (!*s) return (1);
- /* Get the index */
- spec_idx++;
-
- /* Verify information */
- if (spec_idx >= MAX_SPEC) return (2);
- /* Point at the "info" */
- s_ptr = &c_ptr->spec[spec_idx];
+ /* Create the spec entry */
+ c_ptr->spec.emplace_back(player_spec());
- /* Copy title */
- assert(!s_ptr->title);
+ /* Fill in initial values */
+ s_ptr = &c_ptr->spec.back();
s_ptr->title = my_strdup(s);
/* Next... */
diff --git a/src/player_class.hpp b/src/player_class.hpp
index 57282e27..9d9991e3 100644
--- a/src/player_class.hpp
+++ b/src/player_class.hpp
@@ -11,11 +11,6 @@
#include "skill_modifiers.hpp"
/**
- * Maximum number of specialties.
- */
-constexpr int MAX_SPEC = 20;
-
-/**
* Player descriptor and runtime data.
*/
struct player_class
@@ -49,7 +44,7 @@ struct player_class
u32b gods = 0;
- std::array<player_spec, MAX_SPEC> spec;
+ std::vector<player_spec> spec;
std::vector<player_race_ability_type> abilities; /* Abilities to be gained by level; ignores prereqs */
};