summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorNicholas Feinberg <pleasingfung@gmail.com>2014-07-22 22:53:48 -0700
committerNicholas Feinberg <pleasingfung@gmail.com>2014-07-22 22:53:48 -0700
commitb6cf2bc58d6b713433ea508f86a05975d3333713 (patch)
tree945c1b23876f7056ea885b20bbefb57106395e5a /crawl-ref/source
parentcb37f90e438812ca6d78e310328754a50537a8be (diff)
downloadcrawl-ref-b6cf2bc58d6b713433ea508f86a05975d3333713.tar.gz
crawl-ref-b6cf2bc58d6b713433ea508f86a05975d3333713.zip
Refactor out a redundant list of jewellery names
And de-indent l_item_do_subtype() slightly.
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/itemname.cc115
-rw-r--r--crawl-ref/source/itemname.h1
-rw-r--r--crawl-ref/source/l_item.cc128
3 files changed, 119 insertions, 125 deletions
diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc
index f83b372cb1..707a0d83c3 100644
--- a/crawl-ref/source/itemname.cc
+++ b/crawl-ref/source/itemname.cc
@@ -718,52 +718,91 @@ static const char* scroll_type_name(int scrolltype)
}
}
-static const char* jewellery_type_name(int jeweltype)
-{
+/**
+ * Get the name for the effect provided by a kind of jewellery.
+ *
+ * @param jeweltype The jewellery_type of the item in question.
+ * @return A string describing the effect of the given jewellery
+ * subtype.
+ */
+const char* jewellery_effect_name(int jeweltype)
+ {
switch (static_cast<jewellery_type>(jeweltype))
{
- case RING_REGENERATION: return "ring of regeneration";
- case RING_PROTECTION: return "ring of protection";
- case RING_PROTECTION_FROM_FIRE: return "ring of protection from fire";
- case RING_POISON_RESISTANCE: return "ring of poison resistance";
- case RING_PROTECTION_FROM_COLD: return "ring of protection from cold";
- case RING_STRENGTH: return "ring of strength";
- case RING_SLAYING: return "ring of slaying";
- case RING_SEE_INVISIBLE: return "ring of see invisible";
- case RING_INVISIBILITY: return "ring of invisibility";
- case RING_LOUDNESS: return "ring of loudness";
- case RING_TELEPORTATION: return "ring of teleportation";
- case RING_EVASION: return "ring of evasion";
- case RING_SUSTAIN_ABILITIES: return "ring of sustain abilities";
- case RING_STEALTH: return "ring of stealth";
- case RING_DEXTERITY: return "ring of dexterity";
- case RING_INTELLIGENCE: return "ring of intelligence";
- case RING_WIZARDRY: return "ring of wizardry";
- case RING_MAGICAL_POWER: return "ring of magical power";
- case RING_FLIGHT: return "ring of flight";
- case RING_LIFE_PROTECTION: return "ring of positive energy";
- case RING_PROTECTION_FROM_MAGIC: return "ring of protection from magic";
- case RING_FIRE: return "ring of fire";
- case RING_ICE: return "ring of ice";
- case RING_TELEPORT_CONTROL: return "ring of teleport control";
- case AMU_RAGE: return "amulet of rage";
- case AMU_CLARITY: return "amulet of clarity";
- case AMU_WARDING: return "amulet of warding";
- case AMU_RESIST_CORROSION: return "amulet of resist corrosion";
- case AMU_THE_GOURMAND: return "amulet of the gourmand";
+ case RING_REGENERATION: return "regeneration";
+ case RING_PROTECTION: return "protection";
+ case RING_PROTECTION_FROM_FIRE: return "protection from fire";
+ case RING_POISON_RESISTANCE: return "poison resistance";
+ case RING_PROTECTION_FROM_COLD: return "protection from cold";
+ case RING_STRENGTH: return "strength";
+ case RING_SLAYING: return "slaying";
+ case RING_SEE_INVISIBLE: return "see invisible";
+ case RING_INVISIBILITY: return "invisibility";
+ case RING_LOUDNESS: return "loudness";
+ case RING_TELEPORTATION: return "teleportation";
+ case RING_EVASION: return "evasion";
+ case RING_SUSTAIN_ABILITIES: return "sustain abilities";
+ case RING_STEALTH: return "stealth";
+ case RING_DEXTERITY: return "dexterity";
+ case RING_INTELLIGENCE: return "intelligence";
+ case RING_WIZARDRY: return "wizardry";
+ case RING_MAGICAL_POWER: return "magical power";
+ case RING_FLIGHT: return "flight";
+ case RING_LIFE_PROTECTION: return "positive energy";
+ case RING_PROTECTION_FROM_MAGIC: return "protection from magic";
+ case RING_FIRE: return "fire";
+ case RING_ICE: return "ice";
+ case RING_TELEPORT_CONTROL: return "teleport control";
+ case AMU_RAGE: return "rage";
+ case AMU_CLARITY: return "clarity";
+ case AMU_WARDING: return "warding";
+ case AMU_RESIST_CORROSION: return "resist corrosion";
+ case AMU_THE_GOURMAND: return "the gourmand";
#if TAG_MAJOR_VERSION == 34
- case AMU_CONSERVATION: return "amulet of conservation";
- case AMU_CONTROLLED_FLIGHT: return "amulet of controlled flight";
+ case AMU_CONSERVATION: return "conservation";
+ case AMU_CONTROLLED_FLIGHT: return "controlled flight";
#endif
- case AMU_INACCURACY: return "amulet of inaccuracy";
- case AMU_RESIST_MUTATION: return "amulet of resist mutation";
- case AMU_GUARDIAN_SPIRIT: return "amulet of guardian spirit";
- case AMU_FAITH: return "amulet of faith";
- case AMU_STASIS: return "amulet of stasis";
+ case AMU_INACCURACY: return "inaccuracy";
+ case AMU_RESIST_MUTATION: return "resist mutation";
+ case AMU_GUARDIAN_SPIRIT: return "guardian spirit";
+ case AMU_FAITH: return "faith";
+ case AMU_STASIS: return "stasis";
default: return "buggy jewellery";
}
}
+/**
+ * Get the name for the category of a type of jewellery.
+ *
+ * @param jeweltype The jewellery_type of the item in question.
+ * @return A string describing the kind of jewellery it is.
+ */
+static const char* _jewellery_class_name(int jeweltype)
+{
+ if (jeweltype < RING_FIRST_RING || jeweltype >= NUM_JEWELLERY
+ || jeweltype >= NUM_RINGS && jeweltype < AMU_FIRST_AMULET)
+ {
+ return "buggy"; // "buggy buggy jewellery"
+ }
+
+ if (jeweltype < NUM_RINGS)
+ return "ring of";
+ return "amulet of";
+}
+
+/**
+ * Get the name for a type of jewellery.
+ *
+ * @param jeweltype The jewellery_type of the item in question.
+ * @return The full name of the jewellery type in question.
+ */
+static const char* jewellery_type_name(int jeweltype)
+{
+ return make_stringf("%s %s", _jewellery_class_name(jeweltype),
+ jewellery_effect_name(jeweltype)).c_str();
+}
+
+
static const char* ring_secondary_string(int s)
{
switch (s)
diff --git a/crawl-ref/source/itemname.h b/crawl-ref/source/itemname.h
index 06cf4fb136..2030f840de 100644
--- a/crawl-ref/source/itemname.h
+++ b/crawl-ref/source/itemname.h
@@ -145,4 +145,5 @@ string sub_type_string(const item_def &item, bool known = true);
string ego_type_string(const item_def &item, bool terse = false, int override_brand = 0);
const char* potion_type_name(int potiontype); //used in xom.cc
+const char* jewellery_effect_name(int jeweltype) PURE; //used in l_item.cc
#endif
diff --git a/crawl-ref/source/l_item.cc b/crawl-ref/source/l_item.cc
index 413f086c4c..4149875a58 100644
--- a/crawl-ref/source/l_item.cc
+++ b/crawl-ref/source/l_item.cc
@@ -266,105 +266,59 @@ static int l_item_do_class(lua_State *ls)
IDEFN(class, do_class)
-// FIXME: Fold this back into itemname.cc.
-static const char *ring_types[] =
-{
- "regeneration",
- "protection",
- "protection from fire",
- "poison resistance",
- "protection from cold",
- "strength",
- "slaying",
- "see invisible",
- "invisibility",
- "loudness",
- "teleportation",
- "evasion",
- "sustain abilities",
- "stealth",
- "dexterity",
- "intelligence",
- "wizardry",
- "magical power",
- "flight",
- "life protection",
- "protection from magic",
- "fire",
- "ice",
- "teleport control"
-};
-
-static const char *amulet_types[] =
-{
- "rage", "clarity", "warding", "resist corrosion",
- "gourmand",
-#if TAG_MAJOR_VERSION == 34
- "conservation", "controlled flight",
-#endif
- "inaccuracy",
- "resist mutation", "guardian spirit", "faith", "stasis",
-};
-
+// XXX: I really doubt most of this function needs to exist
static int l_item_do_subtype(lua_State *ls)
{
UDATA_ITEM(item);
- COMPILE_CHECK(ARRAYSZ(ring_types) == NUM_RINGS);
- COMPILE_CHECK(ARRAYSZ(amulet_types) == NUM_JEWELLERY - AMU_FIRST_AMULET);
- if (item)
+ if (!item)
{
- const char *s = NULL;
- if (item->base_type == OBJ_ARMOUR)
- s = item_slot_name(get_armour_slot(*item), true);
- if (item_type_known(*item))
+ lua_pushnil(ls);
+ return 1;
+ }
+
+ const char *s = NULL;
+ if (item->base_type == OBJ_ARMOUR)
+ s = item_slot_name(get_armour_slot(*item), true);
+ if (item_type_known(*item))
+ {
+ if (item->base_type == OBJ_JEWELLERY)
+ s = jewellery_effect_name(item->sub_type);
+ else if (item->base_type == OBJ_POTIONS)
{
- if (item->base_type == OBJ_JEWELLERY)
- {
- if (jewellery_is_amulet(*item))
- s = amulet_types[item->sub_type - AMU_FIRST_AMULET];
- else
- s = ring_types[item->sub_type];
- }
- else if (item->base_type == OBJ_POTIONS)
- {
- if (item->sub_type == POT_BLOOD)
- s = "blood";
- else if (item->sub_type == POT_BLOOD_COAGULATED)
- s = "coagulated blood";
- else if (item->sub_type == POT_PORRIDGE)
- s = "porridge";
- else if (item->sub_type == POT_BERSERK_RAGE)
- s = "berserk";
+ if (item->sub_type == POT_BLOOD)
+ s = "blood";
+ else if (item->sub_type == POT_BLOOD_COAGULATED)
+ s = "coagulated blood";
+ else if (item->sub_type == POT_PORRIDGE)
+ s = "porridge";
+ else if (item->sub_type == POT_BERSERK_RAGE)
+ s = "berserk";
#if TAG_MAJOR_VERSION == 34
- else if (item->sub_type == POT_GAIN_STRENGTH
- || item->sub_type == POT_GAIN_DEXTERITY
- || item->sub_type == POT_GAIN_INTELLIGENCE)
- {
- s = "gain ability";
- }
-#endif
- else if (item->sub_type == POT_CURE_MUTATION)
- s = "cure mutation";
- }
- else if (item->base_type == OBJ_BOOKS)
+ else if (item->sub_type == POT_GAIN_STRENGTH
+ || item->sub_type == POT_GAIN_DEXTERITY
+ || item->sub_type == POT_GAIN_INTELLIGENCE)
{
- if (item->sub_type == BOOK_MANUAL)
- s = "manual";
- else
- s = "spellbook";
+ s = "gain ability";
}
+#endif
+ else if (item->sub_type == POT_CURE_MUTATION)
+ s = "cure mutation";
+ }
+ else if (item->base_type == OBJ_BOOKS)
+ {
+ if (item->sub_type == BOOK_MANUAL)
+ s = "manual";
+ else
+ s = "spellbook";
}
-
- if (s)
- lua_pushstring(ls, s);
- else
- lua_pushnil(ls);
-
- return 1;
}
- lua_pushnil(ls);
+ if (s)
+ lua_pushstring(ls, s);
+ else
+ lua_pushnil(ls);
+
return 1;
}