summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:14 +0200
committerBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:14 +0200
commit8bbf783ead4517465445272f9144cf06bdac9be7 (patch)
tree9fa9cc4de0c53df33c557d66a9efbc6781f6fb94 /src
parent013e27d39ee8ee513208d2855c7e3f6252f0c0bf (diff)
Refactor object_type 'artifact name' field to std::string
We don't really need quarks for this since we're not nearly as memory-constrained these days.
Diffstat (limited to 'src')
-rw-r--r--src/cmd1.cc24
-rw-r--r--src/cmd6.cc2
-rw-r--r--src/loadsave.cc34
-rw-r--r--src/melee2.cc4
-rw-r--r--src/object1.cc16
-rw-r--r--src/object2.cc9
-rw-r--r--src/object_type.hpp2
-rw-r--r--src/q_library.cc2
-rw-r--r--src/q_thrain.cc6
-rw-r--r--src/q_wight.cc2
-rw-r--r--src/randart.cc2
-rw-r--r--src/squelch/condition.cc1
-rw-r--r--src/store.cc7
-rw-r--r--src/xtra2.cc10
14 files changed, 51 insertions, 70 deletions
diff --git a/src/cmd1.cc b/src/cmd1.cc
index 36b164b5..f1dfaac9 100644
--- a/src/cmd1.cc
+++ b/src/cmd1.cc
@@ -2046,21 +2046,16 @@ void py_attack(int y, int x, int max_blow)
!(p_ptr->stun || p_ptr->confused || p_ptr->image ||
!(m_ptr->ml)))
{
- if (!(p_ptr->inventory[INVEN_WIELD].art_name))
+ // Only 'Stormbringer' can hit friendlies unless player forces attack.
+ if (p_ptr->inventory[INVEN_WIELD].artifact_name == "'Stormbringer'")
{
- msg_format("You stop to avoid hitting %s.", m_name);
- return;
+ msg_format("Your black blade greedily attacks %s!", m_name);
}
-
- if (!
- (streq
- (quark_str(p_ptr->inventory[INVEN_WIELD].art_name), "'Stormbringer'")))
+ else
{
msg_format("You stop to avoid hitting %s.", m_name);
return;
}
-
- msg_format("Your black blade greedily attacks %s!", m_name);
}
/* Break goi/manashield */
@@ -2740,8 +2735,6 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm)
char m_name[80];
- bool_ stormbringer = FALSE;
-
bool_ old_dtrap, new_dtrap;
bool_ oktomove = TRUE;
@@ -2910,12 +2903,6 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm)
m_ptr = &m_list[c_ptr->m_idx];
auto const mr_ptr = m_ptr->race();
- if (p_ptr->inventory[INVEN_WIELD].art_name)
- {
- if (streq(quark_str(p_ptr->inventory[INVEN_WIELD].art_name), "'Stormbringer'"))
- stormbringer = TRUE;
- }
-
/* Hack -- attack monsters */
if (c_ptr->m_idx && (m_ptr->ml || player_can_enter(c_ptr->feat)))
{
@@ -2936,6 +2923,9 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm)
/* Track a new monster */
if (m_ptr->ml) health_track(c_ptr->m_idx);
+ /* Is it Stormbringer? */
+ bool stormbringer = p_ptr->inventory[INVEN_WIELD].artifact_name == "'Stormbringer'";
+
/* displace? */
if (stormbringer && (randint(1000) > 666))
{
diff --git a/src/cmd6.cc b/src/cmd6.cc
index 4bcade91..393261bf 100644
--- a/src/cmd6.cc
+++ b/src/cmd6.cc
@@ -5077,7 +5077,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item)
spell = a_info[o_ptr->name1].activate;
/* Random Artifacts */
- if (!spell && o_ptr->art_name)
+ if (!spell && (!o_ptr->artifact_name.empty()))
spell = o_ptr->xtra2;
/* Ego Items */
diff --git a/src/loadsave.cc b/src/loadsave.cc
index 6da23406..3f4ba47f 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -1141,31 +1141,15 @@ static void do_item(object_type *o_ptr, ls_flag_t flag)
// Inscription
do_std_string(o_ptr->inscription, flag);
- /* Artifact name */
- if (flag == ls_flag_t::LOAD)
- {
- char buf[128];
- load_string(buf, 128);
- if (buf[0])
- {
- o_ptr->art_name = quark_add(buf);
- }
- }
- if (flag == ls_flag_t::SAVE)
- {
- if (o_ptr->art_name)
- {
- save_string(quark_str(o_ptr->art_name));
- }
- else
- {
- save_string("");
- }
- }
+ // Artifact name
+ do_std_string(o_ptr->artifact_name, flag);
+
+ /* Stick any more shared code before this. The rest
+ of this function is reserved for ls_flag_t::LOAD's
+ cleanup functions */
+
+ if (flag == ls_flag_t::SAVE) return;
- if (flag == ls_flag_t::SAVE) return ; /* Stick any more shared code before this. The rest
- of this function is reserved for ls_flag_t::LOAD's
- cleanup functions */
/*********** END OF ls_flag_t::SAVE ***************/
/* Obtain the "kind" template */
@@ -1248,7 +1232,7 @@ static void do_item(object_type *o_ptr, ls_flag_t flag)
o_ptr->ds = old_ds;
}
- if (o_ptr->art_name) /* A random artifact */
+ if (!o_ptr->artifact_name.empty()) /* A random artifact */
{
o_ptr->dd = old_dd;
o_ptr->ds = old_ds;
diff --git a/src/melee2.cc b/src/melee2.cc
index 562bca57..41756550 100644
--- a/src/melee2.cc
+++ b/src/melee2.cc
@@ -2362,7 +2362,7 @@ void curse_equipment(int chance, int heavy_chance)
}
if ((randint(100) <= heavy_chance) &&
- (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
+ (o_ptr->name1 || o_ptr->name2 || (!o_ptr->artifact_name.empty())))
{
if (!(flags & TR_HEAVY_CURSE))
changed = TRUE;
@@ -2414,7 +2414,7 @@ void curse_equipment_dg(int chance, int heavy_chance)
}
if ((randint(100) <= heavy_chance) &&
- (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
+ (o_ptr->name1 || o_ptr->name2 || (!o_ptr->artifact_name.empty())))
{
if (!(flags & TR_HEAVY_CURSE))
changed = TRUE;
diff --git a/src/object1.cc b/src/object1.cc
index a7c1edf1..b4e1141d 100644
--- a/src/object1.cc
+++ b/src/object1.cc
@@ -717,7 +717,7 @@ void reset_visuals(void)
static void object_flags_xtra(object_type const *o_ptr, object_flag_set *f)
{
// Artifacts don't get *ego* extra powers.
- if (o_ptr->art_name)
+ if (!o_ptr->artifact_name.empty())
{
return;
}
@@ -1126,7 +1126,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
else
basenm = aware ? "& # Amulet~" : "& # Amulet~";
- if (known && !o_ptr->art_name && artifact_p(o_ptr))
+ if (known && o_ptr->artifact_name.empty() && artifact_p(o_ptr))
{
basenm = k_ptr->name;
}
@@ -1149,7 +1149,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
/* Hack -- The One Ring */
if (!aware && (o_ptr->sval == SV_RING_POWER)) modstr = "Plain Gold";
- if (known && !o_ptr->art_name && artifact_p(o_ptr))
+ if (known && o_ptr->artifact_name.empty() && artifact_p(o_ptr))
{
basenm = k_ptr->name;
}
@@ -1681,10 +1681,10 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
}
/* Is it a new random artifact ? */
- if (o_ptr->art_name)
+ if (!o_ptr->artifact_name.empty())
{
t += ' ';
- t += quark_str(o_ptr->art_name);
+ t += o_ptr->artifact_name;
}
@@ -1848,7 +1848,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
else if (o_ptr->to_h)
{
t += fmt::format(" ({:+d}", o_ptr->to_h);
- if (!(flags & TR_HIDE_TYPE) || o_ptr->art_name)
+ if (!(flags & TR_HIDE_TYPE) || (!o_ptr->artifact_name.empty()))
{
t += " to accuracy";
}
@@ -1859,7 +1859,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
else if (o_ptr->to_d)
{
t += fmt::format(" ({:+d}", o_ptr->to_d);
- if (!(flags & TR_HIDE_TYPE) || o_ptr->art_name)
+ if (!(flags & TR_HIDE_TYPE) || (!o_ptr->artifact_name.empty()))
{
t += " to damage";
}
@@ -6291,7 +6291,7 @@ bool artifact_p(object_type const *o_ptr)
return
(o_ptr->tval == TV_RANDART) ||
(o_ptr->name1 ? true : false) ||
- (o_ptr->art_name ? true : false) ||
+ (!o_ptr->artifact_name.empty()) ||
((k_info[o_ptr->k_idx].flags & TR_NORM_ART) ? true : false);
}
diff --git a/src/object2.cc b/src/object2.cc
index b4226f76..f96426fb 100644
--- a/src/object2.cc
+++ b/src/object2.cc
@@ -963,7 +963,7 @@ s32b flag_cost(object_type const *o_ptr, int plusses)
/* Also, give some extra for activatable powers... */
- if ((o_ptr->art_name) && (o_ptr->art_flags & TR_ACTIVATE))
+ if ((!o_ptr->artifact_name.empty()) && (o_ptr->art_flags & TR_ACTIVATE))
{
int type = o_ptr->xtra2;
@@ -2036,7 +2036,7 @@ static void object_mention(object_type *o_ptr)
}
/* Random Artifact */
- else if (o_ptr->art_name)
+ else if (!o_ptr->artifact_name.empty())
{
msg_print("Random artifact");
}
@@ -4177,7 +4177,10 @@ void apply_magic(object_type *o_ptr, int lev, bool_ okay, bool_ good, bool_ grea
}
}
- if (o_ptr->art_name) rating += 40;
+ if (!o_ptr->artifact_name.empty())
+ {
+ rating += 40;
+ }
/* Hack -- analyze ego-items */
else if (o_ptr->name2)
diff --git a/src/object_type.hpp b/src/object_type.hpp
index aec713b0..3a34d181 100644
--- a/src/object_type.hpp
+++ b/src/object_type.hpp
@@ -79,7 +79,7 @@ struct object_type
std::string inscription; /* Inscription index */
- u16b art_name = 0; /* Artifact name (random artifacts) */
+ std::string artifact_name; /* Artifact name */
object_flag_set art_flags; /* Flags */
object_flag_set art_oflags; /* Obvious flags */
diff --git a/src/q_library.cc b/src/q_library.cc
index e47eee4f..c379b6d1 100644
--- a/src/q_library.cc
+++ b/src/q_library.cc
@@ -457,7 +457,7 @@ void quest_library_building(bool_ *paid, bool_ *recreate)
object_type forge;
object_type *q_ptr = &forge;
object_prep(q_ptr, lookup_kind(TV_BOOK, 61));
- q_ptr->art_name = quark_add(player_name);
+ q_ptr->artifact_name = player_name;
q_ptr->found = OBJ_FOUND_REWARD;
object_aware(q_ptr);
object_known(q_ptr);
diff --git a/src/q_thrain.cc b/src/q_thrain.cc
index 0f490bf0..7cd64bbf 100644
--- a/src/q_thrain.cc
+++ b/src/q_thrain.cc
@@ -80,18 +80,20 @@ static bool_ quest_thrain_death_hook(void *, void *in_, void *)
int x = m_ptr->fx;
int y = m_ptr->fy;
int i, j;
- object_type forge, *q_ptr;
delete_monster_idx(r);
/* Wipe the glass walls and create a stair */
for (i = x - 1; i <= x + 1; i++)
+ {
for (j = y - 1; j <= y + 1; j++)
{
if (in_bounds(j, i)) cave_set_feat(j, i, FEAT_FLOOR);
}
+ }
/* Get local object */
+ object_type forge, *q_ptr;
q_ptr = &forge;
/* Wipe the object */
@@ -100,7 +102,7 @@ static bool_ quest_thrain_death_hook(void *, void *in_, void *)
q_ptr->number = 1;
q_ptr->found = OBJ_FOUND_REWARD;
create_artifact(q_ptr, FALSE, TRUE);
- q_ptr->art_name = quark_add("of Thrain");
+ q_ptr->artifact_name = "of Thrain";
/* Drop it in the dungeon */
drop_near(q_ptr, -1, y, x);
diff --git a/src/q_wight.cc b/src/q_wight.cc
index 9583365b..531bec29 100644
--- a/src/q_wight.cc
+++ b/src/q_wight.cc
@@ -75,7 +75,7 @@ static bool_ quest_wight_gen_hook(void *, void *, void *)
/* Name the rags */
- q_ptr->art_name = quark_add("of the Wight");
+ q_ptr->artifact_name = "of the Wight";
q_ptr->art_flags |=
TR_INT |
diff --git a/src/randart.cc b/src/randart.cc
index f7ea95f3..1ccba225 100644
--- a/src/randart.cc
+++ b/src/randart.cc
@@ -379,7 +379,7 @@ bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name)
}
/* Save the inscription */
- o_ptr->art_name = quark_add(new_name);
+ o_ptr->artifact_name = new_name;
o_ptr->name2 = o_ptr->name2b = 0;
/* Window stuff */
diff --git a/src/squelch/condition.cc b/src/squelch/condition.cc
index bb598158..9e93016e 100644
--- a/src/squelch/condition.cc
+++ b/src/squelch/condition.cc
@@ -16,7 +16,6 @@
#include "../player_type.hpp"
#include "../skills.hpp"
#include "../skill_type.hpp"
-#include "../quark.hpp"
#include "../util.hpp"
#include "../variable.hpp"
diff --git a/src/store.cc b/src/store.cc
index 71d6b2d0..a518677b 100644
--- a/src/store.cc
+++ b/src/store.cc
@@ -452,7 +452,7 @@ static void mass_produce(object_type *o_ptr)
}
- if (o_ptr->art_name)
+ if (!o_ptr->artifact_name.empty())
{
if (options->cheat_peek && discount)
{
@@ -510,7 +510,8 @@ static bool_ store_object_similar(object_type const *o_ptr, object_type *j_ptr)
if (o_ptr->name2b != j_ptr->name2b) return (0);
/* Random artifacts don't stack !*/
- if (o_ptr->art_name || j_ptr->art_name) return (0);
+ if (!o_ptr->artifact_name.empty()) return 0;
+ if (!j_ptr->artifact_name.empty()) return 0;
/* Hack -- Identical art_flags! */
if (o_ptr->art_flags != j_ptr->art_flags)
@@ -3396,7 +3397,7 @@ void store_shuffle(int which)
auto o_ptr = &o_ref;
/* Hack -- Sell all old items for "half price" */
- if (!(o_ptr->art_name))
+ if (o_ptr->artifact_name.empty())
o_ptr->discount = 50;
/* Mega-Hack -- Note that the item is "on sale" */
diff --git a/src/xtra2.cc b/src/xtra2.cc
index fdcbfdfa..4334b999 100644
--- a/src/xtra2.cc
+++ b/src/xtra2.cc
@@ -62,10 +62,12 @@
#include "xtra1.hpp"
#include "z-rand.hpp"
-#include <type_traits>
+#include <boost/algorithm/string/predicate.hpp>
#include <cassert>
+#include <fmt/format.h>
+#include <type_traits>
+
-#include <boost/algorithm/string/predicate.hpp>
using boost::algorithm::iequals;
@@ -2492,7 +2494,7 @@ void monster_death(int m_idx)
/* Mega-Hack -- Name the sword */
- q_ptr->art_name = quark_add("'Stormbringer'");
+ q_ptr->artifact_name = "'Stormbringer'";
q_ptr->to_h = 16;
q_ptr->to_d = 16;
q_ptr->ds = 6;
@@ -2688,7 +2690,7 @@ void monster_death(int m_idx)
create_artifact(q_ptr, TRUE, FALSE);
/* Save the inscription */
- q_ptr->art_name = quark_add(format("of %s", r_ptr->name));
+ q_ptr->artifact_name = fmt::format("of {}", r_ptr->name);
q_ptr->found = OBJ_FOUND_MONSTER;
q_ptr->found_aux1 = m_ptr->r_idx;