From 995c6d0ed98d93a8cb361618cb285c153094f414 Mon Sep 17 00:00:00 2001
From: pubby <pubby8@gmail.com>
Date: Wed, 9 Oct 2013 00:43:29 -0500
Subject: [PATCH] Give Trog's Hand its own duration.

Trog's hand was using DUR_REGENERAITON, and setting
ATTR_DIVINE_REGENERATION to true to specify it was the god ability and
not the spell.
This was silly, so this commit gives trog's hand its own duration:
DUR_TROGS_HAND.

This also fixes a very minor bug: previously if you had trog's hand
active and you tried to cast regen, you got penance but the spell was
immediately canceled. Other duration spells were not canceled.
---
 crawl-ref/source/abl-show.cc     |  2 +-
 crawl-ref/source/enum.h          |  3 +++
 crawl-ref/source/godabil.cc      | 16 ++++++++++++++++
 crawl-ref/source/godabil.h       |  2 ++
 crawl-ref/source/l_you.cc        |  3 ++-
 crawl-ref/source/main.cc         |  9 ++++++++-
 crawl-ref/source/misc.cc         |  1 -
 crawl-ref/source/player.cc       | 16 +++++++++++-----
 crawl-ref/source/religion.cc     |  8 ++++----
 crawl-ref/source/spl-cast.cc     |  2 +-
 crawl-ref/source/spl-goditem.cc  |  4 +---
 crawl-ref/source/spl-selfench.cc | 22 +++++++---------------
 crawl-ref/source/spl-selfench.h  |  4 ++--
 crawl-ref/source/status.cc       | 10 +++++++---
 crawl-ref/source/tags.cc         |  8 ++++++++
 crawl-ref/source/wiz-you.cc      |  1 +
 16 files changed, 74 insertions(+), 37 deletions(-)

diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc
index 5328659..4ca916a 100644
--- a/crawl-ref/source/abl-show.cc
+++ b/crawl-ref/source/abl-show.cc
@@ -2462,7 +2462,7 @@ static bool _do_ability(const ability_def& abil)
 
     case ABIL_TROG_REGEN_MR:
         // Trog abilities don't use or train invocations.
-        cast_regen(you.piety / 2, true);
+        trog_do_trogs_hand(you.piety / 2);
         break;
 
     case ABIL_TROG_BROTHERS_IN_ARMS:
diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h
index 51fc992..840f3e6 100644
--- a/crawl-ref/source/enum.h
+++ b/crawl-ref/source/enum.h
@@ -257,7 +257,9 @@ enum actor_type
 enum attribute_type
 {
     ATTR_DIVINE_LIGHTNING_PROTECTION,
+#if TAG_MAJOR_VERSION == 34
     ATTR_DIVINE_REGENERATION,
+#endif
     ATTR_DIVINE_DEATH_CHANNEL,
     ATTR_CARD_COUNTDOWN,
     ATTR_BANISHMENT_IMMUNITY,   // banishment immunity until
@@ -1552,6 +1554,7 @@ enum duration_type
     DUR_GRASPING_ROOTS,
     DUR_SLEEP_IMMUNITY,
     DUR_FIRE_VULN,
+    DUR_TROGS_HAND,
     NUM_DURATIONS
 };
 
diff --git a/crawl-ref/source/godabil.cc b/crawl-ref/source/godabil.cc
index b5a4c30..097643e 100644
--- a/crawl-ref/source/godabil.cc
+++ b/crawl-ref/source/godabil.cc
@@ -1608,6 +1608,22 @@ bool trog_burn_spellbooks()
     return true;
 }
 
