Attached Files |
auto-id.patch [^] (6,420 bytes) 2014-01-03 08:35 [Show Content] [Hide Content]From 07fe3e7d265c7930b48b7f218497d520db75ac2b Mon Sep 17 00:00:00 2001
From: Sage <SageBasilMint@gmail.com>
Date: Thu, 2 Jan 2014 18:36:40 -0800
Subject: [PATCH] Automatically identify the last unknown item in relevant
base types.
'Relevant base types' are wands, staves, scrolls, potions, rings, amulets.
---
crawl-ref/source/itemname.cc | 20 ++++++++++++
crawl-ref/source/items.cc | 70 ++++++++++++++++++++++++++++++++++++++++++
crawl-ref/source/items.h | 2 ++
crawl-ref/source/misc.cc | 2 ++
crawl-ref/source/stash.cc | 4 +++
5 files changed, 98 insertions(+)
diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc
index c2f79cc..a51f70c 100644
--- a/crawl-ref/source/itemname.cc
+++ b/crawl-ref/source/itemname.cc
@@ -52,6 +52,21 @@ static bool _is_random_name_vowel(char let);
static char _random_vowel(int seed);
static char _random_cons(int seed);
+static void _maybe_identify_pack_item()
+{
+ for (int i = 0; i < ENDOFPACK; i++)
+ {
+ item_def& item = you.inv[i];
+ object_class_type basetype = item.base_type;
+ int subtype = item.sub_type;
+ if (item.defined()
+ && you.type_ids[basetype][subtype] != ID_KNOWN_TYPE)
+ {
+ maybe_identify_base_type(item);
+ }
+ }
+}
+
bool is_vowel(const ucs_t chr)
{
const char low = towlower(chr);
@@ -2050,6 +2065,8 @@ void set_ident_type(item_def &item, item_type_id_state_type setting,
// Sometimes (e.g. shops) you can ID an item before you get it;
// don't note twice in those cases.
item.flags |= (ISFLAG_NOTED_ID | ISFLAG_NOTED_GET);
+
+ _maybe_identify_pack_item();
}
}
@@ -2073,7 +2090,10 @@ void set_ident_type(object_class_type basetype, int subtype,
you.type_ids[basetype][subtype] = setting;
request_autoinscribe();
if (setting == ID_KNOWN_TYPE)
+ {
shopping_list.item_type_identified(basetype, subtype);
+ _maybe_identify_pack_item();
+ }
}
}
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index dd05a6f..123e9ab 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -1783,6 +1783,7 @@ int move_item_to_player(int obj, int quant_got, bool quiet,
item.flags &= ~(ISFLAG_DROPPED_BY_ALLY | ISFLAG_UNOBTAINABLE);
god_id_item(item);
+ maybe_identify_base_type(item);
if (item.base_type == OBJ_BOOKS)
maybe_id_book(item, true);
@@ -1884,7 +1885,10 @@ bool move_item_to_grid(int *const obj, const coord_def& p, bool silent)
}
if (you.see_cell(p))
+ {
god_id_item(item);
+ maybe_identify_base_type(item);
+ }
// If it's a stackable type...
if (is_stackable_item(item))
@@ -4174,3 +4178,69 @@ void corrode_item(item_def &item, actor *holder)
else
item.plus = how_rusty;
}
+
+//If there is only one unidentified subtype left in the item's object type,
+//automatically identify it.
+void maybe_identify_base_type(item_def &item)
+{
+ int item_count = 0; //Number of objects in an enum
+ object_class_type basetype = item.base_type;
+ int subtype = item.sub_type;
+ bool is_amulet = false;
+
+ switch (basetype)
+ {
+ case OBJ_WANDS:
+ item_count = NUM_WANDS; break;
+ case OBJ_STAVES:
+ item_count = NUM_STAVES; break;
+ case OBJ_POTIONS:
+ item_count = NUM_POTIONS; break;
+ case OBJ_SCROLLS:
+ item_count = NUM_SCROLLS; break;
+ case OBJ_JEWELLERY:
+ if (subtype >= RING_FIRST_RING && subtype < NUM_RINGS)
+ item_count = NUM_RINGS;
+ else
+ {
+ item_count = NUM_JEWELLERY - AMU_FIRST_AMULET;
+ is_amulet = true;
+ }
+
+ break;
+
+ default:
+ return;
+ }
+
+ int ident_count = 0;
+
+ for (int i = (!is_amulet ? 0 : AMU_FIRST_AMULET);
+ i < (!is_amulet ? item_count : item_count + AMU_FIRST_AMULET);
+ i++)
+ {
+ bool identified = you.type_ids[basetype][i] == ID_KNOWN_TYPE;
+ ident_count += identified ? 1 : 0;
+ }
+
+ if (ident_count == item_count - 1)
+ {
+ for (int i = (!is_amulet ? 0 : AMU_FIRST_AMULET);
+ i < (!is_amulet ? item_count : item_count + AMU_FIRST_AMULET + 1);
+ i++)
+ {
+ set_ident_type(basetype, i, ID_KNOWN_TYPE);
+ }
+
+ string class_name = item_class_name(basetype, true);
+ if (class_name == "jewellery")
+ {
+ if (is_amulet)
+ class_name = "amulet";
+ else
+ class_name = "ring";
+ }
+
+ mprf("You have identified the last %s.", class_name.c_str());
+ }
+}
diff --git a/crawl-ref/source/items.h b/crawl-ref/source/items.h
index a40a322..89a7eec 100644
--- a/crawl-ref/source/items.h
+++ b/crawl-ref/source/items.h
@@ -148,6 +148,8 @@ void move_items(const coord_def r, const coord_def p);
object_class_type get_random_item_mimic_type();
object_class_type get_item_mimic_type();
bool is_valid_mimic_item(const item_def &item);
+
+void maybe_identify_base_type(item_def &item);
// Returns the Orb's position on the ground, or origin()
coord_def orb_position();
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 83990dc..88a94ff 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -2592,7 +2592,9 @@ void auto_id_inventory()
{
item_def& item = you.inv[i];
if (item.defined())
+ {
god_id_item(item, false);
+ }
}
}
diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc
index a20d19a..e2b61f0 100644
--- a/crawl-ref/source/stash.cc
+++ b/crawl-ref/source/stash.cc
@@ -333,6 +333,7 @@ void Stash::update()
hints_first_item(*pitem);
god_id_item(*pitem);
+ maybe_identify_base_type(*pitem);
const item_def& item = *pitem;
if (!_grid_has_perceived_multiple_items(p))
@@ -661,7 +662,10 @@ void Stash::_update_corpses(int rot_time)
void Stash::_update_identification()
{
for (int i = items.size() - 1; i >= 0; i--)
+ {
god_id_item(items[i]);
+ maybe_identify_base_type(items[i]);
+ }
}
void Stash::add_item(const item_def &item, bool add_to_front)
--
1.7.9.5
auto-id-update.patch [^] (6,275 bytes) 2014-01-03 21:36 [Show Content] [Hide Content]From 48cd40d1cdcf7a383920a5340acd45bf27f88369 Mon Sep 17 00:00:00 2001
From: Sage <SageBasilMint@gmail.com>
Date: Thu, 2 Jan 2014 18:36:40 -0800
Subject: [PATCH] Automatically identify the last unknown item in relevant
base types.
'Relevant base types' are wands, staves, scrolls, potions, rings, amulets.
---
crawl-ref/source/itemname.cc | 20 +++++++++++
crawl-ref/source/items.cc | 76 ++++++++++++++++++++++++++++++++++++++++++
crawl-ref/source/items.h | 2 ++
crawl-ref/source/stash.cc | 4 +++
4 files changed, 102 insertions(+)
diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc
index c2f79cc..0863de8 100644
--- a/crawl-ref/source/itemname.cc
+++ b/crawl-ref/source/itemname.cc
@@ -52,6 +52,21 @@ static bool _is_random_name_vowel(char let);
static char _random_vowel(int seed);
static char _random_cons(int seed);
+static void _maybe_identify_pack_item()
+{
+ for (int i = 0; i < ENDOFPACK; i++)
+ {
+ item_def& item = you.inv[i];
+ object_class_type basetype = item.base_type;
+ int subtype = item.sub_type;
+ if (item.defined()
+ && you.type_ids[basetype][subtype] != ID_KNOWN_TYPE)
+ {
+ maybe_identify_base_type(item, true);
+ }
+ }
+}
+
bool is_vowel(const ucs_t chr)
{
const char low = towlower(chr);
@@ -2050,6 +2065,8 @@ void set_ident_type(item_def &item, item_type_id_state_type setting,
// Sometimes (e.g. shops) you can ID an item before you get it;
// don't note twice in those cases.
item.flags |= (ISFLAG_NOTED_ID | ISFLAG_NOTED_GET);
+
+ _maybe_identify_pack_item();
}
}
@@ -2073,7 +2090,10 @@ void set_ident_type(object_class_type basetype, int subtype,
you.type_ids[basetype][subtype] = setting;
request_autoinscribe();
if (setting == ID_KNOWN_TYPE)
+ {
shopping_list.item_type_identified(basetype, subtype);
+ _maybe_identify_pack_item();
+ }
}
}
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index dd05a6f..82d09fd 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -1783,6 +1783,7 @@ int move_item_to_player(int obj, int quant_got, bool quiet,
item.flags &= ~(ISFLAG_DROPPED_BY_ALLY | ISFLAG_UNOBTAINABLE);
god_id_item(item);
+ maybe_identify_base_type(item, false);
if (item.base_type == OBJ_BOOKS)
maybe_id_book(item, true);
@@ -1884,7 +1885,10 @@ bool move_item_to_grid(int *const obj, const coord_def& p, bool silent)
}
if (you.see_cell(p))
+ {
god_id_item(item);
+ maybe_identify_base_type(item, false);
+ }
// If it's a stackable type...
if (is_stackable_item(item))
@@ -4174,3 +4178,75 @@ void corrode_item(item_def &item, actor *holder)
else
item.plus = how_rusty;
}
+
+//If there is only one unidentified subtype left in the item's object type,
+//automatically identify it.
+bool maybe_identify_base_type(item_def &item, bool in_pack)
+{
+ if (you.type_ids[item.base_type][item.sub_type] == ID_KNOWN_TYPE)
+ return false;
+
+ int item_count = 0; //Number of objects in an enum
+ object_class_type basetype = item.base_type;
+ int subtype = item.sub_type;
+ bool is_amulet = false;
+
+ switch (basetype)
+ {
+ case OBJ_WANDS:
+ item_count = NUM_WANDS; break;
+ case OBJ_STAVES:
+ item_count = NUM_STAVES; break;
+ case OBJ_POTIONS:
+ item_count = NUM_POTIONS; break;
+ case OBJ_SCROLLS:
+ item_count = NUM_SCROLLS; break;
+ case OBJ_JEWELLERY:
+ if (subtype >= RING_FIRST_RING && subtype < NUM_RINGS)
+ item_count = NUM_RINGS;
+ else
+ {
+ item_count = NUM_JEWELLERY - AMU_FIRST_AMULET;
+ is_amulet = true;
+ }
+ break;
+
+ default:
+ return false;
+ }
+
+ int ident_count = 0;
+
+ for (int i = (!is_amulet ? 0 : AMU_FIRST_AMULET);
+ i < (!is_amulet ? item_count : item_count + AMU_FIRST_AMULET);
+ i++)
+ {
+ bool identified = you.type_ids[basetype][i] == ID_KNOWN_TYPE;
+ ident_count += identified ? 1 : 0;
+ }
+
+ int adjust = is_amulet ? 1 : 0; //To account for "cfly
+
+ if (ident_count == item_count - 1 - adjust)
+ {
+ set_ident_type(basetype, subtype, ID_KNOWN_TYPE);
+ if (!in_pack &&
+ (basetype == OBJ_STAVES || basetype == OBJ_JEWELLERY))
+ item.props["needs_autopickup"] = true;
+
+ string class_name = item_class_name(basetype, true);
+ if (class_name == "jewellery")
+ {
+ if (is_amulet)
+ class_name = "amulet";
+ else
+ class_name = "ring";
+ }
+
+ mprf("You have identified the last %s.", class_name.c_str());
+
+ return true;
+ }
+
+ return false;
+}
diff --git a/crawl-ref/source/items.h b/crawl-ref/source/items.h
index a40a322..2ec9687 100644
--- a/crawl-ref/source/items.h
+++ b/crawl-ref/source/items.h
@@ -148,6 +148,8 @@ void move_items(const coord_def r, const coord_def p);
object_class_type get_random_item_mimic_type();
object_class_type get_item_mimic_type();
bool is_valid_mimic_item(const item_def &item);
+
+bool maybe_identify_base_type(item_def &item, bool in_pack);
// Returns the Orb's position on the ground, or origin()
coord_def orb_position();
diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc
index a20d19a..069d9ed 100644
--- a/crawl-ref/source/stash.cc
+++ b/crawl-ref/source/stash.cc
@@ -333,6 +333,7 @@ void Stash::update()
hints_first_item(*pitem);
god_id_item(*pitem);
+ maybe_identify_base_type(*pitem, false);
const item_def& item = *pitem;
if (!_grid_has_perceived_multiple_items(p))
@@ -661,7 +662,10 @@ void Stash::_update_corpses(int rot_time)
void Stash::_update_identification()
{
for (int i = items.size() - 1; i >= 0; i--)
+ {
god_id_item(items[i]);
+ maybe_identify_base_type(items[i], false);
+ }
}
void Stash::add_item(const item_def &item, bool add_to_front)
--
1.7.9.5
|