From 8a71071e3d9dd698f31846f2261e5b77ca7085c8 Mon Sep 17 00:00:00 2001 From: zelgadis Date: Sun, 21 Dec 2008 03:57:31 +0000 Subject: Change the spell_type enumerations so that SPELL_NO_SPELL is 0 and the first valid spell (Identify) is 1. This way any bug that causes a spell_type variable to be 0 will be recognized as an invalid spell. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7892 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/acr.cc | 5 ++--- crawl-ref/source/enum.h | 23 +++++++++++------------ crawl-ref/source/spl-data.h | 2 +- crawl-ref/source/spl-util.cc | 11 ++++++----- 4 files changed, 20 insertions(+), 21 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 748f1a58d2..f8b9d9572f 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -4549,13 +4549,12 @@ static void _compile_time_asserts() COMPILE_CHECK(SK_UNARMED_COMBAT == 19 , c1); COMPILE_CHECK(SK_EVOCATIONS == 39 , c2); COMPILE_CHECK(SP_VAMPIRE == 33 , c3); - COMPILE_CHECK(SPELL_BOLT_OF_MAGMA == 18 , c4); + COMPILE_CHECK(SPELL_BOLT_OF_MAGMA == 19 , c4); COMPILE_CHECK(SPELL_POISON_ARROW == 94 , c5); COMPILE_CHECK(SPELL_SUMMON_MUSHROOMS == 223 , c6); //jmf: NEW ASSERTS: we ought to do a *lot* of these - COMPILE_CHECK(NUM_SPELLS < SPELL_NO_SPELL , c7); - COMPILE_CHECK(NUM_JOBS < JOB_UNKNOWN , c8); + COMPILE_CHECK(NUM_JOBS < JOB_UNKNOWN , c7); // Also some runtime stuff; I don't know if the order of branches[] // needs to match the enum, but it currently does. diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h index 7b1072c2f6..a1b7e7d27d 100644 --- a/crawl-ref/source/enum.h +++ b/crawl-ref/source/enum.h @@ -2574,27 +2574,27 @@ enum species_type enum spell_type { - SPELL_IDENTIFY, // 0 + SPELL_NO_SPELL, // 0 + SPELL_IDENTIFY, SPELL_TELEPORT_SELF, SPELL_CAUSE_FEAR, SPELL_CREATE_NOISE, - SPELL_REMOVE_CURSE, - SPELL_MAGIC_DART, // 5 + SPELL_REMOVE_CURSE, // 5 + SPELL_MAGIC_DART, SPELL_FIREBALL, SPELL_SWAP, SPELL_APPORTATION, - SPELL_TWIST, - SPELL_FAR_STRIKE, // 10 + SPELL_TWIST, // 10 + SPELL_FAR_STRIKE, SPELL_DELAYED_FIREBALL, SPELL_STRIKING, SPELL_CONJURE_FLAME, - SPELL_DIG, - SPELL_BOLT_OF_FIRE, // 15 + SPELL_DIG, // 15 + SPELL_BOLT_OF_FIRE, SPELL_BOLT_OF_COLD, SPELL_LIGHTNING_BOLT, - SPELL_BOLT_OF_MAGMA, // 18 - // 19 - SPELL_POLYMORPH_OTHER = 20, // 20 + SPELL_BOLT_OF_MAGMA, + SPELL_POLYMORPH_OTHER, // 20 SPELL_SLOW, SPELL_HASTE, SPELL_PARALYSE, @@ -2793,8 +2793,7 @@ enum spell_type SPELL_COLD_BREATH, SPELL_DRACONIAN_BREATH, - NUM_SPELLS, - SPELL_NO_SPELL = 250 + NUM_SPELLS }; enum slot_select_mode diff --git a/crawl-ref/source/spl-data.h b/crawl-ref/source/spl-data.h index ac8f747a2f..6bf21a8484 100644 --- a/crawl-ref/source/spl-data.h +++ b/crawl-ref/source/spl-data.h @@ -2906,7 +2906,7 @@ { SPELL_NO_SPELL, "nonexistent spell", 0, - 0, + SPFLAG_TESTING, 0, 0, -1, -1, diff --git a/crawl-ref/source/spl-util.cc b/crawl-ref/source/spl-util.cc index c4b96b7ffa..584e297770 100644 --- a/crawl-ref/source/spl-util.cc +++ b/crawl-ref/source/spl-util.cc @@ -89,10 +89,7 @@ void init_spell_descs(void) for (int i = 0; i < NUM_SPELLS; i++) spell_list[i] = -1; - // can only use up to SPELLDATASIZE _MINUS ONE_, or the - // last entry tries to set spell_list[SPELL_NO_SPELL] - // which corrupts the heap. - for (unsigned int i = 0; i < SPELLDATASIZE - 1; i++) + for (unsigned int i = 0; i < SPELLDATASIZE; i++) spell_list[spelldata[i].id] = i; } @@ -901,14 +898,18 @@ int spell_skill2type(unsigned int skill) //jmf: Simplified; moved init code to top function, init_spell_descs(). static spell_desc *_seekspell(spell_type spell) { + ASSERT(spell >= 0 && spell < NUM_SPELLS); + const int index = spell_list[spell]; ASSERT(index != -1); + return (&spelldata[index]); } bool is_valid_spell(spell_type spell) { - return (spell < NUM_SPELLS && spell_list[spell] != -1); + return (spell > SPELL_NO_SPELL && spell < NUM_SPELLS + && spell_list[spell] != -1); } static bool _cloud_helper(cloud_func func, const coord_def& where, -- cgit v1.2.3-54-g00ecf