+void trog_do_trogs_hand(int pow)
+{
+    you.increase_duration(DUR_TROGS_HAND,
+                          5 + roll_dice(2, pow / 3 + 1), 100,
+                          "Your skin crawls.");
+    mpr("You feel resistant to hostile enchantments.", MSGCH_DURATION);
+}
+
+void trog_remove_trogs_hand()
+{
+    if (you.duration[DUR_REGENERATION] == 0)
+        mpr("Your skin stops crawling.", MSGCH_DURATION);
+    mpr("You feel less resistant to hostile enchantments.", MSGCH_DURATION);
+    you.duration[DUR_TROGS_HAND] = 0;
+}
+
 bool beogh_water_walk()
 {
     return (you_worship(GOD_BEOGH) && !player_under_penance()
diff --git a/crawl-ref/source/godabil.h b/crawl-ref/source/godabil.h
index efc734e..38be4c8 100644
--- a/crawl-ref/source/godabil.h
+++ b/crawl-ref/source/godabil.h
@@ -32,6 +32,8 @@ void elyvilon_remove_divine_vigour();
 bool vehumet_supports_spell(spell_type spell);
 
 bool trog_burn_spellbooks();
+void trog_do_trogs_hand(int power);
+void trog_remove_trogs_hand();
 
 void jiyva_paralyse_jellies();
 bool jiyva_remove_bad_mutation();
diff --git a/crawl-ref/source/l_you.cc b/crawl-ref/source/l_you.cc
index 2bd64eb..6ed1bc0 100644
--- a/crawl-ref/source/l_you.cc
+++ b/crawl-ref/source/l_you.cc
@@ -142,7 +142,8 @@ LUARET1(you_mesmerised, boolean, you.duration[DUR_MESMERISED])
 LUARET1(you_on_fire, boolean, you.duration[DUR_LIQUID_FLAMES])
 LUARET1(you_petrifying, boolean, you.duration[DUR_PETRIFYING])
 LUARET1(you_silencing, boolean, you.duration[DUR_SILENCE])
-LUARET1(you_regenerating, boolean, you.duration[DUR_REGENERATION])
+LUARET1(you_regenerating, boolean, you.duration[DUR_REGENERATION]
+                                   || you.duration[DUR_TROGS_HAND])
 LUARET1(you_breath_timeout, boolean, you.duration[DUR_BREATH_WEAPON])
 LUARET1(you_extra_resistant, boolean, you.duration[DUR_RESISTANCE])
 LUARET1(you_mighty, boolean, you.duration[DUR_MIGHT])
diff --git a/crawl-ref/source/main.cc b/crawl-ref/source/main.cc
index 04925ce..d6757b4 100644
--- a/crawl-ref/source/main.cc
+++ b/crawl-ref/source/main.cc
@@ -2429,11 +2429,18 @@ static void _decrement_durations()
                           coinflip(),
                           "Your deflect missiles spell is about to expire...");
 
+    if (_decrement_a_duration(DUR_TROGS_HAND, delay,
+                              NULL, coinflip(),
+                              "You feel the effects of Trog's Hand fading."))
+    {
+        trog_remove_trogs_hand();
+    }
+
     if (_decrement_a_duration(DUR_REGENERATION, delay,
                               NULL, coinflip(),
                               "Your skin is crawling a little less now."))
     {
-        remove_regen(you.attribute[ATTR_DIVINE_REGENERATION]);
+        remove_regen();
     }
 
     _decrement_a_duration(DUR_VEHUMET_GIFT, delay);
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index a95e1d2..81a46e4 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -2053,7 +2053,6 @@ void revive()
     restore_stat(STAT_ALL, 0, true);
     you.rotting = 0;
 
-    you.attribute[ATTR_DIVINE_REGENERATION] = 0;
     you.attribute[ATTR_DELAYED_FIREBALL] = 0;
     clear_trapping_net();
     you.attribute[ATTR_DIVINE_VIGOUR] = 0;
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 4d016c1..1bfc9aa 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -1284,7 +1284,7 @@ static int _player_bonus_regen()
     // Trog's Hand is handled separately so that it will bypass slow healing,
     // and it overrides the spell.
     if (you.duration[DUR_REGENERATION]
-        && !you.attribute[ATTR_DIVINE_REGENERATION])
+        && !you.duration[DUR_TROGS_HAND])
     {
         rr += 100;
     }
@@ -1370,7 +1370,7 @@ int player_regen()
         rr = 0;
 
     // Trog's Hand.  This circumvents the slow healing effect.
-    if (you.attribute[ATTR_DIVINE_REGENERATION])
+    if (you.duration[DUR_TROGS_HAND])
         rr += 100;
 
     return rr;
@@ -1386,8 +1386,13 @@ int player_hunger_rate(bool temp)
     if (you.species == SP_TROLL)
         hunger += 3;            // in addition to the +3 for fast metabolism
 
