summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/spl-util.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-05 10:58:57 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-05 10:58:57 +0000
commita88fd9951f8e4faa48e0ea328df203c13e247fb1 (patch)
treebefd19a3d8f1deff0bd0c3b1c7d716a419043ad4 /crawl-ref/source/spl-util.cc
parent827ca0211f55e05d0ecc2319bfc4fd9f51a37053 (diff)
downloadcrawl-ref-a88fd9951f8e4faa48e0ea328df203c13e247fb1.tar.gz
crawl-ref-a88fd9951f8e4faa48e0ea328df203c13e247fb1.zip
Refix &Z crash-fix, which didn't actually fix the crash. :P
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2335 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/spl-util.cc')
-rw-r--r--crawl-ref/source/spl-util.cc20
1 files changed, 7 insertions, 13 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),