summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2017-05-02 19:20:57 +0200
committerBardur Arantsson <bardur@scientician.net>2017-05-02 19:20:57 +0200
commitaae967c8a33e1aad994b7349abad7fbd447264bb (patch)
treebfd33da5e04f1103710c4de430143e8cddd54de5 /src
parent5bc01c584066a0cea37021eb6e13bd96d74de7b5 (diff)
Remove random_spell::{name,desc}
Diffstat (limited to 'src')
-rw-r--r--src/cmd7.cc78
-rw-r--r--src/loadsave.cc2
-rw-r--r--src/random_spell.hpp3
-rw-r--r--src/random_spell_fwd.hpp3
-rw-r--r--src/spells1.cc22
-rw-r--r--src/spells1.hpp4
6 files changed, 22 insertions, 90 deletions
diff --git a/src/cmd7.cc b/src/cmd7.cc
index 4d491416..38e5d6cd 100644
--- a/src/cmd7.cc
+++ b/src/cmd7.cc
@@ -42,6 +42,8 @@
#include "xtra2.hpp"
#include "z-rand.hpp"
+#include <fmt/format.h>
+
/*
* Describe class powers of Mindcrafters
*
@@ -1270,18 +1272,19 @@ static void print_spell_batch(int batch, int max)
{
auto rspell = &random_spells[batch * 10 + i];
- char buff[80];
+ std::string buff;
+ std::string name = name_spell(rspell);
if (rspell->untried)
{
- strnfmt(buff, 80, " %c) %-30s (Spell untried) ",
- I2A(i), rspell->name);
+ buff = fmt::format(" {:c}) {:<30} (Spell untried) ",
+ (char) I2A(i), name);
}
else
{
- strnfmt(buff, 80, " %c) %-30s %3d %4d%% %3d %3dd%d ",
- I2A(i), rspell->name,
+ buff = fmt::format(" {:c}) {:<30} {:>3d} {:>4d}% {:>3d} {:>3d}d{:d} ",
+ (char) I2A(i), name,
rspell->level, spell_chance_random(rspell), rspell->mana,
rspell->dam_dice, rspell->dam_sides);
}
@@ -1302,7 +1305,6 @@ static random_spell* select_spell_from_batch(std::size_t batch)
auto &random_spells = p_ptr->random_spells;
char tmp[160];
- char out_val[30];
char which;
random_spell* ret = nullptr;
@@ -1316,8 +1318,8 @@ static random_spell* select_spell_from_batch(std::size_t batch)
? random_spells.size() - batch * 10
: 10;
- strnfmt(tmp, 160, "(a-%c, A-%c to browse, / to rename, - to comment) Select a power: ",
- I2A(mut_max - 1), I2A(mut_max - 1) - 'a' + 'A');
+ strnfmt(tmp, 160, "(a-%c) Select a power: ",
+ I2A(mut_max - 1));
prt(tmp, 0, 0);
@@ -1356,65 +1358,7 @@ static random_spell* select_spell_from_batch(std::size_t batch)
continue;
}
- /* Rename */
- if (which == '/')
- {
- prt("Rename which power: ", 0, 0);
- which = tolower(inkey());
-
- if (isalpha(which) && (A2I(which) <= mut_max))
- {
- strcpy(out_val, random_spells[batch*10 + A2I(which)].name);
- if (get_string("Name this power: ", out_val, 29))
- {
- strcpy(random_spells[batch*10 + A2I(which)].name, out_val);
- }
- prt(tmp, 0, 0);
- }
- else
- {
- bell();
- prt(tmp, 0, 0);
- }
-
- /* Wait for next command */
- continue;
- }
-
- /* Comment */
- if (which == '-')
- {
- prt("Comment which power: ", 0, 0);
- which = tolower(inkey());
-
- if (isalpha(which) && (A2I(which) <= mut_max))
- {
- strcpy(out_val, random_spells[batch*10 + A2I(which)].desc);
- if (get_string("Comment this power: ", out_val, 29))
- {
- strcpy(random_spells[batch*10 + A2I(which)].desc, out_val);
- }
- prt(tmp, 0, 0);
- }
- else
- {
- bell();
- prt(tmp, 0, 0);
- }
-
- /* Wait for next command */
- continue;
- }
-
- if (isalpha(which) && isupper(which))
- {
- which = tolower(which);
- c_prt(TERM_L_BLUE, format("%s : %s", random_spells[batch*10 + A2I(which)].name, random_spells[batch*10 + A2I(which)].desc), 0, 0);
- inkey();
- prt(tmp, 0, 0);
- continue;
- }
- else if (isalpha(which) && (A2I(which) < mut_max))
+ if (isalpha(which) && (A2I(which) < mut_max))
{
/* Pick the power */
ret = &random_spells[batch * 10 + A2I(which)];
diff --git a/src/loadsave.cc b/src/loadsave.cc
index 731efab2..5c6b24bb 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -480,8 +480,6 @@ static void do_subrace(ls_flag_t flag)
static void do_random_spell(random_spell *s_ptr, ls_flag_t flag)
{
- do_string(s_ptr->name, 30, flag);
- do_string(s_ptr->desc, 30, flag);
do_s16b(&s_ptr->mana, flag);
do_s16b(&s_ptr->fail, flag);
do_u32b(&s_ptr->proj_flags, flag);
diff --git a/src/random_spell.hpp b/src/random_spell.hpp
index 2ed71096..f02b9848 100644
--- a/src/random_spell.hpp
+++ b/src/random_spell.hpp
@@ -1,14 +1,13 @@
#pragma once
#include "h-basic.h"
+#include <string>
/**
* A structure to describe the random spells of the Power Mages
*/
struct random_spell
{
- char desc[30] = { }; /* Desc of the spell */
- char name[30] = { }; /* Name of the spell */
s16b mana = 0; /* Mana cost */
s16b fail = 0; /* Failure rate */
u32b proj_flags = 0; /* Project function flags */
diff --git a/src/random_spell_fwd.hpp b/src/random_spell_fwd.hpp
new file mode 100644
index 00000000..ee559c31
--- /dev/null
+++ b/src/random_spell_fwd.hpp
@@ -0,0 +1,3 @@
+#pragma once
+
+struct random_spell;
diff --git a/src/spells1.cc b/src/spells1.cc
index aad281a0..fe620256 100644
--- a/src/spells1.cc
+++ b/src/spells1.cc
@@ -50,6 +50,7 @@
#include "z-rand.hpp"
#include <chrono>
+#include <fmt/format.h>
#include <thread>
using std::this_thread::sleep_for;
@@ -8775,8 +8776,7 @@ static void describe_attack_fully(int type, char* r)
* Give a randomly-generated spell a name.
* Note that it only describes the first effect!
*/
-
-static void name_spell(random_spell* s_ptr)
+std::string name_spell(random_spell const *s_ptr)
{
char buff[30];
cptr buff2 = "???";
@@ -8807,7 +8807,7 @@ static void name_spell(random_spell* s_ptr)
}
describe_attack_fully(s_ptr->GF, buff);
- strnfmt(s_ptr->name, 30, "%s - %s", buff2, buff);
+ return fmt::format("{:s} - {:s}", buff2, buff);
}
void generate_spell(int plev)
@@ -8913,22 +8913,6 @@ void generate_spell(int plev)
rspell.GF = destructive_attack_types[rand_int(10)];
}
- // Give the spell a name
- name_spell(&rspell);
-
- // Give the spell a description
- if (ball_desc)
- {
- /* 30 character limit on the string! */
- sprintf(rspell.desc, "Dam: %d, Rad: %d, Pow: %d",
- sides, dice, power);
- }
- else
- {
- sprintf(rspell.desc, "Damage: %dd%d, Power: %d",
- dice, sides, power);
- }
-
// Add
random_spells.emplace_back(rspell);
}
diff --git a/src/spells1.hpp b/src/spells1.hpp
index 5512063f..b67f73bb 100644
--- a/src/spells1.hpp
+++ b/src/spells1.hpp
@@ -1,6 +1,9 @@
#pragma once
+#include <string>
+
#include "h-basic.h"
+#include "random_spell_fwd.hpp"
extern byte spell_color(int type);
extern s16b poly_r_idx(int r_idx);
@@ -27,6 +30,7 @@ extern bool_ project(int who, int rad, int y, int x, int dam, int typ, int flg);
extern bool_ potion_smash_effect(int who, int y, int x, int o_sval);
extern void do_poly_self(void);
extern void corrupt_player(void);
+extern std::string name_spell(random_spell const *);
extern void generate_spell(int plev);
extern bool_ unsafe;
extern s16b do_poly_monster(int y, int x);