-    if (temp && you.duration[DUR_REGENERATION] && you.hp < you.hp_max)
+    if (temp
+        && (you.duration[DUR_REGENERATION]
+            || you.duration[DUR_TROGS_HAND])
+        && you.hp < you.hp_max)
+    {
         hunger += 4;
+    }
 
     // If Cheibriados has slowed your life processes, you will hunger less.
     if (you_worship(GOD_CHEIBRIADOS) && you.piety >= piety_breakpoint(0))
@@ -4081,6 +4086,7 @@ int get_expiration_threshold(duration_type dur)
     case DUR_SHROUD_OF_GOLUBRIA:
     case DUR_INFUSION:
     case DUR_SONG_OF_SLAYING:
+    case DUR_TROGS_HAND:
         return (6 * BASELINE_DELAY);
 
     case DUR_FLIGHT:
@@ -5539,7 +5545,7 @@ void dec_disease_player(int delay)
         }
 
         // Trog's Hand.
-        if (you.attribute[ATTR_DIVINE_REGENERATION])
+        if (you.duration[DUR_TROGS_HAND])
             rr += 100;
 
         // Kobolds get a bonus too.
@@ -6990,7 +6996,7 @@ int player_res_magic(bool calc_unid, bool temp)
         rm += 50;
 
     // Trog's Hand
-    if (you.attribute[ATTR_DIVINE_REGENERATION] && temp)
+    if (you.duration[DUR_TROGS_HAND] && temp)
         rm += 70;
 
     // Enchantment effect
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index c390991..fba2928 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -1092,8 +1092,8 @@ static void _inc_penance(god_type god, int val)
         // Neither does Trog's regeneration or magic resistance.
         else if (god == GOD_TROG)
         {
-            if (you.attribute[ATTR_DIVINE_REGENERATION])
-                remove_regen(true);
+            if (you.duration[DUR_TROGS_HAND])
+                trog_remove_trogs_hand();
 
             make_god_gifts_disappear(); // only on level
         }
@@ -3074,8 +3074,8 @@ void excommunication(god_type new_god)
         break;
 
     case GOD_TROG:
-        if (you.attribute[ATTR_DIVINE_REGENERATION])
-            remove_regen(true);
+        if (you.duration[DUR_TROGS_HAND])
+            trog_remove_trogs_hand();
 
         add_daction(DACT_ALLY_TROG);
 
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index d51014a..0ae4e3b 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -1689,7 +1689,7 @@ static spret_type _do_cast(spell_type spell, int powc,
 
     // General enhancement.
     case SPELL_REGENERATION:
-        return cast_regen(powc, false, fail);
+        return cast_regen(powc, fail);
 
     case SPELL_REPEL_MISSILES:
         return missile_prot(powc, fail);
diff --git a/crawl-ref/source/spl-goditem.cc b/crawl-ref/source/spl-goditem.cc
index 319e2dd..1441957 100644
--- a/crawl-ref/source/spl-goditem.cc
+++ b/crawl-ref/source/spl-goditem.cc
@@ -416,9 +416,7 @@ void antimagic()
         need_msg = true;
     }
 
-    // Don't dispel divine regeneration.
-    if (you.duration[DUR_REGENERATION] > 0
-        && !you.attribute[ATTR_DIVINE_REGENERATION])
+    if (you.duration[DUR_REGENERATION] > 0)
     {
         you.duration[DUR_REGENERATION] = 1;
         need_msg = true;
diff --git a/crawl-ref/source/spl-selfench.cc b/crawl-ref/source/spl-selfench.cc
index ecb4b1f..0226bed 100644
--- a/crawl-ref/source/spl-selfench.cc
+++ b/crawl-ref/source/spl-selfench.cc
@@ -128,28 +128,20 @@ spret_type deflection(int pow, bool fail)
     return SPRET_SUCCESS;
 }
 
-void remove_regen(bool divine_ability)
+void remove_regen()
 {
-    mpr("Your skin stops crawling.", MSGCH_DURATION);
+    if (you.duration[DUR_TROGS_HAND] == 0)
+        mpr("Your skin stops crawling.", MSGCH_DURATION);
     you.duration[DUR_REGENERATION] = 0;
-    if (divine_ability)
-    {
-        mpr("You feel less resistant to hostile enchantments.", MSGCH_DURATION);
-        you.attribute[ATTR_DIVINE_REGENERATION] = 0;
-    }
 }
 
