From 0ec2cec5fad1f5cb1aa048b49bb67bfe493785e6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 29 Mar 2016 20:32:55 +0200 Subject: Have RANDOM_{RESIST,POWER} avoid existing flags --- src/defines.h | 3 --- src/object1.cc | 51 ++++++------------------------------- src/object2.cc | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 78 insertions(+), 55 deletions(-) diff --git a/src/defines.h b/src/defines.h index 519dc535..91d3065d 100644 --- a/src/defines.h +++ b/src/defines.h @@ -2247,9 +2247,6 @@ /* High resist */ #define EGO_XTRA_POWER 2 -/* Special ability */ -#define EGO_XTRA_ABILITY 3 - /*** Object flag values ***/ diff --git a/src/object1.cc b/src/object1.cc index 78206f68..ae0317c7 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -850,40 +850,6 @@ static void object_flags_xtra(object_type const *o_ptr, u32b *f2, u32b *f3, u32b break; } - case EGO_XTRA_ABILITY: - { - /* Choose an ability */ - switch (o_ptr->xtra2 % 8) - { - case 0: - (*f3) |= (TR3_FEATHER); - break; - case 1: - (*f3) |= (TR3_LITE1); - break; - case 2: - (*f3) |= (TR3_SEE_INVIS); - break; - case 3: - (*esp) |= (ESP_ALL); - break; - case 4: - (*f3) |= (TR3_SLOW_DIGEST); - break; - case 5: - (*f3) |= (TR3_REGEN); - break; - case 6: - (*f2) |= (TR2_FREE_ACT); - break; - case 7: - (*f2) |= (TR2_HOLD_LIFE); - break; - } - - break; - } - } } @@ -920,16 +886,13 @@ void object_flags(object_type const *o_ptr, u32b *f1, u32b *f2, u32b *f3, u32b * apply_flags_set(o_ptr->name1, a_ptr->set, f1, f2, f3, f4, f5, esp); } - /* Random artifact ! */ - if (o_ptr->art_flags1 || o_ptr->art_flags2 || o_ptr->art_flags3 || o_ptr->art_flags4 || o_ptr->art_flags5 || o_ptr->art_esp) - { - (*f1) |= o_ptr->art_flags1; - (*f2) |= o_ptr->art_flags2; - (*f3) |= o_ptr->art_flags3; - (*f4) |= o_ptr->art_flags4; - (*f5) |= o_ptr->art_flags5; - (*esp) |= o_ptr->art_esp; - } + /* Mix in art_{flagsX,esp} */ + (*f1) |= o_ptr->art_flags1; + (*f2) |= o_ptr->art_flags2; + (*f3) |= o_ptr->art_flags3; + (*f4) |= o_ptr->art_flags4; + (*f5) |= o_ptr->art_flags5; + (*esp) |= o_ptr->art_esp; /* Extra powers */ if (!(o_ptr->art_name)) diff --git a/src/object2.cc b/src/object2.cc index 145aab4c..18d0e980 100644 --- a/src/object2.cc +++ b/src/object2.cc @@ -2040,6 +2040,63 @@ static void object_mention(object_type *o_ptr) } } +static void random_artifact_power(object_type *o_ptr) +{ + // Shorthand + auto f2 = &o_ptr->art_flags2; + auto f3 = &o_ptr->art_flags3; + auto esp = &o_ptr->art_esp; + + // Choose ability + auto try_choose = [&o_ptr, &f2, &f3, &esp](int choice) { + switch (choice) + { + case 0: + (*f3) |= (TR3_FEATHER); + break; + case 1: + (*f3) |= (TR3_LITE1); + break; + case 2: + (*f3) |= (TR3_SEE_INVIS); + break; + case 3: + (*esp) |= (ESP_ALL); + break; + case 4: + (*f3) |= (TR3_SLOW_DIGEST); + break; + case 5: + (*f3) |= (TR3_REGEN); + break; + case 6: + (*f2) |= (TR2_FREE_ACT); + break; + case 7: + (*f2) |= (TR2_HOLD_LIFE); + break; + } + }; + + // Save old values for comparison + u32b const old_f2 = *f2; + u32b const old_f3 = *f3; + u32b const old_esp = *esp; + + // Choose an ability; make sure we choose one that isn't already chosen + for (int tries = 0; tries < 1000; tries++) + { + // Tentative choice + int choice = rand_int(8); + try_choose(choice); + + // If there's any difference, then we chose a non-overlapping power. + if ((*f2 != old_f2) || (*f3 != old_f3) || (*esp != old_esp)) + { + break; + } + } +} void random_artifact_resistance(object_type * o_ptr) { @@ -2063,20 +2120,26 @@ void random_artifact_resistance(object_type * o_ptr) // Grant the resistance/power if (give_power) { - o_ptr->xtra1 = EGO_XTRA_ABILITY; - - /* Randomize the "xtra" power */ - if (o_ptr->xtra1) - { - o_ptr->xtra2 = randint(256); - } + random_artifact_power(o_ptr); } artifact_bias = 0; if (give_resistance) { - random_resistance(o_ptr, FALSE, ((randint(22)) + 16)); + // Save resistance flags + u32b const f2 = o_ptr->art_flags2; + // 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, FALSE, ((randint(22)) + 16)); + // Picked up a new resistance? + if (f2 != o_ptr->art_flags2) + { + break; + } + } } } -- cgit v1.2.3