diff options
Diffstat (limited to 'crawl-ref/source/effects.cc')
-rw-r--r-- | crawl-ref/source/effects.cc | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index 86cf3d4061..81c7edb13c 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -1403,6 +1403,29 @@ bool acquirement(unsigned char force_class, int agent) return (true); } // end acquirement() +// Remove the "empty" autoinscription, if present. +// Return true if the inscription was there, false otherwise. +bool remove_empty_inscription( item_def& item ) +{ + const char* empty_inscription = "empty"; + size_t p = item.inscription.find(empty_inscription); + if ( p != std::string::npos ) + { + // found it, delete it + size_t prespace = 0; + // if preceded by a space, delete that too + if ( p != 0 && item.inscription[p-1] == ' ' ) + prespace = 1; + item.inscription = + item.inscription.substr(0, p - prespace) + + item.inscription.substr(p + strlen(empty_inscription), + std::string::npos); + return true; + } + else + return false; +} + bool recharge_wand(void) { if (you.equip[EQ_WEAPON] == -1) @@ -1416,19 +1439,7 @@ bool recharge_wand(void) int charge_gain = 0; if (wand.base_type == OBJ_WANDS) { - // remove "empty" autoinscription - const char* empty_inscription = "empty"; - size_t p = wand.inscription.find(empty_inscription); - if ( p != std::string::npos ) { - // found it, delete it - size_t prespace = 0; - if ( p != 0 && wand.inscription[p-1] == ' ' ) - prespace = 1; - wand.inscription = - wand.inscription.substr(0, p - prespace) + - wand.inscription.substr(p + strlen(empty_inscription), - std::string::npos); - } + remove_empty_inscription(wand); switch (wand.sub_type) { case WAND_INVISIBILITY: |