From 5eef4af9d8262ab445d4b140a5dd9e72f1aa5993 Mon Sep 17 00:00:00 2001
From: Immotian <Immotian@yahoo.com>
Date: Sun, 29 Dec 2013 18:23:45 -0800
Subject: [PATCH] Identify the last unknown targetted scroll and last unknown
 healing potion when you know what they are.

Specifically, you know what they are when it has been tried (so you know it
is in one of those categories) and when all the others in that category are
identified. This should probably be extended to nontargetted scrolls, mainly
for ?CW for Mo, and for the last unidentified scroll and last unidentified
potion.
---
 crawl-ref/source/item_use.cc |   30 ++++++++++++++++++++++++++++++
 crawl-ref/source/itemname.cc |   15 +++++++++++++++
 crawl-ref/source/itemname.h  |    1 +
 crawl-ref/source/mon-act.cc  |    3 +++
 crawl-ref/source/potion.cc   |    1 +
 5 files changed, 50 insertions(+)

diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index 8aebd30..8fd6ca1 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -74,6 +74,8 @@ static int _handle_enchant_armour(int item_slot = -1,
 static bool _is_cancellable_scroll(scroll_type scroll);
 static bool _safe_to_remove_or_wear(const item_def &item, bool remove,
                                     bool quiet = false);
+static bool _two_targetted_scrolls_identified();
+static bool _one_targetted_scroll_tried();
 
 // Rather messy - we've gathered all the can't-wield logic from wield_weapon()
 // here.
@@ -1244,6 +1246,22 @@ static bool _safe_to_remove_or_wear(const item_def &item, bool remove, bool quie
     return true;
 }
 
+static bool _two_targetted_scrolls_identified()
+{
+    int ident_count = (you.type_ids[OBJ_SCROLLS][SCR_RECHARGING] == ID_KNOWN_TYPE)
+                    + (you.type_ids[OBJ_SCROLLS][SCR_ENCHANT_ARMOUR] == ID_KNOWN_TYPE)
+                    + (you.type_ids[OBJ_SCROLLS][SCR_IDENTIFY] == ID_KNOWN_TYPE);
+
+    return ident_count == 2;
+}
+
+static bool _one_targetted_scroll_tried()
+{
+    return (you.type_ids[OBJ_SCROLLS][SCR_RECHARGING] ==  ID_TRIED_ITEM_TYPE
+            || (you.type_ids[OBJ_SCROLLS][SCR_ENCHANT_ARMOUR] == ID_TRIED_ITEM_TYPE)
+            || (you.type_ids[OBJ_SCROLLS][SCR_IDENTIFY] == ID_TRIED_ITEM_TYPE));
+}
+
 // Checks whether removing an item would cause flight to end and the
 // player to fall to their death.  Same for clinging.
 bool safe_to_remove(const item_def &item, bool quiet)
@@ -3373,6 +3391,18 @@ void read_scroll(int slot)
              scroll_name.c_str());
     }
 
+    if (_two_targetted_scrolls_identified()
+        && _one_targetted_scroll_tried()
+        && (which_scroll == SCR_IDENTIFY
+            || which_scroll == SCR_RECHARGING
+            || which_scroll == SCR_ENCHANT_ARMOUR))
+    {
+        set_ident_type(OBJ_SCROLLS, SCR_IDENTIFY, ID_KNOWN_TYPE);
+        set_ident_type(OBJ_SCROLLS, SCR_RECHARGING, ID_KNOWN_TYPE);
+        set_ident_type(OBJ_SCROLLS, SCR_ENCHANT_ARMOUR, ID_KNOWN_TYPE);
+        mpr("You have identified the last targetted scroll.");
+    }
+
     if (!alreadyknown && dangerous)
     {
         // Xom loves it when you read an unknown scroll and there is a
diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc
index 52a7062..c2f79cc 100644
--- a/crawl-ref/source/itemname.cc
+++ b/crawl-ref/source/itemname.cc
@@ -2077,6 +2077,21 @@ void set_ident_type(object_class_type basetype, int subtype,
     }
 }
 
+void identify_healing_pots()
+{
+    int ident_count = (you.type_ids[OBJ_POTIONS][POT_CURING] == ID_KNOWN_TYPE)
+                    + (you.type_ids[OBJ_POTIONS][POT_HEAL_WOUNDS] == ID_KNOWN_TYPE);
+    int tried_count = (you.type_ids[OBJ_POTIONS][POT_CURING] == ID_MON_TRIED_TYPE)
+                    + (you.type_ids[OBJ_POTIONS][POT_HEAL_WOUNDS] == ID_MON_TRIED_TYPE);
+
+    if (ident_count == 1 && tried_count == 1)
+    {
+        set_ident_type(OBJ_POTIONS, POT_CURING, ID_KNOWN_TYPE);
+        set_ident_type(OBJ_POTIONS, POT_HEAL_WOUNDS, ID_KNOWN_TYPE);
+        mpr("You have identified the last healing potion.");
+    }
+}
+
 item_type_id_state_type get_ident_type(const item_def &item)
 {
     if (is_artefact(item))
diff --git a/crawl-ref/source/itemname.h b/crawl-ref/source/itemname.h
index 69aad0e..fa22339 100644
--- a/crawl-ref/source/itemname.h
+++ b/crawl-ref/source/itemname.h
@@ -114,6 +114,7 @@ void set_ident_type(item_def &item, item_type_id_state_type setting,
                      bool force = false);
 void set_ident_type(object_class_type basetype, int subtype,
                      item_type_id_state_type setting, bool force = false);
+void identify_healing_pots();
 
 string item_prefix(const item_def &item, bool temp = true);
 string get_menu_colour_prefix_tags(const item_def &item,
diff --git a/crawl-ref/source/mon-act.cc b/crawl-ref/source/mon-act.cc
index ecc7cfc..2864977 100644
--- a/crawl-ref/source/mon-act.cc
+++ b/crawl-ref/source/mon-act.cc
@@ -792,7 +792,10 @@ static bool _handle_potion(monster* mons, bolt & beem)
 
         // Give ID if necessary.
         if (was_visible && id != ID_UNKNOWN_TYPE)
+        {
             set_ident_type(OBJ_POTIONS, ptype, id);
+            identify_healing_pots();
+        }
 
         // Remove it from inventory.
         if (dec_mitm_item_quantity(potion_idx, 1))
diff --git a/crawl-ref/source/potion.cc b/crawl-ref/source/potion.cc
index 265e497..182a753 100644
--- a/crawl-ref/source/potion.cc
+++ b/crawl-ref/source/potion.cc
@@ -532,6 +532,7 @@ bool potion_effect(potion_type pot_eff, int pow, item_def *potion, bool was_know
         set_ident_flags(*potion, ISFLAG_IDENT_MASK);
         set_ident_type(*potion, ID_KNOWN_TYPE);
         mprf("It was a %s.", potion->name(DESC_QUALNAME).c_str());
+        identify_healing_pots();
     }
 
     return true;
-- 
1.7.9.5

