summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-06-20 22:49:05 +0200
committerBardur Arantsson <bardur@scientician.net>2016-06-20 22:49:05 +0200
commit9c26f78ce556d3a0717e4bc5668a1ed59217f414 (patch)
tree4dabc3014c60d469b694022d40405baa8910d843 /src
parent287df870759d0fc854f76d34151a597b9f529b43 (diff)
Change player_{race, spec, class} to non-POD types
Diffstat (limited to 'src')
-rw-r--r--src/init2.cc6
-rw-r--r--src/player_class.hpp167
-rw-r--r--src/player_race.hpp85
-rw-r--r--src/player_race_ability_type.hpp9
-rw-r--r--src/player_race_mod.hpp95
-rw-r--r--src/player_spec.hpp41
-rw-r--r--src/xtra2.cc5
7 files changed, 202 insertions, 206 deletions
diff --git a/src/init2.cc b/src/init2.cc
index 5479708f..a539a470 100644
--- a/src/init2.cc
+++ b/src/init2.cc
@@ -550,9 +550,9 @@ namespace {
static void allocate()
{
- race_info = make_array<player_race>(max_rp_idx);
- race_mod_info = make_array<player_race_mod>(max_rmp_idx);
- class_info = make_array<player_class>(max_c_idx);
+ 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);
meta_class_info = make_array<meta_class_type>(max_mc_idx);
for (std::size_t i = 0; i < max_mc_idx; i++)
diff --git a/src/player_class.hpp b/src/player_class.hpp
index d67d1d73..c5fc8916 100644
--- a/src/player_class.hpp
+++ b/src/player_class.hpp
@@ -15,91 +15,86 @@ constexpr int MAX_SPEC = 20;
*/
struct player_class
{
- const char *title; /* Type of class */
- char *desc; /* Small desc of the class */
- const char *titles[PY_MAX_LEVEL / 5];
- /* Titles */
-
- s16b c_adj[6]; /* Class stat modifier */
-
- s16b c_dis; /* class disarming */
- s16b c_dev; /* class magic devices */
- s16b c_sav; /* class saving throws */
- s16b c_stl; /* class stealth */
- s16b c_srh; /* class searching ability */
- s16b c_fos; /* class searching frequency */
- s16b c_thn; /* class to hit (normal) */
- s16b c_thb; /* class to hit (bows) */
-
- s16b x_dis; /* extra disarming */
- s16b x_dev; /* extra magic devices */
- s16b x_sav; /* extra saving throws */
- s16b x_stl; /* extra stealth */
- s16b x_srh; /* extra searching ability */
- s16b x_fos; /* extra searching frequency */
- s16b x_thn; /* extra to hit (normal) */
- s16b x_thb; /* extra to hit (bows) */
-
- s16b c_mhp; /* Class hit-dice adjustment */
- s16b c_exp; /* Class experience factor */
-
- s16b powers[4]; /* Powers of the class */
-
- s16b spell_book; /* Tval of spell books (if any) */
- s16b spell_stat; /* Stat for spells (if any) */
- s16b spell_lev; /* The higher it is the higher the spells level are */
- s16b spell_fail; /* The higher it is the higher the spells failure are */
- s16b spell_mana; /* The higher it is the higher the spells mana are */
- s16b spell_first; /* Level of first spell */
- s16b spell_weight; /* Weight that hurts spells */
- byte max_spell_level; /* Maximun spell level */
- byte magic_max_spell; /* Maximun numbner of spells one can learn by natural means */
-
- u32b flags1; /* flags */
- u32b flags2; /* flags */
-
- s16b mana;
- s16b blow_num;
- s16b blow_wgt;
- s16b blow_mul;
- s16b extra_blows;
-
- s32b sense_base;
- s32b sense_pl;
- s32b sense_plus;
- byte sense_heavy;
- byte sense_heavy_magic;
-
- s16b obj_tval[5];
- s16b obj_sval[5];
- s16b obj_pval[5];
- s16b obj_dd[5];
- s16b obj_ds[5];
- s16b obj_num;
-
- char body_parts[BODY_MAX]; /* To help to decide what to use when body changing */
-
- u32b oflags1[PY_MAX_LEVEL + 1];
- u32b oflags2[PY_MAX_LEVEL + 1];
- u32b oflags3[PY_MAX_LEVEL + 1];
- u32b oflags4[PY_MAX_LEVEL + 1];
- u32b oflags5[PY_MAX_LEVEL + 1];
- u32b oesp[PY_MAX_LEVEL + 1];
- s16b opval[PY_MAX_LEVEL + 1];
-
- char skill_basem[MAX_SKILLS];
- u32b skill_base[MAX_SKILLS];
- char skill_modm[MAX_SKILLS];
- s16b skill_mod[MAX_SKILLS];
-
- u32b gods;
-
- player_spec spec[MAX_SPEC];
-
- struct
- {
- s16b ability;
- s16b level;
- } abilities[10]; /* Abilitiers to be gained by level(doesnt take prereqs in account) */
+ const char *title = nullptr; /* Type of class */
+ char *desc = nullptr; /* Small desc of the class */
+ const char *titles[PY_MAX_LEVEL / 5] { }; /* Titles */
+
+ s16b c_adj[6] { }; /* Class stat modifier */
+
+ s16b c_dis = 0; /* class disarming */
+ s16b c_dev = 0; /* class magic devices */
+ s16b c_sav = 0; /* class saving throws */
+ s16b c_stl = 0; /* class stealth */
+ s16b c_srh = 0; /* class searching ability */
+ s16b c_fos = 0; /* class searching frequency */
+ s16b c_thn = 0; /* class to hit (normal) */
+ s16b c_thb = 0; /* class to hit (bows) */
+
+ s16b x_dis = 0; /* extra disarming */
+ s16b x_dev = 0; /* extra magic devices */
+ s16b x_sav = 0; /* extra saving throws */
+ s16b x_stl = 0; /* extra stealth */
+ s16b x_srh = 0; /* extra searching ability */
+ s16b x_fos = 0; /* extra searching frequency */
+ s16b x_thn = 0; /* extra to hit (normal) */
+ s16b x_thb = 0; /* extra to hit (bows) */
+
+ s16b c_mhp = 0; /* Class hit-dice adjustment */
+ s16b c_exp = 0; /* Class experience factor */
+
+ s16b powers[4] { }; /* Powers of the class */
+
+ s16b spell_book = 0; /* Tval of spell books (if any) */
+ s16b spell_stat = 0; /* Stat for spells (if any) */
+ s16b spell_lev = 0; /* The higher it is the higher the spells level are */
+ s16b spell_fail = 0; /* The higher it is the higher the spells failure are */
+ s16b spell_mana = 0; /* The higher it is the higher the spells mana are */
+ s16b spell_first = 0; /* Level of first spell */
+ s16b spell_weight = 0; /* Weight that hurts spells */
+ byte max_spell_level = 0; /* Maximun spell level */
+ byte magic_max_spell = 0; /* Maximun numbner of spells one can learn by natural means */
+
+ u32b flags1 = 0;
+ u32b flags2 = 0;
+
+ s16b mana = 0;
+ s16b blow_num = 0;
+ s16b blow_wgt = 0;
+ s16b blow_mul = 0;
+ s16b extra_blows = 0;
+
+ s32b sense_base = 0;
+ s32b sense_pl = 0;
+ s32b sense_plus = 0;
+ byte sense_heavy = 0;
+ byte sense_heavy_magic = 0;
+
+ s16b obj_tval[5] { };
+ s16b obj_sval[5] { };
+ s16b obj_pval[5] { };
+ s16b obj_dd[5] { };
+ s16b obj_ds[5] { };
+ s16b obj_num = 0;
+
+ char body_parts[BODY_MAX] { }; /* To help to decide what to use when body changing */
+
+ u32b oflags1[PY_MAX_LEVEL + 1] { };
+ u32b oflags2[PY_MAX_LEVEL + 1] { };
+ u32b oflags3[PY_MAX_LEVEL + 1] { };
+ u32b oflags4[PY_MAX_LEVEL + 1] { };
+ u32b oflags5[PY_MAX_LEVEL + 1] { };
+ u32b oesp[PY_MAX_LEVEL + 1] { };
+ s16b opval[PY_MAX_LEVEL + 1] { };
+
+ char skill_basem[MAX_SKILLS] { };
+ u32b skill_base[MAX_SKILLS] { };
+ char skill_modm[MAX_SKILLS] { };
+ s16b skill_mod[MAX_SKILLS] { };
+
+ u32b gods = 0;
+
+ std::array<player_spec, MAX_SPEC> spec;
+
+ std::array<player_race_ability_type, 10> abilities; /* Abilitiers to be gained by level(doesnt take prereqs in account) */
};
diff --git a/src/player_race.hpp b/src/player_race.hpp
index 3be39bdf..f1933557 100644
--- a/src/player_race.hpp
+++ b/src/player_race.hpp
@@ -3,68 +3,67 @@
#include "h-basic.h"
#include "body.hpp"
#include "player_defs.hpp"
+#include "player_race_ability_type.hpp"
#include "skills_defs.hpp"
+#include <array>
+
/**
* Player racial descriptior.
*/
struct player_race
{
- const char *title; /* Type of race */
- char *desc;
+ const char *title = nullptr; /* Type of race */
+ char *desc = nullptr;
- s16b r_adj[6]; /* Racial stat bonuses */
+ s16b r_adj[6] { }; /* Racial stat bonuses */
- char luck; /* Luck */
+ char luck = '\0'; /* Luck */
- s16b r_dis; /* disarming */
- s16b r_dev; /* magic devices */
- s16b r_sav; /* saving throw */
- s16b r_stl; /* stealth */
- s16b r_srh; /* search ability */
- s16b r_fos; /* search frequency */
- s16b r_thn; /* combat (normal) */
- s16b r_thb; /* combat (shooting) */
+ s16b r_dis = 0; /* disarming */
+ s16b r_dev = 0; /* magic devices */
+ s16b r_sav = 0; /* saving throw */
+ s16b r_stl = 0; /* stealth */
+ s16b r_srh = 0; /* search ability */
+ s16b r_fos = 0; /* search frequency */
+ s16b r_thn = 0; /* combat (normal) */
+ s16b r_thb = 0; /* combat (shooting) */
- byte r_mhp; /* Race hit-dice modifier */
- u16b r_exp; /* Race experience factor */
+ byte r_mhp = 0; /* Race hit-dice modifier */
+ u16b r_exp = 0; /* Race experience factor */
- byte infra; /* Infra-vision range */
+ byte infra = 0; /* Infra-vision range */
- u32b choice[2]; /* Legal class choices */
+ u32b choice[2] { }; /* Legal class choices */
- s16b powers[4]; /* Powers of the race */
+ s16b powers[4] { }; /* Powers of the race */
- byte body_parts[BODY_MAX]; /* To help to decide what to use when body changing */
+ byte body_parts[BODY_MAX] { }; /* To help to decide what to use when body changing */
- s16b chart; /* Chart history */
+ s16b chart = 0; /* Chart history */
- u32b flags1;
- u32b flags2; /* flags */
+ u32b flags1 = 0;
+ u32b flags2 = 0;
- u32b oflags1[PY_MAX_LEVEL + 1];
- u32b oflags2[PY_MAX_LEVEL + 1];
- u32b oflags3[PY_MAX_LEVEL + 1];
- u32b oflags4[PY_MAX_LEVEL + 1];
- u32b oflags5[PY_MAX_LEVEL + 1];
- u32b oesp[PY_MAX_LEVEL + 1];
- s16b opval[PY_MAX_LEVEL + 1];
+ u32b oflags1[PY_MAX_LEVEL + 1] { };
+ u32b oflags2[PY_MAX_LEVEL + 1] { };
+ u32b oflags3[PY_MAX_LEVEL + 1] { };
+ u32b oflags4[PY_MAX_LEVEL + 1] { };
+ u32b oflags5[PY_MAX_LEVEL + 1] { };
+ u32b oesp[PY_MAX_LEVEL + 1] { };
+ s16b opval[PY_MAX_LEVEL + 1] { };
- char skill_basem[MAX_SKILLS];
- u32b skill_base[MAX_SKILLS];
- char skill_modm[MAX_SKILLS];
- s16b skill_mod[MAX_SKILLS];
+ char skill_basem[MAX_SKILLS] { };
+ u32b skill_base[MAX_SKILLS] { };
+ char skill_modm[MAX_SKILLS] { };
+ s16b skill_mod[MAX_SKILLS] { };
- s16b obj_tval[5];
- s16b obj_sval[5];
- s16b obj_pval[5];
- s16b obj_dd[5];
- s16b obj_ds[5];
- s16b obj_num;
+ s16b obj_tval[5] { };
+ s16b obj_sval[5] { };
+ s16b obj_pval[5] { };
+ s16b obj_dd[5] { };
+ s16b obj_ds[5] { };
+ s16b obj_num = 0;
- struct
- {
- s16b ability;
- s16b level;
- } abilities[10]; /* Abilitiers to be gained by level(doesnt take prereqs in account) */
+ std::array<player_race_ability_type, 10> abilities; /* Abilitiers to be gained by level(doesnt take prereqs in account) */
};
diff --git a/src/player_race_ability_type.hpp b/src/player_race_ability_type.hpp
new file mode 100644
index 00000000..5f520052
--- /dev/null
+++ b/src/player_race_ability_type.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "h-basic.h"
+
+struct player_race_ability_type
+{
+ s16b ability = 0;
+ s16b level = 0;
+};
diff --git a/src/player_race_mod.hpp b/src/player_race_mod.hpp
index 9f21b253..23be55d7 100644
--- a/src/player_race_mod.hpp
+++ b/src/player_race_mod.hpp
@@ -3,73 +3,72 @@
#include "body.hpp"
#include "h-basic.h"
#include "player_defs.hpp"
+#include "player_race_ability_type.hpp"
#include "skills_defs.hpp"
+#include <array>
+
struct player_race_mod
{
- char *title; /* Type of race mod */
- char *desc; /* Desc */
+ char *title = nullptr; /* Type of race mod */
+ char *desc = nullptr; /* Desc */
- bool_ place; /* TRUE = race race modifier, FALSE = Race modifier race */
+ bool_ place = FALSE; /* TRUE = race race modifier, FALSE = Race modifier race */
- s16b r_adj[6]; /* (+) Racial stat bonuses */
+ s16b r_adj[6] { }; /* (+) Racial stat bonuses */
- char luck; /* Luck */
- s16b mana; /* Mana % */
+ char luck = '\0'; /* Luck */
+ s16b mana = 0; /* Mana % */
- s16b r_dis; /* (+) disarming */
- s16b r_dev; /* (+) magic devices */
- s16b r_sav; /* (+) saving throw */
- s16b r_stl; /* (+) stealth */
- s16b r_srh; /* (+) search ability */
- s16b r_fos; /* (+) search frequency */
- s16b r_thn; /* (+) combat (normal) */
- s16b r_thb; /* (+) combat (shooting) */
+ s16b r_dis = 0; /* (+) disarming */
+ s16b r_dev = 0; /* (+) magic devices */
+ s16b r_sav = 0; /* (+) saving throw */
+ s16b r_stl = 0; /* (+) stealth */
+ s16b r_srh = 0; /* (+) search ability */
+ s16b r_fos = 0; /* (+) search frequency */
+ s16b r_thn = 0; /* (+) combat (normal) */
+ s16b r_thb = 0; /* (+) combat (shooting) */
- char r_mhp; /* (+) Race mod hit-dice modifier */
- s16b r_exp; /* (+) Race mod experience factor */
+ char r_mhp = 0; /* (+) Race mod hit-dice modifier */
+ s16b r_exp = 0; /* (+) Race mod experience factor */
- char infra; /* (+) Infra-vision range */
+ char infra = '\0'; /* (+) Infra-vision range */
- u32b choice[2]; /* Legal race choices */
+ u32b choice[2] { }; /* Legal race choices */
- u32b pclass[2]; /* Classes allowed */
- u32b mclass[2]; /* Classes restricted */
+ u32b pclass[2] { }; /* Classes allowed */
+ u32b mclass[2] { }; /* Classes restricted */
- s16b powers[4]; /* Powers of the subrace */
+ s16b powers[4] { }; /* Powers of the subrace */
- char body_parts[BODY_MAX]; /* To help to decide what to use when body changing */
+ char body_parts[BODY_MAX] { }; /* To help to decide what to use when body changing */
- u32b flags1;
- u32b flags2; /* flags */
+ u32b flags1 = 0;
+ u32b flags2 = 0;
- u32b oflags1[PY_MAX_LEVEL + 1];
- u32b oflags2[PY_MAX_LEVEL + 1];
- u32b oflags3[PY_MAX_LEVEL + 1];
- u32b oflags4[PY_MAX_LEVEL + 1];
- u32b oflags5[PY_MAX_LEVEL + 1];
- u32b oesp[PY_MAX_LEVEL + 1];
- s16b opval[PY_MAX_LEVEL + 1];
+ u32b oflags1[PY_MAX_LEVEL + 1] { };
+ u32b oflags2[PY_MAX_LEVEL + 1] { };
+ u32b oflags3[PY_MAX_LEVEL + 1] { };
+ u32b oflags4[PY_MAX_LEVEL + 1] { };
+ u32b oflags5[PY_MAX_LEVEL + 1] { };
+ u32b oesp[PY_MAX_LEVEL + 1] { };
+ s16b opval[PY_MAX_LEVEL + 1] { };
- byte g_attr; /* Overlay graphic attribute */
- char g_char; /* Overlay graphic character */
+ byte g_attr = 0; /* Overlay graphic attribute */
+ char g_char = '\0'; /* Overlay graphic character */
- char skill_basem[MAX_SKILLS];
- u32b skill_base[MAX_SKILLS];
- char skill_modm[MAX_SKILLS];
- s16b skill_mod[MAX_SKILLS];
+ char skill_basem[MAX_SKILLS] { };
+ u32b skill_base[MAX_SKILLS] { };
+ char skill_modm[MAX_SKILLS] { };
+ s16b skill_mod[MAX_SKILLS] { };
- s16b obj_tval[5];
- s16b obj_sval[5];
- s16b obj_pval[5];
- s16b obj_dd[5];
- s16b obj_ds[5];
- s16b obj_num;
+ s16b obj_tval[5] { };
+ s16b obj_sval[5] { };
+ s16b obj_pval[5] { };
+ s16b obj_dd[5] { };
+ s16b obj_ds[5] { };
+ s16b obj_num = 0;
- struct
- {
- s16b ability;
- s16b level;
- } abilities[10]; /* Abilitiers to be gained by level(doesnt take prereqs in account) */
+ std::array<player_race_ability_type, 10> abilities; /* Abilities to be gained by level; doesnt take prereqs in account */
};
diff --git a/src/player_spec.hpp b/src/player_spec.hpp
index 28b32830..5105df31 100644
--- a/src/player_spec.hpp
+++ b/src/player_spec.hpp
@@ -1,38 +1,37 @@
#pragma once
#include "h-basic.h"
+#include "player_race_ability_type.hpp"
#include "skills_defs.hpp"
+#include <array>
+
/**
* Player class descriptor.
*/
struct player_spec
{
- const char *title; /* Type of class spec */
- char *desc; /* Small desc of the class spec */
+ const char *title = nullptr; /* Type of class spec */
+ char *desc = nullptr; /* Small desc of the class spec */
- char skill_basem[MAX_SKILLS]; /* Mod for value */
- u32b skill_base[MAX_SKILLS]; /* value */
- char skill_modm[MAX_SKILLS]; /* mod for mod */
- s16b skill_mod[MAX_SKILLS]; /* mod */
+ char skill_basem[MAX_SKILLS] { }; /* Mod for value */
+ u32b skill_base[MAX_SKILLS] { }; /* value */
+ char skill_modm[MAX_SKILLS] { }; /* mod for mod */
+ s16b skill_mod[MAX_SKILLS] { }; /* mod */
- u32b skill_ideal[MAX_SKILLS]; /* Ideal skill levels at level 50 */
+ u32b skill_ideal[MAX_SKILLS] { }; /* Ideal skill levels at level 50 */
- s16b obj_tval[5];
- s16b obj_sval[5];
- s16b obj_pval[5];
- s16b obj_dd[5];
- s16b obj_ds[5];
- s16b obj_num;
+ s16b obj_tval[5] { };
+ s16b obj_sval[5] { };
+ s16b obj_pval[5] { };
+ s16b obj_dd[5] { };
+ s16b obj_ds[5] { };
+ s16b obj_num = 0;
- u32b gods;
+ u32b gods = 0;
- u32b flags1;
- u32b flags2; /* flags */
+ u32b flags1 = 0;
+ u32b flags2 = 0;
- struct
- {
- s16b ability;
- s16b level;
- } abilities[10]; /* Abilitiers to be gained by level(doesnt take prereqs in account) */
+ std::array<player_race_ability_type, 10> abilities; /* Abilities to be gained by level(doesnt take prereqs in account) */
};
diff --git a/src/xtra2.cc b/src/xtra2.cc
index 222d12cd..5193aa81 100644
--- a/src/xtra2.cc
+++ b/src/xtra2.cc
@@ -5356,11 +5356,6 @@ void switch_subrace(int racem, bool_ copy_old)
/* If we switch to the saved subrace, we copy over the old subrace data */
if (copy_old && (racem == SUBRACE_SAVE))
{
- // This code is very reliant on the race_mod_info
- // elements being simple PODs, in particular the
- // text pointers being *unmanaged* owned pointers.
- static_assert(std::is_pod<player_race_mod>::value,
- "This code needs reworking");
// Keep references to owned pointers.
auto old_title = race_mod_info[SUBRACE_SAVE].title;
auto old_desc = race_mod_info[SUBRACE_SAVE].desc;