From 0ca2a48c7e8d7454b609b9156c9ce56e04e891e3 Mon Sep 17 00:00:00 2001 From: Neil Moore Date: Wed, 6 Aug 2014 00:54:16 -0400 Subject: Remove mon-spll.h enum order dependency. The list of spellbooks in mon-spll.h was originally independent of enum order, but that changed when get_unique_spells was added. Return to the good old days. Thanks to doy for asking about it. --- crawl-ref/source/mon-util.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 026c8542d4..727e0de4f8 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -2302,6 +2302,12 @@ unique_books get_unique_spells(const monster_info &mi) for (size_t i = 0; i < num_books; ++i) { const mon_spellbook_type book = books[i]; + // TODO: should we build an index to speed this reverse lookup? + unsigned int msidx; + for (msidx = 0; msidx < ARRAYSZ(mspell_list); ++msidx) + if (mspell_list[msidx].type == book) + break; + vector spells; for (int j = 0; j < NUM_MONSTER_SPELL_SLOTS; ++j) @@ -2310,7 +2316,10 @@ unique_books get_unique_spells(const monster_info &mi) if (book == MST_GHOST) spell = mi.spells[j]; else - spell = mspell_list[book].spells[j]; + { + ASSERT(msidx < ARRAYSZ(mspell_list)); + spell = mspell_list[msidx].spells[j]; + } bool match = false; -- cgit v1.2.3-54-g00ecf