From 7b4927dc530fe713ac4c784af53e1958d78a4eeb Mon Sep 17 00:00:00 2001 From: dshaligram Date: Thu, 25 Oct 2007 09:11:50 +0000 Subject: Spell changes: strengthened stone arrow and the storms, weakened bolts of fire and cold, and crystal spear. (Re)allow partial spell names when using &Z in wizmode. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2543 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/spl-util.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'crawl-ref/source/spl-util.cc') diff --git a/crawl-ref/source/spl-util.cc b/crawl-ref/source/spl-util.cc index 2f06175670..9cbaace2df 100644 --- a/crawl-ref/source/spl-util.cc +++ b/crawl-ref/source/spl-util.cc @@ -76,13 +76,14 @@ void init_spell_descs(void) spell_list[spelldata[i].id] = i; } // end init_spell_descs() -spell_type spell_by_name(std::string name) +spell_type spell_by_name(std::string name, bool partial_match) { if (name.empty()) return (SPELL_NO_SPELL); lowercase(name); - + + int spellmatch = -1; for (int i = 0; i < NUM_SPELLS; i++) { spell_type type = static_cast(i); @@ -90,11 +91,16 @@ spell_type spell_by_name(std::string name) if (!sptitle) continue; - if (name == lowercase_string(sptitle)) + const std::string spell_name = lowercase_string(sptitle); + if (name == spell_name) return (type); + + if (partial_match && spell_name.find(name) != std::string::npos) + spellmatch = i; } - return (SPELL_NO_SPELL); + return (spellmatch != -1? static_cast(spellmatch) + : SPELL_NO_SPELL); } int get_spell_slot_by_letter( char letter ) -- cgit v1.2.3-54-g00ecf