summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/birth.cc10
-rw-r--r--src/cmd7.cc132
-rw-r--r--src/loadsave.cc22
-rw-r--r--src/player_type.hpp6
-rw-r--r--src/rune_spell.hpp8
-rw-r--r--src/variable.cc6
-rw-r--r--src/variable.hpp3
7 files changed, 72 insertions, 115 deletions
diff --git a/src/birth.cc b/src/birth.cc
index 9081ec06..bb2f0816 100644
--- a/src/birth.cc
+++ b/src/birth.cc
@@ -762,16 +762,6 @@ static void player_wipe(void)
}
}
- /* Wipe the rune spells */
- rune_num = 0;
- for (i = 0; i < MAX_RUNES; i++)
- {
- strcpy(rune_spells[i].name, "");
- rune_spells[i].type = 0;
- rune_spells[i].rune2 = 0;
- rune_spells[i].mana = 0;
- }
-
/* No items */
inven_cnt = 0;
equip_cnt = 0;
diff --git a/src/cmd7.cc b/src/cmd7.cc
index ff98d28d..3f039f32 100644
--- a/src/cmd7.cc
+++ b/src/cmd7.cc
@@ -2849,30 +2849,23 @@ void do_cmd_rune(void)
/*
* Print a batch of runespells.
*/
-static void print_runespell_batch(int batch, int max)
+static void print_runespell_batch(std::size_t batch, int max)
{
- char buff[80];
-
- rune_spell* spell;
-
- int i;
-
- s32b power, powerdiv;
-
- int p, dp;
-
-
prt(format(" %-30s Fail Mana Power", "Name"), 1, 20);
+ int i;
for (i = 0; i < max; i++)
{
- spell = &rune_spells[batch * 10 + i];
+ auto spell = &p_ptr->rune_spells[batch * 10 + i];
- power = spell->mana;
+ int power = spell->mana;
+ s32b powerdiv;
rune_calc_power(&power, &powerdiv);
- p = power;
- dp = powerdiv;
+ int const p = power;
+ int const dp = powerdiv;
+
+ char buff[80];
strnfmt(buff, 80, " %c) %-30s %4d%% %4d %dd%d ", I2A(i), spell->name,
spell_chance_rune(spell), spell->mana, dp, p);
@@ -2887,38 +2880,30 @@ static void print_runespell_batch(int batch, int max)
* List ten random spells and ask to pick one.
*/
-static rune_spell* select_runespell_from_batch(int batch, int *s_idx)
+static rune_spell* select_runespell_from_batch(std::size_t batch, int *s_idx)
{
- char tmp[160];
-
- char out_val[30];
-
- char which;
-
- int mut_max = 10;
-
- rune_spell* ret;
-
+ auto &rune_spells = p_ptr->rune_spells;
character_icky = TRUE;
- if (rune_num < (batch + 1) * 10)
- {
- mut_max = rune_num - batch * 10;
- }
-
- strnfmt(tmp, 160, "(a-%c, * to list, / to rename, - to comment) Select a power: ",
- I2A(mut_max - 1));
+ int const mut_max = (rune_spells.size() < (batch + 1) * 10)
+ ? rune_spells.size() - batch * 10
+ : 10;
+ char tmp[160];
+ strnfmt(tmp, 160, "(a-%c, / to rename, - to comment) Select a power: ",
+ I2A(mut_max - 1));
prt(tmp, 0, 0);
+ rune_spell *ret = nullptr;
+
while (1)
{
Term_save();
print_runespell_batch(batch, mut_max);
- which = inkey();
+ char which = inkey();
Term_load();
@@ -2945,6 +2930,7 @@ static rune_spell* select_runespell_from_batch(int batch, int *s_idx)
if (isalpha(which) && (A2I(which) <= mut_max))
{
+ char out_val[30] = { '\0' };
strcpy(out_val, rune_spells[batch*10 + A2I(which)].name);
if (get_string("Name this power: ", out_val, 29))
{
@@ -2983,27 +2969,28 @@ static rune_spell* select_runespell_from_batch(int batch, int *s_idx)
/*
* Pick a random spell from a menu
*/
-
-rune_spell* select_runespell(int *s_idx)
+static rune_spell* select_runespell(int *s_idx)
{
- char tmp[160];
+ auto const &rune_spells = p_ptr->rune_spells;
char which;
- int batch_max = (rune_num - 1) / 10;
-
- if (rune_num == 0)
+ if (rune_spells.empty())
{
msg_print("There are no runespells you can cast.");
return (NULL);
}
+ std::size_t batch_max = (rune_spells.size() - 1) / 10;
+
character_icky = TRUE;
Term_save();
- strnfmt(tmp, 160, "(a-%c) Select batch of powers: ", I2A(batch_max));
-
- prt(tmp, 0, 0);
+ {
+ char tmp[160];
+ strnfmt(tmp, 160, "(a-%c) Select batch of powers: ", I2A(batch_max));
+ prt(tmp, 0, 0);
+ }
while (1)
{
@@ -3025,7 +3012,7 @@ rune_spell* select_runespell(int *s_idx)
else
{
which = tolower(which);
- if (isalpha(which) && (A2I(which) <= batch_max))
+ if (isalpha(which) && (static_cast<size_t>(A2I(which)) <= batch_max))
{
Term_load();
character_icky = FALSE;
@@ -3044,13 +3031,8 @@ rune_spell* select_runespell(int *s_idx)
* Cast a memorized runespell
* Note that the only limits are antimagic & conf, NOT blind
*/
-void do_cmd_rune_cast()
+static void do_cmd_rune_cast()
{
- rune_spell *s_ptr;
-
- int s_idx;
-
-
/* Require some mana */
if (p_ptr->csp <= 0)
{
@@ -3079,6 +3061,8 @@ void do_cmd_rune_cast()
return;
}
+ int s_idx;
+ rune_spell *s_ptr;
s_ptr = select_runespell(&s_idx);
if (s_ptr == NULL) return;
@@ -3188,35 +3172,34 @@ void do_cmd_runestone()
*/
void do_cmd_rune_add_mem()
{
- rune_spell s_ptr;
-
- rune_spell *ds_ptr = &rune_spells[rune_num];
-
+ auto &rune_spells = p_ptr->rune_spells;
- /* Not when confused */
if (p_ptr->confused)
{
msg_print("You are too confused!");
return;
}
-
- if (rune_num >= MAX_RUNES)
+ if (rune_spells.size() >= MAX_RUNES)
{
msg_print("You have already learned the maximum number of runespells!");
return;
}
+ rune_spell s_ptr;
if (!get_runespell(&s_ptr)) return;
- ds_ptr->type = s_ptr.type;
- ds_ptr->rune2 = s_ptr.rune2;
- ds_ptr->mana = s_ptr.mana;
- strcpy(ds_ptr->name, "Unnamed Runespell");
+ // Create the new rune spell
+ rune_spell ds;
+ ds.type = s_ptr.type;
+ ds.rune2 = s_ptr.rune2;
+ ds.mana = s_ptr.mana;
+ strcpy(ds.name, "Unnamed Runespell");
- get_string("Name this runespell: ", ds_ptr->name, 29);
+ get_string("Name this runespell: ", ds.name, 29);
- rune_num++;
+ // Add to list
+ rune_spells.emplace_back(ds);
/* Take a turn */
energy_use = 100;
@@ -3325,33 +3308,22 @@ void do_cmd_rune_carve()
*/
void do_cmd_rune_del()
{
- rune_spell *s_ptr;
-
- int s_idx;
-
- int i;
-
+ auto &rune_spells = p_ptr->rune_spells;
- /* Not when confused */
if (p_ptr->confused)
{
msg_print("You are too confused!");
return;
}
+ rune_spell *s_ptr;
+ int s_idx;
s_ptr = select_runespell(&s_idx);
if (s_ptr == NULL) return;
- /* Delete and move */
- for (i = s_idx + 1; i < rune_num; i++)
- {
- rune_spells[i - 1].type = rune_spells[i].type;
- rune_spells[i - 1].rune2 = rune_spells[i].rune2;
- rune_spells[i - 1].mana = rune_spells[i].mana;
- strcpy(rune_spells[i - 1].name, rune_spells[i].name);
- }
- rune_num--;
+ /* Delete */
+ rune_spells.erase(rune_spells.begin() + s_idx);
/* Take a turn */
energy_use = 100;
diff --git a/src/loadsave.cc b/src/loadsave.cc
index 06e53d02..8c2a79c4 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -495,6 +495,14 @@ static void do_random_spell(random_spell *s_ptr, ls_flag_t flag)
do_std_bool(&s_ptr->untried, flag);
}
+static void do_rune_spell(rune_spell *s_ptr, ls_flag_t flag)
+{
+ do_string(s_ptr->name, 30, flag);
+ do_s16b(&s_ptr->type, flag);
+ do_s16b(&s_ptr->rune2, flag);
+ do_s16b(&s_ptr->mana, flag);
+}
+
/*
* Show information on the screen, one line at a time.
@@ -892,18 +900,8 @@ static bool_ do_extra(ls_flag_t flag)
/* Random spells */
do_vector(flag, p_ptr->random_spells, do_random_spell);
- /* Spells */
- {
- do_s16b(&rune_num, flag);
-
- for (std::size_t i = 0; i < MAX_RUNES; i++)
- {
- do_string(rune_spells[i].name, 30, flag);
- do_s16b(&rune_spells[i].type, flag);
- do_s16b(&rune_spells[i].rune2, flag);
- do_s16b(&rune_spells[i].mana, flag);
- }
- }
+ /* Rune spells */
+ do_vector(flag, p_ptr->rune_spells, do_rune_spell);
/* Random seed for object flavors. */
do_seed(&seed_flavor(), flag);
diff --git a/src/player_type.hpp b/src/player_type.hpp
index c9c7538b..0e7aa93f 100644
--- a/src/player_type.hpp
+++ b/src/player_type.hpp
@@ -8,6 +8,7 @@
#include "object_type.hpp"
#include "powers.hpp"
#include "random_spell.hpp"
+#include "rune_spell.hpp"
#include "spellbinder.hpp"
#include <array>
@@ -414,6 +415,11 @@ struct player_type
*/
std::vector<random_spell> random_spells;
+ /**
+ * Runecrafter's selfmade spells.
+ */
+ std::vector<rune_spell> rune_spells;
+
/**
* Does the player have the given ability?
*/
diff --git a/src/rune_spell.hpp b/src/rune_spell.hpp
index d04a8dc4..e1e8d190 100644
--- a/src/rune_spell.hpp
+++ b/src/rune_spell.hpp
@@ -7,9 +7,9 @@
*/
struct rune_spell
{
- char name[30]; /* name */
+ char name[30] { '\0' }; /* name */
- s16b type; /* Type of the spell(GF) */
- s16b rune2; /* Modifiers */
- s16b mana; /* Mana involved */
+ s16b type = 0; /* Type of the spell(GF) */
+ s16b rune2 = 0; /* Modifiers */
+ s16b mana = 0; /* Mana involved */
};
diff --git a/src/variable.cc b/src/variable.cc
index 84fcdfba..f3defc5d 100644
--- a/src/variable.cc
+++ b/src/variable.cc
@@ -790,12 +790,6 @@ s32b RANDART_ARMOR;
s32b RANDART_JEWEL;
/*
- * Runecrafter's selfmade spells.
- */
-rune_spell rune_spells[MAX_RUNES];
-s16b rune_num;
-
-/*
* Fate.
*/
fate fates[MAX_FATES];
diff --git a/src/variable.hpp b/src/variable.hpp
index ef480af9..b04f3140 100644
--- a/src/variable.hpp
+++ b/src/variable.hpp
@@ -32,7 +32,6 @@
#include "randart_part_type_fwd.hpp"
#include "random_artifact.hpp"
#include "random_quest.hpp"
-#include "rune_spell.hpp"
#include "school_type.hpp"
#include "set_type_fwd.hpp"
#include "skill_descriptor_fwd.hpp"
@@ -235,8 +234,6 @@ extern random_artifact random_artifacts[MAX_RANDARTS];
extern s32b RANDART_WEAPON;
extern s32b RANDART_ARMOR;
extern s32b RANDART_JEWEL;
-extern rune_spell rune_spells[MAX_RUNES];
-extern s16b rune_num;
extern fate fates[MAX_FATES];
extern byte dungeon_type;
extern s16b *max_dlv;