summaryrefslogtreecommitdiff
path: root/src
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:45:08 +0200
commit3cdeb22086fc177165acb2d7b6530ccc230ec8e6 (patch)
tree3a026b45b8cb1af24aad41bf242a4e8b5b555772 /src
parentbea14b1db03fcd62d7dfd6633a0802f222792311 (diff)
Move class_info to GameEditData
Diffstat (limited to 'src')
-rw-r--r--src/birth.cc17
-rw-r--r--src/files.cc2
-rw-r--r--src/game_edit_data.hpp6
-rw-r--r--src/help.cc4
-rw-r--r--src/help.hpp4
-rw-r--r--src/init1.cc36
-rw-r--r--src/init2.cc1
-rw-r--r--src/loadsave.cc2
-rw-r--r--src/notes.cc3
-rw-r--r--src/player_class.hpp4
-rw-r--r--src/variable.cc10
-rw-r--r--src/variable.hpp6
12 files changed, 49 insertions, 46 deletions
diff --git a/src/birth.cc b/src/birth.cc
index 67817673..ba0ed9df 100644
--- a/src/birth.cc
+++ b/src/birth.cc
@@ -1176,6 +1176,8 @@ static void player_outfit(void)
static void dump_classes(std::vector<u16b> const &classes, int sel, u32b *restrictions)
{
+ auto const &class_info = game->edit_data.class_info;
+
char buf[80];
/* Clean up */
@@ -1200,7 +1202,7 @@ static void dump_classes(std::vector<u16b> const &classes, int sel, u32b *restri
/* Display */
strnfmt(buf, 80, "%c%c%c %s%s", p1,
- (n <= 25) ? I2A(n) : I2D(n - 26), p2, cp_ptr->title, mod);
+ (n <= 25) ? I2A(n) : I2D(n - 26), p2, cp_ptr->title.c_str(), mod);
/* Print some more info */
if (sel == n)
@@ -1235,6 +1237,8 @@ static void dump_classes(std::vector<u16b> const &classes, int sel, u32b *restri
static void dump_specs(int sel_)
{
+ auto const &class_info = game->edit_data.class_info;
+
assert(sel_ >= 0);
std::size_t sel = sel_;
@@ -1477,6 +1481,8 @@ static bool_ do_quick_start = FALSE;
static bool_ player_birth_aux_ask()
{
+ auto &class_info = game->edit_data.class_info;
+
int k, n, v, sel;
int racem[100], max_racem = 0;
@@ -1793,19 +1799,16 @@ static bool_ player_birth_aux_ask()
// Get list of all the classes.
std::vector<u16b> class_types;
- for (std::size_t i = 0; i < max_c_idx; i++)
+ for (std::size_t i = 0; i < class_info.size(); i++)
{
- if (class_info[i].title)
- {
- class_types.push_back(i);
- }
+ class_types.push_back(i);
}
// Sort into display order
std::stable_sort(
class_types.begin(),
class_types.end(),
- [](auto i, auto j) {
+ [&class_info](auto i, auto j) {
return class_info[i].display_order_idx < class_info[j].display_order_idx;
}
);
diff --git a/src/files.cc b/src/files.cc
index 12c05345..24545ef3 100644
--- a/src/files.cc
+++ b/src/files.cc
@@ -4402,6 +4402,8 @@ static void show_info(void)
*/
static void display_scores_aux(int highscore_fd, int from, int to, int note, high_score *score)
{
+ auto const &class_info = game->edit_data.class_info;
+
int i, j, k, n, place;
byte attr;
char out_val[256];
diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp
index 8ffb6b9a..c6f45dc0 100644
--- a/src/game_edit_data.hpp
+++ b/src/game_edit_data.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "owner_type.hpp"
+#include "player_class.hpp"
#include "randart_gen_type.hpp"
#include "randart_part_type.hpp"
#include "store_action_type.hpp"
@@ -40,4 +41,9 @@ struct GameEditData {
*/
std::vector<owner_type> ow_info;
+ /**
+ * Player classes.
+ */
+ std::vector<player_class> class_info;
+
};
diff --git a/src/help.cc b/src/help.cc
index f8d75e79..55051bfa 100644
--- a/src/help.cc
+++ b/src/help.cc
@@ -713,9 +713,9 @@ void help_subrace(cptr subrace)
show_context_help(find_context_help(subrace_table, subrace));
}
-void help_class(cptr klass)
+void help_class(std::string const &klass)
{
- show_context_help(find_context_help(class_table, klass));
+ show_context_help(find_context_help(class_table, klass.c_str()));
}
void help_god(cptr god)
diff --git a/src/help.hpp b/src/help.hpp
index 7c057a01..5272226e 100644
--- a/src/help.hpp
+++ b/src/help.hpp
@@ -2,10 +2,12 @@
#include "h-basic.h"
+#include <string>
+
extern void init_hooks_help();
extern void help_race(cptr race);
extern void help_subrace(cptr subrace);
-extern void help_class(cptr klass);
+extern void help_class(std::string const &klass);
extern void help_god(cptr god);
extern void help_skill(cptr skill);
extern void help_ability(cptr ability);
diff --git a/src/init1.cc b/src/init1.cc
index ac1d6bc7..b4c0a5ac 100644
--- a/src/init1.cc
+++ b/src/init1.cc
@@ -682,13 +682,12 @@ static void strappend(char **s, const char *t)
static bool_ unknown_shut_up = FALSE;
static errr grab_one_class_flag(u32b *choice, cptr what)
{
- int i;
- cptr s;
+ auto const &class_info = game->edit_data.class_info;
/* Scan classes flags */
- for (i = 0; i < max_c_idx && (s = class_info[i].title); i++)
+ for (std::size_t i = 0; i < class_info.size(); i++)
{
- if (streq(what, s))
+ if (class_info[i].title == what)
{
(choice[i / 32]) |= (1L << i);
return (0);
@@ -921,6 +920,8 @@ static int read_ability(std::vector<player_race_ability_type> *abilities, char *
*/
errr init_player_info_txt(FILE *fp)
{
+ auto &class_info = game->edit_data.class_info;
+
int lev = 1;
int tit_idx = 0;
char buf[1024];
@@ -1492,18 +1493,17 @@ errr init_player_info_txt(FILE *fp)
/* Get the entry index */
int i = atoi(buf + 4);
if (i < error_idx) return (4);
- if (i >= max_c_idx) return (2);
/* Save the index */
error_idx = i;
/* Point at the "info" */
- c_ptr = &class_info[i];
+ c_ptr = &expand_to_fit_index(class_info, i);
+ assert(c_ptr->title.empty());
- /* Copy name */
- assert(!c_ptr->title);
+ /* Initialize */
c_ptr->display_order_idx = std::stoi(fields[0]);
- c_ptr->title = my_strdup(fields[1].c_str());
+ c_ptr->title = fields[1];
/* Initialize */
lev = 1;
@@ -1522,15 +1522,13 @@ errr init_player_info_txt(FILE *fp)
switch (buf[4])
{
case '0': /* Class description */
- if (!c_ptr->desc)
+ // Need newline?
+ if (!c_ptr->desc.empty())
{
-
- c_ptr->desc = my_strdup(s);
- }
- else
- {
- strappend(&c_ptr->desc, format("\n%s", s));
+ c_ptr->desc += '\n';
}
+ // Append
+ c_ptr->desc += s;
break;
case '1': /* Class title */
@@ -6960,10 +6958,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst
{
max_rmp_idx = atoi(zz[2]);
}
- else if (zz[1][0] == 'C')
- {
- max_c_idx = atoi(zz[2]);
- }
else if (zz[1][0] == 'H')
{
max_bg_idx = atoi(zz[2]);
@@ -7222,7 +7216,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp)
/* Class */
else if (streq(b + 1, "CLASS"))
{
- v = cp_ptr->title;
+ v = cp_ptr->title.c_str(); // The string SHOULD be stable enough for this
}
/* Player */
diff --git a/src/init2.cc b/src/init2.cc
index 327556e3..9800c4f4 100644
--- a/src/init2.cc
+++ b/src/init2.cc
@@ -553,7 +553,6 @@ namespace {
{
race_info = new player_race[max_rp_idx];
race_mod_info = new player_race_mod[max_rmp_idx];
- class_info = new player_class[max_c_idx];
bg = make_array<hist_type>(max_bg_idx);
gen_skill = new skill_modifiers;
}
diff --git a/src/loadsave.cc b/src/loadsave.cc
index 8c2a79c4..82603563 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -2427,6 +2427,8 @@ static bool do_player_hd(ls_flag_t flag)
*/
static bool_ do_savefile_aux(ls_flag_t flag)
{
+ auto &class_info = game->edit_data.class_info;
+
/* Mention the savefile version */
if (flag == ls_flag_t::LOAD)
{
diff --git a/src/notes.cc b/src/notes.cc
index 8804509e..071b02e9 100644
--- a/src/notes.cc
+++ b/src/notes.cc
@@ -10,6 +10,7 @@
#include "notes.hpp"
#include "files.hpp"
+#include "game.hpp"
#include "player_class.hpp"
#include "player_type.hpp"
#include "util.hpp"
@@ -113,6 +114,8 @@ void add_note(char *note, char code)
*/
void add_note_type(int note_number)
{
+ auto const &class_info = game->edit_data.class_info;
+
char true_long_day[50];
char buf[1024];
time_t ct = time((time_t*)0);
diff --git a/src/player_class.hpp b/src/player_class.hpp
index 0e6f5839..02d0fc11 100644
--- a/src/player_class.hpp
+++ b/src/player_class.hpp
@@ -16,8 +16,8 @@
*/
struct player_class
{
- const char *title = nullptr; /* Type of class */
- char *desc = nullptr; /* Small desc of the class */
+ std::string title; /* Type of class */
+ std::string desc; /* Small desc of the class */
const char *titles[PY_MAX_LEVEL / 5] { }; /* Titles */
int display_order_idx; /* Display order index; lowest first */
diff --git a/src/variable.cc b/src/variable.cc
index 6356d2b9..30d07469 100644
--- a/src/variable.cc
+++ b/src/variable.cc
@@ -424,8 +424,8 @@ player_type *p_ptr = nullptr;
*/
player_race *rp_ptr;
player_race_mod *rmp_ptr;
-player_class *cp_ptr;
-player_spec *spp_ptr;
+player_class const *cp_ptr;
+player_spec const *spp_ptr;
/*
@@ -498,11 +498,6 @@ player_race *race_info;
player_race_mod *race_mod_info;
/*
- * Player class arrays
- */
-player_class *class_info;
-
-/*
* The wilderness features arrays
*/
wilderness_type_info *wf_info;
@@ -689,7 +684,6 @@ u16b max_set_idx = 1;
*/
u16b max_rp_idx;
u16b max_rmp_idx;
-u16b max_c_idx;
/*
* Maximum number of objects in the level
diff --git a/src/variable.hpp b/src/variable.hpp
index d8e5cb17..a86f4d2e 100644
--- a/src/variable.hpp
+++ b/src/variable.hpp
@@ -158,8 +158,8 @@ extern char *keymap_act[KEYMAP_MODES][256];
extern player_type *p_ptr;
extern player_race *rp_ptr;
extern player_race_mod *rmp_ptr;
-extern player_class *cp_ptr;
-extern player_spec *spp_ptr;
+extern player_class const *cp_ptr;
+extern player_spec const *spp_ptr;
extern char player_name[32];
extern char player_base[32];
extern ability_type *ab_info;
@@ -172,7 +172,6 @@ extern ego_item_type *e_info;
extern monster_race *r_info;
extern monster_ego *re_info;
extern dungeon_info_type *d_info;
-extern player_class *class_info;
extern player_race *race_info;
extern player_race_mod *race_mod_info;
extern trap_type *t_info;
@@ -203,7 +202,6 @@ extern u16b max_o_idx;
extern u16b max_m_idx;
extern u16b max_t_idx;
extern u16b max_rp_idx;
-extern u16b max_c_idx;
extern u16b max_rmp_idx;
extern u16b max_st_idx;
extern u16b max_wf_idx;