diff options
-rw-r--r-- | crawl-ref/source/spl-util.cc | 20 | ||||
-rw-r--r-- | crawl-ref/source/spl-util.h | 1 |
2 files changed, 7 insertions, 14 deletions
diff --git a/crawl-ref/source/spl-util.cc b/crawl-ref/source/spl-util.cc index e4065c2beb..918592a9ef 100644 --- a/crawl-ref/source/spl-util.cc +++ b/crawl-ref/source/spl-util.cc @@ -75,34 +75,27 @@ void init_spell_descs(void) spell_list[spelldata[i].id] = i; } // end init_spell_descs() -spell_type spell_by_name(const char* name) +spell_type spell_by_name(std::string name) { - if (name == NULL || strlen(name) == 0) + if (name.empty()) return (SPELL_NO_SPELL); - char spname[80]; - + lowercase(name); + for (int i = 0; i < NUM_SPELLS; i++) { spell_type type = static_cast<spell_type>(i); const char *sptitle = spell_title(type); if (!sptitle) continue; - - strncpy( spname, sptitle, sizeof( spname ) ); - if (strcasecmp(spname, name) == 0) + if (name == lowercase_string(sptitle)) return (type); } return (SPELL_NO_SPELL); } -spell_type spell_by_name(std::string name) -{ - return spell_by_name(name.c_str()); -} - int get_spell_slot_by_letter( char letter ) { ASSERT( isalpha( letter ) ); @@ -834,7 +827,8 @@ int spell_type2skill(unsigned int spelltype) //jmf: simplified; moved init code to top function, init_spell_descs() static spell_desc *seekspell(spell_type spell) { - return (&spelldata[spell_list[spell]]); + const int index = spell_list[spell]; + return (index != -1? &spelldata[index] : NULL); } static bool cloud_helper(int (*func)(int, int, int, cloud_type, kill_category), diff --git a/crawl-ref/source/spl-util.h b/crawl-ref/source/spl-util.h index 4e86d9ff3e..67f76133ef 100644 --- a/crawl-ref/source/spl-util.h +++ b/crawl-ref/source/spl-util.h @@ -64,7 +64,6 @@ struct spell_desc //* * called from: acr void init_spell_descs(void); -spell_type spell_by_name(const char* name); spell_type spell_by_name(std::string name); int get_spell_slot_by_letter( char letter ); |