Re: [CODE] IS_CLASS function

From: Artovil (artovil@arcanerealms.org)
Date: 12/11/01


At 12:27 2001-12-11 -0800, you wrote:
>On Tue, 11 Dec 2001, Artovil wrote:
>
> > Perhaps lazy, but it has a point, since the utils.h file is included
> > in every large file in the mud, and on some puters that takes ages to
> > compile [...]
>
>structs.h is included in every C file in the Mud, except for random.c,
>which also does not include utils.h.  Therefore, if you add/remove/change
>a class, the Mud needs to be recompiled in full anyway.

Funny that you skipped the last part of that paragraph including my
paranthesis in which I stated exactly the same thing, just phrased
differently. ;)  You devil, you.

> > The first version requires a macro for every class, which is kind of
> > redundant.
>
>It's shorter and easier to read.  The second version has no benefit over
>simply using GET_CLASS.

Perhaps easier to read, but harder to find with a grep (if you wanted to
find all the class checks in one sweep without using a long dreary reg exp,
yes, yes, flame ahead).  But I guess it doesn't really matter.  Just a
matter of how you want things structured.  I use the macros, just like the
stock code does, I just wanted to point out that the second solution wasn't
necessarily bad, and the first solution not necessarily good.

> > I have about 10 different magic classes in my MUD, which "forced" me
> > to make a macro, IS_MAGI(ch) ...
>
>You should really have made a table in class.c or constants.c with the
>desired information, etc., in it.  You could consolidate the
>pc_class_names[], etc., arrays as well into your class table.  Then
>instead of IS_MAGI you could do:
>
>   if (class_table[((int) GET_CLASS(ch))].is_magi) {
>     /* ... */
>   }
>
>or, even,
>
>   if (CLASS_FLAGGED(GET_CLASS(ch), CF_MAGI)) {
>     /* ... */
>   }
>
>That seems ultimately more useful and maintainable than a macro.
>
>-dak

The second solution sounds best, since the first seems that I need one int
or bool for every is_type, right?  The last one just stores one int?  Or
did you just use is_magi as an example to clarify?

I will do this right away, seems fun! :)  Thanks Daniel!

*insert your laughter and scoff here*

Regards,
/Torgny

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/24/03 PDT