summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-06-21 13:37:02 +0200
committerBardur Arantsson <bardur@scientician.net>2016-06-21 13:37:02 +0200
commit81585d95403e6e32a5dff056c018f2eff755cc94 (patch)
tree84308d254c3f645b98b1cc0d6e7f3050646681d6
parent60ff0466730fdccea279e5320b3991788cff125f (diff)
Fix random_artifact_resistance() granting 'duplicate' resistance
-rw-r--r--src/object2.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/object2.cc b/src/object2.cc
index f6b526f6..ce0679cc 100644
--- a/src/object2.cc
+++ b/src/object2.cc
@@ -2108,7 +2108,7 @@ static void random_artifact_power(object_type *o_ptr)
void random_artifact_resistance(object_type * o_ptr)
{
- auto art_flags = a_info[o_ptr->name1].flags;
+ auto const art_flags = a_info[o_ptr->name1].flags;
// Check flags of the 'protype' artifact
auto give_resistance = bool(art_flags & TR_RANDOM_RESIST);
@@ -2125,7 +2125,7 @@ void random_artifact_resistance(object_type * o_ptr)
}
}
- // Grant the resistance/power
+ // Grant a power?
if (give_power)
{
random_artifact_power(o_ptr);
@@ -2135,15 +2135,17 @@ void random_artifact_resistance(object_type * o_ptr)
if (give_resistance)
{
- // Save flags
- auto const flags = o_ptr->art_flags;
+ // Save the *combined* pre-existing flags on the object;
+ // including any power we may have granted above.
+ auto const flags_before = art_flags | o_ptr->art_flags;
+
// We'll be a little generous here and make sure that the object
// gets a resistance that it doesn't actually already have.
for (int tries = 0; tries < 1000; tries++)
{
random_resistance(o_ptr, randint(22) + 16);
- // Picked up a new resistance?
- if (flags != o_ptr->art_flags)
+ // Picked up new resistance?
+ if (flags_before != (art_flags | o_ptr->art_flags))
{
break;
}