From 00c00d528adfaddd2cd5708237b2cece4610358b Mon Sep 17 00:00:00 2001 From: Charles Otto Date: Tue, 20 Oct 2009 21:51:52 -0400 Subject: Fix bug [2880266] permanent stat loss when mutating Fix a bug where getting a mutation that restricts equipment slots could cause permanent stat loss by subtracting the stat bonuses from a piece of equipment being removed twice. --- crawl-ref/source/mutation.cc | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'crawl-ref/source/mutation.cc') diff --git a/crawl-ref/source/mutation.cc b/crawl-ref/source/mutation.cc index e7b7d3b8fc..e25a3f0c2e 100644 --- a/crawl-ref/source/mutation.cc +++ b/crawl-ref/source/mutation.cc @@ -2254,6 +2254,8 @@ bool mutate(mutation_type which_mutation, bool failMsg, for (int i = 0; i < 3; ++i) modifiers[i] = stat_modifier(stats[i]); + bool modified_eq = false; + switch (mutat) { case MUT_STRONG: case MUT_AGILE: case MUT_CLEVER: @@ -2270,7 +2272,10 @@ bool mutate(mutation_type which_mutation, bool failMsg, // Hooves and talons force boots off. if (you_tran_can_wear(EQ_BOOTS)) + { remove_one_equip(EQ_BOOTS, false, true); + modified_eq = true; + } break; case MUT_CLAWS: @@ -2281,7 +2286,10 @@ bool mutate(mutation_type which_mutation, bool failMsg, // mutation yet, so we have to check for level 2 or higher claws // here. if (you.mutation[mutat] >= 2 && you_tran_can_wear(EQ_GLOVES)) + { remove_one_equip(EQ_GLOVES, false, true); + modified_eq = true; + } break; case MUT_HORNS: @@ -2295,6 +2303,7 @@ bool mutate(mutation_type which_mutation, bool failMsg, && you_tran_can_wear(EQ_HELMET)) { remove_one_equip(EQ_HELMET, false, true); + modified_eq = true; } break; @@ -2314,13 +2323,21 @@ bool mutate(mutation_type which_mutation, bool failMsg, you.mutation[mutat]++; - for (int i = 0; i < 3; ++i) + // Don't run this loop if we lost some equipment slots since + // removing armour with stat modifiers makes the value of new_modifier + // below different from the previously recorded value, and the + // remove_one_equip call chain already does stat change from + // removing items correctly. -cao + if(!modified_eq) { - const int new_modifier = stat_modifier(stats[i]); - if (new_modifier != modifiers[i]) + for (int i = 0; i < 3; ++i) { - modify_stat(stats[i], new_modifier - modifiers[i], - !stat_msg, "losing a mutation"); + const int new_modifier = stat_modifier(stats[i]); + if (new_modifier != modifiers[i]) + { + modify_stat(stats[i], new_modifier - modifiers[i], + !stat_msg, "losing a mutation"); + } } } -- cgit v1.2.3-54-g00ecf