Re: CODE: Skill/Spell Choosing: Tree Structure

From: Daniel A. Koepke (
Date: 06/17/01

On Sun, 17 Jun 2001, Edward Felch wrote:

>     if (check_level(ch, i))
>        continue;

I could write a whole lot about this code.  Most of it would be on matters
of style, compactness, extensibility, etc.  But I'll cut it to the quick
and just tell you what I'm guessing the problem is.  Don't you really want
the above to be

  if (!check_level(ch, i))

?  A few casual notes: use min_level[CLASS_ADVENTURER] for the minimum
level instead of prereq[2].  Add a MAX_PREREQS #define, make the size of
prereq[] array it, and do

  for (j = 0; j < MAX_PREREQS; j++)
    if (spell_info[i].prereq[j] > 0 &&
        !check_level(ch, spell_info[i].prereq[j]))

  if (j < MAX_PREREQ)

instead of all of the

  if (spell_info[i].prereq[0] > 0)
    if (!check_level(ch, spell_info[i].prereq[0))

checks over and over.  And put the (computationally) simplest checks
before these -- it's a good habit to have because sometimes when you're
programming, it matters (it doesn't in this instance, but, still --
consistency is rarely a bad thing).

Daniel A. Koepke (dak),
Caveat emptor: I say what I mean and mean what I say.  Listen well.
Caveat venditor: Say what you mean, mean what you say.  Say it well.

   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/05/01 PST