-spret_type cast_regen(int pow, bool divine_ability, bool fail)
+spret_type cast_regen(int pow, bool fail)
 {
     fail_check();
-    you.increase_duration(DUR_REGENERATION, 5 + roll_dice(2, pow / 3 + 1), 100,
-                          "Your skin crawls.");
 
-    if (divine_ability)
-    {
-        mpr("You feel resistant to hostile enchantments.");
-        you.attribute[ATTR_DIVINE_REGENERATION] = 1;
-    }
+    you.increase_duration(DUR_REGENERATION,
+                          5 + roll_dice(2, pow / 3 + 1), 100,
+                          "Your skin crawls.");
     return SPRET_SUCCESS;
 }
 
diff --git a/crawl-ref/source/spl-selfench.h b/crawl-ref/source/spl-selfench.h
index 7657407..a12e652 100644
--- a/crawl-ref/source/spl-selfench.h
+++ b/crawl-ref/source/spl-selfench.h
@@ -10,8 +10,8 @@ spret_type ice_armour(int pow, bool fail);
 spret_type missile_prot(int pow, bool fail);
 spret_type deflection(int pow, bool fail);
 
-void remove_regen(bool divine_ability = false);
-spret_type cast_regen(int pow, bool divine_ability = false, bool fail = false);
+void remove_regen();
+spret_type cast_regen(int pow, bool fail = false);
 spret_type cast_revivification(int pow, bool fail);
 
 spret_type cast_swiftness(int power, bool fail = false);
diff --git a/crawl-ref/source/status.cc b/crawl-ref/source/status.cc
index b550cb5..179e3fa 100644
--- a/crawl-ref/source/status.cc
+++ b/crawl-ref/source/status.cc
@@ -740,7 +740,8 @@ static void _describe_glow(status_info* inf)
 
 static void _describe_regen(status_info* inf)
 {
-    const bool regen = (you.duration[DUR_REGENERATION] > 0);
+    const bool regen = (you.duration[DUR_REGENERATION] > 0
+                        || you.duration[DUR_TROGS_HAND] > 0);
     const bool no_heal =
             (you.species == SP_VAMPIRE && you.hunger_state == HS_STARVING)
             || (player_mutation_level(MUT_SLOW_HEALING) == 3);
@@ -750,9 +751,12 @@ static void _describe_regen(status_info* inf)
 
     if (regen)
     {
-        inf->light_colour = _dur_colour(BLUE, dur_expiring(DUR_REGENERATION));
+        if (you.duration[DUR_REGENERATION] > you.duration[DUR_TROGS_HAND])
+            inf->light_colour = _dur_colour(BLUE, dur_expiring(DUR_REGENERATION));
+        else
+            inf->light_colour = _dur_colour(BLUE, dur_expiring(DUR_TROGS_HAND));
         inf->light_text   = "Regen";
-        if (you.attribute[ATTR_DIVINE_REGENERATION])
+        if (you.duration[DUR_TROGS_HAND])
             inf->light_text += " MR";
         else if (no_heal)
             inf->light_colour = DARKGREY;
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index 1eb7793..74fb900 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -2264,6 +2264,14 @@ static void tag_read_you(reader &th)
         you.attribute[j] = 0;
     for (j = NUM_ATTRIBUTES; j < count; ++j)
         unmarshallInt(th);
+#if TAG_MAJOR_VERSION == 34
+    if (you.attribute[ATTR_DIVINE_REGENERATION])
+    {
+        you.attribute[ATTR_DIVINE_REGENERATION] = 0;
+        you.duration[DUR_TROGS_HAND] = you.duration[DUR_REGENERATION];
+        you.duration[DUR_REGENERATION] = 0;
+    }
+#endif
 
     count = unmarshallByte(th);
     ASSERT(count <= NUM_OBJECT_CLASSES);
diff --git a/crawl-ref/source/wiz-you.cc b/crawl-ref/source/wiz-you.cc
index 5c60238..9c5bcdf 100644
--- a/crawl-ref/source/wiz-you.cc
+++ b/crawl-ref/source/wiz-you.cc
@@ -847,6 +847,7 @@ static const char* dur_names[] =
     "grasping roots",
     "sleep immunity",
     "fire vulnerability",
+    "trogs hand"
 };
 
 void wizard_edit_durations(void)
-- 
1.8.2